setpropertyvaluecommand.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 145 行

JAVA
145
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/command/SetPropertyValueCommand.java,v 1.1.1.1 2004/07/01 09:07:46 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:46 $
 *
 * ====================================================================
/*
 * The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
 *
 * Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
 *                        IT Forest Corporation
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 */

package com.webpump.ui.gefmodule.command;

import java.text.MessageFormat;

import org.eclipse.ui.views.properties.IPropertySource;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.internal.GEFMessages;

/**
 * Class for SetPropertyValueCommand
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
public class SetPropertyValueCommand extends Command {

	/**property value*/
	protected Object propertyValue;

	/**property name*/
	protected Object propertyName;

	/**undo value*/
	protected Object undoValue;

	/**reset on undo*/
	protected boolean resetOnUndo;

	/**target*/
	protected IPropertySource target;

	/**
	 * constructor
	 */
	public SetPropertyValueCommand() {
		super(""); //$NON-NLS-1$
	}

	/**
	 * set property value
	 * @param propLabel String
	 */
	public SetPropertyValueCommand(String propLabel) {
		super(
			MessageFormat
				.format(GEFMessages.SetPropertyValueCommand_Label, new Object[] { propLabel })
				.trim());
	}

	/**
	 * whether can execute
	 * @return true
	 */
	public boolean canExecute() {
		return true;
	}

	/**
	 * execute
	 */
	public void execute() {
		resetOnUndo = !getTarget().isPropertySet(propertyName);
		if (!resetOnUndo) {
			undoValue = getTarget().getPropertyValue(propertyName);

			//		org.eclipse.gef.GEF.hack();
			// Temporary until the PropertySheetEntry is fixed to call getEditableValue()
			//		if (undoValue instanceof IPropertySource)
			//			undoValue = ((IPropertySource) undoValue).getEditableValue();
		} else
			undoValue = null;
		getTarget().setPropertyValue(propertyName, propertyValue);
	}

	/**
	 * get target
	 * @return target IPropertySource
	 */
	public IPropertySource getTarget() {
		return target;
	}

	/**
	 * set target
	 * @param aTarget IPropertySource
	 */
	public void setTarget(IPropertySource aTarget) {
		target = aTarget;
	}

	/**
	 * redo
	 */
	public void redo() {
		execute();
	}

	/**
	 * set property id
	 * @param pName Object
	 */
	public void setPropertyId(Object pName) {
		propertyName = pName;
	}

	/**
	 * set property value
	 * @param val Object
	 */
	public void setPropertyValue(Object val) {
		propertyValue = val;
	}

	/**
	 * undo
	 */
	public void undo() {
		if (resetOnUndo)
			getTarget().resetPropertyValue(propertyName);
		else
			getTarget().setPropertyValue(propertyName, undoValue);
	}
}

⌨️ 快捷键说明

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