Révision 3311

TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/rcp/tester/TreeSearchTester.java (revision 3311)
1
package org.txm.treesearch.rcp.tester;
2

  
3
import java.io.File;
4
import java.util.List;
5

  
6
import org.eclipse.core.expressions.PropertyTester;
7
import org.txm.searchengine.cqp.corpus.MainCorpus;
8
import org.txm.treesearch.command.ComputeTreeSearch;
9

  
10
/**
11
 * PropertyTester to check if a corpus has TreeSearchTester indexes
12
 * 
13
 * @author mdecorde
14
 *
15
 */
16
public class TreeSearchTester extends PropertyTester {
17
	
18
	public static final String PROPERTY_NAMESPACE = "org.txm.rcp.testers"; //$NON-NLS-1$
19
	
20
	public static final String TREESEARCH_READY = "TreeSearchReady"; //$NON-NLS-1$
21
	
22
	public TreeSearchTester() {
23
		// TODO Auto-generated constructor stub
24
	}
25
	
26
	@Override
27
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
28
		
29
		if (!TREESEARCH_READY.equals(property)) return false;
30
		
31
		if (receiver == null) {
32
			return false;
33
		}
34
		
35
		if (receiver instanceof List) {
36
			List l = ((List)receiver);
37
			if (l.size() == 0) {
38
				return false;
39
			}
40
			
41
			receiver = l.get(0);
42
			if (!(receiver instanceof MainCorpus)) return false;
43
			
44
			MainCorpus corpus = (MainCorpus) receiver;
45
			if (!(receiver instanceof MainCorpus)) {
46
				return false;
47
			}
48
			
49
			if (corpus.getProjectDirectory() == null) return false;
50
			
51
			return ComputeTreeSearch.getSelectorForCorpus(corpus, null) != null; // any TreeSearch available ?
52
		}
53
		return false;
54
	}
