Exemplo n.º 1
0
 /** Navigate to the linked element. Open it in model editor and print its properties. */
 protected void navigateToElement() {
   IMultiDiagramEditor editor = EditorUtils.getMultiDiagramEditor();
   IViewReference[] views = editor.getSite().getPage().getViewReferences();
   for (IViewReference view : views) {
     IWorkbenchPart part = view.getPart(false);
     if (part instanceof CommonNavigator) {
       CommonNavigator navigator = (CommonNavigator) part;
       // set focus to navigator, otherwise, diagram view will reset the selection
       navigator.setFocus();
       navigator.selectReveal(new StructuredSelection(element));
     }
   }
 }
  @Test
  public void testCreationAndDestructionOnRequirement() {
    Object result =
        ModelExplorerUtils.executeCreateNestedEditorHandlerInModelExplorer(
            papyrusEditor,
            TableCreationInSysMLModelTest.view,
            AllTests.COMMAND_ID,
            TableCreationInSysMLModelTest.requirement1,
            BUNDLE_ID);
    // to refresh the table content
    DisplayUtils.flushEventLoop();
    Assert.assertTrue(result instanceof NatTableEditor);
    NatTableEditor editor = (NatTableEditor) result;
    NattableModelManager manager =
        (NattableModelManager) editor.getAdapter(INattableModelManager.class);
    Assert.assertNotNull(manager);
    Table table = manager.getTable();
    Assert.assertEquals(AllTests.REQUIREMENT_TABLE_ID, table.getTableConfiguration().getType());

    IAxisManager rowAxisManager = manager.getRowAxisManager();
    Collection<Object> managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(2, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));

    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));

    final TransactionalEditingDomain domain =
        (TransactionalEditingDomain) papyrusEditor.getAdapter(TransactionalEditingDomain.class);
    Assert.assertNotNull(domain);
    IElementEditService provider =
        ElementEditServiceUtils.getCommandProvider(TableCreationInSysMLModelTest.requirement1);
    Assert.assertNotNull(provider);
    CreateElementRequest request =
        new CreateElementRequest(
            domain, TableCreationInSysMLModelTest.requirement1, SysMLElementTypes.REQUIREMENT);
    final ICommand creationCommand = provider.getEditCommand(request);
    Assert.assertNotNull(creationCommand);
    Assert.assertTrue(creationCommand.canExecute());

    domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(creationCommand));
    final NamedElement createdElement = (NamedElement) request.getNewElement();
    NamedElement requirement =
        TableCreationInSysMLModelTest.requirement1.getMember(
            createdElement.getName()); // $NON-NLS-1$
    Assert.assertNotNull(requirement);
    nestedRequirement3 = (Class) requirement;

    // to refresh the table content
    DisplayUtils.flushEventLoop();
    managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(3, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));
    Assert.assertTrue(managedAxis.contains(nestedRequirement3));
    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement3));

    DestroyElementRequest destroyRequest =
        new DestroyElementRequest(domain, nestedRequirement3, false);
    provider = ElementEditServiceUtils.getCommandProvider(nestedRequirement3);
    final ICommand destroyCommand = provider.getEditCommand(destroyRequest);
    Assert.assertNotNull(destroyCommand);
    Assert.assertTrue(destroyCommand.canExecute());

    domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(destroyCommand));
    requirement =
        TableCreationInSysMLModelTest.requirement1.getMember(
            createdElement.getName()); // $NON-NLS-1$
    Assert.assertNull(requirement);
    nestedRequirement3 = (Class) requirement;

    // to refresh the table content
    DisplayUtils.flushEventLoop();

    managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(2, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));

    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));
  }