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
.io
.common
.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;
49 private Text textReference
= null;
50 private Button btnClear
= null;
51 private EntitySelectionElement
<Reference
> selectReference
;
52 private Button btnIncludeAcceptedTaxa
;
53 private Button btnIncludeSynonyms
;
54 private Button btnOverwriteExistingAccepted
;
55 private Button btnOverwriteExistingSynonyms
;
56 private Button btnEmptySecundumDetail
;
57 private Button btnIncludeSharedTaxa
;
61 * Create the composite.
65 public SetSecundumConfiguratorWizardPage(SetSecundumForSubtreeConfigurator configurator
, Wizard parent
, int style
) {
66 super("Set Secundum Reference Configuration");
67 this.configurator
= configurator
;
68 this.setDescription(Messages
.SetSecundumConfiguration_Description_Configurator
);
70 // addDisposeListener(new DisposeListener() {
72 // public void widgetDisposed(DisposeEvent e) {
76 // toolkit.paintBordersFor(this);
77 // setLayout(new GridLayout());
78 // setBackground(getBackground());
88 private DataBindingContext
initDataBindings() {
89 DataBindingContext bindingContext
= new DataBindingContext();
91 IObservableValue observeSelectionBtnIncludeAcceptedTaxa
= WidgetProperties
.selection().observe(btnIncludeAcceptedTaxa
);
92 IObservableValue includeAcceptedTaxaConfiguratorObserveValue
= PojoProperties
.value("includeAcceptedTaxa").observe(configurator
);
93 bindingContext
.bindValue(observeSelectionBtnIncludeAcceptedTaxa
, includeAcceptedTaxaConfiguratorObserveValue
, null, null);
95 IObservableValue observeSelectionBtnIncludeSynonyms
= WidgetProperties
.selection().observe(btnIncludeSynonyms
);
96 IObservableValue includeSynonymsConfiguratorObserveValue
= PojoProperties
.value("includeSynonyms").observe(configurator
);
97 bindingContext
.bindValue(observeSelectionBtnIncludeSynonyms
, includeSynonymsConfiguratorObserveValue
, null, null);
99 IObservableValue observeSelectionBtnOverwriteExistingAccepted
= WidgetProperties
.selection().observe(btnOverwriteExistingAccepted
);
100 IObservableValue overwriteExistingAcceptedConfiguratorObserveValue
= PojoProperties
.value("overwriteExistingAccepted").observe(configurator
);
101 bindingContext
.bindValue(observeSelectionBtnOverwriteExistingAccepted
, overwriteExistingAcceptedConfiguratorObserveValue
, null, null);
103 IObservableValue observeSelectionBtnOverwriteExistingSynonyms
= WidgetProperties
.selection().observe(btnOverwriteExistingSynonyms
);
104 IObservableValue overwriteExistingSynonymsConfiguratorObserveValue
= PojoProperties
.value("overwriteExistingSynonyms").observe(configurator
);
105 bindingContext
.bindValue(observeSelectionBtnOverwriteExistingSynonyms
, overwriteExistingSynonymsConfiguratorObserveValue
, null, null);
107 IObservableValue observeSelectionBtnEmptySecundumDetail
= WidgetProperties
.selection().observe(btnEmptySecundumDetail
);
108 IObservableValue emptySecundumDetailConfiguratorObserveValue
= PojoProperties
.value("emptySecundumDetail").observe(configurator
);
109 bindingContext
.bindValue(observeSelectionBtnEmptySecundumDetail
, emptySecundumDetailConfiguratorObserveValue
, null, null);
111 IObservableValue observeSelectionBtnIncludeSharedTaxal
= WidgetProperties
.selection().observe(btnIncludeSharedTaxa
);
112 IObservableValue includeSharedTaxaConfiguratorObserveValue
= PojoProperties
.value("includeSharedTaxa").observe(configurator
);
113 bindingContext
.bindValue(observeSelectionBtnIncludeSharedTaxal
, includeSharedTaxaConfiguratorObserveValue
, null, null);
114 return bindingContext
;
118 public void createControl(Composite parent
) {
120 final Composite composite
= new Composite(parent
, SWT
.NULL
);
122 GridLayout gridLayout
= new GridLayout();
123 gridLayout
.numColumns
= 1;
125 composite
.setLayout(gridLayout
);
126 final Composite compositeRef
= new Composite(composite
, SWT
.NULL
);
128 GridLayout gridLayoutRef
= new GridLayout();
129 gridLayoutRef
.numColumns
= 4;
131 compositeRef
.setLayout(gridLayoutRef
);
132 compositeRef
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
133 Label label
= new Label(compositeRef
, SWT
.NONE
);
134 label
.setText(Messages
.SetSecundumConfiguration_NewSecundum_Label
);
135 label
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, false));
137 textReference
= new Text(compositeRef
, SWT
.BORDER
);
138 textReference
.setEditable(false);
139 textReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
140 textReference
.setTextLimit(Text
.LIMIT
);
142 btnBrowseReference
= new Button(compositeRef
, SWT
.NONE
);
143 btnBrowseReference
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
144 btnBrowseReference
.addListener(SWT
.Selection
, this);
146 btnClear
= new Button(compositeRef
, SWT
.NONE
);
147 btnClear
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
148 btnClear
.addListener(SWT
.Selection
, this);
149 Label labelDescription
= new Label(compositeRef
, SWT
.NONE
);
150 labelDescription
.setText(Messages
.SetSecundumConfiguration_Description
);
151 GridData gd_labelDescription
= new GridData(SWT
.FILL
, SWT
.LEFT
, true, false);
152 gd_labelDescription
.horizontalSpan
= 4;
153 labelDescription
.setLayoutData(gd_labelDescription
);
154 new Label(compositeRef
, SWT
.NONE
);
155 new Label(compositeRef
, SWT
.NONE
);
156 new Label(compositeRef
, SWT
.NONE
);
158 // selectReference = toolkit.createSelectionElement(Rights.class, getConversationHolder(), composite, "Rights", null, EntitySelectionElement.SELECTABLE);
159 final Composite control
= new Composite(composite
, SWT
.NULL
);
160 GridLayout gridLayoutControl
= new GridLayout();
162 control
.setLayout(gridLayoutControl
);
163 control
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
164 // Composite control = toolkit.createComposite(composite);
165 btnIncludeAcceptedTaxa
= new Button(control
, SWT
.CHECK
);
166 btnIncludeAcceptedTaxa
.setText(Messages
.SetSecundumConfiguration_IncludeAcceptedTaxa
);
167 btnIncludeAcceptedTaxa
.setSelection(configurator
.isIncludeAcceptedTaxa());
168 btnIncludeAcceptedTaxa
.addListener(SWT
.Selection
, new Listener() {
170 public void handleEvent(Event e
) {
171 Button b
= (Button
) e
.widget
;
172 GridData data
= (GridData
) btnIncludeAcceptedTaxa
.getLayoutData();
173 data
.exclude
= b
.getSelection();
174 btnOverwriteExistingAccepted
.setVisible(data
.exclude
);
175 btnIncludeSharedTaxa
.setVisible(data
.exclude
);
176 if (!btnIncludeSynonyms
.getSelection() && !data
.exclude
){
177 btnEmptySecundumDetail
.setVisible(false);
178 setPageComplete(false);
180 btnEmptySecundumDetail
.setVisible(true);
181 setPageComplete(true);
186 btnOverwriteExistingAccepted
= new Button(control
, SWT
.CHECK
);
187 GridData gd_btnOverwriteExistingAccepted
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
188 gd_btnOverwriteExistingAccepted
.horizontalIndent
= 10;
189 btnOverwriteExistingAccepted
.setLayoutData(gd_btnOverwriteExistingAccepted
);
190 btnOverwriteExistingAccepted
.setText(Messages
.SetSecundumConfiguration_OverwriteExistingAccepted
);
192 btnIncludeSharedTaxa
= new Button(control
, SWT
.CHECK
);
193 GridData gd_btnIncludeSharedTaxa
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
194 gd_btnIncludeSharedTaxa
.horizontalIndent
= 10;
195 btnIncludeSharedTaxa
.setLayoutData(gd_btnIncludeSharedTaxa
);
196 btnIncludeSharedTaxa
.setText(Messages
.SetSecundumConfiguration_IncludeSharedtaxa
);
197 btnIncludeSharedTaxa
.setSelection(configurator
.isIncludeSharedTaxa());
199 btnIncludeSynonyms
= new Button(control
, SWT
.CHECK
);
200 btnIncludeSynonyms
.setText(Messages
.SetSecundumConfiguration_IncludeSynonyms
);
201 btnIncludeSynonyms
.setSelection(configurator
.isIncludeSynonyms());
202 btnIncludeSynonyms
.addListener(SWT
.Selection
, new Listener() {
204 public void handleEvent(Event e
) {
205 Button b
= (Button
) e
.widget
;
206 GridData data
= (GridData
) btnIncludeSynonyms
.getLayoutData();
207 data
.exclude
= b
.getSelection();
208 btnOverwriteExistingSynonyms
.setVisible(data
.exclude
);
209 if (!btnIncludeAcceptedTaxa
.getSelection() && !data
.exclude
){
210 btnEmptySecundumDetail
.setVisible(false);
211 setPageComplete(false);
213 btnEmptySecundumDetail
.setVisible(true);
214 setPageComplete(true);
220 btnOverwriteExistingAccepted
.setSelection(configurator
.isOverwriteExistingAccepted());
221 btnOverwriteExistingSynonyms
= new Button(control
, SWT
.CHECK
);
222 GridData gd_btnOverwriteExistingSynonyms
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
223 gd_btnOverwriteExistingSynonyms
.horizontalIndent
= 10;
224 btnOverwriteExistingSynonyms
.setLayoutData(gd_btnOverwriteExistingSynonyms
);
225 btnOverwriteExistingSynonyms
.setText(Messages
.SetSecundumConfiguration_OverwriteExistingSynonyms
);
226 btnOverwriteExistingSynonyms
.setSelection(configurator
.isOverwriteExistingSynonyms());
227 btnEmptySecundumDetail
= new Button(control
, SWT
.CHECK
);
228 btnEmptySecundumDetail
.setText(Messages
.SetSecundumConfiguration_EmptySecundumDetail
);
229 btnEmptySecundumDetail
.setSelection(configurator
.isEmptySecundumDetail());
231 m_bindingContext
= initDataBindings();
232 setControl(composite
);
238 public void handleEvent(Event event
) {
240 if(event
.widget
==btnBrowseReference
){
241 reference
= SelectionDialogFactory
.getSelectionFromDialog(Reference
.class, this.getShell(), null, null);
243 this.configurator
.setNewSecundum(reference
);
244 textReference
.setText(reference
.getTitleCache());
248 } else if(event
.widget
==btnClear
){
250 textReference
.setText("");
251 this.configurator
.setNewSecundum(null);
254 textReference
.setText("");
255 this.configurator
.setNewSecundum(null);
264 // public AbstractCdmDetailElement createElement(ICdmFormElement rootElement) {
265 // // TODO Auto-generated method stub