Temporary fix for #2366; fixes #2368; Refactoring annotations in the name editor
authorn.hoffmann <n.hoffmann@localhost>
Tue, 10 May 2011 15:50:12 +0000 (15:50 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 10 May 2011 15:50:12 +0000 (15:50 +0000)
16 files changed:
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorSearch.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/AbstractGroupedContainer.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/ConceptContainer.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/EditorAnnotation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/MisapplicationContainer.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/EditHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchBar.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewClassificationWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationEventDetailElement.java

index b60c284719c564378ea9f842c519039a0f1ef590..eb17b543514a658b5722337ce78b2e8c88d9a551 100644 (file)
@@ -24,15 +24,13 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.ToolItem;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.swt.IFocusService;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
 import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.store.SearchManager;
 
 /**
  * <p>BulkEditorSearchComposite class.</p>
@@ -49,13 +47,10 @@ public class BulkEditorSearch {
         * 
         */
        private static final String SEARCH = "Search";
-
-       private static final String WILDCARD = "*";
        
-       private static final String DEFAULT_TEXT = String.format("Use \'%s\' for wildcard searching", WILDCARD);
+       private static final String DEFAULT_TEXT = String.format("Use \'%s\' for wildcard searching", SearchManager.WILDCARD);
        
        private final BulkEditor editor;
-       private Menu sortMenu;
        
        private Text text;
        private BulkEditorSortCombo sortCombo;
@@ -64,7 +59,6 @@ public class BulkEditorSearch {
        
        
        public Object ORDER_BY = new Object();
-       private ToolItem toolItem;
        
        /**
         * <p>Constructor for BulkEditorSearchComposite.</p>
@@ -184,22 +178,12 @@ public class BulkEditorSearch {
                
                String searchString = getSearchString().trim();
                                
-               if(WILDCARD.equals(searchString.trim())){
-                       BulkEditorUtil.warningDialog("Could not execute search", this, String.format("Please type at least one character when using the \"%s\" wildcard.", WILDCARD));
-                       return;
-               }
-               
-               
                if(DEFAULT_TEXT.equals(searchString) || CdmUtils.isEmpty(searchString)){
                        return;
-               }
+               }                       
                
-               // update query in IEditorInput
-               AbstractBulkEditorInput input = editor.getEditorInput();
-               if (input instanceof AbstractBulkEditorInput) {
-                       BulkEditorQuery query = new BulkEditorQuery(getSearchString(), getComparator());
-                       editor.performSearch(query);
-               }
+               BulkEditorQuery query = new BulkEditorQuery(getSearchString(), getComparator());
+               editor.performSearch(query);
        }
        
        /*
index 00de6d37a773594277672cacf115a446c5604b8a..773c3fc007850fbea51848af2691317305b9caac 100644 (file)
@@ -93,7 +93,7 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
         * @return a {@link java.util.List} object.
         */
        protected abstract List<T> listEntities(IIdentifiableEntityServiceConfigurator configurator);
-       
+               
        /**
         * <p>loadEntity</p>
         *
index e8820f7d292fcffdd1519c86d4dcf0e487f4ef68..17c8db0b7985048993e5aeece29091558330038e 100644 (file)
@@ -102,7 +102,7 @@ public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
        public List<AgentBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
                return CdmStore.getSearchManager().findTeamOrPersons(configurator);
        }
-
+       
        /** {@inheritDoc} */
        @Override
        public AgentBase loadEntity(UUID uuid) {
@@ -139,4 +139,5 @@ public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
        protected IEntityCreator<AgentBase> createEntityCreator() {
                return new AgentCreator();
        }
+
 }
index 09c7c7830c346bee0991c006ca8775bdb811b9ce..5dcc628b3f77fd5bbe4bee1447509486d74b72f1 100644 (file)
@@ -109,4 +109,6 @@ public class GroupEditorInput extends AbstractBulkEditorInput<Group> {
                return entity.getName();
        }
 
+       
+
 }
index 2a806545373844e16aa66f71176ef5a4b88ce569..144b469f0b65376dc2870624412e3778eaf1042e 100644 (file)
@@ -155,7 +155,8 @@ public class NameEditorInput extends AbstractBulkEditorInput<TaxonNameBase> {
         */
        @Override
        public String getText(TaxonNameBase entity) {
-               return ((TaxonNameBase) entity).getFullTitleCache();
+               return (entity).getFullTitleCache();
        }
 
+
 }
index 88a396b886a85cd87f7627ad7269601bf84a149f..bc1fd74e18d138d835bd3a3cfcdac16d3fb5a720 100644 (file)
@@ -84,6 +84,7 @@ public class UserEditorInput extends AbstractBulkEditorInput<User> {
                return CdmStore.getSearchManager().findUsers(configurator);
        }
 
+       
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#loadEntity(java.util.UUID)
         */
@@ -109,4 +110,5 @@ public class UserEditorInput extends AbstractBulkEditorInput<User> {
                return String.format("%s, %s", entity.getUsername(), entity.getPerson());
        }
 
+
 }
