Project

General

Profile

Download (15.3 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.WizardPage;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Button;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.swt.widgets.Listener;
24
import org.eclipse.swt.widgets.Text;
25
import org.eclipse.wb.swt.ResourceManager;
26

    
27
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.taxeditor.l10n.Messages;
30
import eu.etaxonomy.taxeditor.preference.Resources;
31
import eu.etaxonomy.taxeditor.store.StoreUtil;
32
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
33
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
34

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

    
43
    private final SecundumForSubtreeConfigurator configurator;
44

    
45
    private  Button btnBrowseReference = null;
46

    
47
    private Text textReference = null;
48
    private Button btnClear = null;
49
    private EntitySelectionElement<Reference> selectReference;
50
    private Button btnIncludeAcceptedTaxa;
51
    private Button btnIncludeSynonyms;
52
    private Button btnOverwriteExisting;
53
//    private Button btnOverwriteExistingSynonyms;
54
//    private Button btnOverwriteExistingRelations;
55
    private Button btnEmptySecundumDetail;
56
    private Button btnIncludeSharedTaxa;
57
    private Button btnIncludeMisappliedNamed;
58
    private Button btnIncludeProParteSynonyms;
59

    
60

    
61
    /**
62
     * Create the composite.
63
     * @param parent
64
     * @param style
65
     */
66
    public SetSecundumConfiguratorWizardPage(SecundumForSubtreeConfigurator configurator) {
67
        super("Set Secundum Reference Configuration");
68
        this.configurator = configurator;
69

    
70
        this.setDescription(Messages.SetSecundumConfiguration_Description_Configurator);
71
    }
72

    
73
    /**
74
     * @return
75
     */
76
    private DataBindingContext initDataBindings() {
77
        DataBindingContext bindingContext = new DataBindingContext();
78

    
79
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
80
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
81
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
82

    
83
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
84
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
85
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue, null, null);
86

    
87
        IObservableValue observeSelectionBtnIncludeMisappliedNames = WidgetProperties.selection().observe(btnIncludeMisappliedNamed);
88
        IObservableValue includeMisappliedNamesConfiguratorObserveValue = PojoProperties.value("includeMisapplications").observe(configurator);
89
        bindingContext.bindValue(observeSelectionBtnIncludeMisappliedNames, includeMisappliedNamesConfiguratorObserveValue, null, null);
90

    
91
        IObservableValue observeSelectionBtnIncludeProparteSynonyms = WidgetProperties.selection().observe(btnIncludeProParteSynonyms);
92
        IObservableValue includeProparteSynonymsConfiguratorObserveValue = PojoProperties.value("includeProParteSynonyms").observe(configurator);
93
        bindingContext.bindValue(observeSelectionBtnIncludeProparteSynonyms, includeProparteSynonymsConfiguratorObserveValue, null, null);
94

    
95
        IObservableValue observeSelectionBtnOverwriteExisting = WidgetProperties.selection().observe(btnOverwriteExisting);
96
        IObservableValue overwriteExistingConfiguratorObserveValue = PojoProperties.value("overwriteExisting").observe(configurator);
97
        bindingContext.bindValue(observeSelectionBtnOverwriteExisting, overwriteExistingConfiguratorObserveValue, null, null);
98

    
99
        IObservableValue observeSelectionBtnEmptySecundumDetail = WidgetProperties.selection().observe(btnEmptySecundumDetail);
100
        IObservableValue emptySecundumDetailConfiguratorObserveValue = PojoProperties.value("emptySecundumDetail").observe(configurator);
101
        bindingContext.bindValue(observeSelectionBtnEmptySecundumDetail, emptySecundumDetailConfiguratorObserveValue, null, null);
102

    
103
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
104
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
105
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue, null, null);
106
        return bindingContext;
107
    }
108

    
109
    @Override
