X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FAddVariableToChartAction.java;h=4d2a1317aedc07ca9d63faa5c43c05383d3e29d1;hp=4caa80a66037275d2cb8a364075c185496b41901;hb=878d7a270f47ae61c606bbd7ea38d8dc6102db3b;hpb=777f66ad0fc587dd8d313705442dd2338c65ad30 diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/AddVariableToChartAction.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/AddVariableToChartAction.java index 4caa80a66..4d2a1317a 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/AddVariableToChartAction.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/AddVariableToChartAction.java @@ -1,210 +1,211 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.charts.ui; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.simantics.Simantics; -import org.simantics.charts.query.AddChartItem; -import org.simantics.charts.query.ChartAndSubscriptionItemData; -import org.simantics.charts.query.ChartItemDescriptor; -import org.simantics.charts.query.NextChartItemIndexQuery; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.type.BooleanType; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.PossibleModel; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.VariableReference; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.subscription.NewSubscription; -import org.simantics.modeling.subscription.NewSubscriptionItem; -import org.simantics.modeling.subscription.SubscriptionsQuery; -import org.simantics.modeling.subscription.SubscriptionsQuery.SubscriptionsResult; -import org.simantics.trend.configuration.TrendItem.Renderer; -import org.simantics.utils.ui.dialogs.ShowError; - -public class AddVariableToChartAction implements Runnable { - - Resource chart; - Resource subscription; - Resource model; - - String chartName; - String subscriptionName; - SubscriptionsResult subscriptions; - List refs; - List variableReferences; // String references - - public AddVariableToChartAction( Resource chart, Resource subscription, List refs ) { - this.refs = refs; - this.chart = chart; - this.subscription = subscription; - } - - /** - * Reads necessary data from session. - * - * @throws DatabaseException - */ - public AddVariableToChartAction init() throws DatabaseException - { - Simantics.getSession().sync( new ReadRequest() { - @Override - public void run(ReadGraph g) throws DatabaseException { - init(g); - } - } ); - return this; - } - - /** - * Reads necessary data from session. - * - * @throws DatabaseException - */ - public AddVariableToChartAction init( ReadGraph g ) throws DatabaseException - { - Layer0 L0 = Layer0.getInstance(g); - if(chart != null) { - chartName = g.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING); - model = g.syncRequest(new PossibleModel(chart)); - } - else - model = g.syncRequest(new PossibleModel(subscription)); - if (model == null) throw new DatabaseException("Model was not found"); - - Variable configuration = Variables.getConfigurationContext(g, model); - - subscriptions = g.sync( new SubscriptionsQuery(model) ); - if(subscription != null) - subscriptionName = g.getPossibleRelatedValue(subscription, L0.HasLabel, Bindings.STRING); - variableReferences = new ArrayList(); - - for (VariableReference var : refs) { - if ( var.label == null ) { - variableReferences.add( var.getVariableId().toPossibleString(g, configuration) ); - } - } - - return this; - } - - /** - * Opens dialog, if clicked OK, writes to graph async. - * - * Remember to run this in SWT Thread. - */ - public void runInSwt() { - - final Display display = Display.getCurrent(); - final Shell shell = display.getActiveShell(); - - Simantics.getSession().markUndoPoint(); - - for (int i=0; i refs; + List variableReferences; // String references + + public AddVariableToChartAction( Resource chart, Resource subscription, List refs ) { + this.refs = refs; + this.chart = chart; + this.subscription = subscription; + } + + /** + * Reads necessary data from session. + * + * @throws DatabaseException + */ + public AddVariableToChartAction init() throws DatabaseException + { + Simantics.getSession().sync( new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + init(g); + } + } ); + return this; + } + + /** + * Reads necessary data from session. + * + * @throws DatabaseException + */ + public AddVariableToChartAction init( ReadGraph g ) throws DatabaseException + { + Layer0 L0 = Layer0.getInstance(g); + if(chart != null) { + chartName = g.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING); + model = g.syncRequest(new PossibleModel(chart)); + } + else + model = g.syncRequest(new PossibleModel(subscription)); + if (model == null) throw new DatabaseException("Model was not found"); + + Variable configuration = Variables.getConfigurationContext(g, model); + + subscriptions = g.sync( new SubscriptionsQuery(model) ); + if(subscription != null) + subscriptionName = g.getPossibleRelatedValue(subscription, L0.HasLabel, Bindings.STRING); + variableReferences = new ArrayList(); + + for (VariableReference var : refs) { + if ( var.label == null ) { + variableReferences.add( var.getVariableId().toPossibleString(g, configuration) ); + } + } + + return this; + } + + /** + * Opens dialog, if clicked OK, writes to graph async. + * + * Remember to run this in SWT Thread. + */ + public void runInSwt() { + + final Display display = Display.getCurrent(); + final Shell shell = display.getActiveShell(); + + Simantics.getSession().markUndoPoint(); + + for (int i=0; i