Revision 707b6237
Added by Niels Hoffmann over 12 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/EditFeatureTreeWizardPage.java | ||
---|---|---|
46 | 46 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
47 | 47 |
|
48 | 48 |
/** |
49 |
* <p>EditFeatureTreeWizardPage class.</p> |
|
50 |
* |
|
49 |
* <p> |
|
50 |
* EditFeatureTreeWizardPage class. |
|
51 |
* </p> |
|
52 |
* |
|
51 | 53 |
* @author n.hoffmann |
52 | 54 |
* @created Aug 5, 2010 |
53 | 55 |
* @version 1.0 |
54 | 56 |
*/ |
55 |
public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListener, ISelectionChangedListener{ |
|
57 |
public class EditFeatureTreeWizardPage extends WizardPage implements |
|
58 |
ModifyListener, ISelectionChangedListener { |
|
56 | 59 |
|
57 | 60 |
private TreeViewer viewer; |
58 | 61 |
private Label label_title; |
... | ... | |
63 | 66 |
private FeatureTree featureTree; |
64 | 67 |
|
65 | 68 |
/** |
66 |
* <p>Constructor for EditFeatureTreeWizardPage.</p> |
|
67 |
* |
|
68 |
* @param pageName a {@link java.lang.String} object. |
|
69 |
* <p> |
|
70 |
* Constructor for EditFeatureTreeWizardPage. |
|
71 |
* </p> |
|
72 |
* |
|
73 |
* @param pageName |
|
74 |
* a {@link java.lang.String} object. |
|
69 | 75 |
*/ |
70 | 76 |
protected EditFeatureTreeWizardPage(String pageName) { |
71 | 77 |
super(pageName); |
... | ... | |
121 | 127 |
.setToolTipText("Remove a feature from this feature tree."); |
122 | 128 |
|
123 | 129 |
label_treeInfo = new Label(composite, SWT.NULL); |
124 |
label_treeInfo.setText("Order and nesting of feature nodes may be changed through drag and drop."); |
|
130 |
label_treeInfo |
|
131 |
.setText("Order and nesting of feature nodes may be changed through drag and drop."); |
|
125 | 132 |
|
126 | 133 |
viewer.setContentProvider(new FeatureTreeContentProvider()); |
127 | 134 |
viewer.setLabelProvider(new FeatureTreeLabelProvider()); |
128 | 135 |
|
129 |
|
|
130 |
|
|
131 | 136 |
int ops = DND.DROP_COPY | DND.DROP_MOVE; |
132 | 137 |
Transfer[] transfers = new Transfer[] { FeatureNodeTransfer |
133 | 138 |
.getInstance() }; |
... | ... | |
137 | 142 |
new FeatureNodeDropAdapter(viewer)); |
138 | 143 |
|
139 | 144 |
viewer.addSelectionChangedListener(this); |
140 |
|
|
145 |
|
|
141 | 146 |
button_add.addSelectionListener(new AddButtonListener()); |
142 | 147 |
button_remove.addSelectionListener(new RemoveSelectionListener()); |
143 |
|
|
148 |
|
|
144 | 149 |
setControl(composite); |
145 | 150 |
} |
146 | 151 |
|
147 | 152 |
/** |
148 |
* <p>setSelectedTree</p> |
|
149 |
* |
|
150 |
* @param featureTree a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object. |
|
153 |
* <p> |
|
154 |
* setSelectedTree |
|
155 |
* </p> |
|
156 |
* |
|
157 |
* @param featureTree |
|
158 |
* a {@link eu.etaxonomy.cdm.model.description.FeatureTree} |
|
159 |
* object. |
|
151 | 160 |
*/ |
152 | 161 |
public void setSelectedTree(FeatureTree featureTree) { |
153 | 162 |
this.featureTree = featureTree; |
154 | 163 |
viewer.setInput(featureTree); |
155 |
|
|
164 |
|
|
156 | 165 |
text_title.removeModifyListener(this); |
157 | 166 |
text_title.setText(featureTree.getTitleCache()); |
158 | 167 |
text_title.addModifyListener(this); |
... | ... | |
163 | 172 |
public void modifyText(ModifyEvent e) { |
164 | 173 |
featureTree.setTitleCache(text_title.getText(), true); |
165 | 174 |
} |
166 |
|
|
175 |
|
|
167 | 176 |
/** {@inheritDoc} */ |
168 | 177 |
@Override |
169 | 178 |
public void selectionChanged(SelectionChangedEvent event) { |
170 |
IStructuredSelection selection = (IStructuredSelection) event.getSelection(); |
|
171 |
|
|
179 |
IStructuredSelection selection = (IStructuredSelection) event |
|
180 |
.getSelection(); |
|
181 |
|
|
172 | 182 |
button_add.setEnabled(selection.size() <= 1); |
173 | 183 |
button_remove.setEnabled(selection.size() > 0); |
174 | 184 |
} |
175 |
|
|
176 |
private class AddButtonListener extends SelectionAdapter{ |
|
185 |
|
|
186 |
private class AddButtonListener extends SelectionAdapter {
|
|
177 | 187 |
@Override |
178 | 188 |
public void widgetSelected(SelectionEvent e) { |
179 |
AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(featureTree); |
|
189 |
AvailableFeaturesWizard wizard = new AvailableFeaturesWizard( |
|
190 |
featureTree); |
|
180 | 191 |
WizardDialog dialog = new WizardDialog(getShell(), wizard); |
181 |
|
|
182 |
if(dialog.open() == IStatus.OK){ |
|
183 |
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
|
184 |
FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection.getFirstElement() : ((FeatureTree) viewer.getInput()).getRoot()); |
|
185 |
Collection<Feature> additionalFeatures = wizard.getAdditionalFeatures(); |
|
186 |
for(Feature feature : additionalFeatures){ |
|
192 |
|
|
193 |
if (dialog.open() == IStatus.OK) { |
|
194 |
IStructuredSelection selection = (IStructuredSelection) viewer |
|
195 |
.getSelection(); |
|
196 |
FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection |
|
197 |
.getFirstElement() : ((FeatureTree) viewer.getInput()) |
|
198 |
.getRoot()); |
|
199 |
Collection<Feature> additionalFeatures = wizard |
|
200 |
.getAdditionalFeatures(); |
|
201 |
for (Feature feature : additionalFeatures) { |
|
187 | 202 |
FeatureNode child = FeatureNode.NewInstance(feature); |
188 |
CdmStore.getService(IFeatureNodeService.class).saveOrUpdate(child); |
|
203 |
CdmStore.getService(IFeatureNodeService.class) |
|
204 |
.saveOrUpdate(child); |
|
189 | 205 |
parent.addChild(child); |
190 | 206 |
} |
191 | 207 |
viewer.refresh(); |
192 | 208 |
} |
193 | 209 |
} |
194 | 210 |
} |
195 |
|
|
196 |
|
|
197 |
private class RemoveSelectionListener extends SelectionAdapter{ |
|
211 |
|
|
212 |
private class RemoveSelectionListener extends SelectionAdapter { |
|
198 | 213 |
@Override |
199 | 214 |
public void widgetSelected(SelectionEvent e) { |
200 |
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
|
201 |
|
|
202 |
for(Object selectedObject : selection.toArray()){ |
|
215 |
IStructuredSelection selection = (IStructuredSelection) viewer |
|
216 |
.getSelection(); |
|
217 |
|
|
218 |
for (Object selectedObject : selection.toArray()) { |
|
203 | 219 |
FeatureNode featureNode = (FeatureNode) selectedObject; |
204 | 220 |
FeatureNode parent = featureNode.getParent(); |
205 | 221 |
parent.removeChild(featureNode); |
... | ... | |
207 | 223 |
viewer.refresh(); |
208 | 224 |
} |
209 | 225 |
} |
210 |
|
|
226 |
|
|
211 | 227 |
private class FeatureNodeDragListener extends DragSourceAdapter { |
212 | 228 |
|
213 |
private TreeViewer viewer; |
|
229 |
private final TreeViewer viewer;
|
|
214 | 230 |
|
215 | 231 |
public FeatureNodeDragListener(TreeViewer viewer) { |
216 | 232 |
this.viewer = viewer; |
... | ... | |
219 | 235 |
/** |
220 | 236 |
* Method declared on DragSourceListener |
221 | 237 |
*/ |
238 |
@Override |
|
222 | 239 |
public void dragFinished(DragSourceEvent event) { |
223 | 240 |
if (!event.doit) |
224 | 241 |
return; |
... | ... | |
233 | 250 |
/** |
234 | 251 |
* Method declared on DragSourceListener |
235 | 252 |
*/ |
253 |
@Override |
|
236 | 254 |
public void dragSetData(DragSourceEvent event) { |
237 | 255 |
IStructuredSelection selection = (IStructuredSelection) viewer |
238 | 256 |
.getSelection(); |
239 |
FeatureNode[] featureNodes = (FeatureNode[]) selection.toList().toArray(new FeatureNode[selection.size()]); |
|
257 |
FeatureNode[] featureNodes = (FeatureNode[]) selection.toList() |
|
258 |
.toArray(new FeatureNode[selection.size()]); |
|
240 | 259 |
if (FeatureNodeTransfer.getInstance().isSupportedType( |
241 | 260 |
event.dataType)) { |
242 | 261 |
event.data = featureNodes; |
... | ... | |
246 | 265 |
/** |
247 | 266 |
* Method declared on DragSourceListener |
248 | 267 |
*/ |
268 |
@Override |
|
249 | 269 |
public void dragStart(DragSourceEvent event) { |
250 | 270 |
event.doit = !viewer.getSelection().isEmpty(); |
251 | 271 |
} |
... | ... | |
262 | 282 |
public boolean performDrop(Object data) { |
263 | 283 |
FeatureNode target = (FeatureNode) getCurrentTarget(); |
264 | 284 |
int position = 0; |
265 |
|
|
285 |
|
|
266 | 286 |
if (target != null) { |
267 | 287 |
int location = getCurrentLocation(); |
268 | 288 |
FeatureNode parent = target.getParent(); |
269 |
if (location == LOCATION_BEFORE){ |
|
270 |
position = parent.getIndex(target) - 1;
|
|
289 |
if (location == LOCATION_BEFORE) {
|
|
290 |
position = parent.getIndex(target) - 1; |
|
271 | 291 |
target = parent; |
272 | 292 |
} |
273 |
|
|
274 |
if(location == LOCATION_AFTER) { |
|
275 |
position = parent.getIndex(target);
|
|
293 |
|
|
294 |
if (location == LOCATION_AFTER) {
|
|
295 |
position = parent.getIndex(target); |
|
276 | 296 |
target = parent; |
277 | 297 |
} |
278 | 298 |
} |
279 |
|
|
299 |
|
|
280 | 300 |
// set target to root node if there is no target specified |
281 | 301 |
if (target == null) { |
282 | 302 |
FeatureTree featureTree = (FeatureTree) getViewer().getInput(); |
283 | 303 |
target = featureTree.getRoot(); |
284 | 304 |
} |
285 |
|
|
286 |
FeatureNode[] droppedNodes = (FeatureNode[]) data;
|
|
305 |
|
|
306 |
Object[] droppedObjects = (Object[]) data;
|
|
287 | 307 |
TreeViewer viewer = (TreeViewer) getViewer(); |
288 | 308 |
|
289 | 309 |
// cannot drop a feature node onto itself |
290 |
for (FeatureNode droppedNode : droppedNodes) { |
|
291 |
if (droppedNode == null){ |
|
292 |
StoreUtil.warningDialog("Operation not supported yet", this, "We are currently unable to change the order of freshly created " + |
|
293 |
"feature trees nodes. Please close and reopen the dialog to change the order of features."); |
|
310 |
for (Object droppedObject : droppedObjects) { |
|
311 |
if (droppedObject == null) { |
|
312 |
StoreUtil |
|
313 |
.warningDialog( |
|
314 |
"Operation not supported yet", |
|
315 |
this, |
|
316 |
"We are currently unable to change the order of freshly created " |
|
317 |
+ "feature trees nodes. Please close and reopen the dialog to change the order of features."); |
|
294 | 318 |
return false; |
295 | 319 |
} |
296 |
if (droppedNode.equals(target)) {
|
|
320 |
if (droppedObject.equals(target)) {
|
|
297 | 321 |
return false; |
298 | 322 |
} |
299 | 323 |
} |
300 |
for (FeatureNode droppedNode : droppedNodes) { |
|
324 |
for (Object droppedObject : droppedObjects) { |
|
325 |
FeatureNode droppedNode = (FeatureNode) droppedObject; |
|
301 | 326 |
target.addChild(droppedNode, position); |
302 | 327 |
viewer.add(target, droppedNode); |
303 | 328 |
viewer.reveal(droppedNode); |
Also available in: Unified diff
Merged with trunk