1 | package de.uka.ipd.sdq.simulation.preferences; |
2 | |
3 | import org.apache.log4j.Logger; |
4 | import org.eclipse.core.runtime.CoreException; |
5 | import org.eclipse.core.runtime.Platform; |
6 | |
7 | import de.uka.ipd.sdq.simulation.Activator; |
8 | import de.uka.ipd.sdq.simulation.abstractsimengine.ISimEngineFactory; |
9 | import de.uka.ipd.sdq.simulation.abstractsimengine.util.AbstractSimEngineExtensionHelper; |
10 | |
11 | public class SimulationPreferencesHelper { |
12 | |
13 | private static final Logger logger = Logger.getLogger(SimulationPreferencesHelper.class); |
14 | |
15 | /** |
16 | * Returns the default simulation engine. The default engine is the first entry in the list of |
17 | * extensions. |
18 | */ |
19 | public static String getDefaultEngineId() { |
20 | // retrieve all available simulation engines and set the first engine as default. |
21 | String firstEngineId = null; |
22 | try { |
23 | String[][] engineNamesAndIds = AbstractSimEngineExtensionHelper.getEngineNamesAndIds(); |
24 | if (engineNamesAndIds.length > 0) { |
25 | firstEngineId = engineNamesAndIds[0][1]; |
26 | } |
27 | } catch (CoreException e) { |
28 | logger.warn("Could not retrieve simulation engine names and ids.", e); |
29 | } |
30 | return firstEngineId; |
31 | } |
32 | |
33 | public static ISimEngineFactory getPreferredSimulationEngine() { |
34 | // retrieve the id of the preferred engine |
35 | String preferredEngineId = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, |
36 | SimulationPreferencePage.PREFERENCE_SIMULATION_ENGINE_ID, getDefaultEngineId(), null); |
37 | |
38 | // retrieve simulation engine factory for the preferred engine |
39 | ISimEngineFactory engineFactory = null; |
40 | try { |
41 | engineFactory = AbstractSimEngineExtensionHelper.getEngineFactory(preferredEngineId); |
42 | } catch (CoreException e) { |
43 | logger.warn("Could not retrieve simulation engine factory.", e); |
44 | } |
45 | |
46 | return engineFactory; |
47 | } |
48 | |
49 | } |