Revision 249

tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/messages/messages_fr.properties (revision 249)
7 7
RPreferencePage_5 = Utilisateur
8 8
RPreferencePage_6 = Mot de passe
9 9
RPreferencePage_7 = Utiliser la transmission de données R par fichier
10

  
11
SendToR_0 = Transfert vers l'espace de travail R : 
12
SendToR_3 = Rechargement des vues...
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/messages/messages.properties (revision 249)
37 37
RPreferencePage_7 = Use file based R data transfert
38 38
RPreferencePage_8 = R args
39 39
RPreferencePage_9 = Rserve args
40

  
41
SendToR_0 = Sending to R Workspace:
42
SendToR_3 = Refreshing views
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/messages/RUIMessages.java (revision 249)
49 49
	public static String CheckRPackages_5;
50 50
	public static String CheckRPackages_9;
51 51

  
52
	public static String SendToR_0;
53
	public static String SendToR_3;
54

  
52 55
	
53 56
	static {
54 57
		// initialize resource bundle
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/messages/messages_ru.properties (revision 249)
5 5
RPreferencePage_5 = Пользователь
6 6
RPreferencePage_6 = Пароль
7 7
RPreferencePage_7 = Использовать передачу данных R через файл
8

  
9
SendToR_0 = Передача в рабочее пространство R: 
10
SendToR_3 = Поиск видов...
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/ExecuteRText.java (revision 249)
38 38
import org.txm.rcpapplication.StatusLine;
39 39
import org.txm.statsengine.r.core.RWorkspace;
40 40
import org.txm.statsengine.r.core.RWorkspaceException;
41
import org.txm.statsengine.r.rcp.views.RConsole;
42 41
import org.txm.utils.logger.Log;
43 42
// TODO: Auto-generated Javadoc
44 43
/**
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/SendToR.java (revision 249)
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

  
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle_ru.properties (revision 249)
3 3

  
4 4
command.name.46 = Выполнить выделенные строки как скрипт R 
5 5

  
6
command.name.53 = Отправить в R
7

  
6 8
command.name.90 = Добавить текст
7 9

  
8 10
menu.label.11 = R
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle_fr.properties (revision 249)
3 3

  
4 4
command.name.46 = Exécuter la sélection de texte
5 5

  
6
command.name.53 = Envoyer vers R
7

  
6 8
command.name.90 = Vérifier les packages R
7 9

  
8 10
command.name.93 = Reconnecter le RWorkspace
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle.properties (revision 249)
3 3

  
4 4
command.name.46 = Execute Text Selection
5 5

  
6
command.name.53 = Send to R
7

  
6 8
command.name.90 = Check R packages
7 9

  
8 10
command.name.93 = Reconnect to RWorkspace
tmp/org.txm.statsengine.r.rcp/plugin.xml (revision 249)
32 32
            id="ExecuteRText"
33 33
            name="%command.name.46">
34 34
      </command>
35
               <command
36
            defaultHandler="org.txm.statsengine.r.rcp.handlers.SendToR"
37
            id="SendToR"
38
            name="%command.name.53">
39
      </command>
35 40
         
36 41
   </extension>
37 42
   <extension
......
83 88
            </command>
84 89
         </menu>
85 90
      </menuContribution>
91
      <menuContribution
92
            allPopups="false"
93
            locationURI="menu:menu.tools">
94
         <command
95
               commandId="SendToR"
96
               icon="icons/SendToR.png"
97
               style="push">
98
            <visibleWhen
99
                  checkEnabled="false">
100
               <or>
101
                  <reference
102
                        definitionId="OneConcordanceSelected">
103
                  </reference>
104
                  <reference
105
                        definitionId="OneLexiconSelected">
106
                  </reference>
107
                  <reference
108
                        definitionId="OneIndexSelected">
109
                  </reference>
110
                  <reference
111
                        definitionId="OneCooccurrenceSelected">
112
                  </reference>
113
                  <reference
114
                        definitionId="OneReferencerSelected">
115
                  </reference>
116
                  <reference
117
                        definitionId="OneCorpusSelected">
118
                  </reference>
119
               </or>
120
            </visibleWhen>
121
         </command>
122
      </menuContribution>
123
      <menuContribution
124
            allPopups="false"
125
            locationURI="toolbar:org.txm.rcpapplication.toolbartools">
126
         <command
127
               commandId="SendToR"
128
               icon="icons/SendToR.png"
129
               style="push">
130
            <visibleWhen
131
                  checkEnabled="false">
132
               <or>
133
                  <reference
134
                        definitionId="OneConcordanceSelected">
135
                  </reference>
136
                  <reference
137
                        definitionId="OneLexiconSelected">
138
                  </reference>
139
                  <reference
140
                        definitionId="OneIndexSelected">
141
                  </reference>
142
                  <reference
143
                        definitionId="OneCooccurrenceSelected">
144
                  </reference>
145
                  <reference
146
                        definitionId="OneReferencerSelected">
147
                  </reference>
148
                  <reference
149
                        definitionId="OneCorpusSelected">
150
                  </reference>
151
               </or>
152
            </visibleWhen>
153
         </command>
154
      </menuContribution>
155
      <menuContribution
156
            allPopups="false"
157
            locationURI="popup:org.txm.rcpapplication.views.CorporaView">
158
         <command
159
               commandId="SendToR"
160
               icon="icons/SendToR.png"
161
               style="push">
162
            <visibleWhen
163
                  checkEnabled="false">
164
               <or>
165
                  <reference
166
                        definitionId="OneConcordanceSelected">
167
                  </reference>
168
                  <reference
169
                        definitionId="OneLexiconSelected">
170
                  </reference>
171
                  <reference
172
                        definitionId="OneIndexSelected">
173
                  </reference>
174
                  <reference
175
                        definitionId="OneCooccurrenceSelected">
176
                  </reference>
177
                  <reference
178
                        definitionId="OneReferencerSelected">
179
                  </reference>
180
                  <reference
181
                        definitionId="OneCorpusSelected">
182
                  </reference>
183
               </or>
184
            </visibleWhen>
185
         </command>
186
      </menuContribution>
86 187
   </extension>
87 188
   <extension
88 189
         point="org.eclipse.ui.views">

Also available in: Unified diff