Mercurial > hg > ltpda
comparison m-toolbox/classes/@workspaceBrowser/cb_query.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children | 317b5f447f3e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % CB_QUERY queries an LTPDA repository | |
2 % | |
3 % CALL: workspaceBrowser.cb_query | |
4 % | |
5 % M Hewitson 13-11-08 | |
6 % | |
7 % $Id: cb_query.m,v 1.12 2010/07/23 15:09:45 ingo Exp $ | |
8 % | |
9 function cb_query(varargin) | |
10 | |
11 wb = getappdata(0, 'WorkspaceBrowser'); | |
12 | |
13 % Get a connection from the repository manager | |
14 rm = LTPDARepositoryManager; | |
15 conn = rm.manager.selectConnection([]); | |
16 | |
17 if ~isempty(conn) | |
18 % Update | |
19 if ~isempty(rm.gui) | |
20 awtinvoke(rm.gui, 'reloadConnectionTable()'); | |
21 end | |
22 % Get submission info from the user | |
23 rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLmpipeline.repository.RepositoryConnection;Z', [], false, conn, false); | |
24 awtinvoke(rqd, 'setVisible', 'true'); | |
25 | |
26 hExec = handle(rqd.getExecuteBtn(),'callbackproperties'); | |
27 hExec.ActionPerformedCallback = @cb_executeQuery; | |
28 | |
29 hGuiCloses1 = handle(rqd, 'callbackproperties'); | |
30 hGuiCloses1.WindowClosedCallback = @cb_guiClosed1; | |
31 | |
32 end | |
33 | |
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
35 function cb_guiClosed1(varargin) | |
36 % Delete callback handles | |
37 if ishandle(hExec) | |
38 delete(hExec) | |
39 end | |
40 if ishandle(hGuiCloses1) | |
41 delete(hGuiCloses1) | |
42 end | |
43 | |
44 % Delete all variables | |
45 wb = []; | |
46 rm = []; | |
47 conn = []; | |
48 rqd = []; | |
49 end | |
50 | |
51 function cb_executeQuery(varargin) | |
52 | |
53 jQueryTextField = awtinvoke(rqd, 'getQueryTxtField()'); | |
54 jQuery = awtinvoke(jQueryTextField, 'getText()'); | |
55 | |
56 if ~(awtinvoke(conn, 'isConnected()')) | |
57 awtinvoke(conn, 'openConnection()'); | |
58 end | |
59 | |
60 if (awtinvoke(conn, 'isConnected()')) | |
61 | |
62 % lock connection | |
63 awtinvoke(conn, 'setLocked(Z)', true); | |
64 jStmt = awtinvoke(conn, 'createStatement()'); | |
65 | |
66 try | |
67 | |
68 jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery); | |
69 | |
70 % pass to query results table | |
71 qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false); | |
72 awtinvoke(qrt, 'setUsedConn(Lmpipeline.repository.RepositoryConnection;)', conn); | |
73 awtinvoke(qrt, 'setVisible(Z)', 'true'); | |
74 | |
75 hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties'); | |
76 hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable; | |
77 | |
78 hGuiCloses2 = handle(qrt, 'callbackproperties'); | |
79 hGuiCloses2.WindowClosedCallback = @cb_guiClosed2; | |
80 | |
81 catch err | |
82 fprintf(2, [err.message, '\n']); | |
83 end | |
84 awtinvoke(conn, 'setLocked(Z)', false); | |
85 | |
86 end | |
87 | |
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
89 function cb_guiClosed2(varargin) | |
90 % Delete callback handles | |
91 if ishandle(hRetrieve) | |
92 delete(hRetrieve) | |
93 end | |
94 if ishandle(hGuiCloses2) | |
95 delete(hGuiCloses2) | |
96 end | |
97 | |
98 % Delete all variables | |
99 jQueryTextField = []; | |
100 jQuery = []; | |
101 jStmt = []; | |
102 jResult = []; | |
103 qrt = []; | |
104 end | |
105 | |
106 function cb_retrieveObjectsFromTable(varargin) | |
107 | |
108 try | |
109 jResultTable = awtinvoke(qrt, 'getResultsTable()'); | |
110 jColNames = awtinvoke(qrt, 'getColNames()'); | |
111 jObj_id_col = awtinvoke(jColNames, 'indexOf(Ljava.lang.Object;)', 'obj_id'); | |
112 | |
113 if (jObj_id_col == -1) | |
114 msg = 'The results must contain the field ''obj_id'' in order to create constructor blocks.'; | |
115 utils.helper.errorDlg(msg, 'Fields error'); | |
116 jResultTable = []; | |
117 jColNames = []; | |
118 jObj_id_col = []; | |
119 error(msg); | |
120 end | |
121 | |
122 numberStr = ''; | |
123 jRows = double(awtinvoke(jResultTable, 'getSelectedRows()')); | |
124 | |
125 jModel = []; | |
126 if numel(jRows) >= 1 | |
127 jModel = awtinvoke(jResultTable, 'getModel()'); | |
128 numberStr = num2str(awtinvoke(jModel, 'getValueAt(II), ', jRows(1), jObj_id_col)); | |
129 end | |
130 | |
131 for kk = 2:numel(jRows) | |
132 jModel = awtinvoke(jResultTable, 'getModel()'); | |
133 | |
134 objIDstr = num2str( awtinvoke(jModel, 'getValueAt(II)', jRows(kk), jObj_id_col)); | |
135 numberStr = [numberStr, ' ', objIDstr]; | |
136 end | |
137 | |
138 rrd = awtcreate('mpipeline.repository.RepositoryRetrieveDialog', 'Ljava.awt.Frame;Z', [], true); | |
139 | |
140 jObjIDTextField = awtinvoke(rrd, 'getObjectIDsTextField()'); | |
141 awtinvoke(jObjIDTextField, 'setText(Ljava.lang.String;)', numberStr); | |
142 awtinvoke(rrd, 'setVisible(Z)', true); | |
143 | |
144 hGuiCloses3 = handle(rrd, 'callbackproperties'); | |
145 hGuiCloses3.WindowClosedCallback = @cb_guiClosed3; | |
146 | |
147 catch err | |
148 fprintf(2, [err.message, '\n']); | |
149 end | |
150 | |
151 function cb_guiClosed3(varargin) | |
152 % Delete callback handles | |
153 if ishandle(hGuiCloses3) | |
154 delete(hGuiCloses3) | |
155 end | |
156 | |
157 if ~rrd.isCancelled | |
158 workspaceBrowser.retrieveObjectsFromDialog(rrd, conn); | |
159 end | |
160 | |
161 % Delete all variables | |
162 jResultTable = []; | |
163 jColNames = []; | |
164 jObj_id_col = []; | |
165 jRows = []; | |
166 jModel = []; | |
167 rrd = []; | |
168 jObjIDTextField = []; | |
169 end | |
170 | |
171 end % cb_retrieveObjectsFromTable | |
172 | |
173 end % cb_executeQuery | |
174 | |
175 end % cb_query | |
176 | |
177 |