1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.document.ui.contribution;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.viewers.IDecoration;
16 import org.simantics.browsing.ui.content.ImageDecorator;
17 import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.document.DocumentResource;
22 import org.simantics.document.ui.Activator;
23 import org.simantics.utils.ui.gfx.DecorationOverlayIcon;
26 * @author Tuukka Lehtonen
28 public class DocumentVersionImageDecorationRule implements ImageDecorationRule {
31 public boolean isCompatible(Class<?> contentType) {
32 return contentType.equals(Resource.class);
36 public ImageDecorator getImageDecorator(ReadGraph graph, Object content) throws DatabaseException {
38 DocumentResource DOC = DocumentResource.getInstance(graph);
39 if (graph.hasStatement((Resource)content, DOC.HasNewerVersion))
40 return new Dec(Activator.getDefault().clock_red);
46 private class Dec implements ImageDecorator {
47 private ImageDescriptor decorator;
49 public Dec(ImageDescriptor decorator) {
50 this.decorator = decorator;
52 @SuppressWarnings("unchecked")
53 public <Image extends Object> Image decorateImage(Image image, String column, int itemIndex) {
54 return (Image) getDecoration((ImageDescriptor) image,decorator);
58 private ImageDescriptor getDecoration(ImageDescriptor original, ImageDescriptor img) {
59 //ImageDescriptor img = Activator.getDefault().DOCUMENT_DECORATION_ICON;
60 return (original == null) ? img
61 : new DecorationOverlayIcon(original, img, IDecoration.BOTTOM_RIGHT);