fix #6342: fix exception when using ? in selection dialog
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / newWizard / AbstractNewEntityWizard.java
index fee26b5c69658e984556ce720920011128d52691..b05d106fae4309ac238985fdb4bac74f1f692652 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -20,6 +19,7 @@ import org.eclipse.ui.IWorkbench;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -35,7 +35,7 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
                INewWizard, IConversationEnabled {
 
        private ConversationHolder conversation;
-       
+
        protected CdmFormFactory formFactory;
 
        private T entity;
@@ -43,16 +43,23 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
        private IWorkbench workbench;
 
        private IStructuredSelection selection;
-       
+
        /**
         * <p>Constructor for AbstractNewEntityWizard.</p>
         *
         * @param <T> a T object.
         */
        public AbstractNewEntityWizard(){
-               setWindowTitle("New Entity");
+               setWindowTitle(String.format("New %s", getEntityName()));
        }
-       
+
+       /**
+        * FIXME there might be a smarter way to do this,
+        *
+        * @return
+        */
+       protected abstract String getEntityName();
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
         */
@@ -60,12 +67,12 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
        @Override
        public boolean performFinish() {
                saveEntity();
-               
+
                conversation.commit();
                conversation.close();
                return true;
        }
-       
+
        /**
         * <p>Getter for the field <code>entity</code>.</p>
         *
@@ -74,7 +81,7 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
        public T getEntity() {
                return entity;
        }
-       
+
        /**
         * <p>Setter for the field <code>entity</code>.</p>
         *
@@ -83,7 +90,7 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
        public void setEntity(T entity){
                this.entity = entity;
        }
-       
+
        /**
         * Adds the entity to the current persistence context
         */
@@ -95,40 +102,42 @@ public abstract class AbstractNewEntityWizard<T> extends Wizard implements
        /** {@inheritDoc} */
        @Override
        public void init(IWorkbench workbench, IStructuredSelection selection) {
-               this.workbench = workbench != null ? workbench : StoreUtil.getWorkbench();
-               
+               this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench();
+
                if(selection == null){
-                       ISelectionService service = (ISelectionService) this.workbench.getActiveWorkbenchWindow().getSelectionService();
+                       ISelectionService service = this.workbench.getActiveWorkbenchWindow().getSelectionService();
                        if(service.getSelection() instanceof IStructuredSelection){
                                selection = (IStructuredSelection) service.getSelection();
                        }
                }
                this.selection = selection;
-               
+
                formFactory = new CdmFormFactory(Display.getCurrent(), null);
                conversation = CdmStore.createConversation();
                entity = createNewEntity();
-               
+
        }
-       
+
        /**
         * <p>createNewEntity</p>
         *
         * @return a T object.
         */
        protected abstract T createNewEntity();
-       
+
        /**
         * <p>getConversationHolder</p>
         *
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
         */
-       public ConversationHolder getConversationHolder() {
+       @Override
+    public ConversationHolder getConversationHolder() {
                return conversation;
        }
-       
+
        /** {@inheritDoc} */
-       public void update(CdmDataChangeMap changeEvents) {}
+       @Override
+    public void update(CdmDataChangeMap changeEvents) {}
 
        /**
         * @return the workbench