*/
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}
*/
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)
*/
composite.getLblAccessPointUrl().setEnabled(false);
composite.getTxtAccessPoint().setEnabled(false);
}
+ wizard.getContainer().updateButtons();
}
/**
return composite;
}
+
+ public void saveLastState() {
+ lastAccessPoint = composite.getTxtAccessPoint().getText();
+ }
+
}