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.wizard.WizardDialog;
|
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.featuretree.FeatureTreeEditorWizard;
|
31
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* <p>FilteredFeatureTreeSelectionDialog class.</p>
|
36
|
*
|
37
|
* @author n.hoffmann
|
38
|
* @created Sep 17, 2010
|
39
|
* @version 1.0
|
40
|
*/
|
41
|
public class FeatureTreeSelectionDialog extends
|
42
|
AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
|
43
|
|
44
|
/**
|
45
|
* Creates a filtered selection dialog to select a named area.
|
46
|
*
|
47
|
* @param shell
|
48
|
* The shell for displaying this widget
|
49
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
50
|
* @param featureTree a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
51
|
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
52
|
*/
|
53
|
public static FeatureTree select(Shell shell, ConversationHolder conversation, FeatureTree featureTree) {
|
54
|
FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell, conversation,
|
55
|
"Choose a feature tree", false, featureTree);
|
56
|
return getSelectionFromDialog(dialog);
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* <p>Constructor for FilteredFeatureTreeSelectionDialog.</p>
|
61
|
*
|
62
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
63
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
64
|
* @param title a {@link java.lang.String} object.
|
65
|
* @param multi a boolean.
|
66
|
* @param cdmObject a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
67
|
*/
|
68
|
protected FeatureTreeSelectionDialog(Shell shell,
|
69
|
ConversationHolder conversation, String title, boolean multi,
|
70
|
FeatureTree cdmObject) {
|
71
|
super(shell, conversation, title, multi, FeatureTreeSelectionDialog.class.getCanonicalName(), cdmObject);
|
72
|
}
|
73
|
|
74
|
/* (non-Javadoc)
|
75
|
* @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
76
|
*/
|
77
|
/** {@inheritDoc} */
|
78
|
@Override
|
79
|
protected FeatureTree getPersistentObject(UUID uuid) {
|
80
|
return CdmStore.getService(IFeatureTreeService.class).load(uuid);
|
81
|
}
|
82
|
|
83
|
/* (non-Javadoc)
|
84
|
* @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#initModel()
|
85
|
*/
|
86
|
/** {@inheritDoc} */
|
87
|
@Override
|
88
|
protected void initModel() {
|
89
|
List<FeatureTree> featureTrees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
90
|
|
91
|
if(model == null){
|
92
|
model = new ArrayList<UuidAndTitleCache<FeatureTree>>();
|
93
|
}
|
94
|
model.clear();
|
95
|
for(FeatureTree featureTree : featureTrees){
|
96
|
UuidAndTitleCache<FeatureTree> element = new UuidAndTitleCache<FeatureTree>(FeatureTree.class, featureTree.getUuid(),featureTree.getId(), featureTree.getTitleCache());
|
97
|
model.add(element);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
|
103
|
*/
|
104
|
/** {@inheritDoc} */
|
105
|
@Override
|
106
|
protected Control createExtendedContentArea(Composite parent) {
|
107
|
Link link = new Link(parent, SWT.NONE);
|
108
|
link.setText(getNewWizardLinkText());
|
109
|
link.addListener (SWT.Selection, new Listener () {
|
110
|
@Override
|
111
|
public void handleEvent(Event event) {
|
112
|
|
113
|
FeatureTreeEditorWizard wizard = new FeatureTreeEditorWizard();
|
114
|
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
115
|
int status = dialog.open();
|
116
|
|
117
|
if (status == IStatus.OK) {
|
118
|
refresh();
|
119
|
}
|
120
|
}
|
121
|
});
|
122
|
return link;
|
123
|
}
|
124
|
|
125
|
/** {@inheritDoc} */
|
126
|
@Override
|
127
|
protected String getNewWizardLinkText() {
|
128
|
return String.format("Create a new <a>%1s</a>" , "Feature tree ");
|
129
|
}
|
130
|
|
131
|
|
132
|
/** {@inheritDoc} */
|
133
|
@Override
|
134
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
135
|
return null;
|
136
|
}
|
137
|
}
|