private void _listGroup_ListDataChanged(ListGroupNode listGroup, ListEventArgs a) { DataTable table = _dataSet.Tables[listGroup.FullPath]; System.Diagnostics.Debug.Assert(table != null); if (a is RefreshAllListEventArgs) { refreshListData(listGroup, table, a, 0, (int)listGroup.LengthState.Value); } else if (a is DeleteListEventArgs) { deleteListData(listGroup, table, a.ParentIndices, ((DeleteListEventArgs)a).Start, ((DeleteListEventArgs)a).Length); } else if (a is ChangeListEventArgs) { } else if (a is InsertListEventArgs) { InsertListEventArgs ia = (InsertListEventArgs)a; renumberListData(listGroup, table, ia.ParentIndices, ia.InsertAfter + 1, ia.InsertAfter + ia.ItemCount + 1, ia.InsertAfter); refreshListData(listGroup, table, ia, ia.InsertAfter + 1, ia.ItemCount); } }
public ListSelectionSpace(string list) { _listName = list; _list = null; _formula = null; _resolved = false; }
public bool ResolveObject(VariableTable varTable) { _list = varTable.GetListGroup(_listName); _resolved = (_list != null); if (_resolved) { _window = new IndexedDataWindow(_list.DataWindow); changeIndexWindow(_formula); } return(_resolved); }
/* * Constructor */ /// <summary> /// Constructor that initializes BinarySpace /// </summary> public ListSelectionSpace(ListGroupNode list, Dependency df) { _list = list; _listName = list.FullPath; _resolved = true; if (df != null) { _formula = df.Simplify(); _window = new IndexedDataWindow(_list.DataWindow); changeIndexWindow(_formula); } }
/* * Constructor */ public DataGridListCIO(ListGroupNode g) : base(new Panel()) { Panel p = (Panel)this.GetControl(); _listGroup = g; // // This section creates, places, and sizes (to some extent) the // control within the panel. // System.Drawing.SizeF size; _listGrid = new DataGrid(); p.Controls.Add(_listGrid); if (_listGroup.Labels != null) { _listLabel = new Label(); _listLabel.Text = _listGroup.Labels.GetFirstLabel(); _listLabel.Location = new System.Drawing.Point(0, 0); size = Globals.MeasureString(_listLabel.Text, _listLabel.Font); _listLabel.Size = new System.Drawing.Size((int)size.Width, (int)size.Height); p.Controls.Add(_listLabel); _listGrid.Location = new System.Drawing.Point(0, _listLabel.Height + 3); } else { _listGrid.Location = new System.Drawing.Point(0, 0); } p.Resize += new EventHandler(p_Resize); // // Setup the DataGrid to deal with this list structure // setupDataGrid(); // // hook into appropriate events // _listGroup.ListDataChanged += new ListEvent(_listGroup_ListDataChanged); _listGroup.SelectionState.ValueChangedEvent += new PUC.ApplianceState.ValueChangedHandler(SelectionState_ValueChangedEvent); // TODO: hook into appropriate DataGrid events }
/* * Constructors */ public ListIndexState(Appliance appliance, ListGroupNode lg) : base(appliance, "", false) { _listGroup = lg; _dataWindow = lg.DataWindow; IntegerSpace intSpace = new IntegerSpace(new IntNumber(1), new NumberConstraint(this, lg.LengthState)); this.Type = new PUCType(intSpace); this.Labels = new LabelDictionary(); this.Labels.AddLabel(new StringValue("List Index")); this.Labels.AddLabel(new StringValue("Index")); this.ValueChangeRequested += new ValueChangeRequestedHandler(this.changeWindowIndex); _dataWindow.IndexChanged += new EventHandler(WindowIndexChanged); }
/* * Process Method */ public override void Process(GroupNode g, UIGenerator ui) { if (!g.IsList()) { return; } ListGroupNode lg = (ListGroupNode)g; ConcreteInteractionObject cio = ui.Core.ObjectRegistry.ChooseWidget(lg); g.Decorations.Add(ListDecision.DECISION_KEY, new ListDecision()); if (cio != null) { g.Decorations.Add(UnitDecision.DECISION_KEY, new UnitDecision(cio)); } else { // add in some components to allow the user to scroll through elements // in the list and make selections (if relevant) ApplianceState indexState = new ListIndexState(lg.Appliance, lg); ObjectGroupNode idxGrp = new ObjectGroupNode(indexState); lg.Children.Add(idxGrp); idxGrp.Parent = lg; if (lg.SelectionType == SelectionType.One) { lg.SelectionState.ValueChangedEvent += new PUC.ApplianceState.ValueChangedHandler(((ListIndexState)indexState).SelectionChanged); } // TODO: Implement multiple selections code } }
protected void deleteListData(ListGroupNode listGroup, DataTable table, int[] parentIndices, int start, int length) { // TODO: Have to think about removing appropriate rows in child tables System.Int32[] keys; if (parentIndices == null) { keys = new int[1]; } else { keys = new int[parentIndices.Length + 1]; for (int i = 0; i < parentIndices.Length; i++) { keys[i] = parentIndices[i]; } } System.Diagnostics.Debug.Assert(keys.Length == table.PrimaryKey.Length); for (int i = 1; i <= length; i++) // we start with 1 to work with 1-indexed PUC lists { keys[keys.Length - 1] = start + i; DataRow row = table.Rows.Find(keys); if (row != null) { table.Rows.Remove(row); } } table.AcceptChanges(); }
protected void renumberListData(ListGroupNode listGroup, DataTable table, int[] parentIndices, int start, int newstart, int length) { // TODO: have to think about doing renumbering in child tables System.Int32[] keys; if (parentIndices == null) { keys = new int[1]; } else { keys = new int[parentIndices.Length + 1]; for (int i = 0; i < parentIndices.Length; i++) { keys[i] = (System.Int32)parentIndices[i]; } } System.Diagnostics.Debug.Assert(keys.Length == table.PrimaryKey.Length); for (int i = 0; i <= length; i++) // we start with 1 to work with 1-indexed PUC lists { keys[keys.Length - 1] = (System.Int32)start + i; DataRow row = table.Rows.Find(keys); row[INDEX_COL_NAME] = newstart + i; row.AcceptChanges(); } table.AcceptChanges(); }
/* * Constructor */ public OneDimCategoricalList(ListGroupNode g) : base(new Panel()) { Panel p = (Panel)this.GetControl(); _listGroup = g; _listLabels = _listGroup.Labels; // for efficiency, disconnect data windows to internal states _listGroup.DataWindow.Clear(); System.Drawing.SizeF size; _listView = new ListView(); _listView.View = View.Details; _listView.FullRowSelect = true; p.Controls.Add(_listView); if (_listLabels != null) { _listLabel = new Label(); _listLabel.Text = _listLabels.GetShortestLabel(); _listLabel.Location = new System.Drawing.Point(0, 0); size = Globals.MeasureString(_listLabel.Text, _listLabel.Font); _listLabel.Size = new System.Drawing.Size((int)size.Width, (int)size.Height); p.Controls.Add(_listLabel); _listView.Location = new System.Drawing.Point(0, _listLabel.Height + 3); } else { _listView.Location = new System.Drawing.Point(0, 0); } p.Resize += new EventHandler(p_Resize); // determine if multiple selection is being used #if POCKETPC // the CheckBoxes property allows multiple selection on a PocketPC _listView.CheckBoxes #endif #if DESKTOP _listView.MultiSelect #endif = _listGroup.SelectionType == SelectionType.Multiple; // extract the states _states = new ArrayList(); extractStates(_listGroup, true); // identify the columns and set them up IEnumerator states = _states.GetEnumerator(); while (states.MoveNext()) { ApplianceState s = (ApplianceState)states.Current; ColumnHeader ch = new ColumnHeader(); ch.Text = s.Labels.GetShortestLabel(); ch.Width = 20; _listView.Columns.Add(ch); } // hook into appropriate events _listGroup.ListDataChanged += new ListEvent(_listGroup_ListDataChanged); _listGroup.SelectionState.ValueChangedEvent += new PUC.ApplianceState.ValueChangedHandler(SelectionState_ValueChangedEvent); _listView.SelectedIndexChanged += new EventHandler(_listView_SelectedIndexChanged); }
private void _listGroup_ListDataChanged(ListGroupNode listGroup, ListEventArgs a) { System.Diagnostics.Debug.Assert(listGroup == _listGroup); _listView.BeginUpdate(); if (a is RefreshAllListEventArgs) { _listView.Items.Clear(); int length = (int)_listGroup.LengthState.Value; for (int i = 0; i < length; i++) { _listView.Items.Add(new ListViewItem()); } refreshListData(_listGroup.Appliance.VariableTable, 0, length); } else if (a is DeleteListEventArgs) { DeleteListEventArgs da = (DeleteListEventArgs)a; // +1 because indicies are inclusive for (int i = 0; i < da.Length; i++) { _listView.Items.RemoveAt(da.Start); } } else if (a is ChangeListEventArgs) { ChangeListEventArgs ca = (ChangeListEventArgs)a; int lenDiff; if (ca.OldLength < ca.NewLength) { lenDiff = ca.NewLength - ca.OldLength; for (int i = 0; i < lenDiff; i++) { _listView.Items.Insert(ca.Start + i, new ListViewItem()); } for (int i = lenDiff; i < ca.NewLength; i++) { _listView.Items[ca.Start + i].SubItems.Clear(); } } else { lenDiff = ca.OldLength - ca.NewLength; for (int i = 0; i < lenDiff; i++) { _listView.Items.RemoveAt(ca.Start + i); } for (int i = ca.Start; i < (ca.Start + ca.NewLength); i++) { _listView.Items[i].SubItems.Clear(); } } refreshListData(_listGroup.Appliance.VariableTable, ca.Start, ca.NewLength); } else if (a is InsertListEventArgs) { InsertListEventArgs ia = (InsertListEventArgs)a; for (int i = 0; i < ia.ItemCount; i++) { _listView.Items.Insert(ia.InsertAfter + i, new ListViewItem()); } refreshListData(_listGroup.Appliance.VariableTable, ia.InsertAfter, ia.ItemCount); } _listView.EndUpdate(); }
/* * Static Methods */ public static ConcreteInteractionObject CreateListCIO(ListGroupNode g) { return(new DataGridListCIO(g)); }
protected void refreshListData(ListGroupNode listGroup, DataTable table, ListEventArgs a, int start, int length) { IndexedDataWindow win = listGroup.DataWindow; int[] parentIndices = a.ParentIndices; System.Int32[] keys; if (parentIndices == null) { keys = new int[1]; } else { keys = new int[parentIndices.Length + 1]; for (int i = 0; i < parentIndices.Length; i++) { keys[i] = parentIndices[i]; } } System.Diagnostics.Debug.Assert(keys.Length == table.PrimaryKey.Length); for (int i = 1; i <= length; i++) // we start with 1 to work with 1-indexed PUC lists { keys[keys.Length - 1] = win.Index = start + i; DataRow row = null; try // have had some trouble with Rows.Find in an empty table (not sure if that is the only time though) { row = table.Rows.Find(keys); } catch (Exception) { } if (row == null) { // row does not exist...build a new one row = table.NewRow(); // fill in the primary keys for (int j = 0; j < table.PrimaryKey.Length; j++) { row[table.PrimaryKey[j]] = keys[j]; } // add the row table.Rows.Add(row); } // update data in the row IEnumerator cols = table.Columns.GetEnumerator(); while (cols.MoveNext()) { ApplianceObject ao = (ApplianceObject)_columnToStateMap[cols.Current]; if (ao != null && ao.State) { ApplianceState state = (ApplianceState)ao; if (state.Type.ValueSpace.Space == PUC.Types.ValueSpace.BOOLEAN_SPACE) { row[(DataColumn)cols.Current] = (bool)state.Value; } else { row[(DataColumn)cols.Current] = state.Value.ToString(); } } } row.AcceptChanges(); } table.AcceptChanges(); }
protected void gridSetupHelper(BranchGroupNode group, ArrayList listTables, DataTable current, DataGridTableStyle style) { IEnumerator e = group.Children.GetEnumerator(); while (e.MoveNext()) { if (e.Current is ListGroupNode) { ListGroupNode lg = (ListGroupNode)e.Current; // create a new table DataTable table = new DataTable(lg.FullPath); // create array for storing primary keys DataColumn[] keys = new DataColumn[listTables.Count + 1]; // add the table to the DataSet _dataSet.Tables.Add(table); IEnumerator list = listTables.GetEnumerator(); for (int i = 0; list.MoveNext(); i++) { DataTable parentTable = (DataTable)list.Current; string parentIndexCol = parentTable.TableName + "." + INDEX_COL_NAME; // add a column to reference the parent table index table.Columns.Add(parentIndexCol, Type.GetType("System.Int32")); // add column to primary key array keys[i] = table.Columns[parentIndexCol]; } // add the special column with an integer type table.Columns.Add(INDEX_COL_NAME, Type.GetType("System.Int32")); table.Columns[INDEX_COL_NAME].Unique = true; keys[listTables.Count] = table.Columns[INDEX_COL_NAME]; // set primary keys table.PrimaryKey = keys; // determine relation name string relationName = lg.Name; if (lg.Labels != null) { relationName = lg.Labels.GetShortestLabel(); } // make the parent/child DataRelation to the DataSet DataRelation r = new DataRelation(relationName, current.Columns[INDEX_COL_NAME], table.Columns[current.TableName + "." + INDEX_COL_NAME]); // add relation to the DataSet _dataSet.Relations.Add(r); // create the DataGridTableStyle DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = table.TableName; tableStyle.ReadOnly = true; listTables.Add(table); gridSetupHelper(lg, listTables, table, tableStyle); listTables.RemoveAt(listTables.Count - 1); // add TableStyle after all columns have been found _listGrid.TableStyles.Add(tableStyle); } else if (e.Current is BranchGroupNode) { gridSetupHelper((BranchGroupNode)e.Current, listTables, current, style); } else if (e.Current is ObjectGroupNode) { ApplianceObject ao = ((ObjectGroupNode)e.Current).Object; string name = ao.FullName.Substring(current.TableName.Length + 1); if (ao.State) { DataGridColumnStyle columnStyle; Type type; if (((ApplianceState)ao).Type.ValueSpace.Space == PUC.Types.ValueSpace.BOOLEAN_SPACE) { type = true.GetType(); columnStyle = new DataGridBoolColumn(); } else { type = "".GetType(); columnStyle = new DataGridTextBoxColumn(); } columnStyle.MappingName = name; columnStyle.HeaderText = ao.Labels.GetShortestLabel(); columnStyle.ReadOnly = ((ApplianceState)ao).ReadOnly; if (!columnStyle.ReadOnly) { style.ReadOnly = false; } if (((ApplianceState)ao).Type.ValueSpace.Space == PUC.Types.ValueSpace.BINARY_SPACE) { columnStyle.ReadOnly = true; } DataColumn col = new DataColumn(name, type); _columnToStateMap[col] = ao; current.Columns.Add(col); style.GridColumnStyles.Add(columnStyle); } else if (ao is ApplianceCommand) { DataGridBoolColumn columnStyle = new DataGridBoolColumn(); columnStyle.MappingName = name; columnStyle.ReadOnly = style.ReadOnly = false; DataColumn col = new DataColumn(name, true.GetType()); _columnToStateMap[col] = ao; current.Columns.Add(col); style.GridColumnStyles.Add(columnStyle); } } } }