public static void renameProject(Project p, Object caller) { if (p == null) { return; } ContextAwareAction action = (ContextAwareAction) CommonProjectActions.renameProjectAction(); Lookup ctx = Lookups.singleton(p); Action ctxAction = action.createContextAwareInstance(ctx); ctxAction.actionPerformed(new ActionEvent(caller, 0, "")); // NOI18N }
@Override public Action createContextAwareInstance(Lookup actionContext) { if (!ProfilingPointsManager.getDefault().isProfilingSessionInProgress()) { Collection<? extends CodeProfilingPoint.Annotation> anns = actionContext.lookupAll(CodeProfilingPoint.Annotation.class); if (anns.size() == 1) { CodeProfilingPoint pp = anns.iterator().next().profilingPoint(); action.setProfilingPoint(pp); action.setBooleanState(pp.isEnabled()); return action; } } return this; }
@Override public Action createContextAwareInstance(Lookup actionContext) { try { Method getDelegateMethod = action.getClass().getDeclaredMethod("getDelegate"); getDelegateMethod.setAccessible(true); Action act = (Action) getDelegateMethod.invoke(action); String iconBase = (String) action.getValue("iconBase"); if (iconBase != null) { act.putValue(SMALL_ICON, ImageUtilities.loadImageIcon(iconBase, true)); } return act; } catch (Exception ex) { return action.createContextAwareInstance(actionContext); } }
@Override public void actionPerformed(ActionEvent e) { action.actionPerformed(e); }
@Override public void removePropertyChangeListener(PropertyChangeListener listener) { action.removePropertyChangeListener(listener); }
@Override public void addPropertyChangeListener(PropertyChangeListener listener) { action.addPropertyChangeListener(listener); }
@Override public boolean isEnabled() { return action.isEnabled(); }
@Override public void setEnabled(boolean b) { action.setEnabled(b); }
@Override public void putValue(String key, Object value) { action.putValue(key, value); }
@Override public Object getValue(String key) { return action.getValue(key); }