Updated version in pom / project files to taxeditor version : 4.13.0-SNAPSHOT and...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / FeatureTreeSelectionDialog.java
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.swt.widgets.Shell;
17
18 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
19 import eu.etaxonomy.cdm.model.description.FeatureTree;
20 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author n.hoffmann
26 * @created Sep 17, 2010
27 * @version 1.0
28 */
29 public class FeatureTreeSelectionDialog extends
30 AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
31
32 public static FeatureTree select(Shell shell, //ConversationHolder conversation,
33 FeatureTree featureTree) {
34 FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell, //conversation,
35 "Choose a feature tree", false, featureTree);
36 return getSelectionFromDialog(dialog);
37 }
38
39 protected FeatureTreeSelectionDialog(Shell shell,//ConversationHolder conversation,
40 String title, boolean multi,
41 FeatureTree cdmObject) {
42 super(shell, //conversation,
43 title, multi, FeatureTreeSelectionDialog.class.getCanonicalName(), cdmObject);
44 }
45
46 /** {@inheritDoc} */
47 @Override
48 protected FeatureTree getPersistentObject(UUID uuid) {
49 return CdmStore.getService(IFeatureTreeService.class).load(uuid);
50 }
51
52 /** {@inheritDoc} */
53 @Override
54 protected void callService(String pattern) {
55 List<FeatureTree> featureTrees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
56
57 if(model == null){
58 model = new ArrayList<UuidAndTitleCache<FeatureTree>>();
59 }
60 model.clear();
61 for(FeatureTree featureTree : featureTrees){
62 UuidAndTitleCache<FeatureTree> element = new UuidAndTitleCache<FeatureTree>(FeatureTree.class, featureTree.getUuid(),featureTree.getId(), featureTree.getTitleCache());
63 if (element.getTitleCache().matches(pattern)) {
64 model.add(element);
65 }
66 }
67
68 }
69
70 // /** {@inheritDoc} */
71 // @Override
72 // protected Control createExtendedContentArea(Composite parent) {
73 // Link link = new Link(parent, SWT.NONE);
74 // link.setText(getNewWizardLinkText());
75 // link.addListener (SWT.Selection, new Listener () {
76 // @Override
77 // public void handleEvent(Event event) {
78 //
79 // InputDialog input = new InputDialog(getShell(), "New feature tree", "Enter label for new feature tree", null, null);
80 // int status = input.open();
81 // if (status == IStatus.OK) {
82 // String label = input.getValue();
83 // if(label!=null){
84 // FeatureTree featureTree = FeatureTree.NewInstance();
85 // featureTree.setTitleCache(label, false);
86 // CdmStore.getService(IFeatureTreeService.class).save(featureTree);
87 // UuidAndTitleCache<FeatureTree> uuidAndTitleCache = new UuidAndTitleCache<FeatureTree>(FeatureTree.class, featureTree.getUuid(),featureTree.getId(), featureTree.getTitleCache());
88 // model.add(uuidAndTitleCache);
89 // setPattern(featureTree);
90 // }
91 // }
92 // }
93 // });
94 // return link;
95 // }
96
97 /** {@inheritDoc} */
98 @Override
99 protected String[] getNewWizardText() {
100 return new String[]{ "New Feature tree"};
101 }
102
103
104 /** {@inheritDoc} */
105 @Override
106 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
107 return null;
108 }
109 }