|
1 |
package org.txm.chartsengine.rcp;
|
|
2 |
|
|
3 |
|
|
4 |
import java.awt.event.MouseEvent;
|
|
5 |
import java.awt.event.MouseListener;
|
|
6 |
import java.awt.event.MouseMotionListener;
|
|
7 |
import java.io.File;
|
|
8 |
import java.util.ArrayList;
|
|
9 |
import java.util.Arrays;
|
|
10 |
import java.util.List;
|
|
11 |
import java.util.Properties;
|
|
12 |
|
|
13 |
import javax.swing.JComponent;
|
|
14 |
|
|
15 |
import org.eclipse.core.runtime.CoreException;
|
|
16 |
import org.eclipse.core.runtime.IConfigurationElement;
|
|
17 |
import org.eclipse.core.runtime.Platform;
|
|
18 |
import org.eclipse.jface.preference.BooleanFieldEditor;
|
|
19 |
import org.eclipse.jface.preference.ComboFieldEditor;
|
|
20 |
import org.eclipse.swt.SWT;
|
|
21 |
import org.eclipse.swt.graphics.Point;
|
|
22 |
import org.eclipse.swt.layout.GridData;
|
|
23 |
import org.eclipse.swt.layout.RowLayout;
|
|
24 |
import org.eclipse.swt.widgets.Composite;
|
|
25 |
import org.eclipse.swt.widgets.Event;
|
|
26 |
import org.eclipse.swt.widgets.Group;
|
|
27 |
import org.eclipse.swt.widgets.Label;
|
|
28 |
import org.eclipse.swt.widgets.Listener;
|
|
29 |
import org.eclipse.swt.widgets.TabFolder;
|
|
30 |
import org.eclipse.swt.widgets.TabItem;
|
|
31 |
import org.eclipse.swt.widgets.ToolBar;
|
|
32 |
import org.eclipse.ui.IWorkbenchPage;
|
|
33 |
import org.eclipse.ui.IWorkbenchWindow;
|
|
34 |
import org.eclipse.ui.PartInitException;
|
|
35 |
import org.eclipse.ui.PlatformUI;
|
|
36 |
import org.txm.chartsengine.core.ChartCreator;
|
|
37 |
import org.txm.chartsengine.core.ChartsEngine;
|
|
38 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences;
|
|
39 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput;
|
|
40 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart;
|
|
41 |
import org.txm.chartsengine.rcp.events.EventCallBack;
|
|
42 |
import org.txm.chartsengine.rcp.events.EventCallBackHandler;
|
|
43 |
import org.txm.chartsengine.rcp.messages.SWTComponentsProviderMessages;
|
|
44 |
import org.txm.chartsengine.rcp.preferences.___KeyboardBindingProperties;
|
|
45 |
import org.txm.chartsengine.rcp.preferences.___MouseBindingProperties;
|
|
46 |
import org.txm.chartsengine.rcp.swt.ChartComposite;
|
|
47 |
import org.txm.functions.TXMResult;
|
|
48 |
import org.txm.rcp.preferences.TXMPreferencePage;
|
|
49 |
import org.txm.utils.logger.Log;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* A class providing EditorPart and EditorInput according to the current charts engine.
|
|
53 |
* @author sjacquot
|
|
54 |
*
|
|
55 |
*/
|
|
56 |
public abstract class SWTChartsComponentsProvider {
|
|
57 |
|
|
58 |
/**
|
|
59 |
* The charts engine.
|
|
60 |
*/
|
|
61 |
protected ChartsEngine chartsEngine;
|
|
62 |
|
|
63 |
|
|
64 |
/**
|
|
65 |
* The name of the provider.
|
|
66 |
*/
|
|
67 |
protected String name;
|
|
68 |
|
|
69 |
/**
|
|
70 |
* The supported editor input formats.
|
|
71 |
*/
|
|
72 |
protected List<String> supportedInputFormats;
|
|
73 |
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Mouse control properties which will be shared by all implementations and chart editors.
|
|
77 |
*/
|
|
78 |
protected Properties mouseBindingProperties;
|
|
79 |
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Keyboard control properties which will be shared by all implementations and chart editors.
|
|
83 |
*/
|
|
84 |
protected Properties keyboardBindingProperties;
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Installed SWT charts components providers.
|
|
90 |
*/
|
|
91 |
protected static ArrayList<SWTChartsComponentsProvider> chartsComponentsProviders;
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Current SWT charts components provider index in the providers list.
|
|
95 |
*/
|
|
96 |
protected static int currentChartsComponentsProviderIndex;
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
public SWTChartsComponentsProvider(ChartsEngine chartsEngine, Properties mouseBindingProperties, Properties keyboardBindingProperties) {
|
|
101 |
this.chartsEngine = chartsEngine;
|
|
102 |
|
|
103 |
this.mouseBindingProperties = mouseBindingProperties;
|
|
104 |
this.keyboardBindingProperties = keyboardBindingProperties;
|
|
105 |
|
|
106 |
// FIXME: chart engine plugin split tests
|
|
107 |
// this.chartEditorCreators = new HashMap<Class, ChartEditorCreator>();
|
|
108 |
|
|
109 |
|
|
110 |
// FIXME : see if we need to define the L&F as system for AWT/Swing components
|
|
111 |
// If yes, we need to find a way to manage the GTK L&F/Linux bug, see ticket #761
|
|
112 |
// System Look and feel
|
|
113 |
// try {
|
|
114 |
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
115 |
// }
|
|
116 |
// catch(ClassNotFoundException e) {
|
|
117 |
// // TODO Auto-generated catch block
|
|
118 |
// e.printStackTrace();
|
|
119 |
// }
|
|
120 |
// catch(InstantiationException e) {
|
|
121 |
// // TODO Auto-generated catch block
|
|
122 |
// e.printStackTrace();
|
|
123 |
// }
|
|
124 |
// catch(IllegalAccessException e) {
|
|
125 |
// // TODO Auto-generated catch block
|
|
126 |
// e.printStackTrace();
|
|
127 |
// }
|
|
128 |
// catch(UnsupportedLookAndFeelException e) {
|
|
129 |
// // TODO Auto-generated catch block
|
|
130 |
// e.printStackTrace();
|
|
131 |
// }
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
public SWTChartsComponentsProvider(ChartsEngine chartsEngine) {
|
|
136 |
this(chartsEngine, new ___MouseBindingProperties(), new ___KeyboardBindingProperties());
|
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
public SWTChartsComponentsProvider() {
|
|
141 |
this(null);
|
|
142 |
}
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Creates and return a SWT EditorPart filled with a new chart for the specified result and chart type.
|
|
148 |
* @param editorInputName
|
|
149 |
* @param resultData
|
|
150 |
* @param preferencesNode
|
|
151 |
* @param chartType
|
|
152 |
* @return
|
|
153 |
*/
|
|
154 |
public ChartEditorPart createChartEditor(String editorInputName, TXMResult resultData, String preferencesNode, String chartType) {
|
|
155 |
ChartEditorInput chartEditorInput = new ChartEditorInput(this, editorInputName, resultData, preferencesNode, chartType, null);
|
|
156 |
this.createChart(chartEditorInput, resultData, preferencesNode, chartType);
|
|
157 |
ChartEditorPart editor = new ChartEditorPart(this, chartEditorInput);
|
|
158 |
return editor;
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
/**
|
|
164 |
* Creates a new chart for the specified result data and save it in the specified editor input.
|
|
165 |
* A chart editor created with the editor input will be filled with chart.
|
|
166 |
* @param chartEditorInput
|
|
167 |
* @param resultData
|
|
168 |
* @param params
|
|
169 |
*/
|
|
170 |
public void createChart(ChartEditorInput chartEditorInput, TXMResult resultData, String preferencesNode) {
|
|
171 |
this.createChart(chartEditorInput, resultData, preferencesNode, chartEditorInput.getChartType());
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Creates a new chart for the specified result data and chart type and save it in the specified editor input.
|
|
176 |
* A chart editor created with the editor input will be filled with chart.
|
|
177 |
* @param chartEditorInput
|
|
178 |
* @param resultData
|
|
179 |
* @param chartType
|
|
180 |
* @param params
|
|
181 |
*/
|
|
182 |
protected abstract boolean createChart(ChartsEngine chartsEngine, ChartEditorInput chartEditorInput, TXMResult resultData, String preferencesNode, String chartType);
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Creates a new chart for the specified result data and chart type and save it in the specified editor input.
|
|
186 |
* @param chartEditorInput
|
|
187 |
* @param resultData
|
|
188 |
* @param chartType
|
|
189 |
* @param params
|
|
190 |
* @return
|
|
191 |
*/
|
|
192 |
protected boolean createChart(ChartEditorInput chartEditorInput, TXMResult resultData, String preferencesNode, String chartType) {
|
|
193 |
return this.createChart(this.getChartsEngine(), chartEditorInput, resultData, preferencesNode, chartType);
|
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Updates the specified chart stored in the editor and according to the stored TXM result.
|
|
199 |
* @param chartsEngine
|
|
200 |
* @param editor
|
|
201 |
* @param chartType
|
|
202 |
* @param command
|
|
203 |
* @param params
|
|
204 |
* @return
|
|
205 |
*/
|
|
206 |
public boolean updateChart(ChartEditorPart editor, String preferencesNode, String chartType) {
|
|
207 |
ChartCreator chartCreator = this.chartsEngine.getChartCreator(editor.getResultData().getClass(), chartType);
|
|
208 |
if(chartCreator != null) {
|
|
209 |
chartCreator.updateChart(editor.getChart(), editor.getResultData(), preferencesNode);
|
|
210 |
return true;
|
|
211 |
}
|
|
212 |
return false;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Updates the specified chart stored in the editor and according to the stored TXM result.
|
|
218 |
* @param editor
|
|
219 |
* @param command
|
|
220 |
* @param params
|
|
221 |
* @return
|
|
222 |
*/
|
|
223 |
public boolean updateChart(ChartEditorPart editor) {
|
|
224 |
return this.updateChart(editor, editor.getPreferencesNodeQualifier(), editor.getChartType());
|
|
225 |
}
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
/**
|
|
230 |
* Creates and stores SWT charts components providers from installed extension contributions and define the current one according to the specified charts engine output format and provider supported input format.
|
|
231 |
* @return
|
|
232 |
*/
|
|
233 |
public static void createSWTChartsComponentsProviders() {
|
|
234 |
|
|
235 |
|
|
236 |
SWTChartsComponentsProvider.chartsComponentsProviders = new ArrayList<SWTChartsComponentsProvider>();
|
|
237 |
|
|
238 |
String extensionPointId = "org.txm.rcp.swtchartscomponentsprovider"; //$NON-NLS-1$
|
|
239 |
IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
|
|
240 |
|
|
241 |
for(int i = 0; i < contributions.length; i++) {
|
|
242 |
|
|
243 |
// FIXME: to manage more than one input format, Store them in the class rather than in the extension schema?
|
|
244 |
String formatsStr = contributions[i].getAttribute("inputFormat").replace(" ", "").trim();
|
|
245 |
String[] formats = formatsStr.split(",");
|
|
246 |
|
|
247 |
try {
|
|
248 |
SWTChartsComponentsProvider swtChartsComponentsProvider = (SWTChartsComponentsProvider)contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
|
|
249 |
swtChartsComponentsProvider.setName(contributions[i].getAttribute("name")); //$NON-NLS-1$
|
|
250 |
swtChartsComponentsProvider.setEditorSupportedInputFormat(Arrays.asList(formats));
|
|
251 |
|
|
252 |
// Add the first charts engine that supports the input format
|
|
253 |
ChartsEngine chartsEngine = null;
|
|
254 |
for(int j = 0; j < formats.length; j++) {
|
|
255 |
chartsEngine = ChartsEngine.getChartsEngine(formats[j]);
|
|
256 |
if(chartsEngine != null) {
|
|
257 |
break;
|
|
258 |
}
|
|
259 |
}
|
|
260 |
swtChartsComponentsProvider.setChartsEngine(chartsEngine);
|
|
261 |
|
|
262 |
SWTChartsComponentsProvider.chartsComponentsProviders.add(swtChartsComponentsProvider);
|
|
263 |
Log.warning("Starting SWT charts components provider: " + swtChartsComponentsProvider);
|
|
264 |
|
|
265 |
|
|
266 |
}
|
|
267 |
catch(CoreException e) {
|
|
268 |
// TODO Auto-generated catch block
|
|
269 |
e.printStackTrace();
|
|
270 |
}
|
|
271 |
}
|
|
272 |
}
|
|
273 |
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Gets the current charts component provider.
|
|
277 |
* @return the current charts engine
|
|
278 |
*/
|
|
279 |
public static SWTChartsComponentsProvider getCurrent() {
|
|
280 |
return SWTChartsComponentsProvider.chartsComponentsProviders.get(SWTChartsComponentsProvider.currentChartsComponentsProviderIndex);
|
|
281 |
}
|
|
282 |
|
|
283 |
/**
|
|
284 |
* Sets the current charts component provider according to the specified charts engine output format and provider supported input format.
|
|
285 |
* @param name the name of the charts engine to set as current
|
|
286 |
*/
|
|
287 |
public static void setCurrrentComponentsProvider(ChartsEngine chartsEngine) {
|
|
288 |
for(int i = 0; i < SWTChartsComponentsProvider.chartsComponentsProviders.size(); i++) {
|
|
289 |
if(SWTChartsComponentsProvider.chartsComponentsProviders.get(i).getEditorSupportedInputFormats().contains(chartsEngine.getOutputFormat())) {
|
|
290 |
// Set new charts engine
|
|
291 |
SWTChartsComponentsProvider.chartsComponentsProviders.get(i).setChartsEngine(chartsEngine);
|
|
292 |
|
|
293 |
SWTChartsComponentsProvider.currentChartsComponentsProviderIndex = i;
|
|
294 |
Log.warning("Set current SWT charts components provider to: " + SWTChartsComponentsProvider.getCurrent());
|
|
295 |
break;
|
|
296 |
}
|
|
297 |
}
|
|
298 |
}
|
|
299 |
|
|
300 |
|
|
301 |
/**
|
|
302 |
* Gets an SWT charts component provider according to the specified charts engine output format and provider supported input format.
|
|
303 |
* @param chartsEngine
|
|
304 |
* @return
|
|
305 |
*/
|
|
306 |
public static SWTChartsComponentsProvider getComponentsProvider(ChartsEngine chartsEngine) {
|
|
307 |
|
|
308 |
SWTChartsComponentsProvider chartsComponentsProvider = null;
|
|
309 |
|
|
310 |
for(int i = 0; i < SWTChartsComponentsProvider.chartsComponentsProviders.size(); i++) {
|
|
311 |
if(SWTChartsComponentsProvider.chartsComponentsProviders.get(i).getEditorSupportedInputFormats().contains(chartsEngine.getOutputFormat())) {
|
|
312 |
|
|
313 |
chartsComponentsProvider = SWTChartsComponentsProvider.chartsComponentsProviders.get(i);
|
|
314 |
break;
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
return chartsComponentsProvider;
|
|
319 |
}
|
|
320 |
|
|
321 |
|
|
322 |
/**
|
|
323 |
* Gets an installed charts components provider according to its class type.
|
|
324 |
* @param type
|
|
325 |
* @return the installed charts components provider according to its class type if it exists otherwise null;
|
|
326 |
*/
|
|
327 |
public static SWTChartsComponentsProvider getComponentsProvider(Class type) {
|
|
328 |
SWTChartsComponentsProvider provider = null;
|
|
329 |
for(int i = 0; i < SWTChartsComponentsProvider.chartsComponentsProviders.size(); i++) {
|
|
330 |
if(SWTChartsComponentsProvider.chartsComponentsProviders.get(i).getClass().equals(type)) {
|
|
331 |
provider = SWTChartsComponentsProvider.chartsComponentsProviders.get(i);
|
|
332 |
break;
|
|
333 |
}
|
|
334 |
}
|
|
335 |
return provider;
|
|
336 |
}
|
|
337 |
|
|
338 |
|
|
339 |
// /**
|
|
340 |
// * Creates and return a SWT EditorPart for the specified CA result.
|
|
341 |
// * @param ca
|
|
342 |
// * @return a SWT EditorPart
|
|
343 |
// */
|
|
344 |
// public abstract ChartEditorPart createCAFactorialMapChartEditorPart(CA ca);
|
|
345 |
//
|
|
346 |
//
|
|
347 |
// /**
|
|
348 |
// * Creates and return a SWT EditorPart for the singular values of the specified CA result.
|
|
349 |
// * @param ca
|
|
350 |
// * @return a SWT EditorPart
|
|
351 |
// */
|
|
352 |
// public abstract ChartEditorPart createCASingularValuesBarChartEditorPart(CA ca);
|
|
353 |
//
|
|
354 |
|
|
355 |
/**
|
|
356 |
* Creates and return a SWT EditorPart for the specified CAH result.
|
|
357 |
* @param cah
|
|
358 |
* @return a SWT EditorPart
|
|
359 |
*/
|
|
360 |
// public abstract ChartEditorPart createCAHChartEditorPart(Image titleImage, CAH cah);
|
|
361 |
|
|
362 |
|
|
363 |
/**
|
|
364 |
* Creates and return a SWT EditorPart for the specified dimensions of partition result.
|
|
365 |
* @param titleImage
|
|
366 |
* @param partition
|
|
367 |
* @param sortPartsBySize
|
|
368 |
* @return a SWT EditorPart
|
|
369 |
*/
|
|
370 |
// public abstract ChartEditorPart createDimensionsPartitionChartEditorPart(Image titleImage, Partition partition, boolean sortPartsBySize);
|
|
371 |
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Creates and return a SWT EditorPart for the specified specificities result.
|
|
375 |
* @param titleImage the editor title image
|
|
376 |
* @param specificitiesResult the specificities result
|
|
377 |
* @param typeNames the type names
|
|
378 |
* @param partNames the part names
|
|
379 |
* @param specIndex the specificities indices
|
|
380 |
* @param transpose the transpose
|
|
381 |
* @param drawBars the draw bar chart state
|
|
382 |
* @param drawLines the draw line chart state
|
|
383 |
* @param banalite
|
|
384 |
* @param monochrome
|
|
385 |
* @return
|
|
386 |
*/
|
|
387 |
// public abstract ChartEditorPart createSpecificitiesChartEditorPart(Image titleImage, SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean monochrome);
|
|
388 |
|
|
389 |
|
|
390 |
/**
|
|
391 |
* Creates and return a SWT EditorPart for the specified progression result.
|
|
392 |
* @param titleImage
|
|
393 |
* @param progression
|
|
394 |
* @param monochrome
|
|
395 |
* @param monostyle
|
|
396 |
* @param doCumulative
|
|
397 |
* @param file
|
|
398 |
* @return
|
|
399 |
*/
|
|
400 |
//public abstract ChartEditorPart createProgressionChartEditorPart(Image titleImage, Progression progression, boolean monochrome, boolean monostyle, boolean doCumulative);
|
|
401 |
|
|
402 |
|
|
403 |
/**
|
|
404 |
* Set the current charts engine.
|
|
405 |
* @param chartsEngine the chartsEngine to set
|
|
406 |
*/
|
|
407 |
public void setChartsEngine(ChartsEngine chartsEngine) {
|
|
408 |
this.chartsEngine = chartsEngine;
|
|
409 |
}
|
|
410 |
|
|
411 |
|
|
412 |
/**
|
|
413 |
* Gets the charts engine.
|
|
414 |
* @return the chartsEngine
|
|
415 |
*/
|
|
416 |
public ChartsEngine getChartsEngine() {
|
|
417 |
return chartsEngine;
|
|
418 |
}
|
|
419 |
|
|
420 |
|
|
421 |
/**
|
|
422 |
* Creates the chart drawing area composite.
|
|
423 |
* @param parent
|
|
424 |
* @param style
|
|
425 |
* @return the composite
|
|
426 |
*/
|
|
427 |
public abstract ChartComposite createComposite(ChartEditorPart chartEditor, Composite parent);
|
|
428 |
|
|
429 |
|
|
430 |
/**
|
|
431 |
* Returns the export formats supported by the implementation of the <code>EditorPart</code> for the view.
|
|
432 |
* @return
|
|
433 |
*/
|
|
434 |
public abstract ArrayList<String> getEditorSupportedExportFileFormats();
|
|
435 |
|
|
436 |
/**
|
|
437 |
* Returns the input formats supported by the implementation of the <code>EditorPart</code> for viewing.
|
|
438 |
* @return
|
|
439 |
*/
|
|
440 |
public List<String> getEditorSupportedInputFormats() {
|
|
441 |
return this.supportedInputFormats;
|
|
442 |
}
|
|
443 |
|
|
444 |
|
|
445 |
/**
|
|
446 |
* Sets the input formats supported by the implementation of the <code>EditorPart</code> for viewing.
|
|
447 |
* @param supportedInputFormats
|
|
448 |
*/
|
|
449 |
public void setEditorSupportedInputFormat(List<String> supportedInputFormats) {
|
|
450 |
this.supportedInputFormats = supportedInputFormats;
|
|
451 |
}
|
|
452 |
|
|
453 |
/**
|
|
454 |
* Returns the export formats supported by the implementation of the <code>ChartsEngine</code> for the total chart.
|
|
455 |
* @return
|
|
456 |
*/
|
|
457 |
public abstract ArrayList<String> getChartsEngineSupportedExportFileFormats();
|
|
458 |
|
|
459 |
|
|
460 |
/**
|
|
461 |
* Creates a SWT group for the charts engine default preferences area in preference pages.
|
|
462 |
* @return
|
|
463 |
*/
|
|
464 |
public static Group createChartsRenderingPreferencesGroup(Composite parent) {
|
|
465 |
|
|
466 |
Group chartsGroup = new Group(parent, SWT.NONE);
|
|
467 |
|
|
468 |
chartsGroup.setText(SWTComponentsProviderMessages.ChartsEngineSharedPreferencePage_CHARTS_RENDERING_DEFAULT_PREFERENCES);
|
|
469 |
|
|
470 |
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
|
|
471 |
gridData.horizontalSpan = 2;
|
|
472 |
gridData.verticalIndent = 10;
|
|
473 |
chartsGroup.setLayoutData(gridData);
|
|
474 |
|
|
475 |
return chartsGroup;
|
|
476 |
}
|
|
477 |
|
|
478 |
/**
|
|
479 |
* Creates a tab folder with a tab item for rendering preferences.
|
|
480 |
* @param parent
|
|
481 |
* @return
|
|
482 |
*/
|
|
483 |
public static Composite createChartsRenderingPreferencesTabFolderComposite(Composite parent) {
|
|
484 |
|
|
485 |
|
|
486 |
TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
|
|
487 |
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
488 |
gridData.horizontalSpan = 2;
|
|
489 |
tabFolder.setLayoutData(gridData);
|
|
490 |
|
|
491 |
TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
|
|
492 |
tabItem.setText(SWTComponentsProviderMessages.ChartsEngineSharedPreferencePage_CHARTS_RENDERING_DEFAULT_PREFERENCES);
|
|
493 |
Composite composite = new Composite(tabFolder, SWT.NULL);
|
|
494 |
tabItem.setControl(composite);
|
|
495 |
|
|
496 |
|
|
497 |
return composite;
|
|
498 |
}
|
|
499 |
|
|
500 |
/**
|
|
501 |
*
|
|
502 |
* @param page
|
|
503 |
* @param composite
|
|
504 |
*/
|
|
505 |
public static void createChartsRenderingPreferencesFields(TXMPreferencePage page, Composite composite) {
|
|
506 |
|
|
507 |
Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
|
|
508 |
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
|
509 |
gridData.horizontalSpan = 2;
|
|
510 |
separator.setLayoutData(gridData);
|
|
511 |
|
|
512 |
|
|
513 |
page.addField(new BooleanFieldEditor(ChartsEnginePreferences.SHOW_TITLE, SWTComponentsProviderMessages.SWTChartsComponentProvider_SHOW_TITLE, composite));
|
|
514 |
page.addField(new BooleanFieldEditor(ChartsEnginePreferences.SHOW_LEGEND, SWTComponentsProviderMessages.SWTChartsComponentProvider_SHOW_LEGEND, composite));
|
|
515 |
page.addField(new BooleanFieldEditor(ChartsEnginePreferences.SHOW_GRID, SWTComponentsProviderMessages.SWTChartsComponentProvider_SHOW_GRID, composite));
|
|
516 |
|
|
517 |
// Rendering colors mode selection
|
|
518 |
String colorsModes[][] = new String[3][2];
|
|
519 |
colorsModes[0][0] = SWTComponentsProviderMessages.ChartsEnginePreferencePage_RenderingModeColors;
|
|
520 |
colorsModes[0][1] = "0"; //$NON-NLS-1$
|
|
521 |
colorsModes[1][0] = SWTComponentsProviderMessages.ChartsEnginePreferencePage_RenderingModeGrayscale;
|
|
522 |
colorsModes[1][1] = "1"; //$NON-NLS-1$
|
|
523 |
colorsModes[2][0] = SWTComponentsProviderMessages.ChartsEnginePreferencePage_RenderingModeBlackAndWhite;
|
|
524 |
colorsModes[2][1] = "2"; //$NON-NLS-1$
|
|
525 |
|
|
526 |
ComboFieldEditor renderingModeComboField = new ComboFieldEditor(ChartsEnginePreferences.RENDERING_COLORS_MODE, SWTComponentsProviderMessages.ChartsEnginePreferencePage_RenderingColorsMode, colorsModes, composite);
|
|
527 |
page.addField(renderingModeComboField);
|
|
528 |
|
|
529 |
}
|
|
530 |
|
|
531 |
|
|
532 |
/**
|
|
533 |
* Creates a composite panel used to extend the default tool bar.
|
|
534 |
* @param toolBar
|
|
535 |
* @return
|
|
536 |
*/
|
|
537 |
// FIXME: became useless ?
|
|
538 |
public static Composite createToolBarParametersPanel(ToolBar toolBar) {
|
|
539 |
|
|
540 |
Composite parametersPanel = new Composite(toolBar, SWT.NONE);
|
|
541 |
|
|
542 |
RowLayout layout = new RowLayout();
|
|
543 |
layout.wrap = true;
|
|
544 |
layout.center = true;
|
|
545 |
layout.marginTop = 0;
|
|
546 |
layout.marginBottom = 0;
|
|
547 |
layout.marginHeight = 0;
|
|
548 |
parametersPanel.setLayout(layout);
|
|
549 |
|
|
550 |
return parametersPanel;
|
|
551 |
}
|
|
552 |
|
|
553 |
/**
|
|
554 |
* Export the current view of chart editor in the specified file.
|
|
555 |
* @param chartEditor
|
|
556 |
* @param file
|
|
557 |
* @param fileFormat
|
|
558 |
* @return
|
|
559 |
*/
|
|
560 |
public abstract File exportView(ChartEditorPart chartEditor, File file, String fileFormat);
|
|
561 |
|
|
562 |
|
|
563 |
/**
|
|
564 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the type of the chart editor part.
|
|
565 |
* The ID of the editor and the chart type are the editor input result data class name.
|
|
566 |
* @param chartEditorInput
|
|
567 |
* @return
|
|
568 |
*/
|
|
569 |
public ChartEditorPart openEditor(ChartEditorInput chartEditorInput) {
|
|
570 |
return this.openEditor(chartEditorInput, chartEditorInput.getResultData().getClass().getName());
|
|
571 |
}
|
|
572 |
|
|
573 |
/**
|
|
574 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the type of the chart editor part.
|
|
575 |
* The chart type is the editor input result data class name.
|
|
576 |
* @param chartEditorInput
|
|
577 |
* @param editorPartId
|
|
578 |
* @return
|
|
579 |
*/
|
|
580 |
public ChartEditorPart openEditor(ChartEditorInput chartEditorInput, String editorPartId) {
|
|
581 |
return this.openEditor(chartEditorInput, editorPartId, chartEditorInput.getResultData().getClass().getName());
|
|
582 |
}
|
|
583 |
|
|
584 |
|
|
585 |
/**
|
|
586 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the <code>EventCallBack</code> installed extensions.
|
|
587 |
* @param chartEditorInput
|
|
588 |
* @param editorPartId
|
|
589 |
* @param chartType
|
|
590 |
* @return
|
|
591 |
*/
|
|
592 |
// FIXME: this method have some trouble when calling through a progress dialog
|
|
593 |
public ChartEditorPart openEditor(ChartEditorInput chartEditorInput, String editorPartId, String chartType) {
|
|
594 |
|
|
595 |
ChartEditorPart openedChartEditorPart = null;
|
|
596 |
|
|
597 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
|
598 |
IWorkbenchPage page = window.getActivePage();
|
|
599 |
|
|
600 |
// IWorkbenchWindow window = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
|
|
601 |
// IWorkbenchPage page = window.getActivePage();
|
|
602 |
|
|
603 |
boolean isAlreadyOpened = page.findEditor(chartEditorInput) != null;
|
|
604 |
|
|
605 |
// if the editor is already open or the charts engine can create the specified chart type
|
|
606 |
if(isAlreadyOpened || this.chartsEngine.canCreateChart(chartEditorInput.getResultData().getClass(), chartType)) {
|
|
607 |
|
|
608 |
//Log.info(this.name + " - Opening editor for result data type " + chartEditorInput.getResultData().getClass() + " and editor id " + editorPartId);
|
|
609 |
|
|
610 |
|
|
611 |
try {
|
|
612 |
|
|
613 |
openedChartEditorPart = (ChartEditorPart) page.openEditor(chartEditorInput, editorPartId, true);
|
|
614 |
openedChartEditorPart.setWasAlreadyOpened(isAlreadyOpened);
|
|
615 |
|
|
616 |
|
|
617 |
// directly returns if the editor was already opened
|
|
618 |
if(isAlreadyOpened) {
|
|
619 |
return openedChartEditorPart;
|
|
620 |
}
|
|
621 |
|
|
622 |
// FIXME: directly close the editor if it contains no chart
|
|
623 |
// if(openedChartEditorPart.getChart() == null) {
|
|
624 |
// page.closeEditor(openedChartEditorPart, false);
|
|
625 |
// return openedChartEditorPart;
|
|
626 |
// }
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
// FIXME: tests with reuseEditor()
|
|
631 |
//openedChartEditorPart = (ChartEditorPart) page.reuseEditor(editorPart, editorPart.getEditorInput());
|
|
632 |
|
|
633 |
|
|
634 |
// initialize the default shared context menus as Export, etc.
|
|
635 |
initDefaultContextMenus(openedChartEditorPart.getComposite());
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
// registers user entries event call back extensions
|
|
640 |
String extensionPointId = "org.txm.chartsengine.eventcallback"; //$NON-NLS-1$
|
|
641 |
IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
|
|
642 |
|
|
643 |
for(int i = 0; i < contributions.length; i++) {
|
|
644 |
if(contributions[i].getAttribute("chartsEngineName").equals(this.chartsEngine.getName()) //$NON-NLS-1$
|
|
645 |
&& contributions[i].getAttribute("resultDataClass").equals(openedChartEditorPart.getResultData().getClass().getName()) //$NON-NLS-1$
|
|
646 |
) {
|
|
647 |
try {
|
|
648 |
EventCallBack eventCallBack = (EventCallBack)contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
|
|
649 |
|
|
650 |
eventCallBack.setChartEditor(openedChartEditorPart);
|
|
651 |
|
|
652 |
EventCallBackHandler mouseHandler = openedChartEditorPart.getComposite().getMouseCallBackHandler();
|
|
653 |
if(mouseHandler != null && mouseHandler.getEventCallBack(eventCallBack.getClass()) == null) {
|
|
654 |
mouseHandler.registerEventCallBack(eventCallBack);
|
|
655 |
}
|
|
656 |
EventCallBackHandler keyboardHandler = openedChartEditorPart.getComposite().getKeyCallBackHandler();
|
|
657 |
if(keyboardHandler != null && keyboardHandler.getEventCallBack(eventCallBack.getClass()) == null) {
|
|
658 |
keyboardHandler.registerEventCallBack(eventCallBack);
|
|
659 |
}
|
|
660 |
}
|
|
661 |
catch(CoreException e) {
|
|
662 |
e.printStackTrace();
|
|
663 |
}
|
|
664 |
break;
|
|
665 |
}
|
|
666 |
}
|
|
667 |
|
|
668 |
openedChartEditorPart.forceFocus();
|
|
669 |
|
|
670 |
}
|
|
671 |
catch(PartInitException e) {
|
|
672 |
e.printStackTrace();
|
|
673 |
}
|
|
674 |
|
|
675 |
}
|
|
676 |
// get the first installed charts engine that can create chart and use the SWT provider matching it
|
|
677 |
else {
|
|
678 |
Log.warning("Rendering failed with current charts engine, trying to rendering chart with other installed SWT components provider and other charts engine:");
|
|
679 |
|
|
680 |
boolean canCreate = false;
|
|
681 |
for(int i = 0; i < ChartsEngine.getChartsEngines().size() && !canCreate; i++) {
|
|
682 |
if(ChartsEngine.getChartsEngines().get(i) != this.chartsEngine) {
|
|
683 |
ChartsEngine chartsEngine = ChartsEngine.getChartsEngines().get(i);
|
|
684 |
canCreate = chartsEngine.canCreateChart(chartEditorInput.getResultData().getClass());
|
|
685 |
// get a provider that can manage the charts engine
|
|
686 |
if(canCreate) {
|
|
687 |
SWTChartsComponentsProvider provider = SWTChartsComponentsProvider.getComponentsProvider(chartsEngine);
|
|
688 |
if(provider != null) {
|
|
689 |
provider.setChartsEngine(chartsEngine);
|
|
690 |
chartEditorInput.setSWTChartsComponentsProvider(provider);
|
|
691 |
Log.warning(provider.toString());
|
|
692 |
return provider.openEditor(chartEditorInput, editorPartId);
|
|
693 |
}
|
|
694 |
}
|
|
695 |
}
|
|
696 |
}
|
|
697 |
}
|
|
698 |
|
|
699 |
|
|
700 |
return openedChartEditorPart;
|
|
701 |
}
|
|
702 |
|
|
703 |
/**
|
|
704 |
*
|
|
705 |
* @param titleImage
|
|
706 |
* @param editorInputName
|
|
707 |
* @param resultData
|
|
708 |
* @param chartType
|
|
709 |
* @param params
|
|
710 |
* @return
|
|
711 |
*/
|
|
712 |
public ChartEditorPart openEditor(String editorInputName, TXMResult resultData, String preferencesNode, String chartType) {
|
|
713 |
return this.openEditor(this.createChartEditor(editorInputName, resultData, preferencesNode, chartType), chartType);
|
|
714 |
}
|
|
715 |
|
|
716 |
/**
|
|
717 |
*
|
|
718 |
* @param editorInputName
|
|
719 |
* @param resultData
|
|
720 |
* @param params
|
|
721 |
* @return
|
|
722 |
*/
|
|
723 |
public ChartEditorPart openEditor(String editorInputName, TXMResult resultData, String preferencesNode) {
|
|
724 |
return this.openEditor(editorInputName, resultData, preferencesNode, resultData.getClass().getName());
|
|
725 |
}
|
|
726 |
|
|
727 |
|
|
728 |
/**
|
|
729 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the type of the chart editor part.
|
|
730 |
* The ID of the editor is the editor input result data class name.
|
|
731 |
* @param editorPart
|
|
732 |
* @return
|
|
733 |
*/
|
|
734 |
public ChartEditorPart openEditor(ChartEditorPart editorPart) {
|
|
735 |
return this.openEditor(editorPart, editorPart.getEditorInput().getResultData().getClass().getName());
|
|
736 |
}
|
|
737 |
|
|
738 |
/**
|
|
739 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the type of the chart editor part.
|
|
740 |
* The ID of the editor is the editor input result data class name.
|
|
741 |
* @param chartEditorInput
|
|
742 |
* @return
|
|
743 |
*/
|
|
744 |
public ChartEditorPart openEditor(ChartEditorPart editorPart, String chartType) {
|
|
745 |
return this.openEditor(editorPart, editorPart.getEditorInput().getResultData().getClass().getName(), chartType);
|
|
746 |
}
|
|
747 |
|
|
748 |
|
|
749 |
/**
|
|
750 |
* Copy a chart as image in the clipboard from the specified chart component.
|
|
751 |
* @param chartComponent
|
|
752 |
*/
|
|
753 |
public abstract void copyChartToClipboard(Object chartComponent);
|
|
754 |
|
|
755 |
|
|
756 |
/**
|
|
757 |
* Opens the specified <code>ChartEditorPart</code> in the active page and registers the event listeners and context menus according to the type of the chart editor part.
|
|
758 |
* @param editorPart
|
|
759 |
* @param editorId
|
|
760 |
* @return
|
|
761 |
*/
|
|
762 |
public ChartEditorPart openEditor(ChartEditorPart editorPart, String editorId, String chartType) {
|
|
763 |
return this.openEditor(editorPart.getEditorInput(), editorId, chartType);
|
|
764 |
}
|
|
765 |
|
|
766 |
|
|
767 |
|
|
768 |
/**
|
|
769 |
* Initializes the default context menus.
|
|
770 |
* @param composite
|
|
771 |
*/
|
|
772 |
public static void initDefaultContextMenus(ChartComposite composite) {
|
|
773 |
if(composite != null) {
|
|
774 |
composite.initItemAreaContextMenu();
|
|
775 |
composite.initEmptyAreaContextMenu();
|
|
776 |
composite.setCurrentContextMenu(EventCallBack.AREA_EMPTY);
|
|
777 |
}
|
|
778 |
}
|
|
779 |
|
|
780 |
|
|
781 |
|
|
782 |
|
|
783 |
/**
|
|
784 |
* Initializes AWT default events to delegate AWT events to SWT.
|
|
785 |
* @param chartEditor
|
|
786 |
* @param swingComponent
|
|
787 |
*/
|
|
788 |
public static void initializeAWTDelegationListeners(final ChartEditorPart chartEditor, final JComponent swingComponent) {
|
|
789 |
|
|
790 |
// AWT to SWT
|
|
791 |
swingComponent.addMouseMotionListener(new MouseMotionListener() {
|
|
792 |
|
|
793 |
@Override
|
|
794 |
public void mouseMoved(final MouseEvent e) {
|
|
795 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
|
796 |
public void run() {
|
|
797 |
if(!chartEditor.getComposite().isDisposed()) {
|
|
798 |
chartEditor.getComposite().notifyListeners(SWT.MouseMove, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseMove));
|
|
799 |
}
|
|
800 |
}
|
|
801 |
});
|
|
802 |
}
|
|
803 |
|
|
804 |
@Override
|
|
805 |
public void mouseDragged(MouseEvent e) {
|
|
806 |
// TODO Auto-generated method stub
|
|
807 |
|
|
808 |
}
|
|
809 |
});
|
|
810 |
|
|
811 |
swingComponent.addMouseListener(new MouseListener() {
|
|
812 |
|
|
813 |
@Override
|
|
814 |
public void mouseReleased(final MouseEvent e) {
|
|
815 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
|
|
816 |
public void run() {
|
|
817 |
|
|
818 |
// FIXME: context menu
|
|
819 |
if(e.isPopupTrigger()) {
|
|
820 |
|
|
821 |
//System.err.println("SWTChartsComponentsProvider.initializeAWTDelegationListeners(...).new MouseListener() {...}.mouseReleased(...).new Runnable() {...}.run(): AWT popup trigger detected");
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
// update the mouse over item selection according to the mouse event
|
|
826 |
chartEditor.getComposite().getChartComponent().updateMouseOverItem(e);
|
|
827 |
|
|
828 |
// FIXME: temporary disabled for 0.7.8
|
|
829 |
// manually pop up the menu
|
|
830 |
if(chartEditor.getComposite().getMenu() != null) {
|
|
831 |
chartEditor.getComposite().getMenu().setLocation(new Point(e.getXOnScreen(), e.getYOnScreen()));
|
|
832 |
chartEditor.getComposite().getMenu().setVisible(true);
|
|
833 |
}
|
|
834 |
|
|
835 |
// FIXME: the SWT.MenuDetect event delegation doesn't work, it would be better than manually pop up the menu (but other problem is the dynamic menu on chart entity item)
|
|
836 |
//chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
|
837 |
// FIXME: try to delegate the Menu detect event, DOES NOT SEEM TO WORK
|
|
838 |
//chartEditor.getComposite().notifyListeners(SWT.MenuDetect, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MenuDetect));
|
|
839 |
//chartEditor.getComposite().notifyListeners(SWT.Show, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.Show));
|
|
840 |
|
|
841 |
}
|
|
842 |
chartEditor.getComposite().notifyListeners(SWT.MouseUp, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseUp));
|
|
843 |
}
|
|
844 |
});
|
|
845 |
}
|
|
846 |
|
|
847 |
@Override
|
|
848 |
public void mousePressed(final MouseEvent e) {
|
|
849 |
|
|
850 |
// SWT thread
|
|
851 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
|
|
852 |
@Override
|
|
853 |
public void run() {
|
|
854 |
|
|
855 |
chartEditor.getComposite().notifyListeners(SWT.MouseDown, SWTChartsComponentsProvider.swingEventToSWT(chartEditor.getComposite(), swingComponent, e, SWT.MouseDown));
|
|
856 |
|
|
857 |
// FIXME: Debug
|
|
858 |
//System.out.println("SWTChartsComponentProvider.initializeAWTDelegationListeners(...).new MouseListener() {...}.mousePressed(...).new Runnable() {...}.run()");
|
|
859 |
// Activate the editor part on AWT mouse pressed event
|
|
860 |
//chartEditor.activate();
|
|
861 |
}
|
|
862 |
});
|
|
863 |
|
|
864 |
}
|
|
865 |
|
|
866 |
@Override
|
|
867 |
public void mouseExited(java.awt.event.MouseEvent e) {
|
|
868 |
// TODO Auto-generated method stub
|
|
869 |
|
|
870 |
}
|
|
871 |
|
|
872 |
@Override
|
|
873 |
public void mouseEntered(java.awt.event.MouseEvent e) {
|
|
874 |
|
|
875 |
// TODO: DEbug
|
|
876 |
//System.err.println("SWTChartsComponentProvider.initializeSwingDelegationListeners(...) AWT mouse entered");
|
|
877 |
|
|
878 |
// Force the focus in the component on mouse enter
|
|
879 |
/*if(!swingComponent.isFocusOwner()) {
|
|
880 |
|
|
881 |
// SWT thread
|
|
882 |
if(!chartEditor.getComposite().isDisposed()) {
|
|
883 |
chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
|
|
884 |
public void run() {
|