Révision 843

tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/SendToCooccurrence.java (revision 843)
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.index.rcp.handlers;
29

  
30
import org.eclipse.core.commands.ExecutionEvent;
31
import org.eclipse.core.commands.ExecutionException;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.ui.handlers.HandlerUtil;
34
import org.txm.core.preferences.TXMPreferences;
35
import org.txm.core.results.TXMResult;
36
import org.txm.index.core.functions.Index;
37
import org.txm.index.core.functions.Line;
38
import org.txm.rcp.editors.TXMEditor;
39
import org.txm.rcp.handlers.BaseAbstractHandler;
40
import org.txm.searchengine.cqp.corpus.Corpus;
41

  
42
/**
43
 * Sends the selected lines of an index to compute a cooccurrence.
44
 * 
45
 * @author mdecorde.
46
 */
47
public class SendToCooccurrence extends BaseAbstractHandler {
48

  
49
	@Override
50
	public Object execute(ExecutionEvent event) throws ExecutionException {
51
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
52

  
53
		if (selection != null && selection.getFirstElement() instanceof Line) {
54
			
55
			String query = Index.createQuery(selection.toList());
56

  
57
			TXMEditor editor = (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
58

  
59
			// create local result node, store it some parameters and call the linked command
60
			String uuid = TXMResult.createUUID();
61
			TXMResult parentCorpus = Corpus.getFirstParentCorpus(editor.getResult());
62
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, parentCorpus.getUUID());
63
			TXMPreferences.put(uuid, TXMPreferences.QUERY, query);
64
			BaseAbstractHandler.executeCommand("org.txm.cooccurrence.rcp.handlers.ComputeCooccurrences", uuid); //$NON-NLS-1$
65
		}
66
		else	{
67
			this.logCanNotCompute(selection);
68
		}
69
		return null;
70
	}
71

  
72

  
73
}
0 74

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/SendToProgression.java (revision 843)
39 39
import org.txm.index.core.functions.Line;
40 40
import org.txm.rcp.editors.TXMEditor;
41 41
import org.txm.rcp.handlers.BaseAbstractHandler;
42
import org.txm.searchengine.cqp.corpus.Corpus;
42 43
import org.txm.searchengine.cqp.corpus.query.Query;
43 44

  
44 45
/**
45
 * Sends the lines of an index to compute a progression.
46
 * Sends the selected lines of an index to compute a progression.
46 47
 * 
47 48
 * @author mdecorde
48 49
 * @author sjacquot
......
61 62

  
62 63
			TXMEditor editor = (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
63 64

  
64
			// FIXME: tests:
65
			// 1) create an UUID for the future TXMResult
66
			// 2) store some parameters in the local preference node
67
			// 3) call the command in the command target plug-in
68
			//String uuid = "test_link_index_to_progression"; 
65
			// create local result node, store it some parameters and call the linked command
69 66
			String uuid = TXMResult.createUUID();
70
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, editor.getResult().getParent().getUUID());
67
			TXMResult parentCorpus = Corpus.getFirstParentCorpus(editor.getResult());
68
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, parentCorpus.getUUID());
71 69
			TXMPreferences.put(uuid, TXMPreferences.QUERIES, Query.queriesToString(queries));
72 70
			BaseAbstractHandler.executeCommand("org.txm.progression.rcp.handlers.ComputeProgression", uuid); //$NON-NLS-1$
73 71
		}
tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/SendToConcordance.java (revision 843)
40 40
import org.txm.searchengine.cqp.corpus.Corpus;
41 41

  
42 42
/**
43
 * Sends the lines of an index to compute a concordance.
43
 * Sends the selected lines of an index to compute a concordance.
44 44
 * 
45 45
 * @author mdecorde
46 46
 * @author sjacquot
......
60 60

  
61 61
			TXMEditor editor = (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
62 62

  
63
			// FIXME: tests:
64
			// 1) create an UUID for the future TXMResult
65
			// 2) store some parameters in the local preference node
66
			// 3) call the command in the command target plug-in
67
			//String uuid = "test_link_index_to_concordance";
63
			// create local result node, store it some parameters and call the linked command
68 64
			String uuid = TXMResult.createUUID();
69
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, editor.getResult().getParent().getUUID());
65
			TXMResult parentCorpus = Corpus.getFirstParentCorpus(editor.getResult());
66
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, parentCorpus.getUUID());
70 67
			TXMPreferences.put(uuid, TXMPreferences.QUERY, query);
71 68
			BaseAbstractHandler.executeCommand("org.txm.concordance.rcp.handlers.ComputeConcordance", uuid); //$NON-NLS-1$
72 69
		}
......
76 73
		return null;
77 74
	}
78 75

  
76
	// FIXME: not used anymore?
79 77
//	/**
80 78
//	 * Link.
81 79
//	 *
tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/ComputeIndex.java (revision 843)
29 29

  
30 30
import org.eclipse.core.commands.ExecutionEvent;
31 31
import org.eclipse.core.commands.ExecutionException;
32
import org.txm.core.preferences.TXMPreferences;
32 33
import org.txm.index.core.functions.Index;
33 34
import org.txm.index.rcp.editors.IndexEditor;
34 35
import org.txm.rcp.editors.TXMEditor;
......
52 53
			return false;
53 54
		}
54 55

  
55
		Object selection = this.getSelection(event);
56
		Index index = null;
56 57
		
57
		// New editor from corpus
58
		Index index = null;
59
		if (selection instanceof Corpus) {
60
			index = new Index((Corpus) selection);
58
		// From link: creating from UUID and preferences nodes
59
		String uuid = event.getParameter(TXMPreferences.RESULT_UUID);
60
		if (uuid != null && !uuid.isEmpty()) {
61
			index = new Index(uuid);
61 62
		}
62
		// New editor from partition
63
		else if (selection instanceof Partition) {
64
			index = new Index((Partition) selection);
63
		// From view result node
64
		else	{
65
			Object selection = this.getSelection(event);
66
			
67
			// New editor from corpus
68
			if (selection instanceof Corpus) {
69
				index = new Index((Corpus) selection);
70
			}
71
			// New editor from partition
72
			else if (selection instanceof Partition) {
73
				index = new Index((Partition) selection);
74
			}
75
			// Reopen an existing result
76
			else if (selection instanceof Index) { 
77
				index = (Index) selection;
78
			}
79
			else {
80
				return super.logCanNotCompute(selection);
81
			}
65 82
		}
66
		// Reopen an existing result
67
		else if (selection instanceof Index) { 
68
			index = (Index) selection;
69
		}
70
		else {
71
			return super.logCanNotCompute(selection);
72
		}
73 83
		
74
		open(index);
84
		TXMEditor.openEditor(index, IndexEditor.class.getName());
75 85
		
76 86
		return null;
77 87
	}
78 88

  
79
	public static void open(Index index) {
80
		TXMEditor.openEditor(index, IndexEditor.class.getName());
81
	}
82 89
}
tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/SendToIndex.java (revision 843)
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.index.rcp.handlers;
29

  
30
import org.eclipse.core.commands.ExecutionEvent;
31
import org.eclipse.core.commands.ExecutionException;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.ui.handlers.HandlerUtil;
34
import org.txm.core.preferences.TXMPreferences;
35
import org.txm.core.results.TXMResult;
36
import org.txm.index.core.functions.Index;
37
import org.txm.index.core.functions.Line;
38
import org.txm.rcp.editors.TXMEditor;
39
import org.txm.rcp.handlers.BaseAbstractHandler;
40

  
41
/**
42
 * Sends the selected lines of a lexicon to compute an index.
43
 * 
44
 * @author mdecorde
45
 * @author sjacquot
46
 * 
47
 */
