add first implementation for simple details view
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / specimenSearch / SpecimenProviderSelectionController.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.taxeditor.view.specimenSearch;
11
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;
18
19 /**
20 * Controller class for handling {@link SpecimenProviderSelectionComposite}
21 * @author pplitzner
22 * @date 22.05.2014
23 *
24 */
25 public class SpecimenProviderSelectionController implements Listener{
26
27 private SpecimenProviderSelectionComposite composite;
28 private IWizard wizard;
29 private String lastAccessPoint;
30
31 private static SpecimenProviderSelectionController instance;
32
33 public static SpecimenProviderSelectionController getInstance(Composite parent, IWizard wizard){
34 if(instance==null){
35 instance = new SpecimenProviderSelectionController(parent, wizard);
36 return instance;
37 }
38 instance.init(parent, wizard);
39 return instance;
40 }
41
42
43 /**
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
46 */
47 private SpecimenProviderSelectionController(Composite parent, IWizard wizard) {
48 init(parent, wizard);
49 }
50
51 /**
52 * @param parent
53 * @param wizard
54 */
55 private void init(Composite parent, IWizard wizard) {
56 this.wizard = 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);
64
65 loadLastState();
66 }
67
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]);
74 }
75 text.setText(lastAccessPoint);
76 for (int i = 0; i < listeners.length; i++) {
77 text.addListener(SWT.Modify, listeners[i]);
78 }
79
80 }
81 }
82
83
84 /* (non-Javadoc)
85 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
86 */
87 @Override
88 public void handleEvent(Event event) {
89 if(event.widget==composite.getBtnBioCaseProvider()){
90 composite.getTxtAccessPoint().setEnabled(true);
91 composite.getLblAccessPointUrl().setEnabled(true);
92 }
93 else if(event.widget==composite.getBtnGbif()){
94 composite.getLblAccessPointUrl().setEnabled(false);
95 composite.getTxtAccessPoint().setEnabled(false);
96 }
97 wizard.getContainer().updateButtons();
98 }
99
100 /**
101 * @return the composite
102 */
103 public SpecimenProviderSelectionComposite getComposite() {
104 return composite;
105 }
106
107
108 public void saveLastState() {
109 lastAccessPoint = composite.getTxtAccessPoint().getText();
110 }
111
112 }