Example usage for org.eclipse.jface.viewers ComboViewer setLabelProvider

List of usage examples for org.eclipse.jface.viewers ComboViewer setLabelProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ComboViewer setLabelProvider.

Prototype

@Override
public void setLabelProvider(IBaseLabelProvider labelProvider) 

Source Link

Document

The list viewer implementation of this Viewer framework method ensures that the given label provider is an instance of ILabelProvider.

Usage

From source file:org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.java

License:Open Source License

private void createStyleNameControls(final Composite parent) {
    final Label styleNameLabel = new Label(parent, SWT.NONE);
    styleNameLabel.setText(Messages.getString("org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.8")); //$NON-NLS-1$

    final ComboViewer styleNameChooser = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    styleNameChooser.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    styleNameChooser.setContentProvider(new ArrayContentProvider());
    styleNameChooser.setLabelProvider(new LabelProvider() {
        @Override/*www  .j av  a 2s. c  o  m*/
        public String getText(final Object element) {
            if (element instanceof UserStyle) {
                final UserStyle userStyle = (UserStyle) element;
                final String title = userStyle.getTitle();
                if (StringUtils.isBlank(title))
                    return userStyle.getName();
                return title;
            }

            return ObjectUtils.toString(element);
        }
    });

    /* bind input */
    final IObservableValue targetInput = ViewersObservables.observeInput(styleNameChooser);
    final IObservableValue modelInput = BeansObservables.observeValue(m_data,
            ImportShapeFileData.PROPERTY_STYLES);
    m_binding.bindValue(targetInput, modelInput);

    /* bind selection */
    final IObservableValue targetSelection = ViewersObservables.observeSinglePostSelection(styleNameChooser);
    final IObservableValue modelSelection = BeansObservables.observeValue(m_data,
            ImportShapeFileData.PROPERTY_STYLE);
    m_binding.bindValue(targetSelection, modelSelection);

    /* Enablement */
    final IObservableValue modelEnablement = BeansObservables.observeValue(m_data,
            ImportShapeFileData.PROPERTY_STYLE_NAME_CONTROL_ENABLED);

    final IObservableValue targetLabelEnablement = SWTObservables.observeEnabled(styleNameLabel);
    m_binding.bindValue(targetLabelEnablement, modelEnablement);

    final IObservableValue targetComboEnablement = SWTObservables.observeEnabled(styleNameChooser.getControl());
    m_binding.bindValue(targetComboEnablement, modelEnablement);
}

From source file:org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.java

License:Open Source License