48
public class SendToIndex extends BaseAbstractHandler {
49

  
50

  
51
	@Override
52
	public Object execute(ExecutionEvent event) throws ExecutionException {
53
		
54
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
55

  
56
		if (selection != null && selection.getFirstElement() instanceof Line) {
57
			
58
			String query = Index.createQuery(selection.toList());
59

  
60
			TXMEditor editor = (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
61

  
62
			// create local result node, store it some parameters and call the linked command
63
			String uuid = TXMResult.createUUID();
64
			TXMPreferences.put(uuid, TXMPreferences.PARENT_UUID, editor.getResult().getParent().getUUID());
65
			TXMPreferences.put(uuid, TXMPreferences.QUERY, query);
66
			BaseAbstractHandler.executeCommand("org.txm.index.rcp.handlers.ComputeIndex", uuid); //$NON-NLS-1$
67
		}
68
		else	{
69
			this.logCanNotCompute(selection);
70
		}
71
		return null;
72
	}
73

  
74
	// FIXME: not used anymore?
75
//	/**
76
//	 * Link.
77
//	 *
78
//	 * @param voceditor the voceditor
79
//	 * @param selection the selection
80
//	 * @return the object
81
//	 */
82
//	public static Object link(IndexEditor voceditor,
83
//			IStructuredSelection selection) {
84
//		assert (selection.getFirstElement() instanceof Line);
85
//		String query = getQuery(selection);
86
//		if (query.length() == 0)
87
//			return null;
88
//		Corpus corpus = voceditor.getCorpus();
89
//		Concordance concordance = new Concordance(corpus);
90
//		concordance.setParameters(new Query(query), null, null, null, null, null, null, null, null, null, null);
91
//		TXMResultEditorInput editorInput = new TXMResultEditorInput(concordance);
92
////		try {
93
////			System.out.println("Compute indexResult query: "+voceditor.getQuery());
94
////			QueryResult indexResult = corpus.query(voceditor.getQuery(), "Index", false);
95
////			System.out.println("N result: "+indexResult.getNMatch());
96
////
97
////			System.out.println("Compute indexOccResult query: "+query);
98
////			QueryResult indexOccResult = corpus.query(new Query(query), "IndexOcc", false);
99
////			System.out.println("N result: "+indexOccResult.getNMatch());
100
////
101
////			String queryname = "Q"+Corpus.getNextQueryCounter();
102
////			String interQueryString = queryname+"=intersect "+indexResult.getQualifiedCqpId()+" "+indexOccResult.getQualifiedCqpId()+";"; 
103
////			System.out.println("Compute inter query: "+interQueryString);
104
////			((MemCqiClient)CQPSearchEngine.getCqiClient()).query(interQueryString);
105
////			
106
////			QueryResult inter = new QueryResult(queryname, queryname, corpus, new Query(interQueryString));
107
////			System.out.println("indexResult size: "+indexResult.getNMatch());
108
////			System.out.println("indexOccResult size: "+indexOccResult.getNMatch());
109
////			System.out.println("inter size: "+inter.getNMatch());
110
////			
111
////			QueryResult inter2 = corpus.query(new Query("intersect "+indexResult.getQualifiedCqpId()+" "+indexOccResult.getQualifiedCqpId()), "Q"+Corpus.getNextQueryCounter(),false);
112
////			System.out.println("inter2 size: "+inter2.getNMatch());
113
////		} catch (Exception e) {
114
////			e.printStackTrace();
115
////			try {
116
////				System.out.println("CQP error: "+CQPSearchEngine.getCqiClient().getLastError());
117
////			} catch (Exception e1) {
118
////				e1.printStackTrace();
119
////			}
120
////		}
121
////		
122
////		return null;
123
//
124
//		IWorkbenchPage page = voceditor.getEditorSite().getWorkbenchWindow()
125
//				.getActivePage();
126
//		try {
127
//			ConcordanceEditor conceditor = (ConcordanceEditor) page
128
//					.openEditor(editorInput, ConcordanceEditor.ID); //$NON-NLS-1$
129
//		} catch (PartInitException e) {
130
//			System.err.println("Error: "+e.getLocalizedMessage());
131
//		}
132
//
133
//		return null;
134
//	}
135

  
136

  
137
}
0 138

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 843)
41 41
import org.eclipse.swt.layout.FormLayout;
42 42
import org.eclipse.swt.layout.GridData;
43 43
import org.eclipse.swt.layout.GridLayout;
44
import org.eclipse.swt.widgets.Button;
45 44
import org.eclipse.swt.widgets.Composite;
46 45
import org.eclipse.swt.widgets.Display;
47 46
import org.eclipse.swt.widgets.Label;
......
386 385
		Composite resultArea = this.getResultArea();
