| 1 |
1 |
package org.txm.chartsengine.rcp.preferences;
|
| 2 |
2 |
|
| 3 |
3 |
import java.util.ArrayList;
|
|
4 |
import java.util.Map;
|
| 4 |
5 |
import java.util.TreeSet;
|
| 5 |
6 |
|
| 6 |
|
import org.eclipse.core.runtime.IConfigurationElement;
|
| 7 |
|
import org.eclipse.core.runtime.Platform;
|
|
7 |
import org.eclipse.core.runtime.preferences.InstanceScope;
|
| 8 |
8 |
import org.eclipse.jface.preference.ColorFieldEditor;
|
| 9 |
9 |
import org.eclipse.jface.preference.ComboFieldEditor;
|
| 10 |
10 |
import org.eclipse.jface.preference.FontFieldEditor;
|
|
11 |
import org.eclipse.jface.preference.ListEditor;
|
| 11 |
12 |
import org.eclipse.jface.util.PropertyChangeEvent;
|
| 12 |
|
import org.eclipse.swt.layout.GridData;
|
| 13 |
|
import org.eclipse.swt.widgets.Text;
|
| 14 |
13 |
import org.eclipse.ui.IWorkbench;
|
| 15 |
|
import org.eclipse.ui.PlatformUI;
|
| 16 |
|
import org.txm.Toolbox;
|
| 17 |
14 |
import org.txm.chartsengine.core.ChartsEngine;
|
| 18 |
15 |
import org.txm.chartsengine.core.ChartsEnginesManager;
|
| 19 |
16 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences;
|
| 20 |
17 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
|
| 21 |
18 |
import org.txm.chartsengine.rcp.messages.ChartsUIMessages;
|
| 22 |
|
import org.txm.core.engines.EngineType;
|
| 23 |
|
import org.txm.core.preferences.TBXPreferences;
|
| 24 |
19 |
import org.txm.core.preferences.TXMPreferences;
|
| 25 |
20 |
import org.txm.rcp.preferences.TXMPreferencePage;
|
| 26 |
21 |
import org.txm.rcp.preferences.TXMPreferenceStore;
|
| 27 |
|
import org.txm.rcp.TxmPreferences;
|
| 28 |
|
import org.txm.rcp.preferences.ExportPreferencePage;
|
| 29 |
|
import org.txm.rcp.preferences.UserPreferencePage;
|
| 30 |
22 |
import org.txm.utils.logger.Log;
|
| 31 |
23 |
|
| 32 |
24 |
/**
|
| 33 |
|
* The charts engine preference page.
|
|
25 |
* Charts engine preferences page.
|
|
26 |
*
|
| 34 |
27 |
* @author sjacquot
|
| 35 |
28 |
*
|
| 36 |
29 |
*/
|
| ... | ... | |
| 39 |
32 |
/**
|
| 40 |
33 |
* The charts engine selection combo box.
|
| 41 |
34 |
*/
|
| 42 |
|
private ComboFieldEditor chartsEngineComboField;
|
| 43 |
|
|
| 44 |
|
|
|
35 |
private ComboFieldEditor chartsEngineSelectionComboField;
|
|
36 |
|
| 45 |
37 |
/**
|
| 46 |
|
* The property changed state.
|
|
38 |
* The charts engine export formats selection combo box.
|
| 47 |
39 |
*/
|
| 48 |
|
private boolean hasChanged;
|
|
40 |
private ComboFieldEditor chartsEngineExportFormatsComboField;
|
|
41 |
|
|
42 |
protected boolean charsEngineHasChanged = false;
|
| 49 |
43 |
|
| 50 |
|
|
| 51 |
|
/**
|
| 52 |
|
* Instantiates a new export preference page.
|
| 53 |
|
*/
|
| 54 |
|
public ChartsEnginePreferencePage() {
|
| 55 |
|
super();
|
| 56 |
|
this.hasChanged = false;
|
| 57 |
|
}
|
| 58 |
44 |
|
| 59 |
45 |
@Override
|
| 60 |
46 |
protected void createFieldEditors() {
|
| 61 |
47 |
|
| 62 |
|
// populate combo box with installed charts engine contributions
|
| 63 |
|
String extensionPointId = "org.txm.chartsengine.chartsengine"; //$NON-NLS-1$
|
| 64 |
|
IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
|
| 65 |
|
|
| 66 |
48 |
// Charts engine selection
|
| 67 |
|
String chartsEngines[][] = new String[contributions.length][2];
|
| 68 |
|
for(int i = 0; i < contributions.length; i++) {
|
| 69 |
|
chartsEngines[i][0] = contributions[i].getAttribute("description"); //$NON-NLS-1$
|
| 70 |
|
chartsEngines[i][1] = contributions[i].getAttribute("name"); //$NON-NLS-1$
|
|
49 |
String chartsEngines[][] = new String[ChartsEnginesManager.getInstance().size()][2];
|
|
50 |
|
|
51 |
int i = 0;
|
|
52 |
for (Map.Entry<String, ChartsEngine> entry : ChartsEnginesManager.getInstance().entrySet()) {
|
|
53 |
chartsEngines[i][0] = entry.getValue().getDetails();
|
|
54 |
chartsEngines[i][1] = entry.getValue().getName();
|
|
55 |
i++;
|
| 71 |
56 |
}
|
| 72 |
57 |
|
| 73 |
|
this.chartsEngineComboField = new ComboFieldEditor(ChartsEnginePreferences.CURRENT_NAME, ChartsUIMessages.currentEngine, chartsEngines, this.getFieldEditorParent());
|
| 74 |
|
this.addField(this.chartsEngineComboField);
|
| 75 |
|
|
|
58 |
this.chartsEngineSelectionComboField = new ComboFieldEditor(ChartsEnginePreferences.CURRENT_NAME, ChartsUIMessages.currentEngine, chartsEngines, this.getFieldEditorParent());
|
|
59 |
this.addField(this.chartsEngineSelectionComboField);
|
| 76 |
60 |
|
| 77 |
|
// current engine supported export formats
|
| 78 |
|
ArrayList<String> supportedExportFormats = new ArrayList<String>();
|
| 79 |
|
supportedExportFormats.addAll(((ChartsEngine) Toolbox.getEngineManager(EngineType.CHARTS).getCurrentEngine()).getSupportedOutputFileFormats());
|
| 80 |
61 |
|
| 81 |
|
// Sort the set
|
| 82 |
|
TreeSet<String> formatsSet = new TreeSet <String>(supportedExportFormats);
|
| 83 |
|
String[] formats = formatsSet.toArray(new String[formatsSet.size()]);
|
|
62 |
// FIXME: SJ: test to select the chart engine order rather than a exclusive one since the engines are not exclusive anymore, eg. some to create charts and other to create graphs
|
|
63 |
// ListEditor listEditor = new ListEditor(ChartsEnginePreferences.CHARTS_ENGINES_ORDER, "Ordre de préférence des moteurs", this.getFieldEditorParent()) {
|
|
64 |
//
|
|
65 |
// @Override
|
|
66 |
// protected String[] parseString(String enginesOrder) {
|
|
67 |
// return ChartsEnginePreferences.getEnginesOrder(enginesOrder);
|
|
68 |
// }
|
|
69 |
//
|
|
70 |
// @Override
|
|
71 |
// protected String getNewInputObject() {
|
|
72 |
//// InputDialog dialog = new InputDialog(getShell(), "New Buildconfiguration", "Enter the name of the Buildconfiguration to add", "", null);
|
|
73 |
//// if (dialog.open() == InputDialog.OK) {
|
|
74 |
//// return dialog.getValue();
|
|
75 |
//// }
|
|
76 |
// return null;
|
|
77 |
// }
|
|
78 |
//
|
|
79 |
// @Override
|
|
80 |
// protected String createList(String[] engineNames) {
|
|
81 |
// return ChartsEnginePreferences.createEnginesOrder(engineNames);
|
|
82 |
// }
|
|
83 |
// };
|
|
84 |
//
|
|
85 |
// // default initialization
|
|
86 |
// if(!TXMPreferences.keyExists("/" + InstanceScope.SCOPE +"/" + ChartsEnginePreferences.getInstance().getPreferencesNodeQualifier(), ChartsEnginePreferences.CHARTS_ENGINES_ORDER)) {
|
|
87 |
// ChartsEnginePreferences.getInstance().put(ChartsEnginePreferences.CHARTS_ENGINES_ORDER, ChartsEnginesManager.getInstance().createEnginesOrder());
|
|
88 |
// }
|
|
89 |
//
|
|
90 |
// listEditor.setPreferenceName(ChartsEnginePreferences.CHARTS_ENGINES_ORDER);
|
|
91 |
// listEditor.load();
|
|
92 |
//
|
|
93 |
// // hide the "New" and "Remove" buttons
|
|
94 |
// listEditor.getButtonBoxControl(this.getFieldEditorParent()).getChildren()[0].setVisible(false);;
|
|
95 |
// listEditor.getButtonBoxControl(this.getFieldEditorParent()).getChildren()[1].setVisible(false);
|
|
96 |
//
|
|
97 |
// this.addField(listEditor);
|
| 84 |
98 |
|
| 85 |
|
String[][] exportFormats = new String[formats.length][2];
|
| 86 |
|
for(int i = 0; i < formats.length; i++) {
|
| 87 |
|
exportFormats[i][0] = formats[i];
|
| 88 |
|
exportFormats[i][1] = formats[i];
|
| 89 |
|
}
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
// current engine supported export formats
|
|
103 |
this.createExportFormatComboField(ChartsEnginesManager.getInstance().getCurrentEngine());
|
| 90 |
104 |
|
| 91 |
|
this.addField(new ComboFieldEditor(ChartsEnginePreferences.DEFAULT_EXPORT_FORMAT, ChartsUIMessages.defaultExportFormat, exportFormats, this.getFieldEditorParent()));
|
| 92 |
105 |
|
| 93 |
|
|
| 94 |
106 |
// other shared preferences
|
| 95 |
107 |
SWTChartsComponentsProvider.createChartsRenderingPreferencesFields(this, this.getFieldEditorParent());
|
| 96 |
108 |
|
| ... | ... | |
| 107 |
119 |
|
| 108 |
120 |
}
|
| 109 |
121 |
|
|
122 |
/**
|
|
123 |
* Creates the export format combo box according the specified charts engine.
|
|
124 |
*
|
|
125 |
* @param engine
|
|
126 |
*/
|
|
127 |
protected void createExportFormatComboField(ChartsEngine engine) {
|
|
128 |
this.chartsEngineExportFormatsComboField = new ComboFieldEditor(ChartsEnginePreferences.DEFAULT_EXPORT_FORMAT, ChartsUIMessages.defaultExportFormat, ChartsEnginesManager.getExportFormatsEntryNamesAndValues(engine), this.getFieldEditorParent());
|
|
129 |
this.addField(this.chartsEngineExportFormatsComboField);
|
|
130 |
}
|
| 110 |
131 |
|
|
132 |
|
| 111 |
133 |
@Override
|
| 112 |
134 |
public void propertyChange(PropertyChangeEvent event) {
|
| 113 |
135 |
super.propertyChange(event);
|
| 114 |
136 |
|
| 115 |
|
// Store the property changed state for not recreating a new ChartsEngine if the property hasn't been changed
|
|
137 |
// FIXME: SJ: test to try to update the Export formats combo box when changing of current charts engine
|
| 116 |
138 |
// NOTE: SJ: warning, event.getProperty() seems bugged and does not return the correct property name but the string "field_value_editor"
|
| 117 |
|
if(event.getSource() == this.chartsEngineComboField && !event.getNewValue().equals(event.getOldValue())) {
|
| 118 |
|
this.hasChanged = true;
|
|
139 |
if(event.getSource() == this.chartsEngineSelectionComboField && !event.getNewValue().equals(event.getOldValue())) {
|
|
140 |
this.charsEngineHasChanged = true;
|
|
141 |
// this.chartsEngineExportFormatsComboField.dispose();
|
|
142 |
// this.createExportFormatComboField(ChartsEnginesManager.getInstance().getEngine((String) event.getNewValue()));
|
|
143 |
// this.adjustGridLayout();
|
|
144 |
// this.getFieldEditorParent().layout();
|
| 119 |
145 |
}
|
|
146 |
|
| 120 |
147 |
}
|
| 121 |
148 |
|
| 122 |
149 |
|
| ... | ... | |
| 138 |
165 |
ChartsEngine.getChartsEngines().get(i).getTheme().setMonochromeColor(ChartsEnginePreferences.getInstance().getString(ChartsEnginePreferences.MONOCHROME_COLOR));
|
| 139 |
166 |
}
|
| 140 |
167 |
|
|
168 |
Log.info(ChartsUIMessages.recreatingChartsEngineAndSWTChartComponentsProvider);
|
| 141 |
169 |
|
| 142 |
|
// Only if the current engine has changed
|
| 143 |
|
if(this.hasChanged) {
|
|
170 |
ChartsEnginesManager.getInstance().setCurrentEngine(this.getPreferenceStore().getString(ChartsEnginePreferences.CURRENT_NAME));
|
|
171 |
|
|
172 |
// Sets the new current charts SWT component provider according to the new current charts engine
|
|
173 |
SWTChartsComponentsProvider.setCurrrentComponentsProvider(ChartsEnginesManager.getInstance().getCurrentEngine());
|
|
174 |
|
|
175 |
// Reset the default export format to the new current charts engine first supported export file format
|
|
176 |
//ChartsEnginePreferences.getInstance().put(ChartsEnginePreferences.DEFAULT_EXPORT_FORMAT, ChartsEngine.getCurrent().getSupportedOutputFileFormats().get(0));
|
| 144 |
177 |
|
| 145 |
|
Log.info(ChartsUIMessages.recreatingChartsEngineAndSWTChartComponentsProvider);
|
| 146 |
178 |
|
| 147 |
|
Toolbox.getEngineManager(EngineType.CHARTS).setCurrentEngine(this.getPreferenceStore().getString(ChartsEnginePreferences.CURRENT_NAME));
|
| 148 |
|
|
| 149 |
|
// Sets the new current charts SWT component provider according to the new current charts engine
|
| 150 |
|
SWTChartsComponentsProvider.setCurrrentComponentsProvider((ChartsEngine) Toolbox.getEngineManager(EngineType.CHARTS).getCurrentEngine());
|
| 151 |
|
|
| 152 |
|
// Reset the default export format to the new charts engine first supported export file format
|
| 153 |
|
ChartsEnginePreferences.getInstance().put(ChartsEnginePreferences.DEFAULT_EXPORT_FORMAT, ChartsEngine.getCurrent().getSupportedOutputFileFormats().get(0));
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
}
|
| 157 |
|
|
| 158 |
179 |
return true;
|
| 159 |
180 |
}
|
| 160 |
181 |
}
|