Updated filtered selection dialogs to 1) pass up an existing value and 2) create...
authorp.ciardelli <p.ciardelli@localhost>
Tue, 22 Sep 2009 08:31:39 +0000 (08:31 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Tue, 22 Sep 2009 08:31:39 +0000 (08:31 +0000)
.gitattributes
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/AbstractFilteredCdmResourceSelectionDialog.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredAgentSelectionDialog.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredNameSelectionDialog.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredReferenceSelectionDialog.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/NewReferenceInputDialog.java [new file with mode: 0644]

index 02cdf9f1ab47b6421bf4d187ec6755040c71a89e..29f6c74a1078f750960773d9d94f2cde8f80130d 100644 (file)
@@ -1033,6 +1033,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredNameSelecti
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredReferenceSelectionDialog.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredTaxonNodeSelectionDialog.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/NewReferenceInputDialog.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/SelectionDialogDetailsLabelProvider.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/SelectionDialogSelectionLabelProvider.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/UriDialog.java -text
index 1b7158daa85b1bd36bda74e7c858464ce22dfe38..c019988ff75b305f0dfd002b378bbe522c4c14f7 100644 (file)
@@ -12,7 +12,10 @@ package eu.etaxonomy.taxeditor.dialogs;
 
 import java.text.Collator;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.UUID;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,9 +24,12 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
 
+import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
@@ -37,18 +43,85 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends CdmBa
 
 
        protected List<UuidAndTitleCache<T>> model;
+       private Set<T> transientCdmObjects = new HashSet<T>();
        private String settings;        
        
        /**
         * @param shell
         */
-       protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, String title, boolean multi, String settings) {
+       protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, String title, boolean multi, String settings, T cdmObject) {
                super(shell, multi);
                setTitle(title);
                setMessage("Use * for wildcard, or ? to see all entries");
                this.settings = settings;
+               
+               initModel();
+               
+               if (cdmObject != null) {
+                       // If agent is not persistent, add it to the model
+                       if (isObjectTransient(cdmObject)) {
+                               addObjectToModel(cdmObject);
+                       }
+                       setInitialPattern(getTitleCache(cdmObject));
+               }
+       }
+       
+       
+       
+       /**
+        * Check if object was created during the life of this dialog. If not,
+        * retrieve it from the CdmStore.
+        * 
+        * @param cdmUuid
+        * @return
+        */
+       protected T getCdmObjectByUuid(UUID cdmUuid) {
+               for (T cdmObject : transientCdmObjects) {
+                       if (cdmObject.getUuid().equals(cdmUuid)) {
+                               return cdmObject;
+                       }
+               }
+               return getPersistentObject(cdmUuid);
        }
        
+       /**
+        * @param cdmUuid
+        * @return
+        */
+       abstract protected T getPersistentObject(UUID cdmUuid);
+
+       /**
+        * @param cdmObject
+        */
+       protected void addObjectToModel(T cdmObject) {
+               model.add(new UuidAndTitleCache(cdmObject.getClass(), cdmObject.getUuid(), getTitleCache(cdmObject)));
+               transientCdmObjects.add(cdmObject);
+       }
+
+       /**
+        * @param cdmObject
+        * @return
+        */
+       protected boolean isObjectTransient(T cdmObject) {
+               return (getPersistentObject(cdmObject.getUuid()) == null);
+       }
+
+       /**
+        * @param cdmObject
+        * @return
+        */
+       private String getTitleCache(T cdmObject) {
+               if (cdmObject instanceof IIdentifiableEntity) {
+                       return ((IIdentifiableEntity) cdmObject).getTitleCache();                       
+               }
+               return null;
+       }
+
+       /**
+        * 
+        */
+       abstract protected void initModel();
+
        /* (non-Javadoc)
         * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
         */
@@ -70,6 +143,16 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends CdmBa
                };
        }
        
+
+       /**
+        * Set the filter input to the Agent's title cache 
+        * 
+        * @param teamOrPerson
+        */
+       protected void setPattern(T cdmObject) {
+               ((Text) getPatternControl()).setText(getTitleCache(cdmObject));
+       }
+       
        /* (non-Javadoc)
        * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
        */
