[jbosstools-commits] JBoss Tools SVN: r43654 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui: icons and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Sep 13 10:54:15 EDT 2012


Author: adietish
Date: 2012-09-13 10:54:15 -0400 (Thu, 13 Sep 2012)
New Revision: 43654

Added:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/icons/key-icon.png
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/ManageSSHKeysHandler.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizard.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPageModel.java
Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.properties
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java
Log:
[JBIDE-11912] implementing "Manage SSH Keys" dialog for OpenShift Explorer

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/icons/key-icon.png
===================================================================
(Binary files differ)


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/icons/key-icon.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.properties
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.properties	2012-09-13 14:47:06 UTC (rev 43653)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.properties	2012-09-13 14:54:15 UTC (rev 43654)
@@ -6,3 +6,5 @@
 openshift.express.name=OpenShift Server
 openshift.express.description=A server adapter for use with OpenShift Applications
 openshift.express.runtime.name = OpenShift Server Runtime
+
+openshift.command.managekeys=Manage SSH Keys
\ No newline at end of file

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml	2012-09-13 14:47:06 UTC (rev 43653)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml	2012-09-13 14:54:15 UTC (rev 43654)
@@ -310,7 +310,8 @@
       <viewer
             viewerId="org.jboss.tools.openshift.express.ui.viewer.expressConsoleView">
          <popupMenu
-               allowsPlatformContributions="false">
+               allowsPlatformContributions="true"
+               id="org.jboss.tools.openshift.express.ui.viewer.expressConsoleView.popup">
             <insertionPoint
                   name="group.showIn"
                   separator="true">
@@ -679,4 +680,38 @@
          </view>
       	</perspectiveExtension> 
      </extension>
+     <extension
+           point="org.eclipse.ui.commands">
+        <command
+              id="org.jboss.tools.openshift.express.ui.command.manageKeys"
+              name="%openshift.command.managekeys">
+        </command>
+     </extension>
+     <extension
+           point="org.eclipse.ui.handlers">
+        <handler
+              class="org.jboss.tools.openshift.express.internal.ui.command.ManageSSHKeysHandler"
+              commandId="org.jboss.tools.openshift.express.ui.command.manageKeys">
+              <enabledWhen>
+				<with variable="selection">
+         			<iterate ifEmpty="false" operator="or">
+            			<instanceof
+                       		value="org.jboss.tools.openshift.express.internal.core.console.UserDelegate" />
+                    </iterate>
+                </with>
+              </enabledWhen>
+        </handler>
+     </extension>
+     <extension
+           point="org.eclipse.ui.menus">
+        <menuContribution
+              locationURI="popup:org.jboss.tools.openshift.express.ui.viewer.expressConsoleView.popup?before=group.server">
+          <command
+                commandId="org.jboss.tools.openshift.express.ui.command.manageKeys"
+                icon="icons/key-icon.png"
+                id="org.jboss.tools.openshift.express.ui.command.manageKeys"
+                mnemonic="K">
+          </command>
+        </menuContribution>
+     </extension>
 </plugin>

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java	2012-09-13 14:47:06 UTC (rev 43653)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java	2012-09-13 14:54:15 UTC (rev 43654)
@@ -309,6 +309,10 @@
 		this.connected = connected;
 	}
 
