Project

General

Profile

Download (5.83 KB) Statistics
| Branch: | Tag: | Revision:
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.configurator.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.DeleteDescriptiveDataSetConfigurator;
21
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
22
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
23
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
24
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
25
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
26
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
27
import eu.etaxonomy.taxeditor.ui.dialog.configurator.ConfiguratorComposite;
28

    
29
/**
30
 * Abstract subclass of MessageDialog providing the functionality to configure
31
 * a {@link DeleteConfiguratorBase}
32
 * @author pplitzner
33
 * @date Jan 28, 2015
34
 *
35
 */
36
public class DeleteConfiguratorDialog extends MessageDialog{
37

    
38
    private final DeleteConfiguratorBase configurator;
39
    private final boolean fromBulkEditor;
40

    
41
    public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
42
            Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, boolean fromBulkEditor) {
43
        super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
44
        this.configurator = configurator;
45
        this.fromBulkEditor = fromBulkEditor;
46
    }
47

    
48
    public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
49
            Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
50
        this(configurator, parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex, false);
51
    }
52

    
53
    @Override
54
    protected Control createCustomArea(Composite parent) {
55
        ConfiguratorComposite composite = new ConfiguratorComposite(parent, NONE);
56
        if(configurator instanceof TaxonDeletionConfigurator){
57
            composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
58
        }else if (configurator instanceof SynonymDeletionConfigurator){
59
            composite.addConfiguratorComposite(new DeleteTaxonBaseConfiguratorComposite((SynonymDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
60
        }else if(configurator instanceof SpecimenDeleteConfigurator){
61
            composite.addConfiguratorComposite(new DeleteSpecimenConfiguratorComposite((SpecimenDeleteConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
62
        } else if(configurator instanceof TaxonNodeDeletionConfigurator){
63
            composite.addConfiguratorComposite(new DeleteNodeConfiguratorComposite((TaxonNodeDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
64
        }  else if(configurator instanceof NameDeletionConfigurator){
65
            composite.addConfiguratorComposite(new DeleteNameConfiguratorComposite((NameDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
66
        }  else if(configurator instanceof MediaDeletionConfigurator){
67
            composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE, fromBulkEditor));
68
        } else if(configurator instanceof DeleteDescriptiveDataSetConfigurator){
69
            composite.addConfiguratorComposite(new DeleteDescriptiveDatasetConfiguratorComposite((DeleteDescriptiveDataSetConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
70
        }
71

    
72

    
73
        return composite;
74
    }
75

    
76
    public static boolean openConfirmWithConfigurator(DeleteConfiguratorBase configurator, Shell parent, String title, String message) {
77
        DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
78
        return dialog.open() == 0;
79
    }
80

    
81
    @Override
82
    protected boolean isResizable() {
83
        return true;
84
    }
85

    
86

    
87
    protected static String[] getButtonLabels(int kind) {
88
        String[] dialogButtonLabels;
89
        switch (kind) {
90
        case ERROR:
91
        case INFORMATION:
92
        case WARNING: {
93
            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
94
            break;
95
        }
96
        case CONFIRM: {
97
            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
98
                    IDialogConstants.CANCEL_LABEL };
99
            break;
100
        }
101
        case QUESTION: {
102
            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
103
                    IDialogConstants.NO_LABEL };
104
            break;
105
        }
106
        case QUESTION_WITH_CANCEL: {
107
            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
108
                    IDialogConstants.NO_LABEL,
109
                    IDialogConstants.CANCEL_LABEL };
110
            break;
111
        }
112
        default: {
113
            throw new IllegalArgumentException(
114
                    "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
115
        }
116
        }
117
        return dialogButtonLabels;
118
    }
119
}
(1-1/8)