Project

General

Profile

Download (5.78 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.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
import eu.etaxonomy.taxeditor.ui.dialog.configurator.ConfiguratorComposite;
27

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

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

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

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

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

    
75

    
76
        return composite;
77
    }
78

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

    
84
    @Override
85
    protected boolean isResizable() {
86
        return true;
87
    }
88

    
89

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