index ed1aec38006ca49eb4d4aec81a1d30d67cbef3f5..023b00c6ff8af00263d6365ce131db2fb5f99109 100644 (file)
@@ -26,7 +26,6 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Link;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
@@ -47,9 +46,13 @@ public class FilteredAgentSelectionDialog extends
                        .getLogger(FilteredAgentSelectionDialog.class);
        
        /**
-       * @param taxon
-       * @return
-       */
+        * Dialog can be initialized with an agent. Otherwise, leave
+        * agent == NULL.  
+        * 
+        * @param shell
+        * @param agent
+        * @return
+        */
        public static AgentBase selectAgent(Shell shell, AgentBase agent) {
                FilteredAgentSelectionDialog dialog = new FilteredAgentSelectionDialog(shell, 
                                "Choose authors or institutions", false, agent);
@@ -61,25 +64,9 @@ public class FilteredAgentSelectionDialog extends
                if(agentUuid == null){
                        return null;
                }       
-               return dialog.getAgentByUuid(agentUuid);
+               return dialog.getCdmObjectByUuid(agentUuid);
        }
        
-       /**
-        * Check if agent was created during the life of this dialog. If not,
-        * retrieve it from the CdmStore.
-        * 
-        * @param agentUuid
-        * @return
-        */
-       private AgentBase getAgentByUuid(UUID agentUuid) {
-               for (AgentBase agent : transientAgents) {
-                       if (agent.getUuid().equals(agentUuid)) {
-                               return agent;
-                       }
-               }
-               return CdmStore.getAgentService().getAgentByUuid(agentUuid);
-       }
-
        private Set<AgentBase> transientAgents = new HashSet<AgentBase>();
        
        /**
@@ -88,21 +75,11 @@ public class FilteredAgentSelectionDialog extends
         * @param agent 
        */
        protected FilteredAgentSelectionDialog(Shell shell, String title, boolean multi, AgentBase agent) {
-               super(shell, title, multi, FilteredAgentSelectionDialog.class.getCanonicalName());
+               super(shell, title, multi, FilteredAgentSelectionDialog.class.getCanonicalName(), agent);
                
                ILabelProvider labelProvider =  new FilteredCdmResourceLabelProvider();
                setListLabelProvider(labelProvider);
                setDetailsLabelProvider(new DetailsLabelProvider());
-               
-               model = CdmStore.getAgentService().getUuidAndTitleCache();
-               
-               if (agent != null) {
-                       // If agent is not persisent, add it to the model
-                       if (CdmStore.getAgentService().getAgentByUuid(agent.getUuid()) == null) {
-                               addAgentToModel(agent);
-                       }
-                       setInitialPattern(agent.getTitleCache());
-               }
        }
        
        /* (non-Javadoc)
@@ -121,7 +98,7 @@ public class FilteredAgentSelectionDialog extends
                                        teamOrPerson.setTitleCache(dialog.getValue());
                                        teamOrPerson.setNomenclaturalTitle(dialog.getValue());
                                        
-                                       addAgentToModel(teamOrPerson);
+                                       addObjectToModel(teamOrPerson);
                                        setPattern(teamOrPerson);
                                }
                        }
@@ -129,23 +106,6 @@ public class FilteredAgentSelectionDialog extends
                return link;
        }
        
-       /**
-        * Set the filter input to the Agent's title cache 
-        * 
-        * @param teamOrPerson
-        */
-       protected void setPattern(AgentBase agent) {
-               ((Text) getPatternControl()).setText(agent.getTitleCache());
-       }
-
-       /**
-        * @param agent
-        */
-       protected void addAgentToModel(AgentBase agent) {
-               model.add(new UuidAndTitleCache(agent.getClass(), agent.getUuid(), agent.getTitleCache()));
-               transientAgents.add(agent);
-       }
-
        /**
         * @author p.ciardelli
         * @created 18.09.2009
@@ -156,7 +116,7 @@ public class FilteredAgentSelectionDialog extends
                 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
                 */
                public String getText(Object element) {
-                       AgentBase agent = getAgentByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
+                       AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
                        if (agent instanceof INomenclaturalAuthor) {
                                return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'"; 
                        } else {
@@ -164,4 +124,20 @@ public class FilteredAgentSelectionDialog extends
                        }
                }
        }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
