Project

General

Profile

Download (8.95 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.Label;
28

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

    
33
/**
34
 * @author k.luther
35
 * @date 10.10.2017
36
 *
37
 */
38
public class PublishSubTreeConfiguratorWizardPage extends WizardPage implements SelectionListener {
39

    
40
    private DataBindingContext m_bindingContext;
41

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

    
45
    private Button btnIncludeAcceptedTaxa;
46
    private Button btnIncludeSynonyms;
47
    private Button btnIncludeSharedTaxa;
48
    private Button btnIncludeMisappliedNames;
49
    private Button btnIncludeProParteSynonyms;
50
    private Button btnIncludeHybrids;
51

    
52
    private Combo btnPublish;
53

    
54

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

    
62
        this.setDescription(Messages.SetPublishConfiguration_Description_Configurator);
63

    
64
    }
65

    
66

    
67

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

    
74
        final Composite composite = new Composite(parent, SWT.NULL);
75

    
76
        GridLayout gridLayout = new GridLayout();
77
        gridLayout.numColumns = 1;
78

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

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

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

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

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

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

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

    
114
        Label space = new Label(control, SWT.NONE);
115

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

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

    
122

    
123
        m_bindingContext = initDataBindings();
124

    
125
        setControl(composite);
126
    }
127

    
128

    
129

    
130
    protected DataBindingContext initDataBindings() {
131
        DataBindingContext bindingContext = new DataBindingContext();
132

    
133
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
134
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
135
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue);
136

    
137
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
138
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
139
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue);
140

    
141
        IObservableValue observeSelectionBtnIncludeMisappliedNames = WidgetProperties.selection().observe(btnIncludeMisappliedNames);
142
        IObservableValue includeMisappliedNamesConfiguratorObserveValue = PojoProperties.value("includeMisapplications").observe(configurator);
143
        bindingContext.bindValue(observeSelectionBtnIncludeMisappliedNames, includeMisappliedNamesConfiguratorObserveValue);
144

    
145
        IObservableValue observeSelectionBtnIncludeProParteSynonyms = WidgetProperties.selection().observe(btnIncludeProParteSynonyms);
146
        IObservableValue includeProParteSynonymsConfiguratorObserveValue = PojoProperties.value("includeProParteSynonyms").observe(configurator);
147
        bindingContext.bindValue(observeSelectionBtnIncludeProParteSynonyms, includeProParteSynonymsConfiguratorObserveValue);
148

    
149
        IObservableValue observeSelectionBtnIncludeHybrids = WidgetProperties.selection().observe(btnIncludeHybrids);
150
        IObservableValue includeHybridsConfiguratorObserveValue = PojoProperties.value("includeHybrids").observe(configurator);
151
        bindingContext.bindValue(observeSelectionBtnIncludeHybrids, includeHybridsConfiguratorObserveValue);
152

    
153
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
154
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
155
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue);
156

    
157

    
158

    
159
//        IObservableValue observeSelectionBtnPublish = WidgetProperties.selection().observe(btnPublish);
160
//        IObservableValue publishConfiguratorObserveValue = PojoProperties.value("publish").observe(configurator);
161
//        bindingContext.bindValue(observeSelectionBtnPublish, publishConfiguratorObserveValue, null, null);
162
        return bindingContext;
163

    
164
    }
165

    
166
    public void updateContext(){
167
        m_bindingContext.updateTargets();
168
    }
169

    
170

    
171

    
172
    /* (non-Javadoc)
173
     * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
174
     */
175
    @Override
176
    public void widgetSelected(SelectionEvent e) {
177
        if (btnPublish.getSelectionIndex() > 0){
178
            configurator.setPublish(false);
179
        } else{
180
            configurator.setPublish(true);
181
        }
182
        if (!btnIncludeMisappliedNames.getSelection() && !btnIncludeAcceptedTaxa.getSelection() && !btnIncludeProParteSynonyms.getSelection() ){
183
            btnIncludeSharedTaxa.setEnabled(false);
184
        }else{
185
            btnIncludeSharedTaxa.setEnabled(true);
186

    
187
        }
188
        if (!btnIncludeMisappliedNames.getSelection() && !btnIncludeAcceptedTaxa.getSelection() && !btnIncludeProParteSynonyms.getSelection() && !btnIncludeSynonyms.getSelection()){
189
            btnIncludeHybrids.setEnabled(false);
190
        }else{
191
            btnIncludeHybrids.setEnabled(true);
192

    
193
        }
194

    
195
        IWizardContainer container = this.getWizard().getContainer();
196
        container.updateButtons();
197
    }
198

    
199

    
200

    
201
    /* (non-Javadoc)
202
     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
203
     */
204
    @Override
205
    public void widgetDefaultSelected(SelectionEvent e) {
206
        // TODO Auto-generated method stub
207

    
208
    }
209

    
210
    @Override
211
    public boolean isPageComplete(){
212

    
213
         return (btnIncludeAcceptedTaxa.getSelection() || btnIncludeSynonyms.getSelection() || btnIncludeMisappliedNames.getSelection() || btnIncludeProParteSynonyms.getSelection());
214

    
215

    
216
    }
217
}
(5-5/10)