1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.structural.ui.modelBrowser.contributions;
\r
14 import java.text.SimpleDateFormat;
\r
15 import java.util.Date;
\r
16 import java.util.Map;
\r
18 import org.simantics.browsing.ui.common.ColumnKeys;
\r
19 import org.simantics.browsing.ui.model.labels.LabelRule;
\r
20 import org.simantics.databoard.Bindings;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.simulation.ontology.SimulationResource;
\r
26 import org.simantics.utils.datastructures.ArrayMap;
\r
29 * @author Tuukka Lehtonen
\r
31 public enum RunLabelRule implements LabelRule {
\r
35 static final SimpleDateFormat HHmmss = new SimpleDateFormat("HH:mm:ss");
\r
37 public static RunLabelRule get() {
\r
42 public boolean isCompatible(Class<?> contentType) {
\r
43 return contentType.equals(Resource.class);
\r
47 public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
\r
48 Resource run = (Resource) content;
\r
50 Layer0 L0 = Layer0.getInstance(graph);
\r
51 String label = graph.getPossibleRelatedValue2(run, L0.HasLabel);
\r
53 return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { "" });
\r
55 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
56 // FIXME: small database backwards compatibility hack
\r
57 if (SIMU.HasActivationTime != null) {
\r
58 Long activationTime = graph.getPossibleRelatedValue(run, SIMU.HasActivationTime, Bindings.LONG);
\r
59 if (activationTime != null) {
\r
60 String time = HHmmss.format(new Date(activationTime));
\r
61 label += " ("+time+")";
\r
65 return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { label });
\r