55
}
0 56

  
TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/editor/TreeSearchEditor.java (revision 3311)
1
package org.txm.treesearch.editor;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.Arrays;
6
import java.util.HashMap;
7

  
8
import org.eclipse.swt.SWT;
9
import org.eclipse.swt.browser.Browser;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.events.SelectionListener;
12
import org.eclipse.swt.layout.GridData;
13
import org.eclipse.swt.layout.GridLayout;
14
import org.eclipse.swt.widgets.Button;
15
import org.eclipse.swt.widgets.Combo;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.swt.widgets.Label;
19
import org.eclipse.swt.widgets.Listener;
20
import org.eclipse.swt.widgets.Spinner;
21
import org.eclipse.ui.IEditorInput;
22
import org.eclipse.ui.IEditorSite;
23
import org.eclipse.ui.PartInitException;
24
import org.txm.Toolbox;
25
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
26
import org.txm.core.preferences.TXMPreferences;
27
import org.txm.core.results.Parameter;
28
import org.txm.edition.rcp.handlers.OpenEdition;
29
import org.txm.rcp.IImageKeys;
30
import org.txm.rcp.editors.TXMEditor;
31
import org.txm.rcp.editors.TXMResultEditorInput;
32
import org.txm.rcp.swt.GLComposite;
33
import org.txm.rcp.swt.widget.LargeQueryField;
34
import org.txm.rcp.views.QueriesView;
35
import org.txm.rcp.views.corpora.CorporaView;
36
import org.txm.searchengine.cqp.corpus.CQPCorpus;
37
import org.txm.treesearch.command.ComputeTreeSearch;
38
import org.txm.treesearch.function.TreeSearch;
39
import org.txm.treesearch.function.TreeSearchSelector;
40
import org.txm.treesearch.preferences.TreeSearchPreferences;
41
//import org.txm.stat.engine.r.RDevice;
42
import org.txm.utils.logger.Log;
43
//import org.txm.functions.queryindex.QueryIndex;
44

  
45

  
46
public class TreeSearchEditor extends TXMEditor<TreeSearch> {
47
	
48
	/** The Constant ID. */
49
	public static final String ID = TreeSearchEditor.class.getName();
50
	
51
	public Object source;
52
	
53
	public CQPCorpus corpus;
54
	
55
	File svgFile;
56
	
57
	Browser svgPanel;
58
	
59
	@Parameter(key = TXMPreferences.INDEX)
60
	Spinner sentSpinner;
61
	
62
	@Parameter(key = TXMPreferences.SUB_INDEX)
63
	Spinner subSpinner;
64
	
65
	Button okButton;
66
	
67
	private HashMap<String, TreeSearch> tsPerRepresentation = null;
68
	
69
	private TreeSearchSelector currentSelector = null;
70
	
71
	@Parameter(key = TXMPreferences.QUERY)
72
	private LargeQueryField queryArea;
73
	
74
	private Label subCounterLabel;
75
	
76
	private Label sentCounterLabel;
77
	
78
	@Parameter(key = TreeSearchPreferences.NTFEATURE)
79
	private Combo NTCombo;
80
	
81
	@Parameter(key = TreeSearchPreferences.TFEATURE)
82
	private Combo TCombo;
83
	
84
	private Combo representationCombo;
85
	
86
	private Label representationLabel;
87
	
88
	@Override
89
	public void _createPartControl() {
90
		
91
		getMainParametersComposite().getLayout().numColumns = 3;
92
		getMainParametersComposite().getLayout().makeColumnsEqualWidth = false;
93
		
94
		SelectionListener selChangedListener = new SelectionListener() {
95
			
96
			@Override
97
			public void widgetSelected(SelectionEvent e) {
98
				
99
				HashMap<String, TreeSearchSelector> selectors = ComputeTreeSearch.getSelectorsForCorpus(corpus);
100
				
101
				boolean updateFields = false;
102
				if (representationCombo.getText().equals("TIGER") && !currentSelector.getEngine().equals("TIGER")) {
103
					currentSelector = selectors.get("TIGER");
104
					if (!tsPerRepresentation.containsKey("TIGER")) {
105
						tsPerRepresentation.put("TIGER", currentSelector.getTreeSearch(corpus));
106
					}
107
					updateFields = true;
108
				} else if (representationCombo.getText().equals("UD") && !currentSelector.getEngine().equals("UD")) {
109
					currentSelector = selectors.get("UD");
110
					if (!tsPerRepresentation.containsKey("UD")) {
111
						tsPerRepresentation.put("UD", currentSelector.getTreeSearch(corpus));
112
					}
113
					updateFields = true;
114
				}
115
				if (updateFields) {
116
					queryArea.setQueryClass(currentSelector.getQueryClass());
117
					initializeFields();
118
					getEditorInput().setResult(tsPerRepresentation.get(currentSelector.getEngine()));
119
					representationLabel.setImage(IImageKeys.getImage(tsPerRepresentation.get(currentSelector.getEngine()).getIconPath()));
120
					
121
					//if (e.widget == sentSpinner && tsPerRepresentation.get(currentSelector.getEngine()).hasSubMatchesStrategy()) {
122
					
123
					subSpinner.setSelection(1);
124
					subSpinner.setMaximum(tsPerRepresentation.get(currentSelector.getEngine()).getNSubGraph(sentSpinner.getSelection() - 1));
125
					subCounterLabel.setText("/" + tsPerRepresentation.get(currentSelector.getEngine()).getNSubGraph(sentSpinner.getSelection() - 1));
126
					//}
127
				}
128
				
129
				
130
				TreeSearchEditor.this.compute(true);
131
				//reloadGraph();
132
			}
133
			
134
			@Override
135
			public void widgetDefaultSelected(SelectionEvent e) {}
136
		};
137
		
138
		representationLabel = new Label(getMainParametersComposite(), SWT.NONE);
139
		representationLabel.setImage(IImageKeys.getImage(tsPerRepresentation.get(currentSelector.getEngine()).getIconPath()));
140
		representationLabel.setToolTipText("Current representation");
141
		
142
		representationCombo = new Combo(getMainParametersComposite(), SWT.READ_ONLY);
143
		GridData gdataR = new GridData(SWT.FILL, SWT.CENTER, true, true);
144
		representationCombo.setLayoutData(gdataR);
145
		representationCombo.addSelectionListener(selChangedListener);
146
		
147
		Button editionButton = new Button(getMainParametersComposite(), SWT.PUSH);
148
		editionButton.setImage(IImageKeys.getImage(IImageKeys.EDITION));
149
		editionButton.addSelectionListener(new SelectionListener() {
150
			
151
			@Override
152
			public void widgetSelected(SelectionEvent e) {
153
				
154
				try {
155
					String[] currentMatch = TreeSearchEditor.this.getResult().getTextAndWordIDSOfCurrentSentence();
156
					if (currentMatch == null || currentMatch.length != 2 || currentMatch[0] == null || currentMatch[1] == null) {
157
						return;
158
					}
159
					String textId = currentMatch[0];
160
					String wordId = currentMatch[1];
161
					
162
					OpenEdition.openEdition(corpus, null, textId, null, wordId);
163
				}
164
				catch (Exception e1) {
165
					// TODO Auto-generated catch block
166
					e1.printStackTrace();
167
				}
168
			}
169
			
170
			@Override
171
			public void widgetDefaultSelected(SelectionEvent e) { }
172
		});
173
		
174
		// System.out.println(parent.getLayout());
175
		Composite queryPanel = this.getExtendedParametersGroup();
176
		
177
		// fill query Area
178
		GridLayout qlayout = new GridLayout(13, false);
179
		queryPanel.setLayout(qlayout);
180
		
181
		queryArea = new LargeQueryField(queryPanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, currentSelector.getQueryClass());
182
		GridData queryAreaLayoutData = new GridData(GridData.FILL, GridData.FILL, true, true);
183
		queryAreaLayoutData.horizontalSpan = 13;
184
		queryAreaLayoutData.heightHint = 80;
185
		queryAreaLayoutData.minimumHeight = 80;
186
		queryArea.setLayoutData(queryAreaLayoutData);
187
		
188
		queryArea.addListener(SWT.KeyDown, new Listener() {
189
			
190
			@Override
191
			public void handleEvent(Event e) {
192
				if (e.stateMask == SWT.CTRL) {
193
					if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
194
						e.doit = false;
195
						compute(false);
196
					}
197
				}
198
			}
199
		});
200
		
201
		new Label(queryPanel, SWT.NONE).setText("T ");
202
		TCombo = new Combo(queryPanel, SWT.READ_ONLY);
203
		GridData gdata = new GridData(SWT.FILL, SWT.CENTER, true, true);
204
		TCombo.setLayoutData(gdata);
205
		TCombo.addSelectionListener(selChangedListener);
206
		
207
		new Label(queryPanel, SWT.NONE).setText("NT ");
208
		NTCombo = new Combo(queryPanel, SWT.READ_ONLY);
209
		gdata = new GridData(SWT.FILL, SWT.CENTER, true, true);
210
		NTCombo.setLayoutData(gdata);
211
		NTCombo.addSelectionListener(selChangedListener);
212
		
213
		GLComposite navigationAreaComposite = getBottomToolbar().installGLComposite(ConcordanceUIMessages.navigation, 10, false);
214
		navigationAreaComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
215
		
216
		// fill param Area
217
		gdata = new GridData(SWT.FILL, SWT.CENTER, true, true);
218
		new Label(navigationAreaComposite, SWT.NONE).setText("Sent ");
219
		sentSpinner = new Spinner(navigationAreaComposite, SWT.BORDER);
220
		sentSpinner.setMinimum(1);
221
		sentSpinner.setIncrement(1);
222
		sentSpinner.setMaximum(10000000);
223
		sentSpinner.setSelection(1);
224
		gdata = new GridData(SWT.FILL, SWT.CENTER, false, true);
225
		sentSpinner.setLayoutData(gdata);
226
		sentSpinner.addSelectionListener(selChangedListener);
227
		
228
		sentCounterLabel = new Label(navigationAreaComposite, SWT.NONE);
229
		gdata = new GridData(SWT.FILL, SWT.CENTER, true, true);
230
		sentCounterLabel.setLayoutData(gdata);
231
		
232
		//if (tsPerRepresentation.get(currentSelector.getEngine()).hasSubMatchesStrategy()) {
233
		new Label(navigationAreaComposite, SWT.NONE).setText("Sub ");
234
		subSpinner = new Spinner(navigationAreaComposite, SWT.BORDER);
235
		subSpinner.setMinimum(1);
236
		subSpinner.setIncrement(1);
237
		subSpinner.setMaximum(100000000);
238
		subSpinner.setSelection(1);
239
		gdata = new GridData(SWT.FILL, SWT.CENTER, false, true);
240
		subSpinner.setLayoutData(gdata);
241
		subSpinner.addSelectionListener(selChangedListener);
242
		
243
		subCounterLabel = new Label(navigationAreaComposite, SWT.NONE);
244
		gdata = new GridData(SWT.FILL, SWT.CENTER, true, true);
245
		subCounterLabel.setLayoutData(gdata);
246
		//}
247
		
248
		Composite mainPanel = this.getResultArea();
249
		svgPanel = new Browser(mainPanel, SWT.EMBEDDED | SWT.NO_BACKGROUND);
250
		svgPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
251
		
252
		//this.getTopToolbar().setVisible(COMPUTING_PARAMETERS_GROUP_ID, true);
253
		initializeFields();
254
	}