index d09a935a05e33b3328eb20d49a623742c055a024..23c64f27ca3e9fea18dc53e337d9a43909e8ae09 100644 (file)
@@ -9,11 +9,13 @@
 
 package eu.etaxonomy.taxeditor.editor.name.container;
 
+import java.util.List;
 import java.util.Set;
 
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
 import org.eclipse.jface.window.DefaultToolTip;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.dnd.DND;
@@ -48,9 +50,11 @@ import eu.etaxonomy.cdm.model.name.NameRelationship;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
+import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation.EditorAnnotationType;
 import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragListener;
 import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragSourceEffect;
 import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
@@ -165,7 +169,7 @@ abstract public class AbstractGroupedContainer<T extends TaxonBase> implements I
                                getTaxonBase().setTitleCache((getTaxonBase().generateTitle()));
                                
                                // show errors resulting from parsing
-                               calculateErrors();
+                               calculateAnnotations();
                                // store the position of the cursor                             
                                storeCursor();
                                // notify selection listener
@@ -265,15 +269,70 @@ abstract public class AbstractGroupedContainer<T extends TaxonBase> implements I
                        getNameViewer().setText(text);
                        placeCursor();
                }
-               calculateErrors();
+               calculateAnnotations();
        }
        
        /**
         * <p>calculateErrors</p>
         */