+        */
+       @Override
+       protected AgentBase getPersistentObject(UUID cdmUuid) {
+               return CdmStore.getAgentService().getAgentByUuid(cdmUuid);
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
+        */
+       @Override
+       protected void initModel() {
+               model = CdmStore.getAgentService().getUuidAndTitleCache();
+       }
 }
\ No newline at end of file
index 0a41c5fc9f8f24f2f30d07c2b4027368656fbaad..7056a03eeea6c714415f8b17c2323d39f9b6c678 100644 (file)
@@ -13,13 +13,19 @@ package eu.etaxonomy.taxeditor.dialogs;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
+import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.taxeditor.parser.CdmParserUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -35,34 +41,31 @@ public class FilteredNameSelectionDialog extends AbstractFilteredCdmResourceSele
        * @param taxon
        * @return
        */
-       public static TaxonNameBase selectName(Shell shell) {
+       public static TaxonNameBase selectName(Shell shell, TaxonNameBase name) {
                FilteredNameSelectionDialog dialog = new FilteredNameSelectionDialog(shell, 
-                               "Choose a name", false);
+                               "Choose a name", false, name);
                if (dialog.open() == Window.CANCEL) {
                        return null;
                }
                
                UUID nameUuid = dialog.getSelectedUuidAndTitleCache().getUuid();
-               
                if(nameUuid == null){
                        return null;
-               }
-               
-               return CdmStore.getNameService().getTaxonNameByUuid(nameUuid);
+               }       
+               return dialog.getCdmObjectByUuid(nameUuid);
        }
        
        /**
        * @param shell
        * @param title
+        * @param name 
        */
