Skip to main content
summaryrefslogtreecommitdiffstats
blob: 04389611ea91bf1eb31449445de24123a1ffc92e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// RelatieValueHistoryProviderAdapter.java
package org.eclipse.stem.definitions.adapters.relativevalue.history;

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.stem.adapters.history.HistoryExtendedListener;
import org.eclipse.stem.adapters.history.HistoryProviderAdapter;
import org.eclipse.stem.core.model.STEMTime;
import org.eclipse.stem.definitions.adapters.relativevalue.RelativeValueProviderAdapter;

/**
 * This class adapts <code>EObjects</code>'s to
 * <code>RelativeValueProvider</code>'s.
 */
public abstract class RelativeValueHistoryProviderAdapter extends
		RelativeValueProviderAdapter implements RelativeValueHistoryProvider,
		HistoryExtendedListener {

	private List<RelativeValueHistoryExtendedListener> extensionListeners = new CopyOnWriteArrayList<RelativeValueHistoryExtendedListener>();

	// This should be removed DAF
	private static final int earliestCycleNumber = 0;

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getRelativeValue(org.eclipse.emf.edit.provider.ItemPropertyDescriptor,
	 *      org.eclipse.stem.core.model.STEMTime)
	 */
	public double getRelativeValue(final ItemPropertyDescriptor property,
			final STEMTime time) {
		return getRelativeValue((EStructuralFeature) property.getFeature(null),
				time);
	}

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getRelativeValue(org.eclipse.emf.ecore.EStructuralFeature,
	 *      org.eclipse.stem.core.model.STEMTime)
	 */
	abstract public double getRelativeValue(EStructuralFeature feature,
			STEMTime time);

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getAllHistoricRelativeValues(org.eclipse.emf.ecore.EStructuralFeature)
	 */
	abstract public double[] getAllHistoricRelativeValues(
			EStructuralFeature feature);

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getAllHistoricRelativeValues(org.eclipse.emf.edit.provider.ItemPropertyDescriptor)
	 */
	public double[] getAllHistoricRelativeValues(
			final ItemPropertyDescriptor property) {
		return getAllHistoricRelativeValues((EStructuralFeature) property
				.getFeature(null));
	}

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getAllHistoricTimeValues()
	 */
	abstract public STEMTime[] getAllHistoricTimeValues();

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getEarliestTimeValue()
	 */
	abstract public STEMTime getEarliestTimeValue();

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getEarliestCycleNumber()
	 */

	/**
	 * @see org.eclipse.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider#getEarliestCycleNumber()
	 */
	public int getEarliestCycleNumber() {
		return earliestCycleNumber;
	}

	/**
	 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
	 */
	@Override
	public boolean isAdapterForType(final Object type) {
		return type == RelativeValueHistoryProvider.class;
	}

	/**
	 * @see org.eclipse.stem.adapters.history.HistoryExtendedListener#historyExtended(org.eclipse.stem.adapters.history.HistoryProviderAdapter)
	 */
	public void historyExtended(HistoryProviderAdapter historyProviderAdapter) {
		fireHistoryExtended();
	}

	public void addExtensionListener(
			RelativeValueHistoryExtendedListener listener) {
		extensionListeners.add(listener);
	}

	public void removeExtensionListener(
			RelativeValueHistoryExtendedListener listener) {
		extensionListeners.remove(listener);
	}

	protected void fireHistoryExtended() {
		for (RelativeValueHistoryExtendedListener listener : extensionListeners) {
			listener.relativeValueHistoryExtended(this);
		} // for each HistoryExtendedListener
	}

} // RelatieValueHistoryProviderAdapter

Back to the top