Skip to main content
summaryrefslogtreecommitdiffstats
blob: 66dd08506158e615a7af659ca12c548a5a2709e0 (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
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.parts;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.jst.pagedesigner.converter.ITagConverter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.w3c.dom.Node;

/**
 * The model here can only be Document/Element/Text.
 * 
 * @author mengbo
 */
public class HTMLEditPartsFactory implements EditPartFactory {
	private IDOMDocument _destDocument;

	/**
	 * @param destDoc
	 */
	public HTMLEditPartsFactory(IDOMDocument destDoc) {
		this._destDocument = destDoc;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart,
	 *      java.lang.Object)
	 */
	public EditPart createEditPart(EditPart context, Object model) {
        NodeEditPart part = null;
        
        if (model instanceof Node)
        {
    		Node node = (Node) model;
    		if (node.getNodeType() == Node.DOCUMENT_NODE) {
    			part = new DocumentEditPart();
    		} else if (node.getNodeType() == Node.ELEMENT_NODE) {
    			// String tag = ((Element)node).getTagName();
    			// if ("TABLE".equalsIgnoreCase(tag))
    			// part = new HTMLTableEditPart();
    			// else
                    part = new ElementEditPart();
    		} else if (node.getNodeType() == Node.TEXT_NODE
    				|| node.getNodeType() == Node.CDATA_SECTION_NODE) {
    			part = new TextEditPart();
    		}
        }
        // XXX: we need to create wrapper that allows us to know when
        // a model object represents a non-visual decorator
        else if (model instanceof ITagConverter)
        {
            part = new NonVisualComponentEditPart();
        }
        
		if (part != null) {
			part.setDestDocumentForDesign(this._destDocument);
			part.setModel(model);
		}
		return part;
	}

}

Back to the top