changeset 14:5d798afbad8c

Added Extensions Page
author Andriy Petrus <apetrus@redhat.com>
date Tue, 03 Dec 2013 16:08:13 -0500
parents 7f0e75277fb3
children 4d56e43c487c
files src/thermostatplugin/editors/MultiPageEditor.java
diffstat 1 files changed, 75 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/thermostatplugin/editors/MultiPageEditor.java	Tue Dec 03 10:19:30 2013 -0500
+++ b/src/thermostatplugin/editors/MultiPageEditor.java	Tue Dec 03 16:08:13 2013 -0500
@@ -31,7 +31,11 @@
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
@@ -44,7 +48,6 @@
 import org.eclipse.ui.forms.widgets.FormText;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.forms.widgets.TableWrapData;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.part.FileEditorInput;
@@ -60,7 +63,8 @@
 
 import com.redhat.thermostat.plugin.eclipse.model.PluginModel;
 
-public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener {
+public class MultiPageEditor extends MultiPageEditorPart implements
+        IResourceChangeListener {
 
     private TextEditor editor;
 
@@ -91,6 +95,7 @@
         createOverviewPage();
         createCommandPage();
         createSourcePage();
+        createExtensionPage();
     }
 
     private void createOverviewPage() {
@@ -109,7 +114,6 @@
         pageNameAndIndex.put("Overview", index);
     }
 
-
     private void createOverviewSection(Composite parent) {
         Section section = toolkit.createSection(parent, Section.TITLE_BAR);
         section.setText("General Information");
@@ -122,8 +126,7 @@
                 + "<a href=\"http://icedtea.classpath.org/thermostat\">the homepage</a>. "
                 + "Additional information about plugins is available "
                 + "<a href=\"http://icedtea.classpath.org/wiki/Thermostat/ExtensionTutorial\">here</a>."
-                + "</p>"
-                + "</form>";
+                + "</p>" + "</form>";
         System.out.println(onlineHelp);
         helpText.setText(onlineHelp, true, false);
 
@@ -137,13 +140,14 @@
         Composite sectionData = toolkit.createComposite(section);
         sectionData.setLayout(new TableWrapLayout());
 
-        FormText commandAndExtensionsForm = toolkit.createFormText(sectionData, false);
+        FormText commandAndExtensionsForm = toolkit.createFormText(sectionData,
+                false);
         String formContents = ""
-            + "<form>"
-            + "<p>Plugins provide extends or new commands.</p>"
-            + "<li><a href=\"my:extensions\">Extensions</a>: declares which commands provided by other plugins or thermostat itself should be extended</li>"
-            + "<li><a href=\"my:commands\">Commands</a>: declares new commands provided by this plugin</li>"
-            + "</form>";
+                + "<form>"
+                + "<p>Plugins provide extends or new commands.</p>"
+                + "<li><a href=\"my:extensions\">Extensions</a>: declares which commands provided by other plugins or thermostat itself should be extended</li>"
+                + "<li><a href=\"my:commands\">Commands</a>: declares new commands provided by this plugin</li>"
+                + "</form>";
         commandAndExtensionsForm.setText(formContents, true, false);
 
         section.setClient(sectionData);
@@ -216,6 +220,65 @@
         }
     }
 
+    private void createExtensionPage() {
+        toolkit = new FormToolkit(getContainer().getDisplay());
+        Form form = toolkit.createForm(getContainer());
+        form.setText("Extensions");
+        GridLayout layout = new GridLayout();
+        layout.numColumns = 2;
+        layout.makeColumnsEqualWidth = true;
+        form.getBody().setLayout(layout);
+
+        createExtensionSection(form.getBody());
+
+        createExtensionSection(form.getBody());
+
+        int index = addPage(form);
+        setPageText(index, "Extensions");
+        pageNameAndIndex.put("Extensions", index);
+
+    }
+
+    private void createExtensionSection(Composite parent) {
+        Section section = toolkit.createSection(parent, Section.TITLE_BAR
+                | Section.DESCRIPTION);
+        section.setText("All Extensions");
+        section.setDescription("Add, remove, or modify extensions of the Thermostat plugin.");
+        section.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        Composite sectionData = toolkit.createComposite(section);
+        GridLayout layout = new GridLayout();
+        layout.numColumns = 1;
+        sectionData.setLayout(layout);
+
+        final Table extensionsTable = toolkit
+                .createTable(sectionData, SWT.NULL);
+        extensionsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
+        toolkit.paintBordersFor(sectionData);
+
+        // TODO Make this listener do something useful.
+        extensionsTable.addListener(SWT.Selection, new Listener() {
+            public void handleEvent(Event event) {
+                TableItem item = (TableItem) event.item;
+                System.out.println(item.getText());
+            }
+        });
+        // TODO Add items to the list dynamically
+        new TableItem(extensionsTable, SWT.NONE).setText("Sample Extension 1");
+        new TableItem(extensionsTable, SWT.NONE).setText("Sample Extension 2");
+
+        Button addExtensionButton = toolkit.createButton(sectionData,
+                "Add Extension", SWT.PUSH);
+        addExtensionButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP,
+                false, false));
+        // TODO Add listeners for buttons
+        Button removeExtensionButton = toolkit.createButton(sectionData,
+                "Remove Extension", SWT.PUSH);
+        removeExtensionButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP,
+                false, false));
+
+        section.setClient(sectionData);
+    }
 
     /**
      * The <code>MultiPageEditorPart</code> implementation of this
@@ -378,7 +441,7 @@
                     .newInstance();
             Transformer transformer = transformerFactory.newTransformer();
             DOMSource source = new DOMSource(doc);
-            
+
             String filePath = new String(getFilePath());
             if (!filePath.isEmpty()) {
                 StreamResult result = new StreamResult(new File(filePath));
@@ -400,7 +463,6 @@
         }
     }
 
-
     private String getFilePath() {
         IEditorInput input = getEditorInput();
         IPath path = ((FileEditorInput) input).getPath();