/* * Copyright (c) 2004-2011 Marco Maccaferri 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: * Marco Maccaferri - initial API and implementation */ package org.eclipsetrader.ui.internal.charts; import java.util.Date; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipsetrader.core.charts.DataSeries; import org.eclipsetrader.core.charts.IDataSeries; import org.eclipsetrader.core.feed.IOHLC; import org.eclipsetrader.ui.charts.HistogramBarChart; import org.eclipsetrader.ui.charts.IChartObject; import org.eclipsetrader.ui.charts.IChartObjectFactory; import org.eclipsetrader.ui.charts.IChartParameters; public class VOLUME implements IChartObjectFactory, IExecutableExtension { private String id; private String name; private static class ValueWrapper implements IAdaptable { private IOHLC ohlc; public ValueWrapper(IOHLC ohlc) { this.ohlc = ohlc; } /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object getAdapter(Class adapter) { if (adapter.isAssignableFrom(Date.class)) { return ohlc.getDate(); } if (adapter.isAssignableFrom(Number.class)) { return ohlc.getVolume(); } if (adapter.isAssignableFrom(getClass())) { return this; } return null; } } public VOLUME() { } /* (non-Javadoc) * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) */ @Override public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { id = config.getAttribute("id"); name = config.getAttribute("name"); } /* (non-Javadoc) * @see org.eclipsetrader.charts.ui.indicators.IChartIndicator#getId() */ @Override public String getId() { return id; } /* (non-Javadoc) * @see org.eclipsetrader.charts.ui.indicators.IChartIndicator#getName() */ @Override public String getName() { return name; } /* (non-Javadoc) * @see org.eclipsetrader.ui.charts.IChartObjectFactory#createObject(org.eclipsetrader.core.charts.IDataSeries) */ @Override public IChartObject createObject(IDataSeries source) { if (source != null) { IAdaptable[] sourceValues = source.getValues(); ValueWrapper[] values = new ValueWrapper[sourceValues.length]; for (int i = 0; i < values.length; i++) { values[i] = new ValueWrapper((IOHLC) sourceValues[i].getAdapter(IOHLC.class)); } IDataSeries result = new DataSeries(getName(), values); return new HistogramBarChart(result); } return null; } /* (non-Javadoc) * @see org.eclipsetrader.ui.charts.IChartObjectFactory#getParameters() */ @Override public IChartParameters getParameters() { return null; } /* (non-Javadoc) * @see org.eclipsetrader.ui.charts.IChartObjectFactory#setParameters(org.eclipsetrader.ui.charts.IChartParameters) */ @Override public void setParameters(IChartParameters parameters) { name = parameters.hasParameter("name") ? parameters.getString("name") : name; } }