|
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.statsengine.r.rcp.handlers;
|
|
29 |
|
|
30 |
import java.util.List;
|
|
31 |
|
|
32 |
import org.eclipse.core.commands.ExecutionEvent;
|
|
33 |
import org.eclipse.core.commands.ExecutionException;
|
|
34 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
35 |
import org.eclipse.core.runtime.IStatus;
|
|
36 |
import org.eclipse.core.runtime.Status;
|
|
37 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
38 |
import org.eclipse.ui.IEditorPart;
|
|
39 |
import org.eclipse.ui.IEditorReference;
|
|
40 |
import org.eclipse.ui.IWorkbenchPage;
|
|
41 |
import org.eclipse.ui.IWorkbenchWindow;
|
|
42 |
import org.eclipse.ui.handlers.HandlerUtil;
|
|
43 |
import org.eclipse.ui.internal.Workbench;
|
|
44 |
import org.txm.ca.core.functions.CA;
|
|
45 |
import org.txm.cooccurrence.core.functions.Cooccurrence;
|
|
46 |
import org.txm.cooccurrence.rcp.editors.CooccurrencesEditor;
|
|
47 |
import org.txm.functions.concordances.Concordance;
|
|
48 |
import org.txm.functions.referencer.Referencer;
|
|
49 |
import org.txm.index.core.functions.Index;
|
|
50 |
import org.txm.index.rcp.editors.IndexEditor;
|
|
51 |
import org.txm.lexicaltable.core.statsengine.data.LexicalTable;
|
|
52 |
import org.txm.lexicaltable.rcp.editors.LexicalTableEditor;
|
|
53 |
import org.txm.lexicaltable.rcp.editors.LexicalTableEditor2;
|
|
54 |
import org.txm.progression.core.functions.Progression;
|
|
55 |
import org.txm.rcp.handlers.BaseAbstractHandler;
|
|
56 |
import org.txm.rcpapplication.JobsTimer;
|
|
57 |
import org.txm.rcpapplication.commands.editor.CustomizableEditor;
|
|
58 |
import org.txm.rcpapplication.editors.concordances.ConcordancesEditor;
|
|
59 |
import org.txm.rcpapplication.editors.referencer.ReferencerEditor;
|
|
60 |
import org.txm.rcpapplication.utils.JobHandler;
|
|
61 |
import org.txm.rcpapplication.views.corpora.CorporaView;
|
|
62 |
import org.txm.searchengine.cqp.corpus.Corpus;
|
|
63 |
import org.txm.searchengine.cqp.corpus.Lexicon;
|
|
64 |
import org.txm.specificities.core.functions.SpecificitesResult;
|
|
65 |
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor;
|
|
66 |
import org.txm.statsengine.core.data.Vector;
|
|
67 |
import org.txm.statsengine.r.rcp.messages.RUIMessages;
|
|
68 |
import org.txm.statsengine.r.rcp.views.RVariablesView;
|
|
69 |
|
|
70 |
// TODO: Auto-generated Javadoc
|
|
71 |
/**
|
|
72 |
* Delete the selection: TXMObjects and results code for the results must be
|
|
73 |
* added manually here @ author mdecorde.
|
|
74 |
*/
|
|
75 |
public class SendToR extends BaseAbstractHandler {
|
|
76 |
|
|
77 |
/* (non-Javadoc)
|
|
78 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
|
79 |
*/
|
|
80 |
@Override
|
|
81 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
82 |
|
|
83 |
|
|
84 |
if(!super.checkStatsEngine()) {
|
|
85 |
return null;
|
|
86 |
}
|
|
87 |
|
|
88 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
|
|
89 |
|
|
90 |
final List list = selection.toList();
|
|
91 |
JobHandler jobhandler = new JobHandler(RUIMessages.SendToR_0+ list) {
|
|
92 |
@Override
|
|
93 |
protected IStatus run(IProgressMonitor monitor) {
|
|
94 |
this.runInit(monitor);
|
|
95 |
try {
|
|
96 |
JobsTimer.start();
|
|
97 |
monitor.beginTask(RUIMessages.SendToR_0+ list, 100);
|
|
98 |
int delta = 100 / list.size();
|
|
99 |
//System.out.println(selection.toList());
|
|
100 |
for(Object o : list)
|
|
101 |
try {
|
|
102 |
monitor.subTask(RUIMessages.SendToR_0+ o);
|
|
103 |
this.acquireSemaphore();
|
|
104 |
send(o);
|
|
105 |
this.releaseSemaphore();
|
|
106 |
|
|
107 |
monitor.worked(delta);
|
|
108 |
|
|
109 |
} catch (Exception e) {
|
|
110 |
// TODO Auto-generated catch block
|
|
111 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e);
|
|
112 |
}
|
|
113 |
|
|
114 |
monitor.subTask(RUIMessages.SendToR_3);
|
|
115 |
this.syncExec(new Runnable() {
|
|
116 |
@Override
|
|
117 |
public void run() {
|
|
118 |
CorporaView.refresh();
|
|
119 |
RVariablesView.reload();
|
|
120 |
}
|
|
121 |
});
|
|
122 |
} catch (ThreadDeath td) {
|
|
123 |
return Status.CANCEL_STATUS;
|
|
124 |
} finally {
|
|
125 |
monitor.done();
|
|
126 |
JobsTimer.stopAndPrint();
|
|
127 |
}
|
|
128 |
return Status.OK_STATUS;
|
|
129 |
}
|
|
130 |
};
|
|
131 |
jobhandler.startJob();
|
|
132 |
|
|
133 |
|
|
134 |
return null;
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Send.
|
|
139 |
*
|
|
140 |
* @param o the o
|
|
141 |
* @throws Exception the exception
|
|
142 |
*/
|
|
143 |
public static void send(Object o) throws Exception {
|
|
144 |
|
|
145 |
if (o instanceof Lexicon)
|
|
146 |
{
|
|
147 |
Lexicon lex = (Lexicon) o;
|
|
148 |
Vector v = lex.asVector();
|
|
149 |
lex.setSymbol(v.getSymbol());
|
|
150 |
|
|
151 |
System.out.println(lex.getName()+" >> "+lex.getSymbol()); //$NON-NLS-1$
|
|
152 |
} else if (o instanceof Corpus) {
|
|
153 |
Corpus corpus = (Corpus) o;
|
|
154 |
String symbol = corpus.SendToR();
|
|
155 |
|
|
156 |
System.out.println(corpus.getName()+" >> "+symbol); //$NON-NLS-1$
|
|
157 |
} else if (o instanceof Concordance) {
|
|
158 |
Concordance conc = (Concordance) o;
|
|
159 |
String symbol = conc.asRMatrix();
|
|
160 |
|
|
161 |
System.out.println(conc.getName()+" >> "+conc.getSymbol()); //$NON-NLS-1$
|
|
162 |
} else if (o instanceof Referencer) {
|
|
163 |
Referencer referencer = (Referencer) o;
|
|
164 |
String symbol = referencer.asRMatrix();
|
|
165 |
|
|
166 |
System.out.println(referencer.getName()+" >> "+referencer.getSymbol()); //$NON-NLS-1$
|
|
167 |
} else if (o instanceof Cooccurrence) {
|
|
168 |
Cooccurrence cooc = (Cooccurrence) o;
|
|
169 |
String symbol = cooc.asRMatrix();
|
|
170 |
|
|
171 |
System.out.println(cooc.getName()+" >> "+cooc.getSymbol()); //$NON-NLS-1$
|
|
172 |
} else if (o instanceof Index) {
|
|
173 |
Index voc = (Index) o;
|
|
174 |
voc.asRMatrix();
|
|
175 |
|
|
176 |
System.out.println(voc.getName()+" >> "+voc.getSymbol()); //$NON-NLS-1$
|
|
177 |
}
|
|
178 |
}
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Close the editors which uses an Object.
|
|
182 |
*
|
|
183 |
* @param o the object used by an editor
|
|
184 |
*/
|
|
185 |
|
|
186 |
// FIXME: this method should only contains one test on TXMEditor.getResult()
|
|
187 |
public static void closeEditorOfSelection(Object o)
|
|
188 |
{
|
|
189 |
if (o != null) {
|
|
190 |
//get all editors
|
|
191 |
//check editor class
|
|
192 |
//test if object used dispose editor if necessary
|
|
193 |
if (o instanceof Concordance)
|
|
194 |
{
|
|
195 |
for(IWorkbenchPage page : getPages())
|
|
196 |
{
|
|
197 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
198 |
{
|
|
199 |
IEditorPart editor = editorref.getEditor(false);
|
|
200 |
|
|
201 |
if (editor instanceof ConcordancesEditor)
|
|
202 |
if (((Concordance)o).equals(((ConcordancesEditor)editor).getConcordance()))
|
|
203 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
}
|
|
207 |
else if (o instanceof Cooccurrence)
|
|
208 |
{
|
|
209 |
for(IWorkbenchPage page : getPages())
|
|
210 |
{
|
|
211 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
212 |
{
|
|
213 |
IEditorPart editor = editorref.getEditor(false);
|
|
214 |
|
|
215 |
if (editor instanceof CooccurrencesEditor)
|
|
216 |
if (o.equals(((CooccurrencesEditor)editor).getCooc()))
|
|
217 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
218 |
}
|
|
219 |
}
|
|
220 |
}
|
|
221 |
else if (o instanceof CA)
|
|
222 |
{
|
|
223 |
for(IWorkbenchPage page : getPages())
|
|
224 |
{
|
|
225 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
226 |
{
|
|
227 |
IEditorPart editor = editorref.getEditor(false);
|
|
228 |
if (editor instanceof CAEditor)
|
|
229 |
if (o.equals(((CAEditor)editor).getCA()))
|
|
230 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
231 |
}
|
|
232 |
}
|
|
233 |
}
|
|
234 |
else if (o instanceof SpecificitesResult)
|
|
235 |
{
|
|
236 |
for(IWorkbenchPage page : getPages())
|
|
237 |
{
|
|
238 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
239 |
{
|
|
240 |
IEditorPart editor = editorref.getEditor(false);
|
|
241 |
if (editor instanceof SpecificitiesTableEditor)
|
|
242 |
if (o.equals(((SpecificitiesTableEditor)editor).getSpecificitiesResult()))
|
|
243 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
244 |
}
|
|
245 |
}
|
|
246 |
}
|
|
247 |
else if (o instanceof Index)
|
|
248 |
{
|
|
249 |
for(IWorkbenchPage page : getPages())
|
|
250 |
{
|
|
251 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
252 |
{
|
|
253 |
IEditorPart editor = editorref.getEditor(false);
|
|
254 |
if (editor instanceof IndexEditor)
|
|
255 |
{
|
|
256 |
if (o.equals(((IndexEditor)editor).getIndex()))
|
|
257 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
258 |
}
|
|
259 |
}
|
|
260 |
}
|
|
261 |
}
|
|
262 |
else if (o instanceof LexicalTable)
|
|
263 |
{
|
|
264 |
for(IWorkbenchPage page : getPages())
|
|
265 |
{
|
|
266 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
267 |
{
|
|
268 |
IEditorPart editor = editorref.getEditor(false);
|
|
269 |
if (editor instanceof LexicalTableEditor)
|
|
270 |
if (o.equals(((LexicalTableEditor2)editor).getLexicalTable()))
|
|
271 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
272 |
}
|
|
273 |
}
|
|
274 |
}
|
|
275 |
else if (o instanceof Referencer)
|
|
276 |
{
|
|
277 |
for(IWorkbenchPage page : getPages())
|
|
278 |
{
|
|
279 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
280 |
{
|
|
281 |
IEditorPart editor = editorref.getEditor(false);
|
|
282 |
if (editor instanceof ReferencerEditor)
|
|
283 |
if (o.equals(((ReferencerEditor)editor).getReferencer()))
|
|
284 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
285 |
}
|
|
286 |
}
|
|
287 |
}
|
|
288 |
else if (o instanceof Progression)
|
|
289 |
{
|
|
290 |
Progression rep = (Progression)o;
|
|
291 |
for(IWorkbenchPage page : getPages())
|
|
292 |
{
|
|
293 |
for(IEditorReference editorref : page.getEditorReferences())
|
|
294 |
{
|
|
295 |
IEditorPart editor = editorref.getEditor(false);
|
|
296 |
if (editor instanceof CustomizableEditor)
|
|
297 |
{
|
|
298 |
Object source = ((CustomizableEditor)editor).getSource();
|
|
299 |
if (source != null && source instanceof Progression)
|
|
300 |
if (rep.equals(source))
|
|
301 |
editor.getEditorSite().getPage().closeEditor(editor, true);
|
|
302 |
}
|
|
303 |
}
|
|
304 |
}
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
}
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Gets the pages.
|
|
312 |
*
|
|
313 |
* @return the pages
|
|
314 |
*/
|
|
315 |
private static IWorkbenchPage[] getPages()
|
|
316 |
{
|
|
317 |
for(IWorkbenchWindow win : Workbench.getInstance().getWorkbenchWindows())
|
|
318 |
{
|
|
319 |
return win.getPages();
|
|
320 |
}
|
|
321 |
return new IWorkbenchPage[0];
|
|
322 |
}
|
|
323 |
}
|
0 |
324 |
|