deletecommand.java

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

JAVA
151
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/command/DeleteCommand.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.ArrayList;
import java.util.List;

import org.eclipse.gef.commands.Command;

import com.webpump.ui.gefmodule.model.ModelSubpart;
import com.webpump.ui.gefmodule.model.Module;
import com.webpump.ui.gefmodule.model.Task;

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

	/**child*/
	private ModelSubpart child;

	/**parent*/
	private Module parent;

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

	/**source connections*/
	private List sourceConnections = new ArrayList();

	/**target connections*/
	private List targetConnections = new ArrayList();

	/**
	 * constructor
	 */
	public DeleteCommand() {
		super("Delete Object");
	}

	/**
	 * delete connections
	 * @param part ModelSubpart
	 */
	private void deleteConnections(ModelSubpart part) {
		if (part instanceof Module) {
			List children = ((Module) part).getChildren();
			for (int i = 0; i < children.size(); i++)
				deleteConnections((ModelSubpart) children.get(i));
		}
		sourceConnections.addAll(part.getSourceConnections());
		for (int i = 0; i < sourceConnections.size(); i++) {
			Task wire = (Task) sourceConnections.get(i);
			wire.detachSource();
			wire.detachTarget();
		}
		targetConnections.addAll(part.getTargetConnections());
		for (int i = 0; i < targetConnections.size(); i++) {
			Task wire = (Task) targetConnections.get(i);
			wire.detachSource();
			wire.detachTarget();
		}
	}

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

	/**
	 * prim execute
	 */
	protected void primExecute() {
		deleteConnections(child);
		index = parent.getChildren().indexOf(child);
		parent.removeChild(child);
	}

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

	/**
	 * restore connections
	 */
	private void restoreConnections() {
		for (int i = 0; i < sourceConnections.size(); i++) {
			Task wire = (Task) sourceConnections.get(i);
			wire.attachSource();
			wire.attachTarget();
		}
		sourceConnections.clear();
		for (int i = 0; i < targetConnections.size(); i++) {
			Task wire = (Task) targetConnections.get(i);
			wire.attachSource();
			wire.attachTarget();
		}
		targetConnections.clear();
	}

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

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

	/**
	 * undo
	 */
	public void undo() {
		parent.addChild(child, index);
		restoreConnections();
	}
}

⌨️ 快捷键说明

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