From 7bd84a66b41a608ce800f3a21f98c3f82829fb1d Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Tue, 21 Mar 2017 14:54:02 +0100
Subject: [PATCH] ref #6527 Refactor configurator composite
---
.../descriptive/handler/DeleteHandler.java | 7 +-
.../DeleteConfiguratorDialog.java | 10 +-
.../DeleteMediaConfiguratorComposite.java | 117 +++++-------------
3 files changed, 31 insertions(+), 103 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
index 19fc669d1..1da0001b9 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
@@ -17,8 +17,6 @@ import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
@@ -105,10 +103,7 @@ public class DeleteHandler extends AbstractHandler {
// TODO use undo context specific to editor
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
- DeleteConfiguratorDialog dialog;
- dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), Messages.DeleteHandler_CONFIRM_DELETION, null, Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteHandler_DELETE, Messages.DeleteHandler_SKIP }, 0);
- int result_dialog= dialog.open();
- if (result_dialog != Status.OK){
+ if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), Messages.DeleteHandler_CONFIRM_DELETION, Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){
return null;
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java
index 53426590b..41a673982 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java
@@ -46,9 +46,7 @@ public class DeleteConfiguratorDialog extends MessageDialog{
public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
- super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
- this.configurator = configurator;
- this.fromBulkEditor = false;
+ this(configurator, parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex, false);
}
@Override
@@ -65,11 +63,7 @@ public class DeleteConfiguratorDialog extends MessageDialog{
} else if(configurator instanceof NameDeletionConfigurator){
composite.addConfiguratorComposite(new DeleteNameConfiguratorComposite((NameDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
} else if(configurator instanceof MediaDeletionConfigurator){
- if (!fromBulkEditor){
- composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE, fromBulkEditor));
- }else{
- composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
- }
+ composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE, fromBulkEditor));
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java
index 6b5c3cd1d..f6ad7ee75 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java
@@ -15,14 +15,11 @@ import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
@@ -40,48 +37,12 @@ public class DeleteMediaConfiguratorComposite extends Composite {
private final MediaDeletionConfigurator configurator;
private final Button btnDeleteIfUsedInTaxonDescription;
private final Button btnDeleteIfUsedInSpecimenDescription;
- private final Button btnRemoveFromImageGallery;
- private final boolean isInBulkEditor;
+ private Button btnRemoveFromImageGallery;
- /**
- * Create the composite.
- * @param parent
- * @param style
- */
- public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style) {
- super(parent, style);
- this.configurator = configurator;
- this.isInBulkEditor = false;
- addDisposeListener(new DisposeListener() {
- @Override
- public void widgetDisposed(DisposeEvent e) {
- toolkit.dispose();
- }
- });
- toolkit.paintBordersFor(this);
- setLayout(new RowLayout(SWT.VERTICAL));
- setBackground(getBackground());
-
- btnRemoveFromImageGallery = null;
-
- btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
- btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
- btnDeleteIfUsedInTaxonDescription.setSelection(false);
-
- btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
- btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
- btnDeleteIfUsedInSpecimenDescription.setSelection(false);
-
-
- m_bindingContext = initDataBindings();
-
- }
-
public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style, boolean inBulkEditor) {
super(parent, style);
this.configurator = configurator;
- this.isInBulkEditor = inBulkEditor;
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
@@ -89,56 +50,37 @@ public class DeleteMediaConfiguratorComposite extends Composite {
}
});
toolkit.paintBordersFor(this);
- setLayout(new GridLayout());
+ setLayout(new RowLayout(SWT.VERTICAL));
setBackground(getBackground());
-
-
-
- if (!inBulkEditor){
- btnRemoveFromImageGallery = new Button(this, SWT.RADIO);
- btnRemoveFromImageGallery.setText(Messages.DeleteConfiguration_media_removeFromGallery);
-
- btnRemoveFromImageGallery.setSelection(true);
- btnRemoveFromImageGallery.setVisible(true);
- btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.RADIO);
- btnDeleteIfUsedInTaxonDescription.setSelection(false);
- btnDeleteIfUsedInTaxonDescription.setVisible(true);
- btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_delete);
- btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
- btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
- btnDeleteIfUsedInSpecimenDescription.setVisible(false);
- btnDeleteIfUsedInTaxonDescription.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event e) {
- Button b = (Button) e.widget;
- GridData data = (GridData) btnDeleteIfUsedInTaxonDescription.getLayoutData();
- data.exclude = b.getSelection();
- btnDeleteIfUsedInSpecimenDescription.setVisible(data.exclude);
-
- }
- });
-
-
-
-
- } else{
- btnRemoveFromImageGallery =null;
+ if (inBulkEditor){
btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
- btnDeleteIfUsedInTaxonDescription.setSelection(false);
btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
- btnDeleteIfUsedInTaxonDescription.setVisible(true);
-
- btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
- btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
- btnDeleteIfUsedInSpecimenDescription.setVisible(true);
}
+ else {
+ btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.RADIO);
+ btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_delete);
+ btnRemoveFromImageGallery = new Button(this, SWT.RADIO);
+ btnRemoveFromImageGallery.setText(Messages.DeleteConfiguration_media_removeFromGallery);
+ }
+ btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
+ btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
+ if(inBulkEditor){
+ btnDeleteIfUsedInSpecimenDescription.setEnabled(true);
+ }
+ else{
+ btnDeleteIfUsedInSpecimenDescription.setEnabled(false);
+ btnDeleteIfUsedInTaxonDescription.addListener(SWT.Selection, (Event e) -> {
+ Button b = (Button) e.widget;
+ btnDeleteIfUsedInSpecimenDescription.setEnabled(b.getSelection());
-
+ });
+ }
+ btnDeleteIfUsedInTaxonDescription.setSelection(true);
m_bindingContext = initDataBindings();
@@ -150,20 +92,17 @@ public class DeleteMediaConfiguratorComposite extends Composite {
IObservableValue observeSelectionBtnDeleteIfUsedInTaxonDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInTaxonDescription);
IObservableValue deleteIfUsedInTaxonDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInTaxonDescription").observe(configurator);
bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInTaxonDescription, deleteIfUsedInTaxonDescriptionConfiguratorObserveValue, null, null);
- if (isInBulkEditor){
- IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
- IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
- bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
- }else{
+
+ if(btnRemoveFromImageGallery!=null){
IObservableValue observeSelectionBtnRemoveFromImageGallery = WidgetProperties.selection().observe(btnRemoveFromImageGallery);
IObservableValue removeFromImageGalleryConfiguratorObserveValue = PojoProperties.value("onlyRemoveFromGallery").observe(configurator);
bindingContext.bindValue(observeSelectionBtnRemoveFromImageGallery, removeFromImageGalleryConfiguratorObserveValue, null, null);
-
- IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
- IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
- bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
}
+ IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
+ IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
+ bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
+
return bindingContext;
}
--
2.34.1