📄 diagramtreeeditpart.java
字号:
/*******************************************************************************
* $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/parts/DiagramTreeEditPart.java,v 1.4 2006/12/30 02:45:04 niegy Exp $
* $Revision: 1.4 $
* $Date: 2006/12/30 02:45:04 $
*
*==============================================================================
*
* Copyright (c) 2001-2006 Primeton Technologies, Ltd.
* All rights reserved.
*
* Created on 2006-9-28
*******************************************************************************/
package com.primeton.studio.gef.ui.parts;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.editparts.AbstractTreeEditPart;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
import com.primeton.studio.gef.core.Diagram;
import com.primeton.studio.gef.core.NodeElement;
import com.primeton.studio.gef.core.NodeElementLabel;
/**
* TODO此处填写 class 信息
*
* @author niegy (mailto:niegy@primeton.com)
*/
/*
* 修改历史
* $Log: DiagramTreeEditPart.java,v $
* Revision 1.4 2006/12/30 02:45:04 niegy
* 重构代码
*
* Revision 1.3 2006/12/16 09:04:42 niegy
* 重构代码
*
* Revision 1.2 2006/12/12 08:26:39 niegy
* 重构代码,实现一般图元的编辑框
*
* Revision 1.1 2006/11/17 03:15:13 niegy
* create
*
*/
public class DiagramTreeEditPart extends AbstractTreeEditPart implements
Adapter {
private Notifier target;
/**
* Create a new instance of this edit part using the given model element.
* @param model a non-null ShapesDiagram instance
*/
public DiagramTreeEditPart(Diagram model) {
super(model);
}
/**
* Upon activation, attach to the model element as a property change listener.
*/
public void activate() {
if (!isActive()) {
hookIntoModel(getCastedModel());
super.activate();
}
}
/* (non-Javadoc)
* @see org.eclipse.gef.examples.shapes.parts.DataFlowTreeEditPart#createEditPolicies()
*/
protected void createEditPolicies() {
// If this editpart is the root content of the viewer, then disallow removal
if (getParent() instanceof RootEditPart) {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
}
}
/**
* Upon deactivation, detach from the model element as a property change listener.
*/
public void deactivate() {
if (isActive()) {
unhookFromModel(getCastedModel());
super.deactivate();
}
}
private void hookIntoModel(EObject model) {
if(model != null) {
model.eAdapters().add(this);
}
}
private void unhookFromModel(EObject model) {
if(model != null) {
model.eAdapters().remove(this);
}
}
private Diagram getCastedModel() {
return (Diagram) getModel();
}
/**
* Convenience method that returns the EditPart corresponding to a given child.
* @param child a model element instance
* @return the corresponding EditPart or null
*/
private EditPart getEditPartForChild(Object child) {
return (EditPart) getViewer().getEditPartRegistry().get(child);
}
/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
*/
protected List getModelChildren() {
List list = new ArrayList();
for (Iterator iter = getCastedModel().getNodes().iterator(); iter.hasNext();) {
NodeElement element = (NodeElement) iter.next();
if(!(element instanceof NodeElementLabel))
list.add(element);
}
return list; // a list of shapes
}
public void notifyChanged(Notification notification) {
int type = notification.getEventType();
// int featureId = notification.getFeatureID(ModelPackage.class);
// switch(featureId) {
// case ModelPackage.SHAPES_DIAGRAM__SHAPES:
switch(type) {
case Notification.ADD:
if(!(notification.getNewValue() instanceof NodeElementLabel))
addChild(createChild(notification.getNewValue()), -1);
break;
case Notification.REMOVE:
EditPart part = getEditPartForChild(notification.getOldValue());
if(part != null)
removeChild(part);
break;
}
// }
}
public Notifier getTarget() {
return target;
}
public void setTarget(Notifier newTarget) {
target = newTarget;
}
public boolean isAdapterForType(Object type) {
return getModel() == type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -