]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartData.java
b44556b633713f976ce7ec437f715d86919dd287
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / ChartData.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 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.charts.editor;
13
14 import org.simantics.databoard.annotations.Optional;
15 import org.simantics.db.Resource;
16 import org.simantics.history.Collector;
17 import org.simantics.history.HistoryManager;
18 import org.simantics.simulation.data.Datasource;
19 import org.simantics.simulation.experiment.IExperiment;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public final class ChartData {
25
26     /**
27      * The model for which this ChartData is valid, i.e. the model that contains
28      * {@link #run} if {@link #run} is non<code>non-null</code>
29      */
30     @Optional
31     public Resource       model;
32
33     /**
34      * If just reading data from file system, not the database, this may be
35      * <code>null</code>.
36      */
37     @Optional
38     public Resource       run;
39
40     /**
41      * Used for giving the chart access to the active experiment state.
42      */
43     @Optional
44     public IExperiment    experiment;
45
46     /**
47      * May be null if the chart data is not connected to a running experiment.
48      */
49     @Optional
50     public Datasource     datasource;
51
52     @Optional
53     public HistoryManager history;
54
55     /**
56      * Optional collector, Chart uses this to flush data right before drawing it
57      */
58     @Optional
59     public Collector      collector;
60
61     public ChartData(Resource model, Resource run, IExperiment experiment, Datasource datasource, HistoryManager history, Collector collector) {
62         this.model = model;
63         this.run = run;
64         this.experiment = experiment;
65         this.datasource = datasource;
66         this.history = history;
67         this.collector = collector;
68     }
69     
70     public void readFrom(ChartData other) {
71         if (other==null) {
72                 this.model = null;
73                 this.run = null;
74                 this.experiment = null;
75                 this.datasource = null;
76                 this.history = null;
77                 this.collector = null;
78         } else {
79                 this.model = other.model;
80                 this.run = other.run;
81                 this.experiment = other.experiment;
82                 this.datasource = other.datasource;
83                 this.history = other.history;
84                 this.collector = other.collector;
85         }
86     }
87
88     /**
89      * Dispose by closing history
90      */
91     public void dispose() {
92         model = null;
93         run = null;
94         experiment = null;
95         datasource = null;
96         if (history != null) {
97                 history.close();
98                 history = null;
99         }
100     }
101
102 }