public void createControlSource(final Composite parent) {
    final Group group = new Group(parent, SWT.NONE);
    group.setText(Messages/*from w  ww.  ja  va2  s. c  o  m*/
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.5")); //$NON-NLS-1$

    final GridData groupData = new GridData(SWT.FILL, SWT.FILL, true, false);
    group.setLayoutData(groupData);

    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    group.setLayout(gridLayout);

    /* file selection */
    final Label labelFilePath = new Label(group, SWT.READ_ONLY);
    labelFilePath.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.6")); //$NON-NLS-1$

    m_textFileSource = new Text(group, SWT.READ_ONLY | SWT.BORDER);
    m_textFileSource.setText(DEFAUL_FILE_LABEL);
    m_textFileSource.addFocusListener(this);

    final GridData textData = new GridData(SWT.FILL, SWT.FILL, true, false);
    m_textFileSource.setLayoutData(textData);

    /* Choose file button */
    final Button chooseFileButton = new Button(group, SWT.PUSH);
    chooseFileButton.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.7")); //$NON-NLS-1$
    final GridData chooseFileButtonGridData = new GridData();
    chooseFileButtonGridData.horizontalAlignment = GridData.END;
    chooseFileButton.setLayoutData(chooseFileButtonGridData);

    chooseFileButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_sourceFile = chooseFile(m_sourceFile);
            if (m_sourceFile != null) {
                m_textFileSource.setText(m_sourceFile.getPath());
                validate();
            }
        }
    });

    final Label formatLabel = new Label(group, SWT.NONE);
    formatLabel.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.10")); //$NON-NLS-1$

    m_formatCombo = new ComboViewer(group, SWT.READ_ONLY | SWT.DROP_DOWN);

    final GridData formatData = new GridData(SWT.FILL, SWT.FILL, true, false);
    m_formatCombo.getControl().setLayoutData(formatData);

    m_formatCombo.add(m_adapter);

    m_formatCombo.setContentProvider(new ArrayContentProvider());

    m_formatCombo.setLabelProvider(new ILabelProvider() {
        @Override
        public Image getImage(final Object element) {
            return null;
        }

        @Override
        public String getText(final Object element) {
            return element.toString();
        }

        @Override
        public void addListener(final ILabelProviderListener listener) {
            // nothing as labelprovider will not change
        }

        @Override
        public void dispose() {
            // nothing as labelprovider will not change
        }

        @Override
        public boolean isLabelProperty(final Object element, final String property) {
            return true;
        }

        @Override
        public void removeListener(final ILabelProviderListener listener) {
            // nothing
        }
    });

    m_formatCombo.setInput(m_adapter);
    m_formatCombo.addSelectionChangedListener(this);

    if (m_adapter.length > 0)
        m_formatCombo.setSelection(new StructuredSelection(m_adapter[0]));

    // just a placeholder
    new Label(group, SWT.NONE);

    /* time zone selection */
    final Label timezoneLabel = new Label(group, SWT.NONE);
    timezoneLabel.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.0")); //$NON-NLS-1$

    final String[] tz = TimeZone.getAvailableIDs();
    Arrays.sort(tz);

    final ComboViewer comboTimeZones = new ComboViewer(group, SWT.BORDER | SWT.SINGLE);
    comboTimeZones.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    m_timezone = KalypsoCorePlugin.getDefault().getTimeZone();

    comboTimeZones.setContentProvider(new ArrayContentProvider());
    comboTimeZones.setLabelProvider(new LabelProvider());
    comboTimeZones.setInput(tz);

    comboTimeZones.addFilter(new TimezoneEtcFilter());

    comboTimeZones.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) comboTimeZones.getSelection();
            updateTimeZone((String) selection.getFirstElement());
        }
    });

    comboTimeZones.getCombo().addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            updateTimeZone(comboTimeZones.getCombo().getText());
        }
    });

    if (m_timezone != null) {
        final String id = m_timezone.getID();
        if (ArrayUtils.contains(tz, id))
            comboTimeZones.setSelection(new StructuredSelection(id));
        else
            comboTimeZones.getCombo().setText(id);
    }

    // just a placeholder
    new Label(group, SWT.NONE);
}

