/// <summary> /// Moves the selected elements up in the order of columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonMoveUp_Click(object sender, System.EventArgs e) { // This will suspend the events while the lists are udpated. this.listBoxDisplayedFields.BeginUpdate(); // This will move the selected items upward in the list box. foreach (int selectedIndex in this.listBoxDisplayedFields.SelectedIndices) { // Halt the operation if the columns are already at the start of the report. With a multiple selection, this will // appear to halt the whole train of selected items when it reaches the start of the column list. if (selectedIndex == 0) { break; } // Move the element up one in the ordering of the columns in the internal data structures. DataTransform.ColumnNode sourceColumn = (DataTransform.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex]; DataTransform.ColumnNode destinationColumn = (DataTransform.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex - 1]; int sourceIndex = this.displayedList.IndexOf(sourceColumn); int destinationIndex = this.displayedList.IndexOf(destinationColumn); this.displayedList.Move(sourceIndex, destinationIndex); // Move the element up in the list box also. this.listBoxDisplayedFields.Items.RemoveAt(selectedIndex); this.listBoxDisplayedFields.Items.Insert(selectedIndex - 1, sourceColumn); this.listBoxDisplayedFields.SetSelected(selectedIndex - 1, true); } // This will re-enable the events this.listBoxDisplayedFields.EndUpdate(); }
/// <summary> /// Moves the selected elements down in the order of columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonMoveDown_Click(object sender, System.EventArgs e) { // This will suspend the events while the lists are udpated. this.listBoxDisplayedFields.BeginUpdate(); // This willl move each of the items in a downward direction in the list of displayed columns. int[] selectedIndices = new int[this.listBoxDisplayedFields.SelectedIndices.Count]; this.listBoxDisplayedFields.SelectedIndices.CopyTo(selectedIndices, 0); Array.Reverse(selectedIndices); foreach (int selectedIndex in selectedIndices) { // This will stop the operation when the selected columns have reached the rightmost side of the document. if (selectedIndex == this.listBoxDisplayedFields.Items.Count - 1) { break; } // Move the element down in the ordering of the column list data structure. DataTransform.ColumnNode sourceColumn = (DataTransform.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex]; DataTransform.ColumnNode destinationColumn = (DataTransform.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex + 1]; int sourceIndex = this.displayedList.IndexOf(sourceColumn); int destinationIndex = this.displayedList.IndexOf(destinationColumn); this.displayedList.Move(sourceIndex, destinationIndex); // Move the element down the list box also. this.listBoxDisplayedFields.Items.RemoveAt(selectedIndex); this.listBoxDisplayedFields.Items.Insert(selectedIndex + 1, sourceColumn); this.listBoxDisplayedFields.SetSelected(selectedIndex + 1, true); } // This will re-enable the events this.listBoxDisplayedFields.EndUpdate(); }
/// <summary> /// Removes a column from the list of displayed columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonRemove_Click(object sender, System.EventArgs e) { // Make each of the selected columns visible and move it from the 'Displayed' list to the 'Displayed list. Note that // the selection is changed during the loop, so a copy of the selected items is needed for the loop. DataTransform.ColumnNode[] selectedItems = new DataTransform.ColumnNode[this.listBoxDisplayedFields.SelectedItems.Count]; this.listBoxDisplayedFields.SelectedItems.CopyTo(selectedItems, 0); // Move the selected column from the available to the displayed list. foreach (DataTransform.ColumnNode columnNode in selectedItems) { this.displayedList.Remove(columnNode); this.availableList.Add(columnNode); } // Refresh the data in the list boxes. DrawListBoxes(); }
/// <summary> /// Generates the class that transforms a data model into a human read-able document. /// </summary> /// <param name="dataTransform">Describes how to transform abstract data into a document.</param> public DataTransformClass(DataTransform dataTransform) { // /// <summary> // /// Transforms a data model into a document. // /// </summary> // public class PrototypeView : DocumentView // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement("Transforms a data model into a document.", true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Name = dataTransform.DataTransformId; this.BaseTypes.Add("DocumentView"); // The Column Index (Absolute Order) Constants // // Constant Column Indices // internal const int workingStatusImageIndex = 0; // internal const int submittedStatusImageIndex = 1; // internal const int recordIdIndex = 2; bool isFirstColumnIndexConstant = true; for (int columnIndex = 0; columnIndex < dataTransform.Columns.Count; columnIndex++) { DataTransform.ColumnNode columnNode = dataTransform.Columns[columnIndex]; string constantName = CamelCase.Convert(columnNode.ColumnId) + "Index"; CodeMemberField codeMemberField = new CodeMemberField(typeof(Int32), constantName); if (isFirstColumnIndexConstant) { isFirstColumnIndexConstant = false; codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Indices (Column Order)")); } codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Assembly; codeMemberField.InitExpression = new CodePrimitiveExpression(columnIndex); this.Members.Add(codeMemberField); } // The Column Ordinal (Viewer Order) Constants // // Constant Column Indices // internal const int workingStatusImageOrdinal = 0; // internal const int submittedStatusImageOrdinal = 1; // internal const int recordIdOrdinal = 2; bool isFirstColumnOrdinalConstant = true; for (int columnOrdinal = 0; columnOrdinal < dataTransform.View.Count; columnOrdinal++) { DataTransform.ColumnNode columnNode = dataTransform.View[columnOrdinal].Column; string constantName = CamelCase.Convert(columnNode.ColumnId) + "Ordinal"; CodeMemberField codeMemberField = new CodeMemberField(typeof(Int32), constantName); if (isFirstColumnOrdinalConstant) { isFirstColumnOrdinalConstant = false; codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Ordinals (Viewer Order)")); } codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Assembly; codeMemberField.InitExpression = new CodePrimitiveExpression(columnOrdinal); this.Members.Add(codeMemberField); } // The Row Height Constants. // // Constant Row Heights // private const float headerRowHeight = 40F; // private const float workingOrderRowHeight = 20F; // private const float sourceOrderRowHeight = 20F; // private const float destinationOrderRowHeight = 20F; // private const float executionRowHeight = 20F; bool isFirstRowHeightConstant = true; foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates) { foreach (DataTransform.RowNode rowNode in templateNode.Rows) { string constantName = CamelCase.Convert(rowNode.RowId) + "Height"; CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName); if (isFirstRowHeightConstant) { isFirstRowHeightConstant = false; codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Heights")); } codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Private; codeMemberField.InitExpression = new CodePrimitiveExpression(rowNode.Height); this.Members.Add(codeMemberField); } } // The Row Width Constants. // // Constant Row Widths // private const float headerRowHeight = 745F; // private const float workingOrderRowHeight = 745F; // private const float sourceOrderRowHeight = 745F; // private const float destinationOrderRowHeight = 745F; // private const float executionRowHeight = 745F; bool isFirstRowWidthConstant = true; foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates) { foreach (DataTransform.RowNode rowNode in templateNode.Rows) { string constantName = CamelCase.Convert(rowNode.RowId) + "Width"; CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName); if (isFirstRowWidthConstant) { isFirstRowWidthConstant = false; codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Widths")); } codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Private; float rowWidth = 0.0f; foreach (DataTransform.ColumnReferenceNode columnReferenceNode in dataTransform.View) { rowWidth += columnReferenceNode.Column.Width; } codeMemberField.InitExpression = new CodePrimitiveExpression(rowWidth); this.Members.Add(codeMemberField); } } // The Column Width Constants. // // Constant Column Widths // private const float askPriceWidth = 53F; // private const float availableQuantityWidth = 56F; // private const float bidPriceWidth = 53F; // private const float destinationOrderQuantityWidth = 56F; bool isFirstColumnWidthConstant = true; foreach (DataTransform.ColumnNode columnNode in dataTransform.Columns) { string constantName = CamelCase.Convert(columnNode.ColumnId) + "Width"; CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName); if (isFirstColumnWidthConstant) { isFirstColumnWidthConstant = false; codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Widths")); } codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Private; codeMemberField.InitExpression = new CodePrimitiveExpression(columnNode.Width); this.Members.Add(codeMemberField); } // The Comparers // // Comparers // private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> workingOrderRowComparer; // private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> sourceOrderRowComparer; // private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> destinationOrderRowComparer; bool isFirstComparer = true; foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates) { foreach (DataTransform.RowNode rowNode in templateNode.Rows) { foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates) { if (applyTemplateNode.Sorts.Count != 0) { string comparerName = CamelCase.Convert(applyTemplateNode.Select) + "RowComparer"; CodeMemberField codeMemberField = new CodeMemberField(typeof(IComparer <ViewerRow>), comparerName); if (isFirstComparer) { isFirstComparer = false; codeMemberField.Comments.Add(new CodeCommentStatement("Comparers")); } codeMemberField.Attributes = MemberAttributes.Private; this.Members.Add(codeMemberField); } } } } // Add the constructor to the namespace. this.Members.Add(new DataTransformConstructor(dataTransform)); // Add the Build method used to construct the styles. this.Members.Add(new DataTransformInitializeViewMethod(dataTransform)); // Add the Build method used to construct the document. this.Members.Add(new DataTransformBuildViewMethod(dataTransform)); // Add the code for all the template handlers. foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates) { this.Members.Add(new DataTransformTemplateMethod(templateNode)); } }
/// <summary> /// Populate the two list boxes with the hidden and displayed columns. /// </summary> private void DrawListBoxes() { DataTransform.ColumnNode[] availableColumns = new DataTransform.ColumnNode[availableList.Count]; availableList.CopyTo(availableColumns, 0); DataTransform.ColumnNode[] displayedColumns = new DataTransform.ColumnNode[displayedList.Count]; displayedList.CopyTo(displayedColumns, 0); // The idea here is to preserve the selected items in the 'available' list box when it is redrawn with the new // elements. ListBox.SelectedObjectCollection selectedAvailableObjects = this.listBoxAvailableFields.SelectedItems; DataTransform.ColumnNode[] selectedAvailableColumns = new DataTransform.ColumnNode[selectedAvailableObjects.Count]; selectedAvailableObjects.CopyTo(selectedAvailableColumns, 0); // The idea here is to preserve the selected items in the 'displayed' list box when it is redrawn with the new // elements. ListBox.SelectedObjectCollection selectedDisplayedObjects = this.listBoxDisplayedFields.SelectedItems; DataTransform.ColumnNode[] selectedDisplayedColumns = new DataTransform.ColumnNode[selectedDisplayedObjects.Count]; selectedDisplayedObjects.CopyTo(selectedDisplayedColumns, 0); // Clear out the previous entries and repopulate the list of available (hidden) fields. Note that the updating is // suspended so the user doesn't see the items cleared out. If the updating were not inhibited, there would be a // noticable 'blink' as the items were cleared and repopulated. Note that the selected state of the items is preserved // when the list is redrawn. this.listBoxAvailableFields.BeginUpdate(); this.listBoxAvailableFields.Items.Clear(); this.listBoxAvailableFields.Items.AddRange(availableColumns); foreach (DataTransform.ColumnNode column in selectedAvailableColumns) { int index = this.listBoxAvailableFields.Items.IndexOf(column); if (index != -1) { this.listBoxAvailableFields.SetSelected(index, true); } } foreach (DataTransform.ColumnNode column in selectedDisplayedColumns) { int index = this.listBoxAvailableFields.Items.IndexOf(column); if (index != -1) { this.listBoxAvailableFields.SetSelected(index, true); } } this.listBoxAvailableFields.EndUpdate(); // Do the same for the displayed fields. Note that the selected state of the items is preserved when the list is // redrawn. this.listBoxDisplayedFields.BeginUpdate(); this.listBoxDisplayedFields.Items.Clear(); this.listBoxDisplayedFields.Items.AddRange(displayedColumns); foreach (DataTransform.ColumnNode column in selectedAvailableColumns) { int index = this.listBoxDisplayedFields.Items.IndexOf(column); if (index != -1) { this.listBoxDisplayedFields.SetSelected(index, true); } } foreach (DataTransform.ColumnNode column in selectedDisplayedColumns) { int index = this.listBoxDisplayedFields.Items.IndexOf(column); if (index != -1) { this.listBoxDisplayedFields.SetSelected(index, true); } } this.listBoxDisplayedFields.EndUpdate(); }