387 386

  
388 387
		viewer = new TableViewer(resultArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
389
		this.getSite().setSelectionProvider(viewer);
390 388
		
391 389
		viewer.getTable().setLinesVisible(true);
392 390
		viewer.getTable().setHeaderVisible(true);
......
407 405
		viewer.setContentProvider(new LineContentProvider());
408 406
		viewer.setInput(new ArrayList<Property>());
409 407

  
410
		//TODO replace this with command+menucontribution		
411
		//		viewer.getTable().addMouseListener(new MouseAdapter() {
412
		//			@Override
413
		//			public void mouseDoubleClick(MouseEvent e) {
414
		//				Point mouseposition = new Point(e.x
415
		//						+ viewer.getTable().getHorizontalBar()
416
		//						.getSelection(), e.y);
417
		//				int col = getPointedColumn(mouseposition);
418
		//				if (col == 1) {
419
		//					IndexToConcordance.link(IndexEditor.this,
420
		//							(IStructuredSelection) viewer
421
		//							.getSelection());
422
		//				} else if (col == 2) {
423
		//					IndexToProgression.link(IndexEditor.this,
424
		//							(IStructuredSelection) viewer
425
		//							.getSelection());
426
		//				}
427
		//			}
428
		//		});
429

  
430 408
		nColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
431 409
		nColumn.setText(" "); //$NON-NLS-1$
432 410
		nColumn.pack();
......
521 499
		separatorColumn.pack();
522 500
		paramArea.pack();
523 501

  
502
		// Add double click, "Send to" command
503
		TXMEditor.addDoubleClickCommandListener(viewer.getTable(), "org.txm.links.rcp.commands.SendToConcordance"); //$NON-NLS-1$
504

  
524 505
		// Register the context menu
525 506
		TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer);
