Project

General

Profile

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

    
12
import org.eclipse.core.databinding.DataBindingContext;
13
import org.eclipse.core.databinding.beans.PojoProperties;
14
import org.eclipse.core.databinding.observable.value.IObservableValue;
15
import org.eclipse.jface.databinding.swt.WidgetProperties;
16
import org.eclipse.jface.wizard.IWizardContainer;
17
import org.eclipse.jface.wizard.WizardPage;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Combo;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Listener;
30

    
31
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
32
import eu.etaxonomy.taxeditor.l10n.Messages;
33
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
34

    
35
/**
36
 * @author k.luther
37
 * @date 10.10.2017
38
 *
39
 */
40
public class PublishSubTreeConfiguratorWizardPage extends WizardPage implements Listener, SelectionListener {
41

    
42
    private DataBindingContext m_bindingContext;
43

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

    
47
    private Button btnIncludeAcceptedTaxa;
48
    private Button btnIncludeSynonyms;
49
    private Button btnIncludeSharedTaxa;
50
    private Button btnIncludeMisappliedNames;
51
    private Button btnIncludeProParteSynonyms;
52
    private Button btnIncludeHybrids;
53

    
54
    private Combo btnPublish;
55

    
56

    
57
    /**
58
     * @param string
59
     */
60
    public PublishSubTreeConfiguratorWizardPage(PublishForSubtreeConfigurator configurator) {
61
        super("Set Publish Flag Configuration");
62
        this.configurator = configurator;
63

    
64
        this.setDescription(Messages.SetPublishConfiguration_Description_Configurator);
65

    
66
    }
67

    
68

    
69

    
70
    /* (non-Javadoc)
71
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
72
     */
73
    @Override
74
    public void createControl(Composite parent) {
75

    
76
        final Composite composite = new Composite(parent, SWT.NULL);
77

    
78
        GridLayout gridLayout = new GridLayout();
79
        gridLayout.numColumns = 1;
80

    
81
        composite.setLayout(gridLayout);
82
        final Composite control = new Composite(composite, SWT.NULL);
83
        GridLayout gridLayoutControl = new GridLayout();
84

    
85
        control.setLayout(gridLayoutControl);
86
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
87

    
88
        btnPublish = new Combo(control, SWT.BORDER| SWT.READ_ONLY);
89
        btnPublish.setText(Messages.SetPublishConfiguration_Publish);
90
        btnPublish.setToolTipText(Messages.SetPublishConfiguration_Publish_tooltip);
91
        btnPublish.add(Messages.SetPublishConfiguration_publish, 0);
92
        btnPublish.add(Messages.SetPublishConfiguration_dont_publish,1);
93
        if (configurator.isPublish()){
94
            btnPublish.select(0);
95
        }else{
96
            btnPublish.select(1);
97
        }
98
        btnPublish.addSelectionListener(this);
99

    
100
        btnIncludeAcceptedTaxa = new Button(control, SWT.CHECK);
101
        btnIncludeAcceptedTaxa.setText(Messages.SetPublishConfiguration_IncludeAcceptedTaxa);
102
        btnIncludeAcceptedTaxa.addSelectionListener(this);
103

    
104
        btnIncludeSynonyms = new Button(control, SWT.CHECK);
105
        btnIncludeSynonyms.setText(Messages.SetPublishConfiguration_IncludeSynonyms);
106
        btnIncludeSynonyms.addSelectionListener(this);
107

    
108
        btnIncludeMisappliedNames = new Button(control, SWT.CHECK);
109
        btnIncludeMisappliedNames.setText(Messages.SetPublishConfiguration_IncludeMisappliedNames);
110
        btnIncludeMisappliedNames.addSelectionListener(this);
111

    
112
        btnIncludeProParteSynonyms = new Button(control, SWT.CHECK);
113
        btnIncludeProParteSynonyms.setText(Messages.SetPublishConfiguration_IncludeProParteSynonyms);
114
        btnIncludeProParteSynonyms.addSelectionListener(this);
115

    
116
        Label space = new Label(control, SWT.NONE);
117

    
118
        btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
119
        btnIncludeSharedTaxa.setText(Messages.SetPublishConfiguration_IncludeSharedtaxa);
120

    
121
        btnIncludeHybrids = new Button(control, SWT.CHECK);
122
        btnIncludeHybrids.setText(Messages.SetPublishConfiguration_IncludeHybrids);
123

    
124

    
125
        m_bindingContext = initDataBindings();
126

    
127
        setControl(composite);
128
    }
129

    
130
    /* (non-Javadoc)
131
     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
132
     */
133
    @Override
134
    public void handleEvent(Event event) {
135
        // TODO Auto-generated method stub
136

    
137
    }
138

    
139
    protected DataBindingContext initDataBindings() {
140
        DataBindingContext bindingContext = new DataBindingContext();
141

    
142
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
143
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
144
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue);
145

    
146
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
147
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
148
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue);
149

    
150
        IObservableValue observeSelectionBtnIncludeMisappliedNames = WidgetProperties.selection().observe(btnIncludeMisappliedNames);
