Author: adietish
Date: 2010-11-04 12:54:57 -0400 (Thu, 04 Nov 2010)
New Revision: 26263
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/StopInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties
Log:
[JBIDE-7496] added dialog to stop 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 16:32:51
UTC (rev 26262)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 16:54:57
UTC (rev 26263)
@@ -1,5 +1,9 @@
2010-11-04 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties:
+ [JBIDE-7496] added texts for dialog to stop 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):
[JBIDE-7498] do nothing if event's is triggered for cloud's that has been
deleted
* src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java:
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
16:32:51 UTC (rev 26262)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java 2010-11-04
16:54:57 UTC (rev 26263)
@@ -10,13 +10,23 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.commands;
+import java.util.Collection;
+import java.util.List;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
+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.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
@@ -34,18 +44,83 @@
private final static String STOPPING_INSTANCE_TITLE =
"StoppingInstance.title"; //$NON-NLS-1$
private final static String STOPPING_INSTANCE_MSG = "StoppingInstance.msg";
//$NON-NLS-1$
+ private final static String STOP_INSTANCES_DIALOG_TITLE =
"StopInstancesDialog.title"; //$NON-NLS-1$
+ private final static String STOP_INSTANCES_DIALOG_MSG =
"StopInstancesDialog.msg"; //$NON-NLS-1$
+
+ public static class StopInstanceDialog extends ListSelectionDialog {
+ private static class DeltaCloudInstanceProvider implements IStructuredContentProvider
{
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object[] getElements(Object cvInstanceElements) {
+ Assert.isTrue(cvInstanceElements instanceof Collection);
+ Collection<CVInstanceElement> instances = (Collection<CVInstanceElement>)
cvInstanceElements;
+ return instances.toArray(new CVInstanceElement[instances.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 ((CVInstanceElement) element).getName();
+ }
+ };
+
+ public StopInstanceDialog(Shell parentShell, Collection<?> cloudViewElements) {
+ super(parentShell
+ , cloudViewElements
+ , new DeltaCloudInstanceProvider()
+ , new CloudElementNameProvider(),
CVMessages.getString(STOP_INSTANCES_DIALOG_TITLE));
+ setTitle(CVMessages.getString(STOP_INSTANCES_DIALOG_MSG));
+ }
+ }
+
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
- CVInstanceElement cvInstance = UIUtils.getFirstElement(selection,
CVInstanceElement.class);
- stopInstance(cvInstance);
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ if (isSingleInstance(structuredSelection)) {
+ CVInstanceElement cvInstance = UIUtils.getFirstElement(selection,
CVInstanceElement.class);
+ stopInstance(cvInstance);
+ } else {
+ stopWithDialog(structuredSelection);
+ }
}
return Status.OK_STATUS;
}
+ private boolean isSingleInstance(IStructuredSelection selection) {
+ List<?> selectedItems = selection.toList();
+ return selectedItems.size() == 1
+ && selectedItems.get(0) instanceof CVInstanceElement;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void stopWithDialog(IStructuredSelection selection) {
+ StopInstanceDialog dialog = new StopInstanceDialog(
+ UIUtils.getActiveShell()
+ , (List<CVInstanceElement>) selection.toList());
+ if (Dialog.OK == dialog.open()) {
+ stopInstances(dialog.getResult());
+ }
+ }
+
+ private void stopInstances(Object[] cvInstances) {
+ for (int i = 0; i < cvInstances.length; i++) {
+ stopInstance((CVInstanceElement) cvInstances[i]);
+ }
+ }
+
private void stopInstance(CVInstanceElement cvInstance) {
if (cvInstance != null) {
DeltaCloudInstance instance = (DeltaCloudInstance) cvInstance.getElement();
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
16:32:51 UTC (rev 26262)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-11-04
16:54:57 UTC (rev 26263)
@@ -49,6 +49,8 @@
StartingInstance.msg=Starting Instance: {0}
StoppingInstance.title=Stopping Instance
StoppingInstance.msg=Stopping Instance: {0}
+StopInstancesDialog.title=Stop Instances
+StopInstancesDialog.msg=Please choose the instance that shall be stopped by checking
them:
RebootingInstance.title=Rebooting Instance
RebootingInstance.msg=Rebooting Instance: {0}
DestroyingInstance.title=Destroying Instance