ref #7095 Add column sorting to character matrix
[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.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 search() {
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 model.add(element);
69 }
70 }
71
72 @Override
73 protected SelectionListener getNewWizardButtonSelectionListener(){
74 return new SelectionAdapter() {
75
76 @Override
77 public void widgetSelected(SelectionEvent e) {
78 InputDialog dialog = new InputDialog(getShell(), "Feature tree label", "Enter label for feature tree", null, null);
79 if (dialog.open() == Window.OK) {
80 // User clicked OK; update the label with the input
81 FeatureTree tree = FeatureTree.NewInstance();
82 CdmStore.getService(IFeatureTreeService.class).merge(tree,true);
83 tree.setTitleCache(dialog.getValue(), true);
84 refresh();
85 setPattern(tree);
86 }
87 }
88 };
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 protected String[] getNewWizardText() {
94 return new String[]{ "Feature tree "};
95 }
96
97
98 /** {@inheritDoc} */
99 @Override
100 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
101 return null;
102 }
103 }