Project

General

Profile

Download (6.78 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.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Event;
24
import org.eclipse.swt.widgets.Listener;
25

    
26
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
27
import eu.etaxonomy.taxeditor.l10n.Messages;
28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29

    
30
/**
31
 * @author k.luther
32
 * @date 10.10.2017
33
 *
34
 */
35
public class PublishSubTreeConfiguratorWizardPage extends WizardPage implements Listener {
36

    
37
    private DataBindingContext m_bindingContext;
38

    
39
    private final static CdmFormFactory toolkit = new CdmFormFactory(Display.getCurrent());
40
    private final PublishForSubtreeConfigurator configurator;
41

    
42
    private Button btnIncludeAcceptedTaxa;
43
    private Button btnIncludeSynonyms;
44
    private Button btnIncludeSharedTaxa;
45

    
46
    private Button btnPublish;
47

    
48

    
49
    /**
50
     * @param string
51
     */
52
    public PublishSubTreeConfiguratorWizardPage(PublishForSubtreeConfigurator configurator) {
53
        super("Set Publish Flag Configuration");
54
        this.configurator = configurator;
55
        this.setDescription(Messages.SetPublishConfiguration_Description_Configurator);
56

    
57
    }
58

    
59

    
60

    
61
    /* (non-Javadoc)
62
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
63
     */
64
    @Override
65
    public void createControl(Composite parent) {
66

    
67
        final Composite composite = new Composite(parent, SWT.NULL);
68

    
69
        GridLayout gridLayout = new GridLayout();
70
        gridLayout.numColumns = 1;
71

    
72
        composite.setLayout(gridLayout);
73
        final Composite control = new Composite(composite, SWT.NULL);
74
        GridLayout gridLayoutControl = new GridLayout();
75

    
76
        control.setLayout(gridLayoutControl);
77
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
78
      //  Composite control = toolkit.createComposite(composite);
79
        btnIncludeAcceptedTaxa = new Button(control, SWT.CHECK);
80
        btnIncludeAcceptedTaxa.setText(Messages.SetPublishConfiguration_IncludeAcceptedTaxa);
81
        btnIncludeAcceptedTaxa.setSelection(configurator.isIncludeAcceptedTaxa());
82
        btnIncludeAcceptedTaxa.addListener(SWT.Selection, new Listener() {
83
            @Override
84
         public void handleEvent(Event e) {
85
                Button b = (Button) e.widget;
86
                GridData data = (GridData)  btnIncludeAcceptedTaxa.getLayoutData();
87
                data.exclude = b.getSelection();
88

    
89
                btnIncludeSharedTaxa.setVisible(data.exclude);
90
                if (!btnIncludeSynonyms.getSelection() && !data.exclude){
91
                   setPageComplete(false);
92
                }else{
93
                   setPageComplete(true);
94
                }
95
            }
96
        });
97

    
98

    
99
        btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
100
        GridData gd_btnIncludeSharedTaxa = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
101
        gd_btnIncludeSharedTaxa.horizontalIndent = 10;
102
        btnIncludeSharedTaxa.setLayoutData(gd_btnIncludeSharedTaxa);
103
        btnIncludeSharedTaxa.setText(Messages.SetPublishConfiguration_IncludeSharedtaxa);
104
        btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
105

    
106
        btnIncludeSynonyms = new Button(control, SWT.CHECK);
107
        btnIncludeSynonyms.setText(Messages.SetPublishConfiguration_IncludeSynonyms);
108
        btnIncludeSynonyms.setSelection(configurator.isIncludeSynonyms());
109
        btnIncludeSynonyms.addListener(SWT.Selection, new Listener() {
110
            @Override
111
         public void handleEvent(Event e) {
112
                Button b = (Button) e.widget;
113
                GridData data = (GridData)  btnIncludeSynonyms.getLayoutData();
114
                data.exclude = b.getSelection();
115

    
116
                if (!btnIncludeAcceptedTaxa.getSelection() && !data.exclude){
117
                   setPageComplete(false);
118
                }else{
119
                   setPageComplete(true);
120
                }
121

    
122
            }
123
        });
124

    
125
        btnPublish = new Button(control, SWT.CHECK);
126
        btnPublish.setText(Messages.SetPublishConfiguration_Publish);
127
        btnPublish.setToolTipText(Messages.SetPublishConfiguration_Publish_tooltip);
128
        btnPublish.setSelection(configurator.isPublish());
129

    
130
        m_bindingContext = initDataBindings();
131
        setControl(composite);
132
    }
133

    
134
    /* (non-Javadoc)
135
     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
136
     */
137
    @Override
138
    public void handleEvent(Event event) {
139
        // TODO Auto-generated method stub
140

    
141
    }
142

    
143
    protected DataBindingContext initDataBindings() {
144
        DataBindingContext bindingContext = new DataBindingContext();
145

    
146
        IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
147
        IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
148
        bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
149

    
150
        IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
151
        IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
152
        bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue, null, null);
153

    
154

    
155
        IObservableValue observeSelectionBtnIncludeSharedTaxal = WidgetProperties.selection().observe(btnIncludeSharedTaxa);
156
        IObservableValue includeSharedTaxaConfiguratorObserveValue = PojoProperties.value("includeSharedTaxa").observe(configurator);
157
        bindingContext.bindValue(observeSelectionBtnIncludeSharedTaxal, includeSharedTaxaConfiguratorObserveValue, null, null);
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
}
(2-2/5)