Browse files

Hashing out the details of the EC2 dashboard page.

  • Loading branch information...
1 parent f4e77a4 commit d54f3de334fe0b531bb9767d81c24c5c9cbbe19c @johnsteele committed Nov 15, 2011
View
17 com.steelejr.eclipse.aws.ec2/src/com/steelejr/eclipse/aws/ec2/editor/Ec2Composite.java
@@ -25,6 +25,7 @@
* The tree of instances.
*/
private TreeViewer viewer;
+ private List<Instance> my_instances;
/**
* Current account information.
@@ -40,18 +41,19 @@ public Ec2Composite (Composite parent) {
result = ec2.describeInstances();
List<Reservation> reservations = result.getReservations();
- List<Instance> allInstances = new ArrayList<Instance>();
+ my_instances = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
+
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
- allInstances.add(instance);
+ my_instances.add(instance);
}
}
viewer.setContentProvider(new Ec2InstancesContentProvider());
viewer.setLabelProvider(new Ec2InstancesLabelProvider());
- viewer.setInput(allInstances);
+ viewer.setInput(my_instances);
viewer.getTree().setLayout(new GridLayout());
viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
}
@@ -65,4 +67,13 @@ public Ec2Composite (Composite parent) {
public TreeViewer getViewer () {
return viewer;
}
+
+ /**
+ * Returns the list of Instances.
+ *
+ * @return The list of instances.
+ */
+ public List<Instance> getInstances () {
+ return my_instances;
+ }
}
View
125 com.steelejr.eclipse.aws.ec2/src/com/steelejr/eclipse/aws/ec2/editor/Ec2DashboardPage.java
@@ -1,6 +1,7 @@
package com.steelejr.eclipse.aws.ec2.editor;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -21,17 +22,23 @@
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
+import com.amazonaws.services.ec2.model.Instance;
import com.steelejr.eclipse.aws.dashboard.editor.DashboardPageProxy;
import com.steelejr.eclipse.aws.ec2.Activator;
import com.steelejr.eclipse.aws.util.Ec2Images;
-public class Ec2DashboardPage extends DashboardPageProxy implements ISelectionChangedListener {
+public class Ec2DashboardPage extends DashboardPageProxy {
/**
* The EC2Composite maintains the tree of Ec2 instances.
*/
private Ec2Composite my_ec2Comp;
+ private Ec2DetailsComposite my_ec2Details;
private IWorkbenchPartSite my_site;
+ /**
+ * The currently selected instance.
+ */
+ private Instance my_instance;
@Override
@@ -56,9 +63,6 @@ public void createForm(IManagedForm managedForm, IWorkbenchPartSite site) {
/* Details Section */
createDetailsSection (form, toolkit);
-
- /* Create Web Server Section */
- createServerSection (form, toolkit);
}
@@ -128,18 +132,59 @@ public void widgetSelected(SelectionEvent e) {
// tree of instances.
my_ec2Comp = new Ec2Composite (client);
- // Listen for changed instance.
- my_ec2Comp.getViewer().addSelectionChangedListener(this);
-
// right column.
-
-
+ Composite colComp = toolkit.createComposite(client, SWT.WRAP);
+ layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.marginHeight = 0;
+ colComp.setLayout(layout);
+ GridData data = new GridData ();
+ data.verticalAlignment = SWT.TOP;
+ colComp.setLayoutData(data);
+
+
+ // start
+ final Button startButton = toolkit.createButton(colComp, "Start", SWT.PUSH);
+ startButton.setImage(Activator.getDefault().getImageRegistry().get(Ec2Images.IMG_LAUNCH_RUN));
- client.pack();
- section.pack();
+ // stop
+ final Button stopButton = toolkit.createButton(colComp, "Stop", SWT.PUSH);
+ stopButton.setImage(Activator.getDefault().getImageRegistry().get(Ec2Images.IMG_LAUNCH_STOP));
+
+
+ my_ec2Comp.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection() instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object o = selection.getFirstElement();
+ if (o instanceof Instance) {
+ Instance instance = (Instance) o;
+ // If a different instance was selected.
+ if (instance != my_instance) {
+ my_instance = instance;
+ // Update buttons.
+ startButton.setEnabled(my_instance.getState().getName().equals("stopped"));
+ stopButton.setEnabled(my_instance.getState().getName().equals("running"));
+ // Update details.
+ updateDetails ();
+ }
+ }
+ }
+ }
+ });
+ }
+
+
+ /**
+ * Refreshes the details to the currently selected instance.
+ */
+ private void updateDetails () {
}
+
/**
* Creates the details sections which displays the details of the currently selected
* instance in the instance section.
@@ -163,61 +208,9 @@ private void createDetailsSection (ScrolledForm form, FormToolkit toolkit) {
client.setLayout(layout);
client.setLayoutData(new GridData (GridData.FILL_BOTH));
section.setClient(client);
- toolkit.paintBordersFor(client);
- }
-
-
- private void createServerSection (ScrolledForm form, FormToolkit toolkit) {
- Section section = toolkit.createSection(form.getBody(), Section.TWISTIE | Section.TITLE_BAR | Section.EXPANDED);
- section.setText("Downloads");
- section.setLayout(new GridLayout ());
- GridData data = new GridData ();
- data.horizontalSpan = 2;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.FILL;
- section.setLayoutData(data);
- }
-
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
-
- }
-
-
- /**
- * An class to represent the right column composite.
- *
- * @author John Steele
- */
- private class ButtonComposite {
-
- public ButtonComposite (FormToolkit tookit, Composite parent) {
- createComposite (tookit, parent);
- }
-
-
- private void createComposite (FormToolkit toolkit, Composite parent) {
- Composite colComp = toolkit.createComposite(parent, SWT.WRAP);
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- layout.marginHeight = 0;
- colComp.setLayout(layout);
- GridData data = new GridData ();
- data.verticalAlignment = SWT.TOP;
- colComp.setLayoutData(data);
-
-
- // start
- Button b = toolkit.createButton(colComp, "Start", SWT.PUSH);
- b.setImage(Activator.getDefault().getImageRegistry().get(Ec2Images.IMG_LAUNCH_RUN));
-
- // stop
- b = toolkit.createButton(colComp, "Stop", SWT.PUSH);
- b.setImage(Activator.getDefault().getImageRegistry().get(Ec2Images.IMG_LAUNCH_STOP));
- }
+ toolkit.paintBordersFor(client);
+ // Table of details.
+ my_ec2Details = new Ec2DetailsComposite(client);
}
}
View
56 ...steelejr.eclipse.aws.ec2/src/com/steelejr/eclipse/aws/ec2/editor/Ec2DetailsComposite.java
@@ -0,0 +1,56 @@
+package com.steelejr.eclipse.aws.ec2.editor;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableColumn;
+
+import com.amazonaws.services.ec2.model.Instance;
+
+public class Ec2DetailsComposite {
+
+ private TableViewer my_table;
+
+ public Ec2DetailsComposite (Composite parent) {
+ createTable (parent);
+ }
+
+ private void createTable (Composite parent) {
+ my_table = new TableViewer (parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
+ my_table.getTable().setLinesVisible(true);
+ createColumns ();
+ my_table.setContentProvider(new ArrayContentProvider());
+ }
+
+
+ private void createColumns () {
+ // Name column
+ TableViewerColumn nameViewerColumn = new TableViewerColumn(my_table, SWT.NONE);
+ TableColumn tableColumn = nameViewerColumn.getColumn();
+ tableColumn.setText("Name");
+ tableColumn.setResizable(true);
+ tableColumn.setMoveable(true);
+
+ nameViewerColumn.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Instance instance = (Instance) element;
+ }
+ });
+
+ // Value column
+ TableViewerColumn valueViewerColumn = new TableViewerColumn (my_table, SWT.NONE);
+ tableColumn = valueViewerColumn.getColumn();
+ tableColumn.setText("Value");
+ tableColumn.setResizable(true);
+ tableColumn.setMoveable(true);
+ }
+
+
+ public TableViewer getTable () {
+ return my_table;
+ }
+}

0 comments on commit d54f3de

Please sign in to comment.