/** Invoked when an action occurs. */ public void actionPerformed(final java.awt.event.ActionEvent e) { global.actionPerformed(e, performer, type, selectMode); }
public void run() { clearCache(context, this, survive); } } // end of GMReference
/** Constructs new action that is bound to given context and * listens for changes of <code>ActionMap</code> in order to delegate * to right action. */ public ContextAction( ContextAction.Performer<? super T> performer, ContextSelection selectMode, Lookup actionContext, Class<T> type, boolean surviveFocusChange ) { if (performer == null) { throw new NullPointerException("Has to provide a key!"); // NOI18N } this.type = type; this.selectMode = selectMode; this.performer = performer; this.global = ContextManager.findManager(actionContext, surviveFocusChange); }
/** Checks whether a type is enabled. */ public <T> boolean isEnabled(Class<T> type, ContextSelection selectMode, ContextAction.Performer<? super T> enabler) { Lookup.Result<T> result = findResult(type); boolean e = isEnabledOnData(result, type, selectMode); if (e && enabler != null) { e = enabler.enabled(listFromResult(result)); } return e; }
public <T> void registerListener(Class<T> type, ContextAction<T> a) { synchronized (CACHE) { LSet<T> existing = findLSet(type); if (existing == null) { Lookup.Result<T> result = createResult(lookup.lookupResult(type)); existing = new LSet<T>(result, type); listeners.put(type, existing); } existing.add(a); // TBD: a.updateState(new ActionMap(), actionMap.get()); if (a.selectMode == ContextSelection.ALL) { initSelectionAll(); selectionAll.add(a); } } }
public <T> void actionPerformed(final ActionEvent e, ContextAction.Performer<? super T> perf, final Class<T> type, ContextSelection selectMode) { Lookup.Result<T> result = findResult(type); final List<? extends T> all = listFromResult(result); class LkpAE implements Lookup.Provider { private Lookup lookup; public Lookup getLookup() { if (lookup == null) { lookup = new ProxyLookup( Lookups.fixed(all.toArray()), Lookups.exclude(ContextManager.this.lookup, type) ); } return lookup; } } perf.actionPerformed(e, Collections.unmodifiableList(all), new LkpAE()); }
public <T> void unregisterListener(Class<T> type, ContextAction<T> a) { synchronized (CACHE) { Set<ContextAction> existing = findLSet(type); if (existing != null) { existing.remove(a); if (existing.isEmpty()) { listeners.remove(type); } } if (a.selectMode == ContextSelection.ALL && selectionAll != null) { selectionAll.remove(a); if (selectionAll.isEmpty() && !isSurvive()) { selectionAll = null; } } } }
public boolean isEnabled() { assert EventQueue.isDispatchThread(); boolean r = global.isEnabled(type, selectMode, performer); previousEnabled = r; return r; }
private <T> Lookup.Result<T> findResult(final Class<T> type) { LSet<T> lset = findLSet(type); Lookup.Result<T> result; if (lset != null) { result = lset.result; } else { result = lookup.lookupResult(type); } return result; }
public static ContextManager findManager(Lookup context, boolean survive) { synchronized (CACHE) { Map<LookupRef, Reference<ContextManager>> map = survive ? SURVIVE : CACHE; LookupRef lr = new LookupRef(context); Reference<ContextManager> ref = map.get(lr); ContextManager g = ref == null ? null : ref.get(); if (g == null) { g = survive ? new SurviveManager(context) : new ContextManager(context); ref = new GMReference(g, lr, survive); map.put(lr, ref); } return g; } }