Project

General

Profile

Download (12.5 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.Display;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Listener;
25
import org.eclipse.swt.widgets.Text;
26
import org.eclipse.wb.swt.ResourceManager;
27

    
28
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
29
import eu.etaxonomy.cdm.model.reference.Reference;
30
import eu.etaxonomy.taxeditor.l10n.Messages;
31
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
32
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
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 static CdmFormFactory toolkit = new CdmFormFactory(Display.getCurrent());
44
    private final SecundumForSubtreeConfigurator configurator;
45

    
46
    private  Button btnBrowseReference = null;
47

    
48
    private  Text textReference = null;
49
    private  Button btnClear = null;
50
    private EntitySelectionElement<Reference> selectReference;
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(SecundumForSubtreeConfigurator configurator) {
65
        super("Set Secundum Reference Configuration");
66
        this.configurator = configurator;
67
        this.setDescription(Messages.SetSecundumConfiguration_Description_Configurator);
68

    
69

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

    
80

    
81

    
82

    
83
    }
84

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

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

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

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

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

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

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

    
117
    @Override
118
    public void createControl(Composite parent) {
119

    
120
        final Composite composite = new Composite(parent, SWT.NULL);
121

    
122
        GridLayout gridLayout = new GridLayout();
123
        gridLayout.numColumns = 1;
124

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

    
128
        GridLayout gridLayoutRef = new GridLayout();
129
        gridLayoutRef.numColumns = 4;
130

    
131
        compositeRef.setLayout(gridLayoutRef);
132
        compositeRef.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
133
        Label label = new Label(compositeRef, SWT.WRAP);
134
        label.setText(Messages.SetSecundumConfiguration_NewSecundum_Label);
135
        label.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false));
136

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

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

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

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

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

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

    
192
                btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
193
                GridData gd_btnIncludeSharedTaxa = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
194
                gd_btnIncludeSharedTaxa.horizontalIndent = 10;
195
                btnIncludeSharedTaxa.setLayoutData(gd_btnIncludeSharedTaxa);
196
                btnIncludeSharedTaxa.setText(Messages.SetSecundumConfiguration_IncludeSharedtaxa);
197
                btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
198

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

    
217
            }
218
        });
219

    
220
        btnOverwriteExistingAccepted.setSelection(configurator.isOverwriteExistingAccepted());
221
        btnOverwriteExistingSynonyms = new Button(control, SWT.CHECK);
222
        GridData gd_btnOverwriteExistingSynonyms = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
223
        gd_btnOverwriteExistingSynonyms.horizontalIndent = 10;
224
        btnOverwriteExistingSynonyms.setLayoutData(gd_btnOverwriteExistingSynonyms);
225
        btnOverwriteExistingSynonyms.setText(Messages.SetSecundumConfiguration_OverwriteExistingSynonyms);
226
        btnOverwriteExistingSynonyms.setSelection(configurator.isOverwriteExistingSynonyms());
227
        btnEmptySecundumDetail = new Button(control, SWT.CHECK);
228
        btnEmptySecundumDetail.setText(Messages.SetSecundumConfiguration_EmptySecundumDetail);
229
        btnEmptySecundumDetail.setSelection(configurator.isEmptySecundumDetail());
230

    
231
        m_bindingContext = initDataBindings();
232
        setControl(composite);
233
    }
234

    
235

    
236

    
237
    @Override
238
    public void handleEvent(Event event) {
239
        Reference reference;
240
        if(event.widget==btnBrowseReference){
241
            reference = SelectionDialogFactory.getSelectionFromDialog(Reference.class, this.getShell(), null, null);
242
            if(reference!=null){
243
                this.configurator.setNewSecundum(reference);
244
                textReference.setText(reference.getTitleCache());
245

    
246
            }
247

    
248
        } else if(event.widget==btnClear){
249
            reference = null;
250
            textReference.setText("");
251
            this.configurator.setNewSecundum(null);
252
        } else{
253
            reference = null;
254
            textReference.setText("");
255
            this.configurator.setNewSecundum(null);
256
        }
257

    
258
    }
259

    
260
//    /**
261
//     * {@inheritDoc}
262
//     */
263
//    @Override
264
//    public AbstractCdmDetailElement createElement(ICdmFormElement rootElement) {
265
//        // TODO Auto-generated method stub
266
//        return null;
267
//    }
268

    
269

    
270

    
271

    
272
}
(4-4/5)