incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1521019 - in /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model: JcrNode.java ModifiableProperties.java
Date Mon, 09 Sep 2013 09:48:36 GMT
Author: stefanegli
Date: Mon Sep  9 09:48:35 2013
New Revision: 1521019

URL: http://svn.apache.org/r1521019
Log:
SLING-2985 : improvement in the content-browser: show relevant icon of a file based on jcr:content/jcr:mimeType
set

Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java

Modified: 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=1521019&r1=1521018&r2=1521019&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
Mon Sep  9 09:48:35 2013
@@ -46,11 +46,13 @@ import org.eclipse.core.runtime.IAdaptab
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IActionFilter;
 import org.eclipse.ui.IContributorResourceAdapter;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.views.properties.IPropertySource;
 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
@@ -351,6 +353,13 @@ public class JcrNode implements IAdaptab
 			} else
 				try {
 					if (!isVaultFile(resource)){
+						final String jcrMimeType = getJcrContentProperty("jcr:mimeType");
+						if (jcrMimeType!=null && jcrMimeType.length()!=0) {
+							ImageDescriptor desc = getImageDescriptor(resource.getName(), jcrMimeType);
+							if (desc!=null) {
+								return desc.createImage();
+							}
+						}
 						return workbenchLabelProvider.getImage(resource);
 					}
 				} catch (ParserConfigurationException e) {
@@ -374,6 +383,34 @@ public class JcrNode implements IAdaptab
 		return WhitelabelSupport.JCR_NODE_ICON.createImage();
 	}
 
+	private ImageDescriptor getImageDescriptor(String filename, String jcrMimeType) {
+		final String modifiedFilename;
+		if (jcrMimeType.equals("image/jpeg")) {
+			modifiedFilename = filename + ".jpg";
+		} else if (jcrMimeType.startsWith("image/")) {
+			modifiedFilename = filename + "." + (jcrMimeType.substring(jcrMimeType.indexOf("/")+1));
+		} else {
+			return null;
+		}
+		return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(modifiedFilename,
null);
+	}
+
+	private String getJcrContentProperty(String propertyKey) {
+		final Object[] chldrn = getChildren();
+		for (int i = 0; i < chldrn.length; i++) {
+			JcrNode jcrNode = (JcrNode) chldrn[i];
+			if ("jcr:content".equals(jcrNode.getName())) {
+				if (jcrNode.properties!=null) {
+					Object propertyValue = jcrNode.properties.getValue(propertyKey);
+					if (propertyValue!=null) {
+						return String.valueOf(propertyValue);
+					}
+				}
+			}
+		}
+		return null;
+	}
+
 	public String getName() {
 		if (domNode!=null) {
 			return domNode.getNodeName();

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java?rev=1521019&r1=1521018&r2=1521019&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
Mon Sep  9 09:48:35 2013
@@ -62,6 +62,10 @@ public class ModifiableProperties implem
 		return result.toArray(new IPropertyDescriptor[] {});
 	}
 
+	public String getValue(String key) {
+		return properties.get(key);
+	}
+	
 	@Override
 	public Object getPropertyValue(Object id) {
 		Map.Entry<String, String> entry = (Map.Entry<String, String>)id;



Mime
View raw message