]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemNameModifierRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / ChartItemNameModifierRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
3  * 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.charts.ui;
13
14 import org.simantics.browsing.ui.common.ColumnKeys;
15 import org.simantics.browsing.ui.content.Labeler.Modifier;
16 import org.simantics.browsing.ui.model.modifiers.NoModifierRule;
17 import org.simantics.browsing.ui.model.modifiers.StringPropertyModifierRule;
18 import org.simantics.charts.ontology.ChartResource;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.Layer0;
23
24 public class ChartItemNameModifierRule extends StringPropertyModifierRule {
25
26     public ChartItemNameModifierRule(ReadGraph graph) throws DatabaseException {
27         super(graph, Layer0.URIs.HasLabel);
28     }
29
30     @Override
31     public Modifier getModifier(ReadGraph graph, Object content, String columnKey) throws DatabaseException {
32         if (!ColumnKeys.SINGLE.equals(columnKey))
33             return null;
34         if (!(content instanceof Resource))
35             return null;
36
37         Resource resource = (Resource)content;
38         ChartResource CHART = ChartResource.getInstance(graph);
39         Resource subscriptionItemResource = graph.getPossibleObject(resource, CHART.Chart_Item_HasSubscriptionItem);
40         if (subscriptionItemResource == null)
41             return NoModifierRule.NO_MODIFIER;
42
43         return super.getModifier(graph, subscriptionItemResource, columnKey);
44     }
45
46 }