Révision 324
tmp/org.txm.cah.rcp/src/org/txm/cah/rcp/editors/CAHChartEditor.java (revision 324) | ||
---|---|---|
20 | 20 |
import org.txm.chartsengine.rcp.messages.SWTComponentsProviderMessages; |
21 | 21 |
import org.txm.core.preferences.TXMPreferences; |
22 | 22 |
import org.txm.core.results.ITXMResult; |
23 |
import org.txm.rcpapplication.IImageKeys;
|
|
24 |
import org.txm.rcpapplication.JobsTimer;
|
|
25 |
import org.txm.rcpapplication.commands.editor.CustomizableEditor;
|
|
26 |
import org.txm.rcpapplication.utils.JobHandler;
|
|
27 |
import org.txm.rcpapplication.views.QueriesView;
|
|
28 |
import org.txm.rcpapplication.views.corpora.CorporaView;
|
|
23 |
import org.txm.rcp.IImageKeys; |
|
24 |
import org.txm.rcp.JobsTimer; |
|
25 |
import org.txm.rcp.commands.editor.CustomizableEditor; |
|
26 |
import org.txm.rcp.utils.JobHandler; |
|
27 |
import org.txm.rcp.views.QueriesView; |
|
28 |
import org.txm.rcp.views.corpora.CorporaView; |
|
29 | 29 |
import org.txm.searchengine.cqp.corpus.Corpus; |
30 | 30 |
import org.txm.statsengine.r.rcp.views.RVariablesView; |
31 | 31 |
import org.txm.utils.logger.Log; |
... | ... | |
217 | 217 |
} |
218 | 218 |
catch (Exception e) { |
219 | 219 |
System.out.println(e.getLocalizedMessage()); |
220 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e);
|
|
220 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
221 | 221 |
Log.severe("Error while computing CAH: " + e.getLocalizedMessage()); |
222 | 222 |
} |
223 | 223 |
finally { |
tmp/org.txm.cah.rcp/src/org/txm/cah/rcp/handlers/ComputeCAH.java (revision 324) | ||
---|---|---|
54 | 54 |
import org.txm.lexicaltable.core.functions.LexicalTableFactory; |
55 | 55 |
import org.txm.lexicaltable.rcp.editors.LexicalTableDialog; |
56 | 56 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
57 |
import org.txm.rcpapplication.TxmPreferences;
|
|
58 |
import org.txm.rcpapplication.views.corpora.CorporaView;
|
|
57 |
import org.txm.rcp.TxmPreferences; |
|
58 |
import org.txm.rcp.views.corpora.CorporaView; |
|
59 | 59 |
import org.txm.searchengine.cqp.corpus.Partition; |
60 | 60 |
import org.txm.searchengine.cqp.corpus.Property; |
61 | 61 |
import org.txm.statsengine.core.StatException; |
tmp/org.txm.cah.rcp/plugin.xml (revision 324) | ||
---|---|---|
4 | 4 |
<extension |
5 | 5 |
point="org.eclipse.ui.commands"> |
6 | 6 |
<command |
7 |
categoryId="org.txm.rcpapplication.category.txm"
|
|
7 |
categoryId="org.txm.rcp.category.txm" |
|
8 | 8 |
defaultHandler="org.txm.cah.rcp.handlers.ComputeCAH" |
9 | 9 |
id="ComputeCAH" |
10 | 10 |
name="%command.name"> |
... | ... | |
14 | 14 |
point="org.eclipse.ui.menus"> |
15 | 15 |
<menuContribution |
16 | 16 |
allPopups="false" |
17 |
locationURI="toolbar:org.txm.rcpapplication.toolbartools">
|
|
17 |
locationURI="toolbar:org.txm.rcp.toolbartools"> |
|
18 | 18 |
<command |
19 | 19 |
commandId="ComputeCAH" |
20 | 20 |
icon="icons/cah.png" |
... | ... | |
38 | 38 |
</menuContribution> |
39 | 39 |
<menuContribution |
40 | 40 |
allPopups="false" |
41 |
locationURI="popup:org.txm.rcpapplication.views.CorporaView">
|
|
41 |
locationURI="popup:org.txm.rcp.views.CorporaView"> |
|
42 | 42 |
<command |
43 | 43 |
commandId="ComputeCAH" |
44 | 44 |
icon="icons/cah.png" |
... | ... | |
105 | 105 |
<extension |
106 | 106 |
point="org.eclipse.ui.preferencePages"> |
107 | 107 |
<page |
108 |
category="org.txm.rcpapplication.preferences.UserPreferencePage"
|
|
108 |
category="org.txm.rcp.preferences.UserPreferencePage" |
|
109 | 109 |
class="org.txm.cah.rcp.preferences.CAHPreferencePage" |
110 | 110 |
id="org.txm.cah.rcp.preferences.CAHPreferencePage" |
111 | 111 |
name="%page.name"> |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/AdapterFactory.java (revision 324) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.Comparator; |
|
33 |
import java.util.HashMap; |
|
34 |
import java.util.List; |
|
35 |
|
|
36 |
import org.eclipse.core.runtime.IAdapterFactory; |
|
37 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
38 |
import org.eclipse.osgi.util.NLS; |
|
39 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
40 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
41 |
import org.txm.core.results.ITXMResult; |
|
42 |
import org.txm.functions.concordances.Concordance; |
|
43 |
import org.txm.functions.internal.InternalView; |
|
44 |
import org.txm.functions.intertextualdistance.InterTextDistance; |
|
45 |
//import org.txm.functions.queryindex.QueryIndex; |
|
46 |
import org.txm.functions.referencer.Referencer; |
|
47 |
import org.txm.lexicon.core.corpusengine.cqp.Lexicon; |
|
48 |
import org.txm.rcp.adapters.TXMResultAdapter; |
|
49 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
50 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
51 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
52 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
53 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
54 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
55 |
|
|
56 |
// TODO: Auto-generated Javadoc |
|
57 |
/** |
|
58 |
* A factory for creating Adapter objects. |
|
59 |
* |
|
60 |
* @author jmague |
|
61 |
*/ |
|
62 |
public class AdapterFactory implements IAdapterFactory { |
|
63 |
|
|
64 |
private static boolean firstCorpusDiag = true; |
|
65 |
|
|
66 |
private HashMap<Class, IWorkbenchAdapter> externalAdapters = new HashMap<Class, IWorkbenchAdapter>(); |
|
67 |
|
|
68 |
/** The corpus manager adapter. */ |
|
69 |
private IWorkbenchAdapter corpusManagerAdapter = new IWorkbenchAdapter() { |
|
70 |
|
|
71 |
@Override |
|
72 |
public Object[] getChildren(Object corpusManager) { |
|
73 |
Object[] children = null; |
|
74 |
try { |
|
75 |
List<MainCorpus> corpora = new ArrayList<MainCorpus>(CorpusManager.getCorpusManager().getCorpora()); |
|
76 |
Collections.sort(corpora, new Comparator<MainCorpus>() { |
|
77 |
@Override |
|
78 |
public int compare(MainCorpus o1, MainCorpus o2) { |
|
79 |
return o1.getName().compareTo(o2.getName()); |
|
80 |
} |
|
81 |
}); |
|
82 |
|
|
83 |
// check if each corpus has a Base |
|
84 |
if (firstCorpusDiag) { |
|
85 |
firstCorpusDiag = false; |
|
86 |
for (MainCorpus corpus : corpora) { |
|
87 |
if (corpus.getBase() == null) |
|
88 |
System.out.println(NLS.bind(Messages.AdapterFactory_0, corpus)); |
|
89 |
} |
|
90 |
} |
|
91 |
children = corpora.toArray(); |
|
92 |
|
|
93 |
} catch (CqiClientException e) { |
|
94 |
return new Object[0]; |
|
95 |
} |
|
96 |
return children; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public ImageDescriptor getImageDescriptor(Object corpusManager) { |
|
101 |
// TODO Auto-generated method stub |
|
102 |
return null; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public String getLabel(Object corpusManager) { |
|
107 |
// TODO Auto-generated method stub |
|
108 |
return null; |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public Object getParent(Object corpusManager) { |
|
113 |
return null; |
|
114 |
} |
|
115 |
}; |
|
116 |
|
|
117 |
/** The corpus adapter. */ |
|
118 |
private IWorkbenchAdapter corpusAdapter = new IWorkbenchAdapter() { |
|
119 |
|
|
120 |
@Override |
|
121 |
public Object[] getChildren(Object corpus) { |
|
122 |
//List<Subcorpus> subcorpora = ((Corpus) corpus).getSubcorpora(); |
|
123 |
ArrayList<ITXMResult> results = ((Corpus) corpus).getResults(true); |
|
124 |
for (int i = 0; i < results.size(); i++) { |
|
125 |
Object result = results.get(i); |
|
126 |
|
|
127 |
// remove "id" Lexicon from displayed results |
|
128 |
if (result instanceof Lexicon) { |
|
129 |
Lexicon lex = (Lexicon) result; |
|
130 |
if (lex.getProperty().getName().equals("id")) { //$NON-NLS-1$ |
|
131 |
results.remove(result); |
|
132 |
i--; |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
List<Object> children = new ArrayList<Object>(); |
|
137 |
//children.addAll(subcorpora); |
|
138 |
children.addAll(results); |
|
139 |
return children.toArray(); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
144 |
ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.CORPUS); |
|
145 |
return imageDescriptor; |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public String getLabel(Object corpus) { |
|
150 |
if (corpus instanceof MainCorpus) { |
|
151 |
return ((MainCorpus) corpus).getNameForCorporaView(); |
|
152 |
} else { |
|
153 |
return ((Corpus) corpus).getName(); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public Object getParent(Object corpus) { |
|
159 |
if (corpus instanceof Subcorpus) |
|
160 |
return ((Subcorpus) corpus).getMotherSubcorpus(); |
|
161 |
else |
|
162 |
return CorpusManager.getCorpusManager(); |
|
163 |
} |
|
164 |
}; |
|
165 |
|
|
166 |
/** The partition adapter. */ |
|
167 |
private IWorkbenchAdapter partitionAdapter = new IWorkbenchAdapter() { |
|
168 |
|
|
169 |
@Override |
|
170 |
public Object[] getChildren(Object partition) { |
|
171 |
ArrayList<ITXMResult> children = ((Partition) partition).getResults(); |
|
172 |
// System.out.println("PARTITION RESULTS "+children); |
|
173 |
return children.toArray(); |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
178 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
179 |
Application.PLUGIN_ID, IImageKeys.PARTITION); |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public String getLabel(Object partition) { |
|
184 |
return ((Partition) partition).getSimpleName(); //$NON-NLS-1$ |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public Object getParent(Object partition) { |
|
189 |
return ((Partition) partition).getCorpus(); |
|
190 |
} |
|
191 |
}; |
|
192 |
|
|
193 |
// /** The partition adapter. */ |
|
194 |
// private IWorkbenchAdapter queryIndexAdapter = new IWorkbenchAdapter() { |
|
195 |
// @Override |
|
196 |
// public Object[] getChildren(Object obj) { |
|
197 |
// return new Object[0]; |
|
198 |
// } |
|
199 |
// |
|
200 |
// @Override |
|
201 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
202 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
203 |
// Application.PLUGIN_ID, IImageKeys.QUERYINDEX); |
|
204 |
// } |
|
205 |
// |
|
206 |
// @Override |
|
207 |
// public String getLabel(Object qindex) { |
|
208 |
// return "" + ((QueryIndex) qindex).getName(); //$NON-NLS-1$ |
|
209 |
// } |
|
210 |
// |
|
211 |
// @Override |
|
212 |
// public Object getParent(Object qindex) { |
|
213 |
// return ((QueryIndex) qindex).getParent(); |
|
214 |
// } |
|
215 |
// }; |
|
216 |
|
|
217 |
// /** The lexical table adapter. */ |
|
218 |
// private IWorkbenchAdapter lexicalTableAdapter = new IWorkbenchAdapter() { |
|
219 |
// @Override |
|
220 |
// public Object[] getChildren(Object lexicaltable) { |
|
221 |
// // List<Object> children = ((LexicalTable) |
|
222 |
// // lexicaltable).getResults(); |
|
223 |
// // System.out.println("PARTITION RESULTS "+children); |
|
224 |
// return ((LexicalTable)lexicaltable).getResults().toArray(); |
|
225 |
// } |
|
226 |
// |
|
227 |
// @Override |
|
228 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
229 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
230 |
// Application.PLUGIN_ID, IImageKeys.LEXICALTABLE); |
|
231 |
// } |
|
232 |
// |
|
233 |
// @Override |
|
234 |
// public String getLabel(Object lexicaltable) { |
|
235 |
// return "" + ((LexicalTable) lexicaltable).getProperty(); //$NON-NLS-1$ |
|
236 |
// } |
|
237 |
// |
|
238 |
// @Override |
|
239 |
// public Object getParent(Object lexicaltable) { |
|
240 |
// return ((LexicalTable) lexicaltable).getPartition(); |
|
241 |
// } |
|
242 |
// }; |
|
243 |
|
|
244 |
// /** The Progression adapter. */ |
|
245 |
// private IWorkbenchAdapter ProgressionAdapter = new IWorkbenchAdapter() { |
|
246 |
// @Override |
|
247 |
// public Object[] getChildren(Object progression) { |
|
248 |
// return new Object[0]; |
|
249 |
// } |
|
250 |
// |
|
251 |
// @Override |
|
252 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
253 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
254 |
// Application.PLUGIN_ID, IImageKeys.ACTION_PROGRESSION); |
|
255 |
// } |
|
256 |
// |
|
257 |
// @Override |
|
258 |
// public String getLabel(Object progression) { |
|
259 |
// return ((Progression) progression).getDetails(); |
|
260 |
// } |
|
261 |
// |
|
262 |
// @Override |
|
263 |
// public Object getParent(Object progression) { |
|
264 |
// return ((Progression) progression).getCorpus(); |
|
265 |
// } |
|
266 |
// }; |
|
267 |
|
|
268 |
/** The Progression adapter. */ |
|
269 |
private IWorkbenchAdapter interTextDistAdapter = new IWorkbenchAdapter() { |
|
270 |
@Override |
|
271 |
public Object[] getChildren(Object dist) { |
|
272 |
return new Object[0]; |
|
273 |
} |
|
274 |
|
|
275 |
@Override |
|
276 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
277 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
278 |
Application.PLUGIN_ID, IImageKeys.ACTION_INTERTEXTDIST); |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public String getLabel(Object dist) { |
|
283 |
return ((InterTextDistance) dist).getLabel(); |
|
284 |
} |
|
285 |
|
|
286 |
@Override |
|
287 |
public Object getParent(Object dist) { |
|
288 |
return ((InterTextDistance) dist).getTable(); |
|
289 |
} |
|
290 |
}; |
|
291 |
|
|
292 |
/** The InternalView adapter. */ |
|
293 |
private IWorkbenchAdapter InternalViewAdapter = new IWorkbenchAdapter() { |
|
294 |
@Override |
|
295 |
public Object[] getChildren(Object internal) { |
|
296 |
return new Object[0]; |
|
297 |
} |
|
298 |
|
|
299 |
@Override |
|
300 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
301 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
302 |
Application.PLUGIN_ID, IImageKeys.ACTION_INTERNALVIEW); |
|
303 |
} |
|
304 |
|
|
305 |
@Override |
|
306 |
public String getLabel(Object internalView) { |
|
307 |
return ((InternalView) internalView).getDetails(); |
|
308 |
} |
|
309 |
|
|
310 |
@Override |
|
311 |
public Object getParent(Object internalView) { |
|
312 |
return ((InternalView) internalView).getCorpus(); |
|
313 |
} |
|
314 |
}; |
|
315 |
|
|
316 |
// /** The CAH adapter. */ |
|
317 |
// private IWorkbenchAdapter CAHAdapter = new IWorkbenchAdapter() { |
|
318 |
// @Override |
|
319 |
// public Object[] getChildren(Object cah) { |
|
320 |
// return new Object[0]; |
|
321 |
// } |
|
322 |
// |
|
323 |
// @Override |
|
324 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
325 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
326 |
// Application.PLUGIN_ID, IImageKeys.ACTION_CAH); |
|
327 |
// } |
|
328 |
// |
|
329 |
// @Override |
|
330 |
// public String getLabel(Object cah) { |
|
331 |
// return "" + ((CAH) cah).getName(); //$NON-NLS-1$ |
|
332 |
// } |
|
333 |
// |
|
334 |
// @Override |
|
335 |
// public Object getParent(Object cah) { |
|
336 |
// return ((CAH) cah).getParent(); |
|
337 |
// } |
|
338 |
// }; |
|
339 |
// |
|
340 |
// /** The Cooccurrence adapter. */ |
|
341 |
// private IWorkbenchAdapter CooccurrenceAdapter = new IWorkbenchAdapter() { |
|
342 |
// |
|
343 |
// @Override |
|
344 |
// public Object[] getChildren(Object cooccurrence) { |
|
345 |
// return new Object[0]; |
|
346 |
// } |
|
347 |
// |
|
348 |
// @Override |
|
349 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
350 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
351 |
// Application.PLUGIN_ID, IImageKeys.ACTION_COOCCURRENCE); |
|
352 |
// } |
|
353 |
// |
|
354 |
// @Override |
|
355 |
// public String getLabel(Object cooccurrence) { |
|
356 |
// return ((Cooccurrence) cooccurrence).getName(); |
|
357 |
// } |
|
358 |
// |
|
359 |
// @Override |
|
360 |
// public Object getParent(Object cooccurrence) { |
|
361 |
// return ((Cooccurrence) cooccurrence).getCorpus(); |
|
362 |
// } |
|
363 |
// }; |
|
364 |
|
|
365 |
// /** The specificities result adapter. */ |
|
366 |
// private IWorkbenchAdapter specificitiesResultAdapter = new IWorkbenchAdapter() { |
|
367 |
// |
|
368 |
// @Override |
|
369 |
// public Object[] getChildren(Object o) { |
|
370 |
// return new Object[0]; |
|
371 |
// } |
|
372 |
// |
|
373 |
// @Override |
|
374 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
375 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
376 |
// Application.PLUGIN_ID, IImageKeys.ACTION_SPECIFICITIES); |
|
377 |
// } |
|
378 |
// |
|
379 |
// @Override |
|
380 |
// public String getLabel(Object o) { |
|
381 |
// return ((SpecificitesResult) o).getName(); |
|
382 |
// } |
|
383 |
// |
|
384 |
// @Override |
|
385 |
// public Object getParent(Object o) { |
|
386 |
// return ((SpecificitesResult) o).getParent(); |
|
387 |
// } |
|
388 |
// |
|
389 |
// }; |
|
390 |
|
|
391 |
/** The referencer adapter. */ |
|
392 |
private IWorkbenchAdapter referencerAdapter = new IWorkbenchAdapter() { |
|
393 |
@Override |
|
394 |
public Object[] getChildren(Object o) { |
|
395 |
return new Object[0]; |
|
396 |
} |
|
397 |
|
|
398 |
@Override |
|
399 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
400 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
401 |
Application.PLUGIN_ID, IImageKeys.ACTION_REFERENCER); |
|
402 |
} |
|
403 |
|
|
404 |
@Override |
|
405 |
public String getLabel(Object o) { |
|
406 |
return ((Referencer) o).getName(); |
|
407 |
} |
|
408 |
|
|
409 |
@Override |
|
410 |
public Object getParent(Object o) { |
|
411 |
return ((Referencer) o).getParent(); |
|
412 |
} |
|
413 |
}; |
|
414 |
|
|
415 |
/** The concordance adapter. */ |
|
416 |
private IWorkbenchAdapter concordanceAdapter = new IWorkbenchAdapter() { |
|
417 |
@Override |
|
418 |
public Object[] getChildren(Object o) { |
|
419 |
return new Object[0]; |
|
420 |
} |
|
421 |
|
|
422 |
@Override |
|
423 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
424 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
425 |
Application.PLUGIN_ID, IImageKeys.ACTION_CONCORDANCES); |
|
426 |
} |
|
427 |
|
|
428 |
@Override |
|
429 |
public String getLabel(Object o) { |
|
430 |
return ((Concordance) o).getQuery().getQueryString(); |
|
431 |
} |
|
432 |
|
|
433 |
@Override |
|
434 |
public Object getParent(Object o) { |
|
435 |
return ((Concordance) o).getCorpus(); |
|
436 |
} |
|
437 |
}; |
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
/** The Lexicon adapter. */ |
|
442 |
private IWorkbenchAdapter LexiconAdapter = new TXMResultAdapter() { |
|
443 |
@Override |
|
444 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
445 |
return AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.ACTION_FREQUENCY_LIST); |
|
446 |
} |
|
447 |
}; |
|
448 |
|
|
449 |
// /** The Index adapter. */ |
|
450 |
// private IWorkbenchAdapter IndexAdapter = new IWorkbenchAdapter() { |
|
451 |
// |
|
452 |
// @Override |
|
453 |
// public Object[] getChildren(Object o) { |
|
454 |
// return ((Index)o).getResults().toArray(); |
|
455 |
// } |
|
456 |
// |
|
457 |
// @Override |
|
458 |
// public ImageDescriptor getImageDescriptor(Object object) { |
|
459 |
// return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
460 |
// Application.PLUGIN_ID, IImageKeys.ACTION_INDEX); |
|
461 |
// } |
|
462 |
// |
|
463 |
// @Override |
|
464 |
// public String getLabel(Object o) { |
|
465 |
// return ((Index) o).getName(); |
|
466 |
// } |
|
467 |
// |
|
468 |
// @Override |
|
469 |
// public Object getParent(Object o) { |
|
470 |
// return ((Index) o).getParent(); |
|
471 |
// } |
|
472 |
// }; |
|
473 |
|
|
474 |
/** |
|
475 |
* Gets the adapter. |
|
476 |
* |
|
477 |
* @param adaptableObject the adaptable object |
|
478 |
* @param adapterType the adapter type |
|
479 |
* @return the adapter |
|
480 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, |
|
481 |
* java.lang.Class) |
|
482 |
*/ |
|
483 |
@Override |
|
484 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
|
485 |
if (adapterType == IWorkbenchAdapter.class |
|
486 |
&& adaptableObject instanceof CorpusManager) |
|
487 |
return corpusManagerAdapter; |
|
488 |
if (adapterType == IWorkbenchAdapter.class |
|
489 |
&& adaptableObject instanceof Corpus) |
|
490 |
return corpusAdapter; |
|
491 |
if (adapterType == IWorkbenchAdapter.class |
|
492 |
&& adaptableObject instanceof Partition) |
|
493 |
return partitionAdapter; |
|
494 |
// if (adapterType == IWorkbenchAdapter.class |
|
495 |
// && adaptableObject instanceof SpecificitesResult) |
|
496 |
// return specificitiesResultAdapter; |
|
497 |
if (adapterType == IWorkbenchAdapter.class |
|
498 |
&& adaptableObject instanceof Concordance) |
|
499 |
return concordanceAdapter; |
|
500 |
if (adapterType == IWorkbenchAdapter.class |
|
501 |
&& adaptableObject instanceof Referencer) |
|
502 |
return referencerAdapter; |
|
503 |
if (adapterType == IWorkbenchAdapter.class |
|
504 |
&& adaptableObject instanceof Lexicon) |
|
505 |
return LexiconAdapter; |
|
506 |
// if (adapterType == IWorkbenchAdapter.class |
|
507 |
// && adaptableObject instanceof Index) |
|
508 |
// return IndexAdapter; |
|
509 |
// if (adapterType == IWorkbenchAdapter.class |
|
510 |
// && adaptableObject instanceof Progression) |
|
511 |
// return ProgressionAdapter; |
|
512 |
// if (adapterType == IWorkbenchAdapter.class |
|
513 |
// && adaptableObject instanceof Cooccurrence) |
|
514 |
// return CooccurrenceAdapter; |
|
515 |
// if (adapterType == IWorkbenchAdapter.class |
|
516 |
// && adaptableObject instanceof LexicalTable) |
|
517 |
// return lexicalTableAdapter; |
|
518 |
// if (adapterType == IWorkbenchAdapter.class |
|
519 |
// && adaptableObject instanceof CAH) |
|
520 |
// return CAHAdapter; |
|
521 |
if (adapterType == IWorkbenchAdapter.class |
|
522 |
&& adaptableObject instanceof InternalView) |
|
523 |
return InternalViewAdapter; |
|
524 |
if (adapterType == IWorkbenchAdapter.class |
|
525 |
&& adaptableObject instanceof InterTextDistance) |
|
526 |
return interTextDistAdapter; |
|
527 |
|
|
528 |
//check adapters from plugins |
|
529 |
if (externalAdapters.containsKey(adaptableObject.getClass())) { |
|
530 |
return externalAdapters.get(adaptableObject.getClass()); |
|
531 |
} |
|
532 |
return null; |
|
533 |
} |
|
534 |
|
|
535 |
/** |
|
536 |
* Gets the adapter list. |
|
537 |
* |
|
538 |
* @return the adapter list |
|
539 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() |
|
540 |
*/ |
|
541 |
@Override |
|
542 |
@SuppressWarnings("unchecked") //$NON-NLS-1$ |
|
543 |
public Class[] getAdapterList() { |
|
544 |
return new Class[] { IWorkbenchAdapter.class }; |
|
545 |
} |
|
546 |
|
|
547 |
} |
|
0 | 548 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/ExpertEnabled.java (revision 324) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.eclipse.core.expressions.PropertyTester; |
4 | 4 |
import org.txm.core.preferences.TBXPreferences; |
5 |
import org.txm.rcpapplication.TxmPreferences;
|
|
6 |
import org.txm.rcpapplication.preferences.AdvancePreferencePage;
|
|
5 |
import org.txm.rcp.TxmPreferences; |
|
6 |
import org.txm.rcp.preferences.AdvancePreferencePage; |
|
7 | 7 |
|
8 | 8 |
public class ExpertEnabled extends PropertyTester { |
9 | 9 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/BasesView.java (revision 324) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.views; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.Map; |
|
33 |
|
|
34 |
import org.eclipse.jface.action.MenuManager; |
|
35 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
36 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
37 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
38 |
import org.eclipse.jface.viewers.ISelection; |
|
39 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
40 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
41 |
import org.eclipse.jface.viewers.LabelProvider; |
|
42 |
import org.eclipse.jface.viewers.TreeSelection; |
|
43 |
import org.eclipse.jface.viewers.TreeViewer; |
|
44 |
import org.eclipse.jface.viewers.Viewer; |
|
45 |
import org.eclipse.swt.SWT; |
|
46 |
import org.eclipse.swt.events.KeyEvent; |
|
47 |
import org.eclipse.swt.events.KeyListener; |
|
48 |
import org.eclipse.swt.graphics.Image; |
|
49 |
import org.eclipse.swt.widgets.Composite; |
|
50 |
import org.eclipse.swt.widgets.Menu; |
|
51 |
import org.eclipse.ui.PlatformUI; |
|
52 |
import org.eclipse.ui.part.ViewPart; |
|
53 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
54 |
import org.txm.Toolbox; |
|
55 |
import org.txm.objects.Base; |
|
56 |
import org.txm.objects.Edition; |
|
57 |
import org.txm.objects.Page; |
|
58 |
import org.txm.objects.Project; |
|
59 |
import org.txm.objects.Script; |
|
60 |
import org.txm.objects.Text; |
|
61 |
import org.txm.objects.TxmObject; |
|
62 |
import org.txm.objects.Workspace; |
|
63 |
import org.txm.rcp.Application; |
|
64 |
import org.txm.rcp.IImageKeys; |
|
65 |
import org.txm.rcp.commands.EditFile; |
|
66 |
import org.txm.rcp.commands.OpenBrowser; |
|
67 |
import org.txm.rcp.commands.base.DeleteObject; |
|
68 |
import org.txm.rcp.editors.TXMBrowser; |
|
69 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
70 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
71 |
|
|
72 |
// TODO: Auto-generated Javadoc |
|
73 |
/** |
|
74 |
* display the hierarchy of the workspace Projects, Bases, Texts, Edition and |
|
75 |
* Pages. @ author mdecorde |
|
76 |
* |
|
77 |
*/ |
|
78 |
public class BasesView extends ViewPart { |
|
79 |
|
|
80 |
/** The tv. */ |
|
81 |
TreeViewer tv; |
|
82 |
|
|
83 |
/** The ID. */ |
|
84 |
public static String ID = "org.txm.rcp.views.BasesView"; //$NON-NLS-1$ |
|
85 |
|
|
86 |
/** |
|
87 |
* Instantiates a new bases view. |
|
88 |
*/ |
|
89 |
public BasesView() { |
|
90 |
// System.out.println(Messages.ObjectExplorer_9); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Refresh. |
|
95 |
*/ |
|
96 |
public static void refresh() { |
|
97 |
BasesView baseView = (BasesView) PlatformUI.getWorkbench() |
|
98 |
.getActiveWorkbenchWindow().getActivePage().findView( |
|
99 |
BasesView.ID); |
|
100 |
if (baseView != null) |
|
101 |
baseView.tv.refresh(); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Reload. |
|
106 |
*/ |
|
107 |
public static void reload() { |
|
108 |
BasesView baseView = (BasesView) PlatformUI.getWorkbench() |
|
109 |
.getActiveWorkbenchWindow().getActivePage().findView( |
|
110 |
BasesView.ID); |
|
111 |
if (baseView != null) |
|
112 |
baseView._reload(); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* _reload. |
|
117 |
*/ |
|
118 |
public void _reload() { |
|
119 |
tv.setContentProvider(new TxmObjectTreeProvider()); |
|
120 |
tv.setLabelProvider(new TxmObjectLabelProvider()); |
|
121 |
tv.setInput(Toolbox.workspace); |
|
122 |
refresh(); |
|
123 |
} |
|
124 |
|
|
125 |
/* (non-Javadoc) |
|
126 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
127 |
*/ |
|
128 |
@Override |
|
129 |
public void createPartControl(Composite parent) { |
|
130 |
// System.out.println(Messages.ObjectExplorer_9); |
|
131 |
tv = new TreeViewer(parent); |
|
132 |
tv.setContentProvider(new TxmObjectTreeProvider()); |
|
133 |
tv.setLabelProvider(new TxmObjectLabelProvider()); |
|
134 |
tv.setInput(Toolbox.workspace); |
|
135 |
|
|
136 |
tv.addDoubleClickListener(new IDoubleClickListener() { |
|
137 |
|
|
138 |
@Override |
|
139 |
public void doubleClick(DoubleClickEvent event) { |
|
140 |
TreeSelection selection = (TreeSelection) tv.getSelection(); |
|
141 |
if (selection.getFirstElement() instanceof Corpus) { |
|
142 |
File selectedItem = ((Corpus) selection.getFirstElement()) |
|
143 |
.getFirstText().getSource(); |
|
144 |
EditFile.openfile(selectedItem.getAbsolutePath()); |
|
145 |
} else if (selection.getFirstElement() instanceof Text) { |
|
146 |
File selectedItem = ((Text) selection.getFirstElement()) |
|
147 |
.getSource(); |
|
148 |
EditFile.openfile(selectedItem.getAbsolutePath()); |
|
149 |
} else if (selection.getFirstElement() instanceof Edition) { |
|
150 |
Edition edition = ((Edition) selection.getFirstElement()); |
|
151 |
Page firstpage = edition.getFirstPage(); |
|
152 |
TXMBrowser editor = OpenBrowser.openEdition(firstpage |
|
153 |
.getFile().getAbsolutePath(), edition.getName()); |
|
154 |
editor.showPage(firstpage); |
|
155 |
} else if (selection.getFirstElement() instanceof Page) { |
|
156 |
Page page = ((Page) selection.getFirstElement()); |
|
157 |
TXMBrowser editor = OpenBrowser.openEdition(page.getFile() |
|
158 |
.getAbsolutePath()); |
|
159 |
editor.showPage(page); |
|
160 |
} |
|
161 |
} |
|
162 |
}); |
|
163 |
|
|
164 |
tv.getTree().addKeyListener(new KeyListener() { |
|
165 |
|
|
166 |
@Override |
|
167 |
public void keyReleased(KeyEvent e) { |
|
168 |
if (e.keyCode == SWT.DEL) { |
|
169 |
ISelection sel = tv.getSelection(); |
|
170 |
if (sel instanceof IStructuredSelection) { |
|
171 |
if (!DeleteObject.askContinueToDelete((IStructuredSelection)sel)) return; |
|
172 |
DeleteObject.delete(sel); |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public void keyPressed(KeyEvent e) { |
|
179 |
} |
|
180 |
}); |
|
181 |
|
|
182 |
MenuManager menuManager = new MenuManager(); |
|
183 |
Menu menu = menuManager.createContextMenu(tv.getTree()); |
|
184 |
|
|
185 |
// Set the MenuManager |
|
186 |
tv.getTree().setMenu(menu); |
|
187 |
getSite().registerContextMenu(menuManager, tv); |
|
188 |
// Make the selection available |
|
189 |
getSite().setSelectionProvider(tv); |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
/* (non-Javadoc) |
|
194 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
195 |
*/ |
|
196 |
@Override |
|
197 |
public void setFocus() { |
|
198 |
// TODO Auto-generated method stub |
|
199 |
|
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* The Class TxmObjectLabelProvider. |
|
204 |
*/ |
|
205 |
public class TxmObjectLabelProvider extends LabelProvider { |
|
206 |
|
|
207 |
/** The image table. */ |
|
208 |
private Map<ImageDescriptor, Image> imageTable = new HashMap<ImageDescriptor, Image>(); |
|
209 |
|
|
210 |
/* (non-Javadoc) |
|
211 |
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
|
212 |
*/ |
|
213 |
@Override |
|
214 |
public String getText(Object Element) { |
|
215 |
return ((TxmObject) Element).getName(); |
|
216 |
} |
|
217 |
|
|
218 |
/* (non-Javadoc) |
|
219 |
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) |
|
220 |
*/ |
|
221 |
@Override |
|
222 |
public final Image getImage(Object element) { |
|
223 |
ImageDescriptor imageDescriptor = AbstractUIPlugin |
|
224 |
.imageDescriptorFromPlugin(Application.PLUGIN_ID, |
|
225 |
IImageKeys.FILE); |
|
226 |
if (element instanceof Project) |
|
227 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
228 |
Application.PLUGIN_ID, IImageKeys.PROJECT); |
|
229 |
else if (element instanceof Base) |
|
230 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
231 |
Application.PLUGIN_ID, IImageKeys.BASE); |
|
232 |
else if (element instanceof MainCorpus) |
|
233 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
234 |
Application.PLUGIN_ID, IImageKeys.CORPUS); |
|
235 |
else if (element instanceof Text) |
|
236 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
237 |
Application.PLUGIN_ID, IImageKeys.TEXT); |
|
238 |
else if (element instanceof Edition) |
|
239 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
240 |
Application.PLUGIN_ID, IImageKeys.EDITION); |
|
241 |
else if (element instanceof Page) |
|
242 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
243 |
Application.PLUGIN_ID, IImageKeys.FILE); |
|
244 |
else if (element instanceof Script) |
|
245 |
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( |
|
246 |
Application.PLUGIN_ID, IImageKeys.SCRIPT); |
|
247 |
|
|
248 |
Image image = imageTable.get(imageDescriptor); |
|
249 |
if (image == null) { |
|
250 |
image = imageDescriptor.createImage(); |
|
251 |
imageTable.put(imageDescriptor, image); |
|
252 |
} |
|
253 |
return image; |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* The Class TxmObjectTreeProvider. |
|
259 |
*/ |
|
260 |
public class TxmObjectTreeProvider implements ITreeContentProvider { |
|
261 |
|
|
262 |
/* (non-Javadoc) |
|
263 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
264 |
*/ |
|
265 |
@Override |
|
266 |
public Object[] getChildren(Object element) { |
|
267 |
if (element instanceof Workspace) { |
|
268 |
return ((Workspace) element).getProjects().toArray(); |
|
269 |
} else if (element instanceof Project) { |
|
270 |
return ((Project) element).getBases().toArray(); |
|
271 |
} else if (element instanceof Base) { |
|
272 |
return ((Base) element).getCorpora().values().toArray(); |
|
273 |
} else if (element instanceof MainCorpus) { |
|
274 |
return ((Corpus) element).getTexts().toArray(); |
|
275 |
} else if (element instanceof Text) { |
|
276 |
return ((Text) element).getEditions().toArray(); |
|
277 |
} else if (element instanceof Edition) { |
|
278 |
return ((Edition) element).getPages().toArray(); |
|
279 |
} else if (element instanceof Script) { |
|
280 |
return null; |
|
281 |
} |
|
282 |
return null; |
|
283 |
} |
|
284 |
|
|
285 |
/* (non-Javadoc) |
|
286 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
287 |
*/ |
|
288 |
@Override |
|
289 |
public Object getParent(Object element) { |
|
290 |
if (element instanceof Workspace) { |
|
291 |
return null; |
|
292 |
} else if (element instanceof Project) { |
|
293 |
return ((Project) element).getWorkspace(); |
|
294 |
} else if (element instanceof Base) { |
|
295 |
return ((Base) element).getProject(); |
|
296 |
} else if (element instanceof MainCorpus) { |
|
297 |
return ((MainCorpus) element).getBase(); |
|
298 |
} else if (element instanceof Text) { |
|
299 |
return ((Text) element).getCorpus(); |
|
300 |
} else if (element instanceof Edition) { |
|
301 |
return ((Edition) element).getText(); |
|
302 |
} else if (element instanceof Page) { |
|
303 |
return ((Page) element).getEdition(); |
|
304 |
} else if (element instanceof Script) { |
|
305 |
return ((Text) element).getCorpus(); |
|
306 |
} |
|
307 |
return null; |
|
308 |
} |
|
309 |
|
|
310 |
/* (non-Javadoc) |
|
311 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|
312 |
*/ |
|
313 |
@Override |
|
314 |
public boolean hasChildren(Object element) { |
|
315 |
if (element instanceof Workspace) { |
|
316 |
return !((Workspace) element).getProjects().isEmpty(); |
|
317 |
} else if (element instanceof Project) { |
|
318 |
return !((Project) element).getBases().isEmpty(); |
|
319 |
} else if (element instanceof Base) { |
|
320 |
return !((Base) element).getCorpora().values().isEmpty(); |
|
321 |
} else if (element instanceof Corpus) { |
|
322 |
return !((Corpus) element).getTexts().isEmpty(); |
|
323 |
} else if (element instanceof Text) { |
|
324 |
return !((Text) element).getEditions().isEmpty(); |
|
325 |
} else if (element instanceof Edition) { |
|
326 |
return !((Edition) element).getPages().isEmpty(); |
|
327 |
} else if (element instanceof Page) { |
|
328 |
return false; |
|
329 |
} else if (element instanceof Script) { |
|
330 |
return false; |
|
331 |
} |
|
332 |
return false; |
|
333 |
} |
|
334 |
|
|
335 |
/* (non-Javadoc) |
|
336 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
337 |
*/ |
|
338 |
@Override |
|
339 |
public Object[] getElements(Object element) { |
|
340 |
return getChildren(element); |
|
341 |
} |
|
342 |
|
|
343 |
/* (non-Javadoc) |
|
344 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
345 |
*/ |
|
346 |
@Override |
|
347 |
public void dispose() { |
|
348 |
} |
|
349 |
|
|
350 |
/* (non-Javadoc) |
|
351 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
352 |
*/ |
|
353 |
@Override |
|
354 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
355 |
} |
|
356 |
|
|
357 |
} |
|
358 |
|
|
359 |
} |
|
0 | 360 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/GroovyConsole.java (revision 324) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.views; |
|
29 |
|
|
30 |
import java.io.IOException; |
|
31 |
import java.io.PipedInputStream; |
|
32 |
import java.io.PipedOutputStream; |
|
33 |
import java.io.PrintStream; |
|
34 |
|
|
35 |
import org.eclipse.swt.SWT; |
|
36 |
import org.eclipse.swt.custom.StyledText; |
|
37 |
import org.eclipse.swt.layout.GridData; |
|
38 |
import org.eclipse.swt.widgets.Composite; |
|
39 |
import org.eclipse.ui.part.ViewPart; |
|
40 |
import org.txm.rcp.Messages; |
|
41 |
// TODO: Auto-generated Javadoc |
|
42 |
/** |
|
43 |
* not used yet, must display the groovy logs only @ author mdecorde. |
|
44 |
*/ |
|
45 |
public class GroovyConsole extends ViewPart implements Runnable { |
|
46 |
|
|
47 |
/** The ID. */ |
|
48 |
public static String ID = "org.txm.rcp.views.GroovyConsole"; //$NON-NLS-1$ |
|
49 |
|
|
50 |
/** The text area. */ |
|
51 |
private static StyledText textArea; |
|
52 |
|
|
53 |
/** The out. */ |
|
54 |
private static PrintStream out; |
|
55 |
|
|
56 |
/** The err. */ |
|
57 |
private static PrintStream err; |
|
58 |
|
|
59 |
/** The quit. */ |
|
60 |
private boolean quit; |
|
61 |
|
|
62 |
/** The reader. */ |
|
63 |
private Thread reader; |
|
64 |
|
|
65 |
/** The reader2. */ |
|
66 |
private Thread reader2; |
|
67 |
|
|
68 |
/** The pin. */ |
|
69 |
PipedInputStream pin = new PipedInputStream(); |
|
70 |
|
|
71 |
/** The pin2. */ |
|
72 |
PipedInputStream pin2 = new PipedInputStream(); |
|
73 |
|
|
74 |
/** The output. */ |
|
75 |
static PrintStream output = System.out; |
|
76 |
|
|
77 |
/** The errput. */ |
|
78 |
static PrintStream errput = System.err; |
|
79 |
|
|
80 |
/** |
|
81 |
* Instantiates a new groovy console. |
|
82 |
*/ |
|
83 |
public GroovyConsole() { |
|
84 |
try { |
|
85 |
PipedOutputStream pout = new PipedOutputStream(pin); |
|
86 |
out = new PrintStream(pout, true); |
|
87 |
|
|
88 |
new PipedOutputStream(pin2); |
|
89 |
err = new PrintStream(pout, true); |
|
90 |
|
|
91 |
} catch (IOException e) { |
|
92 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
93 |
} |
|
94 |
|
|
95 |
reader = new Thread(this); |
|
96 |
reader.setDaemon(true); |
|
97 |
reader.start(); |
|
98 |
reader2 = new Thread(this); |
|
99 |
reader2.setDaemon(true); |
|
100 |
reader2.start(); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* Redirect. |
|
105 |
* |
|
106 |
* @param b the b |
|
107 |
*/ |
|
108 |
public static void redirect(boolean b) { |
|
109 |
if (b) { |
|
110 |
System.setOut(out); |
|
111 |
System.setErr(err); |
|
112 |
} else { |
|
113 |
System.setOut(output); |
|
114 |
System.setErr(errput); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Lecture de la sortie standard. |
|
120 |
* |
|
121 |
* @param in the in |
|
122 |
* @return the string |
|
123 |
* @throws IOException Signals that an I/O exception has occurred. |
|
124 |
*/ |
|
125 |
protected synchronized String readLine(PipedInputStream in) |
|
126 |
throws IOException { |
|
127 |
String input = ""; //$NON-NLS-1$ |
|
128 |
do { |
|
129 |
int available = in.available(); |
|
130 |
if (available == 0) |
|
131 |
break; |
|
132 |
byte b[] = new byte[available]; |
|
133 |
in.read(b); |
|
134 |
input = input + new String(b, 0, b.length); |
|
135 |
} while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit); //$NON-NLS-1$ //$NON-NLS-2$ |
|
136 |
return input; |
|
137 |
} |
|
138 |
|
|
139 |
/* (non-Javadoc) |
|
140 |
* @see java.lang.Runnable#run() |
|
141 |
*/ |
|
142 |
@Override |
|
143 |
public synchronized void run() { |
|
144 |
try { |
|
145 |
while (Thread.currentThread() == reader) { |
|
146 |
try { |
|
147 |
this.wait(100); |
|
148 |
} catch (InterruptedException ie) { |
|
149 |
} |
|
150 |
if (pin.available() != 0) { |
|
151 |
String input = this.readLine(pin); |
|
152 |
textArea.append(input); |
|
153 |
} |
|
154 |
if (quit) |
|
155 |
return; |
|
156 |
} |
|
157 |
|
|
158 |
while (Thread.currentThread() == reader2) { |
|
159 |
try { |
|
160 |
this.wait(100); |
|
161 |
} catch (InterruptedException ie) { |
|
162 |
} |
|
163 |
if (pin2.available() != 0) { |
|
164 |
String input = this.readLine(pin2); |
|
165 |
textArea.append(input); |
|
166 |
} |
|
167 |
|
|
168 |
if (quit) |
|
169 |
return; |
|
170 |
} |
|
171 |
} catch (Exception e) { |
|
172 |
textArea.append(Messages.GroovyConsole_4); |
|
173 |
textArea.append(Messages.GroovyConsole_5 + e); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
/* (non-Javadoc) |
|
178 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
179 |
*/ |
|
180 |
@Override |
|
181 |
public void createPartControl(Composite parent) { |
|
182 |
textArea = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL |
|
183 |
| SWT.H_SCROLL); |
|
184 |
textArea.setEditable(false); |
|
185 |
|
|
186 |
textArea.setLayoutData(new GridData(GridData.FILL_BOTH |
|
187 |
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Println. |
|
192 |
* |
|
193 |
* @param txt the txt |
|
194 |
*/ |
|
195 |
public static void println(String txt) { |
|
196 |
textArea.append(txt + "\n"); //$NON-NLS-1$ |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Prints the. |
|
201 |
* |
|
202 |
* @param txt the txt |
|
203 |
*/ |
|
204 |
public static void print(String txt) { |
|
205 |
textArea.append(txt); |
|
206 |
} |
|
207 |
|
|
208 |
/* (non-Javadoc) |
|
209 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
210 |
*/ |
|
211 |
@Override |
|
212 |
public void setFocus() { |
|
213 |
// TODO Auto-generated method stub |
|
214 |
|
|
215 |
} |
|
216 |
|
|
217 |
} |
|
0 | 218 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/QueriesView.java (revision 324) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.views; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.io.FileWriter; |
|
32 |
import java.io.IOException; |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.Collection; |
|
35 |
import java.util.Iterator; |
|
36 |
|
|
37 |
import org.eclipse.jface.action.MenuManager; |
|
38 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
39 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
40 |
import org.eclipse.jface.viewers.ISelection; |
|
41 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
42 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
43 |
import org.eclipse.jface.viewers.LabelProvider; |
|
44 |
import org.eclipse.jface.viewers.TreeSelection; |
|
45 |
import org.eclipse.jface.viewers.TreeViewer; |
|
46 |
import org.eclipse.jface.viewers.Viewer; |
|
47 |
import org.eclipse.osgi.util.NLS; |
|
48 |
import org.eclipse.swt.SWT; |
|
49 |
import org.eclipse.swt.events.KeyEvent; |
|
50 |
import org.eclipse.swt.events.KeyListener; |
|
51 |
import org.eclipse.swt.events.SelectionEvent; |
|
52 |
import org.eclipse.swt.events.SelectionListener; |
|
53 |
import org.eclipse.swt.graphics.Image; |
|
54 |
import org.eclipse.swt.layout.GridData; |
|
55 |
import org.eclipse.swt.layout.GridLayout; |
|
56 |
import org.eclipse.swt.widgets.Button; |
|
57 |
import org.eclipse.swt.widgets.Composite; |
|
58 |
import org.eclipse.swt.widgets.Control; |
|
59 |
import org.eclipse.swt.widgets.FileDialog; |
|
60 |
import org.eclipse.swt.widgets.Menu; |
|
61 |
import org.eclipse.ui.PlatformUI; |
|
62 |
import org.eclipse.ui.part.ViewPart; |
|
63 |
import org.txm.Toolbox; |
|
64 |
import org.txm.core.preferences.TBXPreferences; |
|
65 |
import org.txm.objects.Base; |
|
66 |
import org.txm.objects.Corpus; |
|
67 |
import org.txm.objects.Project; |
|
68 |
import org.txm.objects.SavedQuery; |
|
69 |
import org.txm.objects.TxmObject; |
|
70 |
import org.txm.rcp.IImageKeys; |
|
71 |
import org.txm.rcp.Messages; |
|
72 |
import org.txm.rcp.commands.EditFile; |
|
73 |
import org.txm.rcp.commands.base.DeleteObject; |
|
74 |
import org.txm.rcp.swt.dialog.LastOpened; |
|
75 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
76 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
77 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
78 |
import org.txm.utils.logger.Log; |
|
79 |
// TODO: Auto-generated Javadoc |
|
80 |
/** |
|
81 |
* Display the query saved in the Base, each time a query works it is saved @ |
|
82 |
* author mdecorde. |
|
83 |
*/ |
|
84 |
public class QueriesView extends ViewPart { |
|
85 |
|
|
86 |
/** The empty. */ |
|
87 |
ArrayList<Object> empty = new ArrayList<Object>(); |
|
88 |
|
|
89 |
/** The composites. */ |
|
90 |
Control[] composites = new Control[3]; |
|
91 |
|
|
92 |
/** The activated project. */ |
|
93 |
Project activatedProject; |
|
94 |
|
|
95 |
/** The activated base. */ |
|
96 |
Base activatedBase; |
|
97 |
|
|
98 |
/** The tv. */ |
|
99 |
TreeViewer tv; |
|
100 |
|
|
101 |
/** The ID. */ |
|
102 |
public static String ID = "org.txm.rcp.views.QueriesView"; //$NON-NLS-1$ |
|
103 |
|
|
104 |
/** |
|
105 |
* Instantiates a new queries view. |
|
106 |
*/ |
|
107 |
public QueriesView() { |
|
108 |
// System.out.println(Messages.ObjectExplorer_9); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Refresh. |
|
113 |
*/ |
|
114 |
public static void refresh() { |
|
115 |
QueriesView baseView = (QueriesView) PlatformUI.getWorkbench() |
|
116 |
.getActiveWorkbenchWindow().getActivePage().findView( |
|
117 |
QueriesView.ID); |
|
118 |
if (baseView != null) |
|
119 |
baseView.tv.refresh(); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Reload. |
|
124 |
*/ |
|
125 |
public static void reload() { |
|
126 |
QueriesView baseView = (QueriesView) PlatformUI.getWorkbench() |
|
127 |
.getActiveWorkbenchWindow().getActivePage().findView( |
|
128 |
QueriesView.ID); |
|
129 |
if (baseView != null) |
|
130 |
baseView._reload(); |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* _reload. |
|
135 |
*/ |
|
136 |
public void _reload() { |
|
137 |
tv.setContentProvider(new TxmObjectTreeProvider()); |
|
138 |
tv.setLabelProvider(new TxmObjectLabelProvider()); |
|
139 |
if (Toolbox.workspace != null) { |
|
140 |
try { |
|
141 |
Collection<MainCorpus> input = CorpusManager.getCorpusManager().getCorpora(); |
|
142 |
tv.setInput(input); |
|
143 |
refresh(); |
|
144 |
} catch (CqiClientException e) { |
|
145 |
// TODO Auto-generated catch block |
|
146 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
/* (non-Javadoc) |
|
152 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
153 |
*/ |
|
154 |
@Override |
|
155 |
public void createPartControl(Composite parent) { |
|
156 |
// System.out.println(Messages.ObjectExplorer_9); |
|
157 |
|
|
158 |
parent.setLayout(new GridLayout(1, true)); |
|
159 |
Button export = new Button(parent, SWT.PUSH); |
|
160 |
export.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, |
|
161 |
false)); |
|
162 |
export.setText(Messages.QueriesView_1); |
|
163 |
export.addSelectionListener(new SelectionListener() { |
|
164 |
@Override |
|
165 |
public void widgetSelected(SelectionEvent arg0) { |
|
166 |
//Collection<Base> bases = Toolbox.workspace.getProject("default").getBases(); //$NON-NLS-1$ |
|
167 |
File output = new File("queries.txt"); //$NON-NLS-1$ |
|
168 |
|
|
169 |
FileDialog dialog = new FileDialog(arg0.display.getActiveShell(), SWT.SAVE); |
|
170 |
String txmhome = Toolbox.getParam(TBXPreferences.USER_TXM_HOME); |
|
171 |
if (LastOpened.getFile(ID) != null) { |
|
172 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
|
173 |
dialog.setFileName(LastOpened.getFile(ID)); |
|
174 |
} else { |
|
175 |
dialog.setFilterPath(new File(txmhome, Messages.Explorer_3).getAbsolutePath()); |
|
176 |
} |
|
177 |
String path = dialog.open(); |
|
178 |
if (path == null) return; |
|
179 |
if (path.trim().length() > 0) |
|
180 |
output = new File(path); |
|
181 |
|
|
182 |
LastOpened.set(ID, output.getParent(), output.getName()); |
|
183 |
if (!output.getParentFile().exists()) |
|
184 |
return; |
|
185 |
|
|
186 |
|
|
187 |
try { |
|
188 |
FileWriter writer = new FileWriter(output); |
|
189 |
writer.write(Messages.QueriesView_5); |
|
190 |
for (MainCorpus b : CorpusManager.getCorpusManager().getCorpora()) { |
|
191 |
writer.write(" " + b.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
192 |
for (SavedQuery q : b.getQueriesLog()) { |
|
193 |
writer.write(" " + q + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
writer.close(); |
|
198 |
EditFile.openfile(path); |
|
199 |
refresh(); |
|
200 |
} catch (IOException e) { |
|
201 |
Log.severe("Error while exporting queries: "+e.getLocalizedMessage()); |
|
202 |
} catch (CqiClientException e) { |
|
203 |
// TODO Auto-generated catch block |
|
204 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
210 |
} |
|
211 |
}); |
|
212 |
tv = new TreeViewer(parent); |
|
213 |
tv.getTree().setLayoutData( |
|
214 |
new GridData(GridData.FILL, GridData.FILL, true, true)); |
|
215 |
_reload(); |
|
216 |
|
|
217 |
tv.addDoubleClickListener(new IDoubleClickListener() { |
|
218 |
@Override |
|
219 |
public void doubleClick(DoubleClickEvent event) { |
|
220 |
} |
|
221 |
}); |
|
222 |
|
|
223 |
tv.getTree().addKeyListener(new KeyListener() { |
|
224 |
|
|
225 |
@Override |
|
226 |
public void keyReleased(KeyEvent e) { |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public void keyPressed(KeyEvent e) { |
|
231 |
if (e.keyCode == SWT.DEL) { |
|
232 |
ISelection sel = tv.getSelection(); |
|
233 |
if (sel instanceof IStructuredSelection) { |
|
234 |
if (!DeleteObject.askContinueToDelete((IStructuredSelection)sel)) return; |
|
235 |
DeleteObject.delete(sel); |
|
236 |
} |
|
237 |
} |
|
238 |
else if (e.keyCode == SWT.F5) { |
Formats disponibles : Unified diff