You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2016/02/26 23:03:02 UTC

svn commit: r1732565 - in /sling/trunk/tooling/ide/eclipse-ui: plugin.xml src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java

Author: rombert
Date: Fri Feb 26 22:03:02 2016
New Revision: 1732565

URL: http://svn.apache.org/viewvc?rev=1732565&view=rev
Log:
SLING-5565 - Hide 'Deployment Descriptor' navigator content for Sling
content projects 

Install a ContentViewer filter which hides the deployment descriptor for
Sling content projects.

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1732565&r1=1732564&r2=1732565&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Fri Feb 26 22:03:02 2016
@@ -222,6 +222,7 @@
 			point="org.eclipse.ui.navigator.viewer">
 		<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
 			<includes>
+				<contentExtension pattern="org.apache.sling.ide.eclipse-ui.javaEEFilter" />
 				<contentExtension pattern="org.apache.sling.ide.eclipse-ui.navigatorJcrContent" />
 				<contentExtension pattern="org.apache.sling.ide.eclipse-ui.linkHelper"/>	
 			</includes>
@@ -229,6 +230,13 @@
 	</extension>
    <extension
          point="org.eclipse.ui.navigator.navigatorContent">
+      <commonFilter
+     	   name="Sling content project Java EE filter"
+     	   class="org.apache.sling.ide.eclipse.ui.nav.ContentViewerFilter"
+           id="org.apache.sling.ide.eclipse-ui.javaEEFilter"
+           description="Hides Java EE deployment descriptors for content projects."
+           activeByDefault="true">
+      </commonFilter>
       <navigatorContent
             appearsBefore="org.eclipse.jst.jee.ui.ejb"
             contentProvider="org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider"

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java?rev=1732565&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ContentViewerFilter.java Fri Feb 26 22:03:02 2016
@@ -0,0 +1,68 @@
+/*
+ * 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.core.internal.ProjectHelper;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.TreePath;;
+
+/**
+ * The <tt>ContentViewerFilter</tt> ensures that Sling content projects do not have 
+ * the 'Deployment Descriptor' contribution present.
+ *
+ */
+public class ContentViewerFilter extends ViewerFilter {
+
+    @Override
+    public boolean select(Viewer viewer, Object parentElement, Object element) {
+        
+        // the checks are not particularly robust but I was unable to find a better solution
+        // see also https://www.eclipse.org/forums/index.php/t/1075144/
+        switch ( element.getClass().getName()) {
+            case "org.eclipse.jst.j2ee.navigator.internal.LoadingDDNode":
+            case "org.eclipse.jst.j2ee.webapplication.internal.impl.WebAppImpl":
+            case "org.eclipse.jst.jee.ui.internal.navigator.web.WebAppProvider":
+            case "org.eclipse.jst.jee.ui.internal.navigator.LoadingGroupProvider":
+
+                IProject project = getProjectFromParent(parentElement);
+                
+                if ( ProjectHelper.isContentProject(project)) {
+                    return false;
+                }
+                
+                // intentional fall-through
+            default:
+                return true;
+        }
+    }
+
+    private IProject getProjectFromParent(Object parentElement) {
+
+        if (parentElement instanceof TreePath) {
+            Object firstSegment = ((TreePath) parentElement).getFirstSegment();
+            if (firstSegment instanceof IProject) {
+                return (IProject) firstSegment;
+            }
+        } else if (parentElement instanceof IProject) {
+            return (IProject) parentElement;
+        }
+        return null;
+    }
+
+}