Project

General

Profile

Download (4.91 KB) Statistics
| Branch: | Tag: | Revision:
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.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

    
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

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

    
45
    @Override
46
    protected Control createCustomArea(Composite parent) {
47
        DeleteConfiguratorComposite composite = new DeleteConfiguratorComposite(parent, NONE);
48
        if(configurator instanceof TaxonDeletionConfigurator){
49
            composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
50
        }else if (configurator instanceof SynonymDeletionConfigurator){
51
            composite.addConfiguratorComposite(new DeleteTaxonBaseConfiguratorComposite((SynonymDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
52
        }else if(configurator instanceof SpecimenDeleteConfigurator){
53
            composite.addConfiguratorComposite(new DeleteSpecimenConfiguratorComposite((SpecimenDeleteConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
54
        } else if(configurator instanceof TaxonNodeDeletionConfigurator){
55
            composite.addConfiguratorComposite(new DeleteNodeConfiguratorComposite((TaxonNodeDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
56
        }  else if(configurator instanceof NameDeletionConfigurator){
57
            composite.addConfiguratorComposite(new DeleteNameConfiguratorComposite((NameDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
58
        }  else if(configurator instanceof MediaDeletionConfigurator){
59
            composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
60
        }
61

    
62

    
63
        return composite;
64
    }
65

    
66
    public static boolean openConfirmWithConfigurator(DeleteConfiguratorBase configurator, Shell parent, String title, String message) {
67
        DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
68
        return dialog.open() == 0;
69
    }
70

    
71
    @Override
72
    protected boolean isResizable() {
73
        return true;
74
    }
75

    
76

    
77
    protected static String[] getButtonLabels(int kind) {
78
        String[] dialogButtonLabels;
79
        switch (kind) {
80
        case ERROR:
81
        case INFORMATION:
82
        case WARNING: {
83
            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
84
            break;
85
        }
86
        case CONFIRM: {
87
            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
88
                    IDialogConstants.CANCEL_LABEL };
89
            break;
90
        }
91
        case QUESTION: {
92
            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
93
                    IDialogConstants.NO_LABEL };
94
            break;
95
        }
96
        case QUESTION_WITH_CANCEL: {
97
            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
98
                    IDialogConstants.NO_LABEL,
99
                    IDialogConstants.CANCEL_LABEL };
100
            break;
101
        }
102
        default: {
103
            throw new IllegalArgumentException(
104
                    "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
105
        }
106
        }
107
        return dialogButtonLabels;
108
    }
109
}
(2-2/7)