blob: 93a74417f4bcfb22d1f8c992e3e219c0d2970b67 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.core.commands;
import org.eclipse.core.commands.common.AbstractNamedHandleEvent;
/**
* An instance of this class describes changes to an instance of
* <code>Command</code>.
* <p>
* This class is not intended to be extended by clients.
* </p>
*
* @since 3.1
* @see ICommandListener#commandChanged(CommandEvent)
*/
public final class CommandEvent extends AbstractNamedHandleEvent {
/**
* The bit used to represent whether the command has changed its category.
*/
private static final int CHANGED_CATEGORY = LAST_USED_BIT << 1;
/**
* The bit used to represent whether the command has changed its handler.
*/
private static final int CHANGED_HANDLED = LAST_USED_BIT << 2;
/**
* The bit used to represent whether the command has changed its parameters.
*/
private static final int CHANGED_PARAMETERS = LAST_USED_BIT << 3;
/**
* The bit used to represent whether the command has changed its return
* type.
*
* @since 3.2
*/
private static final int CHANGED_RETURN_TYPE = LAST_USED_BIT << 4;
/**
* The bit used to represent whether the command has changed its help
* context identifier.
*
* @since 3.2
*/
private static final int CHANGED_HELP_CONTEXT_ID = LAST_USED_BIT << 5;
/**
* The command that has changed; this value is never <code>null</code>.
*/
private final Command command;
/**
* Creates a new instance of this class.
*
* @param command
* the instance of the interface that changed.
* @param categoryChanged
* <code>true</code>, iff the category property changed.
* @param definedChanged
* <code>true</code>, iff the defined property changed.
* @param descriptionChanged
* <code>true</code>, iff the description property changed.
* @param handledChanged
* <code>true</code>, iff the handled property changed.
* @param nameChanged
* <code>true</code>, iff the name property changed.
* @param parametersChanged
* <code>true</code> if the parameters have changed;
* <code>false</code> otherwise.
*/
public CommandEvent(final Command command, final boolean categoryChanged,
final boolean definedChanged, final boolean descriptionChanged,
final boolean handledChanged, final boolean nameChanged,
final boolean parametersChanged) {
this(command, categoryChanged, definedChanged, descriptionChanged,
handledChanged, nameChanged, parametersChanged, false);
}
/**
* Creates a new instance of this class.
*
* @param command
* the instance of the interface that changed.
* @param categoryChanged
* <code>true</code>, iff the category property changed.
* @param definedChanged
* <code>true</code>, iff the defined property changed.
* @param descriptionChanged
* <code>true</code>, iff the description property changed.
* @param handledChanged
* <code>true</code>, iff the handled property changed.
* @param nameChanged
* <code>true</code>, iff the name property changed.
* @param parametersChanged
* <code>true</code> if the parameters have changed;
* <code>false</code> otherwise.
* @param returnTypeChanged
* <code>true</code> iff the return type property changed;
* <code>false</code> otherwise.
* @since 3.2
*/
public CommandEvent(final Command command, final boolean categoryChanged,
final boolean definedChanged, final boolean descriptionChanged,
final boolean handledChanged, final boolean nameChanged,
final boolean parametersChanged, final boolean returnTypeChanged) {
this(command, categoryChanged, definedChanged, descriptionChanged,
handledChanged, nameChanged, parametersChanged,
returnTypeChanged, false);
}
/**
* Creates a new instance of this class.
*
* @param command
* the instance of the interface that changed.
* @param categoryChanged
* <code>true</code>, iff the category property changed.
* @param definedChanged
* <code>true</code>, iff the defined property changed.
* @param descriptionChanged
* <code>true</code>, iff the description property changed.
* @param handledChanged
* <code>true</code>, iff the handled property changed.
* @param nameChanged
* <code>true</code>, iff the name property changed.
* @param parametersChanged
* <code>true</code> if the parameters have changed;
* <code>false</code> otherwise.
* @param returnTypeChanged
* <code>true</code> iff the return type property changed;
* <code>false</code> otherwise.
* @param helpContextIdChanged
* <code>true</code> iff the help context identifier changed;
* <code>false</code> otherwise.
* @since 3.2
*/
public CommandEvent(final Command command, final boolean categoryChanged,
final boolean definedChanged, final boolean descriptionChanged,
final boolean handledChanged, final boolean nameChanged,
final boolean parametersChanged, final boolean returnTypeChanged,
final boolean helpContextIdChanged) {
super(definedChanged, descriptionChanged, nameChanged);
if (command == null) {
throw new NullPointerException();
}
this.command = command;
if (categoryChanged) {
changedValues |= CHANGED_CATEGORY;
}
if (handledChanged) {
changedValues |= CHANGED_HANDLED;
}
if (parametersChanged) {
changedValues |= CHANGED_PARAMETERS;
}
if (returnTypeChanged) {
changedValues |= CHANGED_RETURN_TYPE;
}
if (helpContextIdChanged) {
changedValues |= CHANGED_HELP_CONTEXT_ID;
}
}
/**
* Returns the instance of the interface that changed.
*
* @return the instance of the interface that changed. Guaranteed not to be
* <code>null</code>.
*/
public final Command getCommand() {
return command;
}
/**
* Returns whether or not the category property changed.
*
* @return <code>true</code>, iff the category property changed.
*/
public final boolean isCategoryChanged() {
return ((changedValues & CHANGED_CATEGORY) != 0);
}
/**
* Returns whether or not the handled property changed.
*
* @return <code>true</code>, iff the handled property changed.
*/
public final boolean isHandledChanged() {
return ((changedValues & CHANGED_HANDLED) != 0);
}
/**
* Returns whether or not the help context identifier changed.
*
* @return <code>true</code>, iff the help context identifier changed.
* @since 3.2
*/
public final boolean isHelpContextIdChanged() {
return ((changedValues & CHANGED_HELP_CONTEXT_ID) != 0);
}
/**
* Returns whether or not the parameters have changed.
*
* @return <code>true</code>, iff the parameters property changed.
*/
public final boolean isParametersChanged() {
return ((changedValues & CHANGED_PARAMETERS) != 0);
}
/**
* Returns whether or not the return type property changed.
*
* @return <code>true</code>, iff the return type property changed.
* @since 3.2
*/
public final boolean isReturnTypeChanged() {
return ((changedValues & CHANGED_RETURN_TYPE) != 0);
}
}