Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/impl/EclipsePreferenceTaskImpl.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/impl/EclipsePreferenceTaskImpl.java309
1 files changed, 309 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/impl/EclipsePreferenceTaskImpl.java b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/impl/EclipsePreferenceTaskImpl.java
new file mode 100644
index 0000000000..3beed3cb54
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/impl/EclipsePreferenceTaskImpl.java
@@ -0,0 +1,309 @@
+/**
+ */
+package org.eclipse.emf.cdo.releng.setup.impl;
+
+import org.eclipse.emf.cdo.releng.setup.EclipsePreferenceTask;
+import org.eclipse.emf.cdo.releng.setup.SetupPackage;
+import org.eclipse.emf.cdo.releng.setup.SetupTaskContext;
+import org.eclipse.emf.cdo.releng.setup.Trigger;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.impl.ENotificationImpl;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.PlatformUI;
+
+import java.util.Set;
+
+/**
+ * <!-- begin-user-doc -->
+ * An implementation of the model object '<em><b>Eclipse Preference Task</b></em>'.
+ * <!-- end-user-doc -->
+ * <p>
+ * The following features are implemented:
+ * <ul>
+ * <li>{@link org.eclipse.emf.cdo.releng.setup.impl.EclipsePreferenceTaskImpl#getKey <em>Key</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.releng.setup.impl.EclipsePreferenceTaskImpl#getValue <em>Value</em>}</li>
+ * </ul>
+ * </p>
+ *
+ * @generated
+ */
+public class EclipsePreferenceTaskImpl extends SetupTaskImpl implements EclipsePreferenceTask
+{
+ /**
+ * The default value of the '{@link #getKey() <em>Key</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @see #getKey()
+ * @generated
+ * @ordered
+ */
+ protected static final String KEY_EDEFAULT = null;
+
+ /**
+ * The cached value of the '{@link #getKey() <em>Key</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @see #getKey()
+ * @generated
+ * @ordered
+ */
+ protected String key = KEY_EDEFAULT;
+
+ /**
+ * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @see #getValue()
+ * @generated
+ * @ordered
+ */
+ protected static final String VALUE_EDEFAULT = null;
+
+ /**
+ * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @see #getValue()
+ * @generated
+ * @ordered
+ */
+ protected String value = VALUE_EDEFAULT;
+
+ private transient Object cachedNode;
+
+ private transient String property;
+
+ private transient String expandedValue;
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ protected EclipsePreferenceTaskImpl()
+ {
+ super();
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ protected EClass eStaticClass()
+ {
+ return SetupPackage.Literals.ECLIPSE_PREFERENCE_TASK;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public String getKey()
+ {
+ return key;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public void setKey(String newKey)
+ {
+ String oldKey = key;
+ key = newKey;
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.ECLIPSE_PREFERENCE_TASK__KEY, oldKey, key));
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public void setValue(String newValue)
+ {
+ String oldValue = value;
+ value = newValue;
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.ECLIPSE_PREFERENCE_TASK__VALUE, oldValue,
+ value));
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ public Object eGet(int featureID, boolean resolve, boolean coreType)
+ {
+ switch (featureID)
+ {
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__KEY:
+ return getKey();
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__VALUE:
+ return getValue();
+ }
+ return super.eGet(featureID, resolve, coreType);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ public void eSet(int featureID, Object newValue)
+ {
+ switch (featureID)
+ {
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__KEY:
+ setKey((String)newValue);
+ return;
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__VALUE:
+ setValue((String)newValue);
+ return;
+ }
+ super.eSet(featureID, newValue);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ public void eUnset(int featureID)
+ {
+ switch (featureID)
+ {
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__KEY:
+ setKey(KEY_EDEFAULT);
+ return;
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__VALUE:
+ setValue(VALUE_EDEFAULT);
+ return;
+ }
+ super.eUnset(featureID);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ public boolean eIsSet(int featureID)
+ {
+ switch (featureID)
+ {
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__KEY:
+ return KEY_EDEFAULT == null ? key != null : !KEY_EDEFAULT.equals(key);
+ case SetupPackage.ECLIPSE_PREFERENCE_TASK__VALUE:
+ return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value);
+ }
+ return super.eIsSet(featureID);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ @Override
+ public String toString()
+ {
+ if (eIsProxy())
+ return super.toString();
+
+ StringBuffer result = new StringBuffer(super.toString());
+ result.append(" (key: ");
+ result.append(key);
+ result.append(", value: ");
+ result.append(value);
+ result.append(')');
+ return result.toString();
+ }
+
+ @Override
+ public Object getOverrideToken()
+ {
+ return createToken(getKey());
+ }
+
+ @Override
+ public Set<Trigger> getValidTriggers()
+ {
+ return Trigger.IDE_TRIGGERS;
+ }
+
+ public boolean isNeeded(SetupTaskContext context) throws Exception
+ {
+ org.osgi.service.prefs.Preferences node = Platform.getPreferencesService().getRootNode();
+
+ String[] segments = key.split("/");
+ for (int i = 0; i < segments.length - 1; i++)
+ {
+ String segment = segments[i];
+ node = node.node(segment);
+ }
+
+ property = segments[segments.length - 1];
+ expandedValue = context.expandString(getValue());
+
+ String oldValue = node.get(property, null);
+ if (expandedValue.equals(oldValue))
+ {
+ return false;
+ }
+
+ cachedNode = node;
+ return true;
+ }
+
+ public void perform(SetupTaskContext context) throws Exception
+ {
+ context.log("Setting preference " + getKey() + " = " + expandedValue);
+
+ final Exception[] exception = { null };
+ PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ org.osgi.service.prefs.Preferences node = (org.osgi.service.prefs.Preferences)cachedNode;
+ node.put(property, expandedValue);
+ node.flush();
+ }
+ catch (Exception ex)
+ {
+ exception[0] = ex;
+ }
+ }
+ });
+
+ if (exception[0] != null)
+ {
+ throw exception[0];
+ }
+ }
+
+} // EclipsePreferenceTaskImpl

Back to the top