Project

General

Profile

Download (3.49 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.newWizard.AbstractNewEntityWizard;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

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

    
37
	public static FeatureTree select(Shell shell, //ConversationHolder conversation,
38
	        FeatureTree featureTree) {
39
		FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell, //conversation,
40
				"Choose a feature tree", false, featureTree);
41
		return getSelectionFromDialog(dialog);
42
	}
43

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

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

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

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

    
73
	}
74

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

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

    
94
	/** {@inheritDoc} */
95
	@Override
96
	protected String[] getNewWizardText() {
97
		return new String[]{ "New Feature tree"};
98
	}
99

    
100

    
101
	/** {@inheritDoc} */
102
	@Override
103
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
104
		return null;
105
	}
106
}
(13-13/42)