Révision 1996

tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEnginesManager.java (revision 1996)
1 1
package org.txm.chartsengine.core;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.Map;
5
import java.util.TreeSet;
4 6

  
7
import org.apache.commons.lang.ArrayUtils;
5 8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.txm.Toolbox;
6 10
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences;
7 11
import org.txm.core.engines.EngineType;
8 12
import org.txm.core.engines.EnginesManager;
9
import org.txm.core.preferences.TXMPreferences;
10 13

  
11 14
/**
12 15
 * Charts engines manager.
......
15 18
 * @author sjacquot
16 19
 *
17 20
 */
18
//FIXME: SJ: useless class, the type and priority/order should be defined in org.txm.core.engines.EnginesManager extension point
19
@Deprecated
20 21
public class ChartsEnginesManager extends EnginesManager<ChartsEngine> {
21 22

  
22 23
	@Override
......
33 34
		ChartsEngine.chartsEngines = new ArrayList<ChartsEngine>();
34 35
//		ChartsEngine.currentChartsEngineIndex = 0;
35 36
//
36
		for (ChartsEngine engine : values()) {
37

  
38
		for (ChartsEngine engine : this.values()) {
37 39
			ChartsEngine.chartsEngines.add(engine);
38 40
		}
41

  
42
		// add the engines sorted by order defined in preferences
43
		this.sortEngines();
39 44
		
45
		
46
//		String[] orderedEnginesNames = ((ChartsEnginePreferences) ChartsEnginePreferences.getInstance()).getEnginesOrder();
47
//		ChartsEngine[] engines = new ChartsEngine[this.size()];
48
//		
49
//		for (ChartsEngine engine : this.values()) {
50
//			//ChartsEngine.chartsEngines.add(engine);
51
//			engines[ArrayUtils.indexOf(orderedEnginesNames, engine.getName())] = engine;
52
//			
53
//		}
54
//		for (int i = 0; i < engines.length; i++) {
55
//			ChartsEngine.chartsEngines.add(engines[i]);	
56
//		}
57
		
58
		
40 59
		//ChartsEngine.setCurrrentChartsEngine(this.getEngine(ChartsEnginePreferences.getInstance().getString(ChartsEnginePreferences.CURRENT_NAME)));
41 60
		
42 61
		this.setCurrentEngine(ChartsEnginePreferences.getInstance().getString(ChartsEnginePreferences.CURRENT_NAME));
......
49 68
		return super.startEngines(monitor);
50 69
	}
51 70
	
71
	
72
	/**
73
	 * Sorts the engines according to the engines order preference.
74
	 */
75
	public void sortEngines() {
76
		String[] orderedEnginesNames = ((ChartsEnginePreferences) ChartsEnginePreferences.getInstance()).getEnginesOrder();
77
		
78
		// existing preference
79
		if(orderedEnginesNames != null)	{
80
			ChartsEngine[] engines = new ChartsEngine[this.size()];
81
			ChartsEngine.chartsEngines.clear();
82
			
83
			for (ChartsEngine engine : this.values()) {
84
				//ChartsEngine.chartsEngines.add(engine);
85
				engines[ArrayUtils.indexOf(orderedEnginesNames, engine.getName())] = engine;
86
				
87
			}
88
			for (int i = 0; i < engines.length; i++) {
89
				ChartsEngine.chartsEngines.add(engines[i]);	
90
			}
91
		}
92
		// non existing preference
93
		else	{
94
			ChartsEnginePreferences.getInstance().put(ChartsEnginePreferences.CHARTS_ENGINES_ORDER, this.createEnginesOrder());
95
		}
96
		
97
	}
98
	
99
	
52 100
	@Override
101
	public ChartsEngine getCurrentEngine() {
102
		return this.currentEngine;
103
		// FIXME: SJ: test to retrieve the first engine of the map
104
//		return ChartsEngine.chartsEngines.get(0);
105
	}
106

  
107
	@Override
108
	public void setCurrentEngine(ChartsEngine engine) {
109
		super.setCurrentEngine(engine);
110

  
111
		this.sortEngines();
112
		//ChartsEngine.chartsEngines.
113
		
114
		//String[] enginesNames = this.getEnginesOrder();
115
	}
116
	
117
	/**
118
	 * Gets an installed charts engine that supports the specified output format.
119
	 * @param outputFormat
120
	 * @return
121
	 */
122
	public ChartsEngine getChartsEngine(String outputFormat)	{
123
		ChartsEngine chartsEngine = null;
124
		for(int i = 0; i < ChartsEngine.chartsEngines.size(); i++) {
125
			if(ChartsEngine.chartsEngines.get(i).getSupportedOutputDisplayFormats().contains(outputFormat) || ChartsEngine.chartsEngines.get(i).getSupportedOutputFileFormats().contains(outputFormat))	{
126
				chartsEngine = ChartsEngine.chartsEngines.get(i);
127
				break;
128
			}
129
		}
130
		return chartsEngine;
131
	}
132
	
133
	/**
134
	 * Creates the charts engine order string with | separator from the specified engines list.
135
	 * @param chartsEngineNames
136
	 * @return
137
	 */
138
	public String createEnginesOrder() {
139
		return ChartsEnginePreferences.createEnginesOrder(this.getEnginesOrder());
140
	}
141
	
142
	/**
143
	 * 
144
	 * @return
145
	 */
146
	public String[] getEnginesOrder() {
147
		String[] engineNames = new String[this.size()];
148
		int i = 0;
149
		for (Map.Entry<String, ChartsEngine> entry : this.entrySet()) {
150
			engineNames[i] = entry.getValue().getName();					
151
			i++;
152
		}
153
		return engineNames;
154
	}
155
	
156
	/**
157
	 * Gets the instance stored in the Toolbox.
158
	 * 
159
	 * @return the instance stored in the Toolbox
160
	 */
161
	public static ChartsEnginesManager getInstance()	{
162
		return (ChartsEnginesManager) Toolbox.getEngineManager(EngineType.CHARTS);
163
	}
164
	
165
	
166
	/**
167
	 * Gets the entry names and values of the supported export formats of the specified charts engine.
168
	 * @param engine
169
	 * @return the entry names and values of the supported export formats of the specified charts engine
170
	 */
171
	public static String[][] getExportFormatsEntryNamesAndValues(ChartsEngine engine)	{
172
		ArrayList<String> supportedExportFormats = new ArrayList<String>();
173
		supportedExportFormats.addAll(engine.getSupportedOutputFileFormats());
174
		
175
		// Sort the set
176
		TreeSet<String> formatsSet = new TreeSet <String>(supportedExportFormats);
177
		String[] formats = formatsSet.toArray(new String[formatsSet.size()]);
178
		
179
		String[][] exportFormats = new String[formats.length][2];
180
		for(int j = 0; j < formats.length; j++) {
181
			exportFormats[j][0] = formats[j];
182
			exportFormats[j][1] = formats[j];
183
		}
184
		return exportFormats;
185
	}
186

  
187
	
188
	@Override
53 189
	public EngineType getEnginesType() {
54 190
		return EngineType.CHARTS;
55 191
	}

Formats disponibles : Unified diff