@Test
  public void testLinkWithSelectionNavigator() throws Exception {
    deleteAllProjects();
    shareProjects(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    myRepoViewUtil.getRootItem(tree, repositoryFile).select();
    // the selection should be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
    getProjectItem(projectExplorerTree, PROJ1).select();

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // activate the link with selection
    toggleLinkWithSelection();

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // select again the project
    projectExplorerTree = TestUtil.getExplorerTree();
    getProjectItem(projectExplorerTree, PROJ1).select();

    // the selection should be project
    assertTrue(tree.selection().get(0, 0).equals(PROJ1));

    // deactivate the link with selection
    toggleLinkWithSelection();
  }
  /**
   * Link with editor, both ways
   *
   * @throws Exception
   */
  @Test
  @Ignore("'Link with Selection' does not activate editor on selection change (bug 409722).")
  public void testLinkWithSelectionEditor() throws Exception {
    deleteAllProjects();
    shareProjects(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    myRepoViewUtil.getRootItem(tree, repositoryFile).select();
    // the selection should be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    SWTBotView view = TestUtil.showExplorerView();
    SWTBotTree projectExplorerTree = view.bot().tree();

    SWTBotTreeItem item =
        getProjectItem(projectExplorerTree, PROJ1).expand().getNode(FOLDER).expand().getNode(FILE1);
    view.show();
    item.doubleClick();

    item =
        getProjectItem(projectExplorerTree, PROJ1).expand().getNode(FOLDER).expand().getNode(FILE2);
    view.show();
    item.doubleClick();
    // now we should have two editors

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // activate the link with selection
    toggleLinkWithSelection();

    bot.editorByTitle(FILE2).show();
    // the selection should have changed to the latest editor
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE2, 10000);

    bot.editorByTitle(FILE1).show();
    // selection should have changed
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);

    // deactivate the link with editor
    toggleLinkWithSelection();

    bot.editorByTitle(FILE2).show();
    // the selection should be still be test.txt
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);

    bot.editorByTitle(FILE1).show();

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();

    // the editor should still be test.txt
    assertEquals(FILE1, bot.activeEditor().getTitle());

    // activate again
    toggleLinkWithSelection();

    // make sure focus is here
    // tried to remove this waitInUI but failed.
    // tried setting focus, waiting for focus, joining RepositoriesView
    // refresh job
    waitInUI();
    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE2), 10000);

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE1)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);

    // deactivate the link with editor
    toggleLinkWithSelection();

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);
  }
  @Test
  public void testDeleteDiagrams() {

    final DiagramRepositoryStore diagramStore =
        RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);

    final int nbDiagramsInRepository = diagramStore.getChildren().size();

    final SWTBotMenu diagramMenu = bot.menu("Diagram");
    final List<String> newDiagramsName = new ArrayList<String>();
    for (int i = 0; i < nbDiagrams; i++) {
      SWTBotTestUtil.createNewDiagram(bot);
      bot.waitUntil(Conditions.widgetIsEnabled(diagramMenu), 40000);
      newDiagramsName.add(bot.activeEditor().getTitle());
    }
    assertEquals("4 diagrams should have been created", nbDiagrams, newDiagramsName.size());

    final int nbEditors = bot.editors().size();
    final String currentDiagramName = bot.activeEditor().getTitle();
    bot.waitUntil(Conditions.widgetIsEnabled(bot.menu("Diagram")), 10000);
    bot.menu("Diagram").menu("Delete...").click();
    bot.waitUntil(Conditions.shellIsActive(Messages.DeleteDiagramWizardPage_title), 10000);

    final SWTBotTree tree = bot.tree();
    assertEquals(
        "the list of diagrams should contain 4 items",
        nbDiagramsInRepository + nbDiagrams,
        tree.getAllItems().length);

    final TableCollection selection = tree.selection();
    assertEquals(
        "only " + currentDiagramName + " should be selected in the tree viewer",
        1,
        selection.rowCount());
    assertEquals(
        "diagram " + currentDiagramName + " should be selected",
        currentDiagramName,
        selection.get(0, 0));

    //   final SWTBotTreeItem firstSwtBotTreeItem = tree.getAllItems()[1];
    //   final SWTBotTreeItem secondSwtBotTreeItem = tree.getAllItems()[2];
    //   final SWTBotTreeItem thirdSwtBotTreeItem = tree.getAllItems()[3];

    tree.select(newDiagramsName.get(1), newDiagramsName.get(2), newDiagramsName.get(3));

    bot.button(Messages.removeProcessLabel).click();

    bot.waitUntil(Conditions.shellIsActive(Messages.confirmProcessDeleteTitle));
    bot.button(IDialogConstants.YES_LABEL).click();
    bot.waitUntil(
        new ICondition() {

          @Override
          public boolean test() throws Exception {
            return nbEditors - 3 == bot.editors().size();
          }

          @Override
          public void init(final SWTBot bot) {}

          @Override
          public String getFailureMessage() {
            return "editors have not been closed after deleted diagrams";
          }
        },
        40000,
        100);

    assertEquals(
        "deleted diagrams are still in repository",
        nbDiagramsInRepository + 1,
        diagramStore.getChildren().size());
  }