/** * Performs a <code>DropObjectsRequest</code> in a modal context thread. Verifies that the diagram * refreshes on the UI thread. * * @throws Exception if an unexpected exception occurs */ public void test_drop_modalContextThread() throws Exception { // Open the test fixture diagram getTestFixture().openDiagram(); final DiagramEditPart diagramEditPart = getDiagramEditPart(); // Create an AND gate in the semantic model ICommand andCommand = new AbstractTransactionalCommand( getTestFixture().getEditingDomain(), "Create AND Gate", null) { // $NON-NLS-1$ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { AndGate newElement = (AndGate) SemanticPackage.eINSTANCE .getEFactoryInstance() .create(SemanticPackage.eINSTANCE.getAndGate()); ContainerElement semanticElement = (ContainerElement) diagramEditPart.resolveSemanticElement(); semanticElement.getChildren().add(newElement); return CommandResult.newOKCommandResult(newElement); } }; andCommand.execute(new NullProgressMonitor(), null); AndGate andGate = (AndGate) andCommand.getCommandResult().getReturnValue(); // Get the initial number of edit parts on the diagram List primaryEditParts = diagramEditPart.getPrimaryEditParts(); int initialEditPartCount = primaryEditParts.size(); // Get the command to drop the AND gate onto the diagram Point dropLocation = ICanonicalShapeCompartmentLayout.UNDEFINED.getLocation(); DropObjectsRequest request = new DropObjectsRequest(); request.setObjects(Collections.singletonList(andGate)); request.setAllowedDetail(DND.DROP_COPY); request.setLocation(dropLocation); Command command = diagramEditPart.getCommand(request); final CommandProxy proxy = new CommandProxy(command); // Execute the command in a forking progress monitor dialog IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { OperationHistoryFactory.getOperationHistory().execute(proxy, monitor, null); } catch (ExecutionException e) { throw new InvocationTargetException(e); } } }; new ProgressMonitorDialog(null).run(true, true, runnable); // Verify that a new edit part has been added to the diagram for the AND gate primaryEditParts = getDiagramEditPart().getPrimaryEditParts(); assertTrue( "Size of primary edit parts should have increased.", primaryEditParts.size() > initialEditPartCount); // $NON-NLS-1$ IGraphicalEditPart andGateEditPart = null; for (Iterator i = primaryEditParts.iterator(); i.hasNext(); ) { IGraphicalEditPart nextEditPart = (IGraphicalEditPart) i.next(); if (andGate.equals(nextEditPart.resolveSemanticElement())) { andGateEditPart = nextEditPart; break; } } assertNotNull("Expected a new edit part for the AND gate", andGateEditPart); // $NON-NLS-1$ }