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

📄 designermodeldigester.java

📁 一个java写的business process management系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 2003-2004, 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.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import net.orthanc.flow4j.designer.editparts.policies.Flow4XYLayoutEditPolicy;
import net.orthanc.flow4j.designer.figures.AnchorRegistry;
import net.orthanc.flow4j.designer.model.commands.ConnectionCommand;
import net.orthanc.flow4j.designer.model.commands.CreateBendpointCommand;
import net.orthanc.flow4j.designer.model.commands.CreateCommand;
import net.orthanc.flow4j.model.AbstractModelDigester;
import net.orthanc.flow4j.model.bind.BendpointBind;
import net.orthanc.flow4j.model.bind.BooleanTransitionBind;
import net.orthanc.flow4j.model.bind.CallFlowletBind;
import net.orthanc.flow4j.model.bind.DecisionFlowletBind;
import net.orthanc.flow4j.model.bind.EndFlowletBind;
import net.orthanc.flow4j.model.bind.FlowModelBind;
import net.orthanc.flow4j.model.bind.FlowletLabelBind;
import net.orthanc.flow4j.model.bind.IFlowletBind;
import net.orthanc.flow4j.model.bind.ILocationHolder;
import net.orthanc.flow4j.model.bind.JavaTaskFlowletBind;
import net.orthanc.flow4j.model.bind.JoinFlowletBind;
import net.orthanc.flow4j.model.bind.JumpFlowletBind;
import net.orthanc.flow4j.model.bind.PropertyBind;
import net.orthanc.flow4j.model.bind.ScriptTaskFlowletBind;
import net.orthanc.flow4j.model.bind.StartFlowletBind;
import net.orthanc.flow4j.model.bind.TemplateFlowletBind;
import net.orthanc.flow4j.model.bind.TransitionBind;
import net.orthanc.flow4j.model.bind.TransitionSourceFlowletBind;
import net.orthanc.flow4j.model.bind.TransitionTargetFlowletBind;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gef.requests.SimpleFactory;

