2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
;
11 import org
.eclipse
.core
.databinding
.DataBindingContext
;
12 import org
.eclipse
.core
.databinding
.beans
.PojoProperties
;
13 import org
.eclipse
.core
.databinding
.observable
.value
.IObservableValue
;
14 import org
.eclipse
.jface
.databinding
.swt
.WidgetProperties
;
15 import org
.eclipse
.jface
.wizard
.Wizard
;
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
.Label
;
25 import org
.eclipse
.swt
.widgets
.Listener
;
26 import org
.eclipse
.swt
.widgets
.Text
;
27 import org
.eclipse
.wb
.swt
.ResourceManager
;
29 import eu
.etaxonomy
.cdm
.api
.service
.config
.SetSecundumForSubtreeConfigurator
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.SelectionDialogFactory
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
41 public class SetSecundumConfiguratorWizardPage
extends WizardPage
implements Listener
{
42 private DataBindingContext m_bindingContext
;
44 private final static CdmFormFactory toolkit
= new CdmFormFactory(Display
.getCurrent());
45 private final SetSecundumForSubtreeConfigurator configurator
;
47 private Button btnBrowseReference
= null;
48 private Text textReference
= null;
49 private Button btnClear
= null;
50 private EntitySelectionElement
<Reference
> selectReference
;
51 private Button btnIncludeAcceptedTaxa
;
52 private Button btnIncludeSynonyms
;
53 private Button btnOverwriteExistingAccepted
;
54 private Button btnOverwriteExistingSynonyms
;
55 private Button btnEmptySecundumDetail
;
56 private Button btnIncludeSharedTaxa
;
60 * Create the composite.
64 public SetSecundumConfiguratorWizardPage(SetSecundumForSubtreeConfigurator configurator
, Wizard parent
, int style
) {
65 super("Set Secundum Reference Configuration");
66 this.configurator
= configurator
;
67 this.setDescription(Messages
.SetSecundumConfiguration_Description
);
69 // addDisposeListener(new DisposeListener() {
71 // public void widgetDisposed(DisposeEvent e) {
75 // toolkit.paintBordersFor(this);
76 // setLayout(new GridLayout());
77 // setBackground(getBackground());
87 private DataBindingContext
initDataBindings() {
88 DataBindingContext bindingContext
= new DataBindingContext();
90 IObservableValue observeSelectionBtnIncludeAcceptedTaxa
= WidgetProperties
.selection().observe(btnIncludeAcceptedTaxa
);
91 IObservableValue includeAcceptedTaxaConfiguratorObserveValue
= PojoProperties
.value("includeAcceptedTaxa").observe(configurator
);
92 bindingContext
.bindValue(observeSelectionBtnIncludeAcceptedTaxa
, includeAcceptedTaxaConfiguratorObserveValue
, null, null);
94 IObservableValue observeSelectionBtnIncludeSynonyms
= WidgetProperties
.selection().observe(btnIncludeSynonyms
);
95 IObservableValue includeSynonymsConfiguratorObserveValue
= PojoProperties
.value("includeSynonyms").observe(configurator
);
96 bindingContext
.bindValue(observeSelectionBtnIncludeSynonyms
, includeSynonymsConfiguratorObserveValue
, null, null);
98 IObservableValue observeSelectionBtnOverwriteExistingAccepted
= WidgetProperties
.selection().observe(btnOverwriteExistingAccepted
);
99 IObservableValue overwriteExistingAcceptedConfiguratorObserveValue
= PojoProperties
.value("overwriteExistingAccepted").observe(configurator
);
100 bindingContext
.bindValue(observeSelectionBtnOverwriteExistingAccepted
, overwriteExistingAcceptedConfiguratorObserveValue
, null, null);
102 IObservableValue observeSelectionBtnOverwriteExistingSynonyms
= WidgetProperties
.selection().observe(btnOverwriteExistingSynonyms
);
103 IObservableValue overwriteExistingSynonymsConfiguratorObserveValue
= PojoProperties
.value("overwriteExistingSynonyms").observe(configurator
);
104 bindingContext
.bindValue(observeSelectionBtnOverwriteExistingSynonyms
, overwriteExistingSynonymsConfiguratorObserveValue
, null, null);
106 IObservableValue observeSelectionBtnEmptySecundumDetail
= WidgetProperties
.selection().observe(btnEmptySecundumDetail
);
107 IObservableValue emptySecundumDetailConfiguratorObserveValue
= PojoProperties
.value("emptySecundumDetail").observe(configurator
);
108 bindingContext
.bindValue(observeSelectionBtnEmptySecundumDetail
, emptySecundumDetailConfiguratorObserveValue
, null, null);
110 IObservableValue observeSelectionBtnIncludeSharedTaxal
= WidgetProperties
.selection().observe(btnIncludeSharedTaxa
);
111 IObservableValue includeSharedTaxaConfiguratorObserveValue
= PojoProperties
.value("includeSharedTaxa").observe(configurator
);
112 bindingContext
.bindValue(observeSelectionBtnIncludeSharedTaxal
, includeSharedTaxaConfiguratorObserveValue
, null, null);
113 return bindingContext
;
117 public void createControl(Composite parent
) {
119 final Composite composite
= new Composite(parent
, SWT
.NULL
);
121 GridLayout gridLayout
= new GridLayout();
122 gridLayout
.numColumns
= 1;
124 composite
.setLayout(gridLayout
);
125 final Composite compositeRef
= new Composite(composite
, SWT
.NULL
);
127 GridLayout gridLayoutRef
= new GridLayout();
128 gridLayoutRef
.numColumns
= 4;
130 compositeRef
.setLayout(gridLayoutRef
);
131 compositeRef
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
132 Label label
= new Label(compositeRef
, SWT
.NONE
);
133 label
.setText(Messages
.SetSecundumConfiguration_NewSecundum_Label
);
134 label
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, false));
136 textReference
= new Text(compositeRef
, SWT
.BORDER
);
137 textReference
.setEditable(false);
138 textReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
139 textReference
.setTextLimit(Text
.LIMIT
);
141 btnBrowseReference
= new Button(compositeRef
, SWT
.NONE
);
142 btnBrowseReference
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
143 btnBrowseReference
.addListener(SWT
.Selection
, this);
144 btnClear
= new Button(compositeRef
, SWT
.NONE
);
145 btnClear
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
146 btnClear
.addListener(SWT
.Selection
, this);
148 // selectReference = toolkit.createSelectionElement(Rights.class, getConversationHolder(), composite, "Rights", null, EntitySelectionElement.SELECTABLE);
149 final Composite control
= new Composite(composite
, SWT
.NULL
);
150 GridLayout gridLayoutControl
= new GridLayout();
151 gridLayoutControl
.numColumns
= 1;
153 control
.setLayout(gridLayoutControl
);
154 control
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
155 // Composite control = toolkit.createComposite(composite);
156 btnIncludeAcceptedTaxa
= new Button(control
, SWT
.CHECK
);
157 btnIncludeAcceptedTaxa
.setText(Messages
.SetSecundumConfiguration_IncludeAcceptedTaxa
);
158 btnIncludeAcceptedTaxa
.setSelection(configurator
.isIncludeAcceptedTaxa());
159 btnIncludeAcceptedTaxa
.addListener(SWT
.Selection
, new Listener() {
161 public void handleEvent(Event e
) {
162 Button b
= (Button
) e
.widget
;
163 GridData data
= (GridData
) btnIncludeAcceptedTaxa
.getLayoutData();
164 data
.exclude
= b
.getSelection();
165 btnOverwriteExistingAccepted
.setVisible(data
.exclude
);
166 btnIncludeSharedTaxa
.setVisible(data
.exclude
);
167 if (!btnIncludeSynonyms
.getSelection() && !data
.exclude
){
168 btnEmptySecundumDetail
.setVisible(false);
169 setPageComplete(false);
171 btnEmptySecundumDetail
.setVisible(true);
172 setPageComplete(true);
177 btnOverwriteExistingAccepted
= new Button(control
, SWT
.CHECK
);
178 btnOverwriteExistingAccepted
.setText(Messages
.SetSecundumConfiguration_OverwriteExistingAccepted
);
180 btnIncludeSynonyms
= new Button(control
, SWT
.CHECK
);
181 btnIncludeSynonyms
.setText(Messages
.SetSecundumConfiguration_IncludeSynonyms
);
182 btnIncludeSynonyms
.setSelection(configurator
.isIncludeSynonyms());
183 btnIncludeSynonyms
.addListener(SWT
.Selection
, new Listener() {
185 public void handleEvent(Event e
) {
186 Button b
= (Button
) e
.widget
;
187 GridData data
= (GridData
) btnIncludeSynonyms
.getLayoutData();
188 data
.exclude
= b
.getSelection();
189 btnOverwriteExistingSynonyms
.setVisible(data
.exclude
);
190 if (!btnIncludeAcceptedTaxa
.getSelection() && !data
.exclude
){
191 btnEmptySecundumDetail
.setVisible(false);
192 setPageComplete(false);
194 btnEmptySecundumDetail
.setVisible(true);
195 setPageComplete(true);
201 btnOverwriteExistingAccepted
.setSelection(configurator
.isOverwriteExistingAccepted());
202 btnOverwriteExistingSynonyms
= new Button(control
, SWT
.CHECK
);
203 btnOverwriteExistingSynonyms
.setText(Messages
.SetSecundumConfiguration_OverwriteExistingSynonyms
);
204 btnOverwriteExistingSynonyms
.setSelection(configurator
.isOverwriteExistingSynonyms());
205 btnEmptySecundumDetail
= new Button(control
, SWT
.CHECK
);
206 btnEmptySecundumDetail
.setText(Messages
.SetSecundumConfiguration_EmptySecundumDetail
);
207 btnEmptySecundumDetail
.setSelection(configurator
.isEmptySecundumDetail());
209 btnIncludeSharedTaxa
= new Button(control
, SWT
.CHECK
);
210 btnIncludeSharedTaxa
.setText(Messages
.SetSecundumConfiguration_IncludeSharedtaxa
);
211 btnIncludeSharedTaxa
.setSelection(configurator
.isIncludeSharedTaxa());
213 m_bindingContext
= initDataBindings();
214 setControl(composite
);
220 public void handleEvent(Event event
) {
222 if(event
.widget
==btnBrowseReference
){
223 reference
= SelectionDialogFactory
.getSelectionFromDialog(Reference
.class, this.getShell(), null, null);
225 this.configurator
.setNewSecundum(reference
);
226 textReference
.setText(reference
.getTitleCache());
230 } else if(event
.widget
==btnClear
){
232 textReference
.setText("");
233 this.configurator
.setNewSecundum(null);
236 textReference
.setText("");
237 this.configurator
.setNewSecundum(null);
246 // public AbstractCdmDetailElement createElement(ICdmFormElement rootElement) {
247 // // TODO Auto-generated method stub