From 61d94a7a2f23dbc7e13b4929d8ddb17d3114b16f Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Fri, 3 Nov 2017 09:06:25 +0100 Subject: [PATCH] ref #6595, #6597 Optimize selection event propagation - reduce rendering of details view etc. --- .../editor/name/container/NameViewer.java | 115 +++++++++--------- .../editor/name/e4/TaxonNameEditorE4.java | 21 +--- .../view/e4/AbstractCdmEditorPartE4.java | 10 +- 3 files changed, 70 insertions(+), 76 deletions(-) diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java index d02ab0313..8fc5f570a 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java @@ -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 RULER_WIDTH=16 */ 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)); **/ } - + /** *

setBackground

* * @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); } - + /** *

getRulerControl

* @@ -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 annotations = this.getAnnotationModel().getAnnotationIterator(); while (annotations.hasNext()) { - Annotation annotation = annotations.next(); + Annotation annotation = annotations.next(); this.getAnnotationModel().removeAnnotation(annotation); } } - + /** * If name.hasProblem() is true, underlines section * of text bounded by name.getProblemStarts() 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); } - + /** *

setText

* @@ -283,7 +283,7 @@ public class NameViewer extends SourceViewer { throw e; } } - + /** *

setMenu

* @@ -299,10 +299,9 @@ public class NameViewer extends SourceViewer { */ public void setCursorToEOL() { getTextWidget().setCaretOffset(getTextWidget().getText().length()); - getTextWidget().setFocus(); } - + /** *

getCursorPosition

* @@ -311,7 +310,7 @@ public class NameViewer extends SourceViewer { public int getCursorPosition(){ return getTextWidget().getCaretOffset(); } - + /** *

setCursorPosition

* @@ -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); } - + /** *

createUndoSupport_

* @@ -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); - + } } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java index 3b60785c4..8debbebd5 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java @@ -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(); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java index 6b763c48d..0f0fb696f 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java @@ -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){ -- 2.34.1