Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 348662 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/graphiti/bot/tests/GFOtherTests.java (-1 / +186 lines)
Lines 1-7 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
4
 * Copyright (c) 2005, 2011 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 * Contributors:
10
 * Contributors:
11
 *    SAP AG - initial API, implementation and documentation
11
 *    SAP AG - initial API, implementation and documentation
12
 *    mwenz - Bug 340627 - Features should be able to indicate cancellation
12
 *    mwenz - Bug 340627 - Features should be able to indicate cancellation
13
 *    mwenz - Bug 348662 - Setting tooptip to null in tool behavior provider doesn't clear up
14
 *                         tooltip if the associated figure has a previous tooltip
13
 *
15
 *
14
 * </copyright>
16
 * </copyright>
15
 *
17
 *
Lines 33-38 Link Here
33
import org.eclipse.core.runtime.IAdaptable;
35
import org.eclipse.core.runtime.IAdaptable;
34
import org.eclipse.core.runtime.OperationCanceledException;
36
import org.eclipse.core.runtime.OperationCanceledException;
35
import org.eclipse.draw2d.Ellipse;
37
import org.eclipse.draw2d.Ellipse;
38
import org.eclipse.draw2d.IFigure;
39
import org.eclipse.draw2d.Label;
36
import org.eclipse.draw2d.Polygon;
40
import org.eclipse.draw2d.Polygon;
37
import org.eclipse.draw2d.SWTGraphics;
41
import org.eclipse.draw2d.SWTGraphics;
38
import org.eclipse.draw2d.geometry.Point;
42
import org.eclipse.draw2d.geometry.Point;
Lines 51-56 Link Here
51
import org.eclipse.emf.transaction.RecordingCommand;
55
import org.eclipse.emf.transaction.RecordingCommand;
52
import org.eclipse.emf.transaction.TransactionalEditingDomain;
56
import org.eclipse.emf.transaction.TransactionalEditingDomain;
53
import org.eclipse.gef.EditPart;
57
import org.eclipse.gef.EditPart;
58
import org.eclipse.gef.GraphicalEditPart;
54
import org.eclipse.gef.GraphicalViewer;
59
import org.eclipse.gef.GraphicalViewer;
55
import org.eclipse.gef.commands.Command;
60
import org.eclipse.gef.commands.Command;
56
import org.eclipse.gef.commands.CommandStack;
61
import org.eclipse.gef.commands.CommandStack;
Lines 80-85 Link Here
80
import org.eclipse.graphiti.mm.algorithms.MultiText;
85
import org.eclipse.graphiti.mm.algorithms.MultiText;
81
import org.eclipse.graphiti.mm.algorithms.Polyline;
86
import org.eclipse.graphiti.mm.algorithms.Polyline;
82
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
87
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
88
import org.eclipse.graphiti.mm.algorithms.Text;
83
import org.eclipse.graphiti.mm.algorithms.styles.AdaptedGradientColoredAreas;
89
import org.eclipse.graphiti.mm.algorithms.styles.AdaptedGradientColoredAreas;
84
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredArea;
90
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredArea;
85
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredAreas;
91
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredAreas;
Lines 120-125 Link Here
120
import org.eclipse.swt.graphics.GC;
126
import org.eclipse.swt.graphics.GC;
121
import org.eclipse.swt.graphics.Image;
127
import org.eclipse.swt.graphics.Image;
122
import org.eclipse.swt.widgets.Display;
128
import org.eclipse.swt.widgets.Display;
129
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
130
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
123
import org.eclipse.swtbot.swt.finder.results.IntResult;
131
import org.eclipse.swtbot.swt.finder.results.IntResult;
124
import org.eclipse.swtbot.swt.finder.results.Result;
132
import org.eclipse.swtbot.swt.finder.results.Result;
125
import org.eclipse.swtbot.swt.finder.results.VoidResult;
133
import org.eclipse.swtbot.swt.finder.results.VoidResult;
Lines 259-264 Link Here
259
	}
267
	}
260
268
261
	@Test
269
	@Test
