2 * Copyright (C) 2016 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
.deleteConfigurator
;
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
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.MediaDeletionConfigurator
;
29 import eu
.etaxonomy
.taxeditor
.Messages
;
36 public class DeleteMediaConfiguratorComposite
extends Composite
{
37 private final DataBindingContext m_bindingContext
;
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
;
48 * Create the composite.
52 public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator
, Composite parent
, int style
) {
54 this.configurator
= configurator
;
55 this.isInBulkEditor
= false;
56 addDisposeListener(new DisposeListener() {
58 public void widgetDisposed(DisposeEvent e
) {
62 toolkit
.paintBordersFor(this);
63 setLayout(new RowLayout(SWT
.VERTICAL
));
64 setBackground(getBackground());
66 btnRemoveFromImageGallery
= null;
68 btnDeleteIfUsedInTaxonDescription
= new Button(this, SWT
.CHECK
);
69 btnDeleteIfUsedInTaxonDescription
.setText(Messages
.DeleteConfiguration_media_deleteIfUsedInTaxonDescription
);
70 btnDeleteIfUsedInTaxonDescription
.setSelection(false);
72 btnDeleteIfUsedInSpecimenDescription
= new Button(this, SWT
.CHECK
);
73 btnDeleteIfUsedInSpecimenDescription
.setText(Messages
.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription
);
74 btnDeleteIfUsedInSpecimenDescription
.setSelection(false);
77 m_bindingContext
= initDataBindings();
81 public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator
, Composite parent
, int style
, boolean inBulkEditor
) {
83 this.configurator
= configurator
;
84 this.isInBulkEditor
= inBulkEditor
;
85 addDisposeListener(new DisposeListener() {
87 public void widgetDisposed(DisposeEvent e
) {
91 toolkit
.paintBordersFor(this);
92 setLayout(new GridLayout());
93 setBackground(getBackground());
99 btnRemoveFromImageGallery
= new Button(this, SWT
.RADIO
);
100 btnRemoveFromImageGallery
.setText(Messages
.DeleteConfiguration_media_removeFromGallery
);
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() {
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
);
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);
132 btnDeleteIfUsedInSpecimenDescription
= new Button(this, SWT
.CHECK
);
133 btnDeleteIfUsedInSpecimenDescription
.setText(Messages
.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription
);
134 btnDeleteIfUsedInSpecimenDescription
.setVisible(true);
143 m_bindingContext
= initDataBindings();
147 protected DataBindingContext
initDataBindings() {
148 DataBindingContext bindingContext
= new DataBindingContext();
150 IObservableValue observeSelectionBtnDeleteIfUsedInTaxonDescription
= WidgetProperties
.selection().observe(btnDeleteIfUsedInTaxonDescription
);
151 IObservableValue deleteIfUsedInTaxonDescriptionConfiguratorObserveValue
= PojoProperties
.value("deleteIfUsedInTaxonDescription").observe(configurator
);
152 bindingContext
.bindValue(observeSelectionBtnDeleteIfUsedInTaxonDescription
, deleteIfUsedInTaxonDescriptionConfiguratorObserveValue
, null, null);
154 IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription
= WidgetProperties
.selection().observe(btnDeleteIfUsedInSpecimenDescription
);
155 IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue
= PojoProperties
.value("deleteIfUsedInSpecimenDescription").observe(configurator
);
156 bindingContext
.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription
, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue
, null, null);
158 IObservableValue observeSelectionBtnRemoveFromImageGallery
= WidgetProperties
.selection().observe(btnRemoveFromImageGallery
);
159 IObservableValue removeFromImageGalleryConfiguratorObserveValue
= PojoProperties
.value("onlyRemoveFromGallery").observe(configurator
);
160 bindingContext
.bindValue(observeSelectionBtnRemoveFromImageGallery
, removeFromImageGalleryConfiguratorObserveValue
, null, null);
162 IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription
= WidgetProperties
.selection().observe(btnDeleteIfUsedInSpecimenDescription
);
163 IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue
= PojoProperties
.value("deleteIfUsedInSpecimenDescription").observe(configurator
);
164 bindingContext
.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription
, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue
, null, null);
167 return bindingContext
;