Java tutorial
/*---------------- FILE HEADER KALYPSO ------------------------------------------ * * This file is part of kalypso. * Copyright (C) 2004 by: * * Technical University Hamburg-Harburg (TUHH) * Institute of River and coastal engineering * Denickestrae 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.ui.wizard.sensor; import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.jface.databinding.swt.ISWTObservableValue; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.databinding.viewers.IViewerObservableValue; import org.eclipse.jface.databinding.viewers.ViewersObservables; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.kalypso.commons.databinding.DataBinder; import org.kalypso.commons.databinding.jface.wizard.DatabindingWizardPage; import org.kalypso.commons.databinding.swt.FileAndHistoryData; import org.kalypso.commons.databinding.swt.FileBinding; import org.kalypso.commons.databinding.validation.TimezoneStringValidator; import org.kalypso.contribs.eclipse.jface.wizard.FileChooserDelegateOpen; import org.kalypso.ogc.sensor.IAxis; import org.kalypso.ogc.sensor.adapter.INativeObservationAdapter; import org.kalypso.ui.wizard.sensor.i18n.Messages; /** * @author doemming */ public class ImportObservationSourcePage extends WizardPage { private final ImportObservationData m_data; private DatabindingWizardPage m_binding; public ImportObservationSourcePage(final String pageName, final ImportObservationData data) { super(pageName, null, null); m_data = data; setDescription(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage0")); //$NON-NLS-1$ setTitle(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage1")); //$NON-NLS-1$ setPageComplete(false); } @Override public void createControl(final Composite parent) { initializeDialogUnits(parent); m_binding = new DatabindingWizardPage(this, null); final Group group = new Group(parent, SWT.NONE); group.setLayout(new GridLayout(3, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); group.setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage2")); //$NON-NLS-1$ setControl(group); createFileControl(group); createFormatControl(group); createTimeZoneControl(group); createParameterTypeControl(group); } private void createFileControl(final Composite parent) { final Label label = new Label(parent, SWT.NONE); label.setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage3")); //$NON-NLS-1$ final FileAndHistoryData sourceFileData = m_data.getSourceFileData(); final IObservableValue modelFile = BeansObservables.observeValue(sourceFileData, FileAndHistoryData.PROPERTY_FILE); final IObservableValue modelHistory = BeansObservables.observeValue(sourceFileData, FileAndHistoryData.PROPERTY_HISTORY); final FileChooserDelegateOpen delegate = new FileChooserDelegateOpen(); // final INativeObservationAdapter[] adapters = m_data.getObservationAdapters(); // FIXME: add filter from adapter // FIXME: get from helper delegate.addFilter("All Files (*.*)", "*.*"); final FileBinding fileBinding = new FileBinding(m_binding, modelFile, delegate); final Control historyControl = fileBinding.createFileFieldWithHistory(parent, modelHistory); historyControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Button searchButton = fileBinding.createFileSearchButton(parent, historyControl); setButtonLayoutData(searchButton); // fileBinding.applyBinding( m_binding ); } private void createFormatControl(final Composite parent) { final Label formatLabel = new Label(parent, SWT.NONE); formatLabel .setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage5")); //$NON-NLS-1$ final ComboViewer formatCombo = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY); formatCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); formatCombo.setContentProvider(new ArrayContentProvider()); formatCombo.setLabelProvider(new LabelProvider()); final INativeObservationAdapter[] input = m_data.getObservationAdapters(); formatCombo.setInput(input); new Label(parent, SWT.NONE); /* Binding */ final IViewerObservableValue target = ViewersObservables.observeSinglePostSelection(formatCombo); final IObservableValue model = BeansObservables.observeValue(m_data, ImportObservationData.PROPERTY_ADAPTER); m_binding.bindValue(target, model); } private void createTimeZoneControl(final Composite parent) { final Label timezoneLabel = new Label(parent, SWT.NONE); timezoneLabel.setText(Messages.getString("ImportObservationSelectionWizardPage.0")); //$NON-NLS-1$ final String[] tz = m_data.getAllTimezones(); final ComboViewer comboTimeZones = new ComboViewer(parent, SWT.BORDER | SWT.SINGLE); comboTimeZones.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); comboTimeZones.setContentProvider(new ArrayContentProvider()); comboTimeZones.setLabelProvider(new LabelProvider()); comboTimeZones.setInput(tz); comboTimeZones.addFilter(new TimezoneEtcFilter()); new Label(parent, SWT.NONE); /* Binding */ final IViewerObservableValue targetSelection = ViewersObservables .observeSinglePostSelection(comboTimeZones); final ISWTObservableValue targetModification = SWTObservables.observeSelection(comboTimeZones.getControl()); final IObservableValue model = BeansObservables.observeValue(m_data, ImportObservationData.PROPERTY_TIMEZONE); final DataBinder modificationBinder = new DataBinder(targetModification, model); modificationBinder.addTargetAfterConvertValidator(new TimezoneStringValidator()); m_binding.bindValue(targetSelection, model); m_binding.bindValue(modificationBinder); } private void createParameterTypeControl(final Composite parent) { final Label formatLabel = new Label(parent, SWT.NONE); formatLabel.setText("Parameter Type"); final ComboViewer parameterCombo = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY); parameterCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); parameterCombo.setContentProvider(new ArrayContentProvider()); parameterCombo.setLabelProvider(new LabelProvider()); final IAxis[] axes = m_data.getAllowedParameterAxes(); parameterCombo.setInput(axes); new Label(parent, SWT.NONE); /* Binding */ final IViewerObservableValue target = ViewersObservables.observeSinglePostSelection(parameterCombo); final IObservableValue model = BeansObservables.observeValue(m_data, ImportObservationData.PROPERTY_PARAMETER_AXIS); m_binding.bindValue(target, model); } }