-       synchronized protected void calculateErrors() {
-               getNameViewer().clearErrors();
-               getNameViewer().setShowParsingErrors(getName());
+       synchronized protected void calculateAnnotations() {
+               getNameViewer().clearAnnotations();
+               showAnnotations();
+       }
+
+       /**
+        * 
+        */
+       public void showAnnotations() {
+               
+               if(getName().hasProblem()){
+                       showParsingProblems();
+               }
+               
+               if(!isNameParsable()){
+                       getNameViewer().addAnnotation(
+                                       new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This name may only be edited in the details view."));
+               }
+               
+               if(isNameUsedMultipleTimes()){
+                       getNameViewer().addAnnotation(new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This taxons name is used multiple times."));
+               }
+               
+               
+       }
+
+       /**
+        * 
+        */
+       private void showParsingProblems() {
+               String text = getNameViewer().getTextWidget().getText();
+               
+               List<ParserProblem> parsingProblems = getName().getParsingProblems();
+               
+               for (ParserProblem problem : parsingProblems) {
+                       getNameViewer().addAnnotation(new EditorAnnotation(problem), getParsingProblemPosition());
+               }       
+       }
+       
+       private Position getParsingProblemPosition(){
+               String text = getNameViewer().getTextWidget().getText();
+               
+               if (getName().hasProblem() && text.length() > 0) {
+                       int start = getName().getProblemStarts();
+                       int length = getName().getProblemEnds() - start;
+                       
+                       if (start == -1 || getName().getProblemEnds() == -1) {
+                               return null;
+                       }
+                       
+                       // Don't let squigglies try to draw beyond the end of the text
+                       if (text.length() < start + length) {
+                               length = text.length() - start;
+                       }
+                       
+                       return new Position(start, length);
+               }
+               return null;
        }
 
        /**
@@ -365,31 +424,30 @@ abstract public class AbstractGroupedContainer<T extends TaxonBase> implements I
                NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(getName());
                boolean enableFreetext = true;
 
-               enableFreetext &= isNameUsedMultipleTimes(name);
-               enableFreetext &= isNameParsable(name);
-               
-               if(!enableFreetext){
-                       getNameViewer().setShowNameNotParsableWarning(name);
-               }
+               enableFreetext |= isNameUsedMultipleTimes();
+               enableFreetext &= isNameParsable();
                
                return enableFreetext;
        }
        
-       private boolean isNameUsedMultipleTimes(NonViralName name){
-               if(name.getTaxonBases().size() != 1){
-                       getNameViewer().setShowMultipleNameUsageWarning(name);
-                       return false;
+       private boolean isNameUsedMultipleTimes(){
+               if(getName().getTaxonBases().size() > 1){
+                       return true;
                }
-               return true;
+               return false;
        }
        
-       private boolean isNameParsable(NonViralName name){
+       private boolean isNameParsable(){
+               TaxonNameBase name = getName();
+               
                boolean isParsable = true; 
                isParsable &= CdmUtils.isEmpty(name.getAppendedPhrase()); //taxonFieldsEmpty();
                
-               isParsable &= ! name.isProtectedAuthorshipCache();
-               isParsable &= ! name.isProtectedNameCache();
-               
+               if(name instanceof NonViralName){
+                       NonViralName nonViralName = (NonViralName) name;
+                       isParsable &= ! nonViralName.isProtectedAuthorshipCache();
+                       isParsable &= ! nonViralName.isProtectedNameCache();
+               }
                
                return isParsable;
        }
@@ -397,12 +455,12 @@ abstract public class AbstractGroupedContainer<T extends TaxonBase> implements I
        /**
         * Parse the text and calculate errors
         */
-       public void parseAndCalculateErrors(){
+       public void parseAndCalculateAnnotations(){
                removeListener();
                String unparsedNameString = getNameViewer().getTextWidget().getText();
                parseHandler.parse(unparsedNameString);
                addListener();
-               calculateErrors();
+               calculateAnnotations();
        }
 
        /**
@@ -894,7 +952,7 @@ abstract public class AbstractGroupedContainer<T extends TaxonBase> implements I
                nonEditableInfoHover.setText(nonEditableHoverText);
                nonEditableInfoLabel.setText(nonEditableText);
                
-               calculateErrors();
+               calculateAnnotations();
        }
        
        /**
index d89622b99e12cdf2a49d34022be95809d16befd0..1e10a43085246be84f43fe3b8a93b890868b2777 100644 (file)
@@ -27,7 +27,7 @@ import eu.etaxonomy.taxeditor.preference.Resources;
  */
 public class ConceptContainer extends AbstractGroupedContainer<Taxon> {
        
-       private TaxonRelationshipType relationshipType;
+       private final TaxonRelationshipType relationshipType;
        
                
        private ConceptContainer(TaxonNameEditor editor, AbstractGroup group,
@@ -117,13 +117,16 @@ public class ConceptContainer extends AbstractGroupedContainer<Taxon> {
                return getTaxonBase();
        }
        
-       /**
-        * <p>calculateErrors</p>
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
         */
-       protected void calculateErrors() {
-               super.calculateErrors();
-               
-               nameViewer.setShowSecError(getTaxonBase());
+       @Override
+       public void showAnnotations() {
+               if(getData().getSec() == null){
+                       getNameViewer().addAnnotation(
+                                       new EditorAnnotation(0, "This taxon requires a sec. reference."));
+               }
+               super.showAnnotations();
        }
        
        /** {@inheritDoc} */
index 64c53afc223972b4a84e867019566ae1bc0bd409..362fa0b31315bf9eda9a3c52bf0e8b9e8bd521eb 100644 (file)
@@ -12,6 +12,7 @@ import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Canvas;
 
+import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.model.ImageResources;
 
 /**
@@ -23,25 +24,59 @@ import eu.etaxonomy.taxeditor.model.ImageResources;
 public class EditorAnnotation extends Annotation implements IAnnotationPresentation {
        private static final Logger logger = Logger
                        .getLogger(EditorAnnotation.class);
-    private IMarker marker;
+    private final IMarker marker;
     private String text;
     private int line;
     private Position position;
 
-    // error identifiers, images and colors
-    /** Constant <code>ERROR_TYPE="editor.error.type"</code> */
-    public static String ERROR_TYPE = "editor.error.type";
-    /** Constant <code>ERROR_IMAGE</code> */
-    public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON);
-    /** Constant <code>ERROR_RGB</code> */
-    public static final RGB ERROR_RGB = new RGB(255, 0, 0);    
+    public enum EditorAnnotationType{
+       WARNING(ImageResources.WARNING_ANNOTATION_ICON, 244, 200, 45),
+       ERROR(ImageResources.ERROR_ANNOTATION_ICON, 255, 0, 0);
+       
+       public Image image;
+       public RGB color;
+       
+       EditorAnnotationType(String imageResource, int r, int g, int b){
+               image = ImageResources.getImage(imageResource);
+               color = new RGB(r, g, b);
+       }
+
+               /**
+                * @param problem
+                * @return
+                */
+               public static EditorAnnotationType getTypeByProblem(
+                               ParserProblem problem) {
+                       if (problem.isWarning()) {
+                               return WARNING;
+                       }else if (problem.isError()) {
+                               return ERROR;
+                       }
+                       return null;
+               }
+       
+    }
+    
+//    // error identifiers, images and colors
+//    /** Constant <code>ERROR_TYPE="editor.error.type"</code> */
+//    public static String ERROR_TYPE = "editor.error.type";
+//    /** Constant <code>ERROR_IMAGE</code> */
+//    public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON);
+//    /** Constant <code>ERROR_RGB</code> */
+//    public static final RGB ERROR_RGB = new RGB(255, 0, 0);    
+//    
+//    /** Constant <code>WARNING_TYPE="editor.warning.type"</code> */
+//    public static String WARNING_TYPE = "editor.warning.type";
+//    /** Constant <code>WARNING_IMAGE</code> */
+//    public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON);
+//    /** Constant <code>WARNING_RGB</code> */
+//    public static final RGB WARNING_RGB = new RGB(244, 200, 45); 
+    
+    
+    public EditorAnnotation(ParserProblem problem){
+       this(EditorAnnotationType.getTypeByProblem(problem), 0, problem.getMessage());
+    }
     
-    /** Constant <code>WARNING_TYPE="editor.warning.type"</code> */
-    public static String WARNING_TYPE = "editor.warning.type";
-    /** Constant <code>WARNING_IMAGE</code> */
-    public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON);
-    /** Constant <code>WARNING_RGB</code> */
-    public static final RGB WARNING_RGB = new RGB(244, 200, 45); 
     
     /**
      * <p>Constructor for EditorAnnotation.</p>
@@ -59,7 +94,7 @@ public class EditorAnnotation extends Annotation implements IAnnotationPresentat
      * @param text a {@link java.lang.String} object.
      */
     public EditorAnnotation(int line, String text) {
-       this(ERROR_TYPE, line, text);
+       this(EditorAnnotationType.ERROR, line, text);
     }
 
     /**
@@ -69,8 +104,8 @@ public class EditorAnnotation extends Annotation implements IAnnotationPresentat
      * @param line a int.
      * @param text a {@link java.lang.String} object.
      */
-    public EditorAnnotation(String type, int line, String text) {
-       super(type, false, text);
+    public EditorAnnotation(EditorAnnotationType type, int line, String text) {
+       super(type.name(), false, text);
         this.marker = null;
         this.line = line;
         this.text = text;
@@ -99,11 +134,12 @@ public class EditorAnnotation extends Annotation implements IAnnotationPresentat
      *
      * @return a {@link java.lang.String} object.
      */
-    public String getText() {
-       if (ERROR_TYPE.equals(getType())) {
+    @Override
+       public String getText() {
+       if (EditorAnnotationType.ERROR.name().equals(getType())) {
                return "Error: " + text;
        }
-       if (WARNING_TYPE.equals(getType())) {
+       if (EditorAnnotationType.WARNING.name().equals(getType())) {
                return "Warning: " + text;
        }
        return super.getText();
@@ -113,14 +149,7 @@ public class EditorAnnotation extends Annotation implements IAnnotationPresentat
         * @return
         */
        private Image getImage() {
-       if (ERROR_TYPE.equals(getType())) {
-               return ERROR_IMAGE;
-       }
-       if (WARNING_TYPE.equals(getType())) {
-               return WARNING_IMAGE;
-       }
-               logger.warn("No image for type " + getType());
-               return null;
+       return EditorAnnotationType.valueOf(getType()).image;
        }
     
     /**
index 33229eb0340af234327bb3be61fb1146118136d4..ae2a122fdbd738146306917a4517ee62aeac7cab 100644 (file)
@@ -83,13 +83,16 @@ public class MisapplicationContainer extends AbstractGroupedContainer<Taxon> {
                return EditorUtil.getFont(Resources.MISAPPLIEDNAME_FONT);
        }
        
-       /**
-        * <p>calculateErrors</p>
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
         */
-       protected void calculateErrors() {
-               super.calculateErrors();
-               
-               nameViewer.setShowSecError(getMisappliedName());
+       @Override
+       public void showAnnotations() {
+               if(getData().getSec() == null){
+                       getNameViewer().addAnnotation(
+                                       new EditorAnnotation(0, "This misapplication requires a sec. reference."));
+               }
+               super.showAnnotations();
        }
        
 
index aa08018871e25a4951d1aff1094c1d99dbf08154..2149e5d75e2a6a0f5d1a43603816ecbdf441e9ff 100644 (file)
@@ -44,12 +44,9 @@ import org.eclipse.ui.operations.UndoActionHandler;
 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
 
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.ViewerConfiguration;
+import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation.EditorAnnotationType;
 import eu.etaxonomy.taxeditor.preference.Resources;
 
 /**
@@ -64,8 +61,8 @@ public class NameViewer extends SourceViewer {
        /** Constant <code>RULER_WIDTH=16</code> */
        public static final int RULER_WIDTH = 16;
        
-       private IVerticalRuler ruler;
-       private AnnotationModel annotationModel;
+       private final IVerticalRuler ruler;
+       private final AnnotationModel annotationModel;
 
        /**
         * <p>Constructor for NameViewer.</p>
@@ -166,6 +163,7 @@ public class NameViewer extends SourceViewer {
         *
         * @return a {@link org.eclipse.swt.widgets.Layout} object.
         */
+       @Override
        protected Layout createLayout() {
                TableWrapLayout layout = new TableWrapLayout();
                layout.numColumns = 2;
@@ -184,29 +182,27 @@ public class NameViewer extends SourceViewer {
                annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());
                
                // Add ability to paint red squigglies
-               annotationPainter.addAnnotationType(EditorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);
-               annotationPainter.setAnnotationTypeColor(EditorAnnotation.ERROR_TYPE
-                               new Color(Display.getDefault(), EditorAnnotation.ERROR_RGB));
+               annotationPainter.addAnnotationType(EditorAnnotationType.ERROR.name(), LineWrapSquigglesStrategy.ID);
+               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image
+                               new Color(Display.getDefault(), EditorAnnotationType.ERROR.color));
 
                // Add ability to paint yellow squigglies
-               annotationPainter.addAnnotationType(EditorAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);
-               annotationPainter.setAnnotationTypeColor(EditorAnnotation.WARNING_TYPE
-                               new Color(Display.getDefault(), EditorAnnotation.WARNING_RGB));
+               annotationPainter.addAnnotationType(EditorAnnotationType.WARNING.name(), LineWrapSquigglesStrategy.ID);
+               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image
+                               new Color(Display.getDefault(), EditorAnnotationType.WARNING.color));
                
                this.addPainter(annotationPainter);
        }
 
 
        /**
-        * <p>clearErrors</p>
+        * <p>clearAnnotations</p>
         */
-       public void clearErrors() {
+       public void clearAnnotations() {
                Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
                while (annotations.hasNext()) {
                        Annotation annotation = annotations.next(); 
-                       if (annotation.getType().equals(EditorAnnotation.ERROR_TYPE) || annotation.getType().equals(EditorAnnotation.WARNING_TYPE)) {
-                               this.getAnnotationModel().removeAnnotation(annotation);
-                       }
+                       this.getAnnotationModel().removeAnnotation(annotation);
                }
        }
        
@@ -217,83 +213,55 @@ public class NameViewer extends SourceViewer {
         *
         * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
         */
-       public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
-                               
-               String text = this.getTextWidget().getText();
-                                               
-               if (name.hasProblem() && text.length() > 0) {
-                       int start = name.getProblemStarts();
-                       int length = name.getProblemEnds() - start;
-                       
-                       if (start == -1 || name.getProblemEnds() == -1) {
-                               return;
-                       }
-                       
-                       // Don't let squigglies try to draw beyond the end of the text
-                       if (text.length() < start + length) {
-                               length = text.length() - start;
-                       }
-                       
-                       for (ParserProblem problem : name.getParsingProblems()) {
-                               
-                               String type = null;
-                               if (problem.isWarning()) {
-                                       type = EditorAnnotation.WARNING_TYPE;
-                               }
-                               if (problem.isError()) {
-                                       type = EditorAnnotation.ERROR_TYPE;
-                               }
-                               if (type == null) {
-                                       continue;
-                               }
-                               this.getAnnotationModel().addAnnotation(
-                                               new EditorAnnotation(type, 0, problem.getMessage()), 
-                                               new Position(start, length));
-                       }
-               }
-       }
+//     public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
+//                             
+//             String text = this.getTextWidget().getText();
+//                                             
+//             if (name.hasProblem() && text.length() > 0) {
+//                     int start = name.getProblemStarts();
+//                     int length = name.getProblemEnds() - start;
+//                     
+//                     if (start == -1 || name.getProblemEnds() == -1) {
+//                             return;
+//                     }
+//                     
+//                     // Don't let squigglies try to draw beyond the end of the text
+//                     if (text.length() < start + length) {
+//                             length = text.length() - start;
+//                     }
+//                     
+//                     for (ParserProblem problem : name.getParsingProblems()) {
+//                             
+//                             String type = null;
+//                             if (problem.isWarning()) {
+//                                     type = EditorAnnotation.WARNING_TYPE;
+//                             }
+//                             if (problem.isError()) {
+//                                     type = EditorAnnotation.ERROR_TYPE;
+//                             }
+//                             if (type == null) {
+//                                     continue;
+//                             }
+//                             this.getAnnotationModel().addAnnotation(
+//                                             new EditorAnnotation(type, 0, problem.getMessage()), 
+//                                             new Position(start, length));
+//                     }
+//                     
+//             }
+//     }
        
-       
-       /**
-        * <p>setShowSecError</p>
-        *
-        * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
-        */
-       public void setShowSecError(Taxon taxon) {
-               
-               // If taxon has no sec, show an annotation
-               if (taxon.getSec() == null) {
-                       
-                       String text = "This taxon requires a sec. reference.";
-                       
-                       this.getAnnotationModel().addAnnotation(
-                                       new EditorAnnotation(0, text),
-                                       new Position(0, 0));
-               }
+       public void addAnnotation(EditorAnnotation annotation){
+               addAnnotation(annotation, null);
        }
-
-       public void setShowMultipleNameUsageWarning(TaxonNameBase name){
-               if(name.getTaxonBases().size() > 1){
-                       String text = "This taxons name is used multiple times.";
-                       
-                       this.getAnnotationModel().addAnnotation(
-                                       new EditorAnnotation(EditorAnnotation.WARNING_TYPE, 0, text),
-                                       new Position(0, 0));
+       
+       public void addAnnotation(EditorAnnotation annotation, Position position){
+               if(position == null){
+                       position = new Position(0, 0);
                }
-       }
-                       
-       /**
-        * @param name
-        */
-       public void setShowNameNotParsableWarning(NonViralName name) {
-               String text = "This name may only be edited in the details view.";
-               
-               this.getAnnotationModel().addAnnotation(
-                               new EditorAnnotation(EditorAnnotation.WARNING_TYPE, 0, text),
-                               new Position(0, 0));
                
+               this.getAnnotationModel().addAnnotation(annotation, position);
        }
-       
+               
        /**
         * <p>setText</p>
         *
index 4b2528db67e7d91968f4a3eda61f8ad158eaa75f..4415ee1d167c387ab1cfd7ca4ca28a04f5a149f1 100644 (file)
@@ -25,7 +25,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
 
@@ -53,7 +52,8 @@ public class EditHandler extends AbstractHandler implements IHandler{
                                Classification classification = (Classification) structuredSelection.getFirstElement();
                                
                                NewClassificationWizard classificationWizard = new NewClassificationWizard();
-                               classificationWizard.init(null, new StructuredSelection(classification));
+                               classificationWizard.init(null, null);
+                               classificationWizard.setEntity(classification);
                                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
                                dialog.open();
                                
index 6375d0663c275ded9d6bab9faf597e8553457f4d..8a6a476ad30a4aaab2001e74804f075e39aedc88 100644 (file)
@@ -52,7 +52,7 @@ public class SearchBar extends WorkbenchWindowControlContribution{
        private Text text_search;
        private String srv;
 
-       private String defaultText = "Use \"*\" for wildcard searching";
+       private final String defaultText = "Use \"*\" for wildcard searching";
 
        final private ConfigurationSelectionListener configurationListener = new ConfigurationSelectionListener();
 
@@ -174,11 +174,13 @@ public class SearchBar extends WorkbenchWindowControlContribution{
                if(searchString == null){
                        return;
                }
+               
                if("*".equals(searchString.trim())){
                        NavigationUtil.warningDialog("Could not execute search", this, "Please type at least one character when using the \"*\" wildcard.");
                        return;
                }
                
+               
                ITaxonServiceConfigurator configurator = configurationListener.getConfigurator();
                configurator.setSearchString(searchString);
                openSearchResultsView(configurator);
@@ -221,7 +223,7 @@ public class SearchBar extends WorkbenchWindowControlContribution{
         */
        class DropdownSelectionListener extends SelectionAdapter {
 
-               private Menu menu;
+               private final Menu menu;
 
                public DropdownSelectionListener(ToolItem dropdown) {
                        menu = new Menu(dropdown.getParent().getShell());
@@ -235,6 +237,7 @@ public class SearchBar extends WorkbenchWindowControlContribution{
                        menuItem.addSelectionListener(configurationListener);
                }
 
+               @Override
                public void widgetSelected(SelectionEvent event) {
                        if (event.detail == SWT.ARROW) {
                                ToolItem item = (ToolItem) event.widget;
@@ -266,6 +269,7 @@ public class SearchBar extends WorkbenchWindowControlContribution{
                 * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
                 * .swt.events.SelectionEvent)
                 */
+               @Override
                public void widgetSelected(SelectionEvent e) {
                        NavigationUtil.info("configuration menu clicked");
                        SearchOption option = (SearchOption) e.widget.getData();
@@ -311,7 +315,7 @@ public class SearchBar extends WorkbenchWindowControlContribution{
                NAME("Names (without taxa)"), 
                COMMON_NAME("Common Names");
 
-               private String label;
+               private final String label;
 
                private SearchOption(String label) {
                        this.label = label;
index fe1ba4480f3266a241822fa4cb5b6eeb8cfe3cc4..a6d99464797e540e3ff46a182cce3dde21f6de15 100644 (file)
@@ -27,6 +27,15 @@ public class NewClassificationWizard extends AbstractNewEntityWizard<Classificat
 
        private ClassificationWizardPage classificationWizardPage;
 
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard#setEntity(java.lang.Object)
+        */
+       @Override
+       public void setEntity(Classification entity) {
+               entity = CdmStore.getService(IClassificationService.class).load(entity.getUuid());
+               super.setEntity(entity);
+       }
+       
        @Override
        public void addPages() {
                classificationWizardPage = new ClassificationWizardPage(formFactory, getConversationHolder(), getEntity());
index 572d5299d5e88a0b770ef3491fcd62c5ec0d4698..8f55da5513c72708059ff865d1f76f4eb926f322 100644 (file)
 package eu.etaxonomy.taxeditor.store;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.IGroupService;
 import eu.etaxonomy.cdm.api.service.INameService;
@@ -37,6 +41,16 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
  * @version 1.0
  */
 public class SearchManager {
+       
+       public static final List NO_RESULTS = Arrays.asList(new Object[]{});
+       
+       public static final String WILDCARD = "*";
+       
+       public static int NO_COUNT = -1;
+       
+       // TODO make this configurable via preferences
+       private static final int MAX_RESULTS_BEFORE_WARNING = 500; 
+       
        /**
         * <p>findNames</p>
         *
@@ -47,9 +61,15 @@ public class SearchManager {
                // TODO we want to use IIdentifiableEntityServiceConfigurator for all find methods
                // unfortunately this is not consistently implemented in the library.
                // FIXME use proper method once it is implemented in the library
-               String titleSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String titleSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(INameService.class).getNamesByName(titleSearchString);
+               return checkLargeResult(configurator, countNames(configurator)) ? CdmStore.getService(INameService.class).getNamesByName(titleSearchString) : NO_RESULTS;
+       }
+       
+
+
+       private int countNames(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
        }
 
        /**
@@ -60,7 +80,11 @@ public class SearchManager {
         */
        public List<UuidAndTitleCache<TaxonBase>> findTaxaAndNames(ITaxonServiceConfigurator configurator){
                
-               return CdmStore.getService(ITaxonService.class).findTaxaAndNamesForEditor(configurator);
+               return checkLargeResult(configurator, countTaxaAndNames(configurator)) ? CdmStore.getService(ITaxonService.class).findTaxaAndNamesForEditor(configurator) : NO_RESULTS;
+       }
+       
+       private int countTaxaAndNames(ITaxonServiceConfigurator configurator){
+               return NO_COUNT;
        }
        
        /**
@@ -73,9 +97,13 @@ public class SearchManager {
                // TODO we want to use IIdentifiableEntityServiceConfigurator for all find methods
                // unfortunately this is not consistently implemented in the library.
                // FIXME use proper method once it is implemented in the library
-               String titleSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String titleSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(IReferenceService.class).findByTitle(null, titleSearchString, null, null, null, null, null, null).getRecords();
+               return checkLargeResult(configurator, countReferences(configurator)) ? CdmStore.getService(IReferenceService.class).findByTitle(null, titleSearchString, null, null, null, null, null, null).getRecords() : NO_RESULTS;
+       }
+       
+       private int countReferences(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
        }
        
        /**
@@ -88,9 +116,13 @@ public class SearchManager {
                // TODO we want to use IIdentifiableEntityServiceConfigurator for all find methods
                // unfortunately this is not consistently implemented in the library.
                // FIXME use proper method once it is implemented in the library
-               String titleSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String titleSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(IAgentService.class).findByTitle(null, titleSearchString, null, null, null, null, null, null).getRecords();
+               return checkLargeResult(configurator, countAgents(configurator)) ? CdmStore.getService(IAgentService.class).findByTitle(null, titleSearchString, null, null, null, null, null, null).getRecords() : NO_RESULTS;
+       }
+       
+       private int countAgents(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
        }
 
        /**
@@ -103,11 +135,19 @@ public class SearchManager {
                // TODO move this to cdmlib
                List<AgentBase> result = new ArrayList<AgentBase>();
                for (AgentBase agent : findAgents(configurator)) {
-                       result.add((AgentBase) agent);
+                       result.add(agent);
                }
                return result;
        }
        
+       /**
+        * @param configurator
+        * @return
+        */
+       private int countTeamOrPersons(IIdentifiableEntityServiceConfigurator configurator) {
+               return NO_COUNT;
+       }
+       
        /**
         * <p>findOccurrences</p>
         *
@@ -118,20 +158,58 @@ public class SearchManager {
                // TODO we want to use IIdentifiableEntityServiceConfigurator for all find methods
                // unfortunately this is not consistently implemented in the library.
                // FIXME use proper method once it is implemented in the library
-               String titleSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String titleSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(IOccurrenceService.class).findByTitle(SpecimenOrObservationBase.class, titleSearchString, null, null, null, null, null, null).getRecords();
+               return checkLargeResult(configurator, countOccurrences(configurator)) ? CdmStore.getService(IOccurrenceService.class).findByTitle(SpecimenOrObservationBase.class, titleSearchString, null, null, null, null, null, null).getRecords() : NO_RESULTS;
+       }
+       
+       private int countOccurrences(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
        }
        
        public List<User> findUsers(IIdentifiableEntityServiceConfigurator configurator){
-               String userNameSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String userNameSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
+               return checkLargeResult(configurator, countUsers(configurator)) ? CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null) : NO_RESULTS;
+       }
+       
+       private int countUsers(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
        }
        
        public List<Group> findGroups(IIdentifiableEntityServiceConfigurator configurator){
-               String groupNameSearchString = configurator.getTitleSearchString().replace("*", "%");
+               String groupNameSearchString = getTitleSearchString(configurator);
                
-               return CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
+               return checkLargeResult(configurator, countGroups(configurator)) ? CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null) : NO_RESULTS;
+       }
+       
+       private int countGroups(IIdentifiableEntityServiceConfigurator configurator){
+               return NO_COUNT;
+       }
+       
+       /**
+        * @param countNames
+        * @return
+        */
+       private boolean checkLargeResult(IIdentifiableEntityServiceConfigurator configurator, int countNames) {
+               if(isWildCardOnly(configurator) || countNames > MAX_RESULTS_BEFORE_WARNING){
+                       return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Large result exptected", "The current search could lead to a very large result. Retrieving this result set might take a long time and/or render the editor unusable.");
+               }else{
+                       return true;
+               }               
+       }
+       
+       private boolean isWildCardOnly(IIdentifiableEntityServiceConfigurator configurator){
+               return WILDCARD.equals(configurator.getTitleSearchString());
+       }
+       
+       /**
+        * TODO this will be obsolete once IIdentifiableEntityServiceConfigurator is implemented in find* methods
+        * 
+        * @param configurator
+        * @return
+        */
+       private String getTitleSearchString(IIdentifiableEntityServiceConfigurator configurator){
+               return configurator.getTitleSearchString().replace(WILDCARD, "%");
        }
 }
index dd0058a9e8cf591b097445a39dd14bd1638da553..526c37c2f26eb99e6b2cf9e26b0b09549a334d89 100644 (file)
@@ -94,7 +94,7 @@ public class DeterminationEventDetailElement extends
                                .createTermComboElement(TermComboType.DETERMINATION_MODIFIER,
                                                element, "Determination Modifier", null, style);
                checkbox_preferredFlag = formFactory.createCheckbox(element,
-                               "Preferred", false, style);
+                               "Current", false, style);
                selection_taxon = (TaxonSelectionElement) formFactory
                                .createSelectionElement(SelectionType.TAXON,
                                                getConversationHolder(), element, "Taxon", null,