-       protected FilteredNameSelectionDialog(Shell shell, String title, boolean multi) {
-               super(shell, title, multi, FilteredNameSelectionDialog.class.getCanonicalName());
+       protected FilteredNameSelectionDialog(Shell shell, String title, boolean multi, TaxonNameBase name) {
+               super(shell, title, multi, FilteredNameSelectionDialog.class.getCanonicalName(), name);
                
                ILabelProvider labelProvider =  new FilteredCdmResourceLabelProvider();
                setListLabelProvider(labelProvider);
                setDetailsLabelProvider(labelProvider);
-               
-               model = CdmStore.getNameService().getUuidAndTitleCache();
        }
        
        /* (non-Javadoc)
@@ -70,6 +73,36 @@ public class FilteredNameSelectionDialog extends AbstractFilteredCdmResourceSele
        */
        @Override
        protected Control createExtendedContentArea(Composite parent) {
-               return null;
+               Link link = new Link(parent, SWT.NONE);
+               link.setText("Click <A>here</A> to create a new name.");
+               link.addListener (SWT.Selection, new Listener () {
+                       public void handleEvent(Event event) {
+                               InputDialog dialog = new InputDialog(getShell(), "Create a name", "Enter new name", "", null);
+                               if (dialog.open() == Window.OK) {
+                                       
+                                       TaxonNameBase name = CdmParserUtil.parseReferencedName(dialog.getValue());
+                                       
+                                       addObjectToModel(name);
+                                       setPattern(name);
+                               }
+                       }
+               });
+               return link;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
+        */
+       @Override
+       protected TaxonNameBase getPersistentObject(UUID cdmUuid) {
+               return CdmStore.getNameService().getTaxonNameByUuid(cdmUuid);
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
+        */
+       @Override
+       protected void initModel() {
+               model = CdmStore.getNameService().getUuidAndTitleCache();               
        }
 }
index 8e2813ad3395c16b1d90c51d22225999820786a9..0d35d2d8e6a479d9bfcf4f9216e4e85b980b965f 100644 (file)
@@ -13,10 +13,16 @@ package eu.etaxonomy.taxeditor.dialogs;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
+import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
@@ -27,45 +33,40 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 04.06.2009
  * @version 1.0
  */
-public class FilteredReferenceSelectionDialog extends
-                                                       AbstractFilteredCdmResourceSelectionDialog<ReferenceBase> {
-       
+public class FilteredReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<ReferenceBase> {
        private static final Logger logger = Logger
-       .getLogger(FilteredReferenceSelectionDialog.class);
+                       .getLogger(FilteredReferenceSelectionDialog.class);
 
-       
        /**
-       * @param taxon
+       * @param reference 
+        * @param taxon
        * @return
        */
-       public static ReferenceBase selectReference(Shell shell) {
+       public static ReferenceBase selectReference(Shell shell, ReferenceBase reference) {
                FilteredReferenceSelectionDialog dialog = new FilteredReferenceSelectionDialog(shell, 
-                               "Choose a reference", false);
+                               "Choose a reference", false, reference);
                if (dialog.open() == Window.CANCEL) {
                        return null;
                }
                
                UUID referenceUuid = dialog.getSelectedUuidAndTitleCache().getUuid();
-               
                if(referenceUuid == null){
                        return null;
-               }
-               
-               return CdmStore.getReferenceService().getReferenceByUuid(referenceUuid); 
+               }       
+               return dialog.getCdmObjectByUuid(referenceUuid); 
        }
 
        /**
        * @param shell
        * @param title
+        * @param reference 
        */
-       protected FilteredReferenceSelectionDialog(Shell shell, String title, boolean multi) {
-               super(shell, title, multi, FilteredReferenceSelectionDialog.class.getCanonicalName());
+       protected FilteredReferenceSelectionDialog(Shell shell, String title, boolean multi, ReferenceBase reference) {
+               super(shell, title, multi, FilteredReferenceSelectionDialog.class.getCanonicalName(), reference);
                
                ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
                setListLabelProvider(labelProvider);
                setDetailsLabelProvider(labelProvider);
-               
-               model = CdmStore.getReferenceService().getUuidAndTitleCache();
        }
        
        /* (non-Javadoc)
@@ -73,7 +74,40 @@ public class FilteredReferenceSelectionDialog extends
        */
        @Override
        protected Control createExtendedContentArea(Composite parent) {
-               return null;
+               Link link = new Link(parent, SWT.NONE);
+               link.setText("Click <A>here</A> to create a new reference.");
+               link.addListener (SWT.Selection, new Listener () {
+                       public void handleEvent(Event event) {
+                               
+                               NewReferenceInputDialog dialog = new NewReferenceInputDialog(getShell());
+                                                               
+                               if (dialog.open() == Window.OK) {
+                                       
+//                                     TeamOrPersonBase teamOrPerson = ("author").equals(event.text) ? Person.NewInstance() : Team.NewInstance();
+//                                     teamOrPerson.setTitleCache(dialog.getValue());
+//                                     teamOrPerson.setNomenclaturalTitle(dialog.getValue());
+//                                     
+//                                     addObjectToModel(teamOrPerson);
+//                                     setPattern(teamOrPerson);
+                               }
+                       }
+               });
+               return link;
        }
 
-}
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
+        */
+       @Override
+       protected ReferenceBase getPersistentObject(UUID cdmUuid) {
+               return CdmStore.getReferenceService().getReferenceByUuid(cdmUuid);
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
+        */
+       @Override
+       protected void initModel() {
+               model = CdmStore.getReferenceService().getUuidAndTitleCache();
+       }
+}
\ No newline at end of file
diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/NewReferenceInputDialog.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/NewReferenceInputDialog.java
new file mode 100644 (file)
index 0000000..c2be317
--- /dev/null
@@ -0,0 +1,324 @@
+/*******************************************************************************\r
+ * Copyright (c) 2000, 2008 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package eu.etaxonomy.taxeditor.dialogs;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.dialogs.Dialog;\r
+import org.eclipse.jface.dialogs.IDialogConstants;\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+import org.eclipse.jface.resource.StringConverter;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.swt.widgets.Text;\r
+\r
+import eu.etaxonomy.cdm.model.reference.Article;\r
+import eu.etaxonomy.cdm.model.reference.BookSection;\r
+import eu.etaxonomy.cdm.model.reference.Generic;\r
+\r
+/**\r
+ * A simple input dialog for soliciting an input string from the user.\r
+ * <p>\r
+ * This concrete dialog class can be instantiated as is, or further subclassed as\r
+ * required.\r
+ * </p>\r
+ */\r
+public class NewReferenceInputDialog extends Dialog {\r
+    /**\r
+     * The title of the dialog.\r
+     */\r
+    private String title;\r
+\r
+    /**\r
+     * The message to display, or <code>null</code> if none.\r
+     */\r
+    private String message;\r
+\r
+    /**\r
+     * The input value; the empty string by default.\r
+     */\r
+    private String value = "";//$NON-NLS-1$\r
+\r
+    /**\r
+     * The input validator, or <code>null</code> if none.\r
+     */\r
+    private IInputValidator validator;\r
+\r
+    /**\r
+     * Ok button widget.\r
+     */\r
+    private Button okButton;\r
+\r
+    /**\r
+     * Input text widget.\r
+     */\r
+    private Text text;\r
+\r
+    /**\r
+     * Error message label widget.\r
+     */\r
+    private Text errorMessageText;\r
+    \r
+    /**\r
+     * Error message string.\r
+     */\r
+    private String errorMessage;\r
+\r
+       private String message2;\r
+\r
+    /**\r
+     * Creates an input dialog with OK and Cancel buttons. Note that the dialog\r
+     * will have no visual representation (no widgets) until it is told to open.\r
+     * <p>\r
+     * Note that the <code>open</code> method blocks for input dialogs.\r
+     * </p>\r
+     * \r
+     * @param parentShell\r
+     *            the parent shell, or <code>null</code> to create a top-level\r
+     *            shell\r
+     * @param dialogTitle\r
+     *            the dialog title, or <code>null</code> if none\r
+     * @param dialogMessage\r
+     *            the dialog message, or <code>null</code> if none\r
+     * @param initialValue\r
+     *            the initial input value, or <code>null</code> if none\r
+     *            (equivalent to the empty string)\r
+     * @param validator\r
+     *            an input validator, or <code>null</code> if none\r
+     */\r
+    public NewReferenceInputDialog(Shell parentShell) {\r
+        super(parentShell);\r
+        this.title = "Create reference";\r
+        this.message = "Choose a reference type:";\r
+        this.message2 = "Enter a title cache:";\r
+        \r
+        types.put("Generic", Generic.class);\r
+        types.put("Book Section", BookSection.class);\r
+        types.put("Article", Article.class);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc) Method declared on Dialog.\r
+     */\r
+    protected void buttonPressed(int buttonId) {\r
+        if (buttonId == IDialogConstants.OK_ID) {\r
+            value = text.getText();\r
+        } else {\r
+            value = null;\r
+        }\r
+        super.buttonPressed(buttonId);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)\r
+     */\r
+    protected void configureShell(Shell shell) {\r
+        super.configureShell(shell);\r
+        if (title != null) {\r
+                       shell.setText(title);\r
+               }\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)\r
+     */\r
+    protected void createButtonsForButtonBar(Composite parent) {\r
+        // create OK and Cancel buttons by default\r
+        okButton = createButton(parent, IDialogConstants.OK_ID,\r
+                IDialogConstants.OK_LABEL, true);\r
+        createButton(parent, IDialogConstants.CANCEL_ID,\r
+                IDialogConstants.CANCEL_LABEL, false);\r
+        //do this here because setting the text will set enablement on the ok\r
+        // button\r
+        text.setFocus();\r
+        if (value != null) {\r
+            text.setText(value);\r
+            text.selectAll();\r
+        }\r
+    }\r
+\r
+    Map<String, Class> types = new HashMap<String, Class>();\r
+    \r
+    /*\r
+     * (non-Javadoc) Method declared on Dialog.\r
+     */\r
+    protected Control createDialogArea(Composite parent) {\r
+        // create composite\r
+        Composite composite = (Composite) super.createDialogArea(parent);\r
+        // create message\r
+        Label label = new Label(composite, SWT.WRAP);\r
+        label.setText(message);\r
+        GridData data = new GridData(GridData.GRAB_HORIZONTAL\r
+                | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
+                | GridData.VERTICAL_ALIGN_CENTER);\r
+        data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
+        label.setLayoutData(data);\r
+        label.setFont(parent.getFont());\r
+        // create combo\r
+        Combo combo = new Combo(composite, SWT.NONE);\r
+        combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL\r
+                | GridData.HORIZONTAL_ALIGN_FILL));\r
+        combo.addModifyListener(new ModifyListener() {\r
+            public void modifyText(ModifyEvent e) {\r
+                validateInput();\r
+            }\r
+        });\r
+        // create message\r
+        Label label2 = new Label(composite, SWT.WRAP);\r
+        label2.setText(message2);\r
+        GridData data2 = new GridData(GridData.GRAB_HORIZONTAL\r
+                | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
+                | GridData.VERTICAL_ALIGN_CENTER);\r
+        data2.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
+        label2.setLayoutData(data);\r
+        label2.setFont(parent.getFont());\r
+        // create text\r
+        text = new Text(composite, getInputTextStyle());\r
+        text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL\r
+                | GridData.HORIZONTAL_ALIGN_FILL));\r
+        text.addModifyListener(new ModifyListener() {\r
+            public void modifyText(ModifyEvent e) {\r
+                validateInput();\r
+            }\r
+        });\r
+        errorMessageText = new Text(composite, SWT.READ_ONLY | SWT.WRAP);\r
+        errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL\r
+                | GridData.HORIZONTAL_ALIGN_FILL));\r
+        errorMessageText.setBackground(errorMessageText.getDisplay()\r
+                .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));\r
+        // Set the error message text\r
+        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=66292\r
+        setErrorMessage(errorMessage);\r
+\r
+        applyDialogFont(composite);\r
+        return composite;\r
+    }\r
+\r
+    /**\r
+     * Returns the error message label.\r
+     * \r
+     * @return the error message label\r
+     * @deprecated use setErrorMessage(String) instead\r
+     */\r
+    protected Label getErrorMessageLabel() {\r
+        return null;\r
+    }\r
+\r
+    /**\r
+     * Returns the ok button.\r
+     * \r
+     * @return the ok button\r
+     */\r
+    protected Button getOkButton() {\r
+        return okButton;\r
+    }\r
+\r
+    /**\r
+     * Returns the text area.\r
+     * \r
+     * @return the text area\r
+     */\r
+    protected Text getText() {\r
+        return text;\r
+    }\r
+\r
+    /**\r
+     * Returns the validator.\r
+     * \r
+     * @return the validator\r
+     */\r
+    protected IInputValidator getValidator() {\r
+        return validator;\r
+    }\r
+\r
+    /**\r
+     * Returns the string typed into this input dialog.\r
+     * \r
+     * @return the input string\r
+     */\r
+    public String getValue() {\r
+        return value;\r
+    }\r
+\r
+    /**\r
+     * Validates the input.\r
+     * <p>\r
+     * The default implementation of this framework method delegates the request\r
+     * to the supplied input validator object; if it finds the input invalid,\r
+     * the error message is displayed in the dialog's message line. This hook\r
+     * method is called whenever the text changes in the input field.\r
+     * </p>\r
+     */\r
+    protected void validateInput() {\r
+        String errorMessage = null;\r
+        if (validator != null) {\r
+            errorMessage = validator.isValid(text.getText());\r
+        }\r
+        // Bug 16256: important not to treat "" (blank error) the same as null\r
+        // (no error)\r
+        setErrorMessage(errorMessage);\r
+    }\r
+\r
+    /**\r
+     * Sets or clears the error message.\r
+     * If not <code>null</code>, the OK button is disabled.\r
+     * \r
+     * @param errorMessage\r
+     *            the error message, or <code>null</code> to clear\r
+     * @since 3.0\r
+     */\r
+    public void setErrorMessage(String errorMessage) {\r
+       this.errorMessage = errorMessage;\r
+       if (errorMessageText != null && !errorMessageText.isDisposed()) {\r
+               errorMessageText.setText(errorMessage == null ? " \n " : errorMessage); //$NON-NLS-1$\r
+               // Disable the error message text control if there is no error, or\r
+               // no error text (empty or whitespace only).  Hide it also to avoid\r
+               // color change.\r
+               // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281\r
+               boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;\r
+               errorMessageText.setEnabled(hasError);\r
+               errorMessageText.setVisible(hasError);\r
+               errorMessageText.getParent().update();\r
+               // Access the ok button by id, in case clients have overridden button creation.\r
+               // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643\r
+               Control button = getButton(IDialogConstants.OK_ID);\r
+               if (button != null) {\r
+                       button.setEnabled(errorMessage == null);\r
+               }\r
+       }\r
+    }\r
+    \r
+       /**\r
+        * Returns the style bits that should be used for the input text field.\r
+        * Defaults to a single line entry. Subclasses may override.\r
+        * \r
+        * @return the integer style bits that should be used when creating the\r
+        *         input text\r
+        * \r
+        * @since 3.4\r
+        */\r
+       protected int getInputTextStyle() {\r
+               return SWT.SINGLE | SWT.BORDER;\r
+       }\r
+}\r