Author: adietish
Date: 2010-10-13 07:37:49 -0400 (Wed, 13 Oct 2010)
New Revision: 25780
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java
Log:
[JBIDE-7326] implemented dialog, renamed action to disconnect action
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-10-13
10:30:17 UTC (rev 25779)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-10-13
11:37:49 UTC (rev 25780)
@@ -58,7 +58,7 @@
DestroyingInstance.msg=Destroying Instance: {0}
ConnectingRSE.msg=Connecting instance as: {0}
ConfirmCloudDelete.title=Confirm Cloud Disconnect
-ConfirmCloudDelete.msg=Confirm disconnecting cloud: {0}
+ConfirmCloudDelete.msg=Please choose the clouds that shall be disconnected by checking
them:
NAME=Name
ID=ID
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java 2010-10-13
10:30:17 UTC (rev 25779)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java 2010-10-13
11:37:49 UTC (rev 25780)
@@ -11,7 +11,6 @@
package org.jboss.tools.deltacloud.ui.views;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -21,7 +20,7 @@
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -71,8 +70,6 @@
private static final String EDIT_CLOUD = "EditCloud.label"; //$NON-NLS-1$
private static final String REFRESH = "Refresh.label"; //$NON-NLS-1$
private static final String CREATE_INSTANCE = "CreateInstance.label";
//$NON-NLS-1$
- private static final String CONFIRM_CLOUD_DELETE_TITLE =
"ConfirmCloudDelete.title"; //$NON-NLS-1$
- private static final String CONFIRM_CLOUD_DELETE_MSG =
"ConfirmCloudDelete.msg"; //$NON-NLS-1$
private final static String START_LABEL = "Start.label"; //$NON-NLS-1$
private final static String STOP_LABEL = "Stop.label"; //$NON-NLS-1$
private final static String REBOOT_LABEL = "Reboot.label"; //$NON-NLS-1$
@@ -89,11 +86,10 @@
private final static String INSTANCE_FILTER = "InstanceFilter.label";
//$NON-NLS-1$
public static final String COLLAPSE_ALL = "CollapseAll.label"; //$NON-NLS-1$
-
private TreeViewer viewer;
private Action createConnection;
- private Action removeCloud;
+ private Action disconnectCloud;
private Action refreshAction;
private Action startAction;
private Action stopAction;
@@ -110,7 +106,6 @@
private CloudViewElement selectedElement;
-
/**
* The constructor.
*/
@@ -183,7 +178,7 @@
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
selectedElement = (CloudViewElement) selection.getFirstElement();
editCloud.setEnabled(selectedElement != null);
- removeCloud.setEnabled(selectedElement != null);
+ disconnectCloud.setEnabled(selectedElement != null);
refreshAction.setEnabled(selectedElement != null);
imageFilterAction.setEnabled(selectedElement != null);
instanceFilterAction.setEnabled(selectedElement != null);
@@ -193,7 +188,7 @@
manager.removeAll();
manager.add(createConnection);
manager.add(editCloud);
- manager.add(removeCloud);
+ manager.add(disconnectCloud);
manager.add(refreshAction);
manager.add(imageFilterAction);
manager.add(instanceFilterAction);
@@ -213,7 +208,7 @@
}
manager.add(createConnection);
manager.add(editCloud);
- manager.add(removeCloud);
+ manager.add(disconnectCloud);
manager.add(imageFilterAction);
manager.add(instanceFilterAction);
// Other plug-ins can contribute there actions here
@@ -226,7 +221,7 @@
private void makeActions() {
createConnection = createNewConnectionAction();
- removeCloud = createRemoveAction();
+ disconnectCloud = createDisconnectAction();
createInstance = createInstanceAction();
editCloud = createEditCloudAction();
refreshAction = createRefreshAction();
@@ -261,7 +256,8 @@
public void run() {
NewCloudConnection wizard = new NewCloudConnection();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
- WizardDialog dialog = new
WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
+ WizardDialog dialog = new
WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ wizard);
dialog.create();
dialog.open();
}
@@ -271,7 +267,7 @@
createConnection.setImageDescriptor(SWTImagesFactory.DESC_CLOUD);
return createConnection;
}
-
+
private Action createCollapseAllAction() {
Action collapseAll = new Action() {
public void run() {
@@ -520,8 +516,17 @@
return editCloud;
}
- private Action createRemoveAction() {
- Action removeCloud = new RemoveAction();
+ private Action createDisconnectAction() {
+ Action removeCloud = new Action() {
+ public void run() {
+ DisconnectCloudsDialog dialog = new DisconnectCloudsDialog(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
+ , ((IStructuredSelection) viewer.getSelection()).toList());
+ if (Dialog.OK == dialog.open()) {
+ viewer.remove(dialog.getResult());
+ }
+ }
+ };
removeCloud.setText(CVMessages.getString(REMOVE_CLOUD));
removeCloud.setToolTipText(CVMessages.getString(REMOVE_CLOUD));
removeCloud.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
@@ -588,44 +593,4 @@
return new CVPropertySheetPage();
return super.getAdapter(adapter);
}
-
- /**
- * A JFace action that removes the clouds that are selected in the tree
- * viewer.
- */
- private class RemoveAction extends Action {
-
- public void run() {
- IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
- for (Iterator<?> iterator = selection.toList().iterator(); iterator.hasNext();)
{
- CloudViewElement element = (CloudViewElement) iterator.next();
- remove(element);
- }
- }
-
- private void remove(CloudViewElement element) {
- while (element != null && !(element instanceof CVCloudElement)) {
- element = (CloudViewElement) element.getParent();
- }
- if (element != null) {
- CVCloudElement cve = (CVCloudElement) element;
- Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
- boolean confirmed = MessageDialog.openConfirm(shell,
- CVMessages.getString(CONFIRM_CLOUD_DELETE_TITLE),
- CVMessages.getFormattedString(CONFIRM_CLOUD_DELETE_MSG, cve.getName()));
- if (confirmed) {
- DeltaCloudManager.getDefault().removeCloud((DeltaCloud) element.getElement());
- CloudViewContentProvider p = (CloudViewContentProvider)
viewer.getContentProvider();
- Object[] elements = p.getElements(getViewSite());
- int index = -1;
- for (int i = 0; i < elements.length; ++i) {
- if (elements[i] == cve)
- index = i;
- }
- if (index >= 0)
- ((TreeViewer) cve.getViewer()).remove(getViewSite(), index);
- }
- }
- }
- }
}
\ No newline at end of file
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java 2010-10-13
11:37:49 UTC (rev 25780)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.views;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+
+public class DisconnectCloudsDialog extends ListSelectionDialog {
+
+ private static final String CONFIRM_CLOUD_DELETE_TITLE =
"ConfirmCloudDelete.title"; //$NON-NLS-1$
+ private static final String CONFIRM_CLOUD_DELETE_MSG =
"ConfirmCloudDelete.msg"; //$NON-NLS-1$
+
+ private static class CloudViewElementsParentContentProvider implements
IStructuredContentProvider {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object[] getElements(Object cloudViewElements) {
+ List<CloudViewElement> cloudViewElementParents = new
ArrayList<CloudViewElement>();
+ for (Object cloudViewElement : (List<CloudViewElement>) cloudViewElements) {
+ if (cloudViewElement instanceof CloudViewElement && ((CloudViewElement)
cloudViewElement).getParent() != null) {
+ cloudViewElementParents.add((CloudViewElement) cloudViewElement);
+ }
+ }
+ return cloudViewElementParents.toArray(new
CloudViewElement[cloudViewElementParents.size()]);
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ private static class CloudElementNameProvider extends LabelProvider {
+ public String getText(Object element) {
+ return ((CloudViewElement) element).getName();
+ }
+ };
+
+ public DisconnectCloudsDialog(Shell parentShell, List<?> cloudViewElements) {
+ super(parentShell
+ , cloudViewElements
+ , new CloudViewElementsParentContentProvider()
+ , new CloudElementNameProvider(), CVMessages.getString(CONFIRM_CLOUD_DELETE_MSG));
+ setTitle(CVMessages.getString(CONFIRM_CLOUD_DELETE_TITLE));
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain