3 // Ben Motmans <ben.motmans@gmail.com>
5 // Copyright (c) 2007 Ben Motmans
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 using System
.Collections
.Generic
;
29 using MonoDevelop
.Core
;
30 using MonoDevelop
.Database
.Sql
;
32 namespace MonoDevelop
.Database
.Components
34 [System
.ComponentModel
.Category("widget")]
35 [System
.ComponentModel
.ToolboxItem(true)]
36 public class SelectColumnWidget
: ScrolledWindow
38 public event EventHandler ColumnToggled
;
40 protected TreeView list
;
41 protected SortedColumnListStore store
;
43 private ColumnSchemaCollection columns
;
45 public SelectColumnWidget ()
50 public SelectColumnWidget (bool showCheckBoxes
)
52 list
= new TreeView ();
53 list
.HeadersVisible
= true;
55 InitializeColumns (showCheckBoxes
);
60 public bool SingleCheck
{
61 get { return store.SingleCheck; }
64 return; //when init isn't called yet
65 store
.SingleCheck
= value;
69 protected virtual void InitializeColumns (bool showCheckBoxes
)
71 TreeViewColumn col
= new TreeViewColumn ();
72 col
.Title
= AddinCatalog
.GetString ("Column");
75 CellRendererToggle toggleRenderer
= new CellRendererToggle ();
76 toggleRenderer
.Activatable
= true;
77 toggleRenderer
.Toggled
+= new ToggledHandler (ItemToggled
);
78 col
.PackStart (toggleRenderer
, false);
79 col
.AddAttribute (toggleRenderer
, "active", SortedColumnListStore
.ColSelectIndex
);
82 CellRendererText textRenderer
= new CellRendererText ();
83 col
.PackStart (textRenderer
, true);
84 col
.AddAttribute (textRenderer
, "text", SortedColumnListStore
.ColNameIndex
);
86 list
.AppendColumn (col
);
89 public void Initialize (ColumnSchemaCollection columns
)
91 this.columns
= columns
;
93 store
= new SortedColumnListStore (columns
);
94 store
.ColumnToggled
+= delegate (object sender
, EventArgs args
) {
95 if (ColumnToggled
!= null)
96 ColumnToggled (this, args
);
98 list
.Model
= store
.Store
;
101 public ColumnSchema SelectedColumn
{
104 if (list
.Selection
.GetSelected (out iter
))
105 return store
.GetColumnSchema (iter
);
110 public IEnumerable
<ColumnSchema
> CheckedColumns
{
111 get { return store.CheckedColumns; }
114 public bool IsColumnChecked
{
115 get { return store.IsColumnChecked; }
118 public void SelectAll ()
123 public void DeselectAll ()
125 store
.DeselectAll ();
128 public void Select (string name
)
133 public void Select (ColumnSchema column
)
135 store
.Select (column
);
138 private void ItemToggled (object sender
, ToggledArgs args
)
141 if (store
.Store
.GetIterFromString (out iter
, args
.Path
))
142 store
.ToggleSelect (iter
);