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.structural.ui.modelBrowser.contributions;
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.db.layer0.request.PossibleModel;
22 import org.simantics.operation.Layer0X;
23 import org.simantics.simulation.ontology.SimulationResource;
26 * @author Tuukka Lehtonen
28 public enum RunLabelDecorationRule implements LabelDecorationRule {
32 public static RunLabelDecorationRule get() {
37 public boolean isCompatible(Class<?> contentType) {
38 return contentType.equals(Resource.class);
42 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
43 Resource run = (Resource) content;
45 Resource model = graph.syncRequest(new PossibleModel(run));
48 if (!graph.hasStatement(model, Layer0X.getInstance(graph).IsActivatedBy))
50 if (!graph.hasStatement(run, SimulationResource.getInstance(graph).IsActive))
53 return new LabelDecorator.Stub() {
55 public String decorateLabel(String label, String column, int itemIndex) {
56 return label + " [ACTIVE]";
58 @SuppressWarnings("unchecked")
60 public <F> F decorateFont(F font, String column, int itemIndex) {
61 return (F) ((FontDescriptor) font).withStyle(SWT.BOLD);