--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.document.ui.contribution;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.IDecoration;\r
+import org.simantics.browsing.ui.content.ImageDecorator;\r
+import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.document.DocumentResource;\r
+import org.simantics.document.ui.Activator;\r
+import org.simantics.utils.ui.gfx.DecorationOverlayIcon;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class DocumentVersionImageDecorationRule implements ImageDecorationRule {\r
+ \r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Resource.class);\r
+ }\r
+\r
+ @Override\r
+ public ImageDecorator getImageDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
+ \r
+ DocumentResource DOC = DocumentResource.getInstance(graph);\r
+ if (graph.hasStatement((Resource)content, DOC.HasNewerVersion))\r
+ return new Dec(Activator.getDefault().clock_red);\r
+ \r
+ return null;\r
+ \r
+ }\r
+ \r
+ private class Dec implements ImageDecorator {\r
+ private ImageDescriptor decorator;\r
+ \r
+ public Dec(ImageDescriptor decorator) {\r
+ this.decorator = decorator;\r
+ }\r
+ @SuppressWarnings("unchecked")\r
+ public <Image extends Object> Image decorateImage(Image image, String column, int itemIndex) {\r
+ return (Image) getDecoration((ImageDescriptor) image,decorator);\r
+ };\r
+ }\r
+\r
+ private ImageDescriptor getDecoration(ImageDescriptor original, ImageDescriptor img) {\r
+ //ImageDescriptor img = Activator.getDefault().DOCUMENT_DECORATION_ICON;\r
+ return (original == null) ? img\r
+ : new DecorationOverlayIcon(original, img, IDecoration.BOTTOM_RIGHT);\r
+ }\r
+\r
+}\r