1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.dialog.selection;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.jface.wizard.WizardDialog;
|
19
|
import org.eclipse.swt.SWT;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
import org.eclipse.swt.widgets.Control;
|
22
|
import org.eclipse.swt.widgets.Event;
|
23
|
import org.eclipse.swt.widgets.Link;
|
24
|
import org.eclipse.swt.widgets.Listener;
|
25
|
import org.eclipse.swt.widgets.Shell;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
28
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
29
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
30
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
31
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeEditorWizard;
|
32
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
* <p>FilteredFeatureTreeSelectionDialog class.</p>
|
37
|
*
|
38
|
* @author n.hoffmann
|
39
|
* @created Sep 17, 2010
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class FeatureTreeSelectionDialog extends
|
43
|
AbstractFilteredCdmResourceSelectionDialog<FeatureTree> {
|
44
|
|
45
|
/**
|
46
|
* Creates a filtered selection dialog to select a named area.
|
47
|
*
|
48
|
* @param shell
|
49
|
* The shell for displaying this widget
|
50
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
51
|
* @param featureTree a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
52
|
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
53
|
*/
|
54
|
public static FeatureTree select(Shell shell, ConversationHolder conversation, FeatureTree featureTree) {
|
55
|
FeatureTreeSelectionDialog dialog = new FeatureTreeSelectionDialog(shell, conversation,
|
56
|
"Choose a feature tree", false, featureTree);
|
57
|
return getSelectionFromDialog(dialog);
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* <p>Constructor for FilteredFeatureTreeSelectionDialog.</p>
|
62
|
*
|
63
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
64
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
65
|
* @param title a {@link java.lang.String} object.
|
66
|
* @param multi a boolean.
|
67
|
* @param cdmObject a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
68
|
*/
|
69
|
protected FeatureTreeSelectionDialog(Shell shell,
|
70
|
ConversationHolder conversation, String title, boolean multi,
|
71
|
FeatureTree cdmObject) {
|
72
|
super(shell, conversation, title, multi, FeatureTreeSelectionDialog.class.getCanonicalName(), cdmObject);
|
73
|
}
|
74
|
|
75
|
/* (non-Javadoc)
|
76
|
* @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
77
|
*/
|
78
|
/** {@inheritDoc} */
|
79
|
@Override
|
80
|
protected FeatureTree getPersistentObject(UUID uuid) {
|
81
|
return CdmStore.getService(IFeatureTreeService.class).load(uuid);
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#initModel()
|
86
|
*/
|
87
|
/** {@inheritDoc} */
|
88
|
@Override
|
89
|
protected void initModel() {
|
90
|
List<FeatureTree> featureTrees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
91
|
|
92
|
if(model == null){
|
93
|
model = new ArrayList<UuidAndTitleCache<FeatureTree>>();
|
94
|
}
|
95
|
model.clear();
|
96
|
for(FeatureTree featureTree : featureTrees){
|
97
|
UuidAndTitleCache<FeatureTree> element = new UuidAndTitleCache<FeatureTree>(FeatureTree.class, featureTree.getUuid(),featureTree.getId(), featureTree.getTitleCache());
|
98
|
model.add(element);
|
99
|
}
|
100
|
}
|
101
|
|
102
|
/* (non-Javadoc)
|
103
|
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
|
104
|
*/
|
105
|
/** {@inheritDoc} */
|
106
|
@Override
|
107
|
protected Control createExtendedContentArea(Composite parent) {
|
108
|
Link link = new Link(parent, SWT.NONE);
|
109
|
link.setText(getNewWizardLinkText());
|
110
|
link.addListener (SWT.Selection, new Listener () {
|
111
|
@Override
|
112
|
public void handleEvent(Event event) {
|
113
|
|
114
|
FeatureTreeEditorWizard wizard = new FeatureTreeEditorWizard();
|
115
|
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
116
|
int status = dialog.open();
|
117
|
|
118
|
if (status == IStatus.OK) {
|
119
|
refresh();
|
120
|
}
|
121
|
}
|
122
|
});
|
123
|
return link;
|
124
|
}
|
125
|
|
126
|
/** {@inheritDoc} */
|
127
|
@Override
|
128
|
protected String getNewWizardLinkText() {
|
129
|
return String.format("Create a new <a>%1s</a>" , "Feature tree ");
|
130
|
}
|
131
|
|
132
|
|
133
|
/** {@inheritDoc} */
|
134
|
@Override
|
135
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
136
|
return null;
|
137
|
}
|
138
|
}
|