Project

General

Profile

Download (3.49 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.view.specimenSearch;
10

    
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;
17

    
18
/**
19
 * Controller class for handling {@link SpecimenProviderSelectionComposite}
20
 * @author pplitzner
21
 * @date 22.05.2014
22
 *
23
 */
24
public class SpecimenProviderSelectionController implements Listener{
25

    
26
    private SpecimenProviderSelectionComposite composite;
27
    private IWizard wizard;
28
    private String lastAccessPoint;
29

    
30
    private static SpecimenProviderSelectionController instance;
31

    
32
    public static SpecimenProviderSelectionController getInstance(Composite parent, IWizard wizard){
33
        if(instance==null){
34
            instance = new SpecimenProviderSelectionController(parent, wizard);
35
            return instance;
36
        }
37
        instance.init(parent, wizard);
38
        return instance;
39
    }
40

    
41

    
42
    /**
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
45
     */
46
    private SpecimenProviderSelectionController(Composite parent, IWizard wizard) {
47
        init(parent, wizard);
48
    }
49

    
50
    /**
51
     * @param parent
52
     * @param wizard
53
     */
54
    private void init(Composite parent, IWizard wizard) {
55
        this.wizard = 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);
63

    
64
        loadLastState();
65
    }
66

    
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]);
73
            }
74
            text.setText(lastAccessPoint);
75
            for (int i = 0; i < listeners.length; i++) {
76
                text.addListener(SWT.Modify, listeners[i]);
77
            }
78

    
79
        }
80
    }
81

    
82

    
83
    /* (non-Javadoc)
84
     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
85
     */
86
    @Override
87
    public void handleEvent(Event event) {
88
        if(event.widget==composite.getBtnBioCaseProvider()){
89
            composite.getTxtAccessPoint().setEnabled(true);
90
            composite.getLblAccessPointUrl().setEnabled(true);
91
        }
92
        else if(event.widget==composite.getBtnGbif()){
93
            composite.getLblAccessPointUrl().setEnabled(false);
94
            composite.getTxtAccessPoint().setEnabled(false);
95
        }
96
        wizard.getContainer().updateButtons();
97
    }
98

    
99
    /**
100
     * @return the composite
101
     */
102
    public SpecimenProviderSelectionComposite getComposite() {
103
        return composite;
104
    }
105

    
106

    
107
    public void saveLastState() {
108
        lastAccessPoint = composite.getTxtAccessPoint().getText();
109
    }
110

    
111
}
(2-2/4)