Project

General

Profile

Download (3.42 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
 */
34
public class FeatureTreeSelectionDialog extends
35
		AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
36

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

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

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

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

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

    
71
	}
72

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

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

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

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