110
    public void createControl(Composite parent) {
111

    
112
        final Composite composite = new Composite(parent, SWT.NULL);
113
        GridData gridComp = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
114
        gridComp.minimumWidth = 200;
115
        GridLayout gridLayout = new GridLayout();
116

    
117
        gridLayout.numColumns = 1;
118
        composite.setLayoutData(gridComp);
119
        composite.setLayout(gridLayout);
120
        final Composite compositeRef = new Composite(composite, SWT.NULL);
121

    
122
        GridLayout gridLayoutRef = new GridLayout();
123
        gridLayoutRef.numColumns = 4;
124

    
125

    
126
        compositeRef.setLayout(gridLayoutRef);
127
        GridData gridRef = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
128
        compositeRef.setLayoutData(gridRef);
129
        Label label = new Label(compositeRef, SWT.WRAP);
130
        label.setText(Messages.SetSecundumConfiguration_NewSecundum_Label);
131
        label.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
132

    
133
        textReference = new Text(compositeRef, SWT.BORDER);
134
        textReference.setEditable(false);
135
        textReference.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
136
//        textReference.setTextLimit(Text.LIMIT);
137
        textReference.setBackground(StoreUtil
138
                .getColor(Resources.COLOR_TEXT_DISABLED_BACKGROUND));
139
        GridData gridTextReference = new GridData(SWT.FILL, SWT.FILL, true, true);
140
        gridTextReference.widthHint = 20;
141
        gridTextReference.grabExcessHorizontalSpace = true;
142
        textReference.setLayoutData(gridTextReference);
143

    
144
        btnBrowseReference = new Button(compositeRef, SWT.NONE);
145
        btnBrowseReference.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/prj_obj.gif"));
146
        btnBrowseReference.addListener(SWT.Selection, this);
147
        btnBrowseReference.setFocus();
148

    
149
        btnClear = new Button(compositeRef, SWT.NONE);
150
        btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
151
        btnClear.addListener(SWT.Selection, this);
152
        Label labelDescription = new Label(compositeRef, SWT.WRAP);
153
        labelDescription.setText(Messages.SetSecundumConfiguration_Description);
154
        GridData gd_labelDescription = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
155
        gd_labelDescription.horizontalSpan = 4;
156
        labelDescription.setLayoutData(gd_labelDescription);
157
//        new Label(compositeRef, SWT.NONE);
158
//        new Label(compositeRef, SWT.NONE);
159
//        new Label(compositeRef, SWT.NONE);
160

    
161
       // selectReference = toolkit.createSelectionElement(Rights.class, getConversationHolder(), composite, "Rights", null, EntitySelectionElement.SELECTABLE);
162
        final Composite control = new Composite(composite, SWT.WRAP);
163
        GridLayout gridLayoutControl = new GridLayout();
164

    
165
        control.setLayout(gridLayoutControl);
166
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
167
      //  Composite control = toolkit.createComposite(composite);
168
        btnIncludeAcceptedTaxa = new Button(control, SWT.CHECK);
169
        btnIncludeAcceptedTaxa.setText(Messages.SetSecundumConfiguration_IncludeAcceptedTaxa);
170
        btnIncludeAcceptedTaxa.setSelection(configurator.isIncludeAcceptedTaxa());
171
        btnIncludeAcceptedTaxa.addListener(SWT.Selection, new Listener() {
172
            @Override
173
         public void handleEvent(Event e) {
174
                Button b = (Button) e.widget;
175
                GridData data = (GridData)  btnIncludeAcceptedTaxa.getLayoutData();
176
                data.exclude = b.getSelection();
177
                boolean isEnabled = true;
178
                if (!btnIncludeSynonyms.getSelection() && !data.exclude){
179
                    isEnabled = false;
180
                }
181
                btnOverwriteExisting.setVisible(isEnabled);
182
                btnEmptySecundumDetail.setVisible(isEnabled);
183
                btnIncludeSharedTaxa.setVisible(isEnabled);
184
                setPageComplete(isEnabled);
185
            }
186
        });
187

    
188
//                btnOverwriteExistingAccepted = new Button(control, SWT.CHECK);
189
//                GridData gd_btnOverwriteExistingAccepted = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
190
//                gd_btnOverwriteExistingAccepted.horizontalIndent = 10;
191
//                btnOverwriteExistingAccepted.setLayoutData(gd_btnOverwriteExistingAccepted);
192
//                btnOverwriteExistingAccepted.setText(Messages.SetSecundumConfiguration_OverwriteExistingAccepted);
193

    
194

    
195

    
196
        btnIncludeSynonyms = new Button(control, SWT.CHECK);
197
        btnIncludeSynonyms.setText(Messages.SetSecundumConfiguration_IncludeSynonyms);
198
        btnIncludeSynonyms.setSelection(configurator.isIncludeSynonyms());
199
        btnIncludeSynonyms.addListener(SWT.Selection, new Listener() {
200
            @Override
201
         public void handleEvent(Event e) {
202
                Button b = (Button) e.widget;
203
                GridData data = (GridData)  btnIncludeSynonyms.getLayoutData();
204
                data.exclude = b.getSelection();
205
                boolean isEnabled = true;
206
                if (!btnIncludeAcceptedTaxa.getSelection() && !data.exclude && !btnIncludeMisappliedNamed.getSelection() && !btnIncludeProParteSynonyms.getSelection()){
207
                    isEnabled = false;
208
                }
209
                btnEmptySecundumDetail.setVisible(isEnabled);
210
                btnOverwriteExisting.setVisible(isEnabled);
211
                btnIncludeSharedTaxa.setVisible(isEnabled);
212
                setPageComplete(isEnabled);
213

    
214
            }
215
        });
216

    
217
//                btnOverwriteExistingSynonyms = new Button(control, SWT.CHECK);
218
//                GridData gd_btnOverwriteExistingSynonyms = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
219
//                gd_btnOverwriteExistingSynonyms.horizontalIndent = 10;
220
//                btnOverwriteExistingSynonyms.setLayoutData(gd_btnOverwriteExistingSynonyms);
221
//                btnOverwriteExistingSynonyms.setText(Messages.SetSecundumConfiguration_OverwriteExistingSynonyms);
222
//                btnOverwriteExistingSynonyms.setSelection(configurator.isOverwriteExistingSynonyms());
223

    
224
        btnIncludeMisappliedNamed = new Button(control, SWT.CHECK);
225
        btnIncludeMisappliedNamed.setText(Messages.SetSecundumConfiguration_IncludeMisapplications);
226
        btnIncludeMisappliedNamed.setSelection(configurator.isIncludeMisapplications());
227
        btnIncludeMisappliedNamed.addListener(SWT.Selection, new Listener() {
228
            @Override
229
         public void handleEvent(Event e) {
230
                Button b = (Button) e.widget;
231
                GridData data = (GridData)  btnIncludeMisappliedNamed.getLayoutData();
232
                data.exclude = b.getSelection();
233
                boolean isEnabled = true;
234
                if (!btnIncludeAcceptedTaxa.getSelection() && !btnIncludeProParteSynonyms.getSelection() && !btnIncludeSynonyms.getSelection() && !data.exclude){
235
                    isEnabled = false;
236
                }
237
                btnEmptySecundumDetail.setVisible(isEnabled);
238
                btnOverwriteExisting.setVisible(isEnabled);
239
                btnIncludeSharedTaxa.setVisible(isEnabled);
240
                setPageComplete(isEnabled);
241
            }
242
        });
243

    
244

    
245

    
246
        btnIncludeProParteSynonyms = new Button(control, SWT.CHECK);
247
        btnIncludeProParteSynonyms.setText(Messages.SetSecundumConfiguration_IncludeProParteSynonyms);
248
        btnIncludeProParteSynonyms.setSelection(configurator.isIncludeProParteSynonyms());
249
        btnIncludeProParteSynonyms.addListener(SWT.Selection, new Listener() {
250
            @Override
251
         public void handleEvent(Event e) {
252
                Button b = (Button) e.widget;
253
                GridData data = (GridData)  btnIncludeProParteSynonyms.getLayoutData();
254
                data.exclude = b.getSelection();
255
                boolean isEnabled = true;
256
                if (!btnIncludeAcceptedTaxa.getSelection() && !btnIncludeMisappliedNamed.getSelection() && !btnIncludeSynonyms.getSelection() && !data.exclude){
257
                    isEnabled = false;
258
                }
259
                btnEmptySecundumDetail.setVisible(isEnabled);
260
                btnOverwriteExisting.setVisible(isEnabled);
261
                btnIncludeSharedTaxa.setVisible(isEnabled);
262
                setPageComplete(isEnabled);
263
            }
264
        });
265

    
266
        Label space = new Label(control, SWT.NONE);
267
        btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
268
        btnIncludeSharedTaxa.setText(Messages.SetSecundumConfiguration_IncludeSharedtaxa);
269
        btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
270

    
271
        btnOverwriteExisting = new Button(control, SWT.CHECK);
272

    
273
        btnOverwriteExisting.setText(Messages.SetSecundumConfiguration_OverwriteExisting);
274
        btnOverwriteExisting.setSelection(configurator.isOverwriteExisting());
275

    
276

    
277
//        btnOverwriteExistingAccepted.setSelection(configurator.isOverwriteExistingAccepted());
278

    
279
        btnEmptySecundumDetail = new Button(control, SWT.CHECK);
280
        btnEmptySecundumDetail.setText(Messages.SetSecundumConfiguration_EmptySecundumDetail);
281
        btnEmptySecundumDetail.setSelection(configurator.isEmptySecundumDetail());
282

    
283
        m_bindingContext = initDataBindings();
284
        setControl(composite);
285
    }
286

    
287

    
288

    
289
    @Override
290
    public void handleEvent(Event event) {
291
        Reference reference;
292
        if(event.widget==btnBrowseReference){
293
            reference = SelectionDialogFactory.getSelectionFromDialog(Reference.class, this.getShell(), null, null);
294
            if(reference!=null){
295
                this.configurator.setNewSecundum(reference);
296
                textReference.setText(reference.getTitleCache());
297

    
298
            }
299

    
300
        } else if(event.widget==btnClear){
301
            reference = null;
302
            textReference.setText("");
303
            this.configurator.setNewSecundum(null);
304
        } else{
305
            reference = null;
306
            textReference.setText("");
307
            this.configurator.setNewSecundum(null);
308
        }
309

    
310
    }
311

    
312

    
313

    
314

    
315

    
316

    
317
}
(7-7/10)