david_williams | b1f7505 | 2005-02-18 00:25:37 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 12 | package org.eclipse.jst.jsp.ui.internal.projection; |
| 13 | |
david_williams | 757ccfe | 2005-05-01 08:03:21 +0000 | [diff] [blame] | 14 | import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 15 | import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; |
| 16 | import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
david_williams | b1f7505 | 2005-02-18 00:25:37 +0000 | [diff] [blame] | 17 | import org.w3c.dom.Node; |
| 18 | |
| 19 | public class ProjectionModelNodeAdapterFactoryJSP extends ProjectionModelNodeAdapterFactoryHTML { |
| 20 | public ProjectionModelNodeAdapterFactoryJSP() { |
david_williams | 6f9dcdd | 2005-10-09 05:14:55 +0000 | [diff] [blame] | 21 | 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_williams | b1f7505 | 2005-02-18 00:25:37 +0000 | [diff] [blame] | 30 | } |
| 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 | } |