Project

General

Profile

Revision 61d94a7a

ID61d94a7a2f23dbc7e13b4929d8ddb17d3114b16f
Parent 1aa2508a
Child eda8e07f

Added by Patrick Plitzner almost 3 years ago

ref #6595, #6597 Optimize selection event propagation

  • reduce rendering of details view etc.

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java
1 1
/**
2 2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy 
3
 * European Distributed Institute of Taxonomy
4 4
 * http://www.e-taxonomy.eu
5
 * 
5
 *
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
 */
......
57 57
 * @version 1.0
58 58
 */
59 59
public class NameViewer extends SourceViewer {
60
		
60

  
61 61
	/** Constant <code>RULER_WIDTH=16</code> */
62 62
	public static final int RULER_WIDTH = 16;
63
	
63

  
64 64
	private final IVerticalRuler ruler;
65 65
	private final AnnotationModel annotationModel;
66 66

  
......
71 71
	 */
72 72
	public NameViewer(Composite parent) {
73 73
		super(parent, new RulerWithIcon(RULER_WIDTH), SWT.WRAP | SWT.MULTI | SWT.RESIZE);
74
											
74

  
75 75
		this.ruler = getVerticalRuler();
76
				
76

  
77 77
		setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
78
				
78

  
79 79
		Canvas canvas = (Canvas) getControl();
80 80
		TableWrapLayout layout = (TableWrapLayout) canvas.getLayout();
81 81
		layout.topMargin = 0;
......
84 84
		layout.leftMargin = 0;
85 85
		layout.verticalSpacing = 10;
86 86
		layout.horizontalSpacing = 0;
87
		
87

  
88 88
		canvas.setLayout(layout);
89
		
89

  
90 90
		// Lay out the viewer's widgets
91 91
		TableWrapData twdata = new TableWrapData(TableWrapData.FILL_GRAB);
92 92
		getControl().setLayoutData(twdata);
93
		
93

  
94 94
		twdata = new TableWrapData(TableWrapData.FILL_GRAB);
95 95
		getTextWidget().setLayoutData(twdata);
96 96
		getTextWidget().setLineSpacing(5);
97
		
98
		// Default implementation adds ruler after the text widget, then 
97

  
98
		// Default implementation adds ruler after the text widget, then
99 99
		//	uses a custom layout to display it before the text widget
100 100
		ruler.getControl().moveAbove(getTextWidget());
101 101

  
102 102
		annotationModel = new AnnotationModel();
103 103
		this.setDocument(new Document(""), annotationModel); //$NON-NLS-1$
104
		
104

  
105 105
		createAnnotationPainter();
106 106

  
107
		this.configure(new ViewerConfiguration());		
108
		
107
		this.configure(new ViewerConfiguration());
108

  
109 109
//		setDecorationSupport();
110 110
//		DocumentUndoManagerRegistry.connect(this.getDocument());
111 111
//		IDocumentUndoManager docUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(this.getDocument());
112
		
112

  
113 113
		/**
114 114
		getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));
115
		getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));		
115
		getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));
116 116
		**/
117 117
	}
118
	
118

  
119 119
	/**
120 120
	 * <p>setBackground</p>
121 121
	 *
122 122
	 * @param color a {@link org.eclipse.swt.graphics.Color} object.
123 123
	 */
124 124
	public void setBackground(Color color) {
125
		
125

  
126 126
		// Set background color of ruler
127 127
		ruler.getControl().setBackground(color);
128 128

  
129 129
		// Set background color of text widget
130 130
		getTextWidget().setBackground(color);
131
		
131

  
132 132
		// Set background color of strip between ruler and textWidget
133
		getTextWidget().getParent().setBackground(color); 
133
		getTextWidget().getParent().setBackground(color);
134 134
	}
135
	
135

  
136 136
	/**
137 137
	 * <p>getRulerControl</p>
138 138
	 *
......
154 154
			throw new IllegalStateException("Viewer's IVerticalRuler is not an instance of RulerWithIcon."); //$NON-NLS-1$
155 155
		}
156 156
	}
157
	
157

  
158 158
	/* (non-Javadoc)
159 159
	 * @see org.eclipse.jface.text.source.SourceViewer#createLayout()
160 160
	 */
......
170 170
		layout.verticalSpacing = 0;
171 171
		return layout;
172 172
	}