/**
 * @author greifa
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class DesignerModelDigester extends AbstractModelDigester {

	private FlowDiagramModelPart flowDiagramModelPart;

	private CompoundCommand createCommand = new CompoundCommand();
	private Map transitionBindToTransitionMapping = new HashMap();
	private Map flowletToFlowletBindMapping = new HashMap();
	private Map flowletIdToFlowletMapping = new HashMap();


	/**
	 * Creates a new digester with the given FlowDiagramModelPart.
	 * It can be an empty FlowDiagramModelPart or a filled one that was just unmarshalled.
	 * 
	 * @param flowDiagramModelPart the flowDiagramModelPart
	 */
	public DesignerModelDigester(FlowDiagramModelPart flowDiagramModelPart) {
		super();
		this.flowDiagramModelPart = flowDiagramModelPart;
	}


	/**
	 * Returns the CompoundComand that is responsible for the creation of all 
	 * EditParts and Figures and so on.
	 * @return the CompoundCommand Which creates all necessary parts for the flowDiagram
	 */
	public CompoundCommand getCreateCommand() {
		return createCommand;
	}


	/**
	 * Digests the flowname attribute.
	 * @see net.orthanc.flow4j.model.IModelDigester#digest(net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	public void digest(FlowModelBind flowModelBind) {
		flowDiagramModelPart.setFlowName(flowModelBind.getFlowName());
		super.digest(flowModelBind);
	}



	/**
	 * @param flowlet
	 * @param flowModel
	 */
	protected void digestStartFlowlet(StartFlowletBind flowletBind, FlowModelBind flowModelBind) {
		CreateRequest request = new CreateRequest();
		request.setFactory(new SimpleFactory(StartFlowletModelPart.class));

		Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
		Rectangle labelRect =
			new Rectangle(flowletBind.getLabel().getX(), flowletBind.getLabel().getY(), 0, 0);

		CompoundCommand command =
			Flow4XYLayoutEditPolicy.getCreateFlowletWithLabelCommand(
				request,
				flowDiagramModelPart,
				flowletRect,
				labelRect,
				flowletBind.getLabel().getText());
		StartFlowletModelPart startFlowletModelpart = (StartFlowletModelPart)((CreateCommand)command.getChildren()[0]).getChild();

		//	set the start's properties
		Map startProperties = new HashMap();
		if (flowletBind.getProperties() != null) {
			for (Iterator iter = flowletBind.getProperties().iterator(); iter.hasNext(); ) {
				PropertyBind taskPropBind = (PropertyBind)iter.next();
				startProperties.put(taskPropBind.getName(), taskPropBind.getValue());
			}			
		}
		startFlowletModelpart.setStartProperties(startProperties);

		flowletToFlowletBindMapping.put(startFlowletModelpart, flowletBind);
		flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), startFlowletModelpart);

		createCommand.add(command);
	}


	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestCallFlowlet(net.orthanc.flow4j.model.bind.CallFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestCallFlowlet(
		CallFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			CreateRequest request = new CreateRequest();
			request.setFactory(new SimpleFactory(CallFlowletModelPart.class));

			Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
			Rectangle labelRect =
				new Rectangle(flowletBind.getLabel().getX(), flowletBind.getLabel().getY(), 0, 0);

			CompoundCommand command =
				Flow4XYLayoutEditPolicy.getCreateFlowletWithLabelCommand(
					request,
					flowDiagramModelPart,
					flowletRect,
					labelRect,
					flowletBind.getLabel().getText());
			FlowDiagramElementModelPart flowletModelpart = ((CreateCommand)command.getChildren()[0]).getChild();
			flowletToFlowletBindMapping.put(flowletModelpart, flowletBind);
			flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), flowletModelpart);

			createCommand.add(command);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestDecisionFlowlet(net.orthanc.flow4j.model.bind.DecisionFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestDecisionFlowlet(
		DecisionFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			CreateRequest request = new CreateRequest();
			request.setFactory(new SimpleFactory(DecisionFlowletModelPart.class));

			Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
			Rectangle labelRect =
				new Rectangle(flowletBind.getLabel().getX(), flowletBind.getLabel().getY(), 0, 0);

			CompoundCommand command =
				Flow4XYLayoutEditPolicy.getCreateFlowletWithLabelCommand(
					request,
					flowDiagramModelPart,
					flowletRect,
					labelRect,
					flowletBind.getLabel().getText());
			DecisionFlowletModelPart decisionFlowletModelpart = (DecisionFlowletModelPart)((CreateCommand)command.getChildren()[0]).getChild();
			decisionFlowletModelpart.setDescription(flowletBind.getDescription());
		
			flowletToFlowletBindMapping.put(decisionFlowletModelpart, flowletBind);
			flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), decisionFlowletModelpart);

			createCommand.add(command);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestEndFlowlet(net.orthanc.flow4j.model.bind.EndFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestEndFlowlet(
		EndFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			CreateRequest request = new CreateRequest();
			request.setFactory(new SimpleFactory(EndFlowletModelPart.class));

			Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
			FlowletModelPart flowletModelpart = (FlowletModelPart)request.getNewObject();

			Command command =
				Flow4XYLayoutEditPolicy.getCreateFlowletCommand(
					request,
					flowDiagramModelPart,
					flowletRect,
					flowletModelpart);
			flowletToFlowletBindMapping.put(flowletModelpart, flowletBind);
			flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), flowletModelpart);

			createCommand.add(command);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestJavaTaskFlowlet(net.orthanc.flow4j.model.bind.JavaTaskFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestJavaTaskFlowlet(
		JavaTaskFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			CreateRequest request = new CreateRequest();
			request.setFactory(new SimpleFactory(JavaTaskFlowletModelPart.class));

			Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
			Rectangle labelRect =
				new Rectangle(flowletBind.getLabel().getX(), flowletBind.getLabel().getY(), 0, 0);

			CompoundCommand command =
				Flow4XYLayoutEditPolicy.getCreateFlowletWithLabelCommand(
					request,
					flowDiagramModelPart,
					flowletRect,
					labelRect,
					flowletBind.getLabel().getText());
			JavaTaskFlowletModelPart taskFlowletModelpart = (JavaTaskFlowletModelPart)((CreateCommand)command.getChildren()[0]).getChild();
		
			//	set the task's properties
			Map taskProperties = new HashMap();
			if (flowletBind.getProperties() != null) {
				for (Iterator iter = flowletBind.getProperties().iterator(); iter.hasNext();) {
					PropertyBind taskPropBind = (PropertyBind) iter.next();
					taskProperties.put(taskPropBind.getName(), taskPropBind.getValue());
				}			
			}
			taskFlowletModelpart.setTaskProperties(taskProperties);
		
			flowletToFlowletBindMapping.put(taskFlowletModelpart, flowletBind);
			flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), taskFlowletModelpart);

			createCommand.add(command);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestJoinFlowlet(net.orthanc.flow4j.model.bind.JoinFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestJoinFlowlet(
		JoinFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			CreateRequest request = new CreateRequest();
			request.setFactory(new SimpleFactory(JoinFlowletModelPart.class));

			Rectangle flowletRect = new Rectangle(flowletBind.getX(), flowletBind.getY(), 0, 0);
			FlowletModelPart flowletModelpart = (FlowletModelPart)request.getNewObject();

			Command command =
				Flow4XYLayoutEditPolicy.getCreateFlowletCommand(
					request,
					flowDiagramModelPart,
					flowletRect,
					flowletModelpart);
			flowletToFlowletBindMapping.put(flowletModelpart, flowletBind);
			flowletIdToFlowletMapping.put(flowletBind.getId(flowModelBind), flowletModelpart);

			createCommand.add(command);
	}

	/* (non-Javadoc)

⌨️ 快捷键说明

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