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

📄 javataskflowletmodelpart.java

📁 一个java写的business process management系统
💻 JAVA
字号:
/*
 * 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.beans.PropertyChangeEvent;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import net.orthanc.flow4j.Flow4JConsts;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.model.propertydescriptors.ROTextPropertyDescriptor;
import net.orthanc.flow4j.designer.model.propertysources.TaskIOParametersPropertySource;
import net.orthanc.flow4j.designer.model.propertysources.TaskPropertiesPropertySource;
import net.orthanc.flow4j.designer.model.propertysources.TaskPropertyPropertySource;
import net.orthanc.flow4j.runtime.ITaskFlowlet;
import net.orthanc.flow4j.runtime.descriptors.TaskPropertyDescriptors;

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.ui.views.properties.PropertyDescriptor;

/**
 *
 * Task flowlet model part.
 * @author agreif
 */
public class JavaTaskFlowletModelPart extends AbstractTaskFlowletModelPart {

	public static final String PROP_JAVATASK_DESCRIPTION = "javatask_description"; //$NON-NLS-1$
	public static final String PROP_JAVATASK_PROPERTIES = "javatask_properties"; //$NON-NLS-1$
	public static final String PROP_JAVATASK_PARAMETERS = "javatask_parameters"; //$NON-NLS-1$

	private HashSet taskFlowletPropertyDescriptors = null;

	/**
	 * Cretes a new instance and also the java task wrapper.
	 */
	public JavaTaskFlowletModelPart() {
		setTaskWrapper(new JavaTaskWrapper());
	}

	/**
	 * Returns the casted task wrapper.
	 * @return the casted task wrapper.
	 */
	private JavaTaskWrapper getJavaTaskWrapper() {
		return (JavaTaskWrapper)getTaskWrapper();
	}


	/**
	 * @see net.orthanc.flow4j.designer.model.FlowletModelPart#getType()
	 */
	public String getType() {
		return Flow4JConsts.JAVATASK;
	}

	/**
	 * Returns a Map that contains the tasks properties and their values.
	 * @return a Map that contains the tasks properties and their values.
	 */
	public Map getTaskProperties() {
		return getJavaTaskWrapper().getTaskProperties();
	}

	/**
	 * Sets a task property. Creates the properties Map if necessary.
	 * @param key the property key
	 * @param value the property value
	 */
	public void setTaskProperty(String key, String value) {
		JavaTaskWrapper taskWrapper = getJavaTaskWrapper();
		Object old = taskWrapper.getTaskProperty(key);
		taskWrapper.setTaskProperty(key, value);
		firePropertyChange(
			TaskPropertyPropertySource.PROP_TASK_PROPERTY_VALUE,
			old,
			value);
	}

	/**
	 * Returns a task property or <code>null</code> if the property is 
	 * not set or the task has no properties at all
	 * @param key the property key
	 * @return a task property or <code>null</code>
	 */
	public String getTaskProperty(String key) {
		return getJavaTaskWrapper().getTaskProperty(key);
	}

	/**
	 * Sets the tasks properties and their values.
	 * @param map Map containing the tasks properties and their values.
	 */
	public void setTaskProperties(Map map) {
		getJavaTaskWrapper().setTaskProperties(map);
	}

	/**
	 * Returns the name of the resource entry that contains the property name
	 * for the flowlet's label
	 * @return key in the resources file
	 * @see net.orthanc.flow4j.designer.model.FlowletWithLabelModelPart#getLabelPropertyNameResource()
	 */
	protected String getLabelPropertyNameResource() {
		return "PropertyDescriptor_JavaTaskFlowlet.label";
	}

	/**
	 * Collects all property descriptors. Those of
	 * the superclass and those of this class
	 * @return Collection with all Property descriptors
	 */
	protected Collection getPropertyDescriptorsCollection() {
		if (taskFlowletPropertyDescriptors == null)
			createPropertyDescriptors();

		return taskFlowletPropertyDescriptors;
	}

	/**
	 * Creates the property descriptors if they have not been
	 * created yet. The following descriptor is added:<br>
	 * ROTextPropertyDescriptor for the task's description
	 */
	private void createPropertyDescriptors() {
		if (taskFlowletPropertyDescriptors != null)
			return;

		taskFlowletPropertyDescriptors =
			new HashSet(super.getPropertyDescriptorsCollection());
/*
//	Peter Friese
				// replace the label property descriptor.
				for (Iterator iter = taskFlowletPropertyDescriptors.iterator();
					iter.hasNext();
					) {
					PropertyDescriptor descriptor =
						(PropertyDescriptor) iter.next();
					if (descriptor
						.getId()
						.equals(FlowletLabelModelPart.PROP_LABEL)) {
						iter.remove();
						taskFlowletPropertyDescriptors.add(
							new TypeLookupPropertyDescriptor(
								FlowletLabelModelPart.PROP_LABEL,
								Flow4JPlugin.getResourceString(
									getLabelPropertyNameResource())));
						break;
					}
				}
//		Peter Friese
*/






		taskFlowletPropertyDescriptors.add(
			new ROTextPropertyDescriptor(
				PROP_JAVATASK_DESCRIPTION,
				Flow4JPlugin.getResourceString(
					"PropertyDescriptor_TaskFlowlet_Description.label")));
		taskFlowletPropertyDescriptors.add(
			new PropertyDescriptor(
				PROP_JAVATASK_PROPERTIES,
				Flow4JPlugin.getResourceString(
					"PropertyDescriptor_TaskFlowlet_Properties.label")));
		taskFlowletPropertyDescriptors.add(
			new PropertyDescriptor(
				PROP_JAVATASK_PARAMETERS,
				Flow4JPlugin.getResourceString(
					"PropertyDescriptor_TaskFlowlet_Parameters.label")));
	}