255
	
256
	protected void initializeFields() {
257
		//String id = corpus.getID();
258
		
259
		//if (ts.isReady()) {
260
		TreeSearch ts = tsPerRepresentation.get(currentSelector.getEngine());
261
		
262
		this.queryArea.setText(ts.getQuery());
263
		
264
		String[] tFeatures = ts.getAvailableTProperties();
265
		if (tFeatures.length > 0) {
266
			TCombo.setItems(tFeatures);
267
			TCombo.setText(tFeatures[0]);
268
		}
269
		
270
		String[] ntFeatures = ts.getAvailableNTProperties();
271
		if (ntFeatures.length > 0) {
272
			NTCombo.setItems(ntFeatures);
273
			NTCombo.setText(ts.getNT());
274
		}
275
		
276
		if (representationCombo.getItemCount() == 0) {
277
			HashMap<String, TreeSearchSelector> selectors = ComputeTreeSearch.getSelectorsForCorpus(corpus);
278
			Log.fine("Syntax representations: "+selectors);
279
			String[] values = selectors.keySet().toArray(new String[selectors.size()]);
280
			representationCombo.setItems(values);
281
			
282
			String defaultEngine = ts.getEngine();//TreeSearchPreferences.getInstance().getString(TreeSearchPreferences.DEFAULT_REPRESENTATION);
283
			representationCombo.select(Arrays.binarySearch(values, defaultEngine));
284
			
285
			if (representationCombo.getItemCount() == 1) {
286
				representationCombo.setVisible(false);
287
			}
288
		}
289
		
290
		if (ts.isComputed()) {
291
			queryArea.setText(ts.getQuery());
292
			sentCounterLabel.setText("/" + ts.getNSentences());
293
			subCounterLabel.setText("/" + ts.getNSubGraph(0));
294
		}
295
		else {
296
			sentCounterLabel.setText("No Sentence");
297
			if (ts.hasSubMatchesStrategy()) subCounterLabel.setText("No sub graph");
298
		}
299
		
300
		if (ts.isDrawn()) {
301
			sentSpinner.setSelection(1);
302
			sentSpinner.setMaximum(ts.getNSentences());
303
			//if (ts.hasSubMatchesStrategy()) {
304
			subSpinner.setSelection(ts.getSub(0));
305
			subSpinner.setMaximum(ts.getNSubGraph(0));
306
			//}
307
			
308
			try {
309
				reloadGraph();
310
			}
311
			catch (Exception e) {
312
				System.out.println("Error during TreeSearch initialization: " + e);
313
				Log.printStackTrace(e);
314
			}
315
		}
316
		else {
317
			sentSpinner.setSelection(1);
318
			if (ts.hasSubMatchesStrategy()) subSpinner.setSelection(1);
319
			if (ts.isComputed()) {
320
				sentSpinner.setMaximum(ts.getNSentences());
321
				if (ts.hasSubMatchesStrategy()) subSpinner.setMaximum(ts.getNSubGraph(0));
322
			}
323
			else {
324
				sentSpinner.setMaximum(1);
325
				if (ts.hasSubMatchesStrategy()) subSpinner.setMaximum(1);
326
			}
327
		}
328
		//		}
329
		//		else {
330
		//			System.out.println("Corpus '" + id + "' is not ready.");
331
		//			return;
332
		//		}
333
	}
