1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\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.jfreechart.chart.properties;
\r
14 import org.eclipse.jface.viewers.ISelection;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.db.layer0.variable.Variable;
\r
19 import org.simantics.db.request.Read;
\r
20 import org.simantics.layer0.Layer0;
\r
21 import org.simantics.modeling.ModelingResources;
\r
22 import org.simantics.selectionview.PropertyTabContributorImpl;
\r
23 import org.simantics.utils.ui.AdaptionUtils;
\r
25 public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl {
\r
28 public Read<String> getPartNameReadRequest(final ISelection forSelection) {
\r
30 return new Read<String>() {
\r
33 public String perform(ReadGraph graph) throws DatabaseException {
\r
34 Layer0 l0 = Layer0.getInstance(graph);
\r
35 ModelingResources mr = ModelingResources.getInstance(graph);
\r
37 final Variable variable = AdaptionUtils.adaptToSingle(forSelection, Variable.class);
\r
38 final Resource resource = AdaptionUtils.adaptToSingle(forSelection, Resource.class);
\r
39 if(resource == null && variable == null) {
\r
44 if(variable != null) {
\r
45 r = (Resource)variable.getRepresents(graph);
\r
50 if(graph.hasStatement(r, mr.ElementToComponent)) {
\r
51 r = graph.getSingleObject(r, mr.ElementToComponent);
\r
53 String label = graph.getPossibleRelatedValue(r, l0.HasLabel);
\r
56 label = graph.getPossibleRelatedValue(r, l0.HasName);
\r
59 return "No name for selection";
\r