Revision 2098

tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/QueryIndexEditor.java (revision 2098)
437 437
			public void keyPressed(KeyEvent e) {
438 438
				// System.out.println("key pressed : "+e.keyCode);
439 439
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
440
					compute();
440
					compute(true);
441 441
				}
442 442
			}
443 443

  
......
519 519
		go.addSelectionListener(new SelectionListener() {
520 520
			@Override
521 521
			public void widgetSelected(SelectionEvent e) {
522
				compute();
522
				compute(true);
523 523
			}
524 524

  
525 525
			@Override
tmp/org.txm.tigersearch.rcp/plugin.xml (revision 2098)
12 12
      <command
13 13
            categoryId="TIGERSearch4TXM.commands.category"
14 14
            id="org.txm.tigersearch.commands.ComputeTIGERSearch"
15
            name="%command.name">
15
            name="%command.name"
16
            returnTypeId="org.txm.function.tigersearch.TIGERSearch">
16 17
      </command>
17 18
      <command
18 19
            categoryId="TIGERSearch4TXM.commands.category"
......
202 203
            class="org.txm.searchengine.ts.TIGERSearchEngine">
203 204
      </SearchEngine>
204 205
   </extension>
206
   <extension
207
         point="org.eclipse.ui.preferencePages">
208
      <page
209
            category="org.txm.rcp.preferences.UserPreferencePage"
210
            class="org.txm.tigersearch.rcp.preferences.TIGERSearchPreferencePage"
211
            id="org.txm.tigersearch.rcp.preferences.TIGERSearchPreferencePage"
212
            name="TIGERSearch">
213
      </page>
214
   </extension>
215
   <extension
216
         point="org.eclipse.core.runtime.adapters">
217
      <factory
218
            adaptableType="org.txm.function.tigersearch.TIGERSearch"
219
            class="org.txm.tigersearch.rcp.TIGERSearchAdapterFactory">
220
         <adapter
221
               type="org.eclipse.ui.model.IWorkbenchAdapter">
222
         </adapter>
223
         <adapter
224
               type="org.eclipse.ui.model.IWorkbenchAdapter2">
225
         </adapter>
226
      </factory>
227
   </extension>
205 228

  
206 229
</plugin>
tmp/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java (revision 2098)
4 4
import java.util.Arrays;
5 5
import java.util.List;
6 6

  
7
import org.eclipse.core.runtime.IAdaptable;
8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.eclipse.jface.resource.ImageDescriptor;
10
import org.eclipse.ui.model.IWorkbenchAdapter;
11
import org.eclipse.ui.plugin.AbstractUIPlugin;
7
import org.txm.core.preferences.TXMPreferences;
8
import org.txm.core.results.Parameter;
12 9
import org.txm.core.results.TXMParameters;
13 10
import org.txm.core.results.TXMResult;
14 11
import org.txm.objects.CorpusBuild;
15
import org.txm.searchengine.cqp.corpus.CQPCorpus;
16
import org.txm.searchengine.cqp.corpus.MainCorpus;
17 12
import org.txm.searchengine.ts.TSCorpus;
18 13
import org.txm.searchengine.ts.TSCorpusManager;
19 14
import org.txm.searchengine.ts.TSMatch;
......
21 16
import org.txm.tigersearch.commands.ComputeTIGERSearch;
22 17
import org.txm.utils.logger.Log;
23 18

  
24
public class TIGERSearch extends TXMResult implements IAdaptable {
19
public class TIGERSearch extends TXMResult {
25 20

  
26 21
	protected TSCorpusManager manager;
27 22
	protected TSCorpus tscorpus;
......
29 24
	protected TSResult tsresult;
30 25
	protected String T, NT;
31 26
	protected CorpusBuild corpus;
32
	protected String query;
33 27

  
28
	@Parameter(key=TXMPreferences.QUERY)
29
	protected String pQuery;
30

  
34 31
	public CorpusBuild getCorpus() {
35 32
		return corpus;
36 33
	}
37
	
34

  
38 35
	public TIGERSearch(CorpusBuild corpus2) {
39 36
		super(corpus2);
40 37
		this.corpus = corpus2;
......
43 40
		File configfile = new File(corpus2.getProjectDirectory(),"tiger/tigersearch.logprop");
44 41
		File registrydir = new File(corpus2.getProjectDirectory(), "tiger");
45 42
		File tscorpusdir = new File(corpus2.getProjectDirectory(), "tiger/"+id);
46
		
43

  
47 44
		if (!tscorpusdir.exists()) {
48 45
			System.out.println("Error: can't find corpus directory: "+tscorpusdir);
49 46
			return;
......
64 61
		}
65 62
	}
66 63

  
67
	public boolean compute(String query) throws Exception {
68
		if (tscorpus == null) return false;
69
		tsresult = null;
70
		if (query.length() == 0) {
71
			return false;
72
		}
73
		this.query = query;
74
		tsresult = tscorpus.query(query);
75
		tsresult.getFirst();
76
		return true;
77
	}
78
	
79 64
	public TSResult getTSResult() {
80 65
		return tsresult;
81 66
	}
82
	
67

  
83 68
	public boolean isComputed() {
84 69
		return tsresult != null;
85 70
	}
86
	
71

  
87 72
	public boolean isDrawn() {
88 73
		return tsresult!= null && T != null && NT != null;
89 74
	}
......
92 77
		if (tsresult == null) return false; // no result
93 78
		this.T = T;
94 79
		this.NT = NT;
95
		
80

  
96 81
		tsresult.setDisplayProperties(Arrays.asList(T), NT);
97
		
82

  
98 83
		try {
99 84
			// iterate to the sub th subgraph
100 85
			TSMatch match = tsresult.getMatch(sent);
......
148 133
		if (tsresult == null) return 0;
149 134
		return tsresult.getCurrentMatch().getNumberOfSubGraph();
150 135
	}
151
	
136

  
152 137
	public int getSent() {
153 138
		if (tsresult == null) return 0;
154 139
		return tsresult.getCurrentMatchNo();
155 140
	}
156
	
141

  
157 142
	public int getSub() {
158 143
		if (tsresult == null) return 0;
159 144
		return tsresult.getCurrentMatch().getCurrentSubMatchNo();
160 145
	}
161
	
162
	/** The WordCloud adapter. */
163
	private static IWorkbenchAdapter tsAdapter = new IWorkbenchAdapter() {
164 146

  
165
		@Override
166
		public Object[] getChildren(Object o) {
167
			return new Object[0];
168
		}
169

  
170
		@Override
171
		public ImageDescriptor getImageDescriptor(Object object) {
172
			return AbstractUIPlugin.imageDescriptorFromPlugin("org.txm.tigersearch.rcp", "icons/functions/TS.png"); //$NON-NLS //$NON-NLS-1$
173
		}
174

  
175
		@Override
176
		public String getLabel(Object o) {
177
			String q = ((TIGERSearch) o).getQuery();
178
			if (q != null) {
179
				return q.substring(0, Math.min(10, q.length())).replaceAll("\n", "")+"...";
180
			} else {
181
				return ((TIGERSearch) o).getCorpus().getName();
182
			}
183
		}
184

  
185
		@Override
186
		public Object getParent(Object o) {
187
			return ((TIGERSearch) o).getParent();
188
		}
189
	};
190
	
191
	
192
	@Override
193
	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapterType) {
194
		if (adapterType == IWorkbenchAdapter.class)
195
			return tsAdapter;
196
		return null;
197
	}
198

  
199 147
	public String getQuery() {
200
		return query;
148
		return pQuery;
201 149
	}
202
	
150

  
203 151
	public String toString() {
204
		if (query != null)
205
			return query.substring(0, Math.min(20,  query.length())).replaceAll("\n", " ")+" T: "+T+" NT: "+NT;
206
		
152
		if (pQuery != null)
153
			return pQuery.substring(0, Math.min(20,  pQuery.length())).replaceAll("\n", " ")+" T: "+T+" NT: "+NT;
154

  
207 155
		return ""+corpus;
208 156
	}
209 157

  
......
211 159
		ComputeTIGERSearch.openEditor(this);
212 160
		return true;
213 161
	}
214
	
162

  
215 163
	@Override
216 164
	public boolean toTxt(File outfile, String encoding, String colseparator,
217 165
			String txtseparator) throws Exception {
......
220 168

  
221 169
	@Override
222 170
	public void clean() {
223
		
171

  
224 172
	}
225
	
173

  
226 174
	/**
227 175
	 * 
228 176
	 * @return the array of extensions to show in the FileDialog SWT widget
......
233 181

  
234 182
	@Override
235 183
	public String getName() {
236
		return query;
184
		return pQuery;
237 185
	}
238 186

  
239 187
	@Override
240 188
	public String getSimpleName() {
241
		return query;
189
		return pQuery;
242 190
	}
243 191

  
244 192
	@Override
245 193
	public String getDetails() {
246
		return query;
194
		return pQuery;
247 195
	}
248 196

  
249 197
	@Override
250 198
	public boolean canCompute() {
251
		return corpus != null && query != null && query.length() > 0;
199
		return corpus != null && pQuery != null && pQuery.length() > 0;
252 200
	}
253 201

  
254 202
	@Override
255 203
	public boolean setParameters(TXMParameters parameters) {
256
		// FIXME: not yet implemented
257
		System.err.println("TIGERSearch.setParameters(): not yet implemented.");
258
		return false;
204
		if (parameters.getString("query") != null) {
205
			this.pQuery = parameters.getString("query");
206
		}
207
		return true;
259 208
	}
260 209

  
261 210
	@Override
262 211
	public boolean saveParameters() throws Exception {
263
		// FIXME: not yet implemented
264
		System.err.println("TIGERSearch.saveParameters(): not yet implemented.");
265
		return false;
212
		return true;
266 213
	}
267 214

  
268 215
	@Override
269 216
	public boolean loadParameters() throws Exception {
270
		// FIXME: not yet implemented
271
		System.err.println("TIGERSearch.loadParameters(): not yet implemented.");
272
		return false;
217
		return true;
273 218
	}
274 219

  
275 220
	@Override
276 221
	protected boolean _compute() throws Exception {
277
		// FIXME: not yet implemented
278
		System.err.println("TIGERSearch._compute(): not yet implemented.");
279
		return false;
222

  
223
		if (tscorpus == null) return false;
224
		tsresult = null;
225
		if (pQuery.length() == 0) {
226
			return false;
227
		}
228
		tsresult = tscorpus.query(pQuery);
229
		tsresult.getFirst();
230
		return true;
280 231
	}
281
	
232

  
282 233
	@Override
283 234
	public String getResultType() {
284 235
		return "Tiger search";
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/commands/ComputeTIGERSearch.java (revision 2098)
82 82
		}
83 83
		
84 84
		try {
85
			TIGERSearchEditor.openEditor(ts,TIGERSearchEditor.ID); //$NON-NLS-1$
85
			TIGERSearchEditor.openEditor(ts, TIGERSearchEditor.ID); //$NON-NLS-1$
86 86
		} catch (Exception e) {
87 87
			Log.printStackTrace(e);
88 88
		}
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/rcp/TIGERSearchAdapterFactory.java (revision 2098)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.tigersearch.rcp;
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

  
10
import ims.tiger.gui.tigersearch.TIGERSearch;
11

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

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

  
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/rcp/preferences/TIGERSearchPreferences.java (revision 2098)
1
package org.txm.tigersearch.rcp.preferences;
2

  
3

  
4
import org.osgi.service.prefs.Preferences;
5
import org.txm.core.preferences.TXMPreferences;
6

  
7
/**
8
 * Preferences initializer and manager.
9
 * 
10
 * @author sjacquot
11
 *
12
 */
13
public class TIGERSearchPreferences extends TXMPreferences {
14

  
15
		
16
	/**
17
	 * Gets the instance.
18
	 * @return the instance
19
	 */
20
	public static TXMPreferences getInstance()	{
21
		if (!TXMPreferences.instances.containsKey(TIGERSearchPreferences.class)) {
22
			new TIGERSearchPreferences();
23
		}
24
		return TXMPreferences.instances.get(TIGERSearchPreferences.class);
25
	}
26

  
27
	
28
	@Override
29
	public void initializeDefaultPreferences() {
30
		super.initializeDefaultPreferences();
31
		
32
		Preferences preferences = this.getDefaultPreferencesNode();
33
//		preferences.putBoolean(GROUP_BY_TEXTS, true);
34
//		preferences.putInt(METHOD, 2);
35
	}
36
}
37

  
38

  
0 39

  
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/rcp/preferences/TIGERSearchPreferencePage.java (revision 2098)
1
package org.txm.tigersearch.rcp.preferences;
2

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

  
8
/**
9
 * TIGERSearch preference page
10
 * @author mdecorde
11
 *
12
 */
13
public class TIGERSearchPreferencePage extends TXMPreferencePage {
14

  
15
	@Override
16
	public void createFieldEditors() {
17
//		this.addField(new ComboFieldEditor(TIGERSearchPreferences.METHOD, "Method", methods, chartsTab));
18
//		this.addField(new BooleanFieldEditor(TIGERSearchPreferences.GROUP_BY_TEXTS, "Group by words", chartsTab));
19
	}
20
	
21
	/*
22
	 * (non-Javadoc)
23
	 * 
24
	 * @see
25
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
26
	 */
27
	@Override
28
	public void init(IWorkbench workbench) {
29
		this.setPreferenceStore(new TXMPreferenceStore(TIGERSearchPreferences.getInstance().getPreferencesNodeQualifier()));
30
		this.setDescription("TIGERSearch");
31
		this.setImageDescriptor(IImageKeys.getImageDescriptor(this.getClass(), "icons/functions/TS.png"));
32
	}
33
}
0 34

  
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/editors/TSIndexEditor.java (revision 2098)
285 285
	/**
286 286
	 * Compute index.
287 287
	 */
288
	public void compute() {
288
	public void _compute() {
289 289
		StatusLine.setMessage(IndexUIMessages.computingIndex);
290 290
		final CQLQuery query; // if the query is empty then we put "[]" instead
291 291
		if (queryWidget.isDisposed()) { // lexicon editor
......
526 526
			@Override
527 527
			public void handleEvent(Event event) {
528 528
				if (!initializing && RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR))
529
					compute();
529
					compute(true);
530 530
			}
531 531
		});
532 532

  
......
534 534
			@Override
535 535
			public void keyPressed(KeyEvent e) {
536 536
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
537
					compute();
537
					compute(true);
538 538
				}
539 539
			}
540 540
			@Override
......
560 560
		SelectionListener listener2 = new SelectionListener() {
561 561
			@Override
562 562
			public void widgetSelected(SelectionEvent e) {
563
				compute();
563
				compute(true);
564 564
			}
565 565
			@Override
566 566
			public void widgetDefaultSelected(SelectionEvent e) { }
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/editors/TIGERSearchEditor.java (revision 2098)
39 39

  
40 40

  
41 41
public class TIGERSearchEditor extends TXMEditor<TIGERSearch> {
42
	
42

  
43 43
	/** The Constant ID. */
44 44
	public static final String ID = "org.txm.tigersearch.editors.TIGERSearchEditor"; //$NON-NLS-1$
45 45

  
......
68 68

  
69 69
		// System.out.println(parent.getLayout());
70 70
		Composite queryPanel = this.getExtendedParametersGroup();
71
	
71

  
72 72
		// fill query Area
73 73
		GridLayout qlayout = new GridLayout(11, false);
74 74
		queryPanel.setLayout(qlayout);
......
138 138
		okButton.addSelectionListener(new SelectionListener() {
139 139
			@Override
140 140
			public void widgetSelected(SelectionEvent e) {
141
				compute();
141
				compute(true);
142 142
			}
143 143

  
144 144
			@Override
......
149 149
				if (e.stateMask == SWT.CTRL)
150 150
					if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
151 151
						e.doit = false;
152
						compute();
152
						compute(true);
153 153
					}
154 154
			}
155 155
		});
......
157 157
		Composite mainPanel = this.getResultArea();
158 158
		svgPanel = new SVGComposite(mainPanel, SWT.EMBEDDED | SWT.NO_BACKGROUND);
159 159
		svgPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
160
		
160

  
161 161
		initializeFields();
162 162
	}
163 163

  
......
223 223
					sentSpinner.setMaximum(ts.getNSentences());
224 224
					subSpinner.setSelection(ts.getSub());
225 225
					subSpinner.setMaximum(ts.getNSubGraph());
226
					
226

  
227 227
					reloadGraph();
228 228
				} else {
229 229
					sentSpinner.setSelection(1);
......
257 257
		return svgFile;
258 258
	}