151
        IObservableValue includeMisappliedNamesConfiguratorObserveValue = PojoProperties.value("includeMisapplications").observe(configurator);
152
        bindingContext.bindValue(observeSelectionBtnIncludeMisappliedNames, includeMisappliedNamesConfiguratorObserveValue);
153

    
154
        IObservableValue observeSelectionBtnIncludeProParteSynonyms = WidgetProperties.selection().observe(btnIncludeProParteSynonyms);
155
        IObservableValue includeProParteSynonymsConfiguratorObserveValue = PojoProperties.value("includeProParteSynonyms").observe(configurator);
156
        bindingContext.bindValue(observeSelectionBtnIncludeProParteSynonyms, includeProParteSynonymsConfiguratorObserveValue);
157

    
158
        IObservableValue observeSelectionBtnIncludeHybrids = WidgetProperties.selection().observe(btnIncludeHybrids);
159
        IObservableValue includeHybridsConfiguratorObserveValue = PojoProperties.value("includeHybrids").observe(configurator);
160
        bindingContext.bindValue(observeSelectionBtnIncludeHybrids, includeHybridsConfiguratorObserveValue);
161

    
162
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
163
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
164
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue);
165

    
166

    
167

    
168
//        IObservableValue observeSelectionBtnPublish = WidgetProperties.selection().observe(btnPublish);
169
//        IObservableValue publishConfiguratorObserveValue = PojoProperties.value("publish").observe(configurator);
170
//        bindingContext.bindValue(observeSelectionBtnPublish, publishConfiguratorObserveValue, null, null);
171
        return bindingContext;
172

    
173
    }
174

    
175
    public void updateContext(){
176
        m_bindingContext.updateTargets();
177
    }
178

    
179

    
180

    
181
    /* (non-Javadoc)
182
     * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
183
     */
184
    @Override
185
    public void widgetSelected(SelectionEvent e) {
186
        if (btnPublish.getSelectionIndex() > 0){
187
            configurator.setPublish(false);
188
        } else{
189
            configurator.setPublish(true);
190
        }
191
        if (!btnIncludeMisappliedNames.getSelection() && !btnIncludeAcceptedTaxa.getSelection() && !btnIncludeProParteSynonyms.getSelection() ){
192
            btnIncludeSharedTaxa.setEnabled(false);
193
        }else{
194
            btnIncludeSharedTaxa.setEnabled(true);
195

    
196
        }
197
        if (!btnIncludeMisappliedNames.getSelection() && !btnIncludeAcceptedTaxa.getSelection() && !btnIncludeProParteSynonyms.getSelection() && !btnIncludeSynonyms.getSelection()){
198
            btnIncludeHybrids.setEnabled(false);
199
        }else{
200
            btnIncludeHybrids.setEnabled(true);
201

    
202
        }
203

    
204
        IWizardContainer container = this.getWizard().getContainer();
205
        container.updateButtons();
206
    }
207

    
208

    
209

    
210
    /* (non-Javadoc)
211
     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
212
     */
213
    @Override
214
    public void widgetDefaultSelected(SelectionEvent e) {
215
        // TODO Auto-generated method stub
216

    
217
    }
218

    
219
    @Override
220
    public boolean isPageComplete(){
221

    
222
         return (btnIncludeAcceptedTaxa.getSelection() || btnIncludeSynonyms.getSelection() || btnIncludeMisappliedNames.getSelection() || btnIncludeProParteSynonyms.getSelection());
223

    
224

    
225
    }
226
}
(2-2/5)