]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.ui/src/org/simantics/document/ui/contribution/DocumentVersionImageDecorationRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / contribution / DocumentVersionImageDecorationRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.document.ui.contribution;
13
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;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public class DocumentVersionImageDecorationRule implements ImageDecorationRule {
29         
30     @Override
31     public boolean isCompatible(Class<?> contentType) {
32         return contentType.equals(Resource.class);
33     }
34
35     @Override
36     public ImageDecorator getImageDecorator(ReadGraph graph, Object content) throws DatabaseException {
37         
38         DocumentResource DOC = DocumentResource.getInstance(graph);
39         if (graph.hasStatement((Resource)content, DOC.HasNewerVersion))
40                 return new Dec(Activator.getDefault().clock_red);
41         
42         return null;
43         
44     }
45     
46         private class Dec implements ImageDecorator {
47                 private ImageDescriptor decorator;
48                 
49                 public Dec(ImageDescriptor decorator) {
50                         this.decorator = decorator;
51                 }
52                 @SuppressWarnings("unchecked")
53                 public <Image extends Object> Image decorateImage(Image image, String column, int itemIndex) {
54                         return (Image) getDecoration((ImageDescriptor) image,decorator);
55                 };
56         }
57
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);
62     }
63
64 }