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.rcpapplication.commands.function;
|
29 |
|
|
30 |
|
import org.eclipse.core.commands.AbstractHandler;
|
31 |
|
import org.eclipse.core.commands.ExecutionEvent;
|
32 |
|
import org.eclipse.core.commands.ExecutionException;
|
33 |
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
34 |
|
import org.eclipse.ui.IWorkbenchPage;
|
35 |
|
import org.eclipse.ui.handlers.HandlerUtil;
|
36 |
|
import org.txm.Toolbox;
|
37 |
|
import org.txm.index.rcp.editors.IndexEditorInput;
|
38 |
|
import org.txm.rcpapplication.TXMWindows;
|
39 |
|
import org.txm.rcpapplication.editors.dictionnary.DictionnaryEditor;
|
40 |
|
import org.txm.searchengine.cqp.corpus.Corpus;
|
41 |
|
|
42 |
|
// TODO: Auto-generated Javadoc
|
43 |
|
/**
|
44 |
|
* Compute a Lexicon used it to create a Index (object) then open it in the
|
45 |
|
* DictionnaryEditor @ author mdecorde.
|
46 |
|
*/
|
47 |
|
public class ComputeLexicon extends AbstractHandler {
|
48 |
|
|
49 |
|
/* (non-Javadoc)
|
50 |
|
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
51 |
|
*/
|
52 |
|
@Override
|
53 |
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
54 |
|
if (!Toolbox.isSearchEngineInitialized()) return false;
|
55 |
|
|
56 |
|
//window = HandlerUtil.getActiveWorkbenchWindow(event);
|
57 |
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
|
58 |
|
|
59 |
|
assert (selection.getFirstElement() instanceof Corpus);
|
60 |
|
|
61 |
|
final Corpus corpus = (Corpus) selection.getFirstElement();
|
62 |
|
|
63 |
|
openEditor(corpus);
|
64 |
|
|
65 |
|
return null;
|
66 |
|
}
|
67 |
|
|
68 |
|
public static boolean openEditor(Corpus corpus) {
|
69 |
|
if (!Toolbox.isSearchEngineInitialized()) return false;
|
70 |
|
|
71 |
|
IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage();
|
72 |
|
IndexEditorInput editorInput = new IndexEditorInput(corpus);
|
73 |
|
DictionnaryEditor voceditor;
|
74 |
|
try {
|
75 |
|
voceditor = (DictionnaryEditor) page.openEditor(editorInput,
|
76 |
|
"org.txm.rcpapplication.editors.dictionnary.DictionnaryEditor"); //$NON-NLS-1$
|
77 |
|
voceditor.compute();
|
78 |
|
// voceditor.initializeFields();
|
79 |
|
return true;
|
80 |
|
} catch (Exception e) {
|
81 |
|
// TODO Auto-generated catch block
|
82 |
|
org.txm.rcpapplication.utils.Logger.printStackTrace(e);
|
83 |
|
}
|
84 |
|
return false;
|
85 |
|
}
|
86 |
|
|
87 |
|
}
|