Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / configurator / SetSecundumConfiguratorWizardPage.java
1 /**
2 * Copyright (C) 2017 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;
10
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;
28
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;
35
36 /**
37 * @author k.luther
38 * @date 10.02.2017
39 *
40 */
41 public class SetSecundumConfiguratorWizardPage extends WizardPage implements Listener {
42 private DataBindingContext m_bindingContext;
43
44 private final static CdmFormFactory toolkit = new CdmFormFactory(Display.getCurrent());
45 private final SetSecundumForSubtreeConfigurator configurator;
46
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;
57
58
59 /**
60 * Create the composite.
61 * @param parent
62 * @param style
63 */
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);
68
69 // addDisposeListener(new DisposeListener() {
70 // @Override
71 // public void widgetDisposed(DisposeEvent e) {
72 // toolkit.dispose();
73 // }
74 // });
75 // toolkit.paintBordersFor(this);
76 // setLayout(new GridLayout());
77 // setBackground(getBackground());
78
79
80
81
82 }
83
84 /**
85 * @return
86 */
87 private DataBindingContext initDataBindings() {
88 DataBindingContext bindingContext = new DataBindingContext();
89
90 IObservableValue observeSelectionBtnIncludeAcceptedTaxa = WidgetProperties.selection().observe(btnIncludeAcceptedTaxa);
91 IObservableValue includeAcceptedTaxaConfiguratorObserveValue = PojoProperties.value("includeAcceptedTaxa").observe(configurator);
92 bindingContext.bindValue(observeSelectionBtnIncludeAcceptedTaxa, includeAcceptedTaxaConfiguratorObserveValue, null, null);
93
94 IObservableValue observeSelectionBtnIncludeSynonyms = WidgetProperties.selection().observe(btnIncludeSynonyms);
95 IObservableValue includeSynonymsConfiguratorObserveValue = PojoProperties.value("includeSynonyms").observe(configurator);
96 bindingContext.bindValue(observeSelectionBtnIncludeSynonyms, includeSynonymsConfiguratorObserveValue, null, null);
97
98 IObservableValue observeSelectionBtnOverwriteExistingAccepted = WidgetProperties.selection().observe(btnOverwriteExistingAccepted);
99 IObservableValue overwriteExistingAcceptedConfiguratorObserveValue = PojoProperties.value("overwriteExistingAccepted").observe(configurator);
100 bindingContext.bindValue(observeSelectionBtnOverwriteExistingAccepted, overwriteExistingAcceptedConfiguratorObserveValue, null, null);
101
102 IObservableValue observeSelectionBtnOverwriteExistingSynonyms = WidgetProperties.selection().observe(btnOverwriteExistingSynonyms);
103 IObservableValue overwriteExistingSynonymsConfiguratorObserveValue = PojoProperties.value("overwriteExistingSynonyms").observe(configurator);
104 bindingContext.bindValue(observeSelectionBtnOverwriteExistingSynonyms, overwriteExistingSynonymsConfiguratorObserveValue, null, null);
105
106 IObservableValue observeSelectionBtnEmptySecundumDetail = WidgetProperties.selection().observe(btnEmptySecundumDetail);
107 IObservableValue emptySecundumDetailConfiguratorObserveValue = PojoProperties.value("emptySecundumDetail").observe(configurator);
108 bindingContext.bindValue(observeSelectionBtnEmptySecundumDetail, emptySecundumDetailConfiguratorObserveValue, null, null);
109
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;
114 }
115
116 @Override
117 public void createControl(Composite parent) {
118
119 final Composite composite = new Composite(parent, SWT.NULL);
120
121 GridLayout gridLayout = new GridLayout();
122 gridLayout.numColumns = 1;
123
124 composite.setLayout(gridLayout);
125 final Composite compositeRef = new Composite(composite, SWT.NULL);
126
127 GridLayout gridLayoutRef = new GridLayout();
128 gridLayoutRef.numColumns = 4;
129
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));
135
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);
140
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);
147
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;
152
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() {
160 @Override
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);
170 }else{
171 btnEmptySecundumDetail.setVisible(true);
172 setPageComplete(true);
173 }
174 }
175 });
176
177 btnOverwriteExistingAccepted = new Button(control, SWT.CHECK);
178 btnOverwriteExistingAccepted.setText(Messages.SetSecundumConfiguration_OverwriteExistingAccepted);
179
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() {
184 @Override
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);
193 }else{
194 btnEmptySecundumDetail.setVisible(true);
195 setPageComplete(true);
196 }
197
198 }
199 });
200
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());
208
209 btnIncludeSharedTaxa = new Button(control, SWT.CHECK);
210 btnIncludeSharedTaxa.setText(Messages.SetSecundumConfiguration_IncludeSharedtaxa);
211 btnIncludeSharedTaxa.setSelection(configurator.isIncludeSharedTaxa());
212
213 m_bindingContext = initDataBindings();
214 setControl(composite);
215 }
216
217
218
219 @Override
220 public void handleEvent(Event event) {
221 Reference reference;
222 if(event.widget==btnBrowseReference){
223 reference = SelectionDialogFactory.getSelectionFromDialog(Reference.class, this.getShell(), null, null);
224 if(reference!=null){
225 this.configurator.setNewSecundum(reference);
226 textReference.setText(reference.getTitleCache());
227
228 }
229
230 } else if(event.widget==btnClear){
231 reference = null;
232 textReference.setText("");
233 this.configurator.setNewSecundum(null);
234 } else{
235 reference = null;
236 textReference.setText("");
237 this.configurator.setNewSecundum(null);
238 }
239
240 }
241
242 // /**
243 // * {@inheritDoc}
244 // */
245 // @Override
246 // public AbstractCdmDetailElement createElement(ICdmFormElement rootElement) {
247 // // TODO Auto-generated method stub
248 // return null;
249 // }
250
251
252
253
254 }