173
		
173

  
174 174
	private void createAnnotationPainter(){
175 175
		// Annotations section
176 176
		IAnnotationAccess fAnnotationAccess = new DefaultMarkerAnnotationAccess();
177
		
177

  
178 178
		// To paint the annotations
179 179
		AnnotationPainter annotationPainter = new AnnotationPainter(this, fAnnotationAccess);
180 180

  
181 181
		// Default SquigglesStrategy doesn't recognize line wraps
182 182
		annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());
183
		
183

  
184 184
		// Add ability to paint red squigglies
185 185
		annotationPainter.addAnnotationType(EditorAnnotationType.ERROR.name(), LineWrapSquigglesStrategy.ID);
186
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image, 
186
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image,
187 187
				new Color(Display.getDefault(), EditorAnnotationType.ERROR.color));
188 188

  
189 189
		// Add ability to paint yellow squigglies
190 190
		annotationPainter.addAnnotationType(EditorAnnotationType.WARNING.name(), LineWrapSquigglesStrategy.ID);
191
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image, 
191
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image,
192 192
				new Color(Display.getDefault(), EditorAnnotationType.WARNING.color));
193
		
193

  
194 194
		this.addPainter(annotationPainter);
195 195
	}
196 196

  
......
201 201
	public void clearAnnotations() {
202 202
		Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
203 203
		while (annotations.hasNext()) {
204
			Annotation annotation = annotations.next(); 
204
			Annotation annotation = annotations.next();
205 205
			this.getAnnotationModel().removeAnnotation(annotation);
206 206
		}
207 207
	}
208
	
208

  
209 209
	/**
210 210
	 * If <code>name.hasProblem()</code> is <code>true</code>, underlines section
211 211
	 * of text bounded by <code>name.getProblemStarts()</code> and
......
214 214
	 * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
215 215
	 */
216 216
//	public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
217
//				
217
//
218 218
//		String text = this.getTextWidget().getText();
219
//						
219
//
220 220
//		if (name.hasProblem() && text.length() > 0) {
221 221
//			int start = name.getProblemStarts();
222 222
//			int length = name.getProblemEnds() - start;
223
//			
223
//
224 224
//			if (start == -1 || name.getProblemEnds() == -1) {
225 225
//				return;
226 226
//			}
227
//			
227
//
228 228
//			// Don't let squigglies try to draw beyond the end of the text
229 229
//			if (text.length() < start + length) {
230 230
//				length = text.length() - start;
231 231
//			}
232
//			
232
//
233 233
//			for (ParserProblem problem : name.getParsingProblems()) {
234
//				
234
//
235 235
//				String type = null;
236 236
//				if (problem.isWarning()) {
237 237
//					type = EditorAnnotation.WARNING_TYPE;
......
243 243
//					continue;
244 244
//				}
245 245
//				this.getAnnotationModel().addAnnotation(
246
//						new EditorAnnotation(type, 0, problem.getMessage()), 
246
//						new EditorAnnotation(type, 0, problem.getMessage()),
247 247
//						new Position(start, length));
248 248
//			}
249
//			
249
//
250 250
//		}
251 251
//	}
252
	
252

  
253 253
	public void addAnnotation(EditorAnnotation annotation){
254 254
		addAnnotation(annotation, null);
255 255
	}
256
	
256

  
257 257
	public void addAnnotation(EditorAnnotation annotation, Position position){
258 258
		if(position == null){
259 259
			position = new Position(0, 0);
260 260
		}
261
		
261

  
262 262
		this.getAnnotationModel().addAnnotation(annotation, position);
263 263
	}
264
		
264

  
265 265
	/**
266 266
	 * <p>setText</p>
267 267
	 *
......
283 283
			throw e;
284 284
		}
285 285
	}
286
	
286

  
287 287
	/**
288 288
	 * <p>setMenu</p>
289 289
	 *
......
299 299
	 */
300 300
	public void setCursorToEOL() {
301 301
		getTextWidget().setCaretOffset(getTextWidget().getText().length());
302
		getTextWidget().setFocus();
303 302
	}