334
	
335
	/**
336
	 * 
337
	 * @return 1..N sentences
338
	 */
339
	public int getNSent() {
340
		return this.sentSpinner.getSelection();
341
	}
342
	
343
	public File getSVGFile() {
344
		return svgFile;
345
	}
346
	
347
	@Override
348
	public void updateResultFromEditor() {
349
		
350
		String query = this.queryArea.getText();
351
		this.queryArea.setText(query.trim());
352
	}
353
	
354
	@Override
355
	public void updateEditorFromResult(boolean update) {
356
		//		if (update == false) {
357
		//			//initializeFields();
358
		//		}
359
		// final String query = queryArea.getText().trim();
360
		// if (query.length() == 0) {
361
		// System.out.println("No query, aborting.");
362
		// return;
363
		// }
364
		
365
		// JobHandler jobhandler = new JobHandler("", this.svgPanel.getParent()) {
366
		// @Override
367
		// protected IStatus run(IProgressMonitor monitor) {
368
		try {
369
			TreeSearch ts = tsPerRepresentation.get(currentSelector.getEngine());
370
			if (ts.getNSentences() > 0) {
371
				sentCounterLabel.setText("/" + ts.getNSentences());
372
				if (ts.hasSubMatchesStrategy()) subCounterLabel.setText("/" + ts.getNSubGraph(0));
373
				sentSpinner.setSelection(ts.getCurrentMatchIndex());
374
				sentSpinner.setMaximum(ts.getNSentences());
375
				
376
				subSpinner.setSelection(ts.getCurrentSubMatchIndex());
377
				subSpinner.setMaximum(ts.getNSubGraph(0));
378
				
379
				reloadGraph();
380
			}
381
			
382
			CorporaView.refresh();
383
			CorporaView.expand(corpus);
384
			QueriesView.refresh();
385
		}
386
		catch (Exception e) {
387
			System.out.println("Error while computing the Tree: " + e);
388
			Log.printStackTrace(e);
389
		}
390
		// JobsTimer.stopAndPrint();
391
		// return Status.OK_STATUS;
392
		// }
393
		// };
394
		// jobhandler.startJob();
395
	}
396
	
397
	/**
398
	 * Reload graph.
399
	 */
