Java tutorial
/*--------------- Kalypso-Header -------------------------------------------------------------------- This file is part of kalypso. Copyright (C) 2004, 2005 by: Technical University Hamburg-Harburg (TUHH) Institute of River and coastal engineering Denickestr. 22 21073 Hamburg, Germany http://www.tuhh.de/wb and Bjoernsen Consulting Engineers (BCE) Maria Trost 3 56070 Koblenz, Germany http://www.bjoernsen.de This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: E-Mail: belger@bjoernsen.de schlienger@bjoernsen.de v.doemming@tuhh.de ---------------------------------------------------------------------------------------------------*/ package org.kalypso.ogc.sensor.view.actions; import java.io.StringReader; import org.apache.commons.io.IOUtils; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.core.runtime.Status; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchPart; import org.kalypso.ogc.sensor.IObservation; import org.kalypso.ogc.sensor.metadata.ITimeseriesConstants; import org.kalypso.ogc.sensor.timeseries.wq.WQException; import org.kalypso.ogc.sensor.timeseries.wq.wqtable.WQTableFactory; import org.kalypso.ogc.sensor.timeseries.wq.wqtable.WQTableSet; import org.kalypso.ogc.sensor.view.ObservationChooser; import org.kalypso.ogc.sensor.view.wq.WQRelationDialog; import org.kalypso.ui.internal.i18n.Messages; import org.xml.sax.InputSource; /** * @author schlienger */ public class ViewWQRelationHandler extends AbstractHandler { /** * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @Override public Object execute(final ExecutionEvent event) { final IEvaluationContext context = (IEvaluationContext) event.getApplicationContext(); final Shell shell = (Shell) context.getVariable(ISources.ACTIVE_SHELL_NAME); final IWorkbenchPart part = (IWorkbenchPart) context.getVariable(ISources.ACTIVE_PART_NAME); final ObservationChooser chooser = (ObservationChooser) part.getAdapter(ObservationChooser.class); final IObservation obs = chooser.isObservationSelected(chooser.getSelection()); if (obs == null) return Status.OK_STATUS; final String propTable = obs.getMetadataList().getProperty(ITimeseriesConstants.MD_WQ_TABLE); if (propTable == null) return Status.OK_STATUS; final StringReader reader = new StringReader(propTable); try { final WQTableSet set = WQTableFactory.parse(new InputSource(reader)); reader.close(); final WQRelationDialog dlg = new WQRelationDialog(shell, Messages.getString("org.kalypso.ogc.sensor.view.actions.ViewWQRelationHandler.0") //$NON-NLS-1$ + obs.getName(), set); dlg.open(); } catch (final WQException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(reader); } return Status.OK_STATUS; } }