From source file:org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    m_binding = new DatabindingWizardPage(this, null);

    final int comboWidth1 = 75;
    final int comboWidth2 = 50;

    final Composite composite = new Composite(parent, SWT.NONE);
    setControl(composite);/*from   w w w.  j  av a2  s  .c om*/
    composite.setLayout(new GridLayout());

    /* Status */
    final IStatus status = m_data.getStatus();
    if (!status.isOK()) {
        final StatusComposite statusComposite = new StatusComposite(composite, SWT.NONE);
        statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        statusComposite.setStatus(status);
    }

    /* river line selection group */
    final Group riverLineGroup = new Group(composite, SWT.NONE);
    riverLineGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    riverLineGroup.setLayout(new GridLayout(2, false));
    riverLineGroup.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.4")); //$NON-NLS-1$

    final Label riverLineText = new Label(riverLineGroup, SWT.NONE);
    riverLineText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    riverLineText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.5")); //$NON-NLS-1$

    final ComboViewer comboRiverLine = new ComboViewer(riverLineGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    final GridData gridDatacomboRiverLine = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gridDatacomboRiverLine.widthHint = comboWidth1;
    comboRiverLine.getControl().setLayoutData(gridDatacomboRiverLine);
    comboRiverLine.setContentProvider(new ArrayContentProvider());
    comboRiverLine.setLabelProvider(new LabelProvider());
    comboRiverLine.setInput(m_data.getRiverThemes());

    final IViewerObservableValue targetRiverLine = ViewersObservables
            .observeSinglePostSelection(comboRiverLine);
    final IObservableValue modelRiverLine = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_RIVER_LINE);
    final IValidator riverLineNotNullValidator = new NotNullValidator<>(IKalypsoFeatureTheme.class,
            IStatus.WARNING, Messages.getString("ConfigureLengthSectionWizardPage.0")); //$NON-NLS-1$
    m_binding.bindValue(targetRiverLine, modelRiverLine, riverLineNotNullValidator);

    /*
     * define properties page ( river name field selection combo river name selection combo, delta station spinner,
     * station field select combo)
     */
    final Group propertyGroup = new Group(composite, SWT.NONE);
    propertyGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    propertyGroup.setLayout(new GridLayout(2, false));
    propertyGroup.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.6")); //$NON-NLS-1$

    /* Water Body Name */
    final Label riverNameText = new Label(propertyGroup, SWT.NONE);
    riverNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    riverNameText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.7")); //$NON-NLS-1$

    final ComboViewer comboRiverNameField = new ComboViewer(propertyGroup, SWT.NONE | SWT.READ_ONLY);
    final GridData gridDataComboRiverName = new GridData(SWT.FILL, SWT.END, true, false);
    gridDataComboRiverName.widthHint = comboWidth2;
    comboRiverNameField.getControl().setLayoutData(gridDataComboRiverName);

    comboRiverNameField.setContentProvider(new ArrayContentProvider());
    comboRiverNameField.setLabelProvider(new PropertyNameLabelProvider());

    final IObservableValue targetRiverNameInput = ViewersObservables.observeInput(comboRiverNameField);
    final IObservableValue modelRiverNameInput = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_RIVER_NAME_INPUT);
    m_binding.bindValue(targetRiverNameInput, modelRiverNameInput);

    final IViewerObservableValue targetRiverName = ViewersObservables
            .observeSinglePostSelection(comboRiverNameField);
    final IObservableValue modelRiverName = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_RIVER_NAME_PROPERTY);
    final IValidator riverNameNotNullValidator = new NotNullValidator<>(IValuePropertyType.class, IStatus.ERROR,
            Messages.getString("ConfigureLengthSectionWizardPage.1")); //$NON-NLS-1$
    m_binding.bindValue(targetRiverName, modelRiverName, riverNameNotNullValidator);

    /* Selected water body */
    final Label selectedRiverText = new Label(propertyGroup, SWT.NONE);
    selectedRiverText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    selectedRiverText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.8")); //$NON-NLS-1$

    final ComboViewer comboSelectedRiverNameField = new ComboViewer(propertyGroup, SWT.NONE | SWT.READ_ONLY);
    final GridData gridDataComboSelectedRiverField = new GridData(SWT.FILL, SWT.END, true, false);
    gridDataComboSelectedRiverField.widthHint = comboWidth2;
    comboSelectedRiverNameField.getControl().setLayoutData(gridDataComboSelectedRiverField);

    comboSelectedRiverNameField.setContentProvider(new ArrayContentProvider());
    comboSelectedRiverNameField.setLabelProvider(new LabelProvider());

    final IObservableValue targetSelectedRiverNameInput = ViewersObservables
            .observeInput(comboSelectedRiverNameField);
    final IObservableValue modelSelectedRiverNameInput = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_RIVER_NAMES);
    m_binding.bindValue(targetSelectedRiverNameInput, modelSelectedRiverNameInput);

    final IViewerObservableValue targetSelectedRiverName = ViewersObservables
            .observeSinglePostSelection(comboSelectedRiverNameField);
    final IObservableValue modelSelectedRiverName = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_SELECTED_RIVER_NAME);
    final IValidator selectedRiverNameNotNullValidator = new NotNullValidator<>(String.class, IStatus.ERROR,
            Messages.getString("ConfigureLengthSectionWizardPage.2")); //$NON-NLS-1$
    m_binding.bindValue(targetSelectedRiverName, modelSelectedRiverName, selectedRiverNameNotNullValidator);

    /* Station from */
    final Label stationFromFieldText = new Label(propertyGroup, SWT.NONE);
    stationFromFieldText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    stationFromFieldText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.9")); //$NON-NLS-1$

    final ComboViewer comboStationFromField = new ComboViewer(propertyGroup, SWT.NONE | SWT.READ_ONLY);
    final GridData gridDatacomboStationFromField = new GridData(SWT.FILL, SWT.END, true, false);
    gridDatacomboStationFromField.widthHint = comboWidth2;
    comboStationFromField.getControl().setLayoutData(gridDatacomboStationFromField);

    comboStationFromField.setContentProvider(new ArrayContentProvider());
    comboStationFromField.setLabelProvider(new PropertyNameLabelProvider());

    final IObservableValue targetStationFromInput = ViewersObservables.observeInput(comboStationFromField);
    final IObservableValue modelStationFromInput = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_STATION_FROM_INPUT);
    m_binding.bindValue(targetStationFromInput, modelStationFromInput);

    final IViewerObservableValue targetStationFrom = ViewersObservables
            .observeSinglePostSelection(comboStationFromField);
    final IObservableValue modelStationFrom = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_STATION_FROM_PROPERTY);
    m_binding.bindValue(targetStationFrom, modelStationFrom);

    /* Station to */
    final Label stationToFieldText = new Label(propertyGroup, SWT.NONE);
    stationToFieldText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    stationToFieldText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.10")); //$NON-NLS-1$

    final ComboViewer comboStationToField = new ComboViewer(propertyGroup, SWT.NONE | SWT.READ_ONLY);
    final GridData gridDatacomboStationToField = new GridData(SWT.FILL, SWT.END, true, false);
    gridDatacomboStationToField.widthHint = comboWidth2;
    comboStationToField.getControl().setLayoutData(gridDatacomboStationToField);

    comboStationToField.setContentProvider(new ArrayContentProvider());
    comboStationToField.setLabelProvider(new PropertyNameLabelProvider());

    final IObservableValue targetStationToInput = ViewersObservables.observeInput(comboStationToField);
    final IObservableValue modelStationToInput = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_STATION_TO_INPUT);
    m_binding.bindValue(targetStationToInput, modelStationToInput);

    final IViewerObservableValue targetStationTo = ViewersObservables
            .observeSinglePostSelection(comboStationToField);
    final IObservableValue modelStationTo = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_STATION_TO_PROPERTY);
    m_binding.bindValue(targetStationTo, modelStationTo);

    /* km or m checkbox */
    final Label dummy1 = new Label(propertyGroup, SWT.NONE);
    dummy1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Button buttonKmValues = new Button(propertyGroup, SWT.CHECK);
    buttonKmValues.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    buttonKmValues.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.11")); //$NON-NLS-1$

    final ISWTObservableValue targetUseKmValues = SWTObservables.observeSelection(buttonKmValues);
    final IObservableValue modelUseKmValues = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_USE_KM_VALUES);
    m_binding.bindValue(targetUseKmValues, modelUseKmValues);

    /* sampling distance */
    final Label samplingDistanceText = new Label(propertyGroup, SWT.NONE);
    samplingDistanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    samplingDistanceText.setText(
            Messages.getString("org.kalypso.ui.wizards.lengthsection.ConfigureLengthSectionWizardPage.12")); //$NON-NLS-1$

    final Spinner samplingDistanceSpinner = new Spinner(propertyGroup, SWT.BORDER | SWT.TRAIL);
    final GridData gridDatastationSpinner = new GridData(SWT.FILL, SWT.END, true, false);
    gridDatastationSpinner.widthHint = 30;
    samplingDistanceSpinner.setLayoutData(gridDatastationSpinner);

    samplingDistanceSpinner.setValues(0, 1, 1000, 0, 1, 100);

    final ISWTObservableValue targetSamplingDistance = SWTObservables.observeSelection(samplingDistanceSpinner);
    final IObservableValue modelSamplingDistance = BeansObservables.observeValue(m_data,
            CreateLengthSectionData.PROPERTY_SAMPLING_DISTANCE);
    m_binding.bindValue(targetSamplingDistance, modelSamplingDistance);
}

