/** {@inheritedDoc}. */ @Override public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { TypeDropHelper helper = new TypeDropHelper(getEditingDomain()); // Single drop management possible drop action list can be proposed if (dropRequest.getObjects().size() == 1) { // List of available drop commands final List<Command> commandChoice = new ArrayList<Command>(); // 1. Try to set the target element type with dropped object Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost()); if ((dropAsSetType != null) && (dropAsSetType.canExecute())) { commandChoice.add(dropAsSetType); } // 3. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { commandChoice.add(defaultDropCommand); } // Prepare the selection command (if several command are available) or return the drop command if (commandChoice.size() > 1) { RunnableWithResult<ICommand> runnable; Display.getDefault() .syncExec( runnable = new RunnableWithResult.Impl<ICommand>() { public void run() { setResult( new SelectAndExecuteCommand( "Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); } }); ICommand selectCommand = runnable.getResult(); return new ICommandProxy(selectCommand); } else if (commandChoice.size() == 1) { return commandChoice.get(0); } // else (command choice is empty) return UnexecutableCommand.INSTANCE; } return super.getDropObjectsCommand(dropRequest); }
/** This method tests if the active part is the model explorer */ protected void testIsModelExplorerActivePart() { RunnableWithResult<IWorkbenchPart> activePartRunnable; Display.getDefault() .syncExec( activePartRunnable = new RunnableWithResult.Impl<IWorkbenchPart>() { public void run() { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart activePart = activePage.getActivePart(); setResult(activePart); } }); Assert.assertTrue( "The active part is not the ModelExplorer", activePartRunnable.getResult() instanceof ModelExplorerPageBookView); // $NON-NLS-1$ }
@Before public void initTests() throws CoreException, IOException, ServiceException { // we open the editor editor = (CoreMultiDiagramEditor) editorFixture.open(); RunnableWithResult<?> runnable; Display.getDefault() .syncExec( runnable = new RunnableWithResult.Impl<Object>() { public void run() { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); modelExplorerView = editorFixture.getModelExplorerView(); modelExplorerView.setFocus(); // we look for the common viewer commonViewer = modelExplorerView.getCommonViewer(); // we look for the selection service selectionService = activeWorkbenchWindow.getSelectionService(); // we look for the testedCommand ICommandService commandService = activeWorkbenchWindow.getService(ICommandService.class); if (commandId != null) { testedCommand = commandService.getCommand(commandId); } commonViewer.expandToLevel(2); List<Customization> appliedCustomizations = org.eclipse.papyrus.views.modelexplorer.Activator.getDefault() .getCustomizationManager() .getManagedCustomizations(); Customization facetSimpleUML = null; Customization facetPapyrusTable = null; Iterator<?> iter = appliedCustomizations.iterator(); while (iter.hasNext()) { Customization custo = (Customization) iter.next(); if (custo.getName().equals("SimpleUML")) { facetSimpleUML = custo; } else if (custo.getName().equals("PapyrusTable")) { facetPapyrusTable = custo; } } Assert.assertNotNull( "Custom SimpleUML not found", facetSimpleUML); // $NON-NLS-1$ Assert.assertNotNull( "Custom PapyrusTable not found", facetPapyrusTable); // $NON-NLS-1$ org.eclipse.papyrus.views.modelexplorer.Activator.getDefault() .getCustomizationManager() .getManagedCustomizations() .add(0, facetPapyrusTable); org.eclipse.papyrus.views.modelexplorer.Activator.getDefault() .getCustomizationManager() .getManagedCustomizations() .add(0, facetSimpleUML); ; setStatus(Status.OK_STATUS); } }); Assert.assertEquals( runnable.getStatus().getMessage(), IStatus.OK, runnable.getStatus().getSeverity()); diagrams = getDiagrams(); }
public static void initTests( final Bundle bundle, final String projectName, final String papyrusModelPath) throws CoreException, IOException, BundleException { ProjectUtils.removeAllProjectFromTheWorkspace(); IProject testProject = ProjectUtils.createProject(projectName); final IFile file = PapyrusProjectUtils.copyPapyrusModel(testProject, bundle, SOURCE_PATH, FILE_ROOT_NAME); RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() { @Override public void run() { try { papyrusEditor = EditorUtils.openPapyrusEditor(file); } catch (PartInitException e) { setStatus(new Status(IStatus.ERROR, bundle.getSymbolicName(), e.getMessage())); } try { TableCreationInSysMLModelTest.view = ModelExplorerUtils.openModelExplorerView(); } catch (PartInitException e) { setStatus(new Status(IStatus.ERROR, bundle.getSymbolicName(), e.getMessage())); } EObject root = ModelExplorerUtils.getRootInModelExplorer(TableCreationInSysMLModelTest.view); TableCreationInSysMLModelTest.rootModel = (Model) root; class_ = (Class) TableCreationInSysMLModelTest.rootModel.getMember("Class1"); // $NON-NLS-1$ requirement1 = (Class) TableCreationInSysMLModelTest.rootModel.getMember( "Requirement1"); //$NON-NLS-1$ requirement2 = (Class) TableCreationInSysMLModelTest.rootModel.getMember( "Requirement2"); //$NON-NLS-1$ if (requirement1 != null) { nestedRequirement1 = (Class) requirement1.getMember("NestedRequirement1"); // $NON-NLS-1$ nestedRequirement2 = (Class) requirement1.getMember("NestedRequirement2"); // $NON-NLS-1$ setStatus(Status.OK_STATUS); } else { setStatus( new Status( IStatus.ERROR, bundle.getSymbolicName(), "Requirement1 not found")); //$NON-NLS-1$ } } }; Display.getDefault().syncExec(runnableWithResult); Assert.assertEquals( runnableWithResult.getStatus().getMessage(), IStatus.OK, runnableWithResult.getStatus().getSeverity()); Assert.assertNotNull(class_); Assert.assertNotNull(requirement1); Assert.assertNotNull(requirement2); Assert.assertNotNull(TableCreationInSysMLModelTest.rootModel); }