Author: stefanegli
Date: Wed Aug 7 14:54:40 2013
New Revision: 1511345
URL: http://svn.apache.org/r1511345
Log:
SLING-2985 : tooling : show content of .content.xml in project explorer
- WIP/Work in progress : adding prototype of content[-package][.content.xml]
browsing. 'mounts' the syncDir as a new toplevel node to a sling-faceted
project and allows browsing through folders/.content.xml-content.
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
(with props)
Modified:
sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/eclipse-ui/plugin.xml
Modified: sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1511345&r1=1511344&r2=1511345&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF Wed Aug 7 14:54:40
2013
@@ -14,6 +14,7 @@ Import-Package: org.apache.sling.ide.ecl
org.eclipse.core.commands,
org.eclipse.core.commands.operations,
org.eclipse.core.resources,
+ org.eclipse.core.resources.mapping,
org.eclipse.core.runtime;version="3.4.0",
org.eclipse.core.runtime.jobs,
org.eclipse.debug.core,
@@ -49,4 +50,7 @@ Import-Package: org.apache.sling.ide.ecl
org.osgi.framework,
org.osgi.util.tracker;version="1.5.0"
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.wst.common.project.facet.ui
+Require-Bundle: org.eclipse.wst.common.project.facet.ui,
+ org.eclipse.ui.navigator;bundle-version="3.5.101",
+ org.eclipse.ui.views;bundle-version="3.6.0",
+ org.eclipse.ui
Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1511345&r1=1511344&r2=1511345&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Wed Aug 7 14:54:40 2013
@@ -114,4 +114,72 @@
</enabledWhen>
</page>
</extension>
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewerContentBinding
viewerId="org.eclipse.ui.navigator.ProjectExplorer">
+ <includes>
+ <contentExtension
pattern="org.apache.sling.ide.eclipse-ui.navigatorJcrContent" />
+ </includes>
+ </viewerContentBinding>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ appearsBefore="org.eclipse.jst.jee.ui.ejb"
+
contentProvider="org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider"
+ icon="icons/obj16/sling.gif"
+ id="org.apache.sling.ide.eclipse-ui.navigatorJcrContent"
+
labelProvider="org.apache.sling.ide.eclipse.ui.nav.JcrContentLabelProvider"
+ name="Sling (JCR) Content"
+ priority="highest">
+ <triggerPoints>
+ <or>
+ <instanceof
+ value="org.eclipse.core.resources.IWorkspaceRoot" />
+ <instanceof
+ value="org.eclipse.core.resources.IProject" />
+ <instanceof
+ value="org.eclipse.core.resources.IFolder" />
+ <instanceof
+ value="org.eclipse.core.resources.IFile" />
+ <instanceof
+ value="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode"
/>
+ </or>
+ </triggerPoints>
+ <enablement>
+ <or>
+ <instanceof
+ value="org.eclipse.core.resources.IWorkspaceRoot" />
+ <instanceof
+ value="org.eclipse.core.resources.IProject" />
+ <instanceof
+ value="org.eclipse.core.resources.IFolder" />
+ <instanceof
+ value="org.eclipse.core.resources.IFile" />
+ <instanceof
+ value="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode"
/>
+ </or>
+ </enablement>
+ <!--org.eclipse.ui.navigator.resourceContent-->
+ <!--org.eclipse.jdt.java.ui.javaContent-->
+ <!--override
+ policy="InvokeAlwaysRegardlessOfSuppressedExt"
+
suppressedExtensionId="org.eclipse.ui.navigator.resourceContent">
+ </override-->
+
+ </navigatorContent>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode"
+
class="org.apache.sling.ide.eclipse.ui.nav.model.JcrNodeAdapterFactory">
+ <adapter
+ type="org.eclipse.core.resources.IFile">
+ </adapter>
+ <adapter
+ type="org.eclipse.core.resources.IResource">
+ </adapter>
+ </factory>
+ </extension>
</plugin>
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.apache.sling.ide.eclipse.ui.internal.Activator;
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.apache.sling.ide.eclipse.ui.nav.model.SyncDir;
+import org.apache.sling.ide.serialization.SerializationManager;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.navigator.ICommonContentExtensionSite;
+import org.eclipse.ui.navigator.IPipelinedTreeContentProvider2;
+import org.eclipse.ui.navigator.PipelinedShapeModification;
+import org.eclipse.ui.navigator.PipelinedViewerUpdate;
+
+/** WIP: content provider for content package view in project explorer **/
+public class JcrContentContentProvider implements ITreeContentProvider,
IPipelinedTreeContentProvider2 {
+
+ @Override
+ public void dispose() {
+ // nothing to be done here
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
+ // nothing to be done here
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return null;
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IProject) {
+ return projectGetChildren((IProject)parentElement);
+ } else if (parentElement instanceof JcrNode) {
+ JcrNode node = (JcrNode)parentElement;
+ return node.getChildren();
+ } else {
+ return null;
+ }
+ }
+
+ private Object[] projectGetChildren(IProject parentElement) {
+ IFolder syncDir = getSyncDir(parentElement);
+ if (syncDir!=null && syncDir.exists()) {
+ return new Object[] {new SyncDir(syncDir)};
+ }
+ return null;
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof IProject) {
+ return projectHasChildren((IProject)element);
+ } else if (element instanceof JcrNode) {
+ JcrNode jcrNode = (JcrNode) element;
+ return jcrNode.hasChildren();
+ }
+ return false;
+ }
+
+ private boolean projectHasChildren(IProject project) {
+ IFolder syncDir = getSyncDir(project);
+ if (syncDir!=null && syncDir.exists()) {
+ return true;
+ }
+ return false;
+ }
+
+ private IFolder getSyncDir(IProject project) {
+ if (!project.isOpen()) {
+ return null;
+ }
+ IResource syncDir =
project.findMember(ProjectUtil.getSyncDirectoryValue(project));
+ return (IFolder) syncDir;
+ }
+
+ @Override
+ public void getPipelinedElements(Object anInput, Set
theCurrentElements) {
+ // we're not adding any elements at the root level
+ // hence nothing to be done here
+ }
+
+
+ @Override
+ public Object getPipelinedParent(Object anObject, Object
aSuggestedParent) {
+ // not fiddling with the parent
+ // hence returning the suggested parent
+ return aSuggestedParent;
+ }
+
+
+ @Override
+ public PipelinedShapeModification interceptAdd(
+ PipelinedShapeModification anAddModification) {
+ // nothing to do here
+ // passing along the parameter unchanged
+ return anAddModification;
+ }
+
+
+ @Override
+ public PipelinedShapeModification interceptRemove(
+ PipelinedShapeModification aRemoveModification) {
+ // nothing to do here
+ // passing along the parameter unchanged
+ return aRemoveModification;
+ }
+
+
+ @Override
+ public boolean interceptRefresh(
+ PipelinedViewerUpdate aRefreshSynchronization) {
+ // nothing to do here
+ return false;
+ }
+
+
+ @Override
+ public boolean interceptUpdate(PipelinedViewerUpdate
anUpdateSynchronization) {
+ // nothing to do here
+ return false;
+ }
+
+
+ @Override
+ public void init(ICommonContentExtensionSite aConfig) {
+ // nothing to do here
+ }
+
+
+ @Override
+ public void restoreState(IMemento aMemento) {
+ // nothing to do here
+ }
+
+
+ @Override
+ public void saveState(IMemento aMemento) {
+ // nothing to do here
+ }
+
+ @Override
+ public void getPipelinedChildren(Object aParent, Set
theCurrentChildren) {
+ if (aParent instanceof IProject) {
+ Object[] children =
projectGetChildren((IProject)aParent);
+ if (children!=null && children.length>0) {
+
theCurrentChildren.addAll(Arrays.asList(children));
+ }
+ return;
+ } else if (aParent instanceof SyncDir) {
+ theCurrentChildren.clear();
+ Object[] children = getChildren(aParent);
+ if (children!=null) {
+
theCurrentChildren.addAll(Arrays.asList(children));
+ }
+ }
+ }
+
+ @Override
+ public boolean hasPipelinedChildren(Object anInput,
+ boolean currentHasChildren) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.navigator.IDescriptionProvider;
+
+/** WIP: label provider for content package view in project explorer **/
+public class JcrContentLabelProvider implements ILabelProvider,
IDescriptionProvider {
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof JcrNode) {
+ JcrNode jcrNode = (JcrNode)element;
+ return jcrNode.getImage();
+ } else {
+ // fallback to default
+ return null;
+ }
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof JcrNode) {
+ JcrNode jcrNode = (JcrNode)element;
+ return jcrNode.getLabel();
+ } else {
+ // fallback to the default
+ return null;
+ }
+ }
+
+ @Override
+ public String getDescription(Object element) {
+ if (element instanceof JcrNode) {
+ JcrNode jcrNode = (JcrNode)element;
+ return jcrNode.getDescription();
+ } else {
+ // fallback to the default
+ return null;
+ }
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentLabelProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav.model;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/** WIP: model object for a [.content.xml] shown in the content package view
in project explorer **/
+public class GenericJcrRootFile extends JcrNode {
+
+ private final IFile file;
+ private final Document document;
+
+ public GenericJcrRootFile(JcrNode parent, IFile file) throws
ParserConfigurationException, SAXException, IOException, CoreException {
+ if (file==null) {
+ throw new IllegalArgumentException("file must not be
null");
+ }
+ this.file = file;
+ setResource(file);
+ this.underlying = this;
+ if (parent==null) {
+ throw new IllegalArgumentException("parent must not be
null");
+ }
+ this.parent = parent;
+ this.domNode = null;
+
+ DocumentBuilder docBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ this.document = docBuilder.parse(file.getContents());
+ handleJcrRoot(this.document.getFirstChild());
+ }
+
+ private void handleJcrRoot(Node domNode) {
+ NodeList children = domNode.getChildNodes();
+ final JcrNode effectiveParent;
+ if (isRootContentXml()) {
+ handleProperties(domNode, parent.properties);
+ effectiveParent = parent;
+ } else {
+ handleProperties(domNode, properties);
+ effectiveParent = this;
+ parent.addChild(this);
+ }
+ for(int i=0; i<children.getLength(); i++) {
+ handleChild(effectiveParent, children.item(i));
+ }
+ }
+
+ private boolean isRootContentXml() {
+ return file.getName().equals(".content.xml");
+ }
+
+ private void handleProperties(Node domNode, ReadOnlyProperties
properties) {
+ NamedNodeMap attributes = domNode.getAttributes();
+ for(int i=0; i<attributes.getLength(); i++) {
+ Node attr = attributes.item(i);
+ properties.add(attr.getNodeName(), attr.getNodeValue());
+ }
+ }
+
+ @Override
+ public String getLabel() {
+ if (isRootContentXml()) {
+ return "SHOULD NOT OCCUR";
+ } else {
+ // de-escape the file name
+
+ String label = file.getName();
+
+ // 1. remove the trailing .xml
+ if (label.endsWith(".xml")) {
+ label = label.substring(0, label.length()-4);
+ }
+
+ // 2. de-escape stuff like '_cq_' to 'cq:'
+ if (label.startsWith("_")) {
+ label = label.substring(1);
+ int first = label.indexOf("_");
+ if (first!=-1) {
+ label = label.substring(0, first) + ":"
+ label.substring(first+1);
+ }
+ }
+ return label;
+ }
+ }
+
+ private void handleChild(JcrNode parent, Node domNode) {
+ if (domNode.getNodeType() == Node.TEXT_NODE) {
+ // ignore
+ return;
+ }
+ if (domNode.getAttributes().getLength() == 0) {
+ // then ignore this empty node
+ // either there is a file or a folder corresponding to
this element
+ // (in which case it will show up again anyway)
+ // or just an empty node without any further attributes
such
+ // as primaryType doesn't help a lot
+ return;
+ }
+ JcrNode childJcrNode = new JcrNode(parent, domNode);
+ childJcrNode.init();
+ handleProperties(domNode, childJcrNode.properties);
+ NodeList children = domNode.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ handleChild(childJcrNode, children.item(i));
+ }
+ }
+
+ public void pickResources(List<Object> membersList) {
+ for (Iterator it = membersList.iterator(); it.hasNext();) {
+ final IResource resource = (IResource) it.next();
+ final String resName = resource.getName();
+ Iterator it2;
+ if (isRootContentXml()) {
+ it2 = parent.children.iterator();
+ } else {
+ it2 = children.iterator();
+ }
+ while(it2.hasNext()) {
+ JcrNode aChild = (JcrNode) it2.next();
+ if (resName.equals(aChild.getName())) {
+ // then pick this one
+ it.remove();
+ aChild.setResource(resource);
+ break;
+ }
+ }
+ }
+
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,381 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav.model;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IContributorResourceAdapter;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/** WIP: model object for a jcr node shown in the content package view in
project explorer **/
+public class JcrNode implements IAdaptable {
+
+ private final class JcrRootHandler extends DefaultHandler {
+ boolean firstElement = true;
+ boolean isVaultFile = false;
+
+ public boolean isVaultFile() {
+ return isVaultFile;
+ }
+
+ @Override
+ public void startElement(String uri, String localName,
+ String qName, Attributes attributes)
+ throws SAXException {
+ if (!firstElement) {
+ return;
+ }
+ firstElement = false;
+ if ("jcr:root".equals(qName)) {
+ String ns = attributes.getValue("xmlns:jcr");
+ if (ns!=null &&
ns.startsWith("http://www.jcp.org/jcr")) {
+ // then this is a vault file with a
jcr:root at the beginning
+ isVaultFile = true;
+ }
+ }
+ }
+ }
+
+ private final static WorkbenchLabelProvider workbenchLabelProvider =
new WorkbenchLabelProvider();
+
+ GenericJcrRootFile underlying;
+
+ JcrNode parent;
+
+ final Set<JcrNode> children = new HashSet<JcrNode>();
+
+ Node domNode;
+
+ private IResource resource;
+
+ private boolean resourceChildrenAdded = false;
+
+ final ReadOnlyProperties properties = new ReadOnlyProperties();
+
+ JcrNode() {
+ // for subclass use only
+ }
+
+ JcrNode(JcrNode parent, Node domNode) {
+ if (parent == null) {
+ throw new IllegalArgumentException("parent must not be
null");
+ }
+ this.parent = parent;
+ // domNode can be null
+ this.domNode = domNode;
+ this.underlying = parent.underlying;
+ parent.addChild(this);
+ }
+
+ @Override
+ public String toString() {
+ return "JcrNode[dom:"+domNode+", file:"+resource+"]";
+ }
+
+ protected void addChild(JcrNode jcrNode) {
+ children.add(jcrNode);
+ }
+
+ /** shown in the navigator (project explorer) as the label of this
element **/
+ public String getLabel() {
+ if (domNode!=null && resource!=null) {
+ return domNode.getNodeName();// + "[domnode+file]";
+ } else if (domNode!=null && resource==null) {
+ return domNode.getNodeName();// + "[domnode]";
+ } else if (resource!=null) {
+ return resource.getName();//+" [file]";
+ } else {
+ return "n/a";
+ }
+ }
+
+ /** shown in the statusbar when this element is selected **/
+ public String getDescription() {
+ return getJcrPath();
+ }
+
+ public boolean hasChildren() {
+ boolean members;
+ try {
+ members = resource!=null && resource instanceof IFolder
&& ((IFolder)resource).members().length>0;
+ } catch (CoreException e) {
+ members = false;
+ }
+ return children.size()>0 || members;
+ }
+
+ public Object[] getChildren() {
+ try {
+ if (resourceChildrenAdded) {
+ return children.toArray();
+ }
+ Map<String,JcrNode> resultMap = new HashMap<String,
JcrNode>();
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ JcrNode node = (JcrNode) it.next();
+ resultMap.put(node.getName(), node);
+ }
+
+ if (resource!=null && resource instanceof IFolder) {
+ IFolder folder = (IFolder)resource;
+ IResource[] members = folder.members();
+ List<Object> membersList = new
LinkedList<Object>(Arrays.asList(members));
+ outerLoop: while(membersList.size()>0) {
+ for (Iterator it =
membersList.iterator(); it.hasNext();) {
+ IResource iResource =
(IResource) it.next();
+ if (isVaultFile(iResource)) {
+ GenericJcrRootFile gjrf
= new GenericJcrRootFile(this, (IFile)iResource);
+ it.remove();
+ //gjrf.getChildren();
+
gjrf.pickResources(membersList);
+
+ // as this might have
added some new children, go through the children again and
+ // add them if they're
not already added
+ for (Iterator it3 =
children.iterator(); it3
+
.hasNext();) {
+ JcrNode node =
(JcrNode) it3.next();
+ if
(!resultMap.containsKey(node.getName())) {
+
resultMap.put(node.getName(), node);
+ }
+ }
+
+ continue outerLoop;
+ }
+ }
+ for (Iterator it =
membersList.iterator(); it.hasNext();) {
+ IResource iResource =
(IResource) it.next();
+ JcrNode node = new
JcrNode(this, (Node)null);
+ node.setResource(iResource);
+ node.init();
+ // load the children - to make
sure we get vault files loaded too
+ node.getChildren();
+ resultMap.put(node.getName(),
node);
+ it.remove();
+ }
+ }
+ }
+ resourceChildrenAdded = true;
+
+ return resultMap.values().toArray();
+ } catch (CoreException e) {
+ return new Object[0];
+ } catch (ParserConfigurationException e) {
+ return new Object[0];
+ } catch (SAXException e) {
+ return new Object[0];
+ } catch (IOException e) {
+ return new Object[0];
+ }
+ }
+
+ protected void init() {
+ // placeholder for initializing any common properties
+ }
+
+ private boolean isVaultFile(IResource iResource)
+ throws ParserConfigurationException, SAXException,
IOException,
+ CoreException {
+ if (iResource.getName().endsWith(".xml")) {
+ // then it could potentially be a vlt file.
+ // let's check if it contains a jcr:root element with
the appropriate namespace
+
+ IFile file = (IFile)iResource;
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ SAXParser saxParser = factory.newSAXParser();
+
+ JcrRootHandler h = new JcrRootHandler();
+ saxParser.parse(new InputSource(file.getContents()), h);
+
+ return h.isVaultFile();
+ }
+ return false;
+ }
+
+ public void setResource(IResource resource) {
+ if (this.resource!=null) {
+ throw new IllegalStateException("can only set resource
once");
+ }
+ this.resource = resource;
+ }
+
+ public Image getImage() {
+ if (resource!=null) {
+ if (resource instanceof IFolder) {
+ Image folderImage =
workbenchLabelProvider.getImage(resource);
+ if (domNode==null && false) {
+ // then make it greyscale
+ folderImage = new
+
Image(folderImage.getDevice(), folderImage,SWT.IMAGE_GRAY);
+ }
+ return folderImage;
+ } else
+ try {
+ if (!isVaultFile(resource)){
+ return
workbenchLabelProvider.getImage(resource);
+ }
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ //if (domNode!=null && children!=null && children.size()>0) {
+ // return workbenchLabelProvider.getImage(domNode);
+ //}
+
+ return SharedImages.SLING_ICON.createImage();
+ }
+
+ public String getName() {
+ if (domNode!=null) {
+ return domNode.getNodeName();
+ } else if (resource!=null) {
+ return resource.getName();
+ } else {
+ return "";
+ }
+ }
+
+ String getJcrPath() {
+ String prefix;
+ if (parent==null) {
+ prefix = "";
+ } else {
+ prefix = parent.getJcrPath();
+ if (!prefix.endsWith("/")) {
+ prefix = prefix + "/";
+ }
+ }
+ return prefix + getName();
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ final Object result = doGetAdapter(adapter);
+ if (result==null) {
+ // System.out.println("adapter looked for: "+adapter+",
result: "+result);
+ }
+ return result;
+ }
+
+ private Object doGetAdapter(Class adapter) {
+ if (adapter==IPropertySource.class) {
+ return properties;
+ } else if (adapter == IFile.class) {
+ if (resource instanceof IFile) {
+ return (IFile)resource;
+ } else {
+ return null;
+ }
+ } else if (adapter == IContributorResourceAdapter.class) {
+ if (resource==null) {
+ return null;
+ }
+ return new IContributorResourceAdapter() {
+
+ @Override
+ public IResource getAdaptedResource(IAdaptable
adaptable) {
+ if (!(adaptable instanceof JcrNode)) {
+ return null;
+ }
+ JcrNode node = (JcrNode)adaptable;
+ if (node.resource!=null) {
+ return node.resource;
+ }
+ return null;
+ }
+ };
+ } else if (adapter == IResource.class) {
+ return resource;
+ } else if (adapter == ResourceMapping.class) {
+ boolean t = true;
+ if (!t) {
+ return null;
+ }
+ if (resource==null) {
+ return null;
+ }
+ return new ResourceMapping() {
+
+ @Override
+ public ResourceTraversal[]
getTraversals(ResourceMappingContext context,
+ IProgressMonitor monitor)
throws CoreException {
+ return new ResourceTraversal[] { new
ResourceTraversal(new IResource[] { resource }, IResource.DEPTH_INFINITE,
IResource.NONE) };
+ }
+
+ @Override
+ public IProject[] getProjects() {
+ if (resource!=null) {
+ return new IProject[]
{resource.getProject()};
+ }
+ return null;
+ }
+
+ @Override
+ public String getModelProviderId() {
+ return
"org.apache.sling.ide.eclipse.ui.nav.model.JcrNode.ResourceMapping";
+ }
+
+ @Override
+ public Object getModelObject() {
+ return resource;
+ }
+ };
+ }
+ return null;
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav.model;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+
+public class JcrNodeAdapterFactory implements IAdapterFactory {
+
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adaptableObject instanceof JcrNode) {
+ JcrNode node = (JcrNode) adaptableObject;
+ return node.getAdapter(adapterType);
+ }
+ return null;
+ }
+
+ @Override
+ public Class[] getAdapterList() {
+ return null;
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNodeAdapterFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav.model;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class ReadOnlyProperties implements IPropertySource {
+
+ private Map<String, String> properties = new HashMap<String, String>();
+
+ public ReadOnlyProperties() {
+
+ }
+
+ public ReadOnlyProperties(Map<String, String> properties) {
+ this.properties.putAll(properties);
+ }
+
+ @Override
+ public Object getEditableValue() {
+ return null;
+ }
+
+ @Override
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ final List<IPropertyDescriptor> result = new
LinkedList<IPropertyDescriptor>();
+ for (Iterator<Map.Entry<String, String>> it =
properties.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<String, String> entry = it.next();
+ IPropertyDescriptor pd = new PropertyDescriptor(entry,
entry.getKey());
+ result.add(pd);
+ }
+ return result.toArray(new IPropertyDescriptor[] {});
+ }
+
+ @Override
+ public Object getPropertyValue(Object id) {
+ Map.Entry<String, String> entry = (Map.Entry<String, String>)id;
+ return entry.getValue();
+ }
+
+ @Override
+ public boolean isPropertySet(Object id) {
+ return properties.containsKey(String.valueOf(id));
+ }
+
+ @Override
+ public void resetPropertyValue(Object id) {
+
+ }
+
+ @Override
+ public void setPropertyValue(Object id, Object value) {
+
+ }
+
+ public void add(String label, String value) {
+ properties.put(label, value);
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ReadOnlyProperties.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java?rev=1511345&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
Wed Aug 7 14:54:40 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.nav.model;
+
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.swt.graphics.Image;
+
+/** WIP: model object for the syncDir [root] shown in the content package view
in project explorer **/
+public class SyncDir extends JcrNode {
+
+ private final IFolder folder;
+
+ public SyncDir(IFolder folder) {
+ if (folder==null) {
+ throw new IllegalArgumentException("folder must not be
null");
+ }
+ this.folder = folder;
+ setResource(folder);
+ }
+
+ @Override
+ public Image getImage() {
+ return SharedImages.SLING_ICON.createImage();
+ }
+
+ public String getLabel() {
+ return folder.getProjectRelativePath()+" [sling synched]";
+ }
+
+ @Override
+ public String getDescription() {
+ return folder.getProjectRelativePath().toString() + "[jcr
root]";
+ }
+
+ public IFolder getFolder() {
+ return folder;
+ }
+
+ @Override
+ public String getName() {
+ return "/";
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
------------------------------------------------------------------------------
svn:mime-type = text/plain