Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.ui.dialog.configurator;
10

    
11
import org.eclipse.core.databinding.DataBindingContext;
12
import org.eclipse.core.databinding.beans.PojoProperties;
13
import org.eclipse.core.databinding.observable.value.IObservableValue;
14
import org.eclipse.jface.databinding.swt.WidgetProperties;
15
import org.eclipse.jface.wizard.Wizard;
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Event;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Listener;
26
import org.eclipse.swt.widgets.Text;
27
import org.eclipse.ui.forms.widgets.FormToolkit;
28
import org.eclipse.wb.swt.ResourceManager;
29

    
30
import eu.etaxonomy.cdm.api.service.config.SetSecundumForSubtreeConfigurator;
31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.taxeditor.Messages;
33
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
34
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35

    
36
/**
37
 * @author k.luther
38
 * @date 10.02.2017
39
 *
40
 */
41
public class SetSecundumConfiguratorWizardPage extends WizardPage implements Listener{
42
    private DataBindingContext m_bindingContext;
43

    
44
    private final FormToolkit toolkit = new CdmFormFactory(Display.getCurrent());
45
    private final SetSecundumForSubtreeConfigurator configurator;
46

    
47
    private  Button btnBrowseReference = null;
48
    private  Text textReference = null;
49
    private  Button btnClear = null;
50

    
51
    private  Button btnIncludeAcceptedTaxa;
52
    private Button btnIncludeSynonyms;
53
    private Button btnOverwriteExistingAccepted;
54
    private Button btnOverwriteExistingSynonyms;
55
    private Button btnEmptySecundumDetail;
56
    private Button btnIncludeSharedTaxa;
57

    
58

    
59
    /**
60
     * Create the composite.
61
     * @param parent
62
     * @param style
63
     */
64
    public SetSecundumConfiguratorWizardPage(SetSecundumForSubtreeConfigurator configurator, Wizard parent, int style ) {
65
        super("Set Secundum Reference Configuration");
66
        this.configurator = configurator;
67

    
68
//        addDisposeListener(new DisposeListener() {
69
//            @Override
70
//            public void widgetDisposed(DisposeEvent e) {
71
//                toolkit.dispose();
72
//            }
73
//        });
74
      //  toolkit.paintBordersFor(this);
75
//        setLayout(new GridLayout());
76
//        setBackground(getBackground());
77

    
78

    
79

    
80

    
81
    }
82

    
83
    /**
84
     * @return
85
     */
86
    private DataBindingContext initDataBindings() {
87
        DataBindingContext bindingContext = new DataBindingContext();
88

    
89
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
90
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
91
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
92

    
93
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
94
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
95
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue, null, null);
96

    
97
        IObservableValue observeSelectionBtnOverwriteExistingAccepted = WidgetProperties.selection().observe(btnOverwriteExistingAccepted);
98
        IObservableValue overwriteExistingAcceptedConfiguratorObserveValue = PojoProperties.value("overwriteExistingAccepted").observe(configurator);
99
        bindingContext.bindValue(observeSelectionBtnOverwriteExistingAccepted, overwriteExistingAcceptedConfiguratorObserveValue, null, null);
100

    
101
        IObservableValue observeSelectionBtnOverwriteExistingSynonyms = WidgetProperties.selection().observe(btnOverwriteExistingSynonyms);
102
        IObservableValue overwriteExistingSynonymsConfiguratorObserveValue = PojoProperties.value("overwriteExistingSynonyms").observe(configurator);
103
        bindingContext.bindValue(observeSelectionBtnOverwriteExistingSynonyms, overwriteExistingSynonymsConfiguratorObserveValue, null, null);
104

    
105
        IObservableValue observeSelectionBtnEmptySecundumDetail = WidgetProperties.selection().observe(btnEmptySecundumDetail);
106
        IObservableValue emptySecundumDetailConfiguratorObserveValue = PojoProperties.value("emptySecundumDetail").observe(configurator);
107
        bindingContext.bindValue(observeSelectionBtnEmptySecundumDetail, emptySecundumDetailConfiguratorObserveValue, null, null);
108

    
109
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
110
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
111
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue, null, null);
112
        return bindingContext;
113
    }
114

    
115
    @Override
