⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flow4xylayouteditpolicy.java

📁 一个java写的business process management系统
💻 JAVA
字号:
/*
 * Copyright (c) 2003, Alexander Greif
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Flow4J-Eclipse project nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

package net.orthanc.flow4j.designer.editparts.policies;

import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.editparts.CallFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.DecisionFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.EndFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.FlowletLabelEditPart;
import net.orthanc.flow4j.designer.editparts.JavaTaskFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.JoinFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.JumpFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.ScriptTaskFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.StartFlowletEditPart;
import net.orthanc.flow4j.designer.editparts.TemplateFlowletEditPart;
import net.orthanc.flow4j.designer.model.CallFlowletModelPart;
import net.orthanc.flow4j.designer.model.DecisionFlowletModelPart;
import net.orthanc.flow4j.designer.model.EndFlowletModelPart;
import net.orthanc.flow4j.designer.model.Flow4JModelPartFactory;
import net.orthanc.flow4j.designer.model.FlowDiagramElementModelPart;
import net.orthanc.flow4j.designer.model.FlowDiagramModelPart;
import net.orthanc.flow4j.designer.model.FlowletLabelModelPart;
import net.orthanc.flow4j.designer.model.FlowletModelPart;
import net.orthanc.flow4j.designer.model.FlowletWithLabelModelPart;
import net.orthanc.flow4j.designer.model.JavaTaskFlowletModelPart;
import net.orthanc.flow4j.designer.model.JavaTaskWrapper;
import net.orthanc.flow4j.designer.model.JoinFlowletModelPart;
import net.orthanc.flow4j.designer.model.JumpFlowletModelPart;
import net.orthanc.flow4j.designer.model.ScriptTaskWrapper;
import net.orthanc.flow4j.designer.model.StartFlowletModelPart;
import net.orthanc.flow4j.designer.model.TemplateFlowletModelPart;
import net.orthanc.flow4j.designer.model.commands.CreateCommand;
import net.orthanc.flow4j.designer.model.commands.SetConstraintCommand;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;

/**
 * @author agreif
 *
 * TODO
 * 
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Flow4XYLayoutEditPolicy extends XYLayoutEditPolicy {

	/**
	 * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createAddCommand(org.eclipse.gef.EditPart, java.lang.Object)
	 */
	protected Command createAddCommand(
		EditPart childEditPart,
		Object constraint) {
		System.out.println("Flow4XYLayoutEditPolicy.createAddCommand");
		/*FlowDiagramElement part = (FlowDiagramElement)childEditPart.getModel();
		Rectangle rect = (Rectangle)constraint;
		
		_AddCommand add = new _AddCommand();
		add.setParent((FlowDiagramModelPart)getHost().getModel());
		add.setChild(part);
		add.setLabel(Flow4JPlugin.getResourceString("EditPolicy_XYLayoutEdit_AddCommand.label"));  //$NON-NLS-1$
		
		SetConstraintCommand setConstraint = new SetConstraintCommand();
		
		setConstraint.setLocation(rect);
		setConstraint.setPart(part);
		setConstraint.setLabel(Flow4JPlugin.getResourceString("EditPolicy_XYLayoutEdit_AddCommand.label"));
		
		return add.chain(setConstraint);
		*/
		return null;
	}

	/**
	 * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart, java.lang.Object)
	 */
	protected Command createChangeConstraintCommand(
		EditPart child,
		Object constraint) {
		SetConstraintCommand locationCommand = new SetConstraintCommand();
		locationCommand.setPart((FlowDiagramElementModelPart) child.getModel());
		locationCommand.setLocation((Rectangle) constraint);

		return locationCommand;
	}

	/**
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
	 */
	protected EditPolicy createChildEditPolicy(EditPart child) {
		if (child instanceof StartFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof JavaTaskFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof ScriptTaskFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof DecisionFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof JoinFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof CallFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof JumpFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof TemplateFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof EndFlowletEditPart)
			return new NonResizableEditPolicy();

		if (child instanceof FlowletLabelEditPart)
			return new NonResizableEditPolicy();

		return super.createChildEditPolicy(child);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDependantCommand(org.eclipse.gef.Request)
	 */
	protected Command getDeleteDependantCommand(Request request) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * Factory method that returns a CreateCommand for flowlet creations.
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
	 */
	protected Command getCreateCommand(CreateRequest request) {
		FlowDiagramModelPart flowDiagram =
			(FlowDiagramModelPart) getHost().getModel();
		if (StartFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"Start");

		if (JavaTaskFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"Task");
		if (request.getNewObjectType() != null && (request.getNewObjectType() instanceof JavaTaskWrapper))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				((JavaTaskWrapper)request.getNewObjectType()).getTaskClassName());

		if (request.getNewObjectType() != null && (request.getNewObjectType() instanceof ScriptTaskWrapper))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				((ScriptTaskWrapper)request.getNewObjectType()).getClassPath().toString());
		//((ScriptTaskWrapper)request.getNewObjectType()).getFile().getFullPath().toString());

		if (DecisionFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"/* boolean stmnt */");

		if (JoinFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(FlowletModelPart) request.getNewObject());

		if (CallFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"someflow");

		if (JumpFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"someflow");

		if (TemplateFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletWithLabelCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(Rectangle) getConstraintFor(request),
				"template");

		if (EndFlowletModelPart.class.equals(request.getNewObjectType()))
			return getCreateFlowletCommand(
				request,
				flowDiagram,
				(Rectangle) getConstraintFor(request),
				(FlowletModelPart) request.getNewObject());

		System.out.println(
			"Flow4XYLayoutEditPolicy.getCreateCommand() unknown type: "
				+ request.getNewObjectType());

		return null;
	}

	/**
	 * Returns a CompoundCommand object that creates a flowlet and its label.
	 * @param request
	 * @param flowDiagram
	 * @param flowletRect
	 * @param labelRect
	 * @param labelText
	 * @return	a CompoundCommand that creates a flowlet and its label
	 */
	static public CompoundCommand getCreateFlowletWithLabelCommand(
		CreateRequest request,
		FlowDiagramModelPart flowDiagram,
		Rectangle flowletRect,
		Rectangle labelRect,
		String labelText) {

		FlowletWithLabelModelPart flowletWithLabel =
			(FlowletWithLabelModelPart) request.getNewObject();
		//	ask factory to create label
		FlowletLabelModelPart flowletLabel =
			Flow4JModelPartFactory.createFlowletLabelModelPart(
				flowletWithLabel);
		flowletLabel.setText(labelText);

		//	create flowlet command
		CreateCommand createFlowletCommand =
			getCreateFlowletCommand(
				request,
				flowDiagram,
				flowletRect,
				flowletWithLabel);
		flowletWithLabel.setFlowletLabel(flowletLabel);
		flowletLabel.setFlowletWithlabel(flowletWithLabel);
		createFlowletCommand.setLabel(
			Flow4JPlugin.getResourceString(
				"EditPolicy_XYLayoutEdit_CreateCommand.label"));

		//	create flowlet label command
		CreateCommand createFlowletLabelCommand = new CreateCommand();
		createFlowletLabelCommand.setParent(flowDiagram);
		createFlowletLabelCommand.setChild(flowletLabel);
		Rectangle constraint = labelRect;
		//(Rectangle)getConstraintFor(request);
		createFlowletLabelCommand.setLocation(constraint);
		createFlowletLabelCommand.setLabel(
			Flow4JPlugin.getResourceString(
				"EditPolicy_XYLayoutEdit_CreateCommand.label"));

		//	create compound command
		CompoundCommand command = new CompoundCommand();
		command.add(createFlowletCommand);
		command.add(createFlowletLabelCommand);

		return command;
	}

	/**
	 * TODO
	 * @param request
	 * @param flowDiagram
	 * @param flowletRect
	 * @param flowlet
	 * @return
	 */
	static public CreateCommand getCreateFlowletCommand(
		CreateRequest request,
		FlowDiagramModelPart flowDiagram,
		Rectangle flowletRect,
		FlowletModelPart flowlet) {

		//	create flowlet command
		CreateCommand createFlowletCommand = new CreateCommand();
		createFlowletCommand.setParent(flowDiagram);
		createFlowletCommand.setChild(flowlet);
		Rectangle constraint = flowletRect;
		//(Rectangle)getConstraintFor(request);
		createFlowletCommand.setLocation(constraint);

		return createFlowletCommand;
	}

}

⌨️ 快捷键说明

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