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

📄 childeditpart.java

📁 对eclipse gef进行封装,可以生成图形化编辑器
💻 JAVA
字号:
/*******************************************************************************
 * $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/parts/ChildEditPart.java,v 1.6 2006/12/30 02:45:04 niegy Exp $
 * $Revision: 1.6 $
 * $Date: 2006/12/30 02:45:04 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2006-11-17
 *******************************************************************************/


package com.primeton.studio.gef.ui.parts;

import java.util.Collections;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;

import com.primeton.studio.gef.core.CorePackage;
import com.primeton.studio.gef.core.NodeElement;
import com.primeton.studio.gef.ui.editor.AbstractGraphicalEditor;
import com.primeton.studio.gef.ui.figure.ChildFigure;

/**
 * TODO 此处填写 class 信息
 *
 * @author niegy (mailto:niegy@primeton.com)
 */
/*
 * 修改历史
 * $Log: ChildEditPart.java,v $
 * Revision 1.6  2006/12/30 02:45:04  niegy
 * 重构代码
 *
 * Revision 1.5  2006/12/08 07:04:32  niegy
 * 重构代码
 *
 * Revision 1.4  2006/12/05 05:18:59  niegy
 * 修改模型,增加连线的扩展点
 *
 * Revision 1.3  2006/11/23 02:42:21  niegy
 * table
 *
 * Revision 1.2  2006/11/22 07:07:38  niegy
 * 增加table
 *
 * Revision 1.1  2006/11/18 12:13:53  niegy
 * 增加容器模型
 * 
 */
public class ChildEditPart extends NodeEditPartEx {

	/**
	 * @param editor
	 */
	public ChildEditPart(AbstractGraphicalEditor editor) {
		super(editor);
		// TODO Auto-generated constructor stub
	}

	 protected IFigure createFigureForModel() {
         IFigure fig = new ChildFigure();  
         return fig;    
     }

	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#refreshVisuals()
	 */
	
	protected void refreshVisuals() {
		// TODO Auto-generated method stub
		super.refreshVisuals();
		NodeElement nodeElement = (NodeElement) getModel();
		if(getFigure() instanceof ChildFigure){
			ChildFigure figure = (ChildFigure) getFigure();
		    figure.setText(nodeElement.getName());
		}
	}

	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#activate()
	 */
	
	public void activate() {
		// TODO Auto-generated method stub
		if (!isActive()) {
			if(!isChild())
				hookIntoModel((EObject)getParent().getModel());
			super.activate();
		}
	}

	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#deactivate()
	 */
	
	public void deactivate() {
		// TODO Auto-generated method stub
		 if (isActive()) {
			 if(!isChild())
				 unhookFromModel((EObject)getParent().getModel());
	         super.deactivate();
	        }
	}
	 
	public void notifyChanged(Notification notification) {		
        int type = notification.getEventType();
        int featureId = notification.getFeatureID(CorePackage.class);
        switch(type) {
        case Notification.SET:
            switch(featureId) {
            case CorePackage.NODE_ELEMENT__COLLAPSED:
            	  refreshSourceConnections();
                  refreshTargetConnections();
                  break;
            }
        }
        
        super.notifyChanged(notification);
	}

	private boolean isChild(){
		if(getParent() instanceof DiagramEditPart)
			return true;
		if(getParent() instanceof CompartmentEditPart)
			return true;
		return false;
	}
	
	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#getModelSourceConnections()
	 */	
	protected List getModelSourceConnections() {
		// TODO Auto-generated method stub
		if(getParent() == null)
			 return Collections.EMPTY_LIST;
		if(isChild())
			return super.getModelSourceConnections();
		NodeElement parent = (NodeElement)getParent().getModel();
		if (!parent.isCollapsed()) {
            return super.getModelSourceConnections();
        } else {
            return Collections.EMPTY_LIST;
        }     
	}

	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#getModelTargetConnections()
	 */
	
	protected List getModelTargetConnections() {
		// TODO Auto-generated method stub
		if(getParent() == null)
			 return Collections.EMPTY_LIST;
		if(isChild())
			return super.getModelTargetConnections();
		NodeElement parent = (NodeElement)getParent().getModel();
		if (!parent.isCollapsed()) {
            return super.getModelTargetConnections();
        } else {
            return Collections.EMPTY_LIST;
        }     
	}

	/* (non-Javadoc)
	 * @see com.primeton.studio.gef.ui.parts.NodeEditPartEx#createEditPolicies()
	 */
	
	protected void createEditPolicies() {
		// TODO Auto-generated method stub
		super.createEditPolicies();
	}   
        
	
	
}

⌨️ 快捷键说明

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