	/**
	 * Returns an Object which represents the appropriate
	 * value for the property name supplied.
	 * In case of label property the request will be routed to the label modelPart.
	 *
	 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
	 * @param propName  Name of the property for which the
	 *                  the values are needed.
	 * @return  Object which is the value of the property.
	 */
	public Object getPropertyValue(Object propName) {
		final String NA = "N/A";
		final String NONE = "[none]";
		ITaskFlowlet taskFlowlet = null;
		try {
			taskFlowlet = getTaskFlowletInstance(getFlowletLabel().getText());
		} catch (ClassNotFoundException e) {
		} catch (Throwable e) {
			Flow4JPlugin.log(e);
			return NA;
		}
		if (PROP_JAVATASK_DESCRIPTION.equals(propName)) {
			if (taskFlowlet == null)
				return NA;
			String desc = taskFlowlet.getDescription();
			return desc == null ? NONE : desc;
		} else if (PROP_JAVATASK_PROPERTIES.equals(propName)) {
			if (taskFlowlet == null)
				return NA;
			TaskPropertyDescriptors descs =
				taskFlowlet.getPropertyDescriptors();
			if (descs == null || descs.isEmpty())
				return NONE;
			return new TaskPropertiesPropertySource(this);
		} else if (PROP_JAVATASK_PARAMETERS.equals(propName)) {
			if (taskFlowlet == null)
				return NA;
			if ((taskFlowlet.getInputParameterDescriptors() == null
				|| taskFlowlet.getInputParameterDescriptors().isEmpty())
				&& (taskFlowlet.getOutputParameterDescriptors() == null
					|| taskFlowlet.getOutputParameterDescriptors().isEmpty()))
				return NONE;
			return new TaskIOParametersPropertySource(this);
		} else
			return super.getPropertyValue(propName);
	}

	/**
	 * Sets the value of a given property with the value
	 * supplied. Also fires a property change if necessary.
	 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
	 * @param id  Name of the parameter to be changed.
	 * @param value  Value to be set to the given parameter.
	 */
	public void setPropertyValue(Object id, Object value) {
		if (PROP_JAVATASK_PROPERTIES.equals(id)) {
			;
		} else
			super.setPropertyValue(id, value);
	}

	/**
	 * Returns the task flowlet instance that's class name is 
	 * the flowlet's label.
	 * @return the task flowlet instance, or throws a classNotFoundException.
	 * @throws ClassNotFoundException
	 */
	public ITaskFlowlet getTaskFlowletInstance()
		throws ClassNotFoundException, Throwable {
		return getTaskFlowletInstance(getFlowletLabel().getText());
	}

	/**
	 * Returns the task flowlet instance, or throws a ClassNotFoundException.
	 * @param taskClassName the calssname of the task flowlet
	 * @return the task flowlet instance, or throws a ClassNotFoundException.
	 * @throws ClassNotFoundException
	 */
	public ITaskFlowlet getTaskFlowletInstance(String taskClassName)
		throws ClassNotFoundException, Throwable {
			
		return getJavaTaskWrapper().getTaskFlowletInstance(taskClassName);
	}
	
	
	public ITaskFlowlet getTaskFlowletInstance(String taskClassName, List classpathURLs)
		throws ClassNotFoundException, Throwable {
			
		return getJavaTaskWrapper().getTaskFlowletInstance(taskClassName,classpathURLs);
	}

	public ITaskFlowlet getTaskFlowletInstance(String taskClassName, IJavaProject javaProject)
		throws ClassNotFoundException, Throwable {
			
		return getJavaTaskWrapper().getTaskFlowletInstance(taskClassName, javaProject);
	}












	/**
	 * Resets the taskProperties HashMap of this ModelPart to <code>null</code>
	 * because the class of the task has changed
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	public void propertyChange(PropertyChangeEvent event) {
		String propName = event.getPropertyName();
		if (FlowletLabelModelPart.PROP_LABEL.equals(propName)) {
			setTaskWrapper(new JavaTaskWrapper());
		} else
			super.propertyChange(event);
	}


}

⌨️ 快捷键说明

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