|
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 |
|