Author: adietish
Date: 2010-12-02 13:15:55 -0500 (Thu, 02 Dec 2010)
New Revision: 27121
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/IPreferenceKeys.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
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/NewCloudConnectionWizard.java
Log:
cleanup
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/IPreferenceKeys.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/IPreferenceKeys.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/IPreferenceKeys.java 2010-12-02
18:15:55 UTC (rev 27121)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * 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.internal.deltacloud.ui.preferences;
+
+public class IPreferenceKeys {
+
+ public static final String LAST_URL =
"org.jboss.tools.internal.deltacloud.ui.wizards.LAST_CREATED_URL";
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/IPreferenceKeys.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java 2010-12-02
18:15:55 UTC (rev 27121)
@@ -0,0 +1,45 @@
+package org.jboss.tools.internal.deltacloud.ui.preferences;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+public class TextPreferenceValue {
+
+ private Plugin plugin;
+ private String prefsKey;
+
+ public TextPreferenceValue(String prefsKey, Plugin plugin) {
+ this.plugin = plugin;
+ this.prefsKey = prefsKey;
+ }
+
+ public String get(String currentValue) {
+ if( currentValue == null || currentValue.equals("")) {
+ // pre-set with previously used
+ Preferences prefs = getPreferences();
+ return prefs.get(prefsKey, "");
+ } else {
+ return currentValue;
+ }
+ }
+
+ public void store(String value) {
+ Preferences prefs = getPreferences();
+ 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
+ }
+ }
+
+ }
+
+ private Preferences getPreferences() {
+ return new InstanceScope().getNode(plugin.getBundle().getSymbolicName());
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2010-12-02
18:14:15 UTC (rev 27120)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-12-02
18:15:55 UTC (rev 27121)
@@ -27,7 +27,6 @@
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
@@ -63,7 +62,8 @@
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.CompositeValidator;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.MandatoryStringValidator;
import org.jboss.tools.internal.deltacloud.ui.common.swt.JFaceUtils;
-import org.osgi.service.prefs.Preferences;
+import org.jboss.tools.internal.deltacloud.ui.preferences.IPreferenceKeys;
+import org.jboss.tools.internal.deltacloud.ui.preferences.TextPreferenceValue;
/**
* @author Jeff Jonhston
@@ -273,14 +273,14 @@
this.connectionModel = new CloudConnectionModel();
this.cloudConnection = cloudConnection;
}
-
- public CloudConnectionPage(String pageName, DeltaCloud initial, CloudConnection
connection)
- throws MalformedURLException, DeltaCloudException {
+ public CloudConnectionPage(String pageName, DeltaCloud initial, CloudConnection
connection)
+ throws MalformedURLException, DeltaCloudException {
+
this(pageName, initial.getName(), initial.getURL(), initial.getUsername(),
initial.getPassword(), initial.getType(), connection);
}
-
+
public CloudConnectionPage(String pageName, String defaultName, String defaultUrl,
String defaultUsername, String defaultPassword, String defaultType,
CloudConnection cloudConnection) throws MalformedURLException {
@@ -325,6 +325,10 @@
new UpdateValueStrategy().setAfterGetValidator(
new MandatoryStringValidator(WizardMessages.getString(MUST_ENTER_A_URL))), null);
+ String url = new TextPreferenceValue(IPreferenceKeys.LAST_URL, Activator.getDefault())
+ .get(urlText.getText());
+ urlText.setText(url);
+
// cloud type
Label typeLabel = new Label(container, SWT.NULL);
typeLabel.setText(WizardMessages.getString(CLOUDTYPE_LABEL));
@@ -451,12 +455,6 @@
f.top = new FormAttachment(passwordText, 5);
ec2pwLink.setLayoutData(f);
- if( urlText.getText().equals("")) {
- // pre-set with previously used
- Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- String previousURL = prefs.get(NewCloudConnectionWizard.LAST_USED_URL, "");
- urlText.setText(previousURL);
- }
setControl(container);
}
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 2010-12-02
18:14:15 UTC (rev 27120)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2010-12-02
18:15:55 UTC (rev 27121)
@@ -12,7 +12,6 @@
import java.text.MessageFormat;
-import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
@@ -23,13 +22,12 @@
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.ErrorUtils;
-import org.osgi.service.prefs.BackingStoreException;
-import org.osgi.service.prefs.Preferences;
+import org.jboss.tools.internal.deltacloud.ui.preferences.IPreferenceKeys;
+import org.jboss.tools.internal.deltacloud.ui.preferences.TextPreferenceValue;
public class NewCloudConnectionWizard extends Wizard implements INewWizard,
CloudConnection {
private static final String MAINPAGE_NAME = "NewCloudConnection.name";
//$NON-NLS-1$
- public static final String LAST_USED_URL =
"org.jboss.tools.internal.deltacloud.ui.wizards.LAST_CREATED_URL";
protected CloudConnectionPage mainPage;
protected DeltaCloud initialCloud;
private String pageTitle;
@@ -112,7 +110,10 @@
public boolean performFinish() {
String name = mainPage.getModel().getName();
String url = mainPage.getModel().getUrl();
- storeUrl(url);
+
+ new TextPreferenceValue(IPreferenceKeys.LAST_URL, Activator.getDefault())
+ .store(url);
+
String username = mainPage.getModel().getUsername();
String password = mainPage.getModel().getPassword();
String type = getServerType();
@@ -128,18 +129,4 @@
}
return true;
}
-
- private void storeUrl(String url) {
- // save URL in some plugin preference key!
- Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- String previousURL = prefs.get(LAST_USED_URL, "");
- if (previousURL == null || previousURL.equals("") ||
!previousURL.equals(url)) {
- prefs.put(LAST_USED_URL, url);
- try {
- prefs.flush();
- } catch (BackingStoreException bse) {
- // intentionally ignore, non-critical
- }
- }
- }
}