Project

General

Profile

Download (9.71 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.deleteConfigurator;
10

    
11
import java.util.List;
12

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

    
32
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
33
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
34
import eu.etaxonomy.cdm.model.taxon.Classification;
35

    
36

    
37
/**
38
 * @author pplitzner
39
 * @date Feb 18, 2015
40
 *
41
 */
42
public class DeleteTaxonBaseConfiguratorComposite extends Composite implements SelectionListener{
43

    
44
    protected  DataBindingContext m_bindingContext;
45

    
46
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
47
    protected final TaxonBaseDeletionConfigurator configurator;
48
    private final Button btnDeleteTaxonName;
49

    
50

    
51
    //name related
52
    private final Button btnRemoveAllNameRelationships;
53
    private final Button btnIgnoreIsBasionym;
54
    private final Button btnIgnoreIsReplacedSynonymFor;
55
    private final Button btnIgnoreHasBasionym;
56
    private final Button btnIgnoreHasReplacedSynonym;
57
    private final Button btnRemoveAllTypeDesignations;
58

    
59
    private Combo classificationSelectionCombo;
60

    
61

    
62
    Classification selectedClassification;
63
    private List<Classification> classifications;
64

    
65

    
66
    /**
67
     * Create the composite.
68
     * @param parent
69
     * @param style
70
     */
71
    public DeleteTaxonBaseConfiguratorComposite(TaxonBaseDeletionConfigurator configurator, Composite parent, int style) {
72
        super(parent, style);
73
        this.configurator = configurator;
74
        addDisposeListener(new DisposeListener() {
75
            @Override
76
            public void widgetDisposed(DisposeEvent e) {
77
                toolkit.dispose();
78
            }
79
        });
80
        toolkit.paintBordersFor(this);
81
        setLayout(new GridLayout());
82
        setBackground(getBackground());
83

    
84
        btnDeleteTaxonName = new Button(this, SWT.CHECK);
85
        btnDeleteTaxonName.setText("Delete name if possible");
86
        btnDeleteTaxonName.setSelection(true);
87
        btnDeleteTaxonName.addListener(SWT.Selection, new Listener() {
88
               @Override
89
            public void handleEvent(Event e) {
90
                   Button b = (Button) e.widget;
91
                   GridData data = (GridData)  btnRemoveAllNameRelationships.getLayoutData();
92
                   data.exclude = b.getSelection();
93
                   btnRemoveAllNameRelationships.setVisible(data.exclude);
94
                   btnIgnoreIsBasionym.setVisible(data.exclude);
95
                   btnIgnoreIsReplacedSynonymFor.setVisible(data.exclude);
96
                   btnIgnoreHasBasionym.setVisible(data.exclude);
97
                   btnIgnoreHasReplacedSynonym.setVisible(data.exclude);
98
                   btnRemoveAllTypeDesignations.setVisible(data.exclude);
99
               }
100
        });
101

    
102

    
103
        //DeleteConfigurator for the name
104

    
105

    
106
        btnRemoveAllNameRelationships = new Button(this, SWT.CHECK);
107
        btnRemoveAllNameRelationships.setText("Remove all name relations");
108
        btnRemoveAllNameRelationships.setSelection(true);
109

    
110
        btnIgnoreIsBasionym = new Button(this, SWT.CHECK);
111
        btnIgnoreIsBasionym.setText("Ignore if it is basionym");
112
        btnIgnoreIsBasionym.setSelection(true);
113

    
114
        btnIgnoreIsReplacedSynonymFor = new Button(this, SWT.CHECK);
115
        btnIgnoreIsReplacedSynonymFor.setText("Ignore if it is replaced synonym");
116
        btnIgnoreIsReplacedSynonymFor.setSelection(true);
117

    
118
        btnIgnoreHasBasionym = new Button(this, SWT.CHECK);
119
        btnIgnoreHasBasionym.setText("Ignore if it has basionym");
120
        btnIgnoreHasBasionym.setSelection(true);
121

    
122
        btnIgnoreHasReplacedSynonym = new Button(this, SWT.CHECK);
123
        btnIgnoreHasReplacedSynonym.setText("Ignore if it has replaced synonym");
124
        btnIgnoreHasReplacedSynonym.setSelection(true);
125

    
126
        btnRemoveAllTypeDesignations = new Button(this, SWT.CHECK);
127
        btnRemoveAllTypeDesignations.setText("Remove all type designations");
128
        btnRemoveAllTypeDesignations.setSelection(true);
129

    
130

    
131

    
132
       // createClassificationSelectionCombo(this);
133
        initDataBindings();
134

    
135

    
136
    }
137

    
138
    protected void initDataBindings() {
139
        m_bindingContext = new DataBindingContext();
140
        //
141
        IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
142
        IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
143
        m_bindingContext.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget, deleteNameIfPossibleConfiguratorObserveValue, null, null);
144

    
145
        NameDeletionConfigurator nameConfig = configurator.getNameDeletionConfig();
146
        IObservableValue observeSelectionbtnRemoveAllNameRelationshipsObserveWidget = WidgetProperties.selection().observe(btnRemoveAllNameRelationships);
147
        IObservableValue deleteRemoveAllNameRelationshipsConfiguratorObserveValue = PojoProperties.value("removeAllNameRelationships").observe(nameConfig);
148
        m_bindingContext.bindValue(observeSelectionbtnRemoveAllNameRelationshipsObserveWidget, deleteRemoveAllNameRelationshipsConfiguratorObserveValue, null, null);
149

    
150
        IObservableValue observeSelectionbtnIgnoreIsBasionymObserveWidget = WidgetProperties.selection().observe(btnIgnoreIsBasionym);
151
        IObservableValue deleteIgnoreIsBasionymConfiguratorObserveValue = PojoProperties.value("ignoreIsBasionymFor").observe(nameConfig);
152
        m_bindingContext.bindValue(observeSelectionbtnIgnoreIsBasionymObserveWidget, deleteIgnoreIsBasionymConfiguratorObserveValue, null, null);
153

    
154
        IObservableValue observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget = WidgetProperties.selection().observe(btnIgnoreIsReplacedSynonymFor);
155
        IObservableValue deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue = PojoProperties.value("ignoreIsReplacedSynonymFor").observe(nameConfig);
156
        m_bindingContext.bindValue(observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget, deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue, null, null);
157

    
158
        IObservableValue observeSelectionbtnIgnoreHasBasionymObserveWidget = WidgetProperties.selection().observe(btnIgnoreHasBasionym);
159
        IObservableValue deleteIgnoreHasBasionymConfiguratorObserveValue = PojoProperties.value("ignoreHasBasionym").observe(nameConfig);
160
        m_bindingContext.bindValue(observeSelectionbtnIgnoreHasBasionymObserveWidget, deleteIgnoreHasBasionymConfiguratorObserveValue, null, null);
161

    
162
        IObservableValue observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget = WidgetProperties.selection().observe(btnIgnoreHasReplacedSynonym);
163
        IObservableValue deleteIgnoreHasReplacedSynonymConfiguratorObserveValue = PojoProperties.value("ignoreHasReplacedSynonym").observe(nameConfig);
164
        m_bindingContext.bindValue(observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget, deleteIgnoreHasReplacedSynonymConfiguratorObserveValue, null, null);
165

    
166
        IObservableValue observeSelectionbtnRemoveAllTypeDesignationsObserveWidget = WidgetProperties.selection().observe(btnRemoveAllTypeDesignations);
167
        IObservableValue deleteRemoveAllTypeDesignationsConfiguratorObserveValue = PojoProperties.value("removeAllTypeDesignations").observe(nameConfig);
168
        m_bindingContext.bindValue(observeSelectionbtnRemoveAllTypeDesignationsObserveWidget, deleteRemoveAllTypeDesignationsConfiguratorObserveValue, null, null);
169

    
170

    
171
    }
172

    
173
  /* private Control createClassificationSelectionCombo(Composite parent){
174
//		classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
175

    
176
		Composite classificationSelection = new Composite(parent, SWT.NULL);
177
		classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
178

    
179
		GridLayout layout = new GridLayout();
180
		classificationSelection.setLayout(layout);
181

    
182
		Label label = new Label(classificationSelection, SWT.NULL);
183
		// TODO not working is not really true but leave it here to remind everyone that this is under construction
184
		label.setText("Select Classification");
185
		classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
186
		classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
187
		classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
188

    
189
		for(Classification tree : classifications){
190
			classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
191

    
192
		}
193

    
194
		classificationSelectionCombo.select(0);
195
		classificationSelectionCombo.addSelectionListener(this);
196

    
197
		return classificationSelection;
198
	}*/
199

    
200
@Override
201
public void widgetSelected(SelectionEvent e) {
202
	selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
203
}
204

    
205
@Override
206
public void widgetDefaultSelected(SelectionEvent e) {
207
	// TODO Auto-generated method stub
208

    
209
}
210
}
(7-7/8)