blob: 06d9384092c4edf53edee42962de37a607cb02d0 (
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
|
/*******************************************************************************
* Copyright (c) 2005 IBM 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:
* IBM Corporation - initial API and implementation
*
*******************************************************************************/
package org.eclipse.wst.html.ui.internal.projection;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.wst.html.core.HTML40Namespace;
import org.eclipse.wst.sse.core.AbstractAdapterFactory;
import org.eclipse.wst.sse.core.INodeAdapter;
import org.eclipse.wst.sse.core.INodeNotifier;
import org.w3c.dom.Node;
public class ProjectionModelNodeAdapterFactoryHTML extends AbstractAdapterFactory {
// copies of this class located in:
// org.eclipse.wst.html.ui.internal.projection
// org.eclipse.jst.jsp.ui.internal.projection
private ProjectionViewer fProjectionViewer;
public ProjectionModelNodeAdapterFactoryHTML() {
adapterKey = ProjectionModelNodeAdapterHTML.class;
}
/**
* Actually creates an adapter for the parent of target if target is the
* "adapt-able" node
*/
protected INodeAdapter createAdapter(INodeNotifier target) {
if ((fProjectionViewer != null) && (target instanceof Node) && ((Node) target).getNodeType() == Node.ELEMENT_NODE) {
Node node = (Node) target;
if (isNodeProjectable(node)) {
// actually work with the parent node to listen for add,
// delete events
Node parent = node.getParentNode();
if (parent instanceof INodeNotifier) {
INodeNotifier parentNotifier = (INodeNotifier) parent;
ProjectionModelNodeAdapterHTML parentAdapter = (ProjectionModelNodeAdapterHTML) parentNotifier.getExistingAdapter(ProjectionModelNodeAdapterHTML.class);
if (parentAdapter == null) {
// create a new adapter for parent
parentAdapter = new ProjectionModelNodeAdapterHTML(this);
parentNotifier.addAdapter(parentAdapter);
}
// call update on parent because a new node has just been
// added
parentAdapter.updateAdapter(parent);
}
}
}
return null;
}
ProjectionViewer getProjectionViewer() {
return fProjectionViewer;
}
/**
* Returns true if node is a node type able to fold
*
* @param node
* @return boolean true if node is projectable, false otherwise
*/
boolean isNodeProjectable(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String tagName = node.getNodeName();
// node is only projectable if it is head, body, script, style,
// table tags
if (HTML40Namespace.ElementName.HEAD.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.BODY.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.SCRIPT.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.STYLE.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.TABLE.equalsIgnoreCase((tagName)))
return true;
}
return false;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.core.AbstractAdapterFactory#release()
*/
public void release() {
fProjectionViewer = null;
super.release();
}
void setProjectionViewer(ProjectionViewer viewer) {
fProjectionViewer = viewer;
}
}
|