400
	private boolean reloadGraph() {
401
		
402
		String T = TCombo.getText();
403
		String NT = NTCombo.getText();
404
		int sent = sentSpinner.getSelection() - 1;
405
		int sub = 0;
406
		
407
		TreeSearch ts = tsPerRepresentation.get(currentSelector.getEngine());
408
		
409
		if (ts.hasSubMatchesStrategy()) sub = subSpinner.getSelection() - 1;
410
		
411
		ts.setIndexAndSubIndex(sent, sub);
412
		
413
		if (ts == null) return false; // no result
414
		if (!ts.isComputed()) return false;
415
		
416
		try {
417
			if (ts.toSVG(svgFile, sent, sub, T, NT)) {
418
				Log.finer("SVG file: "+svgFile);
419
				svgPanel.setUrl(svgFile.toURI().toURL().toString());
420
				svgPanel.layout();
421
				svgPanel.redraw();
422
			}
423
			else {
424
				Log.warning("Error: Fail to generate SVG file: "+svgFile);
425
			}
426
		}
427
		catch (Exception e1) {
428
			Log.printStackTrace(e1);
429
			return false;
430
		}
431
		return true;
432
	}
433
	
434
	@Override
435
	public void _setFocus() {
436
		if (queryArea != null)
437
			queryArea.forceFocus();
438
	}
439
	
440
	@SuppressWarnings("unchecked")
441
	@Override
442
	public void init(IEditorSite site, IEditorInput input)
443
			throws PartInitException {
444
		setSite(site);
445
		setInput(input);
446
		
447
		File resultDir = new File(Toolbox.getTxmHomePath(), "results"); //$NON-NLS-1$
448
		resultDir.mkdirs();
449
		try {
450
			svgFile = File.createTempFile("TreeSearch", ".svg", resultDir);
451
		}
452
		catch (IOException e) {
453
			System.out.println("Error: " + e.getLocalizedMessage());
454
			Log.printStackTrace(e);
455
		}
456
		Log.fine(svgFile.toString());
457
		
458
		TXMResultEditorInput<TreeSearch> ii = (TXMResultEditorInput<TreeSearch>) input;
459
		tsPerRepresentation = new HashMap<>();
460
		tsPerRepresentation.put(ii.getResult().getEngine(), ii.getResult());
461
		currentSelector = ii.getResult().getSelector();
462
		corpus = (CQPCorpus) ii.getResult().getCorpus();
463
	}
464
}
0 465

  
TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/editor/TreeSearchEditorInput.java (revision 3311)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.treesearch.editor;
29

  
30
import org.eclipse.jface.resource.ImageDescriptor;
31
import org.eclipse.ui.IEditorInput;
32
import org.eclipse.ui.IPersistableElement;
33
import org.eclipse.ui.plugin.AbstractUIPlugin;
34
import org.txm.rcp.Application;
35
import org.txm.rcp.IImageKeys;
36
import org.txm.treesearch.function.TreeSearch;
37

  
38
/**
39
 * Simple editor input to query the TIGERSearch search engine
40
 *
41
 * @author mdecorde
42
 */
43
public class TreeSearchEditorInput implements IEditorInput {
44
	
45
	/** The ca. */
46
	private Object source;
47
	private TreeSearch ts;
48
		
49
	/**
50
	 * Instantiates a new correspondance analysis editor input.
51
	 *
52
	 * @param src the source
53
	 */
54
	public TreeSearchEditorInput( Object src, TreeSearch ts) {
55
		super();
56
		this.source = src;
57
		this.ts = ts;
58
	}
59

  
60
	/**
61
	 * Exists.
62
	 *
63
	 * @return true, if successful
64
	 * @see org.eclipse.ui.IEditorInput#exists()
65
	 */
66
	@Override
67
	public boolean exists() {
68
		return false;
69
	}
70

  
71
	/**
72
	 * Gets the image descriptor.
73
	 *
74
	 * @return the image descriptor
75
	 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
76
	 */
77
	@Override
78
	public ImageDescriptor getImageDescriptor() {
79
		return AbstractUIPlugin.imageDescriptorFromPlugin(
80
				Application.PLUGIN_ID,
81
				IImageKeys.ACTION_WORDCLOUD);
82
	}
83

  
84
	/**
85
	 * Gets the name.
86
	 *
87
	 * @return the name
88
	 * @see org.eclipse.ui.IEditorInput#getName()
89
	 */
90
	@Override
91
	public String getName() {
92
		return "TreeSearch"; //$NON-NLS-1$
93
	}
94

  
95
	/**
96
	 * Gets the persistable.
97
	 *
98
	 * @return the persistable
99
	 * @see org.eclipse.ui.IEditorInput#getPersistable()
100
	 */
101
	@Override
102
	public IPersistableElement getPersistable() {
103
		return null;
104
	}
105

  
106
	/**
107
	 * Gets the tool tip text.
108
	 *
109
	 * @return the tool tip text
110
	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
111
	 */
112
	@Override
113
	public String getToolTipText() {
114
		return getName();
115
	}
116

  
117
	/**
118
	 * Gets the adapter.
119
	 *
120
	 * @param arg0 the arg0
121
	 * @return the adapter
122
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
123
	 */
124
	@Override
125
	@SuppressWarnings("unchecked") //$NON-NLS-1$
126
	public Object getAdapter(Class arg0) {
127
		return null;
128
	}
129

  
130
	/**
131
	 * Gets the cA.
132
	 *
133
	 * @return the Correspondance analysis underlying object
134
	 */
135
	public Object getSource() {
136
		return source;
137
	}
138

  
139
	public TreeSearch getTreeSearch() {
140
		return ts;
141
	}
142
}
0 143

  
TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/command/TreeSearchAdapterFactory.java (revision 3311)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
2
package org.txm.treesearch.command;
3

  
4
import org.eclipse.jface.resource.ImageDescriptor;
5
import org.eclipse.ui.plugin.AbstractUIPlugin;
6
import org.osgi.framework.FrameworkUtil;
7
import org.txm.rcp.adapters.TXMResultAdapter;
8
import org.txm.rcp.adapters.TXMResultAdapterFactory;
9
import org.txm.treesearch.function.TreeSearch;
10

  
11
/**
12
 * A factory for creating Adapter objects.
13
 *  
14
 * @author mdecorde
15
 */
