Beispiel #1
0
  public void testPropertyChange() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);
    MyEval listener = new MyEval();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement element = null;
    IConfigurationElement[] elements =
        registry.getConfigurationElementsFor("org.eclipse.core.expressions.definitions");
    for (int i = 0; i < elements.length && element == null; i++) {
      if (elements[i].getAttribute("id").equals("org.eclipse.ui.tests.defWithPropertyTester")) {
        element = elements[i];
      }
    }

    assertNotNull(element);
    Expression expr = ExpressionConverter.getDefault().perform(element.getChildren()[0]);
    service.addEvaluationListener(expr, listener, IEvaluationService.RESULT);
    assertFalse(listener.currentValue);
    assertEquals(1, listener.count);

    StaticVarPropertyTester.result = true;
    assertFalse(listener.currentValue);
    assertEquals(1, listener.count);

    service.requestEvaluation("org.eclipse.ui.tests.class.method");
    assertTrue(listener.currentValue);
    assertEquals(2, listener.count);

    service.requestEvaluation("org.eclipse.ui.tests.class.method");
    assertTrue(listener.currentValue);
    assertEquals(2, listener.count);
  }
Beispiel #2
0
  public void testSourceProvider() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);

    MyEval listener = new MyEval();
    UserExpression expression = new UserExpression("Paul");
    IEvaluationReference ref =
        service.addEvaluationListener(expression, listener, IEvaluationService.RESULT);
    assertEquals(ISources.ACTIVE_CONTEXT << 1, ref.getSourcePriority());
    assertFalse(listener.currentValue);
    assertEquals(1, listener.count);

    ISourceProviderService sps =
        (ISourceProviderService) window.getService(ISourceProviderService.class);
    ActiveUserSourceProvider userProvider =
        (ActiveUserSourceProvider) sps.getSourceProvider("username");

    userProvider.setUsername("John");
    assertFalse(listener.currentValue);
    assertEquals(1, listener.count);

    userProvider.setUsername("Paul");
    assertTrue(listener.currentValue);
    assertEquals(2, listener.count);

    userProvider.setUsername("guest");
    assertFalse(listener.currentValue);
    assertEquals(3, listener.count);
  }
Beispiel #3
0
  public void testTwoEvaluations() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);

    MyEval listener1 = new MyEval();
    MyEval listener2 = new MyEval();
    IContextActivation context1 = null;
    IEvaluationReference evalRef1 = null;
    IEvaluationReference evalRef2 = null;
    IContextService contextService = null;
    try {
      evalRef1 =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener1,
              IEvaluationService.RESULT);
      assertEquals(1, listener1.count);
      assertFalse(listener1.currentValue);

      evalRef2 =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener2,
              IEvaluationService.RESULT);
      assertEquals(1, listener2.count);
      assertFalse(listener2.currentValue);
      evalRef2.setResult(true);

      contextService = (IContextService) window.getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener1.count);
      assertTrue(listener1.currentValue);
      // we already set this guy to true, he should skip
      assertEquals(1, listener2.count);
      assertFalse(listener2.currentValue);

      evalRef1.setResult(false);
      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(2, listener2.count);
      assertFalse(listener2.currentValue);

      // we already set this guy to false, so he should be the old
      // values
      assertEquals(2, listener1.count);
      assertTrue(listener1.currentValue);

    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
      if (evalRef1 != null) {
        service.removeEvaluationListener(evalRef1);
      }
      if (evalRef2 != null) {
        service.removeEvaluationListener(evalRef2);
      }
    }
  }
 protected void requestRefresh() {
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   IEvaluationService evaluationService =
       (IEvaluationService) window.getService(IEvaluationService.class);
   if (evaluationService != null) {
     evaluationService.requestEvaluation("eu.fittest.eclipse.transformtools.members_extension");
   }
 }
 public static IResource getSelectedResource() {
   IEvaluationService evaluationService =
       (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
   if (evaluationService != null) {
     return getSelectedResource(evaluationService.getCurrentState());
   }
   return null;
 }
Beispiel #6
0
 /**
  * 刷新 Command 的可用状态
  *
  * @param nameSpace
  * @param properties ;
  */
 public static void refreshCommand(String nameSpace, String properties) {
   if (nameSpace != null && properties != null) {
     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     IEvaluationService evaluationService =
         (IEvaluationService) window.getService(IEvaluationService.class);
     if (evaluationService != null) {
       evaluationService.requestEvaluation(nameSpace + "." + properties);
     }
   }
 }
 private static IStructuredSelection getActiveSelection() {
   IStructuredSelection selection = null;
   IEvaluationService evaluationService =
       (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
   if (evaluationService != null) {
     IEvaluationContext currentState = evaluationService.getCurrentState();
     Object variable = currentState.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
     if (variable instanceof IStructuredSelection) {
       selection = (IStructuredSelection) variable;
     }
   }
   return (selection == null) ? StructuredSelection.EMPTY : selection;
 }
Beispiel #8
0
 public void XtestSystemProperty() throws Exception {
   // this is not added, as the ability to test system properties with
   // no '.' seems unhelpful
   System.setProperty("isHere", "true");
   IEvaluationService evaluationService =
       (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
   TestExpression test =
       new TestExpression(
           "org.eclipse.core.runtime", "isHere", new Object[] {"true"}, null, false);
   WithExpression exp = new WithExpression("java.lang.System");
   exp.add(test);
   EvaluationResult result = exp.evaluate(evaluationService.getCurrentState());
   assertEquals(EvaluationResult.TRUE, result);
 }
Beispiel #9
0
 public void testPlatformProperty() throws Exception {
   IEvaluationService evaluationService =
       (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
   TestExpression test =
       new TestExpression(
           "org.eclipse.core.runtime",
           "bundleState",
           new Object[] {"org.eclipse.core.expressions"},
           "ACTIVE",
           false);
   WithExpression exp = new WithExpression("org.eclipse.core.runtime.Platform");
   exp.add(test);
   EvaluationResult result = exp.evaluate(evaluationService.getCurrentState());
   assertEquals(EvaluationResult.TRUE, result);
 }
Beispiel #10
0
  public void testBasicService() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);

    MyEval listener = new MyEval();
    IContextActivation context1 = null;
    IEvaluationReference evalRef = null;
    IContextService contextService = null;
    try {
      evalRef =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener,
              IEvaluationService.RESULT);
      assertEquals(1, listener.count);
      assertFalse(listener.currentValue);

      contextService = (IContextService) window.getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener.count);
      assertTrue(listener.currentValue);

      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(3, listener.count);
      assertFalse(listener.currentValue);

      service.removeEvaluationListener(evalRef);
      evalRef = null;
      assertEquals(4, listener.count);

      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(4, listener.count);
      assertFalse(listener.currentValue);
      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(4, listener.count);
      assertFalse(listener.currentValue);
    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
      if (evalRef != null) {
        service.removeEvaluationListener(evalRef);
      }
    }
  }
  @Override
  public boolean performOk() {
    if (this.enableAutoCheckin.getBooleanValue()) {
      if (isEmpty(this.currentValueOfRepoName) /*|| isEmpty(this.currentValueOfRepoBaseLocation)*/
          || isEmpty(this.currentValueOfUserName)
          || isEmpty(this.currentValueOfPassWord)) {
        MessageDialog.openWarning(
            getShell(),
            "Warning",
            "Please enter value to Repository Name,UserName and Password fields.");
        return false;
      }
      /*final String prj = this.preferenceStore.getString(P_REPOSITORY_PROJECT);
      if (isEmpty(prj)) {
      	if (!resetProjectName()) {
      		return false;
      	}
      } else {
      	if (!this.preferenceStore.getString(P_REPOSITORY_URL).equals(this.currentValueOfRepoUrl)) {
      		if (!resetProjectName()) {
      			return false;
      		}
      	}
      }*/
    }

    final boolean status = super.performOk();
    final IEvaluationService service =
        (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
    service.requestEvaluation("org.fastcode.menus.versioncontrol");
    if (status) {
      /*MessageDialog.openInformation(new Shell(), "Information",
      "The SVN url is specific to the project. While working with other project(s), please change the URL.");*/
      VersionControlPreferences.setReload(status);
    } else {
      return status;
    }
    return status;
  }
Beispiel #12
0
  public void testScopedService() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);
    assertTrue(service instanceof SlaveEvaluationService);

    MyEval listener = new MyEval();
    IContextActivation context1 = null;
    IContextService contextService = null;
    try {
      service.addEvaluationListener(
          new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
          listener,
          IEvaluationService.RESULT);
      assertEquals(1, listener.count);
      assertFalse(listener.currentValue);

      contextService = (IContextService) window.getWorkbench().getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener.count);
      assertTrue(listener.currentValue);

      window.close();
      processEvents();
      assertEquals(3, listener.count);
      assertTrue(listener.currentValue);

      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(3, listener.count);
      assertTrue(listener.currentValue);
    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
    }
  }
