Java Code Examples for org.openide.util.ContextAwareAction#getValue()

The following examples show how to use org.openide.util.ContextAwareAction#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static ContextAwareAction context(Map map, boolean instanceReady) {
    Class<?> dataType = readClass(map.get("type")); // NOI18N
    ContextAwareAction ca = _context(map, dataType, Utilities.actionsGlobalContext(), instanceReady);
    // autodetect on/off actions
    if (ca.getValue(Action.SELECTED_KEY) != null) {
        return new StateDelegateAction(map, ca);
    } else {
        return new DelegateAction(map, ca);
    }
}
 
Example 2
Source File: ContextActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testMergeFiresAppropriateChanges() throws Exception {
    System.out.println("testMergeFiresAppropriateChanges");
    E looksInProject = new E();

    IndirectAction overProjectsLookup =
            new IndirectAction(FakeProject.class, looksInProject, true);

    E looksInGlobalSelection = new E();

    looksInGlobalSelection.putValue(Action.NAME, "Global");
    looksInProject.putValue(Action.NAME, "DataObject");

    ContextAwareAction merge = ContextAction.merge(looksInGlobalSelection, overProjectsLookup);

    PCL pcl = new PCL();
    merge.addPropertyChangeListener(pcl);

    looksInGlobalSelection.putValue("whatzit", "foo");
    looksInProject.putValue("whatzit", "bar");

    //We need to request it from merge at least once for it
    //to know about the key and fire changes
    assertEquals("foo", merge.getValue("whatzit"));

    Thing thing = new Thing("thing");
    FakeProject project = new FakeProject(thing);

    assertFalse(merge.isEnabled());
    assertFalse(looksInGlobalSelection.isEnabled());
    assertFalse(looksInProject.isEnabled());

    setContent(project);
    assertTrue(merge.isEnabled());
    assertFalse(looksInGlobalSelection.isEnabled());
    assertTrue(overProjectsLookup.isEnabled());
    synchronized (merge) {
        merge.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }

    pcl.assertEnabledChangedTo(true);
    assertTrue(overProjectsLookup.isEnabled());
    Object val = merge.getValue("whatzit");
    assertEquals("bar", val);
    assertEquals("Merge should not proxy value from disabled action when it " +
            "is not disabled itself, but " +
            "got " + val, "bar", val);

    setContent(thing);
    assertTrue(looksInGlobalSelection.isEnabled());
    assertTrue(merge.isEnabled());
    assertFalse(overProjectsLookup.isEnabled());
    assertEquals("Global", merge.getValue(Action.NAME));
    assertEquals("foo", merge.getValue("whatzit"));
    synchronized (merge) {
        merge.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    assertEquals("foo", pcl.assertFired("whatzit"));

    clearContent();
    synchronized (merge) {
        merge.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }

    setContent(project);
    synchronized (merge) {
        merge.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    pcl.assertFired("whatzit");
    assertTrue(merge.isEnabled());

    setContent(thing);
    assertTrue(merge.isEnabled());
    synchronized (merge) {
        merge.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }

    assertEquals("Global", pcl.assertFired(Action.NAME));
    assertEquals("foo", pcl.assertFired("whatzit"));
}