304 303

  
305
	
304

  
306 305
	/**
307 306
	 * <p>getCursorPosition</p>
308 307
	 *
......
311 310
	public int getCursorPosition(){
312 311
		return getTextWidget().getCaretOffset();
313 312
	}
314
	
313

  
315 314
	/**
316 315
	 * <p>setCursorPosition</p>
317 316
	 *
......
335 334
		IUndoManager undoManager = new TextViewerUndoManager(25);
336 335
		this.setUndoManager(undoManager);
337 336
		undoManager.connect(this);
338
		
337

  
339 338
//		IUndoContext workbenchUndoContext = UiUtil.getWorkbenchUndoContext();
340
		
339

  
341 340
		IUndoContext workbenchUndoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
342
		
341

  
343 342
		OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, workbenchUndoContext);
344 343
//		undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
345 344
		undoAction.setActionDefinitionId(ActionFactory.UNDO.getId());
346
		
345

  
347 346
		// Create the redo action.
348 347
		OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, workbenchUndoContext);
349 348
//		redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
......
355 354
//				actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
356 355
			actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
357 356
			actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
358
			
359
		}		
360
		
357

  
358
		}
359

  
361 360
//		actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
362 361
//		actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
363 362
	}
364
	
363

  
365 364
	/**
366 365
	 * <p>createUndoSupport_</p>
367 366
	 *
......
374 373
		IUndoContext undoContext;
375 374
		if (undoManager instanceof IUndoManagerExtension) {
376 375
			undoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
377
		
376

  
378 377
			OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, undoContext);
379 378
//			PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);
380 379
			undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
381
			
380

  
382 381
			// Create the redo action.
383 382
			OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, undoContext);
384 383
//			PlatformUI.getWorkbench().getHelpSystem().setHelp(redoAction, IAbstractTextEditorHelpContextIds.REDO_ACTION);
......
389 388
			if (actionBars != null) {
390 389
				actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);
391 390
				actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
392
				
391

  
393 392
			}
394 393
		}
395 394
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
174 174
			@Override
175 175
			public boolean setInput(Object input) {
176 176
				if (input instanceof AbstractGroupedContainerE4) {
177
					selection = ((AbstractGroupedContainerE4) input).getData();
178

  
179
			        selService.setSelection(new StructuredSelection(selection));
177
				    TaxonBase newSelection = ((AbstractGroupedContainerE4) input).getData();
178
				    if(selection!=newSelection){
179
				        selection = newSelection;
180
				        selService.setSelection(new StructuredSelection(selection));
181
				    }
180 182
				}else if(input == null){
181 183
					selection = null;
182 184
                    selService.setSelection(new StructuredSelection());
......
511 513
	}
512 514

  
513 515
	public AbstractGroupedContainerE4 getSelectedContainer() {
514

  
515
		TaxonBase selectedTaxonBase = null;
516

  
517
		if (input.getInitiallySelectedTaxonBase() != null) {
518
			selectedTaxonBase = input.getInitiallySelectedTaxonBase();
519
		} else {
520
			if (selection != null) {
521
				selectedTaxonBase = selection;
522
			}
523
		}
524

  
525
		return (selectedTaxonBase != null) ? getContainer(selectedTaxonBase)
516
		return (selection != null) ? getContainer(selection)
526 517
				: getAcceptedNameContainer();
527 518
	}
528 519

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
36 36
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
37 37
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
38 38
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
39
import eu.etaxonomy.taxeditor.event.EventUtility;
39 40
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
40 41
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
41 42
import eu.etaxonomy.taxeditor.view.e4.details.DetailsViewerE4;
......
118 119
    protected abstract void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart);
119 120

  
120 121
    @Inject
121
    @Optional
122 122
    public void selectionChanged(
123
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
124
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
123
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
124
            @Optional@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
125 125
            MPart thisPart, UISynchronize sync){
126
        if(activePart==thisPart && EventUtility.getTaxonEditor()==null){
127
            showEmptyPage();
128
            return;
129
        }
126 130
        if(previousSelection==null ||
127 131
                previousSelection!=selection){//skip redundant rendering of details view
128 132
            if(delaySelection==null){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)