3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.view
.specimenSearch
;
12 import org
.eclipse
.jface
.wizard
.IWizard
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Event
;
16 import org
.eclipse
.swt
.widgets
.Listener
;
17 import org
.eclipse
.swt
.widgets
.Text
;
20 * Controller class for handling {@link SpecimenProviderSelectionComposite}
25 public class SpecimenProviderSelectionController
implements Listener
{
27 private SpecimenProviderSelectionComposite composite
;
28 private IWizard wizard
;
29 private String lastAccessPoint
;
31 private static SpecimenProviderSelectionController instance
;
33 public static SpecimenProviderSelectionController
getInstance(Composite parent
, IWizard wizard
){
35 instance
= new SpecimenProviderSelectionController(parent
, wizard
);
38 instance
.init(parent
, wizard
);
44 * Constructs a new controller which will itself construct the composite
45 * @param parent the parent {@link Composite} for the one handles by this controller
47 private SpecimenProviderSelectionController(Composite parent
, IWizard wizard
) {
55 private void init(Composite parent
, IWizard wizard
) {
57 composite
= new SpecimenProviderSelectionComposite(parent
, SWT
.NONE
);
58 composite
.getBtnBioCaseProvider().addListener(SWT
.Selection
, this);
59 composite
.getBtnGbif().addListener(SWT
.Selection
, this);
60 composite
.getTxtAccessPoint().addListener(SWT
.Modify
, this);
61 composite
.getBtnGbif().setSelection(true);
62 composite
.getTxtAccessPoint().setEnabled(false);
63 composite
.getLblAccessPointUrl().setEnabled(false);
68 private void loadLastState() {
69 if(lastAccessPoint
!=null){
70 Text text
= composite
.getTxtAccessPoint();
71 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
72 for (int i
= 0; i
< listeners
.length
; i
++) {
73 text
.removeListener(SWT
.Modify
, listeners
[i
]);
75 text
.setText(lastAccessPoint
);
76 for (int i
= 0; i
< listeners
.length
; i
++) {
77 text
.addListener(SWT
.Modify
, listeners
[i
]);
85 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
88 public void handleEvent(Event event
) {
89 if(event
.widget
==composite
.getBtnBioCaseProvider()){
90 composite
.getTxtAccessPoint().setEnabled(true);
91 composite
.getLblAccessPointUrl().setEnabled(true);
93 else if(event
.widget
==composite
.getBtnGbif()){
94 composite
.getLblAccessPointUrl().setEnabled(false);
95 composite
.getTxtAccessPoint().setEnabled(false);
97 wizard
.getContainer().updateButtons();
101 * @return the composite
103 public SpecimenProviderSelectionComposite
getComposite() {
108 public void saveLastState() {
109 lastAccessPoint
= composite
.getTxtAccessPoint().getText();