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