ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / deleteConfigurator / DeleteConfiguratorDialog.java
1 /**
2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator;
10
11 import org.eclipse.jface.dialogs.IDialogConstants;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Shell;
18
19 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
20 import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
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.SynonymDeletionConfigurator;
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 @Override
45 protected Control createCustomArea(Composite parent) {
46 DeleteConfiguratorComposite composite = new DeleteConfiguratorComposite(parent, NONE);
47 if(configurator instanceof TaxonDeletionConfigurator){
48 composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
49 }else if (configurator instanceof SynonymDeletionConfigurator){
50 composite.addConfiguratorComposite(new DeleteTaxonBaseConfiguratorComposite((SynonymDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
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 } else if(configurator instanceof NameDeletionConfigurator){
56 composite.addConfiguratorComposite(new DeleteNameConfiguratorComposite((NameDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
57 } else if(configurator instanceof MediaDeletionConfigurator){
58 composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
59 }
60
61
62 return composite;
63 }
64
65 public static boolean openConfirmWithConfigurator(DeleteConfiguratorBase configurator, Shell parent, String title, String message) {
66 DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
67 return dialog.open() == 0;
68 }
69
70 @Override
71 protected boolean isResizable() {
72 return true;
73 }
74
75
76 protected static String[] getButtonLabels(int kind) {
77 String[] dialogButtonLabels;
78 switch (kind) {
79 case ERROR:
80 case INFORMATION:
81 case WARNING: {
82 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
83 break;
84 }
85 case CONFIRM: {
86 dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
87 IDialogConstants.CANCEL_LABEL };
88 break;
89 }
90 case QUESTION: {
91 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
92 IDialogConstants.NO_LABEL };
93 break;
94 }
95 case QUESTION_WITH_CANCEL: {
96 dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
97 IDialogConstants.NO_LABEL,
98 IDialogConstants.CANCEL_LABEL };
99 break;
100 }
101 default: {
102 throw new IllegalArgumentException(
103 "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
104 }
105 }
106 return dialogButtonLabels;
107 }
108 }