public CustomSelection(DataTableBackedList<ControlRow> templateTable, CustomSelectionOperator termCombiningOperator) { this.SearchTerms = new List<SearchTerm>(); this.TermCombiningOperator = termCombiningOperator; // generate search terms for all relevant controls in the template (in control order) foreach (ControlRow control in templateTable) { // skip hidden controls as they're not normally a part of the user experience // this is potentially problematic in corner cases; an option to show terms for all controls can be added if needed if (control.Visible == false) { continue; } // create search term for the control SearchTerm searchTerm = new SearchTerm(); searchTerm.ControlType = control.Type; searchTerm.DataLabel = control.DataLabel; searchTerm.DatabaseValue = control.DefaultValue; searchTerm.Operator = Constant.SearchTermOperator.Equal; searchTerm.Label = control.Label; searchTerm.List = control.GetChoices(); searchTerm.UseForSearching = false; this.SearchTerms.Add(searchTerm); switch (searchTerm.ControlType) { case Constant.Control.Counter: searchTerm.DatabaseValue = "0"; searchTerm.Operator = Constant.SearchTermOperator.GreaterThan; // Makes more sense that people will test for > as the default rather than counters break; case Constant.DatabaseColumn.DateTime: // the first time the CustomViewSelection dialog is popped CarnassialWindow calls SetDateTime() to changes the default date time to the date time // of the current image searchTerm.DatabaseValue = DateTimeHandler.ToDatabaseDateTimeString(Constant.ControlDefault.DateTimeValue); searchTerm.Operator = Constant.SearchTermOperator.GreaterThanOrEqual; // support querying on a range of datetimes by giving the user two search terms, one configured for the start of the interval and one // for the end SearchTerm dateTimeLessThanOrEqual = new SearchTerm(searchTerm); dateTimeLessThanOrEqual.Operator = Constant.SearchTermOperator.LessThanOrEqual; this.SearchTerms.Add(dateTimeLessThanOrEqual); break; case Constant.Control.Flag: searchTerm.DatabaseValue = Boolean.FalseString; break; case Constant.DatabaseColumn.UtcOffset: // the first time it's popped CustomViewSelection dialog changes this default to the date time of the current image searchTerm.SetDatabaseValue(Constant.ControlDefault.DateTimeValue.Offset); break; default: // default values above break; } } }
private void SyncTemplateTableToDatabase(DataTableBackedList<ControlRow> newTable) { this.CreateBackupIfNeeded(); // clear the existing table in the database and add the new values this.Database.DeleteRows(Constant.DatabaseTable.Controls, null); List<List<ColumnTuple>> newTableTuples = new List<List<ColumnTuple>>(); foreach (ControlRow control in newTable) { newTableTuples.Add(control.GetColumnTuples().Columns); } this.Database.Insert(Constant.DatabaseTable.Controls, newTableTuples); // update the in memory table to reflect current database content // could just use the new table but this is done in case a bug results in the insert lacking perfect fidelity this.GetControlsSortedByControlOrder(); }
public void Generate(EditorWindow mainWindow, WrapPanel parent, DataTableBackedList<ControlRow> templateTable) { // used for styling all content and label controls except ComboBoxes since the combo box style is commented out in DataEntryControls.xaml // and defined instead in MainWindow.xaml as an exception workaround DataEntryControls styleProvider = new DataEntryControls(); parent.Children.Clear(); foreach (ControlRow control in templateTable) { // instantiate control UX objects StackPanel stackPanel; switch (control.Type) { case Constant.Control.Note: case Constant.DatabaseColumn.File: case Constant.DatabaseColumn.RelativePath: Label noteLabel = this.CreateLabel(styleProvider, control); TextBox noteContent = this.CreateTextBox(styleProvider, control); stackPanel = this.CreateStackPanel(styleProvider, noteLabel, noteContent); break; case Constant.Control.Counter: RadioButton counterLabel = this.CreateCounterLabelButton(styleProvider, control); TextBox coutnerContent = this.CreateTextBox(styleProvider, control); stackPanel = this.CreateStackPanel(styleProvider, counterLabel, coutnerContent); break; case Constant.Control.Flag: case Constant.DatabaseColumn.DeleteFlag: Label flagLabel = this.CreateLabel(styleProvider, control); CheckBox flagContent = this.CreateFlag(styleProvider, control); flagContent.IsChecked = String.Equals(control.DefaultValue, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) ? true : false; stackPanel = this.CreateStackPanel(styleProvider, flagLabel, flagContent); break; case Constant.Control.FixedChoice: case Constant.DatabaseColumn.ImageQuality: Label choiceLabel = this.CreateLabel(styleProvider, control); ComboBox choiceContent = this.CreateComboBox(styleProvider, control); stackPanel = this.CreateStackPanel(styleProvider, choiceLabel, choiceContent); break; case Constant.DatabaseColumn.DateTime: Label dateTimeLabel = this.CreateLabel(styleProvider, control); DateTimeOffsetPicker dateTimeContent = this.CreateDateTimePicker(control); stackPanel = this.CreateStackPanel(styleProvider, dateTimeLabel, dateTimeContent); break; case Constant.DatabaseColumn.UtcOffset: Label utcOffsetLabel = this.CreateLabel(styleProvider, control); UtcOffsetPicker utcOffsetContent = this.CreateUtcOffsetPicker(control); stackPanel = this.CreateStackPanel(styleProvider, utcOffsetLabel, utcOffsetContent); break; default: throw new NotSupportedException(String.Format("Unhandled control type {0}.", control.Type)); } stackPanel.Tag = control.DataLabel; if (control.Visible == false) { stackPanel.Visibility = Visibility.Collapsed; } // add control to wrap panel parent.Children.Add(stackPanel); } }
public void Generate(WrapPanel parent, DataTableBackedList <ControlRow> templateTable) { // used for styling all content and label controls except ComboBoxes since the combo box style is commented out in DataEntryControls.xaml // and defined instead in MainWindow.xaml as an exception workaround DataEntryControls styleProvider = new DataEntryControls(); parent.Children.Clear(); foreach (ControlRow control in templateTable) { // instantiate control UX objects StackPanel stackPanel; switch (control.Type) { case Constant.Control.Note: case Constant.DatabaseColumn.Date: case Constant.DatabaseColumn.File: case Constant.DatabaseColumn.Folder: case Constant.DatabaseColumn.RelativePath: case Constant.DatabaseColumn.Time: Label noteLabel = EditorControls.CreateLabel(styleProvider, control); TextBox noteContent = EditorControls.CreateTextBox(styleProvider, control); stackPanel = EditorControls.CreateStackPanel(styleProvider, noteLabel, noteContent); break; case Constant.Control.Counter: RadioButton counterLabel = EditorControls.CreateCounterLabelButton(styleProvider, control); IntegerUpDown counterContent = EditorControls.CreateIntegerUpDown(styleProvider, control); stackPanel = EditorControls.CreateStackPanel(styleProvider, counterLabel, counterContent); counterLabel.IsTabStop = false; counterContent.GotFocus += this.Control_GotFocus; counterContent.LostFocus += this.Control_LostFocus; break; case Constant.Control.Flag: case Constant.DatabaseColumn.DeleteFlag: Label flagLabel = EditorControls.CreateLabel(styleProvider, control); CheckBox flagContent = this.CreateFlag(styleProvider, control); flagContent.IsChecked = String.Equals(control.DefaultValue, Constant.BooleanValue.True, StringComparison.OrdinalIgnoreCase) ? true : false; stackPanel = EditorControls.CreateStackPanel(styleProvider, flagLabel, flagContent); break; case Constant.Control.FixedChoice: case Constant.DatabaseColumn.ImageQuality: Label choiceLabel = EditorControls.CreateLabel(styleProvider, control); ComboBox choiceContent = EditorControls.CreateComboBox(styleProvider, control); stackPanel = EditorControls.CreateStackPanel(styleProvider, choiceLabel, choiceContent); break; case Constant.DatabaseColumn.DateTime: Label dateTimeLabel = EditorControls.CreateLabel(styleProvider, control); DateTimePicker dateTimeContent = this.CreateDateTimePicker(control); stackPanel = EditorControls.CreateStackPanel(styleProvider, dateTimeLabel, dateTimeContent); break; case Constant.DatabaseColumn.UtcOffset: Label utcOffsetLabel = EditorControls.CreateLabel(styleProvider, control); UtcOffsetUpDown utcOffsetContent = this.CreateUtcOffsetPicker(control); stackPanel = EditorControls.CreateStackPanel(styleProvider, utcOffsetLabel, utcOffsetContent); break; default: throw new NotSupportedException(String.Format("Unhandled control type {0}.", control.Type)); } stackPanel.Tag = control.DataLabel; if (control.Visible == false) { stackPanel.Visibility = Visibility.Collapsed; } // add control to wrap panel parent.Children.Add(stackPanel); } }