commit abada6da61b3c2406a8260c937a2ac109d54eaac
Author: Cherian Mathew <c.mathew@bgbm.org>
Date:   Wed Sep 26 15:17:38 2012 +0000

     - Renamed EditHandler to EditPolytomousKeyNodesHandler
     - Added handler to create new Polytomous Key

diff --git a/.gitattributes b/.gitattributes
index 3143b50f7..79d0632b5 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -823,7 +823,8 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java -text
-eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditPolytomousKeyNodesHandler.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/NewPolytomousKeyHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/operation/DeleteOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/ClassificationContentProvider.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/ClassificationLabelProvider.java -text
diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml
index c5859503c..2decc0b79 100644
--- a/eu.etaxonomy.taxeditor.navigation/plugin.xml
+++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml
@@ -215,12 +215,17 @@
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.navigation.key.polytomous.polytomousKeyViewPart">
          <command
-               commandId="eu.etaxonomy.taxeditor.navigation.key.polytomous.edit"
+               commandId="eu.etaxonomy.taxeditor.navigation.key.polytomous.newKey"
+               label="New"
+               style="push">
+         </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.navigation.key.polytomous.editNodes"
                label="Edit"
                style="push">
          </command>
          <separator
-               name="eu.etaxonomy.eu.polytomousKeyView.separator"
+               name="eu.etaxonomy.eu.polytomousKeyView.separator2"
                visible="true">
          </separator>
          <command
@@ -269,9 +274,14 @@
    <extension
          point="org.eclipse.ui.commands">
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.navigation.key.polytomous.handler.EditHandler"
-            id="eu.etaxonomy.taxeditor.navigation.key.polytomous.edit"
-            name="Edit Polytomous Key">
+            defaultHandler="eu.etaxonomy.taxeditor.navigation.key.polytomous.handler.NewPolytomousKeyHandler"
+            id="eu.etaxonomy.taxeditor.navigation.key.polytomous.newKey"
+            name="New Polytomous Key">
+      </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.navigation.key.polytomous.handler.EditPolytomousKeyNodesHandler"
+            id="eu.etaxonomy.taxeditor.navigation.key.polytomous.editNodes"
+            name="Edit Polytomous Key Nodes">
       </command>
    </extension>
    <extension
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
index db7b16441..d337870ca 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
@@ -12,7 +12,9 @@ import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.swt.SWT;
@@ -23,6 +25,7 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IMemento;
@@ -80,7 +83,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 	
 	public static final String ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.polytomousKeyViewPart";
 