Beispiel #13
0
  public void testRestriction() {
    boolean temporarilyDisabled = true;
    if (temporarilyDisabled) return;

    IWorkbenchWindow window = openTestWindow();
    IEvaluationService evaluationService =
        (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(evaluationService);
    IContextService contextService = (IContextService) window.getService(IContextService.class);
    assertNotNull(contextService);

    Expression expression =
        new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME});

    final boolean[] propertyChanged = new boolean[1];
    final boolean[] propertyShouldChange = new boolean[1];

    IPropertyChangeListener propertyChangeListener =
        new IPropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals("foo")) propertyChanged[0] = true;
          }
        };
    IEvaluationReference ref =
        evaluationService.addEvaluationListener(expression, propertyChangeListener, "foo");
    ((WorkbenchWindow) window).getMenuRestrictions().add(ref);

    IPropertyChangeListener propertyShouldChangeListener =
        new IPropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals("foo")) propertyShouldChange[0] = true;
          }
        };
    evaluationService.addEvaluationListener(expression, propertyShouldChangeListener, "foo");

    propertyChanged[0] = false;
    propertyShouldChange[0] = false;

    assertFalse(contextService.getActiveContextIds().contains(CONTEXT_ID1));
    IContextActivation activation = contextService.activateContext(CONTEXT_ID1);

    assertTrue(propertyChanged[0]);
    assertTrue(propertyShouldChange[0]);
    propertyChanged[0] = false;
    propertyShouldChange[0] = false;

    contextService.deactivateContext(activation);
    assertTrue(propertyChanged[0]);
    assertTrue(propertyShouldChange[0]);
    assertFalse(contextService.getActiveContextIds().contains(CONTEXT_ID1));
    activation = contextService.activateContext(CONTEXT_ID1);
    propertyChanged[0] = false;
    propertyShouldChange[0] = false;
    assertTrue(contextService.getActiveContextIds().contains(CONTEXT_ID1));

    // open second window
    IWorkbenchWindow window2 = openTestWindow();
    assertFalse(propertyChanged[0]);
    assertTrue(propertyShouldChange[0]);
    assertFalse(contextService.getActiveContextIds().contains(CONTEXT_ID1));
    propertyChanged[0] = false;
    propertyShouldChange[0] = false;

    window2.close();
    processEvents();

    assertTrue(contextService.getActiveContextIds().contains(CONTEXT_ID1));
    assertFalse(propertyChanged[0]);
    assertTrue(propertyShouldChange[0]);
  }