Project

General

Profile

Download (12 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.ui.dialog.selection.SelectionDialogFactory;
31
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
32

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

    
41
    private final SecundumForSubtreeConfigurator configurator;
42

    
43
    private  Button btnBrowseReference = null;
44

    
45
    private  Text textReference = null;
46
    private  Button btnClear = null;
47
    private EntitySelectionElement<Reference> selectReference;
48
    private  Button btnIncludeAcceptedTaxa;
49
    private Button btnIncludeSynonyms;
50
    private Button btnOverwriteExistingAccepted;
51
    private Button btnOverwriteExistingSynonyms;
52
    private Button btnEmptySecundumDetail;
53
    private Button btnIncludeSharedTaxa;
54

    
55

    
56
    /**
57
     * Create the composite.
58
     * @param parent
59
     * @param style
60
     */
61
    public SetSecundumConfiguratorWizardPage(SecundumForSubtreeConfigurator configurator) {
62
        super("Set Secundum Reference Configuration");
63
        this.configurator = configurator;
64
        this.setDescription(Messages.SetSecundumConfiguration_Description_Configurator);
65
    }
66

    
67
    /**
68
     * @return
69
     */
70
    private DataBindingContext initDataBindings() {
71
        DataBindingContext bindingContext = new DataBindingContext();
72

    
73
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
74
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
75
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
76

    
77
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
78
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
79
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue, null, null);
80

    
81
        IObservableValue observeSelectionBtnOverwriteExistingAccepted = WidgetProperties.selection().observe(btnOverwriteExistingAccepted);
82
        IObservableValue overwriteExistingAcceptedConfiguratorObserveValue = PojoProperties.value("overwriteExistingAccepted").observe(configurator);
83
        bindingContext.bindValue(observeSelectionBtnOverwriteExistingAccepted, overwriteExistingAcceptedConfiguratorObserveValue, null, null);
84

    
85
        IObservableValue observeSelectionBtnOverwriteExistingSynonyms = WidgetProperties.selection().observe(btnOverwriteExistingSynonyms);
86
        IObservableValue overwriteExistingSynonymsConfiguratorObserveValue = PojoProperties.value("overwriteExistingSynonyms").observe(configurator);
87
        bindingContext.bindValue(observeSelectionBtnOverwriteExistingSynonyms, overwriteExistingSynonymsConfiguratorObserveValue, null, null);
88

    
89
        IObservableValue observeSelectionBtnEmptySecundumDetail = WidgetProperties.selection().observe(btnEmptySecundumDetail);
90
        IObservableValue emptySecundumDetailConfiguratorObserveValue = PojoProperties.value("emptySecundumDetail").observe(configurator);
91
        bindingContext.bindValue(observeSelectionBtnEmptySecundumDetail, emptySecundumDetailConfiguratorObserveValue, null, null);
92

    
93
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
94
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
95
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue, null, null);
96
        return bindingContext;
97
    }
98

    
99
    @Override
100
    public void createControl(Composite parent) {
101

    
102
        final Composite composite = new Composite(parent, SWT.NULL);
103

    
104
        GridLayout gridLayout = new GridLayout();
105
        gridLayout.numColumns = 1;
106

    
107
        composite.setLayout(gridLayout);
108
        final Composite compositeRef = new Composite(composite, SWT.NULL);
109

    
110
        GridLayout gridLayoutRef = new GridLayout();
111
        gridLayoutRef.numColumns = 4;
112

    
113
        compositeRef.setLayout(gridLayoutRef);
114
        compositeRef.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
115
        Label label = new Label(compositeRef, SWT.WRAP);
116
        label.setText(Messages.SetSecundumConfiguration_NewSecundum_Label);
117
        label.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false));
118

    
119
        textReference = new Text(compositeRef, SWT.BORDER);
120
        textReference.setEditable(false);
121
        textReference.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
122
        textReference.setTextLimit(Text.LIMIT);
123

    
124
        btnBrowseReference = new Button(compositeRef, SWT.NONE);
125
        btnBrowseReference.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/prj_obj.gif"));
126
        btnBrowseReference.addListener(SWT.Selection, this);
127

    
128
        btnClear = new Button(compositeRef, SWT.NONE);
129
        btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
130
        btnClear.addListener(SWT.Selection, this);
131
        Label labelDescription = new Label(compositeRef, SWT.WRAP);
132
        labelDescription.setText(Messages.SetSecundumConfiguration_Description);
133
        GridData gd_labelDescription = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
134
        gd_labelDescription.horizontalSpan = 4;
135
        labelDescription.setLayoutData(gd_labelDescription);
136
        new Label(compositeRef, SWT.NONE);
137
        new Label(compositeRef, SWT.NONE);
138
        new Label(compositeRef, SWT.NONE);
139

    
140
       // selectReference = toolkit.createSelectionElement(Rights.class, getConversationHolder(), composite, "Rights", null, EntitySelectionElement.SELECTABLE);
141
        final Composite control = new Composite(composite, SWT.WRAP);
142
        GridLayout gridLayoutControl = new GridLayout();
143

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

    
168
        btnOverwriteExistingAccepted = new Button(control, SWT.CHECK);
169
        GridData gd_btnOverwriteExistingAccepted = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
170
        gd_btnOverwriteExistingAccepted.horizontalIndent = 10;
171
        btnOverwriteExistingAccepted.setLayoutData(gd_btnOverwriteExistingAccepted);
172
        btnOverwriteExistingAccepted.setText(Messages.SetSecundumConfiguration_OverwriteExistingAccepted);
173

    
174
                btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
175
                GridData gd_btnIncludeSharedTaxa = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
176
                gd_btnIncludeSharedTaxa.horizontalIndent = 10;
177
                btnIncludeSharedTaxa.setLayoutData(gd_btnIncludeSharedTaxa);
178
                btnIncludeSharedTaxa.setText(Messages.SetSecundumConfiguration_IncludeSharedtaxa);
179
                btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
180

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

    
199
            }
200
        });
201

    
202
        btnOverwriteExistingAccepted.setSelection(configurator.isOverwriteExistingAccepted());
203
        btnOverwriteExistingSynonyms = new Button(control, SWT.CHECK);
204
        GridData gd_btnOverwriteExistingSynonyms = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
205
        gd_btnOverwriteExistingSynonyms.horizontalIndent = 10;
206
        btnOverwriteExistingSynonyms.setLayoutData(gd_btnOverwriteExistingSynonyms);
207
        btnOverwriteExistingSynonyms.setText(Messages.SetSecundumConfiguration_OverwriteExistingSynonyms);
208
        btnOverwriteExistingSynonyms.setSelection(configurator.isOverwriteExistingSynonyms());
209
        btnEmptySecundumDetail = new Button(control, SWT.CHECK);
210
        btnEmptySecundumDetail.setText(Messages.SetSecundumConfiguration_EmptySecundumDetail);
211
        btnEmptySecundumDetail.setSelection(configurator.isEmptySecundumDetail());
212

    
213
        m_bindingContext = initDataBindings();
214
        setControl(composite);
215
    }
216

    
217

    
218

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

    
228
            }
229

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

    
240
    }
241

    
242
//    /**
243
//     * {@inheritDoc}
244
//     */
245
//    @Override
246
//    public AbstractCdmDetailElement createElement(ICdmFormElement rootElement) {
247
//        // TODO Auto-generated method stub
248
//        return null;
249
//    }
250

    
251

    
252

    
253

    
254
}
(4-4/5)