16
public class TreeSearchAdapterFactory extends TXMResultAdapterFactory {
17
	
18
	public static final ImageDescriptor ICON =
19
			AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(TreeSearchAdapterFactory.class).getSymbolicName(),
20
					"platform:/plugin/"+ FrameworkUtil.getBundle(TreeSearchAdapterFactory.class).getSymbolicName() + "/icons/functions/Tree.png"); //$NON-NLS-1$ //$NON-NLS-2$
21

  
22
	@Override
23
	public Object getAdapter(Object adaptableObject, Class adapterType) {
24
		if (this.canAdapt(adapterType) && adaptableObject instanceof TreeSearch)	{
25
			return new TXMResultAdapter() {
26
				@Override
27
				public ImageDescriptor getImageDescriptor(Object object) {
28
					return ICON;
29
				}
30
			};
31
		}
32
		return null;
33
	}
34
}
0 35

  
TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/command/ComputeTreeSearch.java (revision 3311)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.treesearch.command;
29

  
30
import java.util.HashMap;
31

  
32
import org.eclipse.core.commands.AbstractHandler;
33
import org.eclipse.core.commands.ExecutionEvent;
34
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.core.runtime.IConfigurationElement;
36
import org.eclipse.core.runtime.RegistryFactory;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.ui.handlers.HandlerUtil;
39
import org.txm.core.messages.TXMCoreMessages;
40
import org.txm.core.preferences.TXMPreferences;
41
import org.txm.core.results.TXMResult;
42
import org.txm.rcp.editors.TXMEditor;
43
import org.txm.searchengine.cqp.corpus.CQPCorpus;
44
import org.txm.treesearch.editor.TreeSearchEditor;
45
import org.txm.treesearch.function.TreeSearch;
46
import org.txm.treesearch.function.TreeSearchSelector;
47
import org.txm.treesearch.preferences.TreeSearchPreferences;
48
import org.txm.utils.logger.Log;
49

  
50

  
51
/**
52
 * Open the TIGERSearch Editor using the current selection OR a preference node set in the RCP command parameter TXMPreferences.RESULT_PARAMETERS_NODE_PATH
53
 * 
54
 * @author mdecorde.
55
 */