526 507
		
tmp/org.txm.index.rcp/build.properties (revision 843)
4 4
               .,\
5 5
               plugin.xml,\
6 6
               icons/,\
7
               OSGI-INF/,\
8
               OSGI-INF/l10n/bundle.properties
7
               OSGI-INF/
tmp/org.txm.index.rcp/plugin.xml (revision 843)
127 127
               style="push">
128 128
         </command>
129 129
      </menuContribution>
130
               <menuContribution
131
                     locationURI="popup:org.txm.index.rcp.editors.DictionnaryEditor">
132
                  <command
133
                        commandId="org.txm.links.rcp.commands.SendToConcordance"
134
                        style="push">
135
                  </command>
136
                  <command
137
                        commandId="org.txm.links.rcp.commands.SendToIndex"
138
                        style="push">
139
                  </command>
140
                  <command
141
                        commandId="org.txm.links.rcp.commands.SendToProgression"
142
                        style="push">
143
                  </command>
144
               </menuContribution>
130 145
      
131 146
   </extension>
132 147
   <extension
......
179 194
            id="org.txm.index.rcp.handlers.ComputeLexicon"
180 195
            name="%command.name.0">
181 196
      </command>
182
                        <command
183
            defaultHandler="org.txm.synopticedition.rcp.commands.link.IndexToConcordance"
184
            id="org.txm.synopticedition.rcp.commands.link.IndexToConcordance"
185
            name="%command.label.73">
186
      </command>
187 197

  
188 198
      <command
189
            defaultHandler="org.txm.index.rcp.handlers.SendToProgression"
190
            id="org.txm.index.rcp.handlers.IndexToProgression"
191
            name="%command.label.103">
192
      </command>
193
      <command
194 199
            defaultHandler="org.txm.synopticedition.rcp.commands.link.IndexToLexicalTable"
195 200
            id="org.txm.synopticedition.rcp.commands.link.IndexToLexicalTable"
196 201
            name="%command.name.43">
197 202
      </command>
198 203
      
199
      <command
200
            defaultHandler="org.txm.synopticedition.rcp.commands.link.IndexToCooccurrence"
201
            id="org.txm.synopticedition.rcp.commands.link.IndexToCooccurrence"
202
            name="%command.name.65">
203
      </command>
204 204
      
205 205
   </extension>
206 206
   <extension
......
231 231
            </iterate>
232 232
         </with>
233 233
      </definition>
234
      <definition
235
            id="IndexEditorActive">
236
         <with
237
               variable="activePart">
238
            <instanceof
239
                  value="org.txm.index.rcp.editors.IndexEditor">
240
            </instanceof>
241
         </with>
242
      </definition>
243
      <definition
244
            id="LexiconEditorActive">
245
         <with
246
               variable="activePart">
247
            <instanceof
248
                  value="org.txm.index.rcp.editors.DictionnaryEditor">
249
            </instanceof>
250
         </with>
251
      </definition>
234 252
   </extension>
235 253
   <extension
236 254
         point="org.txm.statengine.r.rcp.sendtor">
......
250 268
      <handler
251 269
            class="org.txm.index.rcp.handlers.SendToProgression"
252 270
            commandId="org.txm.links.rcp.commands.SendToProgression">
271
         <activeWhen>
272
         <or>
273
           <reference
274
                 definitionId="IndexEditorActive">
275
           </reference>
276
           <reference
277
                 definitionId="LexiconEditorActive">
278
           </reference>
279
         
280
         </or>
281
         
282
         </activeWhen>
253 283
      </handler>
254 284
      <handler
255 285
            class="org.txm.index.rcp.handlers.SendToConcordance"
256 286
            commandId="org.txm.links.rcp.commands.SendToConcordance">
287
         <activeWhen>
288
            <or>
289
               <reference
290
                     definitionId="IndexEditorActive">
291
               </reference>
292
               <reference
293
                     definitionId="LexiconEditorActive">
294
               </reference>
295
            </or>
296
         </activeWhen>
257 297
      </handler>
298
      <handler
299
            class="org.txm.index.rcp.handlers.SendToCooccurrence"
300
            commandId="org.txm.links.rcp.commands.SendToCooccurrence">
301
         <activeWhen>
302
               <reference
303
                     definitionId="IndexEditorActive">
304
               </reference>
305
         </activeWhen>
306
      </handler>
307
      <handler
308
            class="org.txm.index.rcp.handlers.SendToIndex"
309
            commandId="org.txm.links.rcp.commands.SendToIndex">
310
         <activeWhen>
311
               <reference
312
                     definitionId="LexiconEditorActive">
313
               </reference>
314
         </activeWhen>
315
      </handler>
258 316
   </extension>
259 317

  
260 318
</plugin>

Formats disponibles : Unified diff