Author: adietish
Date: 2011-10-17 03:38:58 -0400 (Mon, 17 Oct 2011)
New Revision: 35697
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
Removed:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardModel.java
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainDialog.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
Log:
[JBIDE-9793] cleaning up implementation (moved methods to model)
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
(rev 0)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java 2011-10-17
07:38:58 UTC (rev 35697)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.common;
+
+import java.io.File;
+
+/**
+ * @author André Dietisheim
+ */
+public class FileUtils {
+
+ public static boolean canRead(String path) {
+ if (path == null) {
+ return false;
+ }
+ return canRead(new File(path));
+ }
+
+ public static boolean canRead(File file) {
+ if (file == null) {
+ return false;
+ }
+ return file.canRead();
+ }
+
+
+}
Property changes on:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainDialog.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainDialog.java 2011-10-17
07:16:45 UTC (rev 35696)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainDialog.java 2011-10-17
07:38:58 UTC (rev 35697)
@@ -27,11 +27,11 @@
public class NewDomainDialog extends Wizard {
private String namespace;
- private NewDomainWizardModel model;
+ private NewDomainWizardPageModel model;
public NewDomainDialog(String namespace, ImportProjectWizardModel wizardModel) {
this.namespace = namespace;
- this.model = new NewDomainWizardModel(namespace, wizardModel.getUser());
+ this.model = new NewDomainWizardPageModel(namespace, wizardModel.getUser());
setNeedsProgressMonitor(true);
}
Deleted:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardModel.java 2011-10-17
07:16:45 UTC (rev 35696)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardModel.java 2011-10-17
07:38:58 UTC (rev 35697)
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.openshift.express.internal.ui.wizard;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
-import org.jboss.tools.openshift.express.client.IDomain;
-import org.jboss.tools.openshift.express.client.ISSHPublicKey;
-import org.jboss.tools.openshift.express.client.IUser;
-import org.jboss.tools.openshift.express.client.OpenshiftException;
-import org.jboss.tools.openshift.express.client.SSHPublicKey;
-
-/**
- * @author André Dietisheim
- */
-public class NewDomainWizardModel extends ObservableUIPojo {
-
- public static final String PROPERTY_NAMESPACE = "namespace";
- public static final String PROPERTY_SSHKEY = "sshKey";
- public static final String PROPERTY_DOMAIN = "domain";
-
- private String namespace;
- private IDomain domain;
- private String sshKey;
- private IUser user;
-
- public NewDomainWizardModel(String namespace, IUser user) {
- this.namespace = namespace;
- this.user = user;
- }
-
- public String getNamespace() {
- return this.namespace;
- }
-
- public void createDomain() throws OpenshiftException, IOException {
- IDomain domain = user.createDomain(namespace, loadSshKey());
- setDomain(domain);
- }
-
- public String getSshKey() {
- return sshKey;
- }
-
- public void setSshKey(String sshKey) {
- firePropertyChange(PROPERTY_SSHKEY, this.sshKey, this.sshKey = sshKey);
- }
-
- private ISSHPublicKey loadSshKey() throws IOException, OpenshiftException {
- return new SSHPublicKey(new File(sshKey));
- }
-
- public void setNamespace(String namespace) {
- firePropertyChange(PROPERTY_NAMESPACE, this.namespace, this.namespace = namespace);
- }
-
- public boolean hasDomain() {
- return domain != null;
- }
-
- public IDomain getDomain() {
- return domain;
- }
-
- public void setDomain(IDomain domain) {
- firePropertyChange(PROPERTY_DOMAIN, this.domain, this.domain = domain);
- if (domain != null) {
- setNamespace(domain.getNamespace());
- }
- }
-}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2011-10-17
07:16:45 UTC (rev 35696)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2011-10-17
07:38:58 UTC (rev 35697)
@@ -47,8 +47,8 @@
import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
import org.jboss.tools.openshift.express.client.OpenshiftException;
-import org.jboss.tools.openshift.express.client.SSHKeyPair;
import org.jboss.tools.openshift.express.internal.ui.OpenshiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.common.FileUtils;
import org.jboss.tools.openshift.express.internal.ui.common.StringUtils;
/**
@@ -56,14 +56,12 @@
*/
public class NewDomainWizardPage extends AbstractOpenshiftWizardPage {
- private static final String OPENSHIFT_KEY_PREFIX = "openshift_id_rsa_";
- private static final String PUBLIC_KEY_SUFFIX = ".pub";
private static final String FILTEREXPRESSION_PUBLIC_SSH_KEY = "*.pub";
private static final String FILTERNAME_PUBLIC_SSH_KEY = "Public ssh key file
(*.pub)";
- private NewDomainWizardModel model;
+ private NewDomainWizardPageModel model;
- public NewDomainWizardPage(String namespace, NewDomainWizardModel model, IWizard wizard)
{
+ public NewDomainWizardPage(String namespace, NewDomainWizardPageModel model, IWizard
wizard) {
super("Domain", "Create a new domain", "New Domain",
wizard);
this.model = model;
}
@@ -79,7 +77,7 @@
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(namespaceText);
DataBindingUtils.bindMandatoryTextField(
- namespaceText, "Domain name", NewDomainWizardModel.PROPERTY_NAMESPACE,
model, dbc);
+ namespaceText, "Domain name", NewDomainWizardPageModel.PROPERTY_NAMESPACE,
model, dbc);
Label sshKeyLabel = new Label(container, SWT.NONE);
sshKeyLabel.setText("SSH Public Key");
@@ -90,7 +88,7 @@
.align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sshKeyText);
Binding sshKeyTextBinding = dbc.bindValue(
WidgetProperties.text(SWT.Modify).observe(sshKeyText),
- BeanProperties.value(NewDomainWizardModel.PROPERTY_SSHKEY).observe(model),
+ BeanProperties.value(NewDomainWizardPageModel.PROPERTY_SSHKEY).observe(model),
new UpdateValueStrategy().setAfterGetValidator(new MandatoryStringValidator(
"You have to select a ssh public key")),
new UpdateValueStrategy().setAfterGetValidator(new SSHKeyValidator()));
@@ -128,10 +126,7 @@
if (Dialog.OK == dialog.open()) {
try {
String passPhrase = dialog.getValue();
- String sshKeysDirectory = SshPrivateKeysPreferences.getSshKeyDirectory();
- SSHKeyPair keyPair = createSshKeyPair(passPhrase, sshKeysDirectory);
- SshPrivateKeysPreferences.add(keyPair.getPrivateKeyPath());
- model.setSshKey(keyPair.getPublicKeyPath());
+ model.createSShKeyPair(passPhrase);
} catch (FileNotFoundException ex) {
IStatus status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
"Could not read the ssh key folder", ex);
@@ -152,26 +147,6 @@
};
}
- private SSHKeyPair createSshKeyPair(String passPhrase, String sshKeysDirectory) throws
OpenshiftException {
- String privateKeyPath = getKeyPairFileName(sshKeysDirectory);
- String publicKeyPath = getPublicKeyPath(privateKeyPath);
- return SSHKeyPair.create(passPhrase, privateKeyPath, publicKeyPath);
- }
-
- private String getKeyPairFileName(String sshKeysDirectory) {
- int i = 0;
- File privateKey = null;
- while (isReadable(privateKey = new File(sshKeysDirectory, OPENSHIFT_KEY_PREFIX + i))
- || isReadable(new File(sshKeysDirectory, getPublicKeyPath(privateKey.getName())))) {
- i++;
- }
- return privateKey.getAbsolutePath();
- }
-
- private String getPublicKeyPath(String privateKeyPath) {
- return privateKeyPath + PUBLIC_KEY_SUFFIX;
- }
-
private SelectionListener onBrowse() {
return new SelectionAdapter() {
@@ -217,7 +192,7 @@
public IStatus validate(Object value) {
if (!(value instanceof String)
|| StringUtils.isEmpty((String) value)
- || !isReadable((String) value)) {
+ || !FileUtils.canRead((String) value)) {
return ValidationStatus.error("You have to provide a valid ssh public
key");
}
if (!isKeyKnownToSsh((String) value)) {
@@ -236,7 +211,7 @@
try {
File privateKey = SshPrivateKeysPreferences.getKeyFile(preferencesKey);
if (privateKey == null
- || !isReadable(privateKey)) {
+ || !FileUtils.canRead(privateKey)) {
continue;
}
if (publicKeyPath.startsWith(privateKey.getAbsolutePath() + ".")) {
@@ -250,18 +225,4 @@
}
}
- private boolean isReadable(String path) {
- if (path == null) {
- return false;
- }
- return isReadable(new File(path));
- }
-
- private boolean isReadable(File file) {
- if (file == null) {
- return false;
- }
- return file.exists()
- && file.canRead();
- }
}
Copied:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
(from rev 35692,
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardModel.java)
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
(rev 0)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2011-10-17
07:38:58 UTC (rev 35697)
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.wizard;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
+import org.jboss.tools.openshift.express.client.IDomain;
+import org.jboss.tools.openshift.express.client.ISSHPublicKey;
+import org.jboss.tools.openshift.express.client.IUser;
+import org.jboss.tools.openshift.express.client.OpenshiftException;
+import org.jboss.tools.openshift.express.client.SSHKeyPair;
+import org.jboss.tools.openshift.express.client.SSHPublicKey;
+import org.jboss.tools.openshift.express.internal.ui.common.FileUtils;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewDomainWizardPageModel extends ObservableUIPojo {
+
+ private static final String OPENSHIFT_KEY_PREFIX = "openshift_id_rsa_";
+ private static final String PUBLIC_KEY_SUFFIX = ".pub";
+
+ public static final String PROPERTY_NAMESPACE = "namespace";
+ public static final String PROPERTY_SSHKEY = "sshKey";
+ public static final String PROPERTY_DOMAIN = "domain";
+
+ private String namespace;
+ private IDomain domain;
+ private String sshKey;
+ private IUser user;
+
+ public NewDomainWizardPageModel(String namespace, IUser user) {
+ this.namespace = namespace;
+ this.user = user;
+ }
+
+ public String getNamespace() {
+ return this.namespace;
+ }
+
+ public void createDomain() throws OpenshiftException, IOException {
+ IDomain domain = user.createDomain(namespace, loadSshKey());
+ setDomain(domain);
+ }
+
+ public String getSshKey() {
+ return sshKey;
+ }
+
+ public void createSShKeyPair(String passPhrase) throws FileNotFoundException,
OpenshiftException {
+ String sshKeysDirectory = SshPrivateKeysPreferences.getSshKeyDirectory();
+ SSHKeyPair keyPair = createSshKeyPair(passPhrase, sshKeysDirectory);
+ SshPrivateKeysPreferences.add(keyPair.getPrivateKeyPath());
+ setSshKey(keyPair.getPublicKeyPath());
+ }
+
+ private SSHKeyPair createSshKeyPair(String passPhrase, String sshKeysDirectory) throws
OpenshiftException {
+ String privateKeyPath = getKeyPairFileName(sshKeysDirectory);
+ String publicKeyPath = getPublicKeyPath(privateKeyPath);
+ return SSHKeyPair.create(passPhrase, privateKeyPath, publicKeyPath);
+ }
+
+ private String getKeyPairFileName(String sshKeysDirectory) {
+ int i = 0;
+ File privateKey = null;
+ while (FileUtils.canRead(privateKey = new File(sshKeysDirectory, OPENSHIFT_KEY_PREFIX +
i))
+ || FileUtils.canRead(new File(sshKeysDirectory,
getPublicKeyPath(privateKey.getName())))) {
+ i++;
+ }
+ return privateKey.getAbsolutePath();
+ }
+
+ private String getPublicKeyPath(String privateKeyPath) {
+ return privateKeyPath + PUBLIC_KEY_SUFFIX;
+ }
+
+ public void setSshKey(String sshKey) {
+ firePropertyChange(PROPERTY_SSHKEY, this.sshKey, this.sshKey = sshKey);
+ }
+
+ private ISSHPublicKey loadSshKey() throws IOException, OpenshiftException {
+ return new SSHPublicKey(new File(sshKey));
+ }
+
+ public void setNamespace(String namespace) {
+ firePropertyChange(PROPERTY_NAMESPACE, this.namespace, this.namespace = namespace);
+ }
+
+ public boolean hasDomain() {
+ return domain != null;
+ }
+
+ public IDomain getDomain() {
+ return domain;
+ }
+
+ public void setDomain(IDomain domain) {
+ firePropertyChange(PROPERTY_DOMAIN, this.domain, this.domain = domain);
+ if (domain != null) {
+ setNamespace(domain.getNamespace());
+ }
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain