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

📄 nodeeditpartex.java

📁 对eclipse gef进行封装,可以生成图形化编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.gef.EditPart#understandsRequest(org.eclipse.gef.Request)
     */
    public boolean understandsRequest(Request req) {
        if(req.getType().equals(REQ_DIRECT_EDIT)) return true;
        
        return super.understandsRequest(req);
    }
    
    
    /**
     * Upon deactivation, detach from the model element as a property change listener.
     */
    public void deactivate() {
        if (isActive()) {
            unhookFromModel(getCastedModel());
            super.deactivate();
        }
    }
    
    protected NodeElement getCastedModel() {
        return (NodeElement) getModel();
    }
    
    
    public String getToolTipContent(){
        String ret=null;
        NodeElement nodeElement = getCastedModel();
        ret = "<p><b>Id:</b>" + nodeElement.getId() + "</p>";
        ret += "<p><b>Name:</b>" +nodeElement.getName() + "</p>";
        ret += "<p><b>Comment:</b>" + nodeElement.getDescription() + "</p>";
        return ret;
    }
    
    private void showToolTipOnTop(org.eclipse.swt.graphics.Point location){
        String toolTipContent=getToolTipContent();
        
        if(toolTipContent==null) return;
        
        final DefaultInformationControl infoControl = new DefaultInformationControl(getViewer().getControl().getShell(),
                SWT.BORDER | SWT.RESIZE, SWT.H_SCROLL | SWT.V_SCROLL | SWT.TITLE, 
                new HTMLTextPresenter(true),null);
        infoControl.setSizeConstraints(Integer.MAX_VALUE, Integer.MAX_VALUE);
        infoControl.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent e) {
                infoControl.dispose();  //失去焦点就释放
                isShowTipOnTop=false;
            }
        });
        infoControl.setInformation(toolTipContent);

        org.eclipse.swt.graphics.Point p=this.getViewer().getControl().toDisplay(location);

        Display display=getViewer().getControl().getDisplay();
        org.eclipse.swt.graphics.Rectangle displayBounds = display.getBounds();
        
        Point size=new Point(450,200);
        if (p.x + size.x > displayBounds.width) {
            p.x = displayBounds.width - size.x;
        }
        if (p.y + size.y > displayBounds.height) {
            p.y = p.y - size.y - 16;
        }
        infoControl.setLocation(p);
        infoControl.setSize(450,200);
        infoControl.setVisible(true);
        infoControl.setFocus();
        isShowTipOnTop=true;        
    }
    
    public boolean isShowTipOnTop(){
        return isShowTipOnTop;
    }
    
    public Object getAdapter(Class key) {
        if (IPropertySource.class == key)
            return new NodePropertySource(getModel(),editor.getPluginId());
        return super.getAdapter(key);
    }
    
    protected ConnectionAnchor getConnectionAnchor() {
        if (anchor == null) {
            if (getModel() instanceof NodeElement)//EllipticalShape)
                anchor = new ChopboxAnchor(getFigure());//EllipseAnchor(getFigure());
            else if(getModel() instanceof NodeElementLabel)
            	return null;
            else
                // if Shapes gets extended the conditions above must be updated
                throw new IllegalArgumentException("unexpected model");
        }
        return anchor;
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections()
     */
    protected List getModelSourceConnections() {
        return getCastedModel().getSourceConnections();
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections()
     */
    protected List getModelTargetConnections() {
        return getCastedModel().getTargetConnections();
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
     */
    public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
        return getConnectionAnchor();
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
     */
    public ConnectionAnchor getSourceConnectionAnchor(Request request) {
        return getConnectionAnchor();
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
     */
    public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
        return getConnectionAnchor();
    }
    
    /*
     * (non-Javadoc)
     * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
     */
    public ConnectionAnchor getTargetConnectionAnchor(Request request) {
        return getConnectionAnchor();
    }
    
    protected void refreshVisuals() {
        // notify parent container of changed position & location
        // if this line is removed, the XYLayoutManager used by the parent container 
        // (the Figure of the ShapesDiagramEditPart), will not know the bounds of this figure
        // and will not draw it correctly.
        Rectangle bounds = new Rectangle(
                getCastedModel().getLocation().getX(),
                getCastedModel().getLocation().getY(),
                getCastedModel().getSize().getWidth(),
                getCastedModel().getSize().getHeight());         
        ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), bounds);
    }
    
    public void notifyChanged(Notification notification) {
        int type = notification.getEventType();
        int featureId = notification.getFeatureID(CorePackage.class);
        switch(type) {
        case Notification.SET:
            switch(featureId) {
            case CorePackage.LOCATION__X:
            case CorePackage.LOCATION__Y:
//            case CorePackage.SIZE__WIDTH:
//            case CorePackage.BOUND__HEIGHT:
            case CorePackage.NODE_ELEMENT__LOCATION:
            case CorePackage.NODE_ELEMENT__SIZE:
                refreshVisuals();
                break;
            }
            
        case Notification.ADD:
        case Notification.REMOVE:
        case 8:
            switch(featureId) {
            case CorePackage.NODE_ELEMENT__SOURCE_CONNECTIONS:
                refreshSourceConnections();
                break;
            case CorePackage.NODE_ELEMENT__TARGET_CONNECTIONS:
                refreshTargetConnections();
                break;
                default:{
                	refreshVisuals();
                    refreshSourceConnections();
                    refreshTargetConnections();
                }
            }
        }
    }
    
    public Notifier getTarget() {
        return target;
    }
    
    public void setTarget(Notifier newTarget) {
        target = newTarget;
    }
    
    public boolean isAdapterForType(Object type) {
        return getModel() == type;
    }

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#refreshSourceConnections()
	 */
    public void refreshSourceConnections() {
		// TODO Auto-generated method stub
		super.refreshSourceConnections();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#refreshTargetConnections()
	 */
    public void refreshTargetConnections() {
		// TODO Auto-generated method stub
		super.refreshTargetConnections();
	}
    
    
}

⌨️ 快捷键说明

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