Merge branch 'hotfix/4.5.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / deleteConfigurator / DeleteMediaConfiguratorComposite.java
1 /**
2 * Copyright (C) 2016 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.deleteConfigurator;
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.swt.SWT;
16 import org.eclipse.swt.events.DisposeEvent;
17 import org.eclipse.swt.events.DisposeListener;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.layout.RowLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Event;
25 import org.eclipse.swt.widgets.Listener;
26 import org.eclipse.ui.forms.widgets.FormToolkit;
27
28 import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
29 import eu.etaxonomy.taxeditor.Messages;
30
31 /**
32 * @author k.luther
33 * @date 02.11.2016
34 *
35 */
36 public class DeleteMediaConfiguratorComposite extends Composite {
37 private final DataBindingContext m_bindingContext;
38
39 private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
40 private final MediaDeletionConfigurator configurator;
41 private final Button btnDeleteIfUsedInTaxonDescription;
42 private final Button btnDeleteIfUsedInSpecimenDescription;
43 private final Button btnRemoveFromImageGallery;
44 private final boolean isInBulkEditor;
45
46
47 /**
48 * Create the composite.
49 * @param parent
50 * @param style
51 */
52 public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style) {
53 super(parent, style);
54 this.configurator = configurator;
55 this.isInBulkEditor = false;
56 addDisposeListener(new DisposeListener() {
57 @Override
58 public void widgetDisposed(DisposeEvent e) {
59 toolkit.dispose();
60 }
61 });
62 toolkit.paintBordersFor(this);
63 setLayout(new RowLayout(SWT.VERTICAL));
64 setBackground(getBackground());
65
66 btnRemoveFromImageGallery = null;
67
68 btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
69 btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
70 btnDeleteIfUsedInTaxonDescription.setSelection(false);
71
72 btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
73 btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
74 btnDeleteIfUsedInSpecimenDescription.setSelection(false);
75
76
77 m_bindingContext = initDataBindings();
78
79 }
80
81 public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style, boolean inBulkEditor) {
82 super(parent, style);
83 this.configurator = configurator;
84 this.isInBulkEditor = inBulkEditor;
85 addDisposeListener(new DisposeListener() {
86 @Override
87 public void widgetDisposed(DisposeEvent e) {
88 toolkit.dispose();
89 }
90 });
91 toolkit.paintBordersFor(this);
92 setLayout(new GridLayout());
93 setBackground(getBackground());
94
95
96
97
98 if (!inBulkEditor){
99 btnRemoveFromImageGallery = new Button(this, SWT.RADIO);
100 btnRemoveFromImageGallery.setText(Messages.DeleteConfiguration_media_removeFromGallery);
101
102 btnRemoveFromImageGallery.setSelection(true);
103 btnRemoveFromImageGallery.setVisible(true);
104 btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.RADIO);
105 btnDeleteIfUsedInTaxonDescription.setSelection(false);
106 btnDeleteIfUsedInTaxonDescription.setVisible(true);
107 btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_delete);
108 btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
109 btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
110 btnDeleteIfUsedInSpecimenDescription.setVisible(false);
111 btnDeleteIfUsedInTaxonDescription.addListener(SWT.Selection, new Listener() {
112 @Override
113 public void handleEvent(Event e) {
114 Button b = (Button) e.widget;
115 GridData data = (GridData) btnDeleteIfUsedInTaxonDescription.getLayoutData();
116 data.exclude = b.getSelection();
117 btnDeleteIfUsedInSpecimenDescription.setVisible(data.exclude);
118
119 }
120 });
121
122
123
124
125 } else{
126 btnRemoveFromImageGallery =null;
127 btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
128 btnDeleteIfUsedInTaxonDescription.setSelection(false);
129 btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
130 btnDeleteIfUsedInTaxonDescription.setVisible(true);
131
132 btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
133 btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
134 btnDeleteIfUsedInSpecimenDescription.setVisible(true);
135 }
136
137
138
139
140
141
142
143 m_bindingContext = initDataBindings();
144
145 }
146
147 protected DataBindingContext initDataBindings() {
148 DataBindingContext bindingContext = new DataBindingContext();
149 //
150 IObservableValue observeSelectionBtnDeleteIfUsedInTaxonDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInTaxonDescription);
151 IObservableValue deleteIfUsedInTaxonDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInTaxonDescription").observe(configurator);
152 bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInTaxonDescription, deleteIfUsedInTaxonDescriptionConfiguratorObserveValue, null, null);
153 if (isInBulkEditor){
154 IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
155 IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
156 bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
157 }else{
158 IObservableValue observeSelectionBtnRemoveFromImageGallery = WidgetProperties.selection().observe(btnRemoveFromImageGallery);
159 IObservableValue removeFromImageGalleryConfiguratorObserveValue = PojoProperties.value("onlyRemoveFromGallery").observe(configurator);
160 bindingContext.bindValue(observeSelectionBtnRemoveFromImageGallery, removeFromImageGalleryConfiguratorObserveValue, null, null);
161
162 IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
163 IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
164 bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
165 }
166
167 return bindingContext;
168 }
169
170
171 }