From source file:org.kalypso.ui.wizards.results.editor.VectorEditorComposite.java

License:Open Source License

private void createUomControl(final Composite comp) {
    /* uom type combo */
    // combo text
    final Label comboTextLabel = new Label(comp, SWT.NONE);
    comboTextLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    comboTextLabel.setText(Messages.getString("org.kalypso.ui.wizards.results.VectorEditorComposite.4")); //$NON-NLS-1$

    final ComboViewer uomTypeCombo = new ComboViewer(comp, SWT.READ_ONLY);
    final GridData comboGridData = new GridData(SWT.END, SWT.CENTER, false, false);
    comboGridData.widthHint = 25;//from w  ww. j  av  a 2 s .c  om
    uomTypeCombo.getControl().setLayoutData(comboGridData);
    uomTypeCombo.setContentProvider(new ArrayContentProvider());

    final String[] types = new String[2];
    types[0] = "Meter"; //$NON-NLS-1$
    types[1] = "Pixel"; //$NON-NLS-1$

    uomTypeCombo.setInput(types);
    if (m_uom == UOM.pixel)
        uomTypeCombo.setSelection(new StructuredSelection(uomTypeCombo.getElementAt(1)));
    else
        uomTypeCombo.setSelection(new StructuredSelection(uomTypeCombo.getElementAt(0)));

    uomTypeCombo.setLabelProvider(new LabelProvider() {
        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(final Object element) {

            return super.getText(element);
        }
    });

    // selection listener
    uomTypeCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        @SuppressWarnings("synthetic-access")
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            final Object element = selection.getFirstElement();

            final String string = (String) element;

            // TODO: get the GraphicFill from a GraphicFill editor.
            // right now, there is just possible a plain fill .

            if (string == "Meter") //$NON-NLS-1$
            {
                m_symb.setUom(UOM.meter);
            } else if (string == "Pixel") //$NON-NLS-1$
            {
                m_symb.setUom(UOM.pixel);
            }

            contentChanged();
        }
    });
}