56
public class ComputeTreeSearch extends AbstractHandler {
57
	
58
	/** The ID. */
59
	public static String ID = ComputeTreeSearch.class.getName();
60
	
61
	/*
62
	 * (non-Javadoc)
63
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
64
	 */
65
	@Override
66
	public Object execute(final ExecutionEvent event) throws ExecutionException {
67
		
68
		Object s = null;
69
		
70
		// From link: creating from parameter node
71
		String parametersNodePath = event.getParameter(TXMPreferences.RESULT_PARAMETERS_NODE_PATH);
72
		if (parametersNodePath != null && !parametersNodePath.isEmpty()) {
73
			s = TXMResult.getResult(parametersNodePath); // a TreeSearch or a CQPCorpus
74
		}
75
		else { // From view result node
76
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
77
			s = selection.getFirstElement();
78
		}
79
		
80
		return openEditor(s);
81
	}
82
	
83
	public static HashMap<String, TreeSearchSelector> getSelectorsForCorpus(CQPCorpus corpus) {
84
		
85
		HashMap<String, TreeSearchSelector> ret = new HashMap<String, TreeSearchSelector>();
86
		IConfigurationElement[] contributions = RegistryFactory.getRegistry().getConfigurationElementsFor("org.txm.treesearch.TreeSearchSelector");
87
		
88
		for (int i = 0; i < contributions.length; i++) {
89
			try {
90
				@SuppressWarnings("unchecked")
91
				TreeSearchSelector s = (TreeSearchSelector) contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
92
				
93
				Log.fine(TXMCoreMessages.bind("Initializing selector: {0}...", s));
94
				
95
				if (s.canComputeWith(corpus)) {
96
					ret.put(s.getEngine(), s);
97
				}
98
			}
99
			catch (Exception e) {
100
				Log.severe("Error: failed to instantiate " + contributions[i].getName() + ".");
101
				e.printStackTrace();
102
			}
103
		}
104
		
105
		return ret;
106
	}
107
	
108
	/**
109
	 * 
110
	 * @param corpus
111
	 * @return an available TreeSearch for a corpus (if any)
112
	 */
113
	public static TreeSearchSelector getSelectorForCorpus(CQPCorpus corpus, String defaultEngine) {
114
		
115
		TreeSearchSelector found = null;
116
		
117
		IConfigurationElement[] contributions = RegistryFactory.getRegistry().getConfigurationElementsFor("org.txm.treesearch.TreeSearchSelector");
118
		
119
		for (int i = 0; i < contributions.length; i++) {
120
			try {
121
				@SuppressWarnings("unchecked")
122
				TreeSearchSelector s = (TreeSearchSelector) contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
123
				
124
				Log.fine(TXMCoreMessages.bind("Initializing selector: {0}...", s));
125
				
126
				if (s.canComputeWith(corpus)) {
127
					if (s.getEngine().equals(defaultEngine) || defaultEngine == null) { // it is the default engine, return it !
128
						return s;
129
					}
130
					found = s; //Store 
131
				}
132
			}
133
			catch (Exception e) {
134
				Log.severe("Error: failed to instantiate " + contributions[i].getName() + ".");
135
				e.printStackTrace();
136
			}
137
		}
138
		
139
		return found;
140
	}
141
	
142
	public static TreeSearch getTreeSearchFor(CQPCorpus corpus) {
143
		TreeSearchSelector s = getSelectorForCorpus(corpus, TreeSearchPreferences.getInstance().getString(TreeSearchPreferences.DEFAULT_REPRESENTATION));
144
		if (s != null) return s.getTreeSearch(corpus);
145
		
146
		return null;
147
	}
148
	
149
	public static TreeSearchEditor openEditor(Object obj) {
150
		
151
		TreeSearch ts = null;
152
		
153
		if (obj instanceof CQPCorpus) {
154
			
155
			CQPCorpus corpus = (CQPCorpus)obj;
156
			ts = getTreeSearchFor(corpus);
157
		}
158
		else if (obj instanceof TreeSearch) {
159
			
160
			ts = (TreeSearch) obj;
161
		}
162
		else {
163
			
164
			Log.warning("Selection is not a corpus: " + obj);
165
			return null;
166
		}
167
		
168
		try {
169
			TXMEditor<?> editor = TreeSearchEditor.openEditor(ts, TreeSearchEditor.ID);
170
			if (editor instanceof TreeSearchEditor) {
171
				return (TreeSearchEditor) editor;
172
			}
173
		}
174
		catch (Exception e) {
175
			Log.printStackTrace(e);
176
		}
177
		return null;
178
	}
179
}
0 180

  
TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/preferences/TreeSearchPreferencePage.java (revision 3311)
1
package org.txm.treesearch.preferences;
2

  
3
import org.eclipse.jface.preference.StringFieldEditor;
4
import org.eclipse.ui.IWorkbench;
5
import org.txm.rcp.IImageKeys;
6
import org.txm.rcp.preferences.TXMPreferencePage;
7
import org.txm.rcp.preferences.TXMPreferenceStore;
8

  
9
/**
10
 * Syntatic annotations preferences page
11
 * 
12
 * @author mdecorde
13
 *
14
 */
15
public class TreeSearchPreferencePage extends TXMPreferencePage {
16

  
17
	@Override
18
	public void createFieldEditors() {
19
		this.addField(new StringFieldEditor(TreeSearchPreferences.DEFAULT_REPRESENTATION, "Syntactic representation", this.getFieldEditorParent()));
20
	}
21
	
22
	/*
23
	 * (non-Javadoc)
24
	 * 
25
	 * @see
26
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
27
	 */
28
	@Override
29
	public void init(IWorkbench workbench) {
30
		this.setPreferenceStore(new TXMPreferenceStore(TreeSearchPreferences.getInstance().getPreferencesNodeQualifier()));
31
		this.setDescription("Syntatic annotation");
32
		this.setImageDescriptor(IImageKeys.getImageDescriptor(this.getClass(), "icons/functions/Tree.png"));
33
	}
34
}
0 35

  
TXM/trunk/org.txm.treesearch.rcp/build.properties (revision 3311)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml,\
6
               icons/
0 7

  
TXM/trunk/org.txm.treesearch.rcp/plugin.xml (revision 3311)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.core.expressions.propertyTesters">
6
      <propertyTester
7
            class="org.txm.treesearch.rcp.tester.TreeSearchTester"
8
            id="org.txm.rcp.testers.TreeSearchTester"
9
            namespace="org.txm.rcp.testers"
10
            properties="TreeSearchReady"
11
            type="java.lang.Object">
12
      </propertyTester>
13
   </extension>
14
   <extension
15
         point="org.eclipse.core.runtime.adapters">
16
      <factory
