Merge branch 'release/3.8.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / deleteConfigurator / DeleteConfiguratorDialog.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator;
11
12 import org.eclipse.jface.dialogs.IDialogConstants;
13 import org.eclipse.jface.dialogs.MessageDialog;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Shell;
19
20 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
21 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
22 import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
23 import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
24
25 /**
26 * Abstract subclass of MessageDialog providing the functionality to configure
27 * a {@link DeleteConfiguratorBase}
28 * @author pplitzner
29 * @date Jan 28, 2015
30 *
31 */
32 public class DeleteConfiguratorDialog extends MessageDialog{
33
34 private final DeleteConfiguratorBase configurator;
35
36 public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
37 Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
38 super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
39 this.configurator = configurator;
40 }
41
42 /* (non-Javadoc)
43 * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
44 */
45 @Override
46 protected Control createCustomArea(Composite parent) {
47 DeleteConfiguratorComposite composite = new DeleteConfiguratorComposite(parent, NONE);
48 if(configurator instanceof TaxonBaseDeletionConfigurator){
49 composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonBaseDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
50 }
51 else if(configurator instanceof SpecimenDeleteConfigurator){
52 composite.addConfiguratorComposite(new DeleteSpecimenConfiguratorComposite((SpecimenDeleteConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
53 } else if(configurator instanceof TaxonNodeDeletionConfigurator){
54 composite.addConfiguratorComposite(new DeleteNodeConfiguratorComposite((TaxonNodeDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
55 }
56
57 return composite;
58 }
59
60 public static boolean openConfirmWithConfigurator(DeleteConfiguratorBase configurator, Shell parent, String title, String message) {
61 DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
62 return dialog.open() == 0;
63 }
64
65 /* (non-Javadoc)
66 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
67 */
68 @Override
69 protected boolean isResizable() {
70 return true;
71 }
72
73
74 /**
75 * @param kind
76 * @return
77 */
78 protected static String[] getButtonLabels(int kind) {
79 String[] dialogButtonLabels;
80 switch (kind) {
81 case ERROR:
82 case INFORMATION:
83 case WARNING: {
84 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
85 break;
86 }
87 case CONFIRM: {
88 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
89 IDialogConstants.CANCEL_LABEL };
90 break;
91 }
92 case QUESTION: {
93 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
94 IDialogConstants.NO_LABEL };
95 break;
96 }
97 case QUESTION_WITH_CANCEL: {
98 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
99 IDialogConstants.NO_LABEL,
100 IDialogConstants.CANCEL_LABEL };
101 break;
102 }
103 default: {
104 throw new IllegalArgumentException(
105 "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
106 }
107 }
108 return dialogButtonLabels;
109 }
110 }