Author: adietish
Date: 2010-11-08 09:10:45 -0500 (Mon, 08 Nov 2010)
New Revision: 26329
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
Log:
[JBIDE-7516] refactoring code
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-11-08
13:19:04 UTC (rev 26328)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-11-08
14:10:45 UTC (rev 26329)
@@ -102,15 +102,10 @@
int index = cloudSelector.getSelectionIndex();
if (index >= 0) {
currCloud = clouds[index];
- Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- try {
- prefs.put(IDeltaCloudPreferenceConstants.LAST_CLOUD_IMAGE_VIEW,
currCloud.getName());
- } catch (Exception exc) {
- // do nothing
- }
+ storeSelectedCloud();
- viewer.setInput(new DeltaCloudImage[0]);
- viewer.refresh();
+// viewer.setInput(new DeltaCloudImage[0]);
+// viewer.refresh();
Display.getCurrent().asyncExec(new Runnable() {
@Override
@@ -124,6 +119,15 @@
});
}
}
+
+ private void storeSelectedCloud() {
+ Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
+ try {
+ prefs.put(IDeltaCloudPreferenceConstants.LAST_CLOUD_IMAGE_VIEW,
currCloud.getName());
+ } catch (Exception exc) {
+ // do nothing
+ }
+ }
};
private class ColumnListener extends SelectionAdapter {
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-11-08
13:19:04 UTC (rev 26328)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-11-08
14:10:45 UTC (rev 26329)
@@ -12,7 +12,6 @@
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -20,6 +19,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
@@ -81,6 +81,14 @@
public class InstanceView extends ViewPart implements ICloudManagerListener,
IInstanceListListener {
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID =
"org.jboss.tools.deltacloud.ui.views.InstanceView";
+
+// private static final String CONTEXT_MENU_ID = "popup:" + ID;
+// private static final String VIEW_MENU_ID = "menu:" + ID;
+
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$
@@ -100,29 +108,28 @@
private static final String FILTER = "Filter.label"; //$NON-NLS-1$
private static final String FILTERED_LABEL = "Filtered.label"; //$NON-NLS-1$
private static final String FILTERED_TOOLTIP = "FilteredImages.tooltip";
//$NON-NLS-1$
-
-
+
private TableViewer viewer;
private Composite container;
private Combo cloudSelector;
private Label filterLabel;
private DeltaCloudInstance selectedElement;
-
+
private DeltaCloud[] clouds;
private DeltaCloud currCloud;
-
+
private InstanceViewLabelAndContentProvider contentProvider;
-
- private Action refreshAction;
- private Action filterAction;
- private Action startAction;
- private Action stopAction;
- private Action destroyAction;
- private Action rebootAction;
- private Action rseAction;
-
- private Map<String, Action> instanceActions;
-
+
+ private IAction refreshAction;
+ private IAction filterAction;
+ private IAction startAction;
+ private IAction stopAction;
+ private IAction destroyAction;
+ private IAction rebootAction;
+ private IAction rseAction;
+
+ private HashMap<String, IAction> instanceActions;
+
private InstanceView parentView;
public InstanceView() {
@@ -134,17 +141,13 @@
@Override
public void modifyText(ModifyEvent e) {
int index = cloudSelector.getSelectionIndex();
- if (currCloud != null)
+ if (currCloud != null) {
currCloud.removeInstanceListListener(parentView);
+ }
currCloud = clouds[index];
- Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- try {
- prefs.put(IDeltaCloudPreferenceConstants.LAST_CLOUD_INSTANCE_VIEW,
currCloud.getName());
- } catch(Exception exc) {
- // do nothing
- }
- viewer.setInput(new DeltaCloudInstance[0]);
- viewer.refresh();
+ storeSelectedCloud();
+// viewer.setInput(new DeltaCloudInstance[0]);
+// viewer.refresh();
Display.getCurrent().asyncExec(new Runnable() {
@Override
@@ -153,37 +156,47 @@
currCloud.addInstanceListListener(parentView);
viewer.refresh();
}
-
+
});
}
-
+
+ private void storeSelectedCloud() {
+ Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
+ try {
+ prefs.put(IDeltaCloudPreferenceConstants.LAST_CLOUD_INSTANCE_VIEW,
currCloud.getName());
+ } catch (Exception exc) {
+ // do nothing
+ }
+ }
+
};
-
+
private class ColumnListener extends SelectionAdapter {
-
+
private int column;
private TableViewer viewer;
-
+
public ColumnListener(int column, TableViewer viewer) {
this.column = column;
this.viewer = viewer;
}
+
@Override
public void widgetSelected(SelectionEvent e) {
- InstanceComparator comparator = (InstanceComparator)viewer.getComparator();
+ InstanceComparator comparator = (InstanceComparator) viewer.getComparator();
Table t = viewer.getTable();
if (comparator.getColumn() == column) {
comparator.reverseDirection();
}
comparator.setColumn(column);
- TableColumn tc = (TableColumn)e.getSource();
+ TableColumn tc = (TableColumn) e.getSource();
t.setSortColumn(tc);
t.setSortDirection(SWT.NONE);
viewer.refresh();
}
-
+
};
-
+
@Override
public void dispose() {
for (DeltaCloud cloud : clouds) {
@@ -192,7 +205,7 @@
DeltaCloudManager.getDefault().removeCloudManagerListener(this);
super.dispose();
}
-
+
@Override
public void createPartControl(Composite parent) {
container = new Composite(parent, SWT.NULL);
@@ -200,52 +213,16 @@
layout.marginHeight = 0;
layout.marginWidth = 0;
container.setLayout(layout);
-
- Label cloudSelectorLabel = new Label(container, SWT.NULL);
- cloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
-
- cloudSelector = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
- initializeCloudSelector();
- cloudSelector.addModifyListener(cloudModifyListener);
- // Following is a kludge so that on Linux the Combo is read-only but
- // has a white background.
- cloudSelector.addVerifyListener(new VerifyListener() {
- @Override
- public void verifyText(VerifyEvent e) {
- e.doit = false;
- }
- });
-
+
+ Label cloudSelectorLabel = createCloudSelector();
+
filterLabel = new Label(container, SWT.NULL);
filterLabel.setText(CVMessages.getString(FILTERED_LABEL));
filterLabel.setToolTipText(CVMessages.getString(FILTERED_TOOLTIP));
-
+
Composite tableArea = new Composite(container, SWT.NULL);
- TableColumnLayout tableLayout = new TableColumnLayout();
- tableArea.setLayout(tableLayout);
-
- viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
- Table table = viewer.getTable();
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- contentProvider = new InstanceViewLabelAndContentProvider();
- viewer.setContentProvider(contentProvider);
- viewer.setLabelProvider(contentProvider);
- InstanceComparator comparator = new InstanceComparator(0);
- viewer.setComparator(comparator);
-
- for (int i = 0; i < InstanceViewLabelAndContentProvider.Column.getSize(); ++i) {
- InstanceViewLabelAndContentProvider.Column c =
- InstanceViewLabelAndContentProvider.Column.getColumn(i);
- TableColumn tc = new TableColumn(table, SWT.NONE);
- if (i == 0)
- table.setSortColumn(tc);
- tc.setText(CVMessages.getString(c.name()));
- tableLayout.setColumnData(tc, new ColumnWeightData(c.getWeight(), true));
- tc.addSelectionListener(new ColumnListener(i, viewer));
- }
- table.setSortDirection(SWT.NONE);
-
+ createTableViewer(tableArea);
+
if (currCloud != null) {
currCloud.removeInstanceListListener(parentView);
viewer.setInput(currCloud);
@@ -262,7 +239,7 @@
f.top = new FormAttachment(0, 5 + centering);
f.left = new FormAttachment(0, 30);
cloudSelectorLabel.setLayoutData(f);
-
+
f = new FormData();
f.top = new FormAttachment(0, 5);
f.left = new FormAttachment(cloudSelectorLabel, 5);
@@ -279,17 +256,62 @@
f.right = new FormAttachment(100, 0);
f.bottom = new FormAttachment(100, 0);
tableArea.setLayoutData(f);
-
+
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
"org.jboss.tools.deltacloud.ui.viewer");
makeActions();
hookContextMenu();
hookSelection();
contributeToActionBars();
-
+
DeltaCloudManager.getDefault().addCloudManagerListener(this);
}
-
+
+ private void createTableViewer(Composite tableArea) {
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableArea.setLayout(tableLayout);
+
+ viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER | SWT.MULTI);
+ Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ contentProvider = new InstanceViewLabelAndContentProvider();
+ viewer.setContentProvider(contentProvider);
+ viewer.setLabelProvider(contentProvider);
+ InstanceComparator comparator = new InstanceComparator(0);
+ viewer.setComparator(comparator);
+
+ for (int i = 0; i < InstanceViewLabelAndContentProvider.Column.getSize(); ++i) {
+ InstanceViewLabelAndContentProvider.Column c =
+ InstanceViewLabelAndContentProvider.Column.getColumn(i);
+ TableColumn tc = new TableColumn(table, SWT.NONE);
+ if (i == 0)
+ table.setSortColumn(tc);
+ tc.setText(CVMessages.getString(c.name()));
+ tableLayout.setColumnData(tc, new ColumnWeightData(c.getWeight(), true));
+ tc.addSelectionListener(new ColumnListener(i, viewer));
+ }
+ table.setSortDirection(SWT.NONE);
+ }
+
+ private Label createCloudSelector() {
+ Label cloudSelectorLabel = new Label(container, SWT.NULL);
+ cloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
+
+ cloudSelector = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
+ initializeCloudSelector();
+ cloudSelector.addModifyListener(cloudModifyListener);
+ // Following is a kludge so that on Linux the Combo is read-only but
+ // has a white background.
+ cloudSelector.addVerifyListener(new VerifyListener() {
+ @Override
+ public void verifyText(VerifyEvent e) {
+ e.doit = false;
+ }
+ });
+ return cloudSelectorLabel;
+ }
+
private void hookSelection() {
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
@@ -298,7 +320,7 @@
}
});
}
-
+
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
@@ -320,7 +342,7 @@
private void handleSelection() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
- selectedElement = (DeltaCloudInstance)selection.getFirstElement();
+ selectedElement = (DeltaCloudInstance) selection.getFirstElement();
instanceActions.get(DeltaCloudInstance.START).setEnabled(false);
instanceActions.get(DeltaCloudInstance.STOP).setEnabled(false);
instanceActions.get(DeltaCloudInstance.REBOOT).setEnabled(false);
@@ -332,7 +354,7 @@
}
}
}
-
+
private void fillLocalPullDown(IMenuManager manager) {
manager.add(refreshAction);
manager.add(filterAction);
@@ -362,7 +384,7 @@
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
-
+
private void fillLocalToolBar(IToolBarManager manager) {
manager.add(instanceActions.get(DeltaCloudInstance.START));
manager.add(instanceActions.get(DeltaCloudInstance.STOP));
@@ -371,134 +393,32 @@
}
private void makeActions() {
- refreshAction = new Action() {
- public void run() {
- Thread t = new Thread(new Runnable() {
+ this.refreshAction = createRefreshAction();
+ this.filterAction = createFilterAction();
+ this.startAction = createStartAction();
+ this.stopAction = createStopAction();
+ this.rebootAction = createRebootAction();
+ this.destroyAction = createDestroyAction();
+ this.rseAction = createRseAction();
- @Override
- public void run() {
- if (currCloud != null) {
- currCloud.getInstances();
- }
- }
+ instanceActions = new HashMap<String, IAction>();
+ instanceActions.put(DeltaCloudInstance.START, startAction);
+ instanceActions.put(DeltaCloudInstance.STOP, stopAction);
+ instanceActions.put(DeltaCloudInstance.REBOOT, rebootAction);
+ instanceActions.put(DeltaCloudInstance.DESTROY, destroyAction);
+ }
- });
- t.start();
- }
- };
- refreshAction.setText(CVMessages.getString(REFRESH));
- refreshAction.setToolTipText(CVMessages.getString(REFRESH));
- refreshAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
- getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
-
- filterAction = new Action() {
+ private IAction createRseAction() {
+ IAction rseAction = new Action() {
public void run() {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- // TODO Auto-generated method stub
- Shell shell = viewer.getControl().getShell();
- IWizard wizard = new InstanceFilter(currCloud);
- WizardDialog dialog = new WizardDialog(shell, wizard);
- dialog.create();
- dialog.open();
- if (!currCloud.getInstanceFilter().toString().equals(IInstanceFilter.ALL_STRING))
- filterLabel.setVisible(true);
- else
- filterLabel.setVisible(false);
- }
-
- });
- }
- };
- filterAction.setText(CVMessages.getString(FILTER));
- filterAction.setToolTipText(CVMessages.getString(FILTER));
-
- startAction = new Action() {
- public void run() {
ISelection selection = viewer.getSelection();
- DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
- PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.START,
- CVMessages.getString(STARTING_INSTANCE_TITLE),
- CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new
String[]{instance.getName()}),
- DeltaCloudInstance.RUNNING);
- t.setUser(true);
- t.schedule();
- }
- };
- startAction.setText(CVMessages.getString(START_LABEL));
- startAction.setToolTipText(CVMessages.getString(START_LABEL));
- startAction.setImageDescriptor(SWTImagesFactory.DESC_START);
- startAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_STARTD);
- startAction.setEnabled(false);
-
- stopAction = new Action() {
- public void run() {
- ISelection selection = viewer.getSelection();
- DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
- PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.STOP,
- CVMessages.getString(STOPPING_INSTANCE_TITLE),
- CVMessages.getFormattedString(STOPPING_INSTANCE_MSG, new
String[]{instance.getName()}),
- DeltaCloudInstance.STOPPED);
- t.setUser(true);
- t.schedule();
- }
- };
- stopAction.setText(CVMessages.getString(STOP_LABEL));
- stopAction.setToolTipText(CVMessages.getString(STOP_LABEL));
- stopAction.setImageDescriptor(SWTImagesFactory.DESC_STOP);
- stopAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_STOPD);
- stopAction.setEnabled(false);
-
- rebootAction = new Action() {
- public void run() {
- ISelection selection = viewer.getSelection();
- DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
- PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.REBOOT,
- CVMessages.getString(REBOOTING_INSTANCE_TITLE),
- CVMessages.getFormattedString(REBOOTING_INSTANCE_MSG, new
String[]{instance.getName()}),
- DeltaCloudInstance.RUNNING);
- t.setUser(true);
- t.schedule();
- }
- };
- rebootAction.setText(CVMessages.getString(REBOOT_LABEL));
- rebootAction.setToolTipText(CVMessages.getString(REBOOT_LABEL));
- rebootAction.setImageDescriptor(SWTImagesFactory.DESC_REBOOT);
- rebootAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_REBOOTD);
- rebootAction.setEnabled(false);
-
- destroyAction = new Action() {
- public void run() {
- ISelection selection = viewer.getSelection();
- DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
- PerformDestroyInstanceActionThread t = new
PerformDestroyInstanceActionThread(currCloud, instance,
- CVMessages.getString(DESTROYING_INSTANCE_TITLE),
- CVMessages.getFormattedString(DESTROYING_INSTANCE_MSG, new
String[]{instance.getName()}));
- t.setUser(true);
- t.schedule();
- }
- };
- destroyAction.setText(CVMessages.getString(DESTROY_LABEL));
- destroyAction.setToolTipText(CVMessages.getString(DESTROY_LABEL));
- ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
- ImageDescriptor delete =
ImageDescriptor.createFromImage(sharedImages.getImage(ISharedImages.IMG_ETOOL_DELETE));
- ImageDescriptor delete_disabled =
ImageDescriptor.createFromImage(sharedImages.getImage(ISharedImages.IMG_ETOOL_DELETE_DISABLED));
- destroyAction.setImageDescriptor(delete);
- destroyAction.setDisabledImageDescriptor(delete_disabled);
- destroyAction.setEnabled(false);
-
- rseAction = new Action() {
- public void run() {
- ISelection selection = viewer.getSelection();
- DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
+ DeltaCloudInstance instance = (DeltaCloudInstance) ((IStructuredSelection)
selection).getFirstElement();
String hostname = instance.getHostName();
ISystemRegistry registry = SystemStartHere.getSystemRegistry();
RSECorePlugin rsep = RSECorePlugin.getDefault();
IRSECoreRegistry coreRegistry = rsep.getCoreRegistry();
IRSESystemType[] sysTypes = coreRegistry.getSystemTypes();
- IRSESystemType sshType = null;
+ IRSESystemType sshType = null;
for (IRSESystemType sysType : sysTypes) {
if (sysType.getId().equals(IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID))
sshType = sysType;
@@ -520,15 +440,18 @@
@Override
public void run() {
try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.rse.ui.view.systemView");
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage()
+ .showView("org.eclipse.rse.ui.view.systemView");
} catch (PartInitException e) {
- // TODO Auto-generated catch block
+ // TODO Auto-generated catch
+ // block
Activator.log(e);
}
}
});
return Status.OK_STATUS;
- } catch(Exception e) {
+ } catch (Exception e) {
return Status.CANCEL_STATUS;
}
}
@@ -543,12 +466,13 @@
@Override
public void run() {
try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.rse.ui.view.systemView");
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .showView("org.eclipse.rse.ui.view.systemView");
} catch (PartInitException e) {
Activator.log(e);
}
}
-
+
});
}
} catch (Exception e) {
@@ -559,20 +483,153 @@
};
rseAction.setText(CVMessages.getString(RSE_LABEL));
rseAction.setToolTipText(CVMessages.getString(RSE_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);
+ return rseAction;
}
-
+
+ private IAction createDestroyAction() {
+ IAction destroyAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance = (DeltaCloudInstance) ((IStructuredSelection)
selection).getFirstElement();
+ PerformDestroyInstanceActionThread t = new
PerformDestroyInstanceActionThread(currCloud, instance,
+ CVMessages.getString(DESTROYING_INSTANCE_TITLE),
+ CVMessages.getFormattedString(DESTROYING_INSTANCE_MSG, new String[] {
instance.getName() }));
+ t.setUser(true);
+ t.schedule();
+ }
+ };
+ destroyAction.setText(CVMessages.getString(DESTROY_LABEL));
+ destroyAction.setToolTipText(CVMessages.getString(DESTROY_LABEL));
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ ImageDescriptor delete =
ImageDescriptor.createFromImage(sharedImages.getImage(ISharedImages.IMG_ETOOL_DELETE));
+ ImageDescriptor delete_disabled = ImageDescriptor.createFromImage(sharedImages
+ .getImage(ISharedImages.IMG_ETOOL_DELETE_DISABLED));
+ destroyAction.setImageDescriptor(delete);
+ destroyAction.setDisabledImageDescriptor(delete_disabled);
+ destroyAction.setEnabled(false);
+ return destroyAction;
+ }
+
+ private IAction createStopAction() {
+ IAction stopAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance = (DeltaCloudInstance) ((IStructuredSelection)
selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
+ DeltaCloudInstance.STOP,
+ CVMessages.getString(STOPPING_INSTANCE_TITLE),
+ CVMessages.getFormattedString(STOPPING_INSTANCE_MSG, new String[] {
instance.getName() }),
+ DeltaCloudInstance.STOPPED);
+ t.setUser(true);
+ t.schedule();
+ }
+ };
+ stopAction.setText(CVMessages.getString(STOP_LABEL));
+ stopAction.setToolTipText(CVMessages.getString(STOP_LABEL));
+ stopAction.setImageDescriptor(SWTImagesFactory.DESC_STOP);
+ stopAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_STOPD);
+ stopAction.setEnabled(false);
+ return stopAction;
+ }
+
+ private IAction createRebootAction() {
+ IAction rebootAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance = (DeltaCloudInstance) ((IStructuredSelection)
selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
+ DeltaCloudInstance.REBOOT,
+ CVMessages.getString(REBOOTING_INSTANCE_TITLE),
+ CVMessages.getFormattedString(REBOOTING_INSTANCE_MSG, new String[] {
instance.getName() }),
+ DeltaCloudInstance.RUNNING);
+ t.setUser(true);
+ t.schedule();
+ }
+ };
+ rebootAction.setText(CVMessages.getString(REBOOT_LABEL));
+ rebootAction.setToolTipText(CVMessages.getString(REBOOT_LABEL));
+ rebootAction.setImageDescriptor(SWTImagesFactory.DESC_REBOOT);
+ rebootAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_REBOOTD);
+ rebootAction.setEnabled(false);
+ return rebootAction;
+ }
+
+ private IAction createStartAction() {
+ IAction startAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ DeltaCloudInstance instance = (DeltaCloudInstance) ((IStructuredSelection)
selection).getFirstElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
+ DeltaCloudInstance.START,
+ CVMessages.getString(STARTING_INSTANCE_TITLE),
+ CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new String[] {
instance.getName() }),
+ DeltaCloudInstance.RUNNING);
+ t.setUser(true);
+ t.schedule();
+ }
+ };
+ startAction.setText(CVMessages.getString(START_LABEL));
+ startAction.setToolTipText(CVMessages.getString(START_LABEL));
+ startAction.setImageDescriptor(SWTImagesFactory.DESC_START);
+ startAction.setDisabledImageDescriptor(SWTImagesFactory.DESC_STARTD);
+ startAction.setEnabled(false);
+ return startAction;
+ }
+
+ private IAction createFilterAction() {
+ IAction filterAction = new Action() {
+ public void run() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ Shell shell = viewer.getControl().getShell();
+ IWizard wizard = new InstanceFilter(currCloud);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ dialog.create();
+ dialog.open();
+ if (!currCloud.getInstanceFilter().toString().equals(IInstanceFilter.ALL_STRING))
+ filterLabel.setVisible(true);
+ else
+ filterLabel.setVisible(false);
+ }
+
+ });
+ }
+ };
+ filterAction.setText(CVMessages.getString(FILTER));
+ filterAction.setToolTipText(CVMessages.getString(FILTER));
+ return filterAction;
+ }
+
+ private IAction createRefreshAction() {
+ IAction refreshAction = new Action() {
+ public void run() {
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ if (currCloud != null) {
+ currCloud.getInstances();
+ }
+ }
+
+ });
+ t.start();
+ }
+ };
+ refreshAction.setText(CVMessages.getString(REFRESH));
+ refreshAction.setToolTipText(CVMessages.getString(REFRESH));
+ refreshAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+ getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
+ return refreshAction;
+ }
+
@Override
public void setFocus() {
- // TODO Auto-generated method stub
+ viewer.getControl().setFocus();
+ }
- }
-
private void initializeCloudSelector() {
int defaultIndex = 0;
clouds = DeltaCloudManager.getDefault().getClouds();
@@ -592,7 +649,7 @@
currCloud = clouds[defaultIndex];
}
}
-
+
public void changeEvent(int type) {
String currName = null;
int currIndex = 0;
@@ -621,7 +678,7 @@
currCloud = null;
cloudSelector.setText("");
viewer.setInput(new DeltaCloudInstance[0]);
- }
+ }
cloudSelector.addModifyListener(cloudModifyListener);
}
@@ -633,7 +690,6 @@
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
- // TODO Auto-generated method stub
currCloud.removeInstanceListListener(parentView);
viewer.setInput(finalList);
currCloud.addInstanceListListener(parentView);