changeset 115:d79c9d0a308d

Make dialogs and wizards update dirty state
author Omair Majid <omajid@redhat.com>
date Tue, 04 Mar 2014 15:49:05 -0500
parents 969ba523a22c
children b48371bbae86
files com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/DirtyStateNotifier.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/ExtensionEditPage.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java
diffstat 4 files changed, 56 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java	Tue Mar 04 14:37:29 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java	Tue Mar 04 15:49:05 2014 -0500
@@ -21,7 +21,6 @@
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowLayout;
@@ -40,12 +39,9 @@
 
 import com.redhat.thermostat.tools.eclipse.plugin.BundleInformation;
 import com.redhat.thermostat.tools.eclipse.plugin.Messages;
-import com.redhat.thermostat.tools.eclipse.plugin.editor.Converters.ListToStringConverter;
-import com.redhat.thermostat.tools.eclipse.plugin.editor.Converters.StringToListConverter;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Bundle;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Command;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Environments;
-import com.redhat.thermostat.tools.eclipse.plugin.model.Options;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Plugin;
 
 /**
@@ -53,12 +49,13 @@
  * <p>
  * The details area of the master-details block.
  */
-class CommandEditPage implements IDetailsPage, IChangeListener {
+class CommandEditPage implements IDetailsPage {
 
     private FormToolkit toolkit;
     private Plugin model;
 
     private boolean isDirty = false;
+    private DirtyNotifier dirtyNotifier = new DirtyNotifier();
     private boolean isStale = false;
 
     private Command commandModel;
@@ -93,7 +90,7 @@
     @Override
     public void dispose() {
         if (bindingContext != null) {
-            DataBindingChangeSupport.removeChangeListener(bindingContext, this);
+            DataBindingChangeSupport.removeChangeListener(bindingContext, dirtyNotifier);
             bindingContext.dispose();
         }
     }
@@ -137,7 +134,7 @@
     @Override
     public void selectionChanged(IFormPart part, ISelection selection) {
         if (bindingContext != null) {
-            DataBindingChangeSupport.removeChangeListener(bindingContext, this);
+            DataBindingChangeSupport.removeChangeListener(bindingContext, dirtyNotifier);
             bindingContext.dispose();
         }
 
@@ -148,7 +145,7 @@
         }
 
         bindingContext = initDataBindings();
-        DataBindingChangeSupport.addChangeListener(bindingContext, this);
+        DataBindingChangeSupport.addChangeListener(bindingContext, dirtyNotifier);
     }
 
     @Override
@@ -225,7 +222,7 @@
         editOptions.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                WizardDialog optionsEditDialog = new WizardDialog(contents.getShell(), new OptionsWizard(commandModel));
+                WizardDialog optionsEditDialog = new WizardDialog(contents.getShell(), new OptionsWizard(commandModel, dirtyNotifier));
                 // wizard will update command model as a side-effect if it succeeds
                 optionsEditDialog.open();
             }
@@ -260,6 +257,9 @@
                 if (dialog.open() == Window.OK) {
                     BundleInformation bundleInfo = dialog.getBundleInformation();
                     commandModel.addBundle(new Bundle(bundleInfo.getName(), bundleInfo.getVersion()));
+
+                    // TODO can this be automated through a nested listener?
+                    dirtyNotifier.markDirty();
                 }
             }
         });
@@ -272,6 +272,9 @@
                 Bundle selectedItem = (Bundle)
                         ((IStructuredSelection)bundlesTableViewer.getSelection()).getFirstElement();
                 commandModel.removeBundle(selectedItem);
+
+                // TODO can this be automated through a nested listener?
+                dirtyNotifier.markDirty();
             }
         });
     }
@@ -321,10 +324,17 @@
         return bindingContext;
     }
 
