[8055] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8055] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Clients.OKB.Query {
|
---|
| 29 | [View("CombinedFilter View")]
|
---|
| 30 | [Content(typeof(CombinedFilter), true)]
|
---|
| 31 | public partial class CombinedFilterView : AsynchronousContentView {
|
---|
| 32 | public new CombinedFilter Content {
|
---|
| 33 | get { return (CombinedFilter)base.Content; }
|
---|
| 34 | set { base.Content = value; }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public CombinedFilterView() {
|
---|
| 38 | InitializeComponent();
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override void OnInitialized(System.EventArgs e) {
|
---|
| 42 | base.OnInitialized(e);
|
---|
| 43 | filtersComboBox.DataSource = QueryClient.Instance.Filters.ToList();
|
---|
| 44 | filtersComboBox.DisplayMember = "Label";
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | protected override void OnContentChanged() {
|
---|
| 48 | base.OnContentChanged();
|
---|
| 49 | RemoveFilters();
|
---|
| 50 | label.Text = string.Empty;
|
---|
| 51 | if (Content != null) {
|
---|
| 52 | string nl = Environment.NewLine;
|
---|
| 53 | label.Text = Content.Operation == BooleanOperation.And ? "A" + nl + "N" + nl + "D" : "O" + nl + "R";
|
---|
| 54 |
|
---|
| 55 | foreach (Filter filter in Content.Filters)
|
---|
| 56 | AddFilter(filter);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void SetEnabledStateOfControls() {
|
---|
| 61 | base.SetEnabledStateOfControls();
|
---|
| 62 | addButton.Enabled = Content != null && !ReadOnly && filtersComboBox.SelectedIndex != -1;
|
---|
| 63 | filtersComboBox.Enabled = Content != null && !ReadOnly && filtersComboBox.Items.Count > 0;
|
---|
| 64 | tableLayoutPanel.Enabled = Content != null && !ReadOnly;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | private void AddFilter(Filter filter) {
|
---|
| 68 | Content.Filters.Add(filter);
|
---|
| 69 | int rowIndex = Content.Filters.Count;
|
---|
| 70 |
|
---|
| 71 | tableLayoutPanel.SuspendLayout();
|
---|
| 72 | tableLayoutPanel.RowCount++;
|
---|
| 73 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
---|
| 74 |
|
---|
| 75 | Button removeButton = new Button();
|
---|
| 76 | removeButton.Size = new System.Drawing.Size(24, 24);
|
---|
| 77 | removeButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
---|
| 78 | removeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Remove;
|
---|
| 79 | removeButton.Tag = filter;
|
---|
| 80 | removeButton.Click += new System.EventHandler(removeButton_Click);
|
---|
| 81 | tableLayoutPanel.Controls.Add(removeButton, 0, rowIndex);
|
---|
| 82 |
|
---|
| 83 | ContentView filterView = (ContentView)MainFormManager.CreateDefaultView(filter.GetType());
|
---|
| 84 | filterView.Content = filter;
|
---|
| 85 | filterView.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
| 86 | tableLayoutPanel.Controls.Add(filterView, 1, rowIndex);
|
---|
| 87 |
|
---|
| 88 | tableLayoutPanel.ResumeLayout();
|
---|
| 89 | }
|
---|
| 90 | private void RemoveFilter(Filter filter) {
|
---|
| 91 | int rowIndex = Content.Filters.IndexOf(filter) + 1;
|
---|
| 92 | Content.Filters.Remove(filter);
|
---|
| 93 |
|
---|
| 94 | tableLayoutPanel.SuspendLayout();
|
---|
| 95 | Control removeButton = tableLayoutPanel.GetControlFromPosition(0, rowIndex);
|
---|
| 96 | Control filterView = tableLayoutPanel.GetControlFromPosition(1, rowIndex);
|
---|
| 97 | tableLayoutPanel.Controls.Remove(removeButton);
|
---|
| 98 | removeButton.Dispose();
|
---|
| 99 | tableLayoutPanel.Controls.Remove(filterView);
|
---|
| 100 | filterView.Dispose();
|
---|
| 101 |
|
---|
| 102 | for (int i = rowIndex + 1; i < tableLayoutPanel.RowCount; i++) {
|
---|
| 103 | tableLayoutPanel.SetRow(tableLayoutPanel.GetControlFromPosition(0, i), i - 1);
|
---|
| 104 | tableLayoutPanel.SetRow(tableLayoutPanel.GetControlFromPosition(1, i), i - 1);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | tableLayoutPanel.RowCount--;
|
---|
| 108 | tableLayoutPanel.RowStyles.RemoveAt(rowIndex);
|
---|
| 109 | tableLayoutPanel.ResumeLayout();
|
---|
| 110 | }
|
---|
| 111 | private void RemoveFilters() {
|
---|
| 112 | tableLayoutPanel.SuspendLayout();
|
---|
| 113 | for (int i = tableLayoutPanel.RowCount - 1; i > 0; i--) {
|
---|
| 114 | Control removeButton = tableLayoutPanel.GetControlFromPosition(0, i);
|
---|
| 115 | Control filterView = tableLayoutPanel.GetControlFromPosition(1, i);
|
---|
| 116 | tableLayoutPanel.Controls.Remove(removeButton);
|
---|
| 117 | removeButton.Dispose();
|
---|
| 118 | tableLayoutPanel.Controls.Remove(filterView);
|
---|
| 119 | filterView.Dispose();
|
---|
| 120 | tableLayoutPanel.RowCount--;
|
---|
| 121 | tableLayoutPanel.RowStyles.RemoveAt(i);
|
---|
| 122 | }
|
---|
| 123 | tableLayoutPanel.ResumeLayout();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | private void addButton_Click(object sender, System.EventArgs e) {
|
---|
| 127 | Filter filter = filtersComboBox.SelectedItem as Filter;
|
---|
| 128 | if (filter != null) AddFilter(filter.Clone());
|
---|
| 129 | }
|
---|
| 130 | private void removeButton_Click(object sender, System.EventArgs e) {
|
---|
| 131 | Filter filter = ((Button)sender).Tag as Filter;
|
---|
| 132 | if (filter != null) RemoveFilter(filter);
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | }
|
---|