public void clearContext() throws IOException, CoreException {
   WorkspaceSetupHelper.clearDoiModel();
   try {
     InteractionContext workspaceContext = WorkspaceSetupHelper.getContext();
     ContextCore.getContextManager().activateContext(workspaceContext.getHandleIdentifier());
     context = (CompositeInteractionContext) ContextCore.getContextManager().getActiveContext();
   } catch (Exception e) {
     fail();
   }
 }
  public void testViewRecursion() throws JavaModelException, PartInitException {
    view = (ActiveSearchView) JavaPlugin.getActivePage().showView(ActiveSearchView.ID);
    ActiveSearchView.getFromActivePerspective().setSyncExecForTesting(false);

    for (AbstractRelationProvider provider :
        ContextCorePlugin.getDefault().getRelationProviders()) {
      assertTrue(provider.isEnabled());
    }
    assertEquals(0, view.getViewer().getTree().getItemCount());

    IWorkbenchPart part =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
    IMethod m1 = type1.createMethod("void m1() {\n m1(); \n}", null, true, null);
    StructuredSelection sm1 = new StructuredSelection(m1);
    monitor.selectionChanged(part, sm1);
    IInteractionElement node =
        manager.processInteractionEvent(
            mockInterestContribution(m1.getHandleIdentifier(), scaling.getLandmark()));

    assertEquals(1, ContextCore.getContextManager().getActiveLandmarks().size());

    assertEquals(1, search(2, node).size());

    List<TreeItem> collectedItems = new ArrayList<TreeItem>();
    UiTestUtil.collectTreeItemsInView(view.getViewer().getTree().getItems(), collectedItems);

    // just make sure that the view didn't blow up.
    assertEquals(1, collectedItems.size());
    monitor.selectionChanged(part, sm1);
    manager.processInteractionEvent(
        mockInterestContribution(m1.getHandleIdentifier(), -scaling.getLandmark()));
  }
  public void testSearchAfterDeletion()
      throws JavaModelException, PartInitException, IOException, CoreException {
    view = (ActiveSearchView) JavaPlugin.getActivePage().showView(ActiveSearchView.ID);
    if (view != null) {
      assertEquals(0, view.getViewer().getTree().getItemCount());

      IWorkbenchPart part =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
      IMethod m1 = type1.createMethod("void m1() {\n m2() \n}", null, true, null);
      IMethod m2 = type1.createMethod("void m2() { }", null, true, null);
      StructuredSelection sm2 = new StructuredSelection(m2);
      monitor.selectionChanged(part, sm2);
      IInteractionElement node =
          manager.processInteractionEvent(
              mockInterestContribution(m2.getHandleIdentifier(), scaling.getLandmark()));
      assertEquals(1, ContextCore.getContextManager().getActiveLandmarks().size());

      assertEquals(1, search(2, node).size());

      m1.delete(true, null);
      assertFalse(m1.exists());

      assertEquals(0, search(2, node).size());
    }
  }
 private void addRelationProvider(String contentType, AbstractRelationProvider provider) {
   Set<AbstractRelationProvider> providers = relationProviders.get(contentType);
   if (providers == null) {
     providers = new HashSet<AbstractRelationProvider>();
     relationProviders.put(contentType, providers);
   }
   providers.add(provider);
   // TODO: need facility for removing
   ContextCore.getContextManager().addListener(provider);
 }
  public void testParentResourceMapping() throws CoreException {
    IWorkbenchPart part =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
    IMethod m1 = type1.createMethod("public void m1() { }", null, true, null);

    monitor.selectionChanged(part, new StructuredSelection(m1));
    IInteractionElement m1Node =
        ContextCore.getContextManager().getElement(m1.getHandleIdentifier());
    assertTrue(m1Node.getInterest().isInteresting());

    IResource containingResource =
        ResourcesUiBridgePlugin.getDefault().getResourceForElement(m1Node, true);
    assertEquals(m1.getCompilationUnit().getAdapter(IResource.class), containingResource);
  }
 private boolean isInterestingReferenceParticipant(IReferenceNode object) {
   if (object != null) {
     if (object.getReferenceParticipant() != null) {
       Object element = object.getReferenceParticipant();
       if (element instanceof IAspectDefinition) {
         IAspectDefinition def = (IAspectDefinition) element;
         element =
             BeansModelUtils.getMostSpecificModelElement(
                 def.getAspectStartLineNumber(),
                 def.getAspectEndLineNumber(),
                 (IFile) def.getResource(),
                 null);
       }
       AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(element);
       if (bridge != null) {
         String handle = bridge.getHandleIdentifier(element);
         IInteractionElement interestElement = ContextCore.getContextManager().getElement(handle);
         if (element != null && isInteresting(interestElement)) {
           return true;
         }
         // TODO CD uncomment this if *really* only interested
         // elements
         // should be displayed
         /*
          * else { return false; }
          */
       }
     }
     if (object.getChildren() != null && object.getChildren().length > 0) {
       for (Object child : object.getChildren()) {
         if (child instanceof IReferenceNode) {
           if (isInterestingReferenceParticipant((IReferenceNode) child)) {
             return true;
           }
         }
       }
     }
   }
   return false;
 }
  public void testSelection() throws Exception {

    structureModelBridge = new EcoreGmfDomainBridge();

    activeContext = ContextCore.getContextManager().getActiveContext();
    assertNotNull(activeContext);

    monitor = new DiagramUiEditingMonitor(structureModelBridge, EcoreDiagramUiBridge.getInstance());
    MonitorUi.getSelectionMonitors().add(monitor);

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }

    IFile file = getEmfProject().getProject().getFile("model/library.ecorediag");
    assertNotNull(file);

    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
    }

    StructuredSelection selection = new StructuredSelection(file);

    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    ProjectExplorer pe =
        (ProjectExplorer) page.showView("org.eclipse.ui.navigator.ProjectExplorer");
    pe.getCommonViewer().setSelection(selection);
    monitor.handleWorkbenchPartSelection(pe, selection, true);

    //		assertNotNull(activeContext);
    //		assertEquals(activeContext.getAllElements().size(), 1);
    //		//should this be resource type?
    //		assertEquals(activeContext.getAllElements().get(0).getContentType(), "ecore");
    //		assertEquals(activeContext.getAllElements().get(0).getHandleIdentifier(),
    //				"/org.eclipse.mylyn.modeling.tests.ecorediagram/model/library.ecore");
    //		assertTrue(activeContext.getAllElements().get(0).getInterest().isInteresting());
  }
 public static void clearDoiModel() throws CoreException {
   ContextCore.getContextManager().deleteContext(HELPER_CONTEXT_ID);
   taskscape = new InteractionContext(HELPER_CONTEXT_ID, new InteractionContextScaling());
 }
 private static void helper(String rand) {
   ContextCore.getContextManager().activateContext(rand);
   ContextCore.getContextManager().deactivateContext(rand);
   ContextCore.getContextManager().deleteContext(rand);
 }