comparison m-toolbox/classes/@repogui/buildConditions.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % Callback to build the query conditions panel.
2 %
3 % $Id: buildConditions.m,v 1.5 2011/04/08 08:56:26 hewitson Exp $
4 %
5 function buildConditions(mainfig)
6
7 ALLHEIGHT = 0.06;
8 pmarg = 0.025;
9
10 panel = mainfig.panels(3);
11 Ppos = get(panel, 'Position');
12 Nc = mainfig.Nconditions;
13 conn = mainfig.connection;
14 Gproperties = mainfig.Gproperties;
15 fontsize = Gproperties.fontsize;
16
17 % before deleting, record the table selection
18 tableSelected = mainfig.tableSelected;
19 % record field selection
20 fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList');
21 fselection = get(fieldList, 'Value');
22 % record order by
23 fieldOrder = findobj(mainfig.handle, 'Tag', 'fieldOrderBy');
24 forder = get(fieldOrder, 'Value');
25 % record sort direction
26 sortDir = findobj(mainfig.handle, 'Tag', 'sortDir');
27 sort = get(sortDir, 'Value');
28 % record current conditions
29 conds = cell(Nc,4);
30 for k=1:Nc
31 pmh = findobj(mainfig.handle, 'Tag', sprintf('c%02dField', k));
32 conds{k,1} = get(pmh, 'Value');
33 pmh = findobj(mainfig.handle, 'Tag', sprintf('c%02dCondition', k));
34 conds{k,2} = get(pmh, 'Value');
35 pmh = findobj(mainfig.handle, 'Tag', sprintf('c%02dValue', k));
36 conds{k,3} = get(pmh, 'String');
37 if k<Nc
38 pmh = findobj(mainfig.handle, 'Tag', sprintf('c%02dCompound', k));
39 conds{k,4} = get(pmh, 'Value');
40 end
41 end
42
43 ch = get(panel, 'Children');
44 if ~isempty(ch)
45 delete(ch)
46 drawnow
47 end
48 %--------------------------------------------------------------------------
49 %-- Draw Table selection
50
51 % get tables
52 tables = repogui.getTables(mainfig);
53 Sleft = pmarg;
54 Sheight = ALLHEIGHT;
55 Sbottom = 1 -pmarg - Sheight;
56 Swidth = 0.1;
57
58 sth = uicontrol(panel,'Style','text',...
59 'String', 'From',...
60 'Fontsize', fontsize,...
61 'Units', 'normalized', ...
62 'BackgroundColor', Gproperties.Gcol{3},...
63 'HorizontalAlignment', 'left',...
64 'Position',[Sleft Sbottom Swidth Sheight]);
65
66 Sleft = Sleft + Swidth + pmarg;
67 Swidth = 0.15;
68 pmh = uicontrol(panel,'Style','popupmenu',...
69 'String', tables,...
70 'Fontsize', fontsize,...
71 'Units', 'normalized', ...
72 'BackgroundColor', Gproperties.Gcol{3},...
73 'Value', 1,...
74 'Position',[Sleft Sbottom Swidth Sheight],...
75 'Tag', 'tableSelect');
76 if ~isempty(tableSelected) && tableSelected <= numel(tables)
77 set(pmh, 'Value', tableSelected);
78 end
79 set(pmh, 'Callback', {'repogui.cb_tableSelect', pmh, mainfig});
80
81 %--------------------------------------------------------------------------
82 %-- Draw Fields Selection list
83
84 % get fields
85 fields = repogui.getFields(mainfig, conn);
86 Sleft = pmarg;
87 Sheight = ALLHEIGHT;
88 Sbottom = Sbottom - pmarg - Sheight;
89 Swidth = 0.1;
90
91 sth = uicontrol(panel,'Style','text',...
92 'String', 'Select',...
93 'Fontsize', fontsize,...
94 'Units', 'normalized', ...
95 'BackgroundColor', Gproperties.Gcol{3},...
96 'HorizontalAlignment', 'left',...
97 'Position',[Sleft Sbottom Swidth Sheight]);
98
99 Sheight = 0.5;
100 Sleft = Sleft + pmarg + Swidth;
101 Sbottom = 1 - 2*pmarg - ALLHEIGHT - Sheight;
102 Swidth = 0.15;
103 lbh = uicontrol(panel,'Style','listbox',...
104 'String', fields,...
105 'Value',1,...
106 'Units', 'normalized', ...
107 'BackgroundColor', 'w',...
108 'Fontsize', fontsize,...
109 'Max', 1000,...
110 'Position',[Sleft Sbottom Swidth Sheight],...
111 'Tag', 'fieldsList');
112
113 set(lbh, 'Callback', {'repogui.cb_fieldSelect', pmh, mainfig});
114 if ~isempty(fselection) && tableSelected <= numel(fields)
115 set(lbh, 'Value', fselection);
116 end
117
118 %--------------------------------------------------------------------------
119 %-- Query display
120 listpos = get(lbh, 'Position');
121 Sleft = pmarg;
122 Sheight = ALLHEIGHT;
123 Sbottom = 0.1; %listpos(2) - 40 - Sheight;
124 Swidth = 0.1;
125
126 sth = uicontrol(panel,'Style','text',...
127 'String', 'Query:',...
128 'Units', 'normalized', ...
129 'Fontsize', fontsize,...
130 'Max', 5,...
131 'BackgroundColor', Gproperties.Gcol{3},...
132 'HorizontalAlignment', 'left',...
133 'Position', [Sleft Sbottom Swidth Sheight]);
134
135 Sleft = Sleft + Swidth + pmarg;
136 Swidth = 1-Sleft-pmarg;
137 Sheight = 0.2;
138 Sbottom = 0.06 + pmarg;
139 sth = uicontrol(panel,'Style','edit',...
140 'String', '',...
141 'Fontsize', fontsize,...
142 'Units', 'normalized', ...
143 'Max', 5,...
144 'BackgroundColor', 'w',...
145 'HorizontalAlignment', 'left',...
146 'Position', [Sleft Sbottom Swidth Sheight],...
147 'Tag', 'queryDisplayTxt');
148
149
150
151 %--------------------------------------------------------------------------
152 %-- Draw conditions
153
154 conditions = {'=', '<>', '<=', '>=', '<', '>', 'like', 'not like', 'is'};
155 compounds = {'AND', 'OR', 'XOR'};
156
157 pos = get(lbh, 'Position');
158 Sleft = 0.35;
159 Sheight = ALLHEIGHT;
160 Sbottom = 1-pmarg-Sheight;
161 Swidth = 0.1;
162
163 sth = uicontrol(panel,'Style','text',...
164 'String', 'Where',...
165 'Fontsize', fontsize,...
166 'Units', 'normalized', ...
167 'BackgroundColor', Gproperties.Gcol{3},...
168 'HorizontalAlignment', 'left',...
169 'Position',[Sleft Sbottom Swidth Sheight]);
170
171
172 pos = get(sth, 'Position');
173 Cheight = ALLHEIGHT;
174 STEP = pmarg;
175 for k=1:Nc
176 Cleft = pos(1);
177 Cbottom = pos(2) - pos(4) - pmarg - (k-1)*(Cheight+pmarg);
178 Cwidth = 0.1;
179 % Field Dropdown
180 pmh = uicontrol(panel,'Style','popupmenu',...
181 'String', fields,...
182 'Fontsize', fontsize,...
183 'Units', 'normalized', ...
184 'BackgroundColor', 'w', ...
185 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
186 'Tag', sprintf('c%02dField', k));
187 set(pmh, 'Callback', {'repogui.buildquery', mainfig});
188 if ~isempty(conds{k,1}) && conds{k,1} <= numel(fields)
189 set(pmh, 'Value', conds{k,1});
190 end
191 % Gproperties.Gcol(3),
192 % Condition Dropdown
193 Cleft = Cleft + Cwidth + STEP;
194 Cwidth = 0.1;
195 pmh = uicontrol(panel,'Style','popupmenu',...
196 'String', conditions,...
197 'Fontsize', fontsize,...
198 'Units', 'normalized', ...
199 'BackgroundColor', 'w',...
200 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
201 'Tag', sprintf('c%02dCondition', k));
202 set(pmh, 'Callback', {'repogui.buildquery', mainfig});
203 if ~isempty(conds{k,2})
204 set(pmh, 'Value', conds{k,2});
205 end
206
207 % Value txt box
208 Cleft = Cleft + Cwidth + STEP;
209 Cwidth = 0.2;
210 sth = uicontrol(panel,'Style','edit',...
211 'String','',...
212 'Fontsize', fontsize,...
213 'BackgroundColor', 'w',...
214 'Units', 'normalized', ...
215 'HorizontalAlignment', 'left',...
216 'Position',[Cleft Cbottom Cwidth Cheight],...
217 'Tag', sprintf('c%02dValue', k));
218 set(sth, 'Callback', {'repogui.buildquery', mainfig});
219 if ~isempty(conds{k,3})
220 set(sth, 'String', conds{k,3});
221 end
222
223 % Add compound statement
224 if k<Nc
225 Cleft = Cleft + Cwidth + STEP;
226 Cwidth = 0.1;
227 pmh = uicontrol(panel,'Style','popupmenu',...
228 'String', compounds,...
229 'Fontsize', fontsize,...
230 'Units', 'normalized', ...
231 'BackgroundColor', Gproperties.Gcol{3},...
232 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
233 'Tag', sprintf('c%02dCompound', k));
234 set(pmh, 'Callback', {'repogui.buildquery', mainfig});
235 if ~isempty(conds{k,4})
236 set(pmh, 'Value', conds{k,4});
237 end
238 end
239
240 end
241
242 %--------------------------------------------------------------------------
243 %-- add +/- buttons
244 k = Nc+1;
245 Bbottom = pos(2) - pos(4) - pmarg - (k-1)*(Cheight+pmarg);
246 Bleft = pos(1);
247 Bheight = ALLHEIGHT;
248 Bwidth = 0.03;
249 pbh = uicontrol(panel,'Style','pushbutton','Fontsize', fontsize, 'String','+',...
250 'Units', 'normalized', ...
251 'Position',[Bleft Bbottom Bwidth Bheight ],...
252 'Tag', 'condPlusBtn');
253 set(pbh, 'Callback', {'repogui.cb_condPlusBtn', pbh, panel, mainfig});
254 Bleft = pos(1) + Bwidth + pmarg;
255 pbh = uicontrol(panel,'Style','pushbutton','Fontsize', fontsize, 'String','-',...
256 'Units', 'normalized', ...
257 'Position',[Bleft Bbottom Bwidth Bheight ],...
258 'Tag', 'condSubtractBtn');
259 set(pbh, 'Callback', {'repogui.cb_condSubtractBtn', pbh, panel, mainfig});
260
261
262 %--------------------------------------------------------------------------
263 %-- order by
264 k = Nc + 2;
265 Sleft = pos(1);
266 Sheight = ALLHEIGHT;
267 Swidth = 0.07;
268 Sbottom = pos(2) - pos(4) - pmarg -(k-1)*(Cheight+pmarg);
269 sth = uicontrol(panel,'Style','text',...
270 'String', 'Order by',...
271 'Fontsize', fontsize,...
272 'Units', 'normalized', ...
273 'BackgroundColor', Gproperties.Gcol{3},...
274 'HorizontalAlignment', 'left',...
275 'Position',[Sleft Sbottom Swidth Sheight]);
276 % Gproperties.Gcol
277 % Field Dropdown
278 Sleft = pos(1) + pmarg + Swidth;
279 Swidth = 0.2;
280 pmh = uicontrol(panel,'Style','popupmenu',...
281 'String', fields,...
282 'Fontsize', fontsize,...
283 'Units', 'normalized', ...
284 'BackgroundColor', Gproperties.Gcol{3},...
285 'Value',1,'Position',[Sleft Sbottom Swidth Sheight],...
286 'Tag', 'fieldOrderBy');
287 set(pmh, 'Callback', {'repogui.buildquery', mainfig});
288 if ~isempty(forder)
289 set(pmh, 'Value', forder);
290 end
291
292 % Desc Dropdown
293 Sleft = Sleft + pmarg + Swidth;
294 Swidth = 0.2;
295 pmh = uicontrol(panel,'Style','popupmenu',...
296 'String', {'DESC', 'ASC'},...
297 'Fontsize', fontsize,...
298 'Units', 'normalized', ...
299 'BackgroundColor', Gproperties.Gcol{3},...
300 'Value',1,'Position',[Sleft Sbottom Swidth Sheight],...
301 'Tag', 'sortDir');
302 set(pmh, 'Callback', {'repogui.buildquery', mainfig});
303 if ~isempty(sort)
304 set(pmh, 'Value', sort);
305 end
306
307
308 %--------------------------------------------------------------------------
309 %-- Run query
310
311 Swidth = 0.2;
312 Sleft = 1-Swidth-pmarg;
313 Sheight = ALLHEIGHT;
314 Sbottom = pmarg;
315 uicontrol(panel,'Style','pushbutton','String','Execute query',...
316 'Units', 'normalized', ...
317 'Position',[Sleft Sbottom Swidth Sheight ],...
318 'Tag', 'refreshListBtn', ...
319 'Callback', {'repogui.cb_executeQuery', mainfig});
320
321 % Build query
322 repogui.buildquery(mainfig)
323
324 drawnow
325
326 end