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

📄 javataskflowletlabeleditpart.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;

import java.beans.PropertyChangeEvent;

import net.orthanc.flow4j.base.Util;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.figures.FlowletLabelFigure;
import net.orthanc.flow4j.designer.figures.JavaTaskFlowletToolTipFigure;
import net.orthanc.flow4j.designer.model.FlowletLabelModelPart;
import net.orthanc.flow4j.designer.model.propertysources.TaskPropertyPropertySource;
import net.orthanc.flow4j.runtime.ITaskFlowlet;

import org.eclipse.draw2d.Label;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchPage;

/**
 * Edit part for the TaskFlowletLabel.
 * Checks for the executable class. If it's found then the task's name is 
 * displayed in black, otherwise the classname is displayed in red.
 * @author alex
 */
public class JavaTaskFlowletLabelEditPart
	extends FlowletLabelEditPart
	implements IPerspectiveListener {

	static private final Color TASK_CLASS_NOT_FOUND_COLOR =
		new Color(null, 255, 0, 0);
	static private final Color TASK_CLASS_FOUND_COLOR =
		new Color(null, 0, 0, 0);

	//private FlowletLabelFigure flowletLabelFigure;

	/**
	 * Activates the edit part and updates the flowlet's tooltip's classname property.
	 * This will be the initial value of the tooltip.
	 * @see org.eclipse.gef.EditPart#activate()
	 */
	public void activate() {
		if (isActive())
			return;
		super.activate();
		//	update flowlet's tooltip
		JavaTaskFlowletEditPart taskFlowletEditPart = getTaskFlowletEditPart();
		IFlow4JToolTip toolTip =
			taskFlowletEditPart.getFlowDiagramElementToolTip();
		String className = ((FlowletLabelModelPart) getModel()).getText();
		toolTip.update(
			JavaTaskFlowletToolTipFigure.TOOLTIP_PROP_CLASSNAME,
			className);
			
		//	task label may contain parameterized property references

		taskFlowletEditPart.getJavaTaskFlowlet().addPropertyChangeListener(this);
	}

	/**
	 * Convenience method to return the Task FlowletWithLabelEditPart.
	 * @return  the Task FlowletWithLabelEditPart.
	 */
	private JavaTaskFlowletEditPart getTaskFlowletEditPart() {
		return (JavaTaskFlowletEditPart) getFlowletWithLabelEditPart();
	}

	/**
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	/*protected IFigure createFigure() {
		if (getModel() == null)
			return null;
	
		FlowletLabelFigure flowletLabelFigure =
			(FlowletLabelFigure) Flow4FigureFactory.createFlowletLabelFigure();
		adjustFlowletLabelFigure(flowletLabelFigure);
		return flowletLabelFigure;
	}*/

	/**
	 * Returns the fully qualified class name of the Task Flowlet.
	 * It is the text property of the Flowlet Label Modelpart
	 * @return the fully qualified class name of the Task Flowlet.
	 */
	private String getTaskClassName() {
		return ((FlowletLabelModelPart) getModel()).getText();
	}

	/**
	 * Reacts on the change of the label's text.
	 * Also updates the flowlet's tooltip.
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	public void propertyChange(PropertyChangeEvent event) {
		String propName = event.getPropertyName();
		if (FlowletLabelModelPart.PROP_LABEL.equals(propName)) {
			String taskClassName = (String) event.getNewValue();

			adjustFlowletLabelFigure((FlowletLabelFigure) getFigure());
			//	update JavaTaskFlowletEditPart's tooltip
			JavaTaskFlowletEditPart taskFlowletEditPart = getTaskFlowletEditPart();
			IFlow4JToolTip toolTip =
				taskFlowletEditPart.getFlowDiagramElementToolTip();
			toolTip.update(
				JavaTaskFlowletToolTipFigure.TOOLTIP_PROP_CLASSNAME,
				taskClassName);
		} else
		if (TaskPropertyPropertySource.PROP_TASK_PROPERTY_VALUE.equals(propName)) {
			//	task label may contain parameterized property references
			adjustFlowletLabelFigure((FlowletLabelFigure) getFigure());
		} else
			super.propertyChange(event);
	}

	/**
	 * Sets the label's text and color.
	 * If the editor is not open yet, then a listener for the open
	 * window action is registered and the label is updated later.
	 * @param flowletLabelFigure the figure of the label
	 */
	protected void adjustFlowletLabelFigure(FlowletLabelFigure flowletLabelFigure) {
		String labelText = getTaskClassName();
		Color labelColor = TASK_CLASS_NOT_FOUND_COLOR;

		try {
/*			List runtimeLibs = new ArrayList();
			IJavaProject javaProject = Flow4JPlugin.getJavaProject(((FlowDiagramEditPart) getParent()).getFlowFile().getProject());
			List classpathList = new ArrayList();
			Flow4JPlugin.getResolvedClasspath(Flow4JPlugin.getProject(javaProject), classpathList);
			for (Iterator iter = classpathList.iterator(); iter.hasNext();) {
				IPath path = (IPath) iter.next();
				runtimeLibs.add(path.toFile().toURL());
			}
			ITaskFlowlet taskInstance = getTaskFlowletEditPart().getTaskFlowlet().getTaskFlowletInstance(getTaskClassName(), runtimeLibs);
*/

			IJavaProject javaProject = Flow4JPlugin.getJavaProject(((FlowDiagramEditPart) getParent()).getFlowFile().getProject());
			//ITaskFlowlet taskInstance = Flow4JPlugin.getTaskFlowletInstance(getTaskClassName(), javaProject);
			ITaskFlowlet taskInstance = getTaskFlowletEditPart().getJavaTaskFlowlet().getTaskFlowletInstance(getTaskClassName(), javaProject);

			//	set the label's text to the Task Flowlet's name
			if (taskInstance.getName() != null)
				labelText = Util.replaceProperties(taskInstance.getName(),
								getTaskFlowletEditPart().getJavaTaskFlowlet().getTaskProperties());
			labelColor = TASK_CLASS_FOUND_COLOR;



/*			IEditorPart activeEditor = Flow4JPlugin.getActiveEditor();
			if (activeEditor != null
				&& (activeEditor instanceof FlowEditor)
				&& ((FlowEditor) activeEditor).getFlowFile().equals(
					((FlowDiagramEditPart) getParent()).getFlowFile())) {

				ITaskFlowlet taskInstance = getTaskFlowletEditPart().getTaskFlowlet().getTaskFlowletInstance(getTaskClassName());

				//	set the label's text to the Task Flowlet's name
				labelText = Util.replaceProperties(taskInstance.getName(),getTaskFlowletEditPart().getTaskFlowlet().getTaskProperties());
				labelColor = TASK_CLASS_FOUND_COLOR;
			} else {
				//	editor is not open yet, add this as listener and set the labels later
				Flow4JPlugin.getActiveWorkbenchWindow().addPerspectiveListener(
					this);
			}
*/
		} catch (ClassNotFoundException e) {
			//	class not found
		} catch (Error e) {
			//	can happen if a task, that has compilation errors,
			//	is dragged in the flow editor
		} catch (Throwable e) {
			Flow4JPlugin.log(e);
		}
		//	set the figure's text
		flowletLabelFigure.setText(labelText);
		flowletLabelFigure.setForegroundColor(labelColor);

	}

	/**
	 * Does nothing currently.
	 * @see org.eclipse.ui.IPerspectiveListener#perspectiveActivated(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor)
	 */
	public void perspectiveActivated(
		IWorkbenchPage page,
		IPerspectiveDescriptor perspective) {
		// TODO Auto-generated method stub
	}

	/**
	 * Sets the color and text if the editor is opened.
	 * @see org.eclipse.ui.IPerspectiveListener#perspectiveChanged(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor, java.lang.String)
	 */
	public void perspectiveChanged(
		IWorkbenchPage page,
		IPerspectiveDescriptor perspective,
		String changeId) {
		if (IWorkbenchPage.CHANGE_EDITOR_OPEN.equals(changeId)
			|| IWorkbenchPage.CHANGE_ACTION_SET_SHOW.equals(changeId)) {
			Flow4JPlugin.getActiveWorkbenchWindow().removePerspectiveListener(
				this);
			adjustFlowletLabelFigure((FlowletLabelFigure) getFigure());
		}
	}

	/**
	 * Returns the FlowletLabelEditManager for this type of EditPart.
	 * Sets the <code>forceDirty</code> flag to <code>true</code>
	 * because the edit text differs from the display text.
	 * @return the FlowletLabelEditManager for this type of EditPart.
	 * @see net.orthanc.flow4j.designer.editparts.FlowletLabelEditPart#getFlowletLabelEditManager()
	 */
	protected FlowletLabelEditManager getFlowletLabelEditManager() {
		return new FlowletLabelEditPart.FlowletLabelEditManager(
			this,
			new LabelCellEditorLocator((Label) getFigure()),
			true);
	}

	/**
	 * The direct edit manager for the flowlet's label.
	 * The extra feature here is that the flowlet's name should be 
	 * displayed if it was displayed before and no change performed
	 * while direct editing.
	 * @author alex
	 * /
	private class TaskFlowletLabelEditManager
		extends FlowletLabelEditPart.FlowletLabelEditManager {
	
		/ **	we  retreive the original text from here * /
		private FlowletLabelEditPart.LabelCellEditorLocator locator;
	
		/ **
		 * Contstructor of the inner class
		 * @param source the source edit part
		 * @param locator the cell editor
		 * /
		public TaskFlowletLabelEditManager(
			GraphicalEditPart source,
			LabelCellEditorLocator locator) {
			super(source, locator);
			this.locator = locator;
		}
	
		/ **
		 * Sets the flowlets name if the classname did not change.
		 * @see org.eclipse.gef.tools.DirectEditManager#commit()
		 * /
		protected void commit() {
			if (!isDirty()) {
				Text text = (Text) getCellEditor().getControl();
				//	set to the original Text
				getCellEditor().setValue(locator.getLabel().getText());
				setDirty(true);
			}
			super.commit();
		}
	}
	*/
}

⌨️ 快捷键说明

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