moduletreecontainereditpolicy.java

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

JAVA
130
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/edit/ModuleTreeContainerEditPolicy.java,v 1.1.1.1 2004/07/01 09:07:47 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:47 $
 *
 * ====================================================================
 *
 * 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.edit;

import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.*;
import org.eclipse.gef.editpolicies.TreeContainerEditPolicy;

import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gef.requests.CreateRequest;

import com.webpump.ui.gefmodule.command.CreateCommand;
import com.webpump.ui.gefmodule.model.ModelSubpart;
import com.webpump.ui.gefmodule.model.Module;

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

	/**
	 * create create command
	 * @param child ModelSubpart
	 * @param r Rectangle
	 * @param index int 
	 * @param label String
	 * @return command Command
	 */
	protected Command createCreateCommand(
		ModelSubpart child,
		Rectangle r,
		int index,
		String label) {
		CreateCommand cmd = new CreateCommand();
		Rectangle rect;
		if (r == null) {
			rect = new Rectangle();
			rect.setSize(new Dimension(-1, -1));
		} else {
			rect = r;
		}
		cmd.setLocation(rect);
		cmd.setParent((Module) getHost().getModel());
		cmd.setChild(child);
		cmd.setLabel(label);
		if (index >= 0)
			cmd.setIndex(index);
		return cmd;
	}

	/**
	 * get add command
	 * @param request ChangeBoundsRequest
	 * @return command Command
	 */
	protected Command getAddCommand(ChangeBoundsRequest request) {
		CompoundCommand command = new CompoundCommand();
		command.setDebugLabel("Add in LogicTreeContainerEditPolicy"); //$NON-NLS-1$
		List editparts = request.getEditParts();
		int index = findIndexOfTreeItemAt(request.getLocation());

		for (int i = 0; i < editparts.size(); i++) {
			EditPart child = (EditPart) editparts.get(i);
			if (isAncestor(child, getHost()))
				command.add(UnexecutableCommand.INSTANCE);
			else {
				ModelSubpart childModel = (ModelSubpart) child.getModel();
				command.add(createCreateCommand(childModel, new Rectangle(new org.eclipse.draw2d.geometry.Point(), childModel.getSize()), index, "Reparent ModelSubpart")); //$NON-NLS-1$
			}
		}
		return command;
	}

	/**
	 * get create command
	 * @param request CreateRequest
	 * @return command Command
	 */
	protected Command getCreateCommand(CreateRequest request) {
		ModelSubpart child = (ModelSubpart) request.getNewObject();
		int index = findIndexOfTreeItemAt(request.getLocation());
		return createCreateCommand(child, null, index, "Create ModelSubpart"); //$NON-NLS-1$
	}

	/**
	 * is ancestor
	 * @param source EditPart
	 * @param target EditPart
	 * @return boolean
	 */
	protected boolean isAncestor(EditPart source, EditPart target) {
		if (source == target)
			return true;
		if (target.getParent() != null)
			return isAncestor(source, target.getParent());
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.TreeContainerEditPolicy#getMoveChildrenCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
	 */
	protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
		return null;
	}

}

⌨️ 快捷键说明

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