-	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.edit";
+	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.editNodes";
 	
 	private class ContextListener extends ContextListenerAdapter{
 		/* (non-Javadoc)
@@ -139,24 +142,12 @@ public class PolytomousKeyViewPart extends ViewPart implements
 		viewer.addDoubleClickListener(new IDoubleClickListener() {
 			
 			@Override
-			public void doubleClick(DoubleClickEvent event) {
-				
-				ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
-				
-				Command command = commandService.getCommand(OPEN_COMMAND_ID); 
-				if(command.isEnabled()) {
-					IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
-					try {
-						handlerService.executeCommand(OPEN_COMMAND_ID, null);
-					} catch (NotDefinedException e) {
-						throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID);
-					} catch (Exception e) {
-						NavigationUtil.error(getClass(), "An exception occured while trying to open a selection", e);
-					}
-				}
+			public void doubleClick(DoubleClickEvent event) {				
+			    openSelectedKeyNodes();
 			}
 		});
 		
+		
 		getSite().setSelectionProvider(viewer);
 				
 		createMenu();
@@ -166,6 +157,28 @@ public class PolytomousKeyViewPart extends ViewPart implements
 		}
 	}
 	
+	public void openSelectedKeyNodes() {
+        ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
+        
+        Command command = commandService.getCommand(OPEN_COMMAND_ID); 
+        if(command.isEnabled()) {
+            IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
+            try {                
+                handlerService.executeCommand(OPEN_COMMAND_ID, null);
+            } catch (NotDefinedException e) {
+                throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID);
+            } catch (Exception e) {
+                NavigationUtil.error(getClass(), "An exception occured while trying to open a selection", e);
+            }
+        }
+	}
+	
+	public void setViewerSelection(ISelection selection, boolean reveal) {	  
+	    getSite().setSelectionProvider(viewer);	    
+	    viewer.setSelection(selection,reveal);	    
+	    viewer.getList().notifyListeners(SWT.Selection,new Event());	    
+	}
+	
 	private void createMenu(){
 		MenuManager menuManager = new MenuManager();
 		menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java
deleted file mode 100644
index 6a514cc66..000000000
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java
+++ /dev/null
@@ -1,79 +0,0 @@
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.widgets.Display;
-
-import eu.etaxonomy.cdm.model.description.PolytomousKey;
-import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
-import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
-
-/**
- * @author n.hoffmann
- * @created Dec 3, 2010
- * @version 1.0
- */
-public class EditHandler extends AbstractHandler {
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	@Override
-	public Object execute(ExecutionEvent event) throws ExecutionException {
-		PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
-		
-		ISelection selection = view.getSite().getSelectionProvider().getSelection(); 
-		if(selection instanceof StructuredSelection){
-			final StructuredSelection structuredSelection = (StructuredSelection) selection;
-		
-			Job job = new Job("Opening Polytomous Keys"){
-
-				@Override
-				protected IStatus run(IProgressMonitor monitor) {
-					monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
-					
-					for(final Object selectedObject : structuredSelection.toArray()){
-						if(selectedObject instanceof PolytomousKey){
-							
-							Display.getDefault().asyncExec(new Runnable(){
-
-								@Override
-								public void run() {
-									NavigationUtil.openEditor((PolytomousKey) selectedObject);
-								}
-								
-							});
-							monitor.worked(1);
-						}
-					}
-					monitor.done();
-					return Status.OK_STATUS;
-				}
-				
-			};
-			
-			job.setPriority(Job.SHORT);
-			job.schedule();			
-			
-		}
-		return null;
-	}
-
-}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditPolytomousKeyNodesHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditPolytomousKeyNodesHandler.java
new file mode 100644
index 000000000..04178a92f
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditPolytomousKeyNodesHandler.java
@@ -0,0 +1,80 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
+
+/**
+ * @author n.hoffmann
+ * @created Dec 3, 2010
+ * @version 1.0
+ */
+public class EditPolytomousKeyNodesHandler extends AbstractHandler {
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+	 */
+	@Override
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
+		
+		ISelection selection = view.getSite().getSelectionProvider().getSelection(); 
+		if(selection instanceof StructuredSelection){
+		   
+			final StructuredSelection structuredSelection = (StructuredSelection) selection;
+			
+			Job job = new Job("Opening Polytomous Keys"){
+
+				@Override
+				protected IStatus run(IProgressMonitor monitor) {
+					monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
+					
+					for(final Object selectedObject : structuredSelection.toArray()){
+						if(selectedObject instanceof PolytomousKey){
+							
+							Display.getDefault().asyncExec(new Runnable(){
+
+								@Override
+								public void run() {								    
+									NavigationUtil.openEditor((PolytomousKey) selectedObject);
+								}
+								
+							});
+							monitor.worked(1);
+						}
+					}
+					monitor.done();
+					return Status.OK_STATUS;
+				}
+				
+			};
+			
+			job.setPriority(Job.SHORT);
+			job.schedule();			
+			
+		}
+		return null;
+	}
+
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/NewPolytomousKeyHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/NewPolytomousKeyHandler.java
new file mode 100644
index 000000000..8c4cb4089
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/NewPolytomousKeyHandler.java
@@ -0,0 +1,75 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
+
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.handlers.IHandlerService;
+
+import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator;
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
+import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.DeleteOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.newWizard.NewPolytomousKeyWizard;
+import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
+
+/**
+ * <p>NewTaxonNodeHandler class.</p>
+ *
+ * @author n.hoffmann
+ * @created Sep 15, 2009
+ * @version 1.0
+ */
+public class NewPolytomousKeyHandler extends AbstractHandler implements IHandler {
+
+    /* (non-Javadoc)
+     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     */
+    /** {@inheritDoc} */
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        NewPolytomousKeyWizard wizard = new NewPolytomousKeyWizard();
+        wizard.init(null,null);
+        WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
+        int status = dialog.open();    
+        if(status == Status.OK) {            
+            PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);            
+            List<PolytomousKey> pklist = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);            
+            view.refresh();            
+            view.setViewerSelection(new StructuredSelection(wizard.getEntity()),true);           
+            view.openSelectedKeyNodes();            
+        }
+        return null;
+    }
+}