From source file:org.kalypso.zml.ui.imports.ImportObservationSourcePage.java

License:Open Source License

private void createFormatControl(final Composite parent) {
    final Label formatLabel = new Label(parent, SWT.NONE);
    formatLabel/* w  w  w  .  j  a v  a  2 s . c  om*/
            .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, new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (Objects.isNull(value)) {
                setErrorMessage(Messages.getString("ImportObservationSourcePage.1")); //$NON-NLS-1$
                return Status.CANCEL_STATUS;
            }

            return Status.OK_STATUS;
        }
    });
}

From source file:org.kalypso.zml.ui.imports.ImportObservationSourcePage.java

License:Open Source License

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 = TimezoneUtilities.getSupportedTimezones();

    final ComboViewer comboTimeZones = new ComboViewer(parent,
            SWT.BORDER | SWT.SINGLE | SWT.DROP_DOWN | SWT.READ_ONLY);
    comboTimeZones.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    comboTimeZones.setContentProvider(new ArrayContentProvider());
    comboTimeZones.setLabelProvider(new LabelProvider());
    comboTimeZones.setInput(tz);//from w ww  .  ja  v  a  2s  .co m

    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);
}

From source file:org.kalypso.zml.ui.imports.ImportObservationSourcePage.java

License:Open Source License

private void createParameterTypeControl(final Composite parent) {
    final Label formatLabel = new Label(parent, SWT.NONE);
    formatLabel.setText(Messages.getString("ImportObservationSourcePage.2")); //$NON-NLS-1$

    final ComboViewer parameterCombo = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    parameterCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final ParameterTypeLabelProvider labelProvider = new ParameterTypeLabelProvider();
    parameterCombo.setLabelProvider(labelProvider);
    parameterCombo.setContentProvider(new ArrayContentProvider());

    parameterCombo.setSorter(new ViewerSorter() {
        @Override//from  w w w . j  a va 2  s. co  m
        public int compare(final org.eclipse.jface.viewers.Viewer viewer, final Object e1, final Object e2) {
            final String l1 = labelProvider.getText(e1);
            final String l2 = labelProvider.getText(e2);

            if (StringUtils.isNotEmpty(l1) && StringUtils.isNotEmpty(l2))
                return l1.compareTo(l2);

            return super.compare(viewer, e1, e2);
        }
    });

    final String[] parameterTypes = m_data.getAllowedParameterTypes();
    parameterCombo.setInput(parameterTypes);

    new Label(parent, SWT.NONE);

    /* Binding */
    final IViewerObservableValue target = ViewersObservables.observeSinglePostSelection(parameterCombo);
    final IObservableValue model = BeansObservables.observeValue(m_data,
            ImportObservationData.PROPERTY_PARAMETER_TYPE);

    m_binding.bindValue(target, model);

    if (m_updateMode)
        parameterCombo.getCombo().setEnabled(false);
}

