Author: adietish
Date: 2011-10-03 05:49:53 -0400 (Mon, 03 Oct 2011)
New Revision: 35270
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/AbstractPreferenceValue.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringPreferenceValue.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringsPreferenceValue.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/AbstractPreferenceValue.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringPreferenceValue.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringsPreferenceValue.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/SshPrivateKeysPreferences.java
Log:
[JBIDE-9805] moved StringPreferenceValue etc. to org.jboss.tools.common.ui
Modified: trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-03
09:42:59 UTC (rev 35269)
+++ trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-03
09:49:53 UTC (rev 35270)
@@ -20,6 +20,7 @@
Export-Package: org.jboss.tools.common.ui,
org.jboss.tools.common.ui.databinding,
org.jboss.tools.common.ui.preferences,
+ org.jboss.tools.common.ui.preferencevalue,
org.jboss.tools.common.ui.widget.editor,
org.jboss.tools.common.ui.widget.field,
org.jboss.tools.common.ui.wizard
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/AbstractPreferenceValue.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/AbstractPreferenceValue.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/AbstractPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.preferencevalue;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * @author Andre Dietisheim
+ */
+public abstract class AbstractPreferenceValue<TYPE> {
+
+ private String pluginId;
+ private String prefsKey;
+
+ public AbstractPreferenceValue(String prefsKey, String pluginId) {
+ this.pluginId = pluginId;
+ this.prefsKey = prefsKey;
+ }
+
+ public abstract TYPE get();
+
+ protected String doGet() {
+ return doGet(null);
+ }
+
+ public abstract TYPE get(TYPE currentValue);
+
+ protected String doGet(String currentValue) {
+ if( currentValue == null || currentValue.equals("")) {
+ // pre-set with previously used
+ Preferences prefs = getPreferences(this.pluginId);
+ return prefs.get(prefsKey, "");
+ } else {
+ return currentValue;
+ }
+ }
+
+ public void remove() {
+ String prefsValue = doGet();
+ if (prefsValue == null
+ || prefsValue == null) {
+ return;
+ }
+ store(null);
+ }
+
+ public abstract void store(TYPE value);
+
+ protected void doStore(String value) {
+ Preferences prefs = getPreferences(this.pluginId);
+ String prefsValue = prefs.get(prefsKey, "");
+ if (prefsValue == null
+ || prefsValue.equals("")
+ || !prefsValue.equals(value)) {
+ prefs.put(prefsKey, value);
+ try {
+ prefs.flush();
+ } catch (BackingStoreException bse) {
+ // intentionally ignore, non-critical
+ }
+ }
+ }
+
+ protected Preferences getPreferences(String pluginId) {
+ return InstanceScope.INSTANCE.getNode(pluginId);
+ }
+}
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringPreferenceValue.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringPreferenceValue.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.preferencevalue;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class StringPreferenceValue extends AbstractPreferenceValue<String> {
+
+ public StringPreferenceValue(String prefsKey, String pluginId) {
+ super(prefsKey, pluginId);
+ }
+
+ public String get() {
+ return get(null);
+ }
+
+ public String get(String currentValue) {
+ return doGet(currentValue);
+ }
+
+ public void store(String value) {
+ doStore(value);
+ }
+}
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringsPreferenceValue.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringsPreferenceValue.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/preferencevalue/StringsPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.preferencevalue;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+
+/**
+ * A class that offers access to a collection of values that is stored in the
+ * preferences under a single key.
+ *
+ * @author Andre Dietisheim
+ */
+public class StringsPreferenceValue extends AbstractPreferenceValue<String[]> {
+
+ private String delimiter;
+ private String escapedDelimiter;
+
+ public StringsPreferenceValue(char delimiter, String prefsKey, String pluginId) {
+ super(prefsKey, pluginId);
+ this.delimiter = String.valueOf(delimiter);
+ try {
+ this.escapedDelimiter = URLEncoder.encode(String.valueOf(delimiter),
"UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // cannot happen since we use a fixed, known encoding
+ }
+ }
+
+ public String[] get() {
+ return get(null);
+ }
+
+ public String[] get(String[] currentValues) {
+
+ String string = doGet(null);
+ String[] prefValues = split(string);
+ return overrideValues(currentValues, prefValues);
+ }
+
+ private String[] split(String string) {
+ ArrayList<String> values = new ArrayList<String>();
+ StringTokenizer tokenizer = new StringTokenizer(string, delimiter);
+ while (tokenizer.hasMoreTokens()) {
+ String value = tokenizer.nextToken();
+ String unescapedValue = unescapeDelimiterCharacter(value);
+ values.add(unescapedValue);
+ }
+ return values.toArray(new String[values.size()]);
+ }
+
+ private String[] overrideValues(String[] newValues, String[] prefValues) {
+ if (prefValues == null) {
+ return newValues;
+ }
+
+ for (int i = 0; i < prefValues.length; i++) {
+ if (newValues == null
+ || newValues.length < i) {
+ break;
+ }
+ prefValues[i] = newValues[i];
+ }
+ return prefValues;
+ }
+
+ /**
+ * Adds the given string value to this preference value(s). Duplicate values
+ * are not added.
+ *
+ * @param value
+ * the value to add
+ */
+ public void add(String value) {
+ String currentValues = doGet();
+ StringBuilder builder = new StringBuilder(currentValues);
+ value = escapeDelimiterCharacter(value);
+ if (!contains(value, currentValues)) {
+ if (hasValues(currentValues)) {
+ builder.append(delimiter);
+ }
+ builder.append(value);
+ doStore(builder.toString());
+ }
+ }
+
+ private String escapeDelimiterCharacter(String value) {
+ if (value == null || value.length() == 0) {
+ return value;
+ }
+
+ int index = value.indexOf(delimiter);
+ if (index < 0) {
+ return value;
+ }
+ StringBuilder builder = new StringBuilder(value.substring(0, index));
+ builder.append(escapedDelimiter);
+ builder.append(value.substring(index + 1));
+ return builder.toString();
+ }
+
+ private String unescapeDelimiterCharacter(String value) {
+ if (value == null || value.length() == 0) {
+ return value;
+ }
+
+ int index = value.indexOf(escapedDelimiter);
+ if (index < 0) {
+ return value;
+ }
+ StringBuilder builder = new StringBuilder(value.substring(0, index));
+ builder.append(delimiter);
+ builder.append(value.substring(index + 1));
+ return builder.toString();
+ }
+
+ private boolean contains(String value, String currentValues) {
+ return currentValues != null
+ && currentValues.length() > 0
+ && currentValues.indexOf(value) >= 0;
+ }
+
+ private boolean hasValues(String currentValues) {
+ return currentValues != null && currentValues.length() > 0;
+ }
+
+ /**
+ * Removes the given values from the strings stored in the preferences and
+ * stores the preferences.
+ *
+ * @param values
+ * the values
+ */
+ public void remove(String... valuesToRemove) {
+ boolean removed = false;
+ String[] currentValues = get();
+ if (valuesToRemove != null) {
+ for (int i = 0; i < currentValues.length; i++) {
+ for (String valueToRemove : valuesToRemove) {
+ if (valueToRemove.equals(currentValues[i])) {
+ currentValues[i] = null;
+ removed = true;
+ }
+ }
+ }
+ }
+ if (removed) {
+ store(currentValues);
+ }
+ }
+
+ /**
+ * Overrides the current values in the preferences with the values in the
+ * given array (value in the preferences at index x is overridden with the
+ * value in the given array at index x) and stores the preferences.
+ */
+ public void store(String[] newValues) {
+ String[] currentValues = get();
+ overrideValues(newValues, currentValues);
+ doStore(concatenate(currentValues));
+ }
+
+ public void store() {
+ store(null);
+ }
+
+ protected String concatenate(String[] values) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < values.length; i++) {
+ if (values[i] != null) {
+ if (builder.length() > 0) {
+ builder.append(delimiter);
+ }
+ builder.append(values[i]);
+ }
+ }
+ return builder.toString();
+ }
+}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/META-INF/MANIFEST.MF
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/META-INF/MANIFEST.MF 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/META-INF/MANIFEST.MF 2011-10-03
09:49:53 UTC (rev 35270)
@@ -29,3 +29,4 @@
org.eclipse.wst.server.ui;bundle-version="1.1.305",
org.eclipse.jsch.core;bundle-version="1.1.300",
com.jcraft.jsch;bundle-version="0.1.41"
+Import-Package: org.jboss.tools.common.ui.preferencevalue
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -37,9 +37,9 @@
import org.eclipse.wst.server.ui.ServerUIUtil;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.tools.common.jobs.ChainedJob;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.integration.DeltaCloudIntegrationPlugin;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
import org.jboss.tools.deltacloud.ui.wizard.INewInstanceWizardPage;
import org.jboss.tools.internal.deltacloud.ui.utils.LayoutUtils;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2011-10-03
09:42:59 UTC (rev 35269)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2011-10-03
09:49:53 UTC (rev 35270)
@@ -30,4 +30,5 @@
org.jboss.tools.deltacloud.ui.wizard,
org.jboss.tools.internal.deltacloud.ui.utils;x-friends:="org.jboss.tools.deltacloud.test,org.jboss.tools.deltacloud.integration"
Import-Package: org.jboss.tools.common.ui,
- org.jboss.tools.common.ui.databinding
+ org.jboss.tools.common.ui.databinding,
+ org.jboss.tools.common.ui.preferencevalue
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/AbstractPreferenceValue.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/AbstractPreferenceValue.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/AbstractPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.deltacloud.ui.preferences;
-
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.osgi.service.prefs.BackingStoreException;
-import org.osgi.service.prefs.Preferences;
-
-/**
- * @author Andre Dietisheim
- */
-public abstract class AbstractPreferenceValue<TYPE> {
-
- private String pluginId;
- private String prefsKey;
-
- public AbstractPreferenceValue(String prefsKey, String pluginId) {
- this.pluginId = pluginId;
- this.prefsKey = prefsKey;
- }
-
- public abstract TYPE get();
-
- protected String doGet() {
- return doGet(null);
- }
-
- public abstract TYPE get(TYPE currentValue);
-
- protected String doGet(String currentValue) {
- if( currentValue == null || currentValue.equals("")) {
- // pre-set with previously used
- Preferences prefs = getPreferences(this.pluginId);
- return prefs.get(prefsKey, "");
- } else {
- return currentValue;
- }
- }
-
- public void remove() {
- String prefsValue = doGet();
- if (prefsValue == null
- || prefsValue == null) {
- return;
- }
- store(null);
- }
-
- public abstract void store(TYPE value);
-
- protected void doStore(String value) {
- Preferences prefs = getPreferences(this.pluginId);
- String prefsValue = prefs.get(prefsKey, "");
- if (prefsValue == null
- || prefsValue.equals("")
- || !prefsValue.equals(value)) {
- prefs.put(prefsKey, value);
- try {
- prefs.flush();
- } catch (BackingStoreException bse) {
- // intentionally ignore, non-critical
- }
- }
- }
-
- protected Preferences getPreferences(String pluginId) {
- return new InstanceScope().getNode(pluginId);
- }
-}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringPreferenceValue.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringPreferenceValue.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.deltacloud.ui.preferences;
-
-
-
-/**
- * @author Andre Dietisheim
- */
-public class StringPreferenceValue extends AbstractPreferenceValue<String> {
-
- public StringPreferenceValue(String prefsKey, String pluginId) {
- super(prefsKey, pluginId);
- }
-
- public String get() {
- return get(null);
- }
-
- public String get(String currentValue) {
- return doGet(currentValue);
- }
-
- public void store(String value) {
- doStore(value);
- }
-}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringsPreferenceValue.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringsPreferenceValue.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/preferences/StringsPreferenceValue.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -1,189 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.deltacloud.ui.preferences;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-
-
-/**
- * A class that offers access to a collection of values that is stored in the
- * preferences under a single key.
- *
- * @author Andre Dietisheim
- */
-public class StringsPreferenceValue extends AbstractPreferenceValue<String[]> {
-
- private String delimiter;
- private String escapedDelimiter;
-
- public StringsPreferenceValue(char delimiter, String prefsKey, String pluginId) {
- super(prefsKey, pluginId);
- this.delimiter = String.valueOf(delimiter);
- try {
- this.escapedDelimiter = URLEncoder.encode(String.valueOf(delimiter),
"UTF-8");
- } catch (UnsupportedEncodingException e) {
- // cannot happen since we use a fixed, known encoding
- }
- }
-
- public String[] get() {
- return get(null);
- }
-
- public String[] get(String[] currentValues) {
-
- String string = doGet(null);
- String[] prefValues = split(string);
- return overrideValues(currentValues, prefValues);
- }
-
- private String[] split(String string) {
- ArrayList<String> values = new ArrayList<String>();
- StringTokenizer tokenizer = new StringTokenizer(string, delimiter);
- while (tokenizer.hasMoreTokens()) {
- String value = tokenizer.nextToken();
- String unescapedValue = unescapeDelimiterCharacter(value);
- values.add(unescapedValue);
- }
- return values.toArray(new String[values.size()]);
- }
-
- private String[] overrideValues(String[] newValues, String[] prefValues) {
- if (prefValues == null) {
- return newValues;
- }
-
- for (int i = 0; i < prefValues.length; i++) {
- if (newValues == null
- || newValues.length < i) {
- break;
- }
- prefValues[i] = newValues[i];
- }
- return prefValues;
- }
-
- /**
- * Adds the given string value to this preference value(s). Duplicate values
- * are not added.
- *
- * @param value
- * the value to add
- */
- public void add(String value) {
- String currentValues = doGet();
- StringBuilder builder = new StringBuilder(currentValues);
- value = escapeDelimiterCharacter(value);
- if (!contains(value, currentValues)) {
- if (hasValues(currentValues)) {
- builder.append(delimiter);
- }
- builder.append(value);
- doStore(builder.toString());
- }
- }
-
- private String escapeDelimiterCharacter(String value) {
- if (value == null || value.length() == 0) {
- return value;
- }
-
- int index = value.indexOf(delimiter);
- if (index < 0) {
- return value;
- }
- StringBuilder builder = new StringBuilder(value.substring(0, index));
- builder.append(escapedDelimiter);
- builder.append(value.substring(index + 1));
- return builder.toString();
- }
-
- private String unescapeDelimiterCharacter(String value) {
- if (value == null || value.length() == 0) {
- return value;
- }
-
- int index = value.indexOf(escapedDelimiter);
- if (index < 0) {
- return value;
- }
- StringBuilder builder = new StringBuilder(value.substring(0, index));
- builder.append(delimiter);
- builder.append(value.substring(index + 1));
- return builder.toString();
- }
-
- private boolean contains(String value, String currentValues) {
- return currentValues != null
- && currentValues.length() > 0
- && currentValues.indexOf(value) >= 0;
- }
-
- private boolean hasValues(String currentValues) {
- return currentValues != null && currentValues.length() > 0;
- }
-
- /**
- * Removes the given values from the strings stored in the preferences and
- * stores the preferences.
- *
- * @param values
- * the values
- */
- public void remove(String... valuesToRemove) {
- boolean removed = false;
- String[] currentValues = get();
- if (valuesToRemove != null) {
- for (int i = 0; i < currentValues.length; i++) {
- for (String valueToRemove : valuesToRemove) {
- if (valueToRemove.equals(currentValues[i])) {
- currentValues[i] = null;
- removed = true;
- }
- }
- }
- }
- if (removed) {
- store(currentValues);
- }
- }
-
- /**
- * Overrides the current values in the preferences with the values in the
- * given array (value in the preferences at index x is overridden with the
- * value in the given array at index x) and stores the preferences.
- */
- public void store(String[] newValues) {
- String[] currentValues = get();
- overrideValues(newValues, currentValues);
- doStore(concatenate(currentValues));
- }
-
- public void store() {
- store(null);
- }
-
- protected String concatenate(String[] values) {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < values.length; i++) {
- if (values[i] != null) {
- if (builder.length() > 0) {
- builder.append(delimiter);
- }
- builder.append(values[i]);
- }
- }
- return builder.toString();
- }
-}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -44,6 +44,7 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
@@ -53,7 +54,6 @@
import org.jboss.tools.deltacloud.core.IInstanceFilter;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.ErrorUtils;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.deltacloud.ui.views.Columns;
import org.jboss.tools.deltacloud.ui.views.Columns.Column;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/UIUtils.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -26,8 +26,8 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.ui.preferencevalue.StringsPreferenceValue;
import org.jboss.tools.deltacloud.ui.Activator;
-import org.jboss.tools.deltacloud.ui.preferences.StringsPreferenceValue;
import org.osgi.service.prefs.Preferences;
/**
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -57,6 +57,7 @@
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.LogHelper;
import org.jboss.tools.common.ui.databinding.MandatoryStringValidator;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudDriver;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
@@ -64,7 +65,6 @@
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.CompositeValidator;
import org.jboss.tools.internal.deltacloud.ui.common.swt.JFaceUtils;
import org.jboss.tools.internal.deltacloud.ui.utils.ControlDecorationAdapter;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnectionWizard.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -17,12 +17,12 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudDriver;
import org.jboss.tools.deltacloud.core.job.AbstractCloudJob;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
/**
* @author Jeff Johnston
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -20,6 +20,7 @@
import org.eclipse.ui.IWorkbench;
import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudDriver;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
@@ -27,7 +28,6 @@
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.ErrorUtils;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
/**
* @author Jeff Johnston
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/SshPrivateKeysPreferences.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/SshPrivateKeysPreferences.java 2011-10-03
09:42:59 UTC (rev 35269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/SshPrivateKeysPreferences.java 2011-10-03
09:49:53 UTC (rev 35270)
@@ -15,9 +15,9 @@
import org.apache.deltacloud.client.utils.StringUtils;
import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
+import org.jboss.tools.common.ui.preferencevalue.StringsPreferenceValue;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
-import org.jboss.tools.deltacloud.ui.preferences.StringPreferenceValue;
-import org.jboss.tools.deltacloud.ui.preferences.StringsPreferenceValue;
/**
* @author André Dietisheim