Author: adietish
Date: 2010-11-12 06:22:30 -0500 (Fri, 12 Nov 2010)
New Revision: 26499
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/StringUtils.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/AbstractInstanceHandler.java
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
Log:
[JBIDE-7459] added detailed error reporting with dialog to start/stop/reboot/destroy
instances
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/AbstractInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/AbstractInstanceHandler.java 2010-11-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/AbstractInstanceHandler.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -13,8 +13,11 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.ui.views.PerformInstanceActionThread;
+import org.jboss.tools.internal.deltacloud.ui.utils.StringUtils;
+import org.jboss.tools.internal.deltacloud.ui.utils.StringUtils.IElementFormatter;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
/**
@@ -42,4 +45,24 @@
protected boolean isSingleInstanceSelected(ISelection selection) {
return UIUtils.isSingleSelection(selection, DeltaCloudInstance.class);
}
+
+ @SuppressWarnings("unchecked")
+ protected String getInstanceNames(ISelection selection) {
+ return StringUtils.getFormattedString(((IStructuredSelection) selection).toList(),
+ new IElementFormatter<Object>() {
+
+ @Override
+ public String format(Object element) {
+ if (element instanceof DeltaCloudInstance) {
+ return new StringBuilder()
+ .append(((DeltaCloudInstance) element).getName())
+ .append(",")
+ .toString();
+ } else {
+ return null;
+ }
+ }
+ });
+ }
+
}
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-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DestroyInstanceHandler.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -14,12 +14,16 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.deltacloud.ui.views.PerformDestroyInstanceActionThread;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
@@ -38,16 +42,29 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- if (isSingleInstanceSelected(selection)) {
- DeltaCloudInstance cvInstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
- destroyInstance(cvInstance);
- } else {
- destroyWithDialog((IStructuredSelection) selection);
+ try {
+ if (selection instanceof IStructuredSelection) {
+ if (isSingleInstanceSelected(selection)) {
+ DeltaCloudInstance cvInstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
+ destroyInstance(cvInstance);
+ } else {
+ destroyWithDialog((IStructuredSelection) selection);
+ }
}
+
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ String message = getInstanceNames(selection);
+ IStatus status = StatusFactory.getInstance(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ e.getMessage(),
+ e);
+ ErrorDialog.openError(HandlerUtil.getActiveShell(event),
+ CVMessages.getString("DestroyInstancesDialogError.title"),
+ CVMessages.getFormattedString("DestroyInstancesDialogError.msg", message),
status);
+ return status;
}
-
- return Status.OK_STATUS;
}
@SuppressWarnings("unchecked")
@@ -67,11 +84,11 @@
destroyInstance((DeltaCloudInstance) cvInstances[i]);
}
}
-
+
private void destroyInstance(DeltaCloudInstance instance) {
if (instance != null) {
PerformDestroyInstanceActionThread t = new PerformDestroyInstanceActionThread(
- instance.getDeltaCloud(),
+ instance.getDeltaCloud(),
instance,
CVMessages.getString(DESTROYING_INSTANCE_TITLE),
CVMessages.getFormattedString(DESTROYING_INSTANCE_MSG, new String[] {
instance.getName() }));
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-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/RebootInstanceHandler.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -14,12 +14,16 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
@@ -37,16 +41,29 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- if (isSingleInstanceSelected(selection)) {
- DeltaCloudInstance cvInstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
- rebootInstance(cvInstance);
- } else {
- rebootWithDialog((IStructuredSelection)selection);
+ try {
+ if (selection instanceof IStructuredSelection) {
+ if (isSingleInstanceSelected(selection)) {
+ DeltaCloudInstance cvInstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
+ rebootInstance(cvInstance);
+ } else {
+ rebootWithDialog((IStructuredSelection) selection);
+ }
}
+
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ String message = getInstanceNames(selection);
+ IStatus status = StatusFactory.getInstance(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ e.getMessage(),
+ e);
+ ErrorDialog.openError(HandlerUtil.getActiveShell(event),
+ CVMessages.getString("RebootInstancesDialogError.title"),
+ CVMessages.getFormattedString("RebootInstancesDialogError.msg", message),
status);
+ return status;
}
-
- return Status.OK_STATUS;
}
@SuppressWarnings("unchecked")
@@ -60,13 +77,13 @@
rebootInstances(dialog.getResult());
}
}
-
+
private void rebootInstances(Object[] deltaCloudInstances) {
for (int i = 0; i < deltaCloudInstances.length; i++) {
rebootInstance((DeltaCloudInstance) deltaCloudInstances[i]);
}
}
-
+
private void rebootInstance(DeltaCloudInstance instance) {
if (instance != null) {
executeInstanceAction(
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-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -15,12 +15,16 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
@@ -37,16 +41,29 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- if (isSingleInstanceSelected(selection)) {
- DeltaCloudInstance cvinstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
- startInstance(cvinstance);
- } else {
- startWithDialog((IStructuredSelection) selection);
+ try {
+ if (selection instanceof IStructuredSelection) {
+ if (isSingleInstanceSelected(selection)) {
+ DeltaCloudInstance cvinstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
+ startInstance(cvinstance);
+ } else {
+ startWithDialog((IStructuredSelection) selection);
+ }
}
+
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ String message = getInstanceNames(selection);
+ IStatus status = StatusFactory.getInstance(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ e.getMessage(),
+ e);
+ ErrorDialog.openError(HandlerUtil.getActiveShell(event),
+ CVMessages.getString("StartInstancesDialogError.title"),
+ CVMessages.getFormattedString("StartInstancesDialogError.msg", message),
status);
+ return status;
}
-
- return Status.OK_STATUS;
}
@SuppressWarnings("unchecked")
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-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StopInstanceHandler.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -14,12 +14,16 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
@@ -36,16 +40,28 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- if (isSingleInstanceSelected(selection)) {
- DeltaCloudInstance cvInstance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
- stopInstance(cvInstance);
- } else {
- stopWithDialog((IStructuredSelection) selection);
+ try {
+ if (selection instanceof IStructuredSelection) {
+ if (isSingleInstanceSelected(selection)) {
+ DeltaCloudInstance instance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
+ stopInstance(instance);
+ } else {
+ stopWithDialog((IStructuredSelection) selection);
+ }
}
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ String message = getInstanceNames(selection);
+ IStatus status = StatusFactory.getInstance(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ e.getMessage(),
+ e);
+ ErrorDialog.openError(HandlerUtil.getActiveShell(event),
+ CVMessages.getString("StopInstancesDialogError.title"),
+ CVMessages.getFormattedString("StopInstancesDialogError.msg", message),
status);
+ return status;
}
-
- return Status.OK_STATUS;
}
@SuppressWarnings("unchecked")
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-12
11:07:55 UTC (rev 26498)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-11-12
11:22:30 UTC (rev 26499)
@@ -49,18 +49,26 @@
StartingInstance.msg=Starting Instance: {0}
StartInstancesDialog.title=Start Instances
StartInstancesDialog.msg=Please choose the instances that shall be started by checking
them:
+StartInstancesDialogError.title=Error while starting instance(s)
+StartInstancesDialogError.msg=Could not start instance(s) {0}
StoppingInstance.title=Stopping Instance
StoppingInstance.msg=Stopping Instance: {0}
StopInstancesDialog.title=Stop Instances
StopInstancesDialog.msg=Please choose the instances that shall be stopped by checking
them:
+StopInstancesDialogError.title=Error while stopping instance(s)
+StopInstancesDialogError.msg=Could not stop instance(s) {0}
RebootingInstance.title=Rebooting Instance
RebootingInstance.msg=Rebooting Instance: {0}
RebootInstancesDialog.title=Reboot Instances
RebootInstancesDialog.msg=Please choose the clouds that shall be rebooted by checking
them:
+RebootInstancesDialogError.title=Error while rebooting instance(s)
+RebootInstancesDialogError.msg=Could not reboot instance(s) {0}
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:
+DestroyInstancesDialogError.title=Error while destroying instance(s)
+DestroyInstancesDialogError.msg=Could not destroy instance(s) {0}
ConnectingRSE.msg=Connecting instance as: {0}
ConfirmCloudDelete.title=Confirm Cloud Disconnect
ConfirmCloudDelete.msg=Please choose the clouds that shall be disconnected by checking
them:
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/StringUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/StringUtils.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/StringUtils.java 2010-11-12
11:22:30 UTC (rev 26499)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.internal.deltacloud.ui.utils;
+
+import java.util.Collection;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class StringUtils {
+
+ /**
+ * Returns a formatted string for a collection of elements that get
+ * formatted by a user supplied element formatter.
+ *
+ * @param <E>
+ * the element type
+ * @param elements
+ * the elements
+ * @param elementFormatter
+ * the element formatter
+ * @return the formatted string
+ */
+ public static <E> String getFormattedString(Collection<E> elements,
IElementFormatter<E> elementFormatter) {
+ StringBuilder builder = new StringBuilder();
+ for (E element : elements) {
+ String formattedElement = elementFormatter.format(element);
+ if (formattedElement != null && formattedElement.length() > 0) {
+ builder.append(formattedElement);
+ }
+ }
+ if (builder.length() > 0) {
+ return builder.toString();
+ } else {
+ return "";
+ }
+ }
+
+ public interface IElementFormatter<E> {
+ public String format(E element);
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/StringUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain