]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/RunLabelDecorationRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / modelBrowser / contributions / RunLabelDecorationRule.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.structural.ui.modelBrowser.contributions;
13
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;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public enum RunLabelDecorationRule implements LabelDecorationRule {
29
30     INSTANCE;
31
32     public static RunLabelDecorationRule get() {
33         return INSTANCE;
34     }
35
36     @Override
37     public boolean isCompatible(Class<?> contentType) {
38         return contentType.equals(Resource.class);
39     }
40
41     @Override
42     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
43         Resource run = (Resource) content;
44
45         Resource model = graph.syncRequest(new PossibleModel(run));
46         if (model == null)
47             return null;
48         if (!graph.hasStatement(model, Layer0X.getInstance(graph).IsActivatedBy))
49             return null;
50         if (!graph.hasStatement(run, SimulationResource.getInstance(graph).IsActive))
51             return null;
52
53         return new LabelDecorator.Stub() {
54             @Override
55             public String decorateLabel(String label, String column, int itemIndex) {
56                 return label + " [ACTIVE]";
57             }
58             @SuppressWarnings("unchecked")
59             @Override
60             public <F> F decorateFont(F font, String column, int itemIndex) {
61                 return (F) ((FontDescriptor) font).withStyle(SWT.BOLD);
62             }
63         };
64     }
65
66 }