Introduce NodeElement interface.
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Dec 2020 09:13:23 +0000 (10:13 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Dec 2020 09:13:23 +0000 (10:13 +0100)
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeColumnLabelProvider.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElement.java [new file with mode: 0644]

index c4644789fd2023ef6c9ab0a58150206eb69f3195..7e12becd82f09f70f1f37b0a16558b487ec79d01 100644 (file)
@@ -4,6 +4,8 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.Image;
 
 /** Simplifies writing JCR-based column label provider. */
@@ -22,30 +24,99 @@ public class NodeColumnLabelProvider extends ColumnLabelProvider {
                return super.getImage(node);
        }
 
+       protected Font getNodeFont(Node node) throws RepositoryException {
+               return super.getFont(node);
+       }
+
+       public Color getNodeBackground(Node node) throws RepositoryException {
+               return super.getBackground(node);
+       }
+
+       public Color getNodeForeground(Node node) throws RepositoryException {
+               return super.getForeground(node);
+       }
+
        @Override
        public String getText(Object element) {
                try {
-                       return getNodeText((Node) element);
+                       if (element instanceof Node)
+                               return getNodeText((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeText(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
                } catch (RepositoryException e) {
-                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
                }
        }
 
        @Override
        public Image getImage(Object element) {
                try {
-                       return getNodeImage((Node) element);
+                       if (element instanceof Node)
+                               return getNodeImage((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeImage(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
                } catch (RepositoryException e) {
-                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
                }
        }
 
        @Override
        public String getToolTipText(Object element) {
                try {
-                       return getNodeToolTipText((Node) element);
+                       if (element instanceof Node)
+                               return getNodeToolTipText((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeToolTipText(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
+               } catch (RepositoryException e) {
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
+               }
+       }
+
+       @Override
+       public Font getFont(Object element) {
+               try {
+                       if (element instanceof Node)
+                               return getNodeFont((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeFont(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
+               } catch (RepositoryException e) {
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
+               }
+       }
+
+       @Override
+       public Color getBackground(Object element) {
+               try {
+                       if (element instanceof Node)
+                               return getNodeBackground((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeBackground(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
+               } catch (RepositoryException e) {
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
+               }
+       }
+
+       @Override
+       public Color getForeground(Object element) {
+               try {
+                       if (element instanceof Node)
+                               return getNodeForeground((Node) element);
+                       else if (element instanceof NodeElement)
+                               return getNodeForeground(((NodeElement) element).getNode());
+                       else
+                               throw new IllegalArgumentException("Unsupported element type " + element.getClass());
                } catch (RepositoryException e) {
-                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+                       throw new IllegalStateException("Repository exception when accessing " + element, e);
                }
        }
 
diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElement.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElement.java
new file mode 100644 (file)
index 0000000..787c92e
--- /dev/null
@@ -0,0 +1,8 @@
+package org.argeo.eclipse.ui.jcr;
+
+import javax.jcr.Node;
+
+/** An element which is related to a JCR {@link Node}. */
+public interface NodeElement {
+       Node getNode();
+}