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