1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.modeling.ui.modelBrowser2.contributions;
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;
27 * An imager contribution for giving {@link RelationViewNode} instances an image
28 * in a {@link GraphExplorer} based on the relation the :RelationView instance
36 * L0.AppliesRelation R
39 * it will attempt to adapt <code>R</code> into an
40 * {@link ImageDescriptorProvider} and resolve the {@link ImageDescriptor} from
43 * @author Tuukka Lehtonen
45 public class RelationViewImager extends ImagerContributor<RelationViewNode> {
48 public ImageDescriptor getDescriptor(ReadGraph graph, RelationViewNode input) throws DatabaseException {
49 Resource relation = graph.getPossibleObject(input.resource, Layer0X.getInstance(graph).AppliesRelation);
53 ImageDescriptorProvider provider = graph.getPossibleAdapter(relation, ImageDescriptorProvider.class);
58 return provider.get();
59 } catch (ProvisionException e) {
60 throw new ServiceException(e);