modeleditpart.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 218 行
JAVA
218 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/edit/ModelEditPart.java,v 1.1.1.1 2004/07/01 09:07:47 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:47 $
*
* ====================================================================
*
* 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.edit;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.*;
import org.eclipse.gef.requests.DropRequest;
import com.webpump.ui.gefmodule.figure.NodeFigure;
import com.webpump.ui.gefmodule.model.ModelSubpart;
import com.webpump.ui.gefmodule.model.Task;
/**
* Class for ModelEditPart
*
* @author shi_l
* @version 2.0.0 2004-5-30
*/
abstract public class ModelEditPart
extends org.eclipse.gef.editparts.AbstractGraphicalEditPart
implements NodeEditPart, PropertyChangeListener {
/**accessible editpart*/
private AccessibleEditPart acc;
/**
* activate
*/
public void activate() {
if (isActive())
return;
super.activate();
getModelSubpart().addPropertyChangeListener(this);
}
/**
* create edit policies
*/
protected void createEditPolicies() {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new ModelElementEditPolicy());
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ModelNodeEditPolicy());
}
/**
* create accessible
* @return AccessibleEditPart
*/
abstract protected AccessibleEditPart createAccessible();
/**
* Makes the EditPart insensible to changes in the model
* by removing itself from the model's list of listeners.
*/
public void deactivate() {
if (!isActive())
return;
super.deactivate();
getModelSubpart().removePropertyChangeListener(this);
}
/**
* get accessible editpart
*/
protected AccessibleEditPart getAccessibleEditPart() {
if (acc == null)
acc = createAccessible();
return acc;
}
/**
* Returns the model associated with this as a ModelSubpart.
*
* @return The model of this as a ModelSubpart.
*/
protected ModelSubpart getModelSubpart() {
return (ModelSubpart) getModel();
}
/**
* Returns a list of connections for which this is the
* source.
*
* @return List of connections.
*/
protected List getModelSourceConnections() {
return getModelSubpart().getSourceConnections();
}
/**
* Returns a list of connections for which this is the
* target.
*
* @return List of connections.
*/
protected List getModelTargetConnections() {
return getModelSubpart().getTargetConnections();
}
/**
* Returns the Figure of this, as a node type figure.
*
* @return Figure as a NodeFigure.
*/
protected NodeFigure getNodeFigure() {
return (NodeFigure) getFigure();
}
/**
* Returns the connection anchor for the given
* ConnectionEditPart's source.
*
* @return ConnectionAnchor.
*/
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connEditPart) {
Task task = (Task) connEditPart.getModel();
return getNodeFigure().getConnectionAnchor(task.getSourceTerminal());
}
/**
* Returns the connection anchor of a source connection which
* is at the given point.
*
* @return ConnectionAnchor.
*/
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
Point pt = new Point(((DropRequest) request).getLocation());
return getNodeFigure().getSourceConnectionAnchorAt(pt);
}
/**
* Returns the connection anchor for the given
* ConnectionEditPart's target.
*
* @return ConnectionAnchor.
*/
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connEditPart) {
Task task = (Task) connEditPart.getModel();
return getNodeFigure().getConnectionAnchor(task.getTargetTerminal());
}
/**
* Returns the connection anchor of a terget connection which
* is at the given point.
*
* @return ConnectionAnchor.
*/
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
Point pt = new Point(((DropRequest) request).getLocation());
return getNodeFigure().getTargetConnectionAnchorAt(pt);
}
/**
* Returns the name of the given connection anchor.
*
* @return The name of the ConnectionAnchor as a String.
*/
final protected String mapConnectionAnchorToTerminal(ConnectionAnchor c) {
return getNodeFigure().getConnectionAnchorName(c);
}
/**
* Handles changes in properties of this. It is
* activated through the PropertyChangeListener.
* It updates children, source and target connections,
* and the visuals of this based on the property
* changed.
*
* @param evt Event which details the property change.
*/
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (ModelSubpart.CHILDREN.equals(prop))
refreshChildren();
else if (ModelSubpart.INPUTS.equals(prop))
refreshTargetConnections();
else if (ModelSubpart.OUTPUTS.equals(prop))
refreshSourceConnections();
else if (prop.equals(ModelSubpart.ID_SIZE) || prop.equals(ModelSubpart.ID_LOCATION))
refreshVisuals();
}
/**
* Updates the visual aspect of this.
*/
protected void refreshVisuals() {
Point loc = getModelSubpart().getLocation();
Dimension size = getModelSubpart().getSize();
Rectangle r = new Rectangle(loc, size);
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), r);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?