Révision 438
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMResultEditorInput.java (revision 438) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.editors; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Properties; |
|
5 |
|
|
6 | 3 |
import org.eclipse.jface.resource.ImageDescriptor; |
7 | 4 |
import org.eclipse.ui.IEditorInput; |
8 | 5 |
import org.eclipse.ui.IPersistableElement; |
9 |
import org.txm.core.results.ITXMResult;
|
|
6 |
import org.txm.core.results.TXMResult; |
|
10 | 7 |
|
11 | 8 |
/** |
12 | 9 |
* Base class of all TXM results <code>IEditorInput</code>. |
... | ... | |
26 | 23 |
/** |
27 | 24 |
* TXM result object. |
28 | 25 |
*/ |
29 |
protected ITXMResult result;
|
|
26 |
protected TXMResult result; |
|
30 | 27 |
|
28 |
|
|
31 | 29 |
|
32 |
|
|
33 |
//FIXME: parameters tests |
|
34 |
protected HashMap<String, Object> params; |
|
35 |
protected ITXMResult source; |
|
36 |
|
|
37 |
|
|
38 | 30 |
/** |
39 |
* Creates an editor input with no linked TXM result. |
|
31 |
* Creates an editor input and stores the specified TXM result as source object for further result computing. |
|
32 |
* @param sourceResult |
|
33 |
* @param preferencesNodeQualifier |
|
40 | 34 |
*/ |
41 |
public TXMResultEditorInput() { |
|
42 |
this(null); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* Creates an editor input and stores it the specified TXM result. |
|
48 |
* @param result |
|
49 |
*/ |
|
50 |
public TXMResultEditorInput(ITXMResult result) { |
|
35 |
public TXMResultEditorInput(TXMResult result) { |
|
51 | 36 |
this.result = result; |
52 | 37 |
this.alwaysRecreateEditor = false; |
53 |
|
|
54 | 38 |
} |
55 |
|
|
56 |
//FIXME: parameters tests |
|
57 |
public TXMResultEditorInput(ITXMResult source, HashMap<String, Object> parameters) { |
|
58 |
this.source = source; |
|
59 |
this.params = parameters; |
|
60 |
} |
|
61 | 39 |
|
62 | 40 |
/** |
63 | 41 |
* Gets the TXM result associated with the editor input. |
64 | 42 |
* @return the linked result |
65 | 43 |
*/ |
66 |
public ITXMResult getResult() {
|
|
44 |
public TXMResult getResult() { |
|
67 | 45 |
return result; |
68 | 46 |
} |
69 | 47 |
|
... | ... | |
71 | 49 |
* Sets the result data associated with the editor input. |
72 | 50 |
* @param resultData the resultData to set |
73 | 51 |
*/ |
74 |
//FIXME: this method is only used for CAH, should be removed later |
|
75 |
public void setResult(ITXMResult resultData) { |
|
52 |
public void setResult(TXMResult resultData) { |
|
76 | 53 |
this.result = resultData; |
77 | 54 |
} |
78 | 55 |
|
... | ... | |
86 | 63 |
} |
87 | 64 |
|
88 | 65 |
|
66 |
|
|
89 | 67 |
@Override |
90 | 68 |
public String getName() { |
91 | 69 |
try { |
... | ... | |
156 | 134 |
} |
157 | 135 |
|
158 | 136 |
|
159 |
/** |
|
160 |
* @return the params |
|
161 |
*/ |
|
162 |
public HashMap<String, Object> getParams() { |
|
163 |
return params; |
|
164 |
} |
|
165 | 137 |
|
166 | 138 |
|
167 | 139 |
/** |
168 |
* @return the source |
|
140 |
* Sets and updates the local preferences node qualifier from the result data. |
|
141 |
* Synchronizes the local preferences node with the result data type, etc. |
|
169 | 142 |
*/ |
170 |
public ITXMResult getSource() { |
|
171 |
return source; |
|
143 |
public void syncLocalPreferencesNode() { |
|
144 |
System.err.println("TXMResultEditorInput.syncLocalPreferencesNode(): not yet implemented."); |
|
145 |
// FIXME: persistence test |
|
146 |
// TXMPreferences.putLocalString(this.result, ChartsEnginePreferences.RESULT_DATA_TYPE, this.result.getClass().getName()); |
|
172 | 147 |
} |
173 | 148 |
|
174 |
|
|
149 |
|
|
175 | 150 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/RCPCommandsAPI.java (revision 438) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.editors; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 |
|
|
5 |
import org.eclipse.ui.PartInitException; |
|
3 |
import org.txm.core.results.TXMParameters; |
|
6 | 4 |
import org.txm.core.results.TXMResult; |
7 | 5 |
import org.txm.functions.Command; |
8 | 6 |
import org.txm.functions.CommandsAPI; |
9 |
import org.txm.rcp.TXMWindows; |
|
10 |
import org.txm.utils.logger.Log; |
|
7 |
import org.txm.functions.TXMCommand; |
|
11 | 8 |
|
12 | 9 |
/** |
13 | 10 |
* Interface to call commands from a RCP plugin |
... | ... | |
19 | 16 |
|
20 | 17 |
/** |
21 | 18 |
* @param cmd the command to call or the command to open with the right editor |
22 |
* @param parent the result parent
|
|
19 |
* @param source the result parent
|
|
23 | 20 |
* @param parameters the parameters to compute the command or the parameters to set editor parameters with |
24 | 21 |
* |
25 | 22 |
* @return A result or the editor's result. null if the command failed to compute or to open editor. |
26 | 23 |
*/ |
27 |
public Object call(String cmd, TXMResult parent, HashMap<String, Object> parameters) { |
|
24 |
//FIXME: the source is not used, see if we decide to put it the TXMParameters or not, otherwise define a method TXMResult.setSource() or maybe better a method TXMResult.compute(TXMResul source) |
|
25 |
public Object call(String cmd, TXMResult source, TXMParameters parameters) { |
|
28 | 26 |
|
29 | 27 |
Command command = cmds.get(cmd); |
30 | 28 |
if (command == null) { |
... | ... | |
33 | 31 |
} |
34 | 32 |
|
35 | 33 |
if (command instanceof RCPCommand) { |
36 |
|
|
34 |
|
|
37 | 35 |
RCPCommand rcpcommand = (RCPCommand)command; |
36 |
TXMCommand result = null; |
|
38 | 37 |
|
39 | 38 |
if (rcpcommand.editor_id == null) { |
40 | 39 |
System.out.println("Failed to open editor: no context given."); |
41 | 40 |
return null; |
42 | 41 |
} |
43 | 42 |
|
44 |
// the editor will compute the command |
|
45 |
TXMResultEditorInput editorInput = new TXMResultEditorInput(parent, parameters); |
|
46 | 43 |
try { |
47 |
TXMEditorPart editor = (TXMEditorPart) TXMWindows.getActiveWindow().getActivePage() |
|
48 |
.openEditor(editorInput, rcpcommand.editor_id); |
|
49 |
// if (editor.isReady()) { |
|
44 |
// the editor will compute the command |
|
45 |
result = rcpcommand.clazz.newInstance(); |
|
46 |
result.setParameters(parameters); |
|
47 |
|
|
48 |
TXMResultEditorInput editorInput = new TXMResultEditorInput(result); |
|
49 |
TXMEditorPart editor = TXMEditorPart.openEditor(editorInput, rcpcommand.editor_id); |
|
50 |
if (editor != null) { |
|
50 | 51 |
return editor; |
51 |
// } else { |
|
52 |
// System.out.println("Failed to open editor: internal error during initialisation."); |
|
53 |
// return null; |
|
54 |
// } |
|
55 |
} catch (PartInitException e) { |
|
56 |
System.out.println("Failed to open editor with "+cmd+" command and "+parameters+" parameters: "+e.getLocalizedMessage()); |
|
57 |
Log.printStackTrace(e); |
|
52 |
} |
|
53 |
else { |
|
54 |
System.out.println("Failed to open editor: internal error during initialisation."); |
|
55 |
System.out.println("Failed to open editor with "+cmd+" command and "+parameters+" parameters."); |
|
56 |
} |
|
58 | 57 |
} |
59 |
return null; |
|
60 |
|
|
61 |
} else { |
|
62 |
Object result = super.call(cmd, parent, parameters); |
|
63 |
System.out.println("Done: "+result); |
|
58 |
catch(InstantiationException e) { |
|
59 |
// TODO Auto-generated catch block |
|
60 |
e.printStackTrace(); |
|
61 |
} |
|
62 |
catch(IllegalAccessException e) { |
|
63 |
// TODO Auto-generated catch block |
|
64 |
e.printStackTrace(); |
|
65 |
} |
|
64 | 66 |
return result; |
67 |
} |
|
68 |
else { |
|
69 |
Object result = super.call(cmd, source, parameters); |
|
70 |
System.out.println("Done: " + result); |
|
71 |
return result; |
|
65 | 72 |
} |
66 | 73 |
} |
67 | 74 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditorPart.java (revision 438) | ||
---|---|---|
24 | 24 |
import org.eclipse.ui.part.EditorPart; |
25 | 25 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput; |
26 | 26 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
27 |
import org.txm.cooccurrence.core.preferences.CooccurrencePreferences; |
|
27 | 28 |
import org.txm.cooccurrence.rcp.editors.CooccurrencesEditor; |
28 |
import org.txm.core.results.ITXMResult; |
|
29 |
import org.txm.core.preferences.TXMPreferences; |
|
30 |
import org.txm.core.results.TXMResult; |
|
31 |
import org.txm.core.results.TXMParameters; |
|
29 | 32 |
import org.txm.rcp.IImageKeys; |
30 | 33 |
import org.txm.rcp.Messages; |
31 | 34 |
import org.txm.rcp.StatusLine; |
... | ... | |
67 | 70 |
} |
68 | 71 |
|
69 | 72 |
|
70 |
|
|
73 |
|
|
71 | 74 |
@Override |
72 | 75 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException { |
73 | 76 |
this.setSite(site); |
... | ... | |
247 | 250 |
return (TXMResultEditorInput) super.getEditorInput(); |
248 | 251 |
} |
249 | 252 |
|
253 |
|
|
250 | 254 |
/** |
255 |
* Returns the preferences node qualifier linked to the result of this editor. |
|
256 |
* @return |
|
257 |
*/ |
|
258 |
public String getPreferencesNodeQualifier() { |
|
259 |
return this.getResultData().getPreferencesNodeQualifier(); |
|
260 |
} |
|
261 |
|
|
262 |
|
|
263 |
/** |
|
251 | 264 |
* Returns the result object associated with the editor through its editor input. |
252 | 265 |
* @return |
253 | 266 |
*/ |
254 |
public ITXMResult getResultData() {
|
|
267 |
public TXMResult getResultData() { |
|
255 | 268 |
return this.getEditorInput().getResult(); |
256 | 269 |
} |
257 | 270 |
|
258 | 271 |
|
259 | 272 |
/** |
273 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
274 |
* @param key |
|
275 |
* @return |
|
276 |
*/ |
|
277 |
public int getIntParameterValue(String key) { |
|
278 |
return this.getEditorInput().getResult().getIntParameterValue(key); |
|
279 |
} |
|
280 |
|
|
281 |
|
|
282 |
/** |
|
283 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
284 |
* @param key |
|
285 |
* @return |
|
286 |
*/ |
|
287 |
public float getFloatParameterValue(String key) { |
|
288 |
return this.getEditorInput().getResult().getFloatParameterValue(key); |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
293 |
* @param key |
|
294 |
* @return |
|
295 |
*/ |
|
296 |
public double getDoubleParameterValue(String key) { |
|
297 |
return this.getEditorInput().getResult().getDoubleParameterValue(key); |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
/** |
|
302 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
303 |
* @param key |
|
304 |
* @return |
|
305 |
*/ |
|
306 |
public boolean getBooleanParameterValue(String key) { |
|
307 |
return this.getEditorInput().getResult().getBooleanParameterValue(key); |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
312 |
* @param key |
|
313 |
* @return |
|
314 |
*/ |
|
315 |
public long getLongParameterValue(String key) { |
|
316 |
return this.getEditorInput().getResult().getLongParameterValue(key); |
|
317 |
} |
|
318 |
|
|
319 |
/** |
|
320 |
* Gets the value of the specified key in parameters, local result node or default preferences nodes. |
|
321 |
* @param key |
|
322 |
* @return |
|
323 |
*/ |
|
324 |
public String getStringParameterValue(String key) { |
|
325 |
return this.getEditorInput().getResult().getStringParameterValue(key); |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
260 | 329 |
* Computes and creates or updates the result (from the linked editor input data). |
261 | 330 |
* @param update set if it's an update on an existing result or a creation of a new result |
262 | 331 |
*/ |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/RCPCommand.java (revision 438) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.editors; |
2 | 2 |
|
3 |
import org.txm.core.results.TXMResult; |
|
4 | 3 |
import org.txm.functions.Command; |
4 |
import org.txm.functions.TXMCommand; |
|
5 | 5 |
|
6 | 6 |
/** |
7 | 7 |
* A command that opens an editor (which will computes the result). |
... | ... | |
15 | 15 |
|
16 | 16 |
public final String editor_id; |
17 | 17 |
|
18 |
public RCPCommand(Class<TXMResult> clazz, String editor_id) {
|
|
18 |
public RCPCommand(Class<TXMCommand> clazz, String editor_id) {
|
|
19 | 19 |
super(clazz); |
20 | 20 |
this.editor_id = editor_id; |
21 | 21 |
} |
22 | 22 |
|
23 |
public RCPCommand(String cmd, Class<TXMResult> clazz, String editor_id) {
|
|
23 |
public RCPCommand(String cmd, Class<TXMCommand> clazz, String editor_id) {
|
|
24 | 24 |
super(cmd, clazz); |
25 | 25 |
this.editor_id = editor_id; |
26 | 26 |
} |
Formats disponibles : Unified diff