[jbosstools-commits] JBoss Tools SVN: r43792 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard/ssh and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Sep 18 07:56:10 EDT 2012
Author: adietish
Date: 2012-09-18 07:56:10 -0400 (Tue, 18 Sep 2012)
New Revision: 43792
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/JobScheduler.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java
Log:
[JBIDE-11912] implemented key removal
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/JobScheduler.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/JobScheduler.java 2012-09-18 10:20:16 UTC (rev 43791)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/JobScheduler.java 2012-09-18 11:56:10 UTC (rev 43792)
@@ -25,21 +25,29 @@
this.job = job;
}
- public class ChainedJob {
+ public JobConstraint runWhenDone(Job constrainedJob) {
+ return new JobConstraint(job).runWhenDone(constrainedJob);
+ }
+
+ public class JobConstraint {
private Job job;
- private ChainedJob(Job job) {
+ private JobConstraint(Job job) {
this.job = job;
}
- public ChainedJob andWhenDone(final Job constrainedJob) {
+ public JobConstraint runWhenDone(final Job constrainedJob) {
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
constrainedJob.schedule();
}});
- return new ChainedJob(constrainedJob);
+ return new JobConstraint(constrainedJob);
}
+
+ public void schedule() {
+ JobScheduler.this.job.schedule();
+ }
}
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-09-18 10:20:16 UTC (rev 43791)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-09-18 11:56:10 UTC (rev 43792)
@@ -91,9 +91,10 @@
if (text.length() < maxLength) {
return text;
}
-
- return new StringBuilder(text.substring(0, maxLength - SHORTENING_MARKER.length()))
+ int availableCharacters = maxLength - SHORTENING_MARKER.length();
+ return new StringBuilder(text.substring(0, availableCharacters / 2))
.append(SHORTENING_MARKER)
+ .append(text.substring(text.length() - availableCharacters / 2, text.length()))
.toString();
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-18 10:20:16 UTC (rev 43791)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-18 11:56:10 UTC (rev 43792)
@@ -10,14 +10,18 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard.ssh;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -31,14 +35,16 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.statushandlers.StatusManager;
import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.JobScheduler;
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder;
import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder.IColumnLabelProvider;
-import org.jboss.tools.openshift.express.internal.ui.utils.UIUpdatingJob;
import org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage;
import com.openshift.client.IOpenShiftSSHKey;
@@ -72,13 +78,16 @@
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
.span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
+ ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer))
+ .to(BeanProperties.value(ManageSSHKeysWizardPageModel.PROPERTY_SELECTED_KEY).observe(pageModel))
+ .in(dbc);
Button addButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(addButton);
addButton.setText("Add Existing...");
addButton.addSelectionListener(onAdd());
-
+
Button newButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(newButton);
@@ -88,6 +97,7 @@
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(removeButton);
removeButton.setText("Remove...");
+ removeButton.addSelectionListener(onRemove());
Composite filler = new Composite(sshKeysGroup, SWT.None);
GridDataFactory.fillDefaults()
@@ -100,6 +110,30 @@
refreshButton.addSelectionListener(onRefresh());
}
+ private SelectionListener onRemove() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String keyName = pageModel.getSelectedSSHKey().getName();
+ if (MessageDialog.openConfirm(getShell(),
+ "Remove SSH Key",
+ MessageFormat.format(
+ "Are you sure that you want to remove public SSH key {0} from OpenShift?",
+ keyName)))
+ try {
+ RemoveKeyJob removeSSHKeyJob = new RemoveKeyJob();
+ new JobScheduler(removeSSHKeyJob).runWhenDone(new RefreshViewerJob());
+ setViewerInput(pageModel.getSSHKeys());
+ WizardUtils.runInWizard(removeSSHKeyJob, getContainer()) ;
+ } catch (Exception ex) {
+ StatusManager.getManager().handle(
+ OpenShiftUIActivator.createErrorStatus("Could not remove key " + keyName + ".", ex), StatusManager.LOG);
+ }
+ }
+ };
+ }
+
private SelectionListener onAdd() {
return new SelectionAdapter() {
@@ -149,23 +183,12 @@
@Override
protected void onPageActivated(DataBindingContext dbc) {
try {
- WizardUtils.runInWizard(new Job("Loading ssh keys...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- setViewerInput(pageModel.loadSSHKeys());
- pageModel.loadSSHKeys();
- return Status.OK_STATUS;
- } catch (Exception e) {
- clearViewer();
- return OpenShiftUIActivator.createErrorStatus("Could not load ssh keys.", e);
- }
- }
-
- }, getContainer(), getDataBindingContext());
+ Job loadKeysJob = new LoadKeysJob();
+ new JobScheduler(loadKeysJob).runWhenDone(new RefreshViewerJob());
+ WizardUtils.runInWizard(loadKeysJob, getContainer());
} catch (Exception e) {
- // ignore
+ StatusManager.getManager().handle(
+ OpenShiftUIActivator.createErrorStatus("Could not load ssh keys.", e), StatusManager.LOG);
}
}
@@ -175,15 +198,9 @@
@Override
public void widgetSelected(SelectionEvent e) {
try {
- WizardUtils.runInWizard(new UIUpdatingJob("Refreshing keys...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- pageModel.getUser().refresh();
- setViewerInput(pageModel.getUser().getSSHKeys());
- return Status.OK_STATUS;
- }
- }, getContainer());
+ Job refreshKeysJob = new RefreshKeysJob();
+ new JobScheduler(refreshKeysJob).runWhenDone(new RefreshViewerJob());
+ WizardUtils.runInWizard(refreshKeysJob, getContainer());
} catch (Exception ex) {
StatusManager.getManager().handle(
OpenShiftUIActivator.createErrorStatus("Could not refresh keys.", ex), StatusManager.LOG);
@@ -206,4 +223,58 @@
}
});
}
-}
\ No newline at end of file
+
+ private class RemoveKeyJob extends Job {
+
+ private RemoveKeyJob() {
+ super("Removing SSH key " + pageModel.getSelectedSSHKey().getName() + "...");
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ pageModel.removeKey();
+ return Status.OK_STATUS;
+ }
+ }
+
+ private class RefreshKeysJob extends Job {
+
+ private RefreshKeysJob() {
+ super("Refreshing SSH keys... ");
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ pageModel.refresh();
+ return Status.OK_STATUS;
+ }
+ }
+
+ private class LoadKeysJob extends Job {
+
+ private LoadKeysJob() {
+ super("Loading SSH keys... ");
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ pageModel.loadSSHKeys();
+ return Status.OK_STATUS;
+ }
+ }
+
+ private class RefreshViewerJob extends UIJob {
+
+ public RefreshViewerJob() {
+ super("Refreshing ssh keys...");
+ }
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ viewer.setInput(pageModel.getSSHKeys());
+ return Status.OK_STATUS;
+ }
+ }
+
+}
+
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java 2012-09-18 10:20:16 UTC (rev 43791)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPageModel.java 2012-09-18 11:56:10 UTC (rev 43792)
@@ -24,9 +24,11 @@
public class ManageSSHKeysWizardPageModel extends ObservableUIPojo {
public static final String PROPERTY_SSH_KEYS = "SSHKeys";
+ public static final String PROPERTY_SELECTED_KEY = "selectedSSHKey";
private UserDelegate user;
private List<IOpenShiftSSHKey> keys = new ArrayList<IOpenShiftSSHKey>();
+ private IOpenShiftSSHKey selectedKey;
public ManageSSHKeysWizardPageModel(UserDelegate user) {
this.user = user;
@@ -45,8 +47,30 @@
return this.keys;
}
+ public IOpenShiftSSHKey getSelectedSSHKey() {
+ return selectedKey;
+ }
+
+ public void setSelectedSSHKey(IOpenShiftSSHKey key) {
+ firePropertyChange(PROPERTY_SELECTED_KEY, this.selectedKey, this.selectedKey = key);
+ }
+
+ public void removeKey() {
+ if (selectedKey == null) {
+ return;
+ }
+ selectedKey.destroy();
+ setSSHKeys(user.getSSHKeys());
+ }
+
+ public void refresh() {
+ user.refresh();
+ setSSHKeys(user.getSSHKeys());
+ }
+
public UserDelegate getUser() {
return user;
}
+
}
More information about the jbosstools-commits
mailing list