Project

General

Profile

Download (3.48 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.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

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

    
23
import eu.etaxonomy.cdm.api.service.ITermTreeService;
24
import eu.etaxonomy.cdm.model.term.TermTree;
25
import eu.etaxonomy.cdm.model.term.TermType;
26
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

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

    
37
    private final TermType termType;
38

    
39
    public static TermTree select(Shell shell,
40
    		TermTree featureTree) {
41
        return select(shell, featureTree, null);
42

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

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

    
58
	@Override
59
	protected TermTree getPersistentObject(UUID uuid) {
60
	    List<String> propertyPath = new ArrayList<>();
61
	    propertyPath.add("root.*");
62
		return CdmStore.getService(ITermTreeService.class).load(uuid, propertyPath);
63
	}
64

    
65
	@Override
66
	protected void callService(String pattern) {
67
        model = CdmStore.getService(ITermTreeService.class).getUuidAndTitleCacheByTermType(TermTree.class, termType, limitOfInitialElements, pattern);
68
	}
69

    
70
	@Override
71
    protected SelectionListener getNewWizardButtonSelectionListener(){
72
        return new SelectionAdapter() {
73

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

    
95
	@Override
96
	protected String[] getNewWizardText() {
97
		return new String[]{ Messages.FeatureTreeSelectionDialog_NEW_TREE};
98
	}
99

    
100
	@Override
101
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
102
		return null;
103
	}
104
}
(16-16/46)