Project

General

Profile

Download (3.47 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.IFeatureTreeService;
24
import eu.etaxonomy.cdm.model.description.FeatureTree;
25
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
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
 * @version 1.0
34
 */
35
public class FeatureTreeSelectionDialog extends
36
		AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
37

    
38
	public static FeatureTree select(Shell shell,
39
	        FeatureTree featureTree) {
40
		FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell,
41
				Messages.FeatureTreeSelectionDialog_CHOOSE_TREE, false, featureTree);
42
		return getSelectionFromDialog(dialog);
43
	}
44

    
45
	protected FeatureTreeSelectionDialog(Shell shell,
46
			 String title, boolean multi,
47
			FeatureTree cdmObject) {
48
		super(shell,
49
		        title, multi, FeatureTreeSelectionDialog.class.getCanonicalName(), cdmObject);
50
	}
51

    
52
	@Override
53
	protected FeatureTree getPersistentObject(UUID uuid) {
54
		return CdmStore.getService(IFeatureTreeService.class).load(uuid);
55
	}
56

    
57
	@Override
58
	protected void callService(String pattern) {
59
		List<FeatureTree> featureTrees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
60

    
61
		if(model == null){
62
			model = new ArrayList<UuidAndTitleCache<FeatureTree>>();
63
		}
64
		model.clear();
65
		for(FeatureTree featureTree : featureTrees){
66
			UuidAndTitleCache<FeatureTree> element = new UuidAndTitleCache<FeatureTree>(FeatureTree.class, featureTree.getUuid(),featureTree.getId(), featureTree.getTitleCache());
67
			if(pattern == null || element.getTitleCache().matches("(?i)"+pattern + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$
68
                model.add(element);
69
            }
70
		}
71

    
72
	}
73

    
74
	@Override
75
    protected SelectionListener getNewWizardButtonSelectionListener(){
76
        return new SelectionAdapter() {
77

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

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

    
98
	@Override
99
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
100
		return null;
101
	}
102
}
(15-15/44)