]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/RelationViewImager.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser2 / contributions / RelationViewImager.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.modeling.ui.modelBrowser2.contributions;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.simantics.browsing.ui.GraphExplorer;
16 import org.simantics.browsing.ui.swt.ImagerContributor;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.exception.ServiceException;
21 import org.simantics.modeling.ui.modelBrowser2.model.RelationViewNode;
22 import org.simantics.operation.Layer0X;
23 import org.simantics.ui.icons.ImageDescriptorProvider;
24 import org.simantics.utils.datastructures.cache.ProvisionException;
25
26 /**
27  * An imager contribution for giving {@link RelationViewNode} instances an image
28  * in a {@link GraphExplorer} based on the relation the :RelationView instance
29  * applies to.
30  * 
31  * <p>
32  * Given
33  * 
34  * <pre>
35  * _ : RelationView
36  *     L0.AppliesRelation R
37  * </pre>
38  * 
39  * it will attempt to adapt <code>R</code> into an
40  * {@link ImageDescriptorProvider} and resolve the {@link ImageDescriptor} from
41  * there.
42  * 
43  * @author Tuukka Lehtonen
44  */
45 public class RelationViewImager extends ImagerContributor<RelationViewNode> {
46
47     @Override
48     public ImageDescriptor getDescriptor(ReadGraph graph, RelationViewNode input) throws DatabaseException {
49         Resource relation = graph.getPossibleObject(input.resource, Layer0X.getInstance(graph).AppliesRelation);
50         if (relation == null)
51             return null;
52
53         ImageDescriptorProvider provider = graph.getPossibleAdapter(relation, ImageDescriptorProvider.class);
54         if (provider == null)
55             return null;
56
57         try {
58             return provider.get();
59         } catch (ProvisionException e) {
60             throw new ServiceException(e);
61         }
62     }
63
64 }