2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.view
.specimenSearch
;
11 import org
.eclipse
.jface
.wizard
.IWizard
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.widgets
.Combo
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Event
;
16 import org
.eclipse
.swt
.widgets
.Listener
;
19 * Controller class for handling {@link SpecimenProviderSelectionComposite}
24 public class SpecimenProviderSelectionController
implements Listener
{
26 private SpecimenProviderSelectionComposite composite
;
27 private IWizard wizard
;
28 private String lastAccessPoint
;
30 private static SpecimenProviderSelectionController instance
;
32 public static SpecimenProviderSelectionController
getInstance(Composite parent
, IWizard wizard
){
34 instance
= new SpecimenProviderSelectionController(parent
, wizard
);
37 instance
.init(parent
, wizard
);
43 * Constructs a new controller which will itself construct the composite
44 * @param parent the parent {@link Composite} for the one handles by this controller
46 private SpecimenProviderSelectionController(Composite parent
, IWizard wizard
) {
54 private void init(Composite parent
, IWizard wizard
) {
56 composite
= new SpecimenProviderSelectionComposite(parent
, SWT
.NONE
);
57 composite
.getBtnBioCaseProvider().addListener(SWT
.Selection
, this);
58 composite
.getBtnGbif().addListener(SWT
.Selection
, this);
59 composite
.getTxtAccessPoint().addListener(SWT
.Modify
, this);
60 composite
.getBtnGbif().setSelection(true);
61 composite
.getTxtAccessPoint().setEnabled(false);
62 composite
.getLblAccessPointUrl().setEnabled(false);
67 private void loadLastState() {
68 if(lastAccessPoint
!=null){
69 Combo text
= composite
.getTxtAccessPoint();
70 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
71 for (int i
= 0; i
< listeners
.length
; i
++) {
72 text
.removeListener(SWT
.Modify
, listeners
[i
]);
74 text
.setText(lastAccessPoint
);
75 for (int i
= 0; i
< listeners
.length
; i
++) {
76 text
.addListener(SWT
.Modify
, listeners
[i
]);
84 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
87 public void handleEvent(Event event
) {
88 if(event
.widget
==composite
.getBtnBioCaseProvider()){
89 composite
.getTxtAccessPoint().setEnabled(true);
90 composite
.getLblAccessPointUrl().setEnabled(true);
92 else if(event
.widget
==composite
.getBtnGbif()){
93 composite
.getLblAccessPointUrl().setEnabled(false);
94 composite
.getTxtAccessPoint().setEnabled(false);
96 wizard
.getContainer().updateButtons();
100 * @return the composite
102 public SpecimenProviderSelectionComposite
getComposite() {
107 public void saveLastState() {
108 lastAccessPoint
= composite
.getTxtAccessPoint().getText();