ref #6595, #6597 Optimize selection event propagation
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 3 Nov 2017 08:06:25 +0000 (09:06 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 3 Nov 2017 08:06:39 +0000 (09:06 +0100)
 - reduce rendering of details view etc.

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java

index d02ab0313ed66c30e51e83725f34a0a49298a379..8fc5f570a4a20bce5abdb96b84f773cd947fcc0d 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * 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.
  */
@@ -57,10 +57,10 @@ import eu.etaxonomy.taxeditor.preference.Resources;
  * @version 1.0
  */
 public class NameViewer extends SourceViewer {
-               
+
        /** Constant <code>RULER_WIDTH=16</code> */
        public static final int RULER_WIDTH = 16;
-       
+
        private final IVerticalRuler ruler;
        private final AnnotationModel annotationModel;
 
@@ -71,11 +71,11 @@ public class NameViewer extends SourceViewer {
         */
        public NameViewer(Composite parent) {
                super(parent, new RulerWithIcon(RULER_WIDTH), SWT.WRAP | SWT.MULTI | SWT.RESIZE);
-                                                                                       
+
                this.ruler = getVerticalRuler();
-                               
+
                setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
-                               
+
                Canvas canvas = (Canvas) getControl();
                TableWrapLayout layout = (TableWrapLayout) canvas.getLayout();
                layout.topMargin = 0;
@@ -84,55 +84,55 @@ public class NameViewer extends SourceViewer {
                layout.leftMargin = 0;
                layout.verticalSpacing = 10;
                layout.horizontalSpacing = 0;
-               
+
                canvas.setLayout(layout);
-               
+
                // Lay out the viewer's widgets
                TableWrapData twdata = new TableWrapData(TableWrapData.FILL_GRAB);
                getControl().setLayoutData(twdata);
-               
+
                twdata = new TableWrapData(TableWrapData.FILL_GRAB);
                getTextWidget().setLayoutData(twdata);
                getTextWidget().setLineSpacing(5);
-               
-               // Default implementation adds ruler after the text widget, then 
+
+               // Default implementation adds ruler after the text widget, then
                //      uses a custom layout to display it before the text widget
                ruler.getControl().moveAbove(getTextWidget());
 
                annotationModel = new AnnotationModel();
                this.setDocument(new Document(""), annotationModel); //$NON-NLS-1$
-               
+
                createAnnotationPainter();
 
-               this.configure(new ViewerConfiguration());              
-               
+               this.configure(new ViewerConfiguration());
+
 //             setDecorationSupport();
 //             DocumentUndoManagerRegistry.connect(this.getDocument());
 //             IDocumentUndoManager docUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(this.getDocument());
-               
+
                /**
                getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));
-               getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));              
+               getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));
                **/
        }
-       
+
        /**
         * <p>setBackground</p>
         *
         * @param color a {@link org.eclipse.swt.graphics.Color} object.
         */
        public void setBackground(Color color) {
-               
+
                // Set background color of ruler
                ruler.getControl().setBackground(color);
 
                // Set background color of text widget
                getTextWidget().setBackground(color);
-               
+
                // Set background color of strip between ruler and textWidget
-               getTextWidget().getParent().setBackground(color); 
+               getTextWidget().getParent().setBackground(color);
        }
-       
+
        /**
         * <p>getRulerControl</p>
         *
@@ -154,7 +154,7 @@ public class NameViewer extends SourceViewer {
                        throw new IllegalStateException("Viewer's IVerticalRuler is not an instance of RulerWithIcon."); //$NON-NLS-1$
                }
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.text.source.SourceViewer#createLayout()
         */
@@ -170,27 +170,27 @@ public class NameViewer extends SourceViewer {
                layout.verticalSpacing = 0;
                return layout;
        }
-               
+
        private void createAnnotationPainter(){
                // Annotations section
                IAnnotationAccess fAnnotationAccess = new DefaultMarkerAnnotationAccess();
-               
+
                // To paint the annotations
                AnnotationPainter annotationPainter = new AnnotationPainter(this, fAnnotationAccess);
 
                // Default SquigglesStrategy doesn't recognize line wraps
                annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());
-               
+
                // Add ability to paint red squigglies
                annotationPainter.addAnnotationType(EditorAnnotationType.ERROR.name(), LineWrapSquigglesStrategy.ID);
-               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image, 
+               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image,
                                new Color(Display.getDefault(), EditorAnnotationType.ERROR.color));
 
                // Add ability to paint yellow squigglies
                annotationPainter.addAnnotationType(EditorAnnotationType.WARNING.name(), LineWrapSquigglesStrategy.ID);
-               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image, 
+               annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image,
                                new Color(Display.getDefault(), EditorAnnotationType.WARNING.color));
-               
+
                this.addPainter(annotationPainter);
        }
 
@@ -201,11 +201,11 @@ public class NameViewer extends SourceViewer {
        public void clearAnnotations() {
                Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
                while (annotations.hasNext()) {
-                       Annotation annotation = annotations.next(); 
+                       Annotation annotation = annotations.next();
                        this.getAnnotationModel().removeAnnotation(annotation);
                }
        }
-       
+
        /**
         * If <code>name.hasProblem()</code> is <code>true</code>, underlines section
         * of text bounded by <code>name.getProblemStarts()</code> and
@@ -214,24 +214,24 @@ 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;
@@ -243,25 +243,25 @@ public class NameViewer extends SourceViewer {
 //                                     continue;
 //                             }
 //                             this.getAnnotationModel().addAnnotation(
-//                                             new EditorAnnotation(type, 0, problem.getMessage()), 
+//                                             new EditorAnnotation(type, 0, problem.getMessage()),
 //                                             new Position(start, length));
 //                     }
-//                     
+//
 //             }
 //     }
-       
+
        public void addAnnotation(EditorAnnotation annotation){
                addAnnotation(annotation, null);
        }
-       
+
        public void addAnnotation(EditorAnnotation annotation, Position position){
                if(position == null){
                        position = new Position(0, 0);
                }
-               
+
                this.getAnnotationModel().addAnnotation(annotation, position);
        }
-               
+
        /**
         * <p>setText</p>
         *
@@ -283,7 +283,7 @@ public class NameViewer extends SourceViewer {
                        throw e;
                }
        }
-       
+
        /**
         * <p>setMenu</p>
         *
@@ -299,10 +299,9 @@ public class NameViewer extends SourceViewer {
         */
        public void setCursorToEOL() {
                getTextWidget().setCaretOffset(getTextWidget().getText().length());
-               getTextWidget().setFocus();
        }
 
-       
+
        /**
         * <p>getCursorPosition</p>
         *
@@ -311,7 +310,7 @@ public class NameViewer extends SourceViewer {
        public int getCursorPosition(){
                return getTextWidget().getCaretOffset();
        }
-       
+
        /**
         * <p>setCursorPosition</p>
         *
@@ -335,15 +334,15 @@ public class NameViewer extends SourceViewer {
                IUndoManager undoManager = new TextViewerUndoManager(25);
                this.setUndoManager(undoManager);
                undoManager.connect(this);
-               
+
 //             IUndoContext workbenchUndoContext = UiUtil.getWorkbenchUndoContext();
-               
+
                IUndoContext workbenchUndoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
-               
+
                OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, workbenchUndoContext);
 //             undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
                undoAction.setActionDefinitionId(ActionFactory.UNDO.getId());
-               
+
                // Create the redo action.
                OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, workbenchUndoContext);
 //             redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
@@ -355,13 +354,13 @@ public class NameViewer extends SourceViewer {
 //                             actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
                        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
                        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
-                       
-               }               
-               
+
+               }
+
 //             actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
 //             actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
        }
-       
+
        /**
         * <p>createUndoSupport_</p>
         *
@@ -374,11 +373,11 @@ public class NameViewer extends SourceViewer {
                IUndoContext undoContext;
                if (undoManager instanceof IUndoManagerExtension) {
                        undoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
-               
+
                        OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, undoContext);
 //                     PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);
                        undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
-                       
+
                        // Create the redo action.
                        OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, undoContext);
 //                     PlatformUI.getWorkbench().getHelpSystem().setHelp(redoAction, IAbstractTextEditorHelpContextIds.REDO_ACTION);
@@ -389,7 +388,7 @@ public class NameViewer extends SourceViewer {
                        if (actionBars != null) {
                                actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);
                                actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
-                               
+
                        }
                }
        }
index 3b60785c430d404449485579c51d88a5ae284026..8debbebd540cf79f91725de3c7db56eb32f6602f 100644 (file)
@@ -174,9 +174,11 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
                        @Override
                        public boolean setInput(Object input) {
                                if (input instanceof AbstractGroupedContainerE4) {
-                                       selection = ((AbstractGroupedContainerE4) input).getData();
-
-                               selService.setSelection(new StructuredSelection(selection));
+                                   TaxonBase newSelection = ((AbstractGroupedContainerE4) input).getData();
+                                   if(selection!=newSelection){
+                                       selection = newSelection;
+                                       selService.setSelection(new StructuredSelection(selection));
+                                   }
                                }else if(input == null){
                                        selection = null;
                     selService.setSelection(new StructuredSelection());
@@ -511,18 +513,7 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
        }
 
        public AbstractGroupedContainerE4 getSelectedContainer() {
-
-               TaxonBase selectedTaxonBase = null;
-
-               if (input.getInitiallySelectedTaxonBase() != null) {
-                       selectedTaxonBase = input.getInitiallySelectedTaxonBase();
-               } else {
-                       if (selection != null) {
-                               selectedTaxonBase = selection;
-                       }
-               }
-
-               return (selectedTaxonBase != null) ? getContainer(selectedTaxonBase)
+               return (selection != null) ? getContainer(selection)
                                : getAcceptedNameContainer();
        }
 
index 6b763c48d2b1a3299bfc0735fd5aa0d5afad3fc9..0f0fb696f9766bb23939e97c3249abcd80d99947 100644 (file)
@@ -36,6 +36,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
 import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
+import eu.etaxonomy.taxeditor.event.EventUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.view.e4.details.DetailsViewerE4;
@@ -118,11 +119,14 @@ public abstract class AbstractCdmEditorPartE4
     protected abstract void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart);
 
     @Inject
-    @Optional
     public void selectionChanged(
-            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
+            @Optional@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MPart thisPart, UISynchronize sync){
+        if(activePart==thisPart && EventUtility.getTaxonEditor()==null){
+            showEmptyPage();
+            return;
+        }
         if(previousSelection==null ||
                 previousSelection!=selection){//skip redundant rendering of details view
             if(delaySelection==null){