- reload last entered access point in wizard space
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / specimenSearch / SpecimenProviderSelectionController.java
index 2c0d0e57aebe1e34226520935cc89c77a0c94d6b..6cbeaf562a0a51690a53297bf713d209d1f7fa44 100644 (file)
@@ -9,10 +9,12 @@
 */
 package eu.etaxonomy.taxeditor.view.specimenSearch;
 
+import org.eclipse.jface.wizard.IWizard;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
 
 /**
  * Controller class for handling {@link SpecimenProviderSelectionComposite}
@@ -22,21 +24,63 @@ import org.eclipse.swt.widgets.Listener;
  */
 public class SpecimenProviderSelectionController implements Listener{
 
-    private final SpecimenProviderSelectionComposite composite;
+    private SpecimenProviderSelectionComposite composite;
+    private IWizard wizard;
+    private String lastAccessPoint;
+
+    private static SpecimenProviderSelectionController instance;
+
+    public static SpecimenProviderSelectionController getInstance(Composite parent, IWizard wizard){
+        if(instance==null){
+            instance = new SpecimenProviderSelectionController(parent, wizard);
+            return instance;
+        }
+        instance.init(parent, wizard);
+        return instance;
+    }
+
 
     /**
      * Constructs a new controller which will itself construct the composite
      * @param parent the parent {@link Composite} for the one handles by this controller
      */
-    public SpecimenProviderSelectionController(Composite parent) {
+    private SpecimenProviderSelectionController(Composite parent, IWizard wizard) {
+        init(parent, wizard);
+    }
+
+    /**
+     * @param parent
+     * @param wizard
+     */
+    private void init(Composite parent, IWizard wizard) {
+        this.wizard = wizard;
         composite = new SpecimenProviderSelectionComposite(parent, SWT.NONE);
         composite.getBtnBioCaseProvider().addListener(SWT.Selection, this);
         composite.getBtnGbif().addListener(SWT.Selection, this);
+        composite.getTxtAccessPoint().addListener(SWT.Modify, this);
         composite.getBtnGbif().setSelection(true);
         composite.getTxtAccessPoint().setEnabled(false);
         composite.getLblAccessPointUrl().setEnabled(false);
+
+        loadLastState();
+    }
+
+    private void loadLastState() {
+        if(lastAccessPoint!=null){
+            Text text = composite.getTxtAccessPoint();
+            Listener[] listeners = text.getListeners(SWT.Modify);
+            for (int i = 0; i < listeners.length; i++) {
+                text.removeListener(SWT.Modify, listeners[i]);
+            }
+            text.setText(lastAccessPoint);
+            for (int i = 0; i < listeners.length; i++) {
+                text.addListener(SWT.Modify, listeners[i]);
+            }
+
+        }
     }
 
+
     /* (non-Javadoc)
      * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
      */
@@ -50,6 +94,7 @@ public class SpecimenProviderSelectionController implements Listener{
             composite.getLblAccessPointUrl().setEnabled(false);
             composite.getTxtAccessPoint().setEnabled(false);
         }
+        wizard.getContainer().updateButtons();
     }
 
     /**
@@ -59,4 +104,9 @@ public class SpecimenProviderSelectionController implements Listener{
         return composite;
     }
 
+
+    public void saveLastState() {
+        lastAccessPoint = composite.getTxtAccessPoint().getText();
+    }
+
 }