Skip to main content
summaryrefslogtreecommitdiffstats
blob: 08b76d1375df889c12bf1f422b6c51a794c07f09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.parts;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPolicy;
import org.eclipse.jst.pagedesigner.converter.ITagConverter;
import org.eclipse.jst.pagedesigner.editpolicies.NonVisualChildGraphicalEditPolicy;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * Represents a node that is non-visual in the runtime rendering
 * but which may wish to have a meta-representation on the design canvas.
 *
 */
public class NonVisualComponentEditPart extends NodeEditPart 
{
    protected IFigure createFigure() 
    {
        IFigure figure_ = new ImageFigure(getTagConverter().getVisualImage())
        {

            protected void paintFigure(Graphics graphics) {
                super.paintFigure(graphics);
                
                if (getImage() == null)
                    return;

                Rectangle srcRect = new Rectangle(getImage().getBounds());
                graphics.drawImage(getImage(), srcRect, getClientArea());
            }
            
        };
        
        figure_.setMinimumSize(new Dimension(0,0));
        return figure_;
    }

    public void notifyChanged(INodeNotifier notifier, int eventType,
            Object changedFeature, Object oldValue, Object newValue, int pos) {
        // for now, do nothing
    }

    protected void createEditPolicies() {
        super.createEditPolicies();
        installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE
                          , new NonVisualChildGraphicalEditPolicy());
        installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
                null);
    }

    @Override
    public void deactivate()
    {
        ITagConverter tagConverter = (ITagConverter) getModel();
        if (tagConverter != null)
        {
            tagConverter.dispose();
        }
        
        // always do super stuff
        super.deactivate();
    }

    /**
     * @return the tag converter
     */
    protected ITagConverter getTagConverter()
    {
    	ITagConverter tagConverter = (ITagConverter)getModel();
    	//need to call convertRefresh to get image (if any) from metadata
    	if (tagConverter != null) {
    		tagConverter.convertRefresh(null);
    	}
    	return tagConverter;
    }
    
    /**
     * @return the host element for this edit part
     */
    protected Element getModelElement()
    {
        return getTagConverter().getHostElement();
    }

    public IDOMNode getIDOMNode() 
    {
        return (IDOMNode) getModelElement();
    }

    public Node getDOMNode() {
        return getModelElement();
    }

//    public DragTracker getDragTracker(Request request) {
//        // TODO: need to define drag semantics for these
//        // Also, right now edit part dragging causes bad behaviour
//        // in the non-visual decorator
//        return null;//new ObjectModeDragTracker(this);
//    }
}

Back to the top