270
	public void testTooltip() throws Exception {
271
		/*
272
		 * Tests if the tooltips displayed in a diagram are correctly updated.
273
		 * The test uses the tutorial diagram type because there we had the
274
		 * situation that setting a previously set tooltip to null did not
275
		 * remove the tooltip from the figure. This was caused by the remove of
276
		 * the tooltip happening in the method
277
		 * PictogramElementDelegate.indicateNeededUpdates for the
278
		 * selectionFigure which is in case of the tutorial different from the
279
		 * figure holding the tooltip. See Bugzilla 348662 for details.
280
		 */
281
		final DiagramEditor diagramEditor = openDiagram(ITestConstants.DIAGRAM_TYPE_ID_TUTORIAL);
282
283
		/*
284
		 * Open a new diagram containing just one class
285
		 */
286
		syncExec(new VoidResult() {
287
			@Override
288
			public void run() {
289
290
				final IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
291
				final IFeatureProvider fp = diagramTypeProvider.getFeatureProvider();
292
				final Diagram currentDiagram = diagramTypeProvider.getDiagram();
293
294
				TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
295
				editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
296
297
					@Override
298
					protected void doExecute() {
299
						/*
300
						 * Reuse of functionality originally written to add
301
						 * classes for the ECore test tool. Might need adaption
302
						 * in case of future changes
303
						 */
304
						addClassToDiagram(fp, currentDiagram, 300, 300, "Shape");
305
					}
306
				});
307
			}
308
309
		});
310
311
		/*
312
		 * Check the correctness of the initial tooltip
313
		 */
314
		syncExec(new VoidResult() {
315
			@Override
316
			public void run() {
317
318
				// Get the figure to check the tooltip via SWTBot  
319
				SWTBotGefEditor ed = getGefEditor();
320
				SWTBotGefEditPart editPart = ed.getEditPart("Shape");
321
				IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure();
322
323
				// Check original tooltip
324
				if (!"Shape".equals(((Label) figure.getToolTip()).getText())) {
325
					fail("Tooltip must be 'Shape'");
326
				}
327
			}
328
329
		});
330
331
		/*
332
		 * Change the name of the eClass (and the display name in the diagram to
333
		 * avoid the need for calling the update feature)
334
		 */
335
		syncExec(new VoidResult() {
336
			@Override
337
			public void run() {
338
339
				final IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
340
				final Diagram currentDiagram = diagramTypeProvider.getDiagram();
341
342
				TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
343
344
				final ContainerShape tooltipShape = (ContainerShape) findShapeForEClass(currentDiagram, "Shape");
345
346
				Object bo = diagramTypeProvider.getFeatureProvider().getBusinessObjectForPictogramElement(tooltipShape);
347
				if (bo instanceof EClass) {
348
					final EClass eClass = (EClass) bo;
349
350
					// Change the tooltip to something else and check it
351
					editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
352
						@Override
353
						protected void doExecute() {
354
							eClass.setName("Changed");
355
							Text text = (Text) tooltipShape.getChildren().get(1).getGraphicsAlgorithm();
356
							text.setValue("Changed");
357
						}
358
					});
359
				}
360
			}
361
362
		});
363
364
		/*
365
		 * Check that the tooltip of the figure has been updated
366
		 */
367
		syncExec(new VoidResult() {
368
			@Override
369
			public void run() {
370
371
				final IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
372
				final Diagram currentDiagram = diagramTypeProvider.getDiagram();
373
374
				// Get the figure to check the tooltip via SWTBot  
375
				SWTBotGefEditor ed = getGefEditor();
376
				SWTBotGefEditPart editPart = ed.getEditPart("Changed");
377
				IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure();
378
379
				final ContainerShape tooltipShape = (ContainerShape) findShapeForEClass(currentDiagram, "Changed");
380
381
				Object bo = diagramTypeProvider.getFeatureProvider().getBusinessObjectForPictogramElement(tooltipShape);
382
				if (bo instanceof EClass) {
383
					if (!"Changed".equals(((Label) figure.getToolTip()).getText())) {
384
						fail("Tooltip must be 'Changed' but is '" + ((Label) figure.getToolTip()).getText() + "'");
385
					}
386
				}
387
			}
388
389
		});
390
391
		/*
392
		 * Change the name of the eClass to the empty string (and the display
393
		 * name in the diagram to avoid the need for calling the update
394
		 * feature), this will end up showing no tooltip.
395
		 */
