Author: scabanovich
Date: 2012-01-26 19:08:34 -0500 (Thu, 26 Jan 2012)
New Revision: 38234
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/plugin/ModelPreferenceInitializer.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/plugin.xml
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/PreferenceModelUtilities.java
Log:
JBIDE-6132
https://issues.jboss.org/browse/JBIDE-6132
Load instance of preference XModel through preference store initialization.
Modified: trunk/common/plugins/org.jboss.tools.common.model/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/plugin.xml 2012-01-26 23:38:47 UTC
(rev 38233)
+++ trunk/common/plugins/org.jboss.tools.common.model/plugin.xml 2012-01-27 00:08:34 UTC
(rev 38234)
@@ -406,4 +406,8 @@
</factory>
</extension>
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer
class="org.jboss.tools.common.model.plugin.ModelPreferenceInitializer"/>
+ </extension>
+
</plugin>
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/PreferenceModelUtilities.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/PreferenceModelUtilities.java 2012-01-26
23:38:47 UTC (rev 38233)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/PreferenceModelUtilities.java 2012-01-27
00:08:34 UTC (rev 38234)
@@ -12,6 +12,7 @@
import java.util.Properties;
+import org.eclipse.core.runtime.Platform;
import org.jboss.tools.common.model.ServiceDialog;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelConstants;
@@ -25,29 +26,36 @@
public class PreferenceModelUtilities {
static final String ENT_OPTION_ROOT = "OptionRoot"; //$NON-NLS-1$
- private static class PreferenceModelHolder {
- public static XModel preferenceModel;
+ private static XModel preferenceModel;
- static {
- String f = ModelPlugin.getDefault().getStateLocation().toString();
- Properties p = new Properties();
- p.setProperty(XModelConstants.WORKSPACE, f);
- preferenceModel = createPreferenceModel(p);
- ServiceDialog d = createServiceDialog();
- if(d != null) {
- d.setModel(preferenceModel);
- preferenceModel.setService(d);
- }
+ private static ServiceDialog createServiceDialog() {
+ return
(ServiceDialog)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.common.model.ui.wizards.one.ServiceDialogImpl");
//$NON-NLS-1$
+ }
+
+ public static void initDefaultPreferenceModel() {
+ if(preferenceModel != null) {
+ return;
}
-
- private static ServiceDialog createServiceDialog() {
- return
(ServiceDialog)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.common.model.ui.wizards.one.ServiceDialogImpl");
//$NON-NLS-1$
+ String f = ModelPlugin.getDefault().getStateLocation().toString();
+ Properties p = new Properties();
+ p.setProperty(XModelConstants.WORKSPACE, f);
+ preferenceModel = createPreferenceModel(p);
+ ServiceDialog d = createServiceDialog();
+ if(d != null) {
+ d.setModel(preferenceModel);
+ preferenceModel.setService(d);
}
-
}
public static XModel getPreferenceModel() {
- return PreferenceModelHolder.preferenceModel;
+ if(preferenceModel == null) {
+ Platform.getBundle(ModelPlugin.PLUGIN_ID);
+ //Kick preference store to make it load.
+ ModelPlugin.getDefault().getPreferenceStore().getDefaultBoolean("preferenceModel"); //$NON-NLS-1$
+ //Just in case
+ initDefaultPreferenceModel();
+ }
+ return preferenceModel;
}
public static XModel createPreferenceModel(Properties p) {
@@ -56,14 +64,11 @@
return XModelFactory.getModel(p);
}
- public static void initPreferenceValue(XModel initialModel, Preference preference)
- throws XModelException {
+ public static void initPreferenceValue(XModel initialModel, Preference preference)
throws XModelException {
String value = preference.getValue();
- if (value == null || "".equals(value)) //$NON-NLS-1$
- {
+ if (value == null || value.length() == 0) {
XModelObject object = initialModel.getByPath(preference.getModelPath());
- if (object != null)
- {
+ if (object != null) {
String newValue = object.getAttributeValue(preference.getName());
if (newValue != null && !newValue.equals(value))
preference.setValue(newValue);
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/plugin/ModelPreferenceInitializer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/plugin/ModelPreferenceInitializer.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/plugin/ModelPreferenceInitializer.java 2012-01-27
00:08:34 UTC (rev 38234)
@@ -0,0 +1,19 @@
+package org.jboss.tools.common.model.plugin;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+
+public class ModelPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ ((IScopeContext)DefaultScope.INSTANCE).getNode(ModelPlugin.PLUGIN_ID);
+ PreferenceModelUtilities.initDefaultPreferenceModel();
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/plugin/ModelPreferenceInitializer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain