Author: adietish
Date: 2010-11-04 15:22:50 -0400 (Thu, 04 Nov 2010)
New Revision: 26270
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java
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/CloudViewElementUtils.java
Log:
[JBIDE-7499] added dialog to destroy several instances at once
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 19:06:31
UTC (rev 26269)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 19:22:50
UTC (rev 26270)
@@ -1,5 +1,9 @@
2010-11-04 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/CloudViewElementUtils.java:
+ [JBIDE-7502] extracted common patterns of instance lookup to a util class
+ * src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java:
+ [JBIDE-7502] added dialog to destroy several instances at once
* src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java:
[JBIDE-7501] added dialog to reboot several instances at once
* src/org/jboss/tools/deltacloud/ui/commands/AbstractInstanceHandler.java:
@@ -10,6 +14,7 @@
[JBIDE-7496] added texts for dialog to stop several instances at once
[JBIDE-7499] added texts for dialog to start several instances at once
[JBIDE-7501] added texts for dialog to reboot several instances at once
+ [JBIDE-7502] added texts for dialog to destroy several instances at once
* src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java
(StopInstanceDialog):
[JBIDE-7496] added dialog to stop several instances at once
* src/org/jboss/tools/deltacloud/ui/views/ImageView.java (.modifyText):
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java 2010-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java 2010-11-04
19:22:50 UTC (rev 26270)
@@ -10,11 +10,12 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.commands;
-import org.eclipse.core.commands.AbstractHandler;
+import java.util.List;
+
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -24,37 +25,63 @@
import org.jboss.tools.deltacloud.ui.views.CVInstanceElement;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.deltacloud.ui.views.CloudViewElement;
+import org.jboss.tools.deltacloud.ui.views.CloudViewElementUtils;
import org.jboss.tools.deltacloud.ui.views.PerformDestroyInstanceActionThread;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
/**
* @author Andre Dietisheim
*/
-public class DestroyInstanceHandler extends AbstractHandler implements IHandler {
+public class DestroyInstanceHandler extends AbstractInstanceHandler {
private final static String DESTROYING_INSTANCE_TITLE =
"DestroyingInstance.title"; //$NON-NLS-1$
private final static String DESTROYING_INSTANCE_MSG =
"DestroyingInstance.msg"; //$NON-NLS-1$
+ private final static String DESTROY_INSTANCE_TITLE =
"DestroyInstancesDialog.title"; //$NON-NLS-1$
+ private final static String DESTROY_INSTANCE_MSG =
"DestroyInstancesDialog.msg"; //$NON-NLS-1$
+
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
- CVInstanceElement cvInstance = UIUtils.getFirstElement(selection,
CVInstanceElement.class);
- rebootInstance(cvInstance);
+ if (isSingleInstanceSelected(selection)) {
+ CVInstanceElement cvInstance = UIUtils.getFirstElement(selection,
CVInstanceElement.class);
+ destroyInstance(cvInstance);
+ } else {
+ destroyWithDialog((IStructuredSelection) selection);
+ }
}
return Status.OK_STATUS;
}
- private void rebootInstance(CVInstanceElement cvInstance) {
+ @SuppressWarnings("unchecked")
+ private void destroyWithDialog(IStructuredSelection selection) {
+ CVInstanceElementsSelectionDialog dialog = new CVInstanceElementsSelectionDialog(
+ UIUtils.getActiveShell()
+ , (List<CVInstanceElement>) selection.toList()
+ , CVMessages.getString(DESTROY_INSTANCE_TITLE)
+ , CVMessages.getString(DESTROY_INSTANCE_MSG));
+ if (Dialog.OK == dialog.open()) {
+ destroyInstances(dialog.getResult());
+ }
+ }
+
+ private void destroyInstances(Object[] cvInstances) {
+ for (int i = 0; i < cvInstances.length; i++) {
+ destroyInstance((CVInstanceElement) cvInstances[i]);
+ }
+ }
+
+ private void destroyInstance(CVInstanceElement cvInstance) {
if (cvInstance != null) {
DeltaCloudInstance instance = (DeltaCloudInstance) cvInstance.getElement();
CloudViewElement element = cvInstance;
- while (!(element instanceof CVCloudElement))
- element = (CloudViewElement) element.getParent();
- CVCloudElement cvcloud = (CVCloudElement) element;
+ CVCloudElement cvcloud = CloudViewElementUtils.getCVCloudElement(element);
DeltaCloud cloud = (DeltaCloud) cvcloud.getElement();
- PerformDestroyInstanceActionThread t = new PerformDestroyInstanceActionThread(cloud,
instance,
+ PerformDestroyInstanceActionThread t = new PerformDestroyInstanceActionThread(
+ cloud,
+ instance,
CVMessages.getString(DESTROYING_INSTANCE_TITLE),
CVMessages.getFormattedString(DESTROYING_INSTANCE_MSG, new String[] {
instance.getName() }));
t.setUser(true);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java 2010-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java 2010-11-04
19:22:50 UTC (rev 26270)
@@ -14,7 +14,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
@@ -28,7 +27,7 @@
/**
* @author Andre Dietisheim
*/
-public class RebootInstanceHandler extends AbstractInstanceHandler implements IHandler {
+public class RebootInstanceHandler extends AbstractInstanceHandler {
private final static String REBOOTING_INSTANCE_TITLE =
"RebootingInstance.title"; //$NON-NLS-1$
private final static String REBOOTING_INSTANCE_MSG = "RebootingInstance.msg";
//$NON-NLS-1$
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java 2010-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java 2010-11-04
19:22:50 UTC (rev 26270)
@@ -14,7 +14,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
@@ -28,7 +27,7 @@
/**
* @author Andre Dietisheim
*/
-public class StartInstanceHandler extends AbstractInstanceHandler implements IHandler {
+public class StartInstanceHandler extends AbstractInstanceHandler {
private final static String STARTING_INSTANCE_TITLE =
"StartingInstance.title"; //$NON-NLS-1$
private final static String STARTING_INSTANCE_MSG = "StartingInstance.msg";
//$NON-NLS-1$
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java 2010-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java 2010-11-04
19:22:50 UTC (rev 26270)
@@ -14,7 +14,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
@@ -28,7 +27,7 @@
/**
* @author Andre Dietisheim
*/
-public class StopInstanceHandler extends AbstractInstanceHandler implements IHandler {
+public class StopInstanceHandler extends AbstractInstanceHandler {
private final static String STOPPING_INSTANCE_TITLE =
"StoppingInstance.title"; //$NON-NLS-1$
private final static String STOPPING_INSTANCE_MSG = "StoppingInstance.msg";
//$NON-NLS-1$
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-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-11-04
19:22:50 UTC (rev 26270)
@@ -59,6 +59,8 @@
RebootInstancesDialog.msg=Please choose the clouds that shall be rebooted by checking
them:
DestroyingInstance.title=Destroying Instance
DestroyingInstance.msg=Destroying Instance: {0}
+DestroyInstancesDialog.title=Destroy Instances
+DestroyInstancesDialog.msg=Please choose the clouds that shall be destroyed by checking
them:
ConnectingRSE.msg=Connecting instance as: {0}
ConfirmCloudDelete.title=Confirm Cloud Disconnect
ConfirmCloudDelete.msg=Please choose the clouds that shall be disconnected by checking
them:
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElementUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElementUtils.java 2010-11-04
19:06:31 UTC (rev 26269)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElementUtils.java 2010-11-04
19:22:50 UTC (rev 26270)
@@ -14,13 +14,35 @@
public class CloudViewElementUtils {
+ /**
+ * Returns a DeltaCloud instance for a given cloud view element
+ *
+ * @param element the cloud view element to get the DeltaCloud for
+ * @return the cloud for the given CloudViewElement
+ *
+ * @see DeltaCloud
+ * @see CloudViewElement
+ */
public static DeltaCloud getCloud(CloudViewElement element) {
+ CVCloudElement cvcloud = getCVCloudElement(element);
+ DeltaCloud cloud = (DeltaCloud) cvcloud.getElement();
+ return cloud;
+ }
+
+ /**
+ * Returns a CVCloudElement for a given cloud view element
+ *
+ * @param element the cloud view element to get the CVCloudElement for
+ * @return the CVCloudElement for the given CloudViewElement
+ *
+ * @see CloudViewElement
+ * @see CVCloudElement
+ */
+ public static CVCloudElement getCVCloudElement(CloudViewElement element) {
while (!(element instanceof CVCloudElement)) {
element = (CloudViewElement) element.getParent();
}
- CVCloudElement cvcloud = (CVCloudElement) element;
- DeltaCloud cloud = (DeltaCloud) cvcloud.getElement();
- return cloud;
+ return (CVCloudElement) element;
}
}
Show replies by date