X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.trend%2Fexample%2Forg%2Fsimantics%2Ftrend%2FTestData.java;h=a72789901772359b6b07a60b2777c341290c1ffd;hp=14ea3de272c47bc93ffdb58766a61386b0f81b4c;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.trend/example/org/simantics/trend/TestData.java b/bundles/org.simantics.trend/example/org/simantics/trend/TestData.java index 14ea3de27..a72789901 100644 --- a/bundles/org.simantics.trend/example/org/simantics/trend/TestData.java +++ b/bundles/org.simantics.trend/example/org/simantics/trend/TestData.java @@ -1,92 +1,92 @@ -/******************************************************************************* - * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. - * 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.trend; - -import java.io.File; -import java.util.UUID; - -import org.simantics.databoard.util.Bean; -import org.simantics.history.Collector; -import org.simantics.history.History; -import org.simantics.history.HistoryException; -import org.simantics.history.util.subscription.SubscriptionItem; -import org.simantics.history.HistoryManager; -import org.simantics.history.impl.CollectorImpl; -import org.simantics.simulation.data.DatasourceAdapter; -import org.simantics.simulation.data.PseudoSolver; -import org.simantics.trend.configuration.TrendSamplingFormats; -import org.simantics.utils.FileUtils; - -/** - * Test Data initializes PseudoSolver, HistoryCollector and DatasourceRepository - * - * @author Toni Kalajainen - */ -public class TestData { - - public PseudoSolver solver; - public File workarea; - public HistoryManager historyManager; - public Collector collector; - public DatasourceAdapter adapter; - public String subscriptionId = UUID.randomUUID().toString(); - - public TestData() throws HistoryException { - historyManager = History.createMemoryHistory(); - collector = new CollectorImpl( historyManager ); - init(); - } - - public TestData(File workarea) throws HistoryException { - this.workarea = workarea; - historyManager = History.openFileHistory(workarea); - collector = new CollectorImpl( historyManager ); - init(); - } - - void init() throws HistoryException { - solver = new PseudoSolver(); - SubscriptionItem[] hi = null; - hi = SubscriptionItem.createItems( PseudoSolver.SINE, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "m") ); - historyManager.create(hi); - collector.addItems(hi); - hi = SubscriptionItem.createItems( PseudoSolver.RAMP, subscriptionId, TrendSamplingFormats.createBinarySamplingFormats(0) ); - historyManager.create(hi); - collector.addItems(hi); - hi = SubscriptionItem.createItems( PseudoSolver.RANDOM, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "j") ); - historyManager.create(hi); - collector.addItems(hi); - - adapter = new DatasourceAdapter( collector ); - solver.addListener(adapter); - } - - public void dispose() { - solver.removeListener(adapter); - adapter.reset(); - solver.stop(); - collector.close(); - try { - for (Bean bean : collector.getItems()) { - String id = (String) bean.getFieldUnchecked("id"); - historyManager.delete(id); - } - } catch (HistoryException e) { - e.printStackTrace(); - } - historyManager.close(); - if (workarea != null) { - FileUtils.deleteDir(workarea); - } - } - -} - +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * 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.trend; + +import java.io.File; +import java.util.UUID; + +import org.simantics.databoard.util.Bean; +import org.simantics.history.Collector; +import org.simantics.history.History; +import org.simantics.history.HistoryException; +import org.simantics.history.util.subscription.SubscriptionItem; +import org.simantics.history.HistoryManager; +import org.simantics.history.impl.CollectorImpl; +import org.simantics.simulation.data.DatasourceAdapter; +import org.simantics.simulation.data.PseudoSolver; +import org.simantics.trend.configuration.TrendSamplingFormats; +import org.simantics.utils.FileUtils; + +/** + * Test Data initializes PseudoSolver, HistoryCollector and DatasourceRepository + * + * @author Toni Kalajainen + */ +public class TestData { + + public PseudoSolver solver; + public File workarea; + public HistoryManager historyManager; + public Collector collector; + public DatasourceAdapter adapter; + public String subscriptionId = UUID.randomUUID().toString(); + + public TestData() throws HistoryException { + historyManager = History.createMemoryHistory(); + collector = new CollectorImpl( historyManager ); + init(); + } + + public TestData(File workarea) throws HistoryException { + this.workarea = workarea; + historyManager = History.openFileHistory(workarea); + collector = new CollectorImpl( historyManager ); + init(); + } + + void init() throws HistoryException { + solver = new PseudoSolver(); + SubscriptionItem[] hi = null; + hi = SubscriptionItem.createItems( PseudoSolver.SINE, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "m") ); + historyManager.create(hi); + collector.addItems(hi); + hi = SubscriptionItem.createItems( PseudoSolver.RAMP, subscriptionId, TrendSamplingFormats.createBinarySamplingFormats(0) ); + historyManager.create(hi); + collector.addItems(hi); + hi = SubscriptionItem.createItems( PseudoSolver.RANDOM, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "j") ); + historyManager.create(hi); + collector.addItems(hi); + + adapter = new DatasourceAdapter( collector ); + solver.addListener(adapter); + } + + public void dispose() { + solver.removeListener(adapter); + adapter.reset(); + solver.stop(); + collector.close(); + try { + for (Bean bean : collector.getItems()) { + String id = (String) bean.getFieldUnchecked("id"); + historyManager.delete(id); + } + } catch (HistoryException e) { + e.printStackTrace(); + } + historyManager.close(); + if (workarea != null) { + FileUtils.deleteDir(workarea); + } + } + +} +