-    @Override
-    public void handleChange(ChangeEvent event) {
-        isDirty = true;
+    class DirtyNotifier implements DirtyStateNotifier, IChangeListener {
+        @Override
+        public void handleChange(ChangeEvent event) {
+            markDirty();
+        }
 
-        form.getEditor().editorDirtyStateChanged();
+        @Override
+        public void markDirty() {
+            isDirty = true;
+
+            form.getEditor().editorDirtyStateChanged();
+        }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/DirtyStateNotifier.java	Tue Mar 04 15:49:05 2014 -0500
@@ -0,0 +1,6 @@
+package com.redhat.thermostat.tools.eclipse.plugin.editor;
+
+public interface DirtyStateNotifier {
+
+    public void markDirty();
+}
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/ExtensionEditPage.java	Tue Mar 04 14:37:29 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/ExtensionEditPage.java	Tue Mar 04 15:49:05 2014 -0500
@@ -36,7 +36,7 @@
 /**
  * Edits aspects of a single extension.
  */
-public class ExtensionEditPage implements IDetailsPage, IChangeListener {
+public class ExtensionEditPage implements IDetailsPage {
 
     private FormToolkit toolkit;
     private Plugin model;
@@ -49,6 +49,7 @@
     private FormPage formPage;
 
     private boolean isDirty = false;
+    private DirtyNotifier dirtyNotifier = new DirtyNotifier();
 
     public ExtensionEditPage(FormPage parent) {
         this.formPage = parent;
@@ -66,7 +67,7 @@
     @Override
     public void dispose() {
         if (bindingContext != null) {
-            DataBindingChangeSupport.removeChangeListener(bindingContext, this);
+            DataBindingChangeSupport.removeChangeListener(bindingContext, dirtyNotifier);
             bindingContext.dispose();
         }
     }
@@ -111,7 +112,7 @@
     @Override
     public void selectionChanged(IFormPart part, ISelection selection) {
         if (bindingContext != null) {
-            DataBindingChangeSupport.removeChangeListener(bindingContext, this);
+            DataBindingChangeSupport.removeChangeListener(bindingContext, dirtyNotifier);
             bindingContext.dispose();
         }
 
@@ -119,7 +120,7 @@
         extensionModel = model.getExtension(extensionName);
 
         bindingContext = initDataBindings();
-        DataBindingChangeSupport.addChangeListener(bindingContext, this);
+        DataBindingChangeSupport.addChangeListener(bindingContext, dirtyNotifier);
     }
 
     @Override
@@ -175,6 +176,9 @@
                 if (dialog.open() == Window.OK) {
                     BundleInformation bundleInfo = dialog.getBundleInformation();
                     extensionModel.addBundle(new Bundle(bundleInfo.getName(), bundleInfo.getVersion()));
+
+                    // TODO can this be automated through a nested listener?
+                    dirtyNotifier.markDirty();
                 }
             }
         });
@@ -187,6 +191,9 @@
                 Bundle selectedItem = (Bundle)
                         ((IStructuredSelection)bundlesTableViewer.getSelection()).getFirstElement();
                 extensionModel.removeBundle(selectedItem);
+
+                // TODO can this be automated through a nested listener?
+                dirtyNotifier.markDirty();
             }
         });
 
@@ -204,11 +211,18 @@
         return bindingContext;
     }
 
-    @Override
-    public void handleChange(ChangeEvent event) {
-        isDirty = true;
+    class DirtyNotifier implements IChangeListener, DirtyStateNotifier {
+        @Override
+        public void handleChange(ChangeEvent event) {
+            markDirty();
+        }
 
-        formPage.getEditor().editorDirtyStateChanged();
+        @Override
+        public void markDirty() {
+            isDirty = true;
+
+            formPage.getEditor().editorDirtyStateChanged();
+        }
     }
 
 }
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java	Tue Mar 04 14:37:29 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java	Tue Mar 04 15:49:05 2014 -0500
@@ -18,7 +18,6 @@
 import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
 import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
 import org.eclipse.jface.databinding.viewers.ViewerProperties;
-import org.eclipse.jface.databinding.wizard.WizardPageSupport;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ListViewer;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -48,11 +47,14 @@
 public class OptionsWizard extends Wizard {
 
     private Command commandModel;
+    private DirtyStateNotifier dirtyHandler;
+
     private Options myOptions;
 
-    public OptionsWizard(Command commandModel) {
+    public OptionsWizard(Command commandModel, DirtyStateNotifier dirtyHandler) {
         setNeedsProgressMonitor(true);
 
+        this.dirtyHandler = dirtyHandler;
         this.commandModel = commandModel;
 
         if (commandModel.getOptions() != null) {
@@ -70,6 +72,7 @@
     @Override
     public boolean performFinish() {
         commandModel.setOptions(myOptions);
+        dirtyHandler.markDirty();
 
         return true;
     }