createcommand.java

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

JAVA
180
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/command/CreateCommand.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.util.Vector;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jface.wizard.WizardDialog;

import com.webpump.ui.gefmodule.ModuleEditor;
import com.webpump.ui.gefmodule.dialog.PageDialog;
import com.webpump.ui.gefmodule.model.ModelSubpart;
import com.webpump.ui.gefmodule.model.Module;
import com.webpump.ui.gefmodule.model.Page;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.perspective.WebpumpIDEPlugin;

/**
 * Class for CreateCommand
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
public class CreateCommand extends org.eclipse.gef.commands.Command {

	/**child*/
	private ModelSubpart child;

	/**rect*/
	private Rectangle rect;

	/**parent*/
	private Module parent;

	/**index*/
	private int index = -1;

	/**
	 * constructor
	 */
	public CreateCommand() {
		super("Create Object");
	}

	/**
	 * execute
	 */
	public void execute() {
		if (rect != null) {
			child.setLocation(rect.getLocation());
			if (!rect.isEmpty())
				child.setSize(rect.getSize());
		}
		if (index < 0)
			parent.addChild(child);
		else
			parent.addChild(child, index);
	}

	/**
	 * execute create
	 * @param boolean
	 */
	public boolean executeCreate() {
		PageDialog objWizard = new PageDialog();

		//设置视图的模块信息
		objWizard.setPage((Page) child);
		objWizard.setFile(ModuleEditor.getInputFile());

		Vector pageVector = ((Module) parent).getChildren();
		Page[] pages = (Page[]) pageVector.toArray(new Page[pageVector.size()]);
		objWizard.setPages(pages);

		objWizard.init(WebpumpIDEPlugin.getDefault().getWorkbench(), null);

		WizardDialog objDialog =
			new WizardDialog(
				WebpumpIDEPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
				objWizard);

		objDialog.setPageSize(
			MacroResource.DIALOG_A_SIZE_WIDTH,
			MacroResource.DIALOG_A_SIZE_HEIGHT);

		if (objDialog.open() == WizardDialog.OK) {
			if (rect != null) {
				child.setLocation(rect.getLocation());
				if (!rect.isEmpty())
					child.setSize(rect.getSize());
			}
			if (index < 0)
				parent.addChild(child);
			else
				parent.addChild(child, index);
			return true;
		} else {
			return false;
		}
	}

	/**
	 * get parent
	 * @return parent Module
	 */
	public Module getParent() {
		return parent;
	}

	/**
	 * redo
	 */
	public void redo() {
		if (rect != null) {
			child.setLocation(rect.getLocation());
			child.setSize(rect.getSize());
		}
		if (index < 0)
			parent.addChild(child);
		else
			parent.addChild(child, index);
	}

	/**
	 * set child
	 * @param subpart ModelSubpart
	 */
	public void setChild(ModelSubpart subpart) {
		child = subpart;
	}

	/**
	 * set index
	 * @param index int
	 */
	public void setIndex(int index) {
		this.index = index;
	}

	/**
	 * set location
	 * @param r Rectangle
	 */
	public void setLocation(Rectangle r) {
		rect = r;
	}

	/**
	 * set parent
	 * @param newParent Module
	 */
	public void setParent(Module newParent) {
		parent = newParent;
	}

	/**
	 * undo
	 */
	public void undo() {
		parent.removeChild(child);
	}
}

⌨️ 快捷键说明

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