ref #6527 Refactor configurator composite
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 21 Mar 2017 13:54:02 +0000 (14:54 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 21 Mar 2017 13:54:02 +0000 (14:54 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java

index 19fc669d10874a2a91f9823fa603cc632558a468..1da0001b93d5f1eb7e75843c1e67b3d27fb8a7fa 100644 (file)
@@ -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;
                     }
 
index 53426590b4eebc22ffdbaebd1ebb56c5379dd304..41a673982b35902833d6f5c1346ca2bc6025138b 100644 (file)
@@ -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));
         }
 
 
index 6b5c3cd1dd027c2c70c72ba175f0df918c7570bf..f6ad7ee75ca18033d66cd64af0d8e79429917a16 100644 (file)
@@ -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;
     }