本文整理汇总了Java中org.openide.util.ContextAwareAction类的典型用法代码示例。如果您正苦于以下问题:Java ContextAwareAction类的具体用法?Java ContextAwareAction怎么用?Java ContextAwareAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextAwareAction类属于org.openide.util包,在下文中一共展示了ContextAwareAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
private static void close(final Project prj) {
Mutex.EVENT.readAccess(new Mutex.Action<Object>() {
public Object run() {
LifecycleManager.getDefault().saveAll();
Action closeAction = CommonProjectActions.closeProjectAction();
closeAction = closeAction instanceof ContextAwareAction ? ((ContextAwareAction) closeAction).createContextAwareInstance(Lookups.fixed(new Object[] {prj})) : null;
if (closeAction != null && closeAction.isEnabled()) {
closeAction.actionPerformed(new ActionEvent(prj, -1, "")); // NOI18N
} else {
//fallback:
OpenProjects.getDefault().close(new Project[] {prj});
}
return null;
}
});
}
示例2: testOperationActions
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testOperationActions() throws Exception { // #72397
final NbModuleProject project = generateStandaloneModule("module");
cgpi.setProject(project);
DialogDisplayerImpl dd = (DialogDisplayerImpl) Lookup.getDefault().lookup(DialogDisplayer.class);
FileObject lock = FileUtil.createData(project.getProjectDirectory(), "build/testuserdir/lock");
RandomAccessFile raf = new RandomAccessFile(FileUtil.toFile(lock), "rw");
FileLock lck = raf.getChannel().lock();
EventQueue.invokeAndWait(new Runnable() {
@Override public void run() {
((ContextAwareAction) CommonProjectActions.deleteProjectAction()).createContextAwareInstance(Lookups.singleton(project)).actionPerformed(null);
}
});
assertNotNull("warning message emitted", dd.getLastNotifyDescriptor());
assertEquals("warning message emitted", dd.getLastNotifyDescriptor().getMessage(),
Bundle.ERR_ModuleIsBeingRun());
dd.reset();
lck.release();
raf.close();
lock.delete();
EventQueue.invokeAndWait(new Runnable() {
@Override public void run() {
CommonProjectActions.deleteProjectAction().actionPerformed(null);
}
});
assertNull("no warning message", dd.getLastNotifyDescriptor());
}
示例3: assertAction
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
private void assertAction(String text, Action action, boolean b, Node n) throws Exception {
final Action clone = action instanceof ContextAwareAction ?
((ContextAwareAction)action).createContextAwareInstance(n.getLookup()) :
action;
assertTrue("Expecting " + text + " but was " + action, action.getClass().getName().contains(text));
class Is implements Runnable {
boolean is;
public void run() {
is = clone.isEnabled();
}
}
Is enabled = new Is();
SwingUtilities.invokeAndWait(enabled);
assertEquals("Enabled? " + text + " and: " + b, b, enabled.is);
}
示例4: customPopupActions
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
@ActionID(id = "org.netbeans.modules.maven.customPopup", category = "Project")
@ActionRegistration(displayName = "#LBL_Custom_Run", lazy=false)
@ActionReferences({
@ActionReference(position = 1400, path = "Projects/org-netbeans-modules-maven/Actions"),
@ActionReference(position = 250, path = "Loaders/text/x-maven-pom+xml/Actions"),
@ActionReference(position = 1296, path = "Loaders/text/x-java/Actions"),
@ActionReference(position = 1821, path = "Editors/text/x-java/Popup")
})
@Messages({"LBL_Custom_Run=Run Maven", "LBL_Custom_Run_File=Run Maven"})
public static ContextAwareAction customPopupActions() {
return new ConditionallyShownAction() {
protected @Override Action forProject(Project p, FileObject fo) {
ActionProviderImpl ap = p.getLookup().lookup(ActionProviderImpl.class);
return ap != null ? ap.new CustomPopupActions(triggeredOnFile, triggeredOnPom, fo) : null;
}
};
}
示例5: closeSubprojectsAction
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
@ActionID(id = "org.netbeans.modules.maven.closeSubprojects", category = "Project")
@ActionRegistration(displayName = "#ACT_CloseRequired", lazy=false)
@ActionReference(position = 2000, path = "Projects/org-netbeans-modules-maven/Actions")
@Messages("ACT_CloseRequired=Close Required Projects")
public static ContextAwareAction closeSubprojectsAction() {
return new ConditionallyShownAction() {
protected @Override Action forProject(Project p, FileObject fo) {
NbMavenProjectImpl project = p.getLookup().lookup(NbMavenProjectImpl.class);
if (project != null && NbMavenProject.TYPE_POM.equalsIgnoreCase(project.getProjectWatcher().getPackagingType())) {
return new CloseSubprojectsAction(project);
} else {
return null;
}
}
};
}
示例6: testActionStatusUpdatedOnLookupChange
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testActionStatusUpdatedOnLookupChange() throws Exception {
final InstanceContent content = new InstanceContent();
Lookup lkp = new AbstractLookup( content );
final SaveAsCapable saveAsImpl = new SaveAsCapable() {
public void saveAs(FileObject folder, String name) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
};
TopComponent tc = new TopComponent( lkp );
editorMode.dockInto( tc );
tc.open();
tc.requestActive();
assertTrue(Arrays.asList(WindowManager.getDefault().getOpenedTopComponents(editorMode)).contains(tc));
ContextAwareAction action = SaveAsAction.create();
assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", action.isEnabled() );
Action a = action.createContextAwareInstance( tc.getLookup() );
content.add( saveAsImpl );
assertTrue( "action is enabled for editor windows with SaveAsCapable in their Lookup", a.isEnabled() );
content.remove( saveAsImpl );
assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", a.isEnabled() );
}
示例7: propertyChange
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
/** Requests refresh of our lookup everytime component is chagned.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (TopComponent.Registry.PROP_ACTIVATED.equals (evt.getPropertyName())) {
org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap.class);
}
if ("permanentFocusOwner".equals(evt.getPropertyName())) {
Component[] arr = { (Component)evt.getNewValue() };
if (arr[0] instanceof AbstractButton) {
Action a = ((AbstractButton)arr[0]).getAction();
if (a instanceof ContextAwareAction) {
// ignore focus change into a button with our action
return;
}
}
blickActionMap(null, arr);
}
}
示例8: testCanTCGarbageCollectWhenActionInMap
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testCanTCGarbageCollectWhenActionInMap() {
TopComponent tc = new TopComponent();
class CAA extends AbstractAction implements
ContextAwareAction {
public void actionPerformed(ActionEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Action createContextAwareInstance(Lookup actionContext) {
return this;
}
}
ContextAwareAction del = new CAA();
ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
Action a = context.createContextAwareInstance(tc.getLookup());
tc.getActionMap().put("key", a);
WeakReference<Object> ref = new WeakReference<Object>(tc);
tc = null;
a = null;
del = null;
context = null;
assertGC("Can the component GC?", ref);
}
示例9: testCanTCGarbageCollectWhenActionInMapAndAssignLookup
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testCanTCGarbageCollectWhenActionInMapAndAssignLookup() {
TopComponent tc = new TopComponent();
class CAA extends AbstractAction implements
ContextAwareAction {
public void actionPerformed(ActionEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Action createContextAwareInstance(Lookup actionContext) {
return this;
}
}
tc.associateLookup(Lookups.fixed(tc.getActionMap(), tc));
ContextAwareAction del = new CAA();
ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
Action a = context.createContextAwareInstance(tc.getLookup());
tc.getActionMap().put("key", a);
WeakReference<Object> ref = new WeakReference<Object>(tc);
tc = null;
a = null;
del = null;
context = null;
assertGC("Can the component GC?", ref);
}
示例10: testContextAction
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testContextAction() throws Exception {
Action a = Actions.forID("Tools", "on.int");
assertTrue("It is context aware action", a instanceof ContextAwareAction);
InstanceContent ic = new InstanceContent();
AbstractLookup lkp = new AbstractLookup(ic);
Action clone = ((ContextAwareAction) a).createContextAwareInstance(lkp);
NumberLike ten = new NumberLike(10);
ic.add(ten);
assertEquals("Number lover!", clone.getValue(Action.NAME));
clone.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Global Action not called", 10, Context.cnt);
ic.remove(ten);
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Global Action stays same", 10, Context.cnt);
}
示例11: testMultiContextAction
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testMultiContextAction() throws Exception {
ContextAwareAction a = (ContextAwareAction) Actions.forID("Tools", "on.numbers");
InstanceContent ic = new InstanceContent();
AbstractLookup lkp = new AbstractLookup(ic);
Action clone = a.createContextAwareInstance(lkp);
NumberLike ten = new NumberLike(10);
NumberLike three = new NumberLike(3);
ic.add(ten);
ic.add(three);
assertEquals("Number lover!", clone.getValue(Action.NAME));
clone.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Global Action not called", 13, MultiContext.cnt);
ic.remove(ten);
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Adds 3", 16, MultiContext.cnt);
ic.remove(three);
assertFalse("It is disabled", clone.isEnabled());
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("No change", 16, MultiContext.cnt);
}
示例12: testActionsUpdatedWhenActionMapChanges
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testActionsUpdatedWhenActionMapChanges() throws Exception {
ContextAwareAction a = Actions.callback("ahoj", null, true, "Ahoj!", "no/icon.png", true);
final InstanceContent ic = new InstanceContent();
Lookup lkp = new AbstractLookup(ic);
ActionMap a1 = new ActionMap();
ActionMap a2 = new ActionMap();
a2.put("ahoj", new Enabled());
ic.add(a1);
Action clone = a.createContextAwareInstance(lkp);
class L implements PropertyChangeListener {
int cnt;
public void propertyChange(PropertyChangeEvent evt) {
cnt++;
}
}
L listener = new L();
clone.addPropertyChangeListener(listener);
assertFalse("Not enabled", isEnabled(clone));
ic.set(Collections.singleton(a2), null);
assertTrue("Enabled now", isEnabled(clone));
assertEquals("one change", 1, listener.cnt);
}
示例13: testSurviveFocusChange
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testSurviveFocusChange() throws Exception {
InstanceContent ic = new InstanceContent();
Lookup lkp = new AbstractLookup(ic);
Action clone = ((ContextAwareAction) Actions.forID("cat", "survive")).createContextAwareInstance(lkp);
L listener = new L();
clone.addPropertyChangeListener(listener);
assertFalse("Disabled", clone.isEnabled());
Object val = Integer.valueOf(1);
ic.add(val);
assertTrue("Enabled now", clone.isEnabled());
assertEquals("One change", 1, listener.cnt);
ic.remove(val);
assertTrue("Still Enabled", clone.isEnabled());
Survival.value = 0;
clone.actionPerformed(new ActionEvent(this, 0, ""));
assertEquals("Added one", 1, Survival.value);
}
示例14: testListenerGCed
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testListenerGCed () throws Exception {
InstanceContent ic = new InstanceContent();
lkp = new AbstractLookup(ic);
Lookup.Result<Integer> lookupResult = lkp.lookupResult(Integer.class);
Action action = ((ContextAwareAction) Actions.forID("cat", "survive")).createContextAwareInstance(lkp);
Action fallbackAction = ((GeneralAction.DelegateAction) action).fallback;
WeakReference<Action> fallbackActionRef = new WeakReference<Action>(fallbackAction);
WeakReference<Action> clone = new WeakReference<Action>(action);
cm = ContextManager.findManager(lkp, true);
WeakReference lsetRef = new WeakReference<Object>(cm.findLSet(Integer.class));
action = null;
assertGC("Action should be GCed", clone);
fallbackAction = null;
assertGC("Fallback action should be GCed", fallbackActionRef);
assertGC("Action LSet Should be GCed", lsetRef);
lookupResult.allInstances();
}
示例15: testBasicUsageWithEnablerFromLayer
import org.openide.util.ContextAwareAction; //导入依赖的package包/类
public void testBasicUsageWithEnablerFromLayer() throws Exception {
FileObject folder;
folder = FileUtil.getConfigFile("actions/support/test");
assertNotNull("testing layer is loaded: ", folder);
FileObject fo = folder.getFileObject("testContextEnabler.instance");
Object obj = fo.getAttribute("instanceCreate");
if (!(obj instanceof ContextAwareAction)) {
fail("Shall create an action: " + obj);
}
ContextAwareAction caa = (ContextAwareAction)obj;
Action action = caa.createContextAwareInstance(lookupProxy);
doBasicUsageWithEnabler(action);
}