1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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.label;
14 import org.eclipse.jface.resource.FontDescriptor;
15 import org.eclipse.swt.SWT;
16 import org.simantics.browsing.ui.content.LabelDecorator;
17 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.diagram.stubs.DiagramResource;
22 import org.simantics.modeling.ModelingResources;
25 * @author Tuukka Lehtonen
27 public class ConnectionRelationLabelDecorationRule implements LabelDecorationRule {
29 public static final ConnectionRelationLabelDecorationRule INSTANCE = new ConnectionRelationLabelDecorationRule();
31 static LabelDecorator DECO = new LabelDecorator.Stub() {
32 @SuppressWarnings("unchecked")
33 public <F> F decorateFont(F font, String column, int itemIndex) {
34 return (F) ((FontDescriptor) font).withStyle(SWT.BOLD);
39 public boolean isCompatible(Class<?> contentType) {
40 return contentType.equals(Resource.class);
44 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
45 Resource cr = (Resource) content;
46 DiagramResource DIA = DiagramResource.getInstance(graph);
47 ModelingResources MOD = ModelingResources.getInstance(graph);
49 for (Resource dcr : graph.getObjects(cr, MOD.ConnectionRelationToDiagramConnectionRelation)) {
50 for (Resource terminal : graph.getObjects(dcr, DIA.HasConnectionPoint_Inverse)) {
51 if (graph.isInstanceOf(terminal, DIA.Terminal))