diff options
author | david_williams | 2005-02-18 00:25:37 +0000 |
---|---|---|
committer | david_williams | 2005-02-18 00:25:37 +0000 |
commit | b1f750527601db95bf888485ae79acf073261df5 (patch) | |
tree | 9235e39faf3675bd4b7aa3c3f639c397ab47b6f2 /bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java | |
parent | c5f3c431c9c3812c28a906d613c4283708018a62 (diff) | |
download | webtools.sourceediting-b1f750527601db95bf888485ae79acf073261df5.tar.gz webtools.sourceediting-b1f750527601db95bf888485ae79acf073261df5.tar.xz webtools.sourceediting-b1f750527601db95bf888485ae79acf073261df5.zip |
[85776] preliminary infrastructure for document folding in wtp source editors
Diffstat (limited to 'bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java')
-rw-r--r-- | bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java new file mode 100644 index 0000000000..4efab4eb27 --- /dev/null +++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java @@ -0,0 +1,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.jst.jsp.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; + } +} |