+	public List<IOpenShiftSSHKey> getSSHKeys() {
+		return delegate.getSSHKeys();
+	}
+
 	public IOpenShiftSSHKey getSSHKeyByPublicKey(String publicKey) throws OpenShiftUnknonwSSHKeyTypeException, OpenShiftException {
 		return delegate.getSSHKeyByPublicKey(publicKey);
 	}

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/ManageSSHKeysHandler.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/ManageSSHKeysHandler.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/ManageSSHKeysHandler.java	2012-09-13 14:54:15 UTC (rev 43654)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.command;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ManageSSHKeysWizard;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class ManageSSHKeysHandler extends AbstractHandler {
+
+	/**
+	 * the command has been executed, so extract extract the needed information
+	 * from the application context.
+	 */
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		ISelection selection = HandlerUtil.getCurrentSelection(event);
+		if (selection instanceof IStructuredSelection) {
+			Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+			if (selectedElement instanceof UserDelegate) {
+				UserDelegate user = (UserDelegate) selectedElement;
+				WizardUtils.openWizardDialog(new ManageSSHKeysWizard(user), HandlerUtil.getActiveShell(event));
+			}
+		}
+		return null;
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/command/ManageSSHKeysHandler.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizard.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizard.java	2012-09-13 14:54:15 UTC (rev 43654)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.wizard.Wizard;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+
+/**
+ * @author André Dietisheim
+ */
+public class ManageSSHKeysWizard extends Wizard {
+
+	private UserDelegate user;
+
+	public ManageSSHKeysWizard(UserDelegate user) {
+		this.user = user;
+		setNeedsProgressMonitor(true);
+	}
+
+	@Override
+	public boolean performFinish() {
+		return true;
+	}
+
+	@Override
+	public void addPages() {
+		addPage(new ManageSSHKeysWizardPage(user, this));
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizard.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java	2012-09-13 14:54:15 UTC (rev 43654)
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.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.ViewerSupport;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.IOpenShiftSSHKey;
+
+/**
+ * @author André Dietisheim
+ */
+public class ManageSSHKeysWizardPage extends AbstractOpenShiftWizardPage {
+
+	private ManageSSHKeysWizardPageModel pageModel;
+	private TableViewer viewer;
+
+	public ManageSSHKeysWizardPage(UserDelegate user, IWizard wizard) {
+		super("Manage SSH Keys", "Manage the SSH keys that are available to your OpenShift account",
+				"ManageSSHKeysPage", wizard);
+		this.pageModel = new ManageSSHKeysWizardPageModel(user);
+	}
+
+	@Override
+	protected void doCreateControls(Composite parent, DataBindingContext dbc) {
+		GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
+
+		Group embedGroup = new Group(parent, SWT.NONE);
+		embedGroup.setText("SSH Public Keys");
+		GridDataFactory.fillDefaults()
+				.hint(200, 300).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(embedGroup);
+		GridLayoutFactory.fillDefaults()
+				.numColumns(3).margins(6, 6).applyTo(embedGroup);
+
+		Composite tableContainer = new Composite(embedGroup, SWT.NONE);
+		this.viewer = createTable(tableContainer);
+		GridDataFactory.fillDefaults()
+				.span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
+		ViewerSupport.bind(
+				viewer,
+				BeanProperties.list(ManageSSHKeysWizardPageModel.PROPERTY_SSH_KEYS).observe(pageModel), 
+				BeanProperties.values(new String[]{"name", "keyType", "publicKey"}));
+	}
+
+	protected TableViewer createTable(Composite tableContainer) {
+		Table table =
+				new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
+		table.setLinesVisible(true);
+		TableColumnLayout tableLayout = new TableColumnLayout();
+		tableContainer.setLayout(tableLayout);
+		TableViewer viewer = new TableViewer(table);
+		viewer.setComparer(new EqualityComparer());
+		viewer.setContentProvider(new ArrayContentProvider());
+
+		viewer.setSorter(new ViewerSorter() {
+
+			@Override
+			public int compare(Viewer viewer, Object thisKey, Object thatKey) {
+				if (thisKey instanceof IOpenShiftSSHKey 
+						&& thatKey instanceof IOpenShiftSSHKey) {
+					return ((IOpenShiftSSHKey) thisKey).getName().compareTo(((IEmbeddableCartridge) thatKey).getName());
+				}
+				return super.compare(viewer, thisKey, thatKey);
+			}
+
+		});
+
+		createTableColumn("Name", 1, new CellLabelProvider() {
+
+			@Override
+			public void update(ViewerCell cell) {
+				IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
+				cell.setText(key.getName());
+			}
+		}, viewer, tableLayout);
+		createTableColumn("Type", 1, new CellLabelProvider() {
+
+			@Override
+			public void update(ViewerCell cell) {
+				IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
+				cell.setText(key.getName());
+			}
+		}, viewer, tableLayout);
+		createTableColumn("Public Key", 1, new CellLabelProvider() {
+
+			@Override
+			public void update(ViewerCell cell) {
+				IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
+				cell.setText(key.getPublicKey());
+			}
+		}, viewer, tableLayout);
+		return viewer;
+	}
+
+	private void createTableColumn(String name, int weight, CellLabelProvider cellLabelProvider, TableViewer viewer,
+			TableColumnLayout layout) {
+		TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
+		column.getColumn().setText(name);
+		column.setLabelProvider(cellLabelProvider);
+		layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+	}
+
+	@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());
+		} catch (Exception e) {
+			// ignore
+		}
+	}
+
+	private void clearViewer() {
+		setViewerInput(new ArrayList<IOpenShiftSSHKey>());
+	}
+
+	private void setViewerInput(final Collection<IOpenShiftSSHKey> keys) {
+		getShell().getDisplay().syncExec(new Runnable() {
+
+			@Override
+			public void run() {
+				viewer.setInput(keys);
+			}
+		});
+	}
+
+	/**
+	 * Viewer element comparer based on #equals(). The default implementation in
+	 * CheckboxTableViewer compares elements based on instance identity.
+	 * <p>
+	 * We need this since the available cartridges (item listed in the viewer)
+	 * are not the same instance as the ones in the embedded application (items
+	 * to check in the viewer).
+	 */
+	private static class EqualityComparer implements IElementComparer {
+
+		@Override
+		public boolean equals(Object thisObject, Object thatObject) {
+			if (thisObject == null) {
+				return thatObject != null;
+			}
+
+			if (thatObject == null) {
+				return false;
+			}
+
+			return thisObject.equals(thatObject);
+		}
+
+		@Override
+		public int hashCode(Object element) {
+			return element.hashCode();
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPageModel.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPageModel.java	2012-09-13 14:54:15 UTC (rev 43654)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+
+import com.openshift.client.IOpenShiftSSHKey;
+
+/**
+ * @author André Dietisheim
+ */
+public class ManageSSHKeysWizardPageModel extends ObservableUIPojo {
+
+	public static final String PROPERTY_SSH_KEYS = "sshKeys";
+
+	private UserDelegate user;
+	private List<IOpenShiftSSHKey> keys = new ArrayList<IOpenShiftSSHKey>();
+
+	public ManageSSHKeysWizardPageModel(UserDelegate user) {
+		this.user = user;
+	}
+
+	public List<IOpenShiftSSHKey> loadSSHKeys() {
+		return setSSHKeys(user.getSSHKeys());
+	}
+
+	public List<IOpenShiftSSHKey> getSSHKeys() {
+		return keys;
+	}
+
+	public List<IOpenShiftSSHKey> setSSHKeys(List<IOpenShiftSSHKey> keys) {
+		firePropertyChange(PROPERTY_SSH_KEYS, this.keys, this.keys = keys);
+		return this.keys;
+	}
+
+	public UserDelegate getUser() {
+		return user;
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list