116
    public void createControl(Composite parent) {
117

    
118
        final Composite composite = new Composite(parent, SWT.NULL);
119

    
120
        GridLayout gridLayout = new GridLayout();
121
        gridLayout.numColumns = 1;
122

    
123
        composite.setLayout(gridLayout);
124
        final Composite compositeRef = new Composite(composite, SWT.NULL);
125

    
126
        GridLayout gridLayoutRef = new GridLayout();
127
        gridLayoutRef.numColumns = 4;
128

    
129
        compositeRef.setLayout(gridLayoutRef);
130
        compositeRef.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
131
        Label label = new Label(compositeRef, SWT.NONE);
132
        label.setText(Messages.SetSecundumConfiguration_NewSecundum_Label);
133
        //label.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false));
134

    
135
        textReference = new Text(compositeRef, SWT.BORDER);
136
        textReference.setEditable(false);
137
        textReference.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
138
        textReference.setTextLimit(Text.LIMIT);
139

    
140
        btnBrowseReference = new Button(compositeRef, SWT.NONE);
141
        btnBrowseReference.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
142
        btnBrowseReference.addListener(SWT.Selection, this);
143
        btnClear = new Button(compositeRef, SWT.NONE);
144
        btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
145
        btnClear.addListener(SWT.Selection, this);
146

    
147
        final Composite control = new Composite(composite, SWT.NULL);
148
        GridLayout gridLayoutControl = new GridLayout();
149
        gridLayoutControl.numColumns = 1;
150

    
151
        control.setLayout(gridLayoutControl);
152
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
153
      //  Composite control = toolkit.createComposite(composite);
154
        btnIncludeAcceptedTaxa = new Button(control, SWT.CHECK);
155
        btnIncludeAcceptedTaxa.setText(Messages.SetSecundumConfiguration_IncludeAcceptedTaxa);
156
        btnIncludeAcceptedTaxa.setSelection(configurator.isIncludeAcceptedTaxa());
157
        btnIncludeAcceptedTaxa.addListener(SWT.Selection, new Listener() {
158
            @Override
159
         public void handleEvent(Event e) {
160
                Button b = (Button) e.widget;
161
                GridData data = (GridData)  btnIncludeAcceptedTaxa.getLayoutData();
162
                data.exclude = b.getSelection();
163
                btnOverwriteExistingAccepted.setVisible(data.exclude);
164
                btnIncludeSharedTaxa.setVisible(data.exclude);
165
                if (!btnIncludeSynonyms.getSelection() && !data.exclude){
166
                    btnEmptySecundumDetail.setVisible(false);
167
                    setPageComplete(false);
168
                }else{
169
                    btnEmptySecundumDetail.setVisible(true);
170
                    setPageComplete(true);
171
                }
172
            }
173
        });
174

    
175
        btnOverwriteExistingAccepted = new Button(control, SWT.CHECK);
176
        btnOverwriteExistingAccepted.setText(Messages.SetSecundumConfiguration_OverwriteExistingAccepted);
177

    
178
        btnIncludeSynonyms = new Button(control, SWT.CHECK);
179
        btnIncludeSynonyms.setText(Messages.SetSecundumConfiguration_IncludeSynonyms);
180
        btnIncludeSynonyms.setSelection(configurator.isIncludeSynonyms());
181
        btnIncludeSynonyms.addListener(SWT.Selection, new Listener() {
182
            @Override
183
         public void handleEvent(Event e) {
184
                Button b = (Button) e.widget;
185
                GridData data = (GridData)  btnIncludeSynonyms.getLayoutData();
186
                data.exclude = b.getSelection();
187
                btnOverwriteExistingSynonyms.setVisible(data.exclude);
188
                if (!btnIncludeAcceptedTaxa.getSelection() && !data.exclude){
189
                    btnEmptySecundumDetail.setVisible(false);
190
                    setPageComplete(false);
191
                }else{
192
                    btnEmptySecundumDetail.setVisible(true);
193
                    setPageComplete(true);
194
                }
195

    
196
            }
197
        });
198

    
199
        btnOverwriteExistingAccepted.setSelection(configurator.isOverwriteExistingAccepted());
200
        btnOverwriteExistingSynonyms = new Button(control, SWT.CHECK);
201
        btnOverwriteExistingSynonyms.setText(Messages.SetSecundumConfiguration_OverwriteExistingSynonyms);
202
        btnOverwriteExistingSynonyms.setSelection(configurator.isOverwriteExistingSynonyms());
203
        btnEmptySecundumDetail = new Button(control, SWT.CHECK);
204
        btnEmptySecundumDetail.setText(Messages.SetSecundumConfiguration_EmptySecundumDetail);
205
        btnEmptySecundumDetail.setSelection(configurator.isEmptySecundumDetail());
206

    
207
        btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
208
        btnIncludeSharedTaxa.setText(Messages.SetSecundumConfiguration_IncludeSharedtaxa);
209
        btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
210

    
211
        m_bindingContext = initDataBindings();
212
        setControl(composite);
213
    }
214

    
215

    
216

    
217
    @Override
218
    public void handleEvent(Event event) {
219
        Reference reference;
220
        if(event.widget==btnBrowseReference){
221
            reference = SelectionDialogFactory.getSelectionFromDialog(Reference.class, this.getShell(), null, null);
222
            if(reference!=null){
223
                this.configurator.setNewSecundum(reference);
224
                textReference.setText(reference.getTitleCache());
225

    
226
            }
227

    
228
        } else if(event.widget==btnClear){
229
            reference = null;
230
            textReference.setText("");
231
            this.configurator.setNewSecundum(null);
232
        } else{
233
            reference = null;
234
            textReference.setText("");
235
            this.configurator.setNewSecundum(null);
236
        }
237

    
238
    }
239

    
240

    
241

    
242

    
243
}
(2-2/3)