259 259

  
260
	public void compute() {
261
		final String query = queryArea.getText().trim();
262
		if (query.length() == 0) {
263
			System.out.println("No query, aborting.");
264
			return;
265
		}
260
	@Override
261
	public void updateResultFromEditor() {
262
		// FIXME: not yet implemented
263
		System.err.println("TIGERSearchEditor.updateResultFromEditor(): not yet implemented.");
264
	}
266 265

  
267
		JobHandler jobhandler = new JobHandler("", this.svgPanel.getParent()) {
268
			@Override
269
			protected IStatus run(IProgressMonitor monitor) {
270
				try {
271
					try {
272
						ts.compute(query);
273
						if (ts.isComputed() && !isStored) {
274
							isStored = true;
275
						}
276
					} catch(Exception e) {
277
						System.out.println("TIGERSearch error: "+e);
278
						return Status.CANCEL_STATUS;
279
					}
266
	@Override
267
	public void updateEditorFromResult(boolean update) {
268
		//		final String query = queryArea.getText().trim();
269
		//		if (query.length() == 0) {
270
		//			System.out.println("No query, aborting.");
271
		//			return;
272
		//		}
280 273

  
281
					this.syncExec(new Runnable() {
282
						@Override
283
						public void run() {
274
		//		JobHandler jobhandler = new JobHandler("", this.svgPanel.getParent()) {
275
		//			@Override
276
		//			protected IStatus run(IProgressMonitor monitor) {
277
		try {
278
			//					try {
279
			//						ts.compute(query);
280
			//						if (ts.isComputed() && !isStored) {
281
			//							isStored = true;
282
			//						}
283
			//					} catch(Exception e) {
284
			//						System.out.println("TIGERSearch error: "+e);
285
			//						return Status.CANCEL_STATUS;
286
			//					}
284 287

  
285
							sentCounterLabel.setText("/"+ts.getNSentences());
286
							subCounterLabel.setText("/"+ts.getNSubGraph());
287
							sentSpinner.setSelection(1);
288
							sentSpinner.setMaximum(ts.getNSentences());
289
							subSpinner.setSelection(1);
290
							subSpinner.setMaximum(ts.getNSubGraph());
288
			//					this.syncExec(new Runnable() {
289
			//						@Override
290
			//						public void run() {
291 291

  
292
							reloadGraph();
292
			sentCounterLabel.setText("/"+ts.getNSentences());
293
			subCounterLabel.setText("/"+ts.getNSubGraph());
294
			sentSpinner.setSelection(1);
295
			sentSpinner.setMaximum(ts.getNSentences());
296
			subSpinner.setSelection(1);
297
			subSpinner.setMaximum(ts.getNSubGraph());
293 298

  
294
							CorporaView.refresh();
295
							CorporaView.expand(corpus);
296
							QueriesView.refresh();
297
							RVariablesView.refresh();
299
			reloadGraph();
298 300

  
299
							System.out.println("Done.");
300
						}
301
					});
302
				} catch (Exception e) {
303
					System.out.println("Error while computing the TIGERSearch: "+e);
304
					Log.printStackTrace(e);
305
				} finally {
306
					monitor.done();
307
				}
308
				JobsTimer.stopAndPrint();
309
				return Status.OK_STATUS;
310
			}
311
		};
312
		jobhandler.startJob();
301
			CorporaView.refresh();
302
			CorporaView.expand(corpus);
303
			QueriesView.refresh();
304
			RVariablesView.refresh();
305

  
306
			System.out.println("Done.");
307
			//						}
308
			//					});
309
		} catch (Exception e) {
310
			System.out.println("Error while computing the TIGERSearch: "+e);
311
			Log.printStackTrace(e);
312
		}
313
		//				JobsTimer.stopAndPrint();
314
		//				return Status.OK_STATUS;
315
		//			}
316
		//		};
317
		//		jobhandler.startJob();
313 318
	}
314 319

  
315 320
	/**
......
351 356
			throws PartInitException {
352 357
		setSite(site);
353 358
		setInput(input);
354
		
359

  
355 360
		File resultDir = new File(Toolbox.getTxmHomePath(), "results"); //$NON-NLS-1$
356 361
		resultDir.mkdirs();
357 362
		try {
......
361 366
			Log.printStackTrace(e);
362 367
		} //$NON-NLS-1$ //$NON-NLS-2$
363 368
		Log.fine(svgFile.toString());
364
		
369

  
365 370
		TXMResultEditorInput<TIGERSearch> ii = (TXMResultEditorInput<TIGERSearch>) input;
366 371
		ts = ii.getResult();
367 372
		corpus = ts.getCorpus();
368 373
	}
369

  
370
	@Override
371
	public void updateResultFromEditor() {
372
		// FIXME: not yet implemented
373
		System.err.println("TIGERSearchEditor.updateResultFromEditor(): not yet implemented.");
374
	}
375

  
376
	@Override
377
	public void updateEditorFromResult(boolean update) {
378
		// FIXME: not yet implemented
379
		System.err.println("TIGERSearchEditor.updateEditorFromResult(): not yet implemented.");
380
	}
381

  
382

  
383 374
}

Also available in: Unified diff