- refactored delete configrator dialog
[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
24 /**
25 * Abstract subclass of MessageDialog providing the functionality to configure
26 * a {@link DeleteConfiguratorBase}
27 * @author pplitzner
28 * @date Jan 28, 2015
29 *
30 */
31 public class DeleteConfiguratorDialog extends MessageDialog{
32
33 private final DeleteConfiguratorBase configurator;
34
35 public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
36 Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
37 super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
38 this.configurator = configurator;
39 }
40
41 /* (non-Javadoc)
42 * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
43 */
44 @Override
45 protected Control createCustomArea(Composite parent) {
46 DeleteConfiguratorComposite composite = new DeleteConfiguratorComposite(parent, NONE);
47 if(configurator instanceof TaxonBaseDeletionConfigurator){
48 composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonBaseDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
49 }
50 else if(configurator instanceof SpecimenDeleteConfigurator){
51 composite.addConfiguratorComposite(new DeleteSpecimenConfiguratorComposite((SpecimenDeleteConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
52 }
53 return composite;
54 }
55
56 public static boolean openConfirmWithConfigurator(DeleteConfiguratorBase configurator, Shell parent, String title, String message) {
57 DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
58 return dialog.open() == 0;
59 }
60
61 /* (non-Javadoc)
62 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
63 */
64 @Override
65 protected boolean isResizable() {
66 return true;
67 }
68
69
70 /**
71 * @param kind
72 * @return
73 */
74 protected static String[] getButtonLabels(int kind) {
75 String[] dialogButtonLabels;
76 switch (kind) {
77 case ERROR:
78 case INFORMATION:
79 case WARNING: {
80 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
81 break;
82 }
83 case CONFIRM: {
84 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
85 IDialogConstants.CANCEL_LABEL };
86 break;
87 }
88 case QUESTION: {
89 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
90 IDialogConstants.NO_LABEL };
91 break;
92 }
93 case QUESTION_WITH_CANCEL: {
94 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
95 IDialogConstants.NO_LABEL,
96 IDialogConstants.CANCEL_LABEL };
97 break;
98 }
99 default: {
100 throw new IllegalArgumentException(
101 "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
102 }
103 }
104 return dialogButtonLabels;
105 }
106 }