396
		syncExec(new VoidResult() {
397
			@Override
398
			public void run() {
399
400
				final IDiagramTypeProvider diagramTypeProvider = diagramEditor.getDiagramTypeProvider();
401
				final Diagram currentDiagram = diagramTypeProvider.getDiagram();
402
403
				TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
404
405
				final ContainerShape tooltipShape = (ContainerShape) findShapeForEClass(currentDiagram, "Changed");
406
407
				Object bo = diagramTypeProvider.getFeatureProvider().getBusinessObjectForPictogramElement(tooltipShape);
408
				if (bo instanceof EClass) {
409
					final EClass eClass = (EClass) bo;
410
411
					// Change the tooltip to null and check it
412
					editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
413
						@Override
414
						protected void doExecute() {
415
							eClass.setName(""); // Empty name means no tooltip
416
							Text text = (Text) tooltipShape.getChildren().get(1).getGraphicsAlgorithm();
417
							text.setValue("Changed");
418
						}
419
					});
420
				}
421
			}
422
423
		});
424
425
		/*
426
		 * Check that the tooltip of the figure has been removed
427
		 */
428
		syncExec(new VoidResult() {
429
			@Override
430
			public void run() {
431
432
				// Get the figure to check the tooltip via SWTBot  
433
				SWTBotGefEditor ed = getGefEditor();
434
				SWTBotGefEditPart editPart = ed.getEditPart("");
435
				IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure();
436
				if (figure.getToolTip() != null) {
437
					fail("Tooltip must be null, but was '" + ((Label) figure.getToolTip()).getText() + "'");
438
				}
439
			}
440
441
		});
442
443
		shutdownEditor(diagramEditor);
444
	}
445
446
	@Test
262
	public void testUndoRedo() throws Exception {
447
	public void testUndoRedo() throws Exception {
263
		final DiagramEditor diagramEditor = openDiagram(ITestConstants.DIAGRAM_TYPE_ID_ECORE);
448
		final DiagramEditor diagramEditor = openDiagram(ITestConstants.DIAGRAM_TYPE_ID_ECORE);
264
449
(-)src/org/eclipse/graphiti/bot/tests/util/ITestConstants.java (-2 / +10 lines)
Lines 1-7 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
4
 * Copyright (c) 2005, 2011 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *    SAP AG - initial API, implementation and documentation
11
 *    SAP AG - initial API, implementation and documentation
12
 *    mwenz - Bug 348662 - Setting tooptip to null in tool behavior provider doesn't clear up
13
 *                         tooltip if the associated figure has a previous tooltip
12
 *
14
 *
13
 * </copyright>
15
 * </copyright>
14
 *
16
 *
Lines 24-33 Link Here
24
	 */
26
	 */
25
	public static final String DIAGRAM_TYPE_ID_SKETCH = "testtool.sketch";
27
	public static final String DIAGRAM_TYPE_ID_SKETCH = "testtool.sketch";
26
28
27
28
	/**
29
	/**
29
	 * The Constant DIAGRAM_TYPE_ID_ECORE.
30
	 * The Constant DIAGRAM_TYPE_ID_ECORE.
30
	 */
31
	 */
31
	public static final String DIAGRAM_TYPE_ID_ECORE = "testtool.ecore";
32
	public static final String DIAGRAM_TYPE_ID_ECORE = "testtool.ecore";
32
33
34
	/**
35
	 * The Constant DIAGRAM_TYPE_ID_TUTORIAL.
36
	 * 
37
	 * @since 0.9
38
	 */
39
	public static final String DIAGRAM_TYPE_ID_TUTORIAL = "tutorial";
40
33
}
41
}
(-)src/org/eclipse/graphiti/ui/internal/parts/PictogramElementDelegate.java (-36 / +38 lines)
Lines 1-7 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
4
 * Copyright (c) 2005, 2011 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *    SAP AG - initial API, implementation and documentation
11
 *    SAP AG - initial API, implementation and documentation
12
 *    mwenz - Bug 348662 - Setting tooptip to null in tool behavior provider doesn't clear up
13
 *                         tooltip if the associated figure has a previous tooltip
12
 *
14
 *
13
 * </copyright>
15
 * </copyright>
14
 *
16
 *
Lines 593-614 Link Here
593
			// Retreat to graphiti behavior.
595
			// Retreat to graphiti behavior.
594
			selectionFigure = figure;
596
			selectionFigure = figure;
595
		}
597
		}
596
		boolean indicatedNeededUpdates = false;
598
597
		// indicate needed updates onselectionFigure (using figure would cause
599
		// Create a tooltip label
598
		// problems with invisible rectangles)
600
		Label tooltipLabel = null;
601
602
		// First check the need for an update needed tooltip
603
		Label indicateUpdateNeedeTooltipLabel = null;
