Révision 236
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle.properties (revision 236) | ||
---|---|---|
1 |
|
|
2 |
command.name.45 = Run R script |
|
3 |
|
|
4 |
command.name.46 = Execute Text Selection |
|
5 |
|
|
6 |
command.name.90 = Check R packages |
|
7 |
|
|
8 |
command.name.93 = Reconnect to RWorkspace |
|
9 |
|
|
10 |
menu.label.11 = R |
|
11 |
|
|
12 |
page.name = Statistics Engine |
|
13 |
|
|
14 |
view.name.5 = R variables |
|
15 |
|
|
16 |
view.name.6 = R Console |
|
0 | 17 |
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle_ru.properties (revision 236) | ||
---|---|---|
1 |
|
|
2 |
command.name.45 = Выполнить скрипт R |
|
3 |
|
|
4 |
command.name.46 = Выполнить выделенные строки как скрипт R |
|
5 |
|
|
6 |
command.name.90 = Добавить текст |
|
7 |
|
|
8 |
menu.label.11 = R |
|
9 |
|
|
10 |
page.name = Статистическая машина |
|
11 |
|
|
12 |
view.name.5 = Переменные R |
|
13 |
|
|
14 |
view.name.6 = Консоль R |
|
0 | 15 |
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle_fr.properties (revision 236) | ||
---|---|---|
1 |
|
|
2 |
command.name.45 = Exécuter le script R |
|
3 |
|
|
4 |
command.name.46 = Exécuter la sélection de texte |
|
5 |
|
|
6 |
command.name.90 = Vérifier les packages R |
|
7 |
|
|
8 |
command.name.93 = Reconnecter le RWorkspace |
|
9 |
|
|
10 |
menu.label.11 = R |
|
11 |
|
|
12 |
page.name = Moteur de Statistiques |
|
13 |
|
|
14 |
view.name.5 = Variables R |
|
15 |
|
|
16 |
view.name.6 = Console R |
|
0 | 17 |
tmp/org.txm.statsengine.r.rcp/OSGI-INF/l10n/bundle_ru_utf-8.properties (revision 236) | ||
---|---|---|
1 |
command.name.45=Выполнить скрипт R |
|
2 |
page.name=Статистическая машина |
|
3 |
command.name.90=Добавить текст |
|
4 |
command.label.137=Консоль R |
|
5 |
command.label.138=Переменные R |
|
0 | 6 |
tmp/org.txm.statsengine.r.rcp/plugin.xml (revision 236) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.eclipse.ui.preferencePages"> |
|
6 |
<page |
|
7 |
category="org.txm.rcpapplication.preferences.AdvancePreferencePage" |
|
8 |
class="org.txm.statsengine.r.rcp.preferences.RPreferencePage" |
|
9 |
id="org.txm.statsengine.r.rcp.preferences.RPreferencePage" |
|
10 |
name="%page.name"> |
|
11 |
</page> |
|
12 |
</extension> |
|
13 |
<extension |
|
14 |
point="org.eclipse.ui.commands"> |
|
15 |
<command |
|
16 |
defaultHandler="org.txm.statsengine.r.rcp.handlers.CheckRPackages" |
|
17 |
id="CheckRPackages" |
|
18 |
name="%command.name.90"> |
|
19 |
</command> |
|
20 |
<command |
|
21 |
defaultHandler="org.txm.statsengine.r.rcp.handlers.ReconnectToRWorkspace" |
|
22 |
id="ReconnectToRWorkspace" |
|
23 |
name="%command.name.93"> |
|
24 |
</command> |
|
25 |
<command |
|
26 |
defaultHandler="org.txm.statsengine.r.rcp.handlers.ExecuteRScript" |
|
27 |
id="ExecuteRScript" |
|
28 |
name="%command.name.45"> |
|
29 |
</command> |
|
30 |
<command |
|
31 |
defaultHandler="org.txm.statsengine.r.rcp.handlers.ExecuteRText" |
|
32 |
id="ExecuteRText" |
|
33 |
name="%command.name.46"> |
|
34 |
</command> |
|
35 |
|
|
36 |
</extension> |
|
37 |
<extension |
|
38 |
point="org.eclipse.ui.menus"> |
|
39 |
<menuContribution |
|
40 |
allPopups="false" |
|
41 |
locationURI="menu:menu.file"> |
|
42 |
<command |
|
43 |
commandId="CheckRPackages" |
|
44 |
style="push"> |
|
45 |
</command> |
|
46 |
</menuContribution> |
|
47 |
<menuContribution |
|
48 |
allPopups="false" |
|
49 |
locationURI="menu:menu.display.views"> |
|
50 |
<command |
|
51 |
commandId="org.eclipse.ui.views.showView" |
|
52 |
icon="icons/R.png" |
|
53 |
label="%view.name.6" |
|
54 |
style="push"> |
|
55 |
<parameter |
|
56 |
name="org.eclipse.ui.views.showView.viewId" |
|
57 |
value="RConsoleView"> |
|
58 |
</parameter> |
|
59 |
</command> |
|
60 |
<command |
|
61 |
commandId="org.eclipse.ui.views.showView" |
|
62 |
icon="icons/R.png" |
|
63 |
label="%view.name.5" |
|
64 |
style="push"> |
|
65 |
<parameter |
|
66 |
name="org.eclipse.ui.views.showView.viewId" |
|
67 |
value="RVariablesView"> |
|
68 |
</parameter> |
|
69 |
</command> |
|
70 |
</menuContribution> |
|
71 |
<menuContribution |
|
72 |
locationURI="popup:#TextEditorContext"> |
|
73 |
<menu |
|
74 |
icon="icons/R.png" |
|
75 |
label="%menu.label.11"> |
|
76 |
<command |
|
77 |
commandId="ExecuteRText" |
|
78 |
style="push"> |
|
79 |
</command> |
|
80 |
<command |
|
81 |
commandId="ExecuteRScript" |
|
82 |
style="push"> |
|
83 |
</command> |
|
84 |
</menu> |
|
85 |
</menuContribution> |
|
86 |
</extension> |
|
87 |
<extension |
|
88 |
point="org.eclipse.ui.views"> |
|
89 |
<view |
|
90 |
allowMultiple="false" |
|
91 |
category="org.txm.rcpapplication" |
|
92 |
class="org.txm.statsengine.r.rcp.views.RConsole" |
|
93 |
icon="icons/R.png" |
|
94 |
id="RConsoleView" |
|
95 |
name="%view.name.6" |
|
96 |
restorable="true"> |
|
97 |
</view> |
|
98 |
<view |
|
99 |
category="org.txm.rcpapplication" |
|
100 |
class="org.txm.statsengine.r.rcp.views.RVariablesView" |
|
101 |
icon="icons/R.png" |
|
102 |
id="RVariablesView" |
|
103 |
name="%view.name.5" |
|
104 |
restorable="true"> |
|
105 |
</view> |
|
106 |
|
|
107 |
</extension> |
|
108 |
|
|
109 |
</plugin> |
|
0 | 110 |
tmp/org.txm.statsengine.r.rcp/.settings/org.eclipse.jdt.core.prefs (revision 236) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.statsengine.r.rcp/.classpath (revision 236) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.statsengine.r.rcp/META-INF/MANIFEST.MF (revision 236) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: R Statistics Engine RCP |
|
4 |
Bundle-SymbolicName: org.txm.statsengine.r.rcp;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
7 |
Require-Bundle: org.txm.core;bundle-version="0.7.0", |
|
8 |
org.txm.statsengine.r.core;bundle-version="1.0.0", |
|
9 |
org.eclipse.core.runtime;bundle-version="3.10.0", |
|
10 |
org.eclipse.ui;bundle-version="3.106.1", |
|
11 |
org.txm.rcp;bundle-version="0.7.8" |
|
12 |
Export-Package: org.txm.statsengine.r.rcp.views |
|
0 | 13 |
tmp/org.txm.statsengine.r.rcp/.project (revision 236) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.statsengine.r.rcp</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/TXMRServeWatcher.java (revision 236) | ||
---|---|---|
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; |
|
29 |
|
|
30 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
31 |
import org.eclipse.swt.widgets.Display; |
|
32 |
import org.txm.rcpapplication.Messages; |
|
33 |
import org.txm.rcpapplication.views.corpora.CorporaView; |
|
34 |
import org.txm.statsengine.r.core.RserveWatcher; |
|
35 |
|
|
36 |
// TODO: Auto-generated Javadoc |
|
37 |
/** |
|
38 |
* Watch if RServe is running |
|
39 |
*/ |
|
40 |
@Deprecated |
|
41 |
public class TXMRServeWatcher extends RserveWatcher{ |
|
42 |
|
|
43 |
/** The parent. */ |
|
44 |
private Display parent; |
|
45 |
|
|
46 |
/** |
|
47 |
* Instantiates a new tXMR serve watcher. |
|
48 |
* |
|
49 |
* @param parent the parent |
|
50 |
*/ |
|
51 |
TXMRServeWatcher(Display parent) |
|
52 |
{ |
|
53 |
this.parent = parent; |
|
54 |
} |
|
55 |
|
|
56 |
/* (non-Javadoc) |
|
57 |
* @see org.txm.RserveWatcher#restart() |
|
58 |
*/ |
|
59 |
@Override |
|
60 |
public boolean restart() |
|
61 |
{ |
|
62 |
parent.syncExec(new Runnable(){ |
|
63 |
@Override |
|
64 |
public void run(){ |
|
65 |
MessageDialog d = |
|
66 |
new MessageDialog( |
|
67 |
parent.getActiveShell(), |
|
68 |
Messages.TXMRServeWatcher_0, |
|
69 |
null, |
|
70 |
Messages.TXMRServeWatcher_1, |
|
71 |
MessageDialog.ERROR, |
|
72 |
new String[] { Messages.TXMRServeWatcher_2 }, |
|
73 |
0); |
|
74 |
d.open(); |
|
75 |
} |
|
76 |
}); |
|
77 |
|
|
78 |
boolean ret = super.restart(); |
|
79 |
|
|
80 |
parent.syncExec(new Runnable(){ |
|
81 |
@Override |
|
82 |
public void run(){ |
|
83 |
MessageDialog d = |
|
84 |
new MessageDialog( |
|
85 |
parent.getActiveShell(), |
|
86 |
Messages.TXMRServeWatcher_3, |
|
87 |
null, |
|
88 |
Messages.TXMRServeWatcher_4, |
|
89 |
MessageDialog.ERROR, |
|
90 |
new String[] { Messages.TXMRServeWatcher_2 }, |
|
91 |
0); |
|
92 |
d.open(); |
|
93 |
} |
|
94 |
}); |
|
95 |
|
|
96 |
if (ret) |
|
97 |
{ |
|
98 |
parent.syncExec(new Runnable(){ |
|
99 |
@Override |
|
100 |
public void run(){ |
|
101 |
CorporaView.reload(); |
|
102 |
} |
|
103 |
}); |
|
104 |
} |
|
105 |
|
|
106 |
return ret; |
|
107 |
} |
|
108 |
} |
|
0 | 109 |
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/views/RConsole.java (revision 236) | ||
---|---|---|
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.views; |
|
29 |
|
|
30 |
import org.eclipse.jface.action.Action; |
|
31 |
import org.eclipse.swt.SWT; |
|
32 |
import org.eclipse.swt.custom.StyledText; |
|
33 |
import org.eclipse.swt.layout.GridData; |
|
34 |
import org.eclipse.swt.widgets.Composite; |
|
35 |
import org.eclipse.swt.widgets.Display; |
|
36 |
import org.eclipse.ui.IViewPart; |
|
37 |
import org.eclipse.ui.IWorkbenchWindow; |
|
38 |
import org.eclipse.ui.PlatformUI; |
|
39 |
import org.eclipse.ui.part.ViewPart; |
|
40 |
import org.txm.Toolbox; |
|
41 |
import org.txm.rcpapplication.IImageKeys; |
|
42 |
import org.txm.rcpapplication.Messages; |
|
43 |
import org.txm.statsengine.r.core.RWorkspace; |
|
44 |
import org.txm.statsengine.r.core.RWorkspaceException; |
|
45 |
import org.txm.utils.MessagePrinter; |
|
46 |
import org.txm.utils.StreamHog; |
|
47 |
import org.txm.utils.logger.Log; |
|
48 |
|
|
49 |
/** |
|
50 |
* display the R logs only |
|
51 |
* @author mdecorde. |
|
52 |
*/ |
|
53 |
public class RConsole extends ViewPart implements MessagePrinter { |
|
54 |
|
|
55 |
/** The ID. */ |
|
56 |
public static String ID = "org.txm.rcpapplication.views.RConsole"; //$NON-NLS-1$ |
|
57 |
|
|
58 |
/** The text area. */ |
|
59 |
private StyledText textArea; |
|
60 |
private Display display; |
|
61 |
boolean readyToDisplay = false; |
|
62 |
|
|
63 |
// /** The out. */ |
|
64 |
// private static PrintStream out; |
|
65 |
// |
|
66 |
// /** The err. */ |
|
67 |
// private static PrintStream err; |
|
68 |
// |
|
69 |
// /** The quit. */ |
|
70 |
// private boolean quit; |
|
71 |
// |
|
72 |
// /** The reader. */ |
|
73 |
// private Thread reader; |
|
74 |
// |
|
75 |
// /** The reader2. */ |
|
76 |
// private Thread reader2; |
|
77 |
// |
|
78 |
// /** The pin. */ |
|
79 |
// PipedInputStream pin = new PipedInputStream(); |
|
80 |
// |
|
81 |
// /** The pin2. */ |
|
82 |
// PipedInputStream pin2 = new PipedInputStream(); |
|
83 |
// |
|
84 |
// /** The output. */ |
|
85 |
// static PrintStream output = System.out; |
|
86 |
// |
|
87 |
// /** The errput. */ |
|
88 |
// static PrintStream errput = System.err; |
|
89 |
// |
|
90 |
// /** The blue. */ |
|
91 |
// static Color blue; |
|
92 |
// |
|
93 |
// /** The red. */ |
|
94 |
// static Color red; |
|
95 |
|
|
96 |
/** |
|
97 |
* Instantiates a new r console. |
|
98 |
*/ |
|
99 |
public RConsole() { |
|
100 |
// try { |
|
101 |
// PipedOutputStream pout = new PipedOutputStream(pin); |
|
102 |
// out = new PrintStream(pout, true); |
|
103 |
// |
|
104 |
// new PipedOutputStream(pin2); |
|
105 |
// err = new PrintStream(pout, true); |
|
106 |
// |
|
107 |
// } catch (IOException e) { |
|
108 |
// org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
109 |
// } |
|
110 |
// |
|
111 |
// reader = new Thread(this); |
|
112 |
// reader.setDaemon(true); |
|
113 |
// reader.start(); |
|
114 |
// reader2 = new Thread(this); |
|
115 |
// reader2.setDaemon(true); |
|
116 |
// reader2.start(); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Redirect. |
|
121 |
* |
|
122 |
* @param b the b |
|
123 |
*/ |
|
124 |
public static void redirect(boolean b) { |
|
125 |
// if (b) { |
|
126 |
// System.setOut(out); |
|
127 |
// System.setErr(err); |
|
128 |
// } else { |
|
129 |
// System.setOut(output); |
|
130 |
// System.setErr(errput); |
|
131 |
// } |
|
132 |
} |
|
133 |
|
|
134 |
// /** |
|
135 |
// * Lecture de la sortie standard. |
|
136 |
// * |
|
137 |
// * @param in the in |
|
138 |
// * @return the string |
|
139 |
// * @throws IOException Signals that an I/O exception has occurred. |
|
140 |
// */ |
|
141 |
// protected synchronized String readLine(PipedInputStream in) |
|
142 |
// throws IOException { |
|
143 |
// String input = ""; //$NON-NLS-1$ |
|
144 |
// do { |
|
145 |
// int available = in.available(); |
|
146 |
// if (available == 0) |
|
147 |
// break; |
|
148 |
// byte b[] = new byte[available]; |
|
149 |
// in.read(b); |
|
150 |
// input = input + new String(b, 0, b.length); |
|
151 |
// } while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit); //$NON-NLS-1$ //$NON-NLS-2$ |
|
152 |
// return input; |
|
153 |
// } |
|
154 |
// |
|
155 |
// /* (non-Javadoc) |
|
156 |
// * @see java.lang.Runnable#run() |
|
157 |
// */ |
|
158 |
// @Override |
|
159 |
// public synchronized void run() { |
|
160 |
// try { |
|
161 |
// while (Thread.currentThread() == reader) { |
|
162 |
// try { |
|
163 |
// this.wait(100); |
|
164 |
// } catch (InterruptedException ie) { |
|
165 |
// } |
|
166 |
// if (pin.available() != 0) { |
|
167 |
// String input = this.readLine(pin); |
|
168 |
// textArea.append(input); |
|
169 |
// } |
|
170 |
// if (quit) |
|
171 |
// return; |
|
172 |
// } |
|
173 |
// |
|
174 |
// while (Thread.currentThread() == reader2) { |
|
175 |
// try { |
|
176 |
// this.wait(100); |
|
177 |
// } catch (InterruptedException ie) { |
|
178 |
// } |
|
179 |
// if (pin2.available() != 0) { |
|
180 |
// String input = this.readLine(pin2); |
|
181 |
// textArea.append(input); |
|
182 |
// } |
|
183 |
// |
|
184 |
// if (quit) |
|
185 |
// return; |
|
186 |
// } |
|
187 |
// } catch (Exception e) { |
|
188 |
// textArea.append(Messages.GroovyConsole_4); |
|
189 |
// textArea.append(Messages.GroovyConsole_5 + e); |
|
190 |
// } |
|
191 |
// } |
|
192 |
|
|
193 |
/* (non-Javadoc) |
|
194 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
195 |
*/ |
|
196 |
@Override |
|
197 |
public void createPartControl(Composite parent) { |
|
198 |
display = parent.getDisplay(); |
|
199 |
|
|
200 |
// blue = parent.getDisplay().getSystemColor(SWT.COLOR_BLUE); |
|
201 |
// red = parent.getDisplay().getSystemColor(SWT.COLOR_RED); |
|
202 |
|
|
203 |
textArea = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL |
|
204 |
| SWT.H_SCROLL); |
|
205 |
textArea.setEditable(false); |
|
206 |
|
|
207 |
textArea.setLayoutData(new GridData(GridData.FILL_BOTH |
|
208 |
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); |
|
209 |
|
|
210 |
// Custom Action for the View's Menu |
|
211 |
Action lCustomAction = new Action() { |
|
212 |
public void run() { |
|
213 |
clear(); |
|
214 |
} |
|
215 |
}; |
|
216 |
lCustomAction.setId("org.txm.rcpapplication.views.RConsole.clear"); //$NON-NLS-1$ |
|
217 |
//lCustomAction.setText("Clear"); |
|
218 |
lCustomAction.setImageDescriptor(IImageKeys.getImageDescriptor(IImageKeys.ACTION_DELETE)); |
|
219 |
getViewSite().getActionBars().getToolBarManager().add(lCustomAction); |
|
220 |
|
|
221 |
connectToRWorkspace(); |
|
222 |
} |
|
223 |
|
|
224 |
public void reconnectToRWorkspace() { |
|
225 |
readyToDisplay = false; |
|
226 |
connectToRWorkspace(); |
|
227 |
} |
|
228 |
|
|
229 |
public void connectToRWorkspace() { |
|
230 |
if (!readyToDisplay && Toolbox.isStatEngineInitialized()) { |
|
231 |
RWorkspace rw = null; |
|
232 |
Log.warning(Messages.RConsole_0); |
|
233 |
try { |
|
234 |
rw = RWorkspace.getRWorkspaceInstance(); |
|
235 |
if (rw == null) return; |
|
236 |
StreamHog errorLogger = rw.getErrorLogger(); |
|
237 |
StreamHog inputLogger = rw.getInputLogger(); |
|
238 |
//if (errorLogger.getMessagePrinter() == null) { |
|
239 |
//System.out.println("SET MESSAGEPRINTER OF THE RCONSOLE"); |
|
240 |
if (errorLogger != null) |
|
241 |
errorLogger.addMessagePrinter(this); |
|
242 |
if (inputLogger != null) |
|
243 |
inputLogger.addMessagePrinter(this); |
|
244 |
readyToDisplay = true; |
|
245 |
//} |
|
246 |
} catch (RWorkspaceException e) { |
|
247 |
System.out.println(Messages.RConsole_1+e); |
|
248 |
Log.printStackTrace(e); |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Println. |
|
255 |
* |
|
256 |
* @param txt the txt |
|
257 |
*/ |
|
258 |
String txtToPrint; |
|
259 |
public void println(String txt) { |
|
260 |
txtToPrint = txt; |
|
261 |
display.syncExec(new Runnable() { |
|
262 |
public void run() { |
|
263 |
if (textArea != null) { |
|
264 |
textArea.append(txtToPrint + "\n"); //$NON-NLS-1$ |
|
265 |
textArea.setTopIndex(textArea.getLineCount()); |
|
266 |
} |
|
267 |
} |
|
268 |
}); |
|
269 |
} |
|
270 |
|
|
271 |
/** |
|
272 |
* Prints the. |
|
273 |
* |
|
274 |
* @param txt the txt |
|
275 |
*/ |
|
276 |
public void print(String txt) { |
|
277 |
txtToPrint = txt; |
|
278 |
display.syncExec(new Runnable() { |
|
279 |
public void run() { |
|
280 |
if (textArea != null) { |
|
281 |
textArea.append(txtToPrint); //$NON-NLS-1$ |
|
282 |
textArea.setTopIndex(textArea.getLineCount()); |
|
283 |
} |
|
284 |
} |
|
285 |
}); |
|
286 |
} |
|
287 |
|
|
288 |
/* (non-Javadoc) |
|
289 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
290 |
*/ |
|
291 |
@Override |
|
292 |
public void setFocus() { |
|
293 |
// TODO Auto-generated method stub |
|
294 |
} |
|
295 |
|
|
296 |
public void clear() { |
|
297 |
if (textArea != null) |
|
298 |
textArea.setText(""); //$NON-NLS-1$ |
|
299 |
} |
|
300 |
|
|
301 |
public static void reload() { |
|
302 |
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { |
|
303 |
IViewPart v = window.getActivePage().findView(RConsole.ID); |
|
304 |
if (v == null) return; |
|
305 |
RConsole rc = (RConsole) v; |
|
306 |
rc.reconnectToRWorkspace(); |
|
307 |
} |
|
308 |
} |
|
309 |
} |
|
0 | 310 |
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/views/RVariablesView.java (revision 236) | ||
---|---|---|
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.views; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.lang.reflect.Method; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Collection; |
|
34 |
import java.util.Iterator; |
|
35 |
import java.util.List; |
|
36 |
|
|
37 |
import org.eclipse.jface.action.MenuManager; |
|
38 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
39 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
40 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
41 |
import org.eclipse.jface.viewers.LabelProvider; |
|
42 |
import org.eclipse.jface.viewers.TreeSelection; |
|
43 |
import org.eclipse.jface.viewers.TreeViewer; |
|
44 |
import org.eclipse.jface.viewers.Viewer; |
|
45 |
import org.eclipse.osgi.util.NLS; |
|
46 |
import org.eclipse.swt.SWT; |
|
47 |
import org.eclipse.swt.events.KeyEvent; |
|
48 |
import org.eclipse.swt.events.KeyListener; |
|
49 |
import org.eclipse.swt.events.SelectionEvent; |
|
50 |
import org.eclipse.swt.events.SelectionListener; |
|
51 |
import org.eclipse.swt.graphics.Image; |
|
52 |
import org.eclipse.swt.layout.GridData; |
|
53 |
import org.eclipse.swt.layout.GridLayout; |
|
54 |
import org.eclipse.swt.widgets.Button; |
|
55 |
import org.eclipse.swt.widgets.Composite; |
|
56 |
import org.eclipse.swt.widgets.Menu; |
|
57 |
import org.eclipse.ui.IWorkbenchPage; |
|
58 |
import org.eclipse.ui.IWorkbenchWindow; |
|
59 |
import org.eclipse.ui.PlatformUI; |
|
60 |
import org.eclipse.ui.part.ViewPart; |
|
61 |
import org.txm.Toolbox; |
|
62 |
import org.txm.ca.core.functions.CA; |
|
63 |
import org.txm.cah.core.functions.CAH; |
|
64 |
import org.txm.cooccurrence.core.functions.Cooccurrence; |
|
65 |
import org.txm.core.results.ITXMResult; |
|
66 |
import org.txm.functions.concordances.Concordance; |
|
67 |
import org.txm.functions.referencer.Referencer; |
|
68 |
import org.txm.index.core.functions.Index; |
|
69 |
import org.txm.lexicaltable.core.statsengine.data.LexicalTable; |
|
70 |
import org.txm.objects.Base; |
|
71 |
import org.txm.progression.core.functions.Progression; |
|
72 |
import org.txm.rcpapplication.IImageKeys; |
|
73 |
import org.txm.rcpapplication.Messages; |
|
74 |
import org.txm.rcpapplication.commands.EditFile; |
|
75 |
import org.txm.rcpapplication.commands.R.CopySelection; |
|
76 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
77 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
78 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
79 |
import org.txm.searchengine.cqp.corpus.Lexicon; |
|
80 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
81 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
82 |
import org.txm.specificities.core.functions.SpecificitesResult; |
|
83 |
import org.txm.statsengine.r.core.RWorkspace; |
|
84 |
// TODO: Auto-generated Javadoc |
|
85 |
/** |
|
86 |
* The Class RVariablesView. |
|
87 |
*/ |
|
88 |
public class RVariablesView extends ViewPart { |
|
89 |
|
|
90 |
/** The tv. */ |
|
91 |
TreeViewer tv; |
|
92 |
|
|
93 |
/** The ID. */ |
|
94 |
public static String ID = "org.txm.rcpapplication.views.RVariablesView"; //$NON-NLS-1$ |
|
95 |
|
|
96 |
/** |
|
97 |
* Refresh. |
|
98 |
*/ |
|
99 |
public static void refresh() { |
|
100 |
IWorkbenchWindow activeworksbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
101 |
if (activeworksbench == null) |
|
102 |
return; |
|
103 |
IWorkbenchPage activepage = activeworksbench.getActivePage(); |
|
104 |
if (activepage == null) |
|
105 |
return; |
|
106 |
RVariablesView rview = (RVariablesView) activepage.findView(RVariablesView.ID); |
|
107 |
if (rview != null) |
|
108 |
rview.tv.refresh(); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Reload. |
|
113 |
*/ |
|
114 |
public static void reload() { |
|
115 |
|
|
116 |
IWorkbenchWindow activeworksbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
117 |
if (activeworksbench == null) |
|
118 |
return; |
|
119 |
IWorkbenchPage activepage = activeworksbench.getActivePage(); |
|
120 |
if (activepage == null) |
|
121 |
return; |
|
122 |
RVariablesView rview = (RVariablesView) activepage.findView(RVariablesView.ID); |
|
123 |
if (rview != null) |
|
124 |
rview._reload(); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* _reload. |
|
129 |
*/ |
|
130 |
public void _reload() { |
|
131 |
tv.setContentProvider(new RVariablesTreeProvider()); |
|
132 |
tv.setLabelProvider(new RVariablesLabelProvider()); |
|
133 |
List<MainCorpus> corpora; |
|
134 |
try { |
|
135 |
corpora = CorpusManager.getCorpusManager().getCorpora(); |
|
136 |
if (corpora != null) |
|
137 |
{ |
|
138 |
buildTreeContent(corpora); |
|
139 |
tv.refresh(); |
|
140 |
} |
|
141 |
} catch (CqiClientException e) { } |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Builds the tree content. |
|
146 |
* |
|
147 |
* @param corpora the corpora |
|
148 |
*/ |
|
149 |
protected void buildTreeContent(List<MainCorpus> corpora) |
|
150 |
{ |
|
151 |
ArrayList<ITXMResult> notempty = new ArrayList<ITXMResult>(corpora); |
|
152 |
for(ITXMResult container : corpora) |
|
153 |
{ |
|
154 |
String symbol = null; |
|
155 |
try { |
|
156 |
Method getname = container.getClass().getMethod("getSymbol"); //$NON-NLS-1$ |
|
157 |
symbol = (String)getname.invoke(container); |
|
158 |
} catch (Exception e2) {} |
|
159 |
|
|
160 |
if (symbol != null) |
|
161 |
continue; |
|
162 |
|
|
163 |
//System.out.println("check "+container.getName()); |
|
164 |
if (container.getResults().size() > 0 |
|
165 |
//FIXME: commented by SJ for TXMResult implementation |
|
166 |
//|| container.getSubHasResults().size() > 0 |
|
167 |
) |
|
168 |
{ |
|
169 |
if (!deepSearch(container)) |
|
170 |
notempty.remove(container); |
|
171 |
} |
|
172 |
else |
|
173 |
{ |
|
174 |
notempty.remove(container); |
|
175 |
} |
|
176 |
} |
|
177 |
tv.setInput(notempty); |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Deep search. |
|
182 |
* |
|
183 |
* @param container the container |
|
184 |
* @return true, if successful |
|
185 |
*/ |
|
186 |
protected boolean deepSearch(ITXMResult container) |
|
187 |
{ |
|
188 |
boolean own = hasSymbol(container.getResults()); |
|
189 |
if (own) |
|
190 |
{ |
|
191 |
return true; |
|
192 |
} |
|
193 |
else // continue deeper |
|
194 |
{ |
|
195 |
|
|
196 |
for(ITXMResult children : container.getResults()) |
|
197 |
{ |
|
198 |
boolean childrencontainer = deepSearch(children); |
|
199 |
if (childrencontainer) |
|
200 |
return true; |
|
201 |
} |
|
202 |
} |
|
203 |
return false; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Checks for symbol. |
|
208 |
* |
|
209 |
* @param results the results |
|
210 |
* @return true, if successful |
|
211 |
*/ |
|
212 |
private boolean hasSymbol(ArrayList<ITXMResult> results) { |
|
213 |
String symbol = null; |
|
214 |
for(Object rez : results) |
|
215 |
{ |
|
216 |
try { |
|
217 |
Method getname = rez.getClass().getMethod("getSymbol"); //$NON-NLS-1$ |
|
218 |
symbol = (String)getname.invoke(rez); |
|
219 |
} catch (Exception e2) {} |
|
220 |
if (symbol != null) |
|
221 |
return true; |
|
222 |
} |
|
223 |
return false; |
|
224 |
} |
|
225 |
|
|
226 |
/* (non-Javadoc) |
|
227 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
228 |
*/ |
|
229 |
@Override |
|
230 |
public void createPartControl(Composite parent) { |
|
231 |
parent.setLayout(new GridLayout(2, true)); |
|
232 |
Button export = new Button(parent, SWT.PUSH); |
|
233 |
export.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, |
|
234 |
false)); |
|
235 |
export.setText(Messages.RVariablesView_1); |
|
236 |
export.addSelectionListener(new SelectionListener() { |
|
237 |
@Override |
|
238 |
public void widgetSelected(SelectionEvent arg0) { |
|
239 |
//System.out.println("reload"); |
|
240 |
_reload(); |
|
241 |
} |
|
242 |
|
|
243 |
@Override |
|
244 |
public void widgetDefaultSelected(SelectionEvent arg0) { } |
|
245 |
}); |
|
246 |
|
|
247 |
Button logs = new Button(parent, SWT.PUSH); |
|
248 |
logs.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
249 |
logs.setText(Messages.RVariablesView_2); |
|
250 |
logs.addSelectionListener(new SelectionListener() { |
|
251 |
@Override |
|
252 |
public void widgetSelected(SelectionEvent arg0) { |
|
253 |
//System.out.println("reload"); |
|
254 |
|
|
255 |
try { |
|
256 |
File homedir = new File(Toolbox.getParam(Toolbox.USER_TXM_HOME)); |
|
257 |
long time = System.currentTimeMillis(); |
|
258 |
File tmp = new File(homedir, "REvalLogs.txt"); //$NON-NLS-1$ |
|
259 |
RWorkspace.saveEvalLog(tmp); |
|
260 |
EditFile.openfile(tmp.getAbsolutePath()); |
|
261 |
} catch (Exception e) { |
|
262 |
// TODO Auto-generated catch block |
|
263 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
@Override |
|
268 |
public void widgetDefaultSelected(SelectionEvent arg0) { } |
|
269 |
}); |
|
270 |
|
|
271 |
tv = new TreeViewer(parent); |
|
272 |
tv.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1)); |
|
273 |
//_reload(); |
|
274 |
|
|
275 |
tv.addDoubleClickListener(new IDoubleClickListener() { |
|
276 |
@Override |
|
277 |
public void doubleClick(DoubleClickEvent event) { |
|
278 |
} |
|
279 |
}); |
|
280 |
|
|
281 |
tv.getTree().addKeyListener(new KeyListener() { |
|
282 |
|
|
283 |
@Override |
|
284 |
public void keyReleased(KeyEvent e) { |
|
285 |
} |
|
286 |
|
|
287 |
@Override |
|
288 |
public void keyPressed(KeyEvent e) { |
|
289 |
/* |
|
290 |
if (e.keyCode == SWT.DEL) { |
|
291 |
DeleteObject.delete(tv.getSelection()); |
|
292 |
} |
|
293 |
else if (e.keyCode == SWT.F5) { |
|
294 |
reload(); |
|
295 |
}*/ |
|
296 |
if ((char)e.keyCode == 'c' & ((e.stateMask & SWT.CTRL) != 0)) |
|
297 |
{ |
|
298 |
TreeSelection selection = (TreeSelection) tv.getSelection(); |
|
299 |
CopySelection.copyFirst(selection); |
|
300 |
|
|
301 |
} |
|
302 |
} |
|
303 |
}); |
|
304 |
|
|
305 |
MenuManager menuManager = new MenuManager(); |
|
306 |
Menu menu = menuManager.createContextMenu(tv.getTree()); |
|
307 |
|
|
308 |
// Set the MenuManager |
|
309 |
tv.getTree().setMenu(menu); |
|
310 |
getSite().registerContextMenu(menuManager, tv); |
|
311 |
// Make the selection available |
|
312 |
getSite().setSelectionProvider(tv); |
|
313 |
} |
|
314 |
|
|
315 |
/* (non-Javadoc) |
|
316 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
317 |
*/ |
|
318 |
@Override |
|
319 |
public void setFocus() { |
|
320 |
// TODO Auto-generated method stub |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
/** |
|
325 |
* The Class RVariablesLabelProvider. |
|
326 |
*/ |
|
327 |
public class RVariablesLabelProvider extends LabelProvider{ |
|
328 |
|
|
329 |
/* (non-Javadoc) |
|
330 |
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
|
331 |
*/ |
|
332 |
@Override |
|
333 |
public String getText(Object element) { |
|
334 |
String name =""; //$NON-NLS-1$ |
|
335 |
String symbol = null; |
|
336 |
|
|
337 |
try { |
|
338 |
Method getname = element.getClass().getMethod("getName"); //$NON-NLS-1$ |
|
339 |
name = (String)getname.invoke(element); |
|
340 |
} catch (Exception e) {} |
|
341 |
|
|
342 |
try { |
|
343 |
Method getname = element.getClass().getMethod("getSymbol"); //$NON-NLS-1$ |
|
344 |
symbol = (String)getname.invoke(element); |
|
345 |
} catch (Exception e) {} |
|
346 |
|
|
347 |
if (symbol == null) |
|
348 |
return name; |
|
349 |
else |
|
350 |
return NLS.bind(Messages.RVariablesView_9, name, symbol); |
|
351 |
} |
|
352 |
|
|
353 |
/* (non-Javadoc) |
|
354 |
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) |
|
355 |
*/ |
|
356 |
@Override |
|
357 |
public final Image getImage(Object element) { |
|
358 |
if (element instanceof Corpus) |
|
359 |
return IImageKeys.getImage(IImageKeys.CORPUS); |
|
360 |
else if (element instanceof Partition) |
|
361 |
return IImageKeys.getImage(IImageKeys.PARTITION); |
|
362 |
else if (element instanceof Lexicon) |
|
363 |
return IImageKeys.getImage(IImageKeys.ACTION_FREQUENCY_LIST); |
|
364 |
else if (element instanceof Index) |
|
365 |
return IImageKeys.getImage(IImageKeys.ACTION_INDEX); |
|
366 |
else if (element instanceof SpecificitesResult) |
|
367 |
return IImageKeys.getImage(IImageKeys.ACTION_SPECIFICITIES); |
|
368 |
else if (element instanceof Concordance) |
|
369 |
return IImageKeys.getImage(IImageKeys.ACTION_CONCORDANCES); |
|
370 |
else if (element instanceof Cooccurrence) |
|
371 |
return IImageKeys.getImage(IImageKeys.ACTION_COOCCURRENCE); |
|
372 |
else if (element instanceof LexicalTable) |
|
373 |
return IImageKeys.getImage(IImageKeys.LEXICALTABLE); |
|
374 |
else if (element instanceof CA) |
|
375 |
return IImageKeys.getImage(IImageKeys.ACTION_CORRESPONDANCE_ANALYSIS); |
|
376 |
else if (element instanceof CAH) |
|
377 |
return IImageKeys.getImage(IImageKeys.ACTION_CAH); |
|
378 |
else if (element instanceof Referencer) |
|
379 |
return IImageKeys.getImage(IImageKeys.ACTION_REFERENCER); |
|
380 |
else if (element instanceof Progression) |
|
381 |
return IImageKeys.getImage(IImageKeys.ACTION_PROGRESSION); |
|
382 |
return null; |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
/** |
|
387 |
* The Class RVariablesTreeProvider. |
|
388 |
*/ |
|
389 |
public class RVariablesTreeProvider implements ITreeContentProvider { |
|
390 |
|
|
391 |
/* (non-Javadoc) |
|
392 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
393 |
*/ |
|
394 |
@Override |
|
395 |
public Object[] getChildren(Object element) { |
|
396 |
//System.out.println("get children of "+element); |
|
397 |
if (element instanceof ITXMResult) { |
|
398 |
// List<Object> results = ((HasResults) element).getResults(); |
|
399 |
// ArrayList<ITXMResult> sub = ((HasResults) element).getSubHasResults(); |
|
400 |
//ArrayList<Object> children = new ArrayList<Object>(); |
|
401 |
// children.addAll(sub); |
|
402 |
// children.addAll(results); |
|
403 |
|
|
404 |
ArrayList<ITXMResult> children = ((ITXMResult)element).getDeepResults(); |
|
405 |
|
|
406 |
for(int i = 0 ; i < children.size() ; i++) |
|
407 |
{ |
|
408 |
|
|
409 |
Object obj = children.get(i); |
|
410 |
//System.out.println("test > "+obj); |
|
411 |
if (obj instanceof ITXMResult) |
|
412 |
{ |
|
413 |
//System.out.println("deap "+obj); |
|
414 |
if (!deepSearch((ITXMResult) obj)) |
|
415 |
{ |
|
416 |
children.remove(i); |
|
417 |
i--; |
|
418 |
} |
|
419 |
} |
|
420 |
else |
|
421 |
{ |
|
422 |
String symbol = null; |
|
423 |
try { |
|
424 |
Method getname = obj.getClass().getMethod("getSymbol"); //$NON-NLS-1$ |
|
425 |
symbol = (String)getname.invoke(obj); |
|
426 |
} catch (Exception e) {} |
|
427 |
//System.out.println("symbol "+symbol); |
|
428 |
if (symbol == null) |
|
429 |
{ |
|
430 |
children.remove(i); |
|
431 |
i--; |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
//System.out.println(""+element+" > "+children); |
|
436 |
return children.toArray(); |
|
437 |
} |
|
438 |
return new Object[0]; |
|
439 |
} |
|
440 |
|
|
441 |
/* (non-Javadoc) |
|
442 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
443 |
*/ |
|
444 |
@Override |
|
445 |
public Object getParent(Object element) { |
|
446 |
Partition partition = null; |
|
447 |
try { |
|
448 |
Method getname = element.getClass().getMethod("getPartition"); //$NON-NLS-1$ |
|
449 |
partition = (Partition)getname.invoke(element); |
|
450 |
} catch (Exception e) {} |
|
451 |
|
|
452 |
if (partition == null) |
|
453 |
{ |
|
454 |
return partition; |
|
455 |
} |
|
456 |
|
|
457 |
Corpus corpus = null; |
|
458 |
try { |
|
459 |
Method getname = element.getClass().getMethod("getCorpus"); //$NON-NLS-1$ |
|
460 |
corpus = (Corpus)getname.invoke(element); |
|
461 |
} catch (Exception e) {} |
|
462 |
|
|
463 |
return corpus; |
|
464 |
} |
|
465 |
|
|
466 |
/* (non-Javadoc) |
|
467 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|
468 |
*/ |
|
469 |
@Override |
|
470 |
public boolean hasChildren(Object element) { |
|
471 |
if (element instanceof ITXMResult) { |
|
472 |
return getChildren(element).length > 0; |
|
473 |
} |
|
474 |
return false; |
|
475 |
} |
|
476 |
|
|
477 |
/* (non-Javadoc) |
|
478 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
479 |
*/ |
|
480 |
@Override |
|
481 |
public Object[] getElements(Object element) { |
|
482 |
Collection<Base> input = (Collection<Base>) element; |
|
483 |
Object[] objects = new Object[input.size()]; |
|
484 |
Iterator<Base> it = input.iterator(); |
|
485 |
int i = 0; |
|
486 |
while (it.hasNext()) { |
|
487 |
objects[i] = it.next(); |
|
488 |
i++; |
|
489 |
} |
|
490 |
return objects; |
|
491 |
} |
|
492 |
|
|
493 |
/* (non-Javadoc) |
|
494 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
495 |
*/ |
|
496 |
@Override |
|
497 |
public void dispose() { |
|
498 |
} |
|
499 |
|
|
500 |
/* (non-Javadoc) |
|
501 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
502 |
*/ |
|
503 |
@Override |
|
504 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
0 | 508 |
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/ExecuteRScript.java (revision 236) | ||
---|---|---|
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.io.BufferedReader; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileReader; |
|
33 |
import java.util.Iterator; |
|
34 |
|
|
35 |
import org.eclipse.core.commands.AbstractHandler; |
|
36 |
import org.eclipse.core.commands.ExecutionEvent; |
|
37 |
import org.eclipse.core.commands.ExecutionException; |
|
38 |
import org.eclipse.core.runtime.Platform; |
|
39 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
|
40 |
import org.eclipse.jface.viewers.ISelection; |
|
41 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
42 |
import org.eclipse.osgi.util.NLS; |
|
43 |
import org.eclipse.swt.SWT; |
|
44 |
import org.eclipse.swt.widgets.FileDialog; |
|
45 |
import org.eclipse.swt.widgets.Shell; |
|
46 |
import org.eclipse.ui.IViewPart; |
|
47 |
import org.eclipse.ui.IWorkbenchPage; |
|
48 |
import org.eclipse.ui.IWorkbenchPart; |
|
49 |
import org.eclipse.ui.IWorkbenchWindow; |
|
50 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
51 |
import org.eclipse.ui.ide.FileStoreEditorInput; |
|
52 |
import org.txm.rcpapplication.Application; |
|
53 |
import org.txm.rcpapplication.Messages; |
|
54 |
import org.txm.rcpapplication.StatusLine; |
|
55 |
import org.txm.rcpapplication.editors.TxtEditor; |
|
56 |
import org.txm.rcpapplication.preferences.ScriptPreferenceInitializer; |
|
57 |
import org.txm.rcpapplication.preferences.ScriptPreferencePage; |
|
58 |
import org.txm.rcpapplication.swt.dialog.LastOpened; |
|
59 |
import org.txm.statsengine.r.core.RWorkspace; |
|
60 |
import org.txm.statsengine.r.core.RWorkspaceException; |
|
61 |
import org.txm.statsengine.r.rcp.views.RConsole; |
|
62 |
import org.txm.utils.logger.Log; |
|
63 |
// TODO: Auto-generated Javadoc |
|
64 |
/** |
|
65 |
* Handler: Execute a R script file in the same thread a the RCP. |
|
66 |
* |
|
67 |
* @author mdecorde |
|
68 |
*/ |
|
69 |
public class ExecuteRScript extends AbstractHandler { |
|
70 |
|
|
71 |
private static final String ID = "org.txm.rcpapplication.commands.ExecuteRScript"; //$NON-NLS-1$ |
|
72 |
/* (non-Javadoc) |
|
73 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
74 |
*/ |
|
75 |
@Override |
|
76 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
77 |
String result = ""; //$NON-NLS-1$ |
|
78 |
IWorkbenchWindow aww = HandlerUtil.getActiveWorkbenchWindow(event); |
|
79 |
IWorkbenchPage page = aww.getActivePage(); |
|
80 |
IViewPart view = page.findView(RConsole.ID); |
|
81 |
if (view != null && view instanceof RConsole) { |
|
82 |
((RConsole)view).connectToRWorkspace(); |
|
83 |
} |
|
84 |
IWorkbenchPart part = page.getActivePart(); |
|
85 |
|
|
86 |
ISelection selection = page.getSelection(); |
|
87 |
if (part != null && part instanceof TxtEditor) { |
|
88 |
TxtEditor te = (TxtEditor) part; |
|
89 |
FileStoreEditorInput input = (FileStoreEditorInput) te |
|
90 |
.getEditorInput(); |
|
91 |
|
|
92 |
File f = new File(input.getURI().getPath()); |
|
93 |
result = f.getAbsolutePath(); |
|
94 |
} else if (selection != null |
|
95 |
& selection instanceof IStructuredSelection) { |
|
96 |
File file = null; |
|
97 |
IStructuredSelection strucSelection = (IStructuredSelection) selection; |
|
98 |
for (Iterator<Object> iterator = strucSelection.iterator(); iterator |
|
99 |
.hasNext();) { |
|
100 |
file = (File) iterator.next(); |
|
101 |
result = file.getAbsolutePath(); |
|
102 |
break; |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
if ("" == result) { //$NON-NLS-1$ |
|
107 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
108 |
.getShell(); |
|
109 |
FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
|
110 |
if (LastOpened.getFile(ID) != null) { |
|
111 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
|
112 |
dialog.setFileName(LastOpened.getFile(ID)); |
|
113 |
} |
|
114 |
dialog.setFilterExtensions(new String[] { "*.R" }); //$NON-NLS-1$ |
|
115 |
|
|
116 |
IPreferencesService service = Platform.getPreferencesService(); |
|
117 |
String scriptCurrentDir = service.getString(Application.PLUGIN_ID, |
|
118 |
ScriptPreferencePage.SCRIPT_CURRENT_DIR, |
|
119 |
ScriptPreferenceInitializer.SCRIPT_CURRENT_DIR_DEFAULT, |
|
120 |
null); |
|
121 |
|
|
122 |
dialog.setFilterPath(scriptCurrentDir); |
|
123 |
result = dialog.open(); |
|
124 |
if (result == null) return null; |
|
125 |
LastOpened.set(ID, new File(result)); |
|
126 |
} |
|
127 |
|
|
128 |
executeScript(result); |
|
129 |
return null; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Execute script. |
|
134 |
* |
|
135 |
* @param scriptfile the scriptfile |
|
136 |
*/ |
|
137 |
public static void executeScript(String scriptfile) { |
|
138 |
File rFile = new File(scriptfile); |
|
139 |
if (!rFile.exists()) { |
|
140 |
System.err.println(NLS.bind(Messages.ExecuteScriptR_0, rFile)); |
|
141 |
return; |
|
142 |
} |
|
143 |
|
|
144 |
RWorkspace rw = null; |
|
145 |
try { |
|
146 |
rw = RWorkspace.getRWorkspaceInstance(); |
|
147 |
} catch (RWorkspaceException e1) { |
|
148 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e1); |
|
149 |
return; |
|
150 |
} |
|
151 |
boolean initState = rw.isLogging(); |
|
152 |
rw.setLog(true); |
|
153 |
try { |
|
154 |
System.out.println(NLS.bind(Messages.ExecuteRScript_1, rFile.getName())); |
|
155 |
long time = System.currentTimeMillis(); |
|
156 |
//execute a file line per line |
|
157 |
|
|
158 |
//if (TxmPreferences.getBoolean(RPreferencePage.R_REMOTE)) { |
|
159 |
BufferedReader reader = new BufferedReader(new FileReader(rFile));// create a file reader |
|
160 |
String line = reader.readLine();// read next line |
|
161 |
StringBuffer buffer = new StringBuffer(); |
|
162 |
while(line != null) { |
|
163 |
buffer.append(line+"\n"); //$NON-NLS-1$ |
|
164 |
line = reader.readLine();//read next line |
|
165 |
} |
|
166 |
|
|
167 |
String allScript = buffer.toString(); |
|
168 |
//if (rw.isLogging() && allScript.length() > 0) RConsole.printUser(allScript); |
|
169 |
|
|
170 |
//String str = rw.userEval(allScript); // evaluate line in R |
|
171 |
rw.eval(allScript); |
|
172 |
//if (str != null && rw.isLogging() && str.length() > 0) |
|
173 |
//RConsole.printServer(str); |
|
174 |
reader.close(); |
|
175 |
// } else { |
|
176 |
// String cmd = "source(\""+rFile.getAbsolutePath().replace("\\", "/")+"\")"; |
|
177 |
// if (rw.isLogging()) |
|
178 |
// RConsole.printUser)(cmd); |
|
179 |
// String str = rw.userEval(cmd);//evaluate line in R |
|
180 |
// if (rw.isLogging() && str.length() > 0) |
|
181 |
// RConsole.printServer(cmd); |
|
182 |
// } |
|
183 |
System.out.println(Messages.ExecuteRScript_2+(System.currentTimeMillis()-time)+Messages.ExecuteRScript_3); |
|
184 |
} catch(Exception e) { |
|
185 |
System.out.println(NLS.bind(Messages.ExecuteScriptR_1, rFile, e)); |
|
186 |
StatusLine.error(NLS.bind(Messages.ExecuteScriptR_1, rFile, e)); |
|
187 |
Log.printStackTrace(e); |
|
188 |
} |
|
189 |
|
|
190 |
rw.setLog(initState); |
|
191 |
} |
|
192 |
} |
|
0 | 193 |
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/ExecuteRText.java (revision 236) | ||
---|---|---|
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 |
Formats disponibles : Unified diff