From source file:org.kalypso.zml.ui.table.dialogs.input.ChooseSteppingDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *//*from  w  w  w  . j  a  v a2s. c  o m*/
@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout());

    if (ArrayUtils.isEmpty(m_steppings)) {
        m_toolkit.createLabel(composite, Messages.ChooseSteppingDialog_2);
        return composite;
    }

    m_toolkit.createLabel(composite, Messages.ChooseSteppingDialog_3);
    final ComboViewer viewer = new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);
    viewer.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(final Object element) {
            final Integer step = (Integer) element;

            final Calendar calendar = Calendar.getInstance(KalypsoCorePlugin.getDefault().getTimeZone());
            calendar.setTime(m_current);
            calendar.add(Calendar.HOUR_OF_DAY, step);

            final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); //$NON-NLS-1$

            return String.format(Messages.ChooseSteppingDialog_4, step, sdf.format(calendar.getTime()));
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(m_steppings);

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            m_selection = (Integer) selection.getFirstElement();
        }
    });

    viewer.setSelection(new StructuredSelection(m_steppings[0]));

    m_toolkit.adapt(composite);

    return composite;
}

From source file:org.locationtech.udig.tutorials.featureeditor.CountryFeaturePanel3.java

License:Open Source License

@Override
public void createFieldEditors() {
    StringAttributeField field = addField(new StringAttributeField("SQKM", "Area (square km)", getParent()));
    field.getLabelControl(getParent()).setToolTipText("Area km");

    field = addField(new StringAttributeField("SQMI", "Square Miles:", getParent()));
    field.getLabelControl(getParent()).setToolTipText("Area miles");

    ComboAttributeField2 combo = addField(
            new ComboAttributeField2(COLOR_MAP, "Color Map", Arrays.asList(COLOR_MAP_OPTS), getParent()));
    ComboViewer viewer = combo.getViewer();
    viewer.setLabelProvider(new LabelProvider() {
        @Override/*from   w w  w  .  ja  v a  2 s .  c  o m*/
        public String getText(Object element) {
            return "Color " + element;
        }
    });
}

From source file:org.obeonetwork.dsl.spem.gen.doc.wizard.Gendoc2WizardPage.java

License:Open Source License

/**
 * this method add all the necessary listeners to the comboviewer1
 * /*from   w  ww .  ja  v  a 2 s . c o  m*/
 * @param comboViewer1
 *            the combo viewer1 that output all the possible template of
 *            model
 */
private void manageTemplateCombo(ComboViewer comboViewer1) {
    comboViewer1.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Collection<?>) {
                Collection<?> coll = (Collection<?>) inputElement;
                return coll.toArray();
            }
            return null;
        }
    });

    comboViewer1.setLabelProvider(new ILabelProvider() {

        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return true;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public Image getImage(Object element) {
            return null;
        }

        public String getText(Object element) {
            if (element instanceof IGendoc2Runner) {
                return ((IGendoc2Runner) element).getLabel();
            } else {
                return null;
            }

        }
    });

    comboViewer1.setInput(getGWizard().getRunners());
    combo_1.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            IGendoc2Runner selectedRunner = getSelectedRunner();

            if (comboViewer != null && selectedRunner != null) {
                comboViewer.setInput(selectedRunner);

                if (combo.getItemCount() > 0) {
                    combo.select(0);
                }
            }
            getGWizard().refresh();
        }
    });
    if (combo_1.getItemCount() > 0) {
        combo_1.select(0);

    }
}