Author: jjohnstn
Date: 2010-08-11 18:13:55 -0400 (Wed, 11 Aug 2010)
New Revision: 24072
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
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/InstanceView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
Log:
2010-08-11 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties: Add new messages.
* src/org/jboss/tools/deltacloud/ui/views/InstanceView.java (listChanged): Fix problem
with notification loop.
(PerformInstanceActionThread): New class to perform instance actions.
(makeActions): Add instance actions.
(createPartControl): Fix up notification loop.
(refreshInstance): New method.
(fillContextMenu): Use actions of instance to populate context menu.
* src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
(inputChanged): Allow
setting of the instance list directly instead of calling getInstances and causing
notification
to start again.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-08-11 22:10:38
UTC (rev 24071)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-08-11 22:13:55
UTC (rev 24072)
@@ -1,5 +1,19 @@
2010-08-11 Jeff Johnston <jjohnstn(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties: Add new messages.
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceView.java (listChanged): Fix problem
+ with notification loop.
+ (PerformInstanceActionThread): New class to perform instance actions.
+ (makeActions): Add instance actions.
+ (createPartControl): Fix up notification loop.
+ (refreshInstance): New method.
+ (fillContextMenu): Use actions of instance to populate context menu.
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
(inputChanged): Allow
+ setting of the instance list directly instead of calling getInstances and causing
notification
+ to start again.
+
+2010-08-11 Jeff Johnston <jjohnstn(a)redhat.com>
+
* src/org/jboss/tools/deltacloud/ui/CustomProgressMonitorDialog.java: New file.
* src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java (getAdapter): Fix
warning.
* src/org/jboss/tools/deltacloud/ui/views/InstancePropertySource.java
(InstancePropertySource): Ditto.
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-08-11
22:10:38 UTC (rev 24071)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties 2010-08-11
22:13:55 UTC (rev 24072)
@@ -23,6 +23,11 @@
CreateInstance.label=Launch Instance
DeleteInstance.label=Delete Instance
+Start.label=Start
+Stop.label=Stop
+Reboot.label=Reboot
+Destroy.label=Destroy
+
NAME=Name
ID=ID
HOSTNAME=Public Hostname
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-08-11
22:10:38 UTC (rev 24071)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-08-11
22:13:55 UTC (rev 24072)
@@ -1,5 +1,9 @@
package org.jboss.tools.deltacloud.ui.views;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -28,6 +32,7 @@
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
@@ -45,16 +50,29 @@
public class InstanceView extends ViewPart implements ICloudManagerListener,
IInstanceListListener {
private final static String CLOUD_SELECTOR_LABEL = "CloudSelector.label";
//$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$
+ private final static String DESTROY_LABEL = "Destroy.label"; //$NON-NLS-1$
+
private TableViewer viewer;
private Composite container;
private Combo cloudSelector;
- @SuppressWarnings("unused")
private DeltaCloudInstance selectedElement;
private DeltaCloud[] clouds;
private DeltaCloud currCloud;
+ private InstanceViewLabelAndContentProvider contentProvider;
+
private Action doubleClickAction;
+ private Action startAction;
+ private Action stopAction;
+ private Action destroyAction;
+ private Action rebootAction;
+
+ private Map<String, Action> instanceActions;
+
private InstanceView parentView;
public InstanceView() {
@@ -134,8 +152,9 @@
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
- viewer.setContentProvider(new InstanceViewLabelAndContentProvider());
- viewer.setLabelProvider(new InstanceViewLabelAndContentProvider());
+ contentProvider = new InstanceViewLabelAndContentProvider();
+ viewer.setContentProvider(contentProvider);
+ viewer.setLabelProvider(contentProvider);
InstanceComparator comparator = new InstanceComparator(0);
viewer.setComparator(comparator);
@@ -151,6 +170,7 @@
}
table.setSortDirection(SWT.UP);
+ currCloud.removeInstanceListListener(parentView);
viewer.setInput(clouds[0]);
currCloud.addInstanceListListener(parentView);
@@ -220,7 +240,10 @@
}
private void fillContextMenu(IMenuManager manager) {
- //TODO
+ List<String> actions = selectedElement.getActions();
+ for (String action : actions) {
+ manager.add(instanceActions.get(action));
+ }
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
@@ -229,6 +252,31 @@
//TODO
}
+ private class PerformInstanceActionThread extends Thread {
+ private DeltaCloud cloud;
+ private DeltaCloudInstance instance;
+ private String action;
+
+ public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
String action) {
+ super();
+ this.cloud = cloud;
+ this.instance = instance;
+ this.action = action;
+ }
+
+ @Override
+ public void run() {
+ cloud.performInstanceAction(instance.getId(), action);
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ refreshInstance(instance);
+ }
+ });
+
+ }
+ }
+
private void makeActions() {
doubleClickAction = new Action() {
public void run() {
@@ -237,8 +285,68 @@
showMessage("Double-click detected on "+obj.toString());
}
};
+ startAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.START);
+ t.start();
+ }
+ };
+ startAction.setText(CVMessages.getString(START_LABEL));
+ startAction.setToolTipText(CVMessages.getString(START_LABEL));
+
+ stopAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.STOP);
+ t.start();
+ }
+ };
+ stopAction.setText(CVMessages.getString(STOP_LABEL));
+ stopAction.setToolTipText(CVMessages.getString(STOP_LABEL));
+
+ rebootAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.REBOOT);
+ t.start();
+ }
+ };
+ rebootAction.setText(CVMessages.getString(REBOOT_LABEL));
+ rebootAction.setToolTipText(CVMessages.getString(REBOOT_LABEL));
+
+ destroyAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.DESTROY);
+ t.start();
+ }
+ };
+ destroyAction.setText(CVMessages.getString(DESTROY_LABEL));
+ destroyAction.setToolTipText(CVMessages.getString(DESTROY_LABEL));
+
+ instanceActions = new HashMap<String, Action>();
+ instanceActions.put(DeltaCloudInstance.START, startAction);
+ instanceActions.put(DeltaCloudInstance.STOP, stopAction);
+ instanceActions.put(DeltaCloudInstance.REBOOT, rebootAction);
+ instanceActions.put(DeltaCloudInstance.DESTROY, destroyAction);
}
+ private void refreshInstance(DeltaCloudInstance instance) {
+ DeltaCloudInstance[] instances =
(DeltaCloudInstance[])contentProvider.getElements(currCloud);
+ for (int i = 0; i < instances.length; ++i) {
+ DeltaCloudInstance d = instances[i];
+ if (d == instance) {
+ currCloud.refreshInstance(d.getId());
+ break;
+ }
+ }
+ }
+
private void hookDoubleClickAction() {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
@@ -292,9 +400,9 @@
@Override
public void listChanged(DeltaCloudInstance[] list) {
currCloud.removeInstanceListListener(parentView);
- viewer.setInput(currCloud);
+ viewer.setInput(list);
+ currCloud.addInstanceListListener(parentView);
viewer.refresh();
- currCloud.addInstanceListListener(parentView);
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-08-11
22:10:38 UTC (rev 24071)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-08-11
22:13:55 UTC (rev 24072)
@@ -70,8 +70,12 @@
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput != null) {
- cloud = (DeltaCloud)newInput;
- instances = cloud.getInstances();
+ if (newInput instanceof DeltaCloudInstance[]) {
+ instances = (DeltaCloudInstance[])newInput;
+ } else {
+ cloud = (DeltaCloud)newInput;
+ instances = cloud.getInstances();
+ }
}
}