Project

General

Profile

Download (3.38 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11

    
12
import java.util.UUID;
13

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

    
21
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
22
import eu.etaxonomy.cdm.model.term.TermType;
23
import eu.etaxonomy.cdm.model.term.FeatureTree;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

    
28
/**
29
 * @author n.hoffmann
30
 * @created Sep 17, 2010
31
 */
32
public class FeatureTreeSelectionDialog extends
33
		AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
34

    
35
    private final TermType termType;
36

    
37
    public static FeatureTree select(Shell shell,
38
            FeatureTree featureTree) {
39
        return select(shell, featureTree, null);
40

    
41
    }
42
	public static FeatureTree select(Shell shell,
43
	        FeatureTree featureTree, TermType termType) {
44
		FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell,
45
				Messages.FeatureTreeSelectionDialog_CHOOSE_TREE, false, featureTree, termType);
46
		return getSelectionFromDialog(dialog);
47
	}
48

    
49
	protected FeatureTreeSelectionDialog(Shell shell,
50
			 String title, boolean multi,
51
			FeatureTree cdmObject, TermType termType) {
52
		super(shell, title, multi, FeatureTreeSelectionDialog.class.getCanonicalName(), cdmObject);
53
		this.termType = termType;
54
	}
55

    
56
	@Override
57
	protected FeatureTree getPersistentObject(UUID uuid) {
58
		return CdmStore.getService(IFeatureTreeService.class).load(uuid);
59
	}
60

    
61
	@Override
62
	protected void callService(String pattern) {
63
        model = CdmStore.getService(IFeatureTreeService.class).getUuidAndTitleCacheByTermType(FeatureTree.class, termType, limitOfInitialElements, pattern);
64
	}
65

    
66
	@Override
67
    protected SelectionListener getNewWizardButtonSelectionListener(){
68
        return new SelectionAdapter() {
69

    
70
            @Override
71
            public void widgetSelected(SelectionEvent e) {
72
                InputDialog dialog = new InputDialog(getShell(), Messages.FeatureTreeSelectionDialog_TREE_LABEL, Messages.FeatureTreeSelectionDialog_ENTER_LABEL, null, null);
73
                if (dialog.open() == Window.OK) {
74
                    // User clicked OK; update the label with the input
75
                    FeatureTree tree = null;
76
                    if(termType!=null){
77
                        tree = FeatureTree.NewInstance(termType);
78
                    }
79
                    else{
80
                        tree = FeatureTree.NewInstance();
81
                    }
82
                    tree.setTitleCache(dialog.getValue(), true);
83
                    CdmStore.getService(IFeatureTreeService.class).merge(tree,true);
84
                    refresh();
85
                    setPattern(tree);
86
                  }
87
            }
88
        };
89
    }
90

    
91
	@Override
92
	protected String[] getNewWizardText() {
93
		return new String[]{ Messages.FeatureTreeSelectionDialog_NEW_TREE};
94
	}
95

    
96
	@Override
97
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
98
		return null;
99
	}
100
}
(15-15/45)