]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/RunLabelRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / modelBrowser / contributions / RunLabelRule.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 java.text.SimpleDateFormat;
15 import java.util.Date;
16 import java.util.Map;
17
18 import org.simantics.browsing.ui.common.ColumnKeys;
19 import org.simantics.browsing.ui.model.labels.LabelRule;
20 import org.simantics.databoard.Bindings;
21 import org.simantics.db.ReadGraph;
22 import org.simantics.db.Resource;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.layer0.Layer0;
25 import org.simantics.simulation.ontology.SimulationResource;
26 import org.simantics.utils.datastructures.ArrayMap;
27
28 /**
29  * @author Tuukka Lehtonen
30  */
31 public enum RunLabelRule implements LabelRule {
32
33     INSTANCE;
34
35         static final SimpleDateFormat HHmmss = new SimpleDateFormat("HH:mm:ss");
36         
37     public static RunLabelRule get() {
38         return INSTANCE;
39     }
40
41     @Override
42     public boolean isCompatible(Class<?> contentType) {
43         return contentType.equals(Resource.class);
44     }
45
46     @Override
47     public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
48         Resource run = (Resource) content;
49
50         Layer0 L0 = Layer0.getInstance(graph);
51         String label = graph.getPossibleRelatedValue2(run, L0.HasLabel);
52         if (label == null)
53             return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { "" });
54         
55         SimulationResource SIMU = SimulationResource.getInstance(graph);
56         // FIXME: small database backwards compatibility hack
57         if (SIMU.HasActivationTime != null) {
58             Long activationTime = graph.getPossibleRelatedValue(run, SIMU.HasActivationTime, Bindings.LONG);
59             if (activationTime != null) {
60                 String time = HHmmss.format(new Date(activationTime));
61                 label += " ("+time+")";
62             }
63         }
64
65         return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { label });
66     }
67
68 }