Project

General

Profile

Download (7.83 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.WizardPage;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Combo;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.swt.widgets.Event;
27
import org.eclipse.swt.widgets.Listener;
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 Listener, 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

    
49
    private Combo btnPublish;
50

    
51

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

    
59
        this.setDescription(Messages.SetPublishConfiguration_Description_Configurator);
60

    
61
    }
62

    
63

    
64

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

    
71
        final Composite composite = new Composite(parent, SWT.NULL);
72

    
73
        GridLayout gridLayout = new GridLayout();
74
        gridLayout.numColumns = 1;
75

    
76
        composite.setLayout(gridLayout);
77
        final Composite control = new Composite(composite, SWT.NULL);
78
        GridLayout gridLayoutControl = new GridLayout();
79

    
80
        control.setLayout(gridLayoutControl);
81
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
82

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

    
95

    
96
      //  Composite control = toolkit.createComposite(composite);
97
        btnIncludeAcceptedTaxa = new Button(control, SWT.CHECK);
98
        btnIncludeAcceptedTaxa.setText(Messages.SetPublishConfiguration_IncludeAcceptedTaxa);
99
        btnIncludeAcceptedTaxa.setSelection(configurator.isIncludeAcceptedTaxa());
100
        btnIncludeAcceptedTaxa.addListener(SWT.Selection, new Listener() {
101
            @Override
102
         public void handleEvent(Event e) {
103
                Button b = (Button) e.widget;
104
                GridData data = (GridData)  btnIncludeAcceptedTaxa.getLayoutData();
105
                data.exclude = b.getSelection();
106

    
107
                btnIncludeSharedTaxa.setVisible(data.exclude);
108
                if (!btnIncludeSynonyms.getSelection() && !data.exclude){
109
                   setPageComplete(false);
110
                }else{
111
                   setPageComplete(true);
112
                }
113
            }
114
        });
115

    
116

    
117
        btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
118
        GridData gd_btnIncludeSharedTaxa = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
119
        gd_btnIncludeSharedTaxa.horizontalIndent = 10;
120
        btnIncludeSharedTaxa.setLayoutData(gd_btnIncludeSharedTaxa);
121
        btnIncludeSharedTaxa.setText(Messages.SetPublishConfiguration_IncludeSharedtaxa);
122
        btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
123

    
124
        btnIncludeSynonyms = new Button(control, SWT.CHECK);
125
        btnIncludeSynonyms.setText(Messages.SetPublishConfiguration_IncludeSynonyms);
126
        btnIncludeSynonyms.setSelection(configurator.isIncludeSynonyms());
127
        btnIncludeSynonyms.addListener(SWT.Selection, new Listener() {
128
            @Override
129
         public void handleEvent(Event e) {
130
                Button b = (Button) e.widget;
131
                GridData data = (GridData)  btnIncludeSynonyms.getLayoutData();
132
                data.exclude = b.getSelection();
133

    
134
                if (!btnIncludeAcceptedTaxa.getSelection() && !data.exclude){
135
                   setPageComplete(false);
136
                }else{
137
                   setPageComplete(true);
138
                }
139

    
140
            }
141
        });
142

    
143

    
144
        m_bindingContext = initDataBindings();
145
        setControl(composite);
146
    }
147

    
148
    /* (non-Javadoc)
149
     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
150
     */
151
    @Override
152
    public void handleEvent(Event event) {
153
        // TODO Auto-generated method stub
154

    
155
    }
156

    
157
    protected DataBindingContext initDataBindings() {
158
        DataBindingContext bindingContext = new DataBindingContext();
159

    
160
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
161
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
162
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
163

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

    
168

    
169
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
170
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
171
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue, null, null);
172

    
173
//        IObservableValue observeSelectionBtnPublish = WidgetProperties.selection().observe(btnPublish);
174
//        IObservableValue publishConfiguratorObserveValue = PojoProperties.value("publish").observe(configurator);
175
//        bindingContext.bindValue(observeSelectionBtnPublish, publishConfiguratorObserveValue, null, null);
176
        return bindingContext;
177

    
178
    }
179

    
180

    
181

    
182
    /* (non-Javadoc)
183
     * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
184
     */
185
    @Override
186
    public void widgetSelected(SelectionEvent e) {
187
        if (btnPublish.getSelectionIndex() > 0){
188
            configurator.setPublish(false);
189
        } else{
190
            configurator.setPublish(true);
191
        }
192

    
193
    }
194

    
195

    
196

    
197
    /* (non-Javadoc)
198
     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
199
     */
200
    @Override
201
    public void widgetDefaultSelected(SelectionEvent e) {
202
        // TODO Auto-generated method stub
203

    
204
    }
205
}
(2-2/5)