17
            adaptableType="org.txm.treesearch.function.TreeSearch"
18
            class="org.txm.treesearch.command.TreeSearchAdapterFactory">
19
         <adapter
20
               type="org.eclipse.ui.model.IWorkbenchAdapter">
21
         </adapter>
22
         <adapter
23
               type="org.eclipse.ui.model.IWorkbenchAdapter2">
24
         </adapter>
25
      </factory>
26
   </extension>
27
   <extension
28
         point="org.eclipse.ui.editors">
29
      <editor
30
            class="org.txm.treesearch.editor.TreeSearchEditor"
31
            default="false"
32
            icon="icons/functions/Tree.png"
33
            id="org.txm.treesearch.editor.TreeSearchEditor"
34
            name="Syntactic Tree">
35
      </editor>
36
   </extension>
37
   <extension
38
         point="org.eclipse.ui.commands">
39
      <category
40
            description="%category.description"
41
            id="TreeSearch4TXM.commands.category"
42
            name="Syntactic Tree">
43
      </category>
44
      <command
45
            categoryId="TreeSearch4TXM.commands.category"
46
            defaultHandler="org.txm.treesearch.command.ComputeTreeSearch"
47
            id="org.txm.treesearch.command.ComputeTreeSearch"
48
            name="Syntactic Tree"
49
            returnTypeId="org.txm.treesearch.function.TreeSearch">
50
      </command>
51
   </extension>
52
   <extension
53
         point="org.eclipse.ui.menus">
54
         <menuContribution
55
            allPopups="false"
56
            locationURI="popup:org.txm.rcp.views.corpora.CorporaView?after=org.txm.rcp.corporaview.annotation">
57
         <command
58
               commandId="org.txm.tigersearch.commands.ComputeTreeSearch"
59
               icon="icons/functions/Tree.png"
60
               label="%command.label"
61
               style="push">
62
            <visibleWhen
63
                  checkEnabled="false">
64
               <or>
65
                  <test
66
                        forcePluginActivation="true"
67
                        property="org.txm.rcp.testers.TreeSearchReady"
68
                        value="TreeSearchReady">
69
                  </test>
70
               </or>
71
            </visibleWhen>
72
         </command>
73
      </menuContribution>
74
      <menuContribution
75
            allPopups="false"
76
            locationURI="toolbar:org.txm.rcp.toolbartools">
77
         <command
78
               commandId="org.txm.treesearch.command.ComputeTreeSearch"
79
               icon="icons/functions/Tree.png"
80
               label="%command.label"
81
               style="push">
82
            <visibleWhen
83
                  checkEnabled="false">
84
               <or>
85
                  <test
86
                        forcePluginActivation="true"
87
                        property="org.txm.rcp.testers.TreeSearchReady"
88
                        value="TreeSearchReady">
89
                  </test>
90
               </or>
91
            </visibleWhen>
92
         </command>
93
      </menuContribution>
94
      
95
      <menuContribution
96
            locationURI="popup:org.txm.concordance.rcp.editors.ConcordanceEditor">
97
         <command
98
               commandId="org.txm.treesearch.command.ComputeTreeSearch"
99
               icon="icons/functions/Tree.png"
100
               label="Send To TreeSearch"
101
               style="push">
102
         </command>
103
      </menuContribution>
104
   </extension>
105
   <extension
106
         point="org.eclipse.ui.preferencePages">
107
      <page
108
            category="org.txm.rcp.preferences.AdvancePreferencePage"
109
            class="org.txm.treesearch.preferences.TreeSearchPreferencePage"
110
            id="org.txm.treesearch.preferences.TreeSearchPreferencePage"
111
            name="Syntactic annotation">
112
      </page>
113
   </extension>
114

  
115
</plugin>
0 116

  
TXM/trunk/org.txm.treesearch.rcp/.settings/org.eclipse.jdt.core.prefs (revision 3311)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4
org.eclipse.jdt.core.compiler.compliance=1.8
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.8
0 8

  
TXM/trunk/org.txm.treesearch.rcp/.classpath (revision 3311)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="output" path="bin"/>
11
</classpath>
0 12

  
TXM/trunk/org.txm.treesearch.rcp/META-INF/MANIFEST.MF (revision 3311)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: org.txm.treesearch.rcp
4
Bundle-SymbolicName: org.txm.treesearch.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Automatic-Module-Name: org.txm.treesearch.rcp
7
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8
Require-Bundle: org.txm.rcp;bundle-version="0.8.2";visibility:=reexport,
9
 org.txm.treesearch.core;visibility:=reexport,
10
 org.txm.edition.rcp;bundle-version="1.0.0";visibility:=reexport
11
Export-Package: org.txm.treesearch.command,
12
 org.txm.treesearch.editor,
13
 org.txm.treesearch.rcp.tester
0 14

  
TXM/trunk/org.txm.treesearch.rcp/.project (revision 3311)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.treesearch.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  

Formats disponibles : Unified diff