Author: adietish
Date: 2010-11-04 09:08:28 -0400 (Thu, 04 Nov 2010)
New Revision: 26247
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
Log:
[JBIDE-7495] changed dialog and handler to climb up the hierarchy to the connection and
offer to disconnect the cloud connection
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java 2010-11-04
13:01:26 UTC (rev 26246)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java 2010-11-04
13:08:28 UTC (rev 26247)
@@ -10,6 +10,11 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.commands;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -38,7 +43,7 @@
if (selection instanceof IStructuredSelection) {
DisconnectCloudsDialog dialog = new DisconnectCloudsDialog(
shell
- , ((IStructuredSelection) selection).toList());
+ , getSelectedClouds(selection));
if (Dialog.OK == dialog.open()) {
removeCloudViewElements(dialog.getResult());
}
@@ -47,12 +52,46 @@
return Status.OK_STATUS;
}
- private void removeCloudViewElements(Object[] cloudViewerElements) {
- for (Object cloudViewElement : cloudViewerElements) {
- if (cloudViewElement instanceof CloudViewElement) {
- DeltaCloud deltaCloud = (DeltaCloud) ((CloudViewElement)
cloudViewElement).getElement();
- DeltaCloudManager.getDefault().removeCloud(deltaCloud);
+ private Collection<DeltaCloud> getSelectedClouds(ISelection selection) {
+ Set<DeltaCloud> selectedClouds = new HashSet<DeltaCloud>();
+ List<?> selectedElements = ((IStructuredSelection) selection).toList();
+ for (Object element : selectedElements) {
+ DeltaCloud deltaCloud = getDeltaCloud(element);
+ if (deltaCloud != null) {
+ selectedClouds.add(deltaCloud);
}
}
+ return selectedClouds;
}
+
+ private DeltaCloud getDeltaCloud(Object item) {
+ if (!(item instanceof CloudViewElement)) {
+ return null;
+ }
+
+ DeltaCloud cloud = getDeltaCloud((CloudViewElement) item);
+
+ if (cloud == null) {
+ return null;
+ }
+ return cloud;
+ }
+
+ private DeltaCloud getDeltaCloud(CloudViewElement element) {
+ if (element == null) {
+ return null;
+ }
+ Object cloud = element.getElement();
+ if (cloud instanceof DeltaCloud) {
+ return (DeltaCloud) cloud;
+ }
+
+ return getDeltaCloud((CloudViewElement) element.getParent());
+ }
+
+ private void removeCloudViewElements(Object[] deltaClouds) {
+ for (Object deltaCloud : deltaClouds) {
+ DeltaCloudManager.getDefault().removeCloud((DeltaCloud) deltaCloud);
+ }
+ }
}
Modified:
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 2010-11-04
13:01:26 UTC (rev 26246)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java 2010-11-04
13:08:28 UTC (rev 26247)
@@ -10,32 +10,29 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import org.eclipse.core.runtime.Assert;
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;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
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 {
+ private static class DeltaCloudItemProvider 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()]);
+ Assert.isTrue(cloudViewElements instanceof Collection);
+ Collection<DeltaCloud> deltaClouds = (Collection<DeltaCloud>)
cloudViewElements;
+ return deltaClouds.toArray(new DeltaCloud[deltaClouds.size()]);
}
@Override
@@ -49,14 +46,14 @@
private static class CloudElementNameProvider extends LabelProvider {
public String getText(Object element) {
- return ((CloudViewElement) element).getName();
+ return ((DeltaCloud) element).getName();
}
};
- public DisconnectCloudsDialog(Shell parentShell, List<?> cloudViewElements) {
+ public DisconnectCloudsDialog(Shell parentShell, Collection<?> cloudViewElements)
{
super(parentShell
, cloudViewElements
- , new CloudViewElementsParentContentProvider()
+ , new DeltaCloudItemProvider()
, new CloudElementNameProvider(), CVMessages.getString(CONFIRM_CLOUD_DELETE_MSG));
setTitle(CVMessages.getString(CONFIRM_CLOUD_DELETE_TITLE));
}
Show replies by date