Project

General

Profile

Download (3.84 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2014 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.selection;
10

    
11
import java.util.UUID;
12

    
13
import org.eclipse.jface.dialogs.InputDialog;
14
import org.eclipse.jface.window.Window;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Shell;
20

    
21
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
22
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
23
import eu.etaxonomy.cdm.model.description.WorkingSet;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

    
28
/**
29
 * @author pplitzner
30
 * @date 11.03.2014
31
 *
32
 */
33
public class WorkingSetSelectionDialog extends
34
AbstractFilteredCdmResourceSelectionDialog<WorkingSet> {
35

    
36
    public static WorkingSet select(Shell shell, WorkingSet workingSet){
37
        WorkingSetSelectionDialog dialog = new WorkingSetSelectionDialog(shell,
38
                "Choose working set", false, WorkingSetSelectionDialog.class.getCanonicalName(), workingSet);
39
        return getSelectionFromDialog(dialog);
40
    }
41

    
42
    /**
43
     * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
44
     */
45
    protected WorkingSetSelectionDialog(Shell shell, String title,
46
            boolean multi, String settings, WorkingSet cdmObject) {
47
        super(shell, title, multi, settings, cdmObject);
48
    }
49

    
50
    /** {@inheritDoc} */
51
    @Override
52
    protected WorkingSet getPersistentObject(UUID uuid) {
53
        Object object = CdmStore.getService(IWorkingSetService.class).load(uuid);
54

    
55
        WorkingSet workingSet = (WorkingSet) HibernateProxyHelper.deproxy(object);
56

    
57
        if(workingSet != null){
58
            return workingSet;
59
        }
60
        MessagingUtils.error(this.getClass(), "Selected element is not a working set", null);
61
        return null;
62
    }
63

    
64
    /** {@inheritDoc} */
65
    @Override
66
    protected void callService(String pattern) {
67
        model = CdmStore.getService(IWorkingSetService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
68
    }
69

    
70
    @Override
71
    protected String getTitle(WorkingSet cdmObject) {
72
        if(cdmObject!=null){
73
            return cdmObject.getLabel();
74
        }
75
        return super.getTitle(cdmObject);
76
    }
77

    
78
    /** {@inheritDoc} */
79
    @Override
80
    protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
81
        return null;
82
    }
83

    
84
    @Override
85
    protected SelectionListener getNewWizardButtonSelectionListener(){
86
        return new SelectionAdapter() {
87

    
88
            @Override
89
            public void widgetSelected(SelectionEvent e) {
90
                Object source = e.getSource();
91
                if (source instanceof Button){
92
                    Button sourceButton = (Button) source;
93
                }
94
                InputDialog dialog = new InputDialog(getShell(), "Working set label", "Enter label for working set", null, null);
95
                if (dialog.open() == Window.OK) {
96
                    // User clicked OK; update the label with the input
97
                    WorkingSet workingSet = WorkingSet.NewInstance();
98
                    CdmStore.getService(IWorkingSetService.class).merge(workingSet,true);
99
                    workingSet.setLabel(dialog.getValue());
100
                    workingSet.setTitleCache(dialog.getValue(), true);
101
                    refresh();
102
                    setPattern(workingSet);
103
                  }
104
            }
105
        };
106
    }
107

    
108
    /** {@inheritDoc} */
109
    @Override
110
    protected String[] getNewWizardText() {
111
        return new String[]{"Working set "};
112
    }
113

    
114
}
(40-40/40)