--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.structural.ui.modelBrowser.contributions;\r
+\r
+import org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.operation.Layer0X;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public enum RunLabelDecorationRule implements LabelDecorationRule {\r
+\r
+ INSTANCE;\r
+\r
+ public static RunLabelDecorationRule get() {\r
+ return INSTANCE;\r
+ }\r
+\r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Resource.class);\r
+ }\r
+\r
+ @Override\r
+ public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
+ Resource run = (Resource) content;\r
+\r
+ Resource model = graph.syncRequest(new PossibleModel(run));\r
+ if (model == null)\r
+ return null;\r
+ if (!graph.hasStatement(model, Layer0X.getInstance(graph).IsActivatedBy))\r
+ return null;\r
+ if (!graph.hasStatement(run, SimulationResource.getInstance(graph).IsActive))\r
+ return null;\r
+\r
+ return new LabelDecorator.Stub() {\r
+ @Override\r
+ public String decorateLabel(String label, String column, int itemIndex) {\r
+ return label + " [ACTIVE]";\r
+ }\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ return (F) ((FontDescriptor) font).withStyle(SWT.BOLD);\r
+ }\r
+ };\r
+ }\r
+\r
+}\r