fixes #2348
authorn.hoffmann <n.hoffmann@localhost>
Wed, 27 Apr 2011 09:52:30 +0000 (09:52 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 27 Apr 2011 09:52:30 +0000 (09:52 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/EditFeatureTreeWizardPage.java

index 98386cae2d6c485f67b1b9df3f9c5ba4a99383ab..6f4b12b14b7030a7ee3ba101bd9896c66b1c0ffe 100644 (file)
@@ -46,13 +46,16 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
- * <p>EditFeatureTreeWizardPage class.</p>
- *
+ * <p>
+ * EditFeatureTreeWizardPage class.
+ * </p>
+ * 
  * @author n.hoffmann
  * @created Aug 5, 2010
  * @version 1.0
  */
-public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListener, ISelectionChangedListener{
+public class EditFeatureTreeWizardPage extends WizardPage implements
+               ModifyListener, ISelectionChangedListener {
 
        private TreeViewer viewer;
        private Label label_title;
@@ -63,9 +66,12 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
        private FeatureTree featureTree;
 
        /**
-        * <p>Constructor for EditFeatureTreeWizardPage.</p>
-        *
-        * @param pageName a {@link java.lang.String} object.
+        * <p>
+        * Constructor for EditFeatureTreeWizardPage.
+        * </p>
+        * 
+        * @param pageName
+        *            a {@link java.lang.String} object.
         */
        protected EditFeatureTreeWizardPage(String pageName) {
                super(pageName);
@@ -121,13 +127,12 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                                .setToolTipText("Remove a feature from this feature tree.");
 
                label_treeInfo = new Label(composite, SWT.NULL);
-               label_treeInfo.setText("Order and nesting of feature nodes may be changed through drag and drop.");
+               label_treeInfo
+                               .setText("Order and nesting of feature nodes may be changed through drag and drop.");
 
                viewer.setContentProvider(new FeatureTreeContentProvider());
                viewer.setLabelProvider(new FeatureTreeLabelProvider());
 
-               
-               
                int ops = DND.DROP_COPY | DND.DROP_MOVE;
                Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
                                .getInstance() };
@@ -137,22 +142,26 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                                new FeatureNodeDropAdapter(viewer));
 
                viewer.addSelectionChangedListener(this);
-               
+
                button_add.addSelectionListener(new AddButtonListener());
                button_remove.addSelectionListener(new RemoveSelectionListener());
-               
+
                setControl(composite);
        }
 
        /**
-        * <p>setSelectedTree</p>
-        *
-        * @param featureTree a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
+        * <p>
+        * setSelectedTree
+        * </p>
+        * 
+        * @param featureTree
+        *            a {@link eu.etaxonomy.cdm.model.description.FeatureTree}
+        *            object.
         */
        public void setSelectedTree(FeatureTree featureTree) {
                this.featureTree = featureTree;
                viewer.setInput(featureTree);
-               
+
                text_title.removeModifyListener(this);
                text_title.setText(featureTree.getTitleCache());
                text_title.addModifyListener(this);
@@ -163,43 +172,50 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
        public void modifyText(ModifyEvent e) {
                featureTree.setTitleCache(text_title.getText(), true);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
-               IStructuredSelection selection = (IStructuredSelection) event.getSelection(); 
-               
+               IStructuredSelection selection = (IStructuredSelection) event
+                               .getSelection();
+
                button_add.setEnabled(selection.size() <= 1);
                button_remove.setEnabled(selection.size() > 0);
        }
-       
-       private class AddButtonListener extends SelectionAdapter{
+
+       private class AddButtonListener extends SelectionAdapter {
                @Override
                public void widgetSelected(SelectionEvent e) {
-                       AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(featureTree);
+                       AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(
+                                       featureTree);
                        WizardDialog dialog = new WizardDialog(getShell(), wizard);
-                       
-                       if(dialog.open() == IStatus.OK){
-                               IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
-                               FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection.getFirstElement() : ((FeatureTree) viewer.getInput()).getRoot());
-                               Collection<Feature> additionalFeatures = wizard.getAdditionalFeatures();
-                               for(Feature feature : additionalFeatures){
+
+                       if (dialog.open() == IStatus.OK) {
+                               IStructuredSelection selection = (IStructuredSelection) viewer
+                                               .getSelection();
+                               FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection
+                                               .getFirstElement() : ((FeatureTree) viewer.getInput())
+                                               .getRoot());
+                               Collection<Feature> additionalFeatures = wizard
+                                               .getAdditionalFeatures();
+                               for (Feature feature : additionalFeatures) {
                                        FeatureNode child = FeatureNode.NewInstance(feature);
-                                       CdmStore.getService(IFeatureNodeService.class).saveOrUpdate(child);
+                                       CdmStore.getService(IFeatureNodeService.class)
+                                                       .saveOrUpdate(child);
                                        parent.addChild(child);
                                }
                                viewer.refresh();
                        }
                }
        }
-       
-       
-       private class RemoveSelectionListener extends SelectionAdapter{
+
+       private class RemoveSelectionListener extends SelectionAdapter {
                @Override
                public void widgetSelected(SelectionEvent e) {
-                       IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
-                       
-                       for(Object selectedObject : selection.toArray()){
+                       IStructuredSelection selection = (IStructuredSelection) viewer
+                                       .getSelection();
+
+                       for (Object selectedObject : selection.toArray()) {
                                FeatureNode featureNode = (FeatureNode) selectedObject;
                                FeatureNode parent = featureNode.getParent();
                                parent.removeChild(featureNode);
@@ -207,10 +223,10 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                        viewer.refresh();
                }
        }
-       
+
        private class FeatureNodeDragListener extends DragSourceAdapter {
 
-               private TreeViewer viewer;
+               private final TreeViewer viewer;
 
                public FeatureNodeDragListener(TreeViewer viewer) {
                        this.viewer = viewer;
@@ -219,6 +235,7 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                /**
                 * Method declared on DragSourceListener
                 */
+               @Override
                public void dragFinished(DragSourceEvent event) {
                        if (!event.doit)
                                return;
@@ -233,10 +250,12 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                /**
                 * Method declared on DragSourceListener
                 */
+               @Override
                public void dragSetData(DragSourceEvent event) {
                        IStructuredSelection selection = (IStructuredSelection) viewer
                                        .getSelection();
-                       FeatureNode[] featureNodes = (FeatureNode[]) selection.toList().toArray(new FeatureNode[selection.size()]);
+                       FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
+                                       .toArray(new FeatureNode[selection.size()]);
                        if (FeatureNodeTransfer.getInstance().isSupportedType(
                                        event.dataType)) {
                                event.data = featureNodes;
@@ -246,6 +265,7 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                /**
                 * Method declared on DragSourceListener
                 */
+               @Override
                public void dragStart(DragSourceEvent event) {
                        event.doit = !viewer.getSelection().isEmpty();
                }
@@ -262,42 +282,47 @@ public class EditFeatureTreeWizardPage extends WizardPage implements ModifyListe
                public boolean performDrop(Object data) {
                        FeatureNode target = (FeatureNode) getCurrentTarget();
                        int position = 0;
-                       
+
                        if (target != null) {
                                int location = getCurrentLocation();
                                FeatureNode parent = target.getParent();
-                               if (location == LOCATION_BEFORE){
-                                       position = parent.getIndex(target) - 1; 
+                               if (location == LOCATION_BEFORE) {
+                                       position = parent.getIndex(target) - 1;
                                        target = parent;
                                }
-                                               
-                               if(location == LOCATION_AFTER) {
-                                       position = parent.getIndex(target); 
+
+                               if (location == LOCATION_AFTER) {
+                                       position = parent.getIndex(target);
                                        target = parent;
                                }
                        }
-                       
+
                        // set target to root node if there is no target specified
                        if (target == null) {
                                FeatureTree featureTree = (FeatureTree) getViewer().getInput();
                                target = featureTree.getRoot();
                        }
-                       
-                       FeatureNode[] droppedNodes = (FeatureNode[]) data;
+
+                       Object[] droppedObjects = (Object[]) data;
                        TreeViewer viewer = (TreeViewer) getViewer();
 
                        // cannot drop a feature node onto itself
-                       for (FeatureNode droppedNode : droppedNodes) {
-                               if (droppedNode == null){
-                                       StoreUtil.warningDialog("Operation not supported yet", this, "We are currently unable to change the order of freshly created " +
-                                                       "feature trees nodes. Please close and reopen the dialog to change the order of features.");
+                       for (Object droppedObject : droppedObjects) {
+                               if (droppedObject == null) {
+                                       StoreUtil
+                                                       .warningDialog(
+                                                                       "Operation not supported yet",
+                                                                       this,
+                                                                       "We are currently unable to change the order of freshly created "
+                                                                                       + "feature trees nodes. Please close and reopen the dialog to change the order of features.");
                                        return false;
                                }
-                               if (droppedNode.equals(target)) {
+                               if (droppedObject.equals(target)) {
                                        return false;
                                }
                        }
-                       for (FeatureNode droppedNode : droppedNodes) {
+                       for (Object droppedObject : droppedObjects) {
+                               FeatureNode droppedNode = (FeatureNode) droppedObject;
                                target.addChild(droppedNode, position);
                                viewer.add(target, droppedNode);
                                viewer.reveal(droppedNode);