blob: e7b217065abb37a15ebf19f344c912441b98605b [file] [log] [blame]
david_williamsb1f75052005-02-18 00:25:37 +00001/*******************************************************************************
2 * Copyright (c) 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *
11 *******************************************************************************/
12package org.eclipse.jst.jsp.ui.internal.projection;
13
david_williams757ccfe2005-05-01 08:03:21 +000014import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace;
david_williams4ad020f2005-04-18 08:00:30 +000015import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
16import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
david_williamsb1f75052005-02-18 00:25:37 +000017import org.w3c.dom.Node;
18
19public class ProjectionModelNodeAdapterFactoryJSP extends ProjectionModelNodeAdapterFactoryHTML {
20 public ProjectionModelNodeAdapterFactoryJSP() {
david_williams6f9dcdd2005-10-09 05:14:55 +000021 this(ProjectionModelNodeAdapterJSP.class);
22 }
23
24 public ProjectionModelNodeAdapterFactoryJSP(Object adapterKey, boolean registerAdapters) {
25 super(adapterKey, registerAdapters);
26 }
27
28 public ProjectionModelNodeAdapterFactoryJSP(Object adapterKey) {
29 super(adapterKey);
david_williamsb1f75052005-02-18 00:25:37 +000030 }
31
32 /**
33 * Actually creates an adapter for the parent of target if target is the
34 * "adapt-able" node
35 */
36 protected INodeAdapter createAdapter(INodeNotifier target) {
37 if ((getProjectionViewer() != null) && (target instanceof Node) && ((Node) target).getNodeType() == Node.ELEMENT_NODE) {
38 Node node = (Node) target;
39 if (isNodeProjectable(node)) {
40
41 // actually work with the parent node to listen for add,
42 // delete events
43 Node parent = node.getParentNode();
44 if (parent instanceof INodeNotifier) {
45 INodeNotifier parentNotifier = (INodeNotifier) parent;
46 ProjectionModelNodeAdapterJSP parentAdapter = (ProjectionModelNodeAdapterJSP) parentNotifier.getExistingAdapter(ProjectionModelNodeAdapterJSP.class);
47 if (parentAdapter == null) {
48 // create a new adapter for parent
49 parentAdapter = new ProjectionModelNodeAdapterJSP(this);
50 parentNotifier.addAdapter(parentAdapter);
51 }
52 // call update on parent because a new node has just been
53 // added
54 parentAdapter.updateAdapter(parent);
55 }
56 }
57 }
58
59 return null;
60 }
61
62 /**
63 * Returns true if node is a node type able to fold
64 *
65 * @param node
66 * @return boolean true if node is projectable, false otherwise
67 */
68 boolean isNodeProjectable(Node node) {
69 if (node.getNodeType() == Node.ELEMENT_NODE) {
70 String tagName = node.getNodeName();
71 // node is only projectable if it is jsp scriptlet tag
72 if (JSP11Namespace.ElementName.SCRIPTLET.equalsIgnoreCase(tagName))
73 return true;
74 }
75 return false;
76 }
77}