modelsubpart.java

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

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

import java.util.Enumeration;
import java.util.Vector;

import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

/**
 * Class for ModelSubpart
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
abstract public class ModelSubpart extends ModelElement {

	/**id*/
	private String id;

	/**inputs*/
	protected Vector inputs = new Vector(4, 4);

	/**location*/
	protected Point location = new Point(0, 0);

	/**outputs*/
	protected Vector outputs = new Vector(4, 4);

	/**size*/
	protected Dimension size = new Dimension(-1, -1);

	/**descriptors*/
	protected static IPropertyDescriptor[] descriptors = null;

	/**id of the size*/
	public static String ID_SIZE = "size"; //$NON-NLS-1$

	/**id of the location*/
	public static String ID_LOCATION = "location"; //$NON-NLS-1$

	static {
		descriptors = new IPropertyDescriptor[0];
	}

	/**
	 * constructor
	 */
	public ModelSubpart() {
		setID(getNewID());
	}

	/**
	 * connect input
	 * @param w Task
	 */
	public void connectInput(Task w) {
		inputs.addElement(w);
		update();
		fireStructureChange(INPUTS, w);
	}

	/**
	 * connect output
	 * @param w Task
	 */
	public void connectOutput(Task w) {
		outputs.addElement(w);
		update();
		fireStructureChange(OUTPUTS, w);
	}

	/**
	 * disconnect input
	 * @param w Task
	 */
	public void disconnectInput(Task w) {
		inputs.remove(w);
		update();
		fireStructureChange(INPUTS, w);
	}

	/**
	 * disconnect output
	 * @param w Task
	 */
	public void disconnectOutput(Task w) {
		outputs.removeElement(w);
		update();
		fireStructureChange(OUTPUTS, w);
	}

	/**
	 * get connections
	 * @return connections Vector
	 */
	public Vector getConnections() {
		Vector v = (Vector) outputs.clone();
		Enumeration ins = inputs.elements();
		while (ins.hasMoreElements())
			v.addElement(ins.nextElement());
		return v;
	}

	/**
	 * get icon
	 * @return icon Image
	 */
	public Image getIcon() {
		return getIconImage();
	}

	/**
	 * get icon image
	 * @return Image
	 */
	abstract public Image getIconImage();

	/**
	 * get id
	 * @return id String
	 */
	public String getID() {
		return id;
	}
	/*
	protected boolean getInput(String terminal) {
		Task w = (Task)inputs.get(terminal);
		return (w == null) ? false : w.getValue();
	}
	*/

	/**
	 * get location
	 * @return location
	 */
	public Point getLocation() {
		return location;
	}

	/**
	 * get new id
	 * @return String
	 */
	abstract protected String getNewID();

	/**
	 * Returns useful property descriptors for the use
	 * in property sheets. this supports location and
	 * size.
	 *
	 * @return  Array of property descriptors.
	 */
	public IPropertyDescriptor[] getPropertyDescriptors() {
		return descriptors;
	}

	/**
	 * get size
	 * @return size Dimension
	 */
	public Dimension getSize() {
		return size;
	}

	/**
	 * get source connections
	 * @return outputs Vector
	 */
	public Vector getSourceConnections() {
		return (Vector) outputs.clone();
	}

	/**
	 * get target connections
	 * @return inputs Vector
	 */
	public Vector getTargetConnections() {
		/*	Enumeration enum = inputs.elements();
			Vector v = new Vector(inputs.size());
			while (enum.hasMoreElements())
				v.addElement(enum.nextElement());
			return v;*/
		return (Vector) inputs.clone();
	}

	/**
	 * is property set
	 * @return true
	 */
	public boolean isPropertySet() {
		return true;
	}

	/*
	 * Does nothing for the present, but could be
	 * used to reset the properties of this to 
	 * whatever values are desired.
	 *
	 * @param id  Parameter which is to be reset.
	 *
	public void resetPropertyValue(Object id){
		if(ID_SIZE.equals(id)){;}
		if(ID_LOCATION.equals(id)){;}
	}
	*/

	/**
	 * set id
	 * @param s String
	 */
	public void setID(String s) {
		id = s;
	}

	/**
	 * set location
	 * @param p Point
	 */
	public void setLocation(Point p) {
		if (location.equals(p))
			return;
		location = p;
		firePropertyChange("location", null, p); //$NON-NLS-1$
	}

	/**
	 * set output
	 * @param terminal String
	 * @param val boolean
	 */
	protected void setOutput(String terminal, boolean val) {
		Enumeration enum = outputs.elements();
		Task w;
		while (enum.hasMoreElements()) {
			w = (Task) enum.nextElement();
			if (w.getSourceTerminal().equals(terminal) && this.equals(w.getSource()))
				w.setValue(val);
		}
	}

	/**
	 * set size
	 * @param d Dimension
	 */
	public void setSize(Dimension d) {
		if (size.equals(d))
			return;
		size = d;
		firePropertyChange("size", null, size); //$NON-NLS-1$
	}
}

⌨️ 快捷键说明

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