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

📄 externalactionmanager.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		/**		 * {@inheritDoc}		 * 		 * Calling this method with an undefined command id will generate a log		 * message.		 */		public final boolean isActive(final String commandId) {			if (commandId != null) {				final Command command = commandManager.getCommand(commandId);				if (!command.isDefined()						&& (!loggedCommandIds.contains(commandId))) {					// The command is not yet defined, so we should log this.					final String message = MessageFormat.format(Util							.translateString(RESOURCE_BUNDLE,									"undefinedCommand.WarningMessage", null), //$NON-NLS-1$							new String[] { command.getId() });					IStatus status = new Status(IStatus.ERROR,							"org.eclipse.jface", //$NON-NLS-1$							0, message, new Exception());					Policy.getLog().log(status);					// And remember this item so we don't log it again.					loggedCommandIds.add(commandId);					command.addCommandListener(new ICommandListener() {						/*						 * (non-Javadoc)						 * 						 * @see org.eclipse.ui.commands.ICommandListener#commandChanged(org.eclipse.ui.commands.CommandEvent)						 */						public final void commandChanged(								final CommandEvent commandEvent) {							if (command.isDefined()) {								command.removeCommandListener(this);								loggedCommandIds.remove(commandId);							}						}					});					return true;				}				return activeChecker.isActive(commandId);			}			return true;		}		/**		 * @see org.eclipse.jface.action.ExternalActionManager.ICallback#removePropertyChangeListener(String,		 *      IPropertyChangeListener)		 */		public final void removePropertyChangeListener(final String commandId,				final IPropertyChangeListener listener) {			final IPropertyChangeListener existingListener = (IPropertyChangeListener) registeredListeners					.get(commandId);			if (existingListener == listener) {				registeredListeners.remove(commandId);				if (registeredListeners.isEmpty()) {					bindingManager.removeBindingManagerListener(this);					bindingManagerListenerAttached = false;				}			}		}	}	/**	 * Defines a callback mechanism for developer who wish to further control	 * the visibility of legacy action-based contribution items.	 * 	 * @since 3.1	 */	public static interface IActiveChecker {		/**		 * Checks whether the command with the given identifier should be		 * considered active. This can be used in systems using some kind of		 * user interface filtering (e.g., activities in the Eclipse workbench).		 * 		 * @param commandId		 *            The identifier for the command; must not be		 *            <code>null</code>		 * @return <code>true</code> if the command is active;		 *         <code>false</code> otherwise.		 */		public boolean isActive(String commandId);	}	/**	 * <p>	 * A callback which communicates with the applications binding manager. This	 * interface provides more information from the binding manager, which	 * allows greater integration. Implementing this interface is preferred over	 * {@link ExternalActionManager.ICallback}.	 * </p>	 * <p>	 * Clients may implement this interface, but must not extend.	 * </p>	 * 	 * @since 3.2	 */	public static interface IBindingManagerCallback extends ICallback {		/**		 * <p>		 * Returns the active bindings for a particular command identifier.		 * </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 TriggerSequence[] getActiveBindingsFor(String commandId);	}	/**	 * A callback mechanism for some external tool to communicate extra	 * information to actions and action contribution items.	 * 	 * @since 3.0	 */	public static interface ICallback {		/**		 * <p>		 * Adds a listener to the object referenced by <code>identifier</code>.		 * This listener will be notified if a property of the item is to be		 * changed. This identifier is specific to mechanism being used. In the		 * case of the Eclipse workbench, this is the command identifier.		 * </p>		 * <p>		 * A single instance of the listener may only ever be associated with		 * one identifier. Attempts to add the listener twice (without a removal		 * in between) has undefined behaviour.		 * </p>		 * 		 * @param identifier		 *            The identifier of the item to which the listener should be		 *            attached; must not be <code>null</code>.		 * @param listener		 *            The listener to be added; must not be <code>null</code>.		 */		public void addPropertyChangeListener(String identifier,				IPropertyChangeListener listener);		/**		 * An accessor for the accelerator associated with the item indicated by		 * the identifier. This identifier is specific to mechanism being used.		 * In the case of the Eclipse workbench, this is the command identifier.		 * 		 * @param identifier		 *            The identifier of the item from which the accelerator		 *            should be obtained ; must not be <code>null</code>.		 * @return An integer representation of the accelerator. This is the		 *         same accelerator format used by SWT.		 */		public Integer getAccelerator(String identifier);		/**		 * An accessor for the accelerator text associated with the item		 * indicated by the identifier. This identifier is specific to mechanism		 * being used. In the case of the Eclipse workbench, this is the command		 * identifier.		 * 		 * @param identifier		 *            The identifier of the item from which the accelerator text		 *            should be obtained ; must not be <code>null</code>.		 * @return A string representation of the accelerator. This is the		 *         string representation that should be displayed to the user.		 */		public String getAcceleratorText(String identifier);		/**		 * Checks to see whether the given accelerator is being used by some		 * other mechanism (outside of the menus controlled by JFace). This is		 * used to keep JFace from trying to grab accelerators away from someone		 * else.		 * 		 * @param accelerator		 *            The accelerator to check -- in SWT's internal accelerator		 *            format.		 * @return <code>true</code> if the accelerator is already being used		 *         and shouldn't be used again; <code>false</code> otherwise.		 */		public boolean isAcceleratorInUse(int accelerator);		/**		 * Checks whether the item matching this identifier is active. This is		 * used to decide whether a contribution item with this identifier		 * should be made visible. An inactive item is not visible.		 * 		 * @param identifier		 *            The identifier of the item from which the active state		 *            should be retrieved; must not be <code>null</code>.		 * @return <code>true</code> if the item is active; <code>false</code>		 *         otherwise.		 */		public boolean isActive(String identifier);		/**		 * Removes a listener from the object referenced by		 * <code>identifier</code>. This identifier is specific to mechanism		 * being used. In the case of the Eclipse workbench, this is the command		 * identifier.		 * 		 * @param identifier		 *            The identifier of the item to from the listener should be		 *            removed; must not be <code>null</code>.		 * @param listener		 *            The listener to be removed; must not be <code>null</code>.		 */		public void removePropertyChangeListener(String identifier,				IPropertyChangeListener listener);	}	/**	 * The singleton instance of this class. This value may be <code>null</code>--	 * if it has not yet been initialized.	 */	private static ExternalActionManager instance;	/**	 * Retrieves the current singleton instance of this class.	 * 	 * @return The singleton instance; this value is never <code>null</code>.	 */	public static ExternalActionManager getInstance() {		if (instance == null) {			instance = new ExternalActionManager();		}		return instance;	}	/**	 * The callback mechanism to use to retrieve extra information.	 */	private ICallback callback;	/**	 * Constructs a new instance of <code>ExternalActionManager</code>.	 */	private ExternalActionManager() {		// This is a singleton class. Only this class should create an instance.	}	/**	 * An accessor for the current call back.	 * 	 * @return The current callback mechanism being used. This is the callback	 *         that should be queried for extra information about actions and	 *         action contribution items. This value may be <code>null</code>	 *         if there is no extra information.	 */	public ICallback getCallback() {		return callback;	}	/**	 * A mutator for the current call back	 * 	 * @param callbackToUse	 *            The new callback mechanism to use; this value may be	 *            <code>null</code> if the default is acceptable (i.e., no	 *            extra information will provided to actions).	 */	public void setCallback(ICallback callbackToUse) {		callback = callbackToUse;	}}

⌨️ 快捷键说明

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