599
		if (selectionFigure != null) {
604
		if (selectionFigure != null) {
600
			indicatedNeededUpdates = indicateNeededUpdates(selectionFigure, updateNeeded);
605
			// Indicate needed updates on selectionFigure (using figure would cause problems with invisible rectangles)
606
			indicateUpdateNeedeTooltipLabel = indicateNeededUpdates(selectionFigure, updateNeeded);
601
		}
607
		}
602
608
603
		// set tool tips
609
		// Use the update needed tooltip in case it exists...
604
		if (!indicatedNeededUpdates) {
610
		if (indicateUpdateNeedeTooltipLabel != null) {
605
			final String toolTip = toolBehaviorProvider.getToolTip(graphicsAlgorithm);
611
			// Use update needed tooltip in any case (tool provided tooltip would be probably invalid)
606
			//do not show empty tool tips
612
			tooltipLabel = indicateUpdateNeedeTooltipLabel;
613
		} else {
614
			// ... if not get the tool provided tooltip (for performance reasons only called in case no update needed tooltip exists)
615
			String toolTip = toolBehaviorProvider.getToolTip(graphicsAlgorithm);
607
			if (toolTip != null && !toolTip.isEmpty()) {
616
			if (toolTip != null && !toolTip.isEmpty()) {
608
				Label ttf = new Label(toolTip);
617
				// null or empty string means no tooltip wanted
609
				figure.setToolTip(ttf);
618
				tooltipLabel = new Label(toolTip);
610
			}
619
			}
611
		}
620
		}
621
622
		// Set the tooltip in any case, especially also when it's null to clean up a previously set tooltip (see Bugzilla 348662) 
623
		figure.setToolTip(tooltipLabel);
612
	}
624
	}
613
625
614
	private void refreshFont(AbstractText text, Figure label) {
626
	private void refreshFont(AbstractText text, Figure label) {
Lines 912-945 Link Here
912
	 * @param figure
924
	 * @param figure
913
	 * @param updateNeeded
925
	 * @param updateNeeded
914
	 */
926
	 */
915
	private boolean indicateNeededUpdates(IFigure figure, IReason updateNeeded) {
927
	private Label indicateNeededUpdates(IFigure figure, IReason updateNeeded) {
916
		boolean ret = false;
928
		Label ret = null;
917
		if (figure != null && updateNeeded != null) {
929
		if (figure != null && updateNeeded != null && updateNeeded.toBoolean()) {
930
			// The figure needs an update, we indicate that with a red border and a tooltip showing the reason for the update 
931
			figure.setForegroundColor(ColorConstants.red);
918
			if (figure instanceof Shape) {
932
			if (figure instanceof Shape) {
919
				Shape draw2dShape = (Shape) figure;
933
				Shape draw2dShape = (Shape) figure;
920
				IFigure toolTip = draw2dShape.getToolTip();
934
				draw2dShape.setLineWidth(2);
921
				if (toolTip != null) {
935
				draw2dShape.setLineStyle(Graphics.LINE_DOT);
922
					draw2dShape.setToolTip(null);
923
				}
924
			}
925
936
926
			if (updateNeeded.toBoolean()) {
937
				String updateNeededText = updateNeeded.getText();
927
				figure.setForegroundColor(ColorConstants.red);
938
				if (updateNeededText != null && updateNeededText.length() > 0) {
928
				if (figure instanceof Shape) {
939
					Label toolTipFigure = new Label();
929
					Shape draw2dShape = (Shape) figure;
940
					toolTipFigure.setText(updateNeededText);
930
					draw2dShape.setLineWidth(2);
941
					org.eclipse.swt.graphics.Image image = PlatformUI.getWorkbench().getSharedImages()
931
					draw2dShape.setLineStyle(Graphics.LINE_DOT);
942
							.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
932
943
					toolTipFigure.setIcon(image);
933
					String updateNeededText = updateNeeded.getText();
944
					ret = toolTipFigure;
934
					if (updateNeededText != null && updateNeededText.length() > 0) {
935
						Label toolTipFigure = new Label();
936
						toolTipFigure.setText(updateNeededText);
937
						org.eclipse.swt.graphics.Image image = PlatformUI.getWorkbench().getSharedImages()
938
								.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
939
						toolTipFigure.setIcon(image);
940
						draw2dShape.setToolTip(toolTipFigure);
941
						ret = true;
942
					}
943
				}
945
				}
944
			}
946
			}
945
		}
947
		}

Return to bug 348662