Révision 130
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditorPart.java (revision 130) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp.editors; |
|
2 |
|
|
3 |
|
|
4 |
import java.io.File; |
|
5 |
import java.util.ArrayList; |
|
6 |
|
|
7 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
8 |
import org.eclipse.swt.SWT; |
|
9 |
import org.eclipse.swt.events.SelectionEvent; |
|
10 |
import org.eclipse.swt.events.SelectionListener; |
|
11 |
import org.eclipse.swt.layout.FormAttachment; |
|
12 |
import org.eclipse.swt.layout.FormData; |
|
13 |
import org.eclipse.swt.layout.FormLayout; |
|
14 |
import org.eclipse.swt.layout.RowLayout; |
|
15 |
import org.eclipse.swt.widgets.Composite; |
|
16 |
import org.eclipse.swt.widgets.Group; |
|
17 |
import org.eclipse.swt.widgets.ToolItem; |
|
18 |
import org.eclipse.ui.IEditorInput; |
|
19 |
import org.eclipse.ui.IEditorSite; |
|
20 |
import org.eclipse.ui.IPartListener; |
|
21 |
import org.eclipse.ui.IWorkbenchPart; |
|
22 |
import org.eclipse.ui.PartInitException; |
|
23 |
import org.eclipse.ui.PlatformUI; |
|
24 |
import org.eclipse.ui.part.EditorPart; |
|
25 |
import org.eclipse.ui.part.MultiPageEditorPart; |
|
26 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
27 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
28 |
import org.txm.chartsengine.rcp.swt.ChartComposite; |
|
29 |
import org.txm.chartsengine.rcp.swt.ChartEditorToolBar; |
|
30 |
import org.txm.functions.TXMResult; |
|
31 |
import org.txm.rcp.editors.TXMEditorPart; |
|
32 |
import org.txm.rcpapplication.Application; |
|
33 |
|
|
34 |
/** |
|
35 |
* Base class of all charts SWT <code>EditorPart</code> subclasses. |
|
36 |
* @author sjacquot |
|
37 |
* |
|
38 |
*/ |
|
39 |
public class ChartEditorPart extends TXMEditorPart { |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* The <code>EditorPart</code> ID constant. |
|
44 |
*/ |
|
45 |
protected static final String ID = ChartEditorPart.class.getCanonicalName(); |
|
46 |
|
|
47 |
/** |
|
48 |
* The tool bar. |
|
49 |
*/ |
|
50 |
protected ChartEditorToolBar toolBar; |
|
51 |
|
|
52 |
protected Composite parametersComposite; |
|
53 |
|
|
54 |
protected Group parametersGroup; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* The chart drawing area composite. |
|
59 |
*/ |
|
60 |
protected ChartComposite chartComposite; |
|
61 |
|
|
62 |
|
|
63 |
protected boolean wasAlreadyOpened; |
|
64 |
|
|
65 |
/** |
|
66 |
* The multi pages editor which contains this editor if exists. |
|
67 |
*/ |
|
68 |
protected MultiPageEditorPart parentMultiPagesEditor = null; |
|
69 |
|
|
70 |
|
|
71 |
/** |
|
72 |
* Linked editors. |
|
73 |
*/ |
|
74 |
protected ArrayList<EditorPart> linkedEditors = null; |
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
/** |
|
79 |
* |
|
80 |
*/ |
|
81 |
public ChartEditorPart() { |
|
82 |
super(); |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
/** |
|
88 |
* |
|
89 |
* @param swtComponentsProvider |
|
90 |
* @param editorInputName |
|
91 |
* @param titleImage |
|
92 |
* @param resultData |
|
93 |
* @param chartContainer |
|
94 |
*/ |
|
95 |
public ChartEditorPart(SWTChartsComponentsProvider swtComponentsProvider, String editorInputName, TXMResult resultData, String preferencesNodeQualifier, String chartType, Object chartContainer) { |
|
96 |
this(swtComponentsProvider, new ChartEditorInput(swtComponentsProvider, editorInputName, resultData, preferencesNodeQualifier, chartType, chartContainer)); |
|
97 |
} |
|
98 |
|
|
99 |
|
|
100 |
/** |
|
101 |
* |
|
102 |
* @param swtComponentsProvider |
|
103 |
* @param chartEditorInput |
|
104 |
*/ |
|
105 |
public ChartEditorPart(SWTChartsComponentsProvider swtComponentsProvider, ChartEditorInput chartEditorInput) { |
|
106 |
this.setInput(chartEditorInput); |
|
107 |
this.setPartName(chartEditorInput.getName()); |
|
108 |
|
|
109 |
this.wasAlreadyOpened = false; |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
// /** |
|
115 |
// * Gets the <code>EditorPart</code> ID. |
|
116 |
// * @return the ID |
|
117 |
// */ |
|
118 |
// public abstract String getID(); |
|
119 |
|
|
120 |
|
|
121 |
/** |
|
122 |
* Gets the <code>EditorPart</code> ID. |
|
123 |
* @return the ID |
|
124 |
*/ |
|
125 |
public String getID() { |
|
126 |
return ID; |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
@Override |
|
131 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException { |
|
132 |
this.setSite(site); |
|
133 |
this.setInput(input); |
|
134 |
// FIXME: see how to use the Adapters and AdapterFactory to define image and title of Editor in the contributing plug-ins |
|
135 |
// another way is to use editors extension in plug-ins and redefine icon and name, using this solution the problem is that the name (which is also editor title) can not be dynamic according to the result data |
|
136 |
// so it seems better to use Adapters if that's possible |
|
137 |
this.setPartName(input.getName()); |
|
138 |
} |
|
139 |
|
|
140 |
|
|
141 |
@Override |
|
142 |
public void createPartControl(Composite parent) { |
|
143 |
|
|
144 |
super.createPartControl(parent); |
|
145 |
|
|
146 |
// Test, original code |
|
147 |
FormLayout mainLayout = new FormLayout(); |
|
148 |
|
|
149 |
// mainLayout.marginHeight = 5; |
|
150 |
// mainLayout.marginWidth = 5; |
|
151 |
|
|
152 |
mainLayout.marginTop = 3; |
|
153 |
mainLayout.marginLeft = 0; |
|
154 |
mainLayout.spacing = 3; |
|
155 |
parent.setLayout(mainLayout); |
|
156 |
|
|
157 |
|
|
158 |
// parent.setLayout(new RowLayout(SWT.VERTICAL)); |
|
159 |
// parent.setLayoutData(new RowData(50, 40)); |
|
160 |
|
|
161 |
|
|
162 |
// Toolbar |
|
163 |
// FIXME: tests |
|
164 |
//this.toolBar = new ChartEditorToolBar(parent, SWT.FLAT | SWT.SHADOW_OUT, this); |
|
165 |
this.toolBar = new ChartEditorToolBar(parent, SWT.FLAT, this); |
|
166 |
|
|
167 |
|
|
168 |
// FIXME: dimensions/margin tests |
|
169 |
// this.toolBar.computeSize(1500, 800, true); |
|
170 |
// this.toolBar.setBounds(200, 400, 1500, 300); |
|
171 |
// this.toolBar.pack(); |
|
172 |
// this.toolBar.setSize(1500, 800); |
|
173 |
|
|
174 |
|
|
175 |
// FIXME: command parameters composite |
|
176 |
this.parametersComposite = new Composite(parent, SWT.NONE); |
|
177 |
|
|
178 |
|
|
179 |
// FIXME: group tests |
|
180 |
this.parametersGroup = new Group(this.parametersComposite, SWT.NONE); |
|
181 |
this.parametersGroup.setText("Command parameters"); |
|
182 |
RowLayout layout1 = new RowLayout(); |
|
183 |
layout1.marginLeft = 10; |
|
184 |
layout1.marginTop = 10; |
|
185 |
layout1.spacing = 8; |
|
186 |
layout1.wrap = true; |
|
187 |
layout1.center = true; |
|
188 |
this.parametersGroup.setLayout(layout1); |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
FormData formData = new FormData(); |
|
193 |
formData.top = new FormAttachment(this.toolBar); |
|
194 |
//formData.bottom = new FormAttachment(100); |
|
195 |
formData.left = new FormAttachment(0); |
|
196 |
formData.right = new FormAttachment(100); |
|
197 |
formData.height = 0; |
|
198 |
this.parametersComposite.setLayoutData(formData); |
|
199 |
|
|
200 |
//this.parametersComposite.setBackground(new Color (Display.getCurrent(), 255, 0, 0)); |
|
201 |
|
|
202 |
RowLayout layout = new RowLayout(); |
|
203 |
layout.marginLeft = 10; |
|
204 |
layout.marginTop = 10; |
|
205 |
layout.spacing = 8; |
|
206 |
layout.wrap = true; |
|
207 |
layout.center = true; |
|
208 |
this.parametersComposite.setLayout(layout); |
|
209 |
//this.parametersGroup.setLayout(layout); |
|
210 |
|
|
211 |
|
|
212 |
this.parametersComposite.setVisible(false); |
|
213 |
this.parametersComposite.getParent().layout(true); |
|
214 |
|
|
215 |
|
|
216 |
// FIXME: tests show/hide parameters |
|
217 |
final ToolItem showParameters = new ToolItem(this.toolBar, SWT.CHECK); |
|
218 |
showParameters.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, "platform:/plugin/org.txm.rcp/icons/add.png").createImage()); |
|
219 |
showParameters.setToolTipText("Show/Hide command parameters"); |
|
220 |
showParameters.setSelection(false); |
|
221 |
|
|
222 |
showParameters.addSelectionListener(new SelectionListener() { |
|
223 |
|
|
224 |
@Override |
|
225 |
public void widgetSelected(SelectionEvent e) { |
|
226 |
|
|
227 |
parametersComposite.pack(); |
|
228 |
int height = 0; |
|
229 |
if(showParameters.getSelection()) { |
|
230 |
height = parametersComposite.getSize().y; |
|
231 |
} |
|
232 |
((FormData)parametersComposite.getLayoutData()).height = height; |
|
233 |
parametersComposite.getParent().layout(true); |
|
234 |
parametersComposite.setVisible(showParameters.getSelection()); |
|
235 |
} |
|
236 |
|
|
237 |
@Override |
|
238 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
239 |
// TODO Auto-generated method stub |
|
240 |
|
|
241 |
} |
|
242 |
}); |
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
// FIXME: background color tests |
|
248 |
//this.toolBar.setBackground(parent.getBackground()); |
|
249 |
//this.toolBar.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
250 |
|
|
251 |
// Chart composite |
|
252 |
ChartComposite composite = this.getEditorInput().getSWTChartsComponentsProvider().createComposite(this, parent); |
|
253 |
|
|
254 |
// FormData formData2 = new FormData(); |
|
255 |
// formData2.top = new FormAttachment(toolBarsComposite, 10); |
|
256 |
// composite.setLayoutData(formData2); |
|
257 |
|
|
258 |
|
|
259 |
// FIXME: open dialog box message if the composite doesn't contain any chart (typically when the charts engine doesn't contain chart creator for the specified result data type) |
|
260 |
// if(composite.getChart() == null) { |
|
261 |
// MessageDialog.openWarning(parent.getShell(), "Warning", "Current charts engine can not create chart for " + this.getResultData().getClass().getSimpleName() + " result type. You can set another charts engine in the preferences."); |
|
262 |
// } |
|
263 |
|
|
264 |
// FIXME: background color tests |
|
265 |
//this.composite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
266 |
//parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
267 |
|
|
268 |
|
|
269 |
} |
|
270 |
|
|
271 |
|
|
272 |
/** |
|
273 |
* Activate the editor in the UI. |
|
274 |
*/ |
|
275 |
public void activate() { |
|
276 |
// Activate the parent multi pages editor instead of this editor if it exists |
|
277 |
if(this.parentMultiPagesEditor != null) { |
|
278 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(this.parentMultiPagesEditor); |
|
279 |
} |
|
280 |
else { |
|
281 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(this); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Forces the Composite to get the focus. |
|
287 |
*/ |
|
288 |
public void forceFocus() { |
|
289 |
// FIXME: debug |
|
290 |
//System.err.println("ChartEditorPart.forceFocus()"); |
|
291 |
|
|
292 |
this.chartComposite.notifyListeners(SWT.FocusIn, null); // Needed to force the composite listener to handle the focus event |
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
@Override |
|
297 |
public void setFocus() { |
|
298 |
|
|
299 |
// FIXME: debug |
|
300 |
//System.err.println("ChartEditorPart.setFocus()"); |
|
301 |
|
|
302 |
this.chartComposite.setFocus(); |
|
303 |
|
|
304 |
} |
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
@Override |
|
310 |
public boolean isDirty() { |
|
311 |
return false; |
|
312 |
} |
|
313 |
|
|
314 |
@Override |
|
315 |
public boolean isSaveAsAllowed() { |
|
316 |
return false; |
|
317 |
} |
|
318 |
|
|
319 |
|
|
320 |
@Override |
|
321 |
public void doSave(IProgressMonitor monitor) { |
|
322 |
// TODO Auto-generated method stub |
|
323 |
|
|
324 |
} |
|
325 |
|
|
326 |
@Override |
|
327 |
public void doSaveAs() { |
|
328 |
// TODO Auto-generated method stub |
|
329 |
|
|
330 |
} |
|
331 |
|
|
332 |
|
|
333 |
/** |
|
334 |
* Gets the editor input. |
|
335 |
* @return the editorInput |
|
336 |
*/ |
|
337 |
public ChartEditorInput getEditorInput() { |
|
338 |
return (ChartEditorInput) super.getEditorInput(); |
|
339 |
} |
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
/** |
|
344 |
* Gets the chart drawing area composite. |
|
345 |
* @return the composite |
|
346 |
*/ |
|
347 |
public ChartComposite getComposite() { |
|
348 |
return this.chartComposite; |
|
349 |
} |
|
350 |
|
|
351 |
|
|
352 |
/** |
|
353 |
* Resets the chart view (zoom, pan, rotation). |
|
354 |
*/ |
|
355 |
public void resetView() { |
|
356 |
this.chartComposite.resetView(); |
|
357 |
} |
|
358 |
|
|
359 |
/** |
|
360 |
* Zooms the chart view at x and y coordinates. |
|
361 |
* @param x |
|
362 |
* @param y |
|
363 |
* @param zoomIn |
|
364 |
*/ |
|
365 |
public void zoom(double x, double y, boolean zoomIn) { |
|
366 |
this.chartComposite.zoom(x, y, zoomIn); |
|
367 |
} |
|
368 |
|
|
369 |
/** |
|
370 |
* Pans the chart view. |
|
371 |
* @param chartComponent |
|
372 |
* @param srcX |
|
373 |
* @param srcY |
|
374 |
* @param dstX |
|
375 |
* @param dstY |
|
376 |
* @param panFactor |
|
377 |
*/ |
|
378 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) { |
|
379 |
this.chartComposite.pan(srcX, srcY, dstX, dstY, panFactor); |
|
380 |
} |
|
381 |
|
|
382 |
|
|
383 |
/** |
|
384 |
* Copy the current chart view to clipboard. |
|
385 |
*/ |
|
386 |
public void copyChartViewToClipboard() { |
|
387 |
this.getEditorInput().getSWTChartsComponentsProvider().copyChartToClipboard(this.getComposite().getChartComponent()); |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* Loads the chart from the chart object stored into the composite. |
|
392 |
*/ |
|
393 |
public void loadChart() { |
|
394 |
getSite().getShell().getDisplay().syncExec(new Runnable() { |
|
395 |
@Override |
|
396 |
public void run() { |
|
397 |
chartComposite.reloadChart(); |
|
398 |
} |
|
399 |
}); |
|
400 |
} |
|
401 |
|
|
402 |
|
|
403 |
/** |
|
404 |
* Updates the specified chart stored in the editor and according to the stored TXM result. |
|
405 |
* @return |
|
406 |
*/ |
|
407 |
public boolean updateChart() { |
|
408 |
return this.getSWTChartsComponentsProvider().updateChart(this); |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Creates a new chart for the specified result data and save it in the current editor input. |
|
413 |
* @param resultData |
|
414 |
* @param preferencesNode |
|
415 |
*/ |
|
416 |
public void createChart(TXMResult resultData, String preferencesNode) { |
|
417 |
this.getSWTChartsComponentsProvider().createChart(this.getEditorInput(), resultData, preferencesNode); |
|
418 |
} |
|
419 |
|
|
420 |
/** |
|
421 |
* Creates a new chart for current stored result and save it in the current editor input. |
|
422 |
*/ |
|
423 |
public void createChart() { |
|
424 |
this.createChart(this.getResultData(), this.getPreferencesNodeQualifier()); |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* Disposes the editor. |
|
429 |
* Implementations using a Composite to embed AWT/Swing components should manually call this.composite.dispose() in the redefined method. |
|
430 |
*/ |
|
431 |
public void dispose() { |
|
432 |
this.chartComposite.dispose(); |
|
433 |
super.dispose(); |
|
434 |
} |
|
435 |
|
|
436 |
/** |
|
437 |
* Returns the preferences node qualifier linked to the chart of this editor. |
|
438 |
* @return |
|
439 |
*/ |
|
440 |
public String getPreferencesNodeQualifier() { |
|
441 |
return this.getEditorInput().getPreferencesNodeQualifier(); |
|
442 |
} |
|
443 |
|
|
444 |
/** |
|
445 |
* Closes the editor from the UI thread. |
|
446 |
*/ |
|
447 |
public void close() { |
|
448 |
final EditorPart self = this; |
|
449 |
getSite().getShell().getDisplay().syncExec(new Runnable() { |
|
450 |
@Override |
|
451 |
public void run() { |
|
452 |
getSite().getPage().closeEditor(self, false); |
|
453 |
} |
|
454 |
}); |
|
455 |
} |
|
456 |
|
|
457 |
/** |
|
458 |
* Returns the tool bar of this editor. |
|
459 |
* @return the toolBar |
|
460 |
*/ |
|
461 |
public ChartEditorToolBar getToolBar() { |
|
462 |
return toolBar; |
|
463 |
} |
|
464 |
|
|
465 |
/** |
|
466 |
* Returns the result object associated with the editor. |
|
467 |
* @return |
|
468 |
*/ |
|
469 |
public TXMResult getResultData() { |
|
470 |
return this.getEditorInput().getResultData(); |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* |
|
475 |
* @return |
|
476 |
*/ |
|
477 |
public String getChartType() { |
|
478 |
return this.getEditorInput().getChartType(); |
|
479 |
} |
|
480 |
|
|
481 |
/** |
|
482 |
* Returns the chart associated with the editor. |
|
483 |
* @return |
|
484 |
*/ |
|
485 |
public Object getChart() { |
|
486 |
return this.chartComposite.getChart(); |
|
487 |
} |
|
488 |
|
|
489 |
/** |
|
490 |
* Returns the chart components provider associated with the editor. |
|
491 |
* @return |
|
492 |
*/ |
|
493 |
public SWTChartsComponentsProvider getSWTChartsComponentsProvider() { |
|
494 |
return this.getEditorInput().getSWTChartsComponentsProvider(); |
|
495 |
} |
|
496 |
|
|
497 |
|
|
498 |
/** |
|
499 |
* Exports the current view of the chart editor in the specified file. |
|
500 |
* @param file |
|
501 |
* @param fileFormat |
|
502 |
* @return |
|
503 |
*/ |
|
504 |
public File exportView(File file, String fileFormat) { |
|
505 |
return this.getSWTChartsComponentsProvider().exportView(this, file, fileFormat); |
|
506 |
} |
|
507 |
|
|
508 |
|
|
509 |
|
|
510 |
/** |
|
511 |
* Gets the parent multipages editor part if exists. |
|
512 |
* @return the parentMultiPagesEditor |
|
513 |
*/ |
|
514 |
public MultiPageEditorPart getParentMultiPagesEditor() { |
|
515 |
return parentMultiPagesEditor; |
|
516 |
} |
|
517 |
|
|
518 |
|
|
519 |
/** |
|
520 |
* Sets the specified multipages editor part as parent of this one. |
|
521 |
* @param parentMultiPagesEditor the parentMultiPagesEditor to set |
|
522 |
*/ |
|
523 |
public void setParentMultiPagesEditor(MultiPageEditorPart parentMultiPagesEditor) { |
|
524 |
this.parentMultiPagesEditor = parentMultiPagesEditor; |
|
525 |
} |
|
526 |
|
|
527 |
|
|
528 |
/** |
|
529 |
* Links the specified editor to this editor. |
|
530 |
* @param editor |
|
531 |
*/ |
|
532 |
public void addLinkedEditor(final EditorPart editor) { |
|
533 |
if(this.linkedEditors == null) { |
|
534 |
this.linkedEditors = new ArrayList<EditorPart>(); |
|
535 |
} |
|
536 |
if(!this.linkedEditors.contains(editor)) { |
|
537 |
this.linkedEditors.add(editor); |
|
538 |
|
|
539 |
// FIXME: debug |
|
540 |
//System.err.println(this.getClass().getSimpleName() + ": A linked editor of type \"" + editor.getClass().getSimpleName() + "\" has been added to this one. Linked editors count: " + this.linkedEditors.size() + "."); |
|
541 |
|
|
542 |
// FIXME: temporary solution to break the link with chart editor from another TXM result editor when its closed |
|
543 |
// a better solution would be to redefine the onclose event in a root class of all TXM editors |
|
544 |
editor.getSite().getPage().addPartListener(new IPartListener() { |
|
545 |
|
|
546 |
@Override |
|
547 |
public void partOpened(IWorkbenchPart part) { |
|
548 |
// TODO Auto-generated method stub |
|
549 |
|
|
550 |
} |
|
551 |
|
|
552 |
@Override |
|
553 |
public void partDeactivated(IWorkbenchPart part) { |
|
554 |
// TODO Auto-generated method stub |
|
555 |
|
|
556 |
} |
|
557 |
|
|
558 |
@Override |
|
559 |
public void partClosed(IWorkbenchPart part) { |
|
560 |
if(part.equals(editor)) { |
|
561 |
// FIXME: Debug |
|
562 |
//System.out.println("ChartEditorPart.addLinkedEditor(...).new IPartListener() {...}.partClosed()"); |
|
563 |
// TODO Auto-generated method stub |
|
564 |
removeLinkedEditor(editor); |
|
565 |
editor.getSite().getPage().removePartListener(this); |
|
566 |
} |
|
567 |
} |
|
568 |
|
|
569 |
@Override |
|
570 |
public void partBroughtToTop(IWorkbenchPart part) { |
|
571 |
// TODO Auto-generated method stub |
|
572 |
|
|
573 |
} |
|
574 |
|
|
575 |
@Override |
|
576 |
public void partActivated(IWorkbenchPart part) { |
|
577 |
// TODO Auto-generated method stub |
|
578 |
|
|
579 |
} |
|
580 |
}); |
|
581 |
|
|
582 |
|
|
583 |
} |
|
584 |
} |
|
585 |
|
|
586 |
/** |
|
587 |
* Unlinks the specified editor from this editor. |
|
588 |
* @param editor |
|
589 |
*/ |
|
590 |
public void removeLinkedEditor(EditorPart editor) { |
|
591 |
if(this.linkedEditors != null) { |
|
592 |
if(this.linkedEditors.remove(editor)) { |
|
593 |
// FIXME: debug |
|
594 |
//System.err.println(this.getClass().getSimpleName() + ": A linked editor of type \"" + editor.getClass().getSimpleName() + "\" has been removed from this one. Linked editors count: " + this.linkedEditors.size() + "."); |
|
595 |
} |
|
596 |
} |
|
597 |
if(this.linkedEditors.isEmpty()) { |
|
598 |
this.linkedEditors = null; |
|
599 |
} |
|
600 |
} |
|
601 |
|
|
602 |
/** |
|
603 |
* Gets the linked editors to this one if exist. |
|
604 |
* @return |
|
605 |
*/ |
|
606 |
public ArrayList<EditorPart> getLinkedEditors() { |
|
607 |
return this.linkedEditors; |
|
608 |
} |
|
609 |
|
|
610 |
/** |
|
611 |
* Gets the first linked editor of the specified class if exists. |
|
612 |
* @param editorClass |
|
613 |
* @return |
|
614 |
*/ |
|
615 |
public EditorPart getLinkedEditor(Class editorClass) { |
|
616 |
EditorPart editor = null; |
|
617 |
if(this.linkedEditors != null) { |
|
618 |
for(int i = 0; i < this.linkedEditors.size(); i++) { |
|
619 |
if(this.linkedEditors.get(i).getClass().equals(editorClass)) { |
|
620 |
editor = this.linkedEditors.get(i); |
|
621 |
break; |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
625 |
return editor; |
|
626 |
} |
|
627 |
|
|
628 |
|
|
629 |
/** |
|
630 |
* Gets the linked editors of the specified class if exist otherwise returns an empty list. |
|
631 |
* @param editorClass |
|
632 |
* @return |
|
633 |
*/ |
|
634 |
public ArrayList<EditorPart> getLinkedEditors(Class editorClass) { |
|
635 |
ArrayList<EditorPart> editors = new ArrayList<EditorPart>(); |
|
636 |
if(this.linkedEditors != null) { |
|
637 |
for(int i = 0; i < this.linkedEditors.size(); i++) { |
|
638 |
if(this.linkedEditors.get(i).getClass().equals(editorClass)) { |
|
639 |
editors.add(this.linkedEditors.get(i)); |
|
640 |
} |
|
641 |
} |
|
642 |
} |
|
643 |
return editors; |
|
644 |
} |
|
645 |
|
|
646 |
|
|
647 |
// FIXME: useless ? |
|
648 |
// /** |
|
649 |
// * Gets the first linked editor linked to the specified editor input. |
|
650 |
// * @param editorClass |
|
651 |
// * @return |
|
652 |
// */ |
|
653 |
// public EditorPart getLinkedEditor(IEditorInput editorInput) { |
|
654 |
// EditorPart editor = null; |
|
655 |
// if(this.linkedEditors != null) { |
|
656 |
// for(int i = 0; i < this.linkedEditors.size(); i++) { |
|
657 |
// if(this.linkedEditors.get(i).getEditorInput().equals(editorInput)) { |
|
658 |
// editor = this.linkedEditors.get(i); |
|
659 |
// break; |
|
660 |
// } |
|
661 |
// } |
|
662 |
// } |
|
663 |
// return editor; |
|
664 |
// } |
|
665 |
|
|
666 |
|
|
667 |
|
|
668 |
|
|
669 |
|
|
670 |
/** |
|
671 |
* @param composite the composite to set |
|
672 |
*/ |
|
673 |
public void setComposite(ChartComposite composite) { |
|
674 |
this.chartComposite = composite; |
|
675 |
} |
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
/** |
|
680 |
* @return the parametersComposite |
|
681 |
*/ |
|
682 |
public Composite getParametersComposite() { |
|
683 |
return parametersComposite; |
|
684 |
} |
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
/** |
|
689 |
* @return the wasAlreadyOpened |
|
690 |
*/ |
|
691 |
public boolean wasAlreadyOpened() { |
|
692 |
return wasAlreadyOpened; |
|
693 |
} |
|
694 |
|
|
695 |
|
|
696 |
|
|
697 |
/** |
|
698 |
* @param wasAlreadyOpened the wasAlreadyOpened to set |
|
699 |
*/ |
|
700 |
public void setWasAlreadyOpened(boolean wasAlreadyOpened) { |
|
701 |
this.wasAlreadyOpened = wasAlreadyOpened; |
|
702 |
} |
|
703 |
|
|
704 |
|
|
705 |
|
|
706 |
/** |
|
707 |
* @return the parametersGroup |
|
708 |
*/ |
|
709 |
public Group getParametersGroup() { |
|
710 |
return parametersGroup; |
|
711 |
} |
|
712 |
|
|
713 |
} |
|
0 | 714 |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditorInput.java (revision 130) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp.editors; |
|
2 |
|
|
3 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
4 |
import org.eclipse.ui.IEditorInput; |
|
5 |
import org.eclipse.ui.IPersistableElement; |
|
6 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
7 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
8 |
import org.txm.core.preferences.TXMPreferences; |
|
9 |
import org.txm.functions.TXMResult; |
|
10 |
import org.txm.functions.specificities.SpecificitesResult; |
|
11 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
12 |
|
|
13 |
/** |
|
14 |
* Base class of all charts SWT <code>IEditorInput</code> implementations. |
|
15 |
* @author sjacquot |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class ChartEditorInput implements IEditorInput { |
|
19 |
|
|
20 |
/** |
|
21 |
* The name. |
|
22 |
*/ |
|
23 |
protected String name; |
|
24 |
|
|
25 |
|
|
26 |
/** |
|
27 |
* TXM result object. |
|
28 |
*/ |
|
29 |
protected TXMResult resultData; |
|
30 |
|
|
31 |
/** |
|
32 |
* Chart type. |
|
33 |
*/ |
|
34 |
protected String chartType; |
|
35 |
|
|
36 |
|
|
37 |
protected String preferencesNodeQualifier; |
|
38 |
|
|
39 |
/** |
|
40 |
* SWT chart components provider used to create the chart editor. |
|
41 |
* Store it allows the switch of component provider in the RCP in keeping the chart editors in a coherent state. |
|
42 |
*/ |
|
43 |
protected SWTChartsComponentsProvider swtChartsComponentsProvider = null; |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* The chart container (for example : can be a file, an AWT/Swing component as ChartPanel for JFC, etc.). |
|
48 |
*/ |
|
49 |
protected Object chartContainer; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* Creates a chart editor input linked to the current SWT charts components provider. |
|
54 |
* @param resultData |
|
55 |
* @param preferencesNodeQualifier |
|
56 |
*/ |
|
57 |
public ChartEditorInput(TXMResult resultData, String preferencesNodeQualifier) { |
|
58 |
this(SWTChartsComponentsProvider.getCurrent(), resultData, preferencesNodeQualifier); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Creates a chart editor input linked to the specified SWT charts components provider. |
|
63 |
* @param swtComponentsProvider |
|
64 |
* @param resultData |
|
65 |
* @param preferencesNodeQualifier |
|
66 |
*/ |
|
67 |
public ChartEditorInput(SWTChartsComponentsProvider swtComponentsProvider, TXMResult resultData, String preferencesNodeQualifier) { |
|
68 |
this(swtComponentsProvider, resultData, preferencesNodeQualifier, resultData.getClass().getName()); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Creates a chart editor input linked to the specified SWT charts components provider. |
|
73 |
* @param swtComponentsProvider |
|
74 |
* @param resultData |
|
75 |
* @param preferencesNodeQualifier |
|
76 |
* @param chartType |
|
77 |
*/ |
|
78 |
public ChartEditorInput(SWTChartsComponentsProvider swtComponentsProvider, TXMResult resultData, String preferencesNodeQualifier, String chartType) { |
|
79 |
this(swtComponentsProvider, "Chart editor input", resultData, preferencesNodeQualifier, chartType, null); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Creates a chart editor input linked to the specified SWT charts components provider. |
|
84 |
* @param swtComponentsProvider |
|
85 |
* @param name |
|
86 |
* @param resultData |
|
87 |
* @param preferencesNodeQualifier |
|
88 |
* @param chartType |
|
89 |
* @param chartContainer |
|
90 |
*/ |
|
91 |
public ChartEditorInput(SWTChartsComponentsProvider swtComponentsProvider, String name, TXMResult resultData, String preferencesNodeQualifier, String chartType, Object chartContainer) { |
|
92 |
this.swtChartsComponentsProvider = swtComponentsProvider; |
|
93 |
this.name = name; |
|
94 |
this.resultData = resultData; |
|
95 |
this.preferencesNodeQualifier = preferencesNodeQualifier; |
|
96 |
this.chartType = chartType; |
|
97 |
this.chartContainer = chartContainer; |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
@Override |
|
104 |
public boolean exists() { |
|
105 |
// TODO Auto-generated method stub |
|
106 |
return false; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public ImageDescriptor getImageDescriptor() { |
|
111 |
// TODO Auto-generated method stub |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public String getName() { |
|
117 |
return this.name; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public IPersistableElement getPersistable() { |
|
122 |
// TODO Auto-generated method stub |
|
123 |
return null; |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public String getToolTipText() { |
|
128 |
return this.getName(); |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public Object getAdapter(Class type) { |
|
133 |
// FIXME |
|
134 |
// System.err.println("************** ChartEditorInput.getAdapter() type = " + type + " / adaptable object = " + this); |
|
135 |
// // if the object implements or extends the desired interface, use it |
|
136 |
// |
|
137 |
// if (type.isInstance(IResource.class)) |
|
138 |
//// |
|
139 |
// return this; |
|
140 |
//// |
|
141 |
//// |
|
142 |
//// |
|
143 |
//// // if the object is able to adapt itself, let it do it |
|
144 |
//// |
|
145 |
//// if (this instanceof IAdaptable) { |
|
146 |
//// |
|
147 |
//// IAdaptable adaptable = (IAdaptable) this; |
|
148 |
//// |
|
149 |
//// Object adapter = adaptable.getAdapter(type); |
|
150 |
//// |
|
151 |
//// if (adapter != null) |
|
152 |
//// |
|
153 |
//// return adapter; |
|
154 |
//// |
|
155 |
//// } |
|
156 |
// |
|
157 |
// |
|
158 |
// |
|
159 |
// // delegate to the global adapter manager |
|
160 |
// |
|
161 |
// return Platform.getAdapterManager().getAdapter(this, type); |
|
162 |
|
|
163 |
|
|
164 |
return null; |
|
165 |
} |
|
166 |
|
|
167 |
|
|
168 |
/** |
|
169 |
* Gets the result data associated with the editor input. |
|
170 |
* @return the resultData |
|
171 |
*/ |
|
172 |
public TXMResult getResultData() { |
|
173 |
return resultData; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Sets the result data associated with the editor input. |
|
178 |
* @param resultData the resultData to set |
|
179 |
*/ |
|
180 |
public void setResultData(TXMResult resultData) { |
|
181 |
this.resultData = resultData; |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Sets the name of the editor input. |
|
186 |
* @param name the name to set |
|
187 |
*/ |
|
188 |
public void setName(String name) { |
|
189 |
this.name = name; |
|
190 |
} |
|
191 |
|
|
192 |
// FIXME: became useless ? |
|
193 |
// /** |
|
194 |
// * Sets the specific SWT chart components provider to use while the chart editor initialization. |
|
195 |
// * This is used for creating an editor with a specific components provider therefore the global application components provider will not be used if this member is different from null. |
|
196 |
// * @param swtChartComponentsProvider the swtComponentProvider to set |
|
197 |
// */ |
|
198 |
// public void setSWTChartComponentsProvider(SWTChartsComponentProvider swtChartComponentsProvider) { |
|
199 |
// this.swtChartComponentsProvider = swtChartComponentsProvider; |
|
200 |
// } |
|
201 |
|
|
202 |
|
|
203 |
/** |
|
204 |
* Gets the SWT chart components provider linked to this editor input. |
|
205 |
* @return the swtComponentProvider |
|
206 |
*/ |
|
207 |
public SWTChartsComponentsProvider getSWTChartsComponentsProvider() { |
|
208 |
return this.swtChartsComponentsProvider; |
|
209 |
} |
|
210 |
|
|
211 |
|
|
212 |
@Override |
|
213 |
public boolean equals(Object obj) { |
|
214 |
if(obj instanceof ChartEditorInput) { |
|
215 |
// FIXME: validate these tests for all chart editors |
|
216 |
// if(this == obj) { |
|
217 |
// return true; |
|
218 |
// }; |
|
219 |
// Always recreate an editor for specificites result |
|
220 |
if(((ChartEditorInput) obj).getResultData() instanceof SpecificitesResult) { |
|
221 |
return false; |
|
222 |
} |
|
223 |
// Always recreate an editor for partition dimension result |
|
224 |
if(((ChartEditorInput) obj).getResultData() instanceof Partition) { |
|
225 |
return false; |
|
226 |
} |
|
227 |
return this.resultData == ((ChartEditorInput) obj).getResultData(); |
|
228 |
} |
|
229 |
return false; |
|
230 |
} |
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
/** |
|
235 |
* @return the chartContainer |
|
236 |
*/ |
|
237 |
public Object getChartContainer() { |
|
238 |
return chartContainer; |
|
239 |
} |
|
240 |
|
|
241 |
|
|
242 |
/** |
|
243 |
* @param chartContainer the chartContainer to set |
|
244 |
*/ |
|
245 |
public void setChartContainer(Object chartContainer) { |
|
246 |
this.chartContainer = chartContainer; |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
/** |
|
251 |
* @param swtChartsComponentsProvider the swtChartsComponentsProvider to set |
|
252 |
*/ |
|
253 |
public void setSWTChartsComponentsProvider(SWTChartsComponentsProvider swtChartsComponentsProvider) { |
|
254 |
this.swtChartsComponentsProvider = swtChartsComponentsProvider; |
|
255 |
} |
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
/** |
|
260 |
* @return the chartType |
|
261 |
*/ |
|
262 |
public String getChartType() { |
|
263 |
return chartType; |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* @return the preferencesNodeQualifier |
|
268 |
*/ |
|
269 |
public String getPreferencesNodeQualifier() { |
|
270 |
return preferencesNodeQualifier; |
|
271 |
} |
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
/** |
|
276 |
* Sets and updates the local preferences node qualifier from the result data. |
|
277 |
* Synchronizes the local preferences node with the result data type, chart type, etc. |
|
278 |
*/ |
|
279 |
public void syncLocalPreferencesNode() { |
|
280 |
//this.preferencesNodeQualifier = TXMPreferences.getId(this.resultData); |
|
281 |
// FIXME: persistence test |
|
282 |
TXMPreferences.putLocalString(this.resultData, ChartsEnginePreferences.CHART_TYPE, this.chartType); |
|
283 |
TXMPreferences.putLocalString(this.resultData, ChartsEnginePreferences.RESULT_DATA_TYPE, this.resultData.getClass().getName()); |
|
284 |
} |
|
285 |
|
|
286 |
|
|
287 |
} |
|
0 | 288 |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/IChartComponent.java (revision 130) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp; |
|
2 |
|
|
3 |
import java.awt.event.MouseEvent; |
|
4 |
|
|
5 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
6 |
|
|
7 |
/** |
|
8 |
* Chart component interface. |
|
9 |
* @author sjacquot |
|
10 |
* |
|
11 |
*/ |
|
12 |
public interface IChartComponent { |
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
/** |
|
17 |
* Zooms the view at x and y coordinates. |
|
18 |
* @param x |
|
19 |
* @param y |
|
20 |
* @param zoomIn |
|
21 |
*/ |
|
22 |
public abstract void zoom(double x, double y, boolean zoomIn); |
|
23 |
|
|
24 |
/** |
|
25 |
* Resets the view. |
|
26 |
*/ |
|
27 |
public abstract void resetView(); |
|
28 |
|
|
29 |
/** |
|
30 |
* Pans the view. |
|
31 |
* @param srcX |
|
32 |
* @param srcY |
|
33 |
* @param dstX |
|
34 |
* @param dstY |
|
35 |
* @param panFactor |
|
36 |
*/ |
|
37 |
public abstract void pan(double srcX, double srcY, double dstX, double dstY, double panFactor); |
|
38 |
|
|
39 |
/** |
|
40 |
* Gets the linked editor. |
|
41 |
* @return |
|
42 |
*/ |
|
43 |
public ChartEditorPart getChartEditor(); |
|
44 |
|
|
45 |
/** |
|
46 |
* Sets the linked editor. |
|
47 |
* @param editor |
|
48 |
*/ |
|
49 |
public void setChartEditor(ChartEditorPart editor); |
|
50 |
|
|
51 |
/** |
|
52 |
* Update the mouse over item selection according to the specified mouse event. |
|
53 |
* @param event |
|
54 |
*/ |
|
55 |
public void updateMouseOverItem(MouseEvent event); |
|
56 |
} |
|
0 | 57 |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/___EditableComboFieldEditor.java (revision 130) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp.swt; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.Assert; |
|
4 |
import org.eclipse.jface.preference.FieldEditor; |
|
5 |
import org.eclipse.swt.SWT; |
|
6 |
import org.eclipse.swt.events.SelectionAdapter; |
|
7 |
import org.eclipse.swt.events.SelectionEvent; |
|
8 |
import org.eclipse.swt.layout.GridData; |
|
9 |
import org.eclipse.swt.widgets.Combo; |
|
10 |
import org.eclipse.swt.widgets.Composite; |
|
11 |
import org.eclipse.swt.widgets.Control; |
|
12 |
|
|
13 |
// FIXME : changeable JFace ComboFieldEditor, see if needed or not when the preferences structure for charts engine will be defined |
|
14 |
public class ___EditableComboFieldEditor extends FieldEditor { |
|
15 |
|
|
16 |
/** |
|
17 |
* The <code>Combo</code> widget. |
|
18 |
*/ |
|
19 |
private Combo fCombo; |
|
20 |
|
|
21 |
/** |
|
22 |
* The value (not the name) of the currently selected item in the Combo |
|
23 |
* widget. |
|
24 |
*/ |
|
25 |
private String fValue; |
|
26 |
|
|
27 |
/** |
|
28 |
* The names (labels) and underlying values to populate the combo widget. |
|
29 |
* These should be arranged as: { {name1, value1}, {name2, value2}, ...} |
|
30 |
*/ |
|
31 |
private String[][] fEntryNamesAndValues; |
|
32 |
|
|
33 |
|
|
34 |
private Composite parent; |
|
35 |
|
|
36 |
/** |
|
37 |
* Create the combo box field editor. |
|
38 |
* |
|
39 |
* @param name |
|
40 |
* the name of the preference this field editor works on |
|
41 |
* @param labelText |
|
42 |
* the label text of the field editor |
|
43 |
* @param entryNamesAndValues |
|
44 |
* the names (labels) and underlying values to populate the combo |
|
45 |
* widget. These should be arranged as: { {name1, value1}, |
|
46 |
* {name2, value2}, ...} |
|
47 |
* @param parent |
|
48 |
* the parent composite |
|
49 |
*/ |
|
50 |
public ___EditableComboFieldEditor(String name, String labelText, String[][] entryNamesAndValues, Composite parent) { |
|
51 |
init(name, labelText); |
|
52 |
this.parent = parent; |
|
53 |
Assert.isTrue(checkArray(entryNamesAndValues)); |
|
54 |
fEntryNamesAndValues = entryNamesAndValues; |
|
55 |
createControl(parent); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Checks whether given <code>String[][]</code> is of "type" |
|
60 |
* <code>String[][2]</code>. |
|
61 |
* |
|
62 |
* @return <code>true</code> if it is ok, and <code>false</code> otherwise |
|
63 |
*/ |
|
64 |
private boolean checkArray(String[][] table) { |
|
65 |
if(table == null) { |
|
66 |
return false; |
|
67 |
} |
|
68 |
for(int i = 0; i < table.length; i++) { |
|
69 |
String[] array = table[i]; |
|
70 |
if(array == null || array.length != 2) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
} |
|
74 |
return true; |
|
75 |
} |
|
76 |
|
|
77 |
/* |
|
78 |
* (non-Javadoc) |
|
79 |
* |
|
80 |
* @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) |
|
81 |
*/ |
|
82 |
protected void adjustForNumColumns(int numColumns) { |
|
83 |
if(numColumns > 1) { |
|
84 |
Control control = getLabelControl(); |
|
85 |
int left = numColumns; |
|
86 |
if(control != null) { |
|
87 |
((GridData) control.getLayoutData()).horizontalSpan = 1; |
|
88 |
left = left - 1; |
|
89 |
} |
|
90 |
((GridData) fCombo.getLayoutData()).horizontalSpan = left; |
|
91 |
} |
|
92 |
else { |
|
93 |
Control control = getLabelControl(); |
|
94 |
if(control != null) { |
|
95 |
((GridData) control.getLayoutData()).horizontalSpan = 1; |
|
96 |
} |
|
97 |
((GridData) fCombo.getLayoutData()).horizontalSpan = 1; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* (non-Javadoc) |
|
103 |
* |
|
104 |
* @see |
|
105 |
* org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt |
|
106 |
* .widgets.Composite, int) |
|
107 |
*/ |
|
108 |
protected void doFillIntoGrid(Composite parent, int numColumns) { |
|
109 |
int comboC = 1; |
|
110 |
if(numColumns > 1) { |
|
111 |
comboC = numColumns - 1; |
|
112 |
} |
|
113 |
Control control = getLabelControl(parent); |
|
114 |
GridData gd = new GridData(); |
|
115 |
gd.horizontalSpan = 1; |
|
116 |
control.setLayoutData(gd); |
|
117 |
control = getComboBoxControl(parent); |
|
118 |
gd = new GridData(); |
|
119 |
gd.horizontalSpan = comboC; |
|
120 |
gd.horizontalAlignment = GridData.FILL; |
|
121 |
control.setLayoutData(gd); |
|
122 |
control.setFont(parent.getFont()); |
|
123 |
} |
|
124 |
|
|
125 |
/* |
|
126 |
* (non-Javadoc) |
|
127 |
* |
|
128 |
* @see org.eclipse.jface.preference.FieldEditor#doLoad() |
|
129 |
*/ |
|
130 |
protected void doLoad() { |
|
131 |
updateComboForValue(getPreferenceStore().getString(getPreferenceName())); |
|
132 |
} |
|
133 |
|
|
134 |
/* |
|
135 |
* (non-Javadoc) |
|
136 |
* |
|
137 |
* @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() |
|
138 |
*/ |
|
139 |
protected void doLoadDefault() { |
|
140 |
updateComboForValue(getPreferenceStore().getDefaultString(getPreferenceName())); |
|
141 |
} |
|
142 |
|
|
143 |
/* |
|
144 |
* (non-Javadoc) |
|
145 |
* |
|
146 |
* @see org.eclipse.jface.preference.FieldEditor#doStore() |
|
147 |
*/ |
|
148 |
protected void doStore() { |
|
149 |
if(fValue == null) { |
|
150 |
getPreferenceStore().setToDefault(getPreferenceName()); |
|
151 |
return; |
|
152 |
} |
|
153 |
getPreferenceStore().setValue(getPreferenceName(), fValue); |
|
154 |
} |
|
155 |
|
|
156 |
/* |
|
157 |
* (non-Javadoc) |
|
158 |
* |
|
159 |
* @see org.eclipse.jface.preference.FieldEditor#getNumberOfControls() |
|
160 |
*/ |
|
161 |
public int getNumberOfControls() { |
|
162 |
return 2; |
|
163 |
} |
|
164 |
|
|
165 |
/* |
|
166 |
* Lazily create and return the Combo control. |
|
167 |
*/ |
|
168 |
public Combo getComboBoxControl(Composite parent) { |
|
169 |
if(fCombo == null) { |
|
170 |
fCombo = new Combo(parent, SWT.READ_ONLY); |
|
171 |
fCombo.setFont(parent.getFont()); |
|
172 |
for(int i = 0; i < fEntryNamesAndValues.length; i++) { |
|
173 |
fCombo.add(fEntryNamesAndValues[i][0], i); |
|
174 |
} |
|
175 |
|
|
176 |
fCombo.addSelectionListener(new SelectionAdapter() { |
|
177 |
public void widgetSelected(SelectionEvent evt) { |
|
178 |
String oldValue = fValue; |
|
179 |
String name = fCombo.getText(); |
|
180 |
fValue = getValueForName(name); |
|
181 |
setPresentsDefaultValue(false); |
|
182 |
fireValueChanged(VALUE, oldValue, fValue); |
|
183 |
} |
|
184 |
}); |
|
185 |
} |
|
186 |
return fCombo; |
|
187 |
} |
|
188 |
|
|
189 |
/* |
|
190 |
* Given the name (label) of an entry, return the corresponding value. |
|
191 |
*/ |
|
192 |
private String getValueForName(String name) { |
|
193 |
for(int i = 0; i < fEntryNamesAndValues.length; i++) { |
|
194 |
String[] entry = fEntryNamesAndValues[i]; |
|
195 |
if(name.equals(entry[0])) { |
|
196 |
return entry[1]; |
|
197 |
} |
|
198 |
} |
|
199 |
return fEntryNamesAndValues[0][0]; |
|
200 |
} |
|
201 |
|
|
202 |
/* |
|
203 |
* Set the name in the combo widget to match the specified value. |
|
204 |
*/ |
|
205 |
private void updateComboForValue(String value) { |
|
206 |
fValue = value; |
|
207 |
for(int i = 0; i < fEntryNamesAndValues.length; i++) { |
|
208 |
if(value.equals(fEntryNamesAndValues[i][1])) { |
|
209 |
fCombo.setText(fEntryNamesAndValues[i][0]); |
|
210 |
return; |
|
211 |
} |
|
212 |
} |
|
213 |
if(fEntryNamesAndValues.length > 0) { |
|
214 |
fValue = fEntryNamesAndValues[0][1]; |
|
215 |
fCombo.setText(fEntryNamesAndValues[0][0]); |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
/* |
|
220 |
* (non-Javadoc) |
|
221 |
* |
|
222 |
* @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean, |
|
223 |
* org.eclipse.swt.widgets.Composite) |
|
224 |
*/ |
|
225 |
public void setEnabled(boolean enabled, Composite parent) { |
|
226 |
super.setEnabled(enabled, parent); |
|
227 |
getComboBoxControl(parent).setEnabled(enabled); |
|
228 |
} |
|
229 |
|
|
230 |
|
|
231 |
/** |
|
232 |
* |
|
233 |
* @param entryNamesAndValues |
|
234 |
*/ |
|
235 |
public void setEntryNamesAndValues(String[][] entryNamesAndValues) { |
|
236 |
Assert.isTrue(checkArray(entryNamesAndValues)); |
|
237 |
this.fEntryNamesAndValues = entryNamesAndValues; |
|
238 |
|
|
239 |
this.getComboBoxControl(parent).dispose(); |
|
240 |
this.fCombo = null; |
|
241 |
createControl(this.parent); |
|
242 |
|
|
243 |
// FIXME : fonctionne mal, la sélection dans la combo box se fait bien mais c'est l'ancienne valeur d'index 0 qui est envoyée en tant que pref |
|
244 |
// this.fCombo.select(0); |
|
245 |
} |
|
246 |
|
|
247 |
} |
|
0 | 248 |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/ChartComposite.java (revision 130) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp.swt; |
|
2 |
|
|
3 |
import java.awt.Component; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.EventListener; |
|
6 |
|
|
7 |
import org.eclipse.jface.action.MenuManager; |
|
8 |
import org.eclipse.swt.SWT; |
|
9 |
import org.eclipse.swt.widgets.Composite; |
|
10 |
import org.eclipse.swt.widgets.Menu; |
|
11 |
import org.eclipse.swt.widgets.MenuItem; |
|
12 |
import org.eclipse.ui.PlatformUI; |
|
13 |
import org.eclipse.ui.menus.IMenuService; |
|
14 |
import org.txm.chartsengine.rcp.IChartComponent; |
|
15 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
16 |
import org.txm.chartsengine.rcp.events.EventCallBack; |
|
17 |
import org.txm.chartsengine.rcp.events.EventCallBackHandler; |
|
18 |
|
|
19 |
/** |
|
20 |
* Chart drawing area composite. |
|
21 |
* @author sjacquot |
|
22 |
* |
|
23 |
*/ |
|
24 |
public abstract class ChartComposite extends Composite { |
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
protected static final String CONTEXT_MENU_ID = "ChartEditorContextMenu"; //$NON-NLS-1$ |
|
29 |
|
|
30 |
|
|
31 |
/** |
|
32 |
* Custom tool tip. |
|
33 |
*/ |
|
34 |
// FIXME: tests HTML tool tips |
|
35 |
protected ___CustomHTMLToolTip toolTip; |
|
36 |
|
|
37 |
/** |
|
38 |
* The chart component. |
|
39 |
*/ |
|
40 |
protected IChartComponent chartComponent; |
|
41 |
|
|
42 |
/** |
|
43 |
* Context menus. |
|
44 |
*/ |
|
45 |
protected ArrayList<Menu> contextMenus; |
|
46 |
|
|
47 |
|
|
48 |
protected ChartEditorPart chartEditor; |
|
49 |
|
|
50 |
/** |
|
51 |
* |
|
52 |
* @param parent |
|
53 |
* @param style |
|
54 |
*/ |
|
55 |
public ChartComposite(ChartEditorPart chartEditor, Composite parent, int style) { |
|
56 |
super(parent, style); |
|
57 |
|
|
58 |
this.chartEditor = chartEditor; |
|
59 |
|
|
60 |
this.contextMenus = new ArrayList<Menu>(); |
|
61 |
this.contextMenus.add(null); |
|
62 |
this.contextMenus.add(null); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* Creates the pop up menu dedicated to empty area location click event. |
|
68 |
*/ |
|
69 |
public void initEmptyAreaContextMenu() { |
|
70 |
|
|
71 |
// FIXME: tests de liens vers menu RCP + changement dynamique d'une entrée du menu => ne fonctionne pas pour la modif dynamique |
|
72 |
// System.err.println("ChartComposite.initEmptyAreaContextMenu()"); |
|
73 |
MenuManager menuManager = new MenuManager(); |
|
74 |
//// menuManager.setRemoveAllWhenShown(true); |
|
75 |
IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IMenuService.class); |
|
76 |
menuService.populateContributionManager(menuManager, "popup:" + CONTEXT_MENU_ID); //$NON-NLS-1$ |
|
77 |
Menu menu = menuManager.createContextMenu(this); |
|
78 |
menuManager.update(true); |
|
79 |
this.contextMenus.set(EventCallBack.AREA_EMPTY, menu); |
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
// FIXME: manual creation |
|
84 |
// Menu menu = new Menu(this); |
|
85 |
// MenuItem exportViewItem = new MenuItem(menu, SWT.CASCADE); |
|
86 |
// exportViewItem.setText(SWTComponentsProviderMessages.ChartEditorToolBar_SHARED_BUTTON_EXPORT_VIEW_LABEL + "..."); |
|
87 |
// exportViewItem.setImage(IImageKeys.getImage(IImageKeys.CHARTS_EXPORT_VIEW)); |
|
88 |
// if(this.chartComponent != null) { |
|
89 |
// exportViewItem.addSelectionListener(new BaseSelectionListener(this.chartComponent.getChartEditor(), BaseSelectionListener.EXPORT_VIEW)); |
|
90 |
// } |
|
91 |
// |
|
92 |
// this.contextMenus.set(EventCallBack.AREA_EMPTY, menu); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Creates the pop up menu dedicated to chart item location click event. |
|
98 |
*/ |
|
99 |
public void initItemAreaContextMenu() { |
|
100 |
Menu menu = new Menu(this); |
|
101 |
MenuItem chartEntityLabelItem = new MenuItem(menu, SWT.CASCADE); |
|
102 |
//chartEntityLabelItem.setText(""); // this string is dedicated to be overridden by the current selected chart entity label/name |
|
103 |
|
|
104 |
// FIXME : tests |
|
105 |
// MenuItem refreshItem = new MenuItem(menu, SWT.NONE); |
|
106 |
// refreshItem.setText("Refresh"); |
|
107 |
// MenuItem deleteItem = new MenuItem(menu, SWT.NONE); |
|
108 |
// deleteItem.setText("Delete"); |
|
109 |
// |
|
110 |
Menu newMenu = new Menu(menu); |
|
111 |
chartEntityLabelItem.setMenu(newMenu); |
|
112 |
|
|
113 |
// MenuItem shortcutItem = new MenuItem(newMenu, SWT.NONE); |
|
114 |
// shortcutItem.setText("Shortcut"); |
|
115 |
// MenuItem iconItem = new MenuItem(newMenu, SWT.NONE); |
|
116 |
// iconItem.setText("Icon"); |
|
117 |
|
|
118 |
this.contextMenus.set(EventCallBack.AREA_ITEM, menu); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Defines the current context menu to display on menu event. |
|
123 |
* @param index |
|
124 |
*/ |
|
125 |
public void setCurrentContextMenu(int index) { |
|
126 |
this.setMenu(this.contextMenus.get(index)); |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Gets the menu specified by its index. |
|
131 |
* @param index |
|
132 |
* @return |
|
133 |
*/ |
|
134 |
public Menu getContextMenu(int index) { |
|
135 |
return this.contextMenus.get(index); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Loads the chart from specified data. |
|
140 |
* @param data |
|
141 |
*/ |
|
142 |
public abstract void loadChart(Object data); |
|
143 |
|
|
144 |
|
|
145 |
/** |
|
146 |
* Reloads the chart from the chart object stored into the composite. |
|
147 |
* This method is especially used for file based implementations of charts engine for reloading a file that has been externally modified. |
|
148 |
*/ |
|
149 |
public abstract void reloadChart(); |
Formats disponibles : Unified diff