⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bindingmanager.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
							.equals(parentId)) {						if ((!window) && (!dialog)) {							contextIdItr.remove();						}						break;					}					context = contextManager.getContext(parentId);					parentId = context.getParentId();				}			} catch (NotDefinedException e) {				// since this context was part of an undefined hierarchy,				// I'm going to yank it out as a bad bet				contextIdItr.remove();				// This is a logging optimization, only log the error once.				if (context==null || !bindingErrors.contains(context.getId())) {					if (context!=null) {						bindingErrors.add(context.getId());					}										// now log like you've never logged before!					Policy							.getLog()							.log(									new Status(											IStatus.ERROR,											Policy.JFACE,											IStatus.OK,											"Undefined context while filtering dialog/window contexts", //$NON-NLS-1$											e));				}			}		}		return createContextTreeFor(contextIds);	}	/**	 * <p>	 * Notifies all of the listeners to this manager that the defined or active	 * schemes of bindings have changed.	 * </p>	 * <p>	 * The time this method takes to complete is dependent on external	 * listeners.	 * </p>	 * 	 * @param event	 *            The event to send to all of the listeners; must not be	 *            <code>null</code>.	 */	private final void fireBindingManagerChanged(final BindingManagerEvent event) {		if (event == null) {			throw new NullPointerException();		}		final Object[] listeners = getListeners();		for (int i = 0; i < listeners.length; i++) {			final IBindingManagerListener listener = (IBindingManagerListener) listeners[i];			listener.bindingManagerChanged(event);		}	}	/**	 * <p>	 * Returns the active bindings. The caller must not modify the returned map.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>. If the active bindings are	 * not yet computed, then this completes in <code>O(nn)</code>, where	 * <code>n</code> is the number of bindings.	 * </p>	 * 	 * @return The map of triggers (<code>TriggerSequence</code>) to	 *         bindings (<code>Binding</code>) which are currently active.	 *         This value may be <code>null</code> if there are no active	 *         bindings, and it may be empty.	 */	private final Map getActiveBindings() {		if (activeBindings == null) {			recomputeBindings();		}		return activeBindings;	}	/**	 * <p>	 * Returns the active bindings indexed by command identifier.	 * The caller must not modify the returned map.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>. If the active bindings are	 * not yet computed, then this completes in <code>O(nn)</code>, where	 * <code>n</code> is the number of bindings.	 * </p>	 * 	 * @return The map of fully-parameterized commands (<code>ParameterizedCommand</code>)	 *         to triggers (<code>TriggerSequence</code>) which are	 *         currently active. This value may be <code>null</code> if there	 *         are no active bindings, and it may be empty.	 */	private final Map getActiveBindingsByParameterizedCommand() {		if (activeBindingsByParameterizedCommand == null) {			recomputeBindings();		}		return activeBindingsByParameterizedCommand;	}	/**	 * <p>	 * Computes the bindings for the current state of the application, but	 * disregarding the current contexts. This can be useful when trying to	 * display all the possible bindings.	 * </p>	 * <p>	 * This method completes in <code>O(n)</code>, where <code>n</code> is	 * the number of bindings.	 * </p>	 * 	 * @return A map of trigger (<code>TriggerSequence</code>) to bindings (	 *         <code>Collection</code> containing <code>Binding</code>).	 *         This map may be empty, but it is never <code>null</code>.	 */	public final Map getActiveBindingsDisregardingContext() {		if (bindings == null) {			// Not yet initialized. This is happening too early. Do nothing.			return Collections.EMPTY_MAP;		}		// Build a cached binding set for that state.		final CachedBindingSet bindingCache = new CachedBindingSet(null,				locales, platforms, activeSchemeIds);		/*		 * Check if the cached binding set already exists. If so, simply set the		 * active bindings and return.		 */		CachedBindingSet existingCache = (CachedBindingSet) cachedBindings				.get(bindingCache);		if (existingCache == null) {			existingCache = bindingCache;			cachedBindings.put(existingCache, existingCache);		}		Map commandIdsByTrigger = existingCache.getBindingsByTrigger();		if (commandIdsByTrigger != null) {			if (DEBUG) {				Tracing.printTrace("BINDINGS", "Cache hit"); //$NON-NLS-1$ //$NON-NLS-2$			}			return Collections.unmodifiableMap(commandIdsByTrigger);		}		// There is no cached entry for this.		if (DEBUG) {			Tracing.printTrace("BINDINGS", "Cache miss"); //$NON-NLS-1$ //$NON-NLS-2$		}		// Compute the active bindings.		commandIdsByTrigger = new HashMap();		final Map triggersByParameterizedCommand = new HashMap();		computeBindings(null, commandIdsByTrigger,				triggersByParameterizedCommand);		existingCache.setBindingsByTrigger(commandIdsByTrigger);		existingCache.setTriggersByCommandId(triggersByParameterizedCommand);		return Collections.unmodifiableMap(commandIdsByTrigger);	}	/**	 * <p>	 * Computes the bindings for the current state of the application, but	 * disregarding the current contexts. This can be useful when trying to	 * display all the possible bindings.	 * </p>	 * <p>	 * This method completes in <code>O(n)</code>, where <code>n</code> is	 * the number of bindings.	 * </p>	 * 	 * @return A map of trigger (<code>TriggerSequence</code>) to bindings (	 *         <code>Collection</code> containing <code>Binding</code>).	 *         This map may be empty, but it is never <code>null</code>.	 * @since 3.2	 */	private final Map getActiveBindingsDisregardingContextByParameterizedCommand() {		if (bindings == null) {			// Not yet initialized. This is happening too early. Do nothing.			return Collections.EMPTY_MAP;		}		// Build a cached binding set for that state.		final CachedBindingSet bindingCache = new CachedBindingSet(null,				locales, platforms, activeSchemeIds);		/*		 * Check if the cached binding set already exists. If so, simply set the		 * active bindings and return.		 */		CachedBindingSet existingCache = (CachedBindingSet) cachedBindings				.get(bindingCache);		if (existingCache == null) {			existingCache = bindingCache;			cachedBindings.put(existingCache, existingCache);		}		Map triggersByParameterizedCommand = existingCache				.getTriggersByCommandId();		if (triggersByParameterizedCommand != null) {			if (DEBUG) {				Tracing.printTrace("BINDINGS", "Cache hit"); //$NON-NLS-1$ //$NON-NLS-2$			}			return Collections.unmodifiableMap(triggersByParameterizedCommand);		}		// There is no cached entry for this.		if (DEBUG) {			Tracing.printTrace("BINDINGS", "Cache miss"); //$NON-NLS-1$ //$NON-NLS-2$		}		// Compute the active bindings.		final Map commandIdsByTrigger = new HashMap();		triggersByParameterizedCommand = new HashMap();		computeBindings(null, commandIdsByTrigger,				triggersByParameterizedCommand);		existingCache.setBindingsByTrigger(commandIdsByTrigger);		existingCache.setTriggersByCommandId(triggersByParameterizedCommand);		return Collections.unmodifiableMap(triggersByParameterizedCommand);	}	/**	 * <p>	 * Computes the bindings for the current state of the application, but	 * disregarding the current contexts. This can be useful when trying to	 * display all the possible bindings.	 * </p>	 * <p>	 * This method completes in <code>O(n)</code>, where <code>n</code> is	 * the number of bindings.	 * </p>	 * 	 * @return All of the active bindings (<code>Binding</code>), not sorted	 *         in any fashion. This collection may be empty, but it is never	 *         <code>null</code>.	 */	public final Collection getActiveBindingsDisregardingContextFlat() {		final Collection bindingCollections = getActiveBindingsDisregardingContext()				.values();		final Collection mergedBindings = new ArrayList();		final Iterator bindingCollectionItr = bindingCollections.iterator();		while (bindingCollectionItr.hasNext()) {			final Collection bindingCollection = (Collection) bindingCollectionItr					.next();			if ((bindingCollection != null) && (!bindingCollection.isEmpty())) {				mergedBindings.addAll(bindingCollection);			}		}		return mergedBindings;	}	/**	 * <p>	 * Returns the active bindings for a particular command identifier, but	 * discounting the current contexts. This method operates in O(n) time over	 * the number of bindings.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>. If the active bindings are	 * not yet computed, then this completes in <code>O(nn)</code>, where	 * <code>n</code> is the number of bindings.	 * </p>	 * 	 * @param parameterizedCommand	 *            The fully-parameterized command whose bindings are requested.	 *            This argument may be <code>null</code>.	 * @return The array of active triggers (<code>TriggerSequence</code>)	 *         for a particular command identifier. This value is guaranteed to	 *         never be <code>null</code>, but it may be empty.	 * @since 3.2	 */	public final TriggerSequence[] getActiveBindingsDisregardingContextFor(			final ParameterizedCommand parameterizedCommand) {		final Object object = getActiveBindingsDisregardingContextByParameterizedCommand()				.get(parameterizedCommand);		if (object instanceof Collection) {			final Collection collection = (Collection) object;			return (TriggerSequence[]) collection					.toArray(new TriggerSequence[collection.size()]);		}		return EMPTY_TRIGGER_SEQUENCE;	}	/**	 * <p>	 * Returns the active bindings for a particular command identifier. This	 * method operates in O(n) time over the number of bindings.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>. If the active bindings are	 * not yet computed, then this completes in <code>O(nn)</code>, where	 * <code>n</code> is the number of bindings.	 * </p>	 * 	 * @param parameterizedCommand	 *            The fully-parameterized command whose bindings are requested.	 *            This argument may be <code>null</code>.	 * @return The array of active triggers (<code>TriggerSequence</code>)	 *         for a particular command identifier. This value is guaranteed to	 *         never be <code>null</code>, but it may be empty.	 */	public final TriggerSequence[] getActiveBindingsFor(			final ParameterizedCommand parameterizedCommand) {		final Object object = getActiveBindingsByParameterizedCommand().get(				parameterizedCommand);		if (object instanceof Collection) {			final Collection collection = (Collection) object;			return (TriggerSequence[]) collection					.toArray(new TriggerSequence[collection.size()]);		}		return EMPTY_TRIGGER_SEQUENCE;	}	/**	 * <p>	 * Returns the active bindings for a particular command identifier. This	 * method operates in O(n) time over the number of bindings.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>. If the active bindings are	 * not yet computed, then this completes in <code>O(nn)</code>, where	 * <code>n</code> is the number of bindings.	 * </p>	 * 	 * @param commandId	 *            The identifier of the command whose bindings are requested.	 *            This argument may be <code>null</code>. It is assumed that	 *            the command has no parameters.	 * @return The array of active triggers (<code>TriggerSequence</code>)	 *         for a particular command identifier. This value is guaranteed not	 *         to be <code>null</code>, but it may be empty.	 */	public final TriggerSequence[] getActiveBindingsFor(final String commandId) {		final ParameterizedCommand parameterizedCommand = new ParameterizedCommand(				commandManager.getCommand(commandId), null);		final Object object = getActiveBindingsByParameterizedCommand().get(				parameterizedCommand);		if (object instanceof Collection) {			final Collection collection = (Collection) object;			return (TriggerSequence[]) collection					.toArray(new TriggerSequence[collection.size()]);		}		return EMPTY_TRIGGER_SEQUENCE;	}	/**	 * A variation on {@link BindingManager#getActiveBindingsFor(String)} that	 * returns an array of bindings, rather than trigger sequences. This method	 * is needed for doing "best" calculations on the active bindings.	 * 	 * @param commandId	 *            The identifier of the command for which the active bindings	 *            should be retrieved; must not be <code>null</code>.	 * @return The active bindings for the given command; this value may be	 *         <code>null</code> if there are no active bindings.	 * @since 3.2	 */	private final Binding[] getActiveBindingsFor1(final String commandId) {		final TriggerSequence[] triggers = getActiveBindingsFor(commandId);		if (triggers.length == 0) {			return null;		}		final Map activeBindings = getActiveBindings();		if (activeBindings != null) {			final Binding[] bindings = new Binding[triggers.length];			for (int i = 0; i < triggers.length; i++) {				final TriggerSequence triggerSequence = triggers[i];				final Object object = activeBindings.get(triggerSequence);				final Binding binding = (Binding) object;				bindings[i] = binding;			}			return bindings;		}		return null;	}	/**	 * <p>	 * Gets the currently active scheme.	 * </p>	 * <p>	 * This method completes in <code>O(1)</code>.	 * </p>	 * 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -