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

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

Introduction

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

Prototype

@Override
    public Control getControl() 

Source Link

Usage

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 a v a 2  s.co m*/
    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  w  w . j  a  va  2  s  .  co m
    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 ava 2  s . c  o m*/
            .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 w w  .ja va 2  s . 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/* ww w  .  j  a v  a  2s .  c o 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.svenk.redmine.ui.wizard.querypage.RedmineGuiHelper.java

License:Open Source License

public static void placeListElements(final Composite parent, int columns,
        final Collection<? extends IRedmineQueryField> queryFields,
        final Map<? extends IRedmineQueryField, ListViewer> lstSearchValues,
        final Map<? extends IRedmineQueryField, ComboViewer> lstSearchOperators) {

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(columns * 2, true);
    composite.setLayout(layout);//w  ww.  j av  a  2 s. com

    GridData commonGridData = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    commonGridData.horizontalAlignment = SWT.FILL;

    GridData listGridData = new GridData();
    listGridData.verticalSpan = 2;
    listGridData.heightHint = 100;
    listGridData.widthHint = 85;

    IRedmineQueryField[] fields = queryFields.toArray(new IRedmineQueryField[queryFields.size()]);

    for (int i = 1; i <= fields.length; i++) {
        IRedmineQueryField queryField = fields[i - 1];

        Label label = new Label(composite, SWT.NONE);
        label.setText(queryField.getLabel());
        label.setLayoutData(commonGridData);

        ListViewer list = lstSearchValues.get(queryField);
        list.getControl().setParent(composite);
        list.getControl().setLayoutData(listGridData);

        if (i % columns == 0 || i == queryFields.size()) {
            int sv = (i % columns == 0) ? i - columns : i - i % columns;
            if (i % columns != 0) {
                listGridData = new GridData();
                listGridData.verticalSpan = 2;
                listGridData.heightHint = 100;
                listGridData.horizontalSpan = (columns - (i % columns)) * 2 + 1;
                listGridData.widthHint = 85;
                list.getControl().setLayoutData(listGridData);
            }
            for (int j = sv; j < i; j++) {
                IRedmineQueryField tmpSearchField = fields[j];

                ComboViewer combo = lstSearchOperators.get(tmpSearchField);
                combo.getControl().setParent(composite);
                combo.getControl().setLayoutData(commonGridData);
            }
        }
    }
}

From source file:org.svenk.redmine.ui.wizard.querypage.RedmineGuiHelper.java

License:Open Source License

public static void placeTextElements(final Composite parent,
        final Collection<? extends IRedmineQueryField> queryFields,
        final Map<? extends IRedmineQueryField, Text> txtSearchValues,
        final Map<? extends IRedmineQueryField, ComboViewer> txtSearchOperators) {

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);/*from ww  w  . j a  v  a 2 s  . c o  m*/

    GridData commonGridData = new GridData();
    GridData textGridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
    textGridData.minimumWidth = 300;

    for (IRedmineQueryField queryField : queryFields) {
        Label label = new Label(composite, SWT.NONE);
        label.setText(queryField.getLabel());
        label.setLayoutData(commonGridData);

        ComboViewer combo = txtSearchOperators.get(queryField);
        combo.getControl().setParent(composite);
        combo.getControl().setLayoutData(commonGridData);

        Text text = txtSearchValues.get(queryField);
        text.setParent(composite);
        text.setLayoutData(textGridData);
    }
}

From source file:org.svenk.redmine.ui.wizard.querypage.RedmineQueryPage.java

License:Open Source License

private void updateCustomFieldFilter(String listDataKey) {
    LabelProvider labelProvider = new RedmineLabelProvider();
    List<RedmineCustomField> customFields = listData.get(listDataKey).getCustomTicketFields();

    List<IRedmineQueryField> lstKeys = new ArrayList<IRedmineQueryField>(lstCustomSearchValues.keySet());
    List<IRedmineQueryField> txtKeys = new ArrayList<IRedmineQueryField>(txtCustomSearchValues.keySet());

    Collection<Composite> oldComposites = new ArrayList<Composite>(2);
    for (Control child : customComposite.getChildren()) {
        if (child instanceof Composite) {
            oldComposites.add((Composite) child);
        }//from   w w w . jav a  2 s. c om
    }

    if (customFields != null) {
        for (RedmineCustomField customField : customFields) {
            if (!customField.isSupportFilter()) {
                continue;
            }

            Control control = null;
            ComboViewer combo = null;
            SearchField searchfield = null;

            switch (customField.getType()) {
            case LIST: {
                ListViewer list = null;
                if (lstKeys.remove(customField)) {
                    list = lstCustomSearchValues.get(customField);
                    control = list.getControl();
                } else {
                    list = new ListViewer(customComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
                    list.setLabelProvider(labelProvider);
                    list.setContentProvider(new RedmineContentProvider());
                    control = list.getControl();
                    lstCustomSearchValues.put(customField, list);
                    searchfield = SearchField.fromCustomTicketField(customField);
                }
                list.setInput(customField.getListValues());
                break;
            }
            case BOOL: {
                if (txtKeys.remove(customField)) {
                    control = txtCustomSearchValues.get(customField);
                } else {
                    txtKeys.remove(customField);
                    Text text = new Text(customComposite, SWT.NONE);
                    text.setText(OPERATOR_BOOLEAN_TRUE);
                    text.setEditable(false);
                    txtCustomSearchValues.put(customField, text);
                    control = text;
                    searchfield = SearchField.fromCustomTicketField(customField);
                }
                break;
            }
            case STRING:
            case TEXT:
            case INT:
            case DATE:
            case FLOAT: {
                if (txtKeys.remove(customField)) {
                    control = txtCustomSearchValues.get(customField);
                } else {
                    txtKeys.remove(customField);
                    Text text = new Text(customComposite, SWT.BORDER);
                    txtCustomSearchValues.put(customField, text);
                    control = text;
                    searchfield = SearchField.fromCustomTicketField(customField);
                }
                break;
            }
            }

            if (searchfield == null) {
                combo = customSearchOperators.get(customField);
                combo.getControl().setParent(customComposite);
                control.setParent(customComposite);
            } else {
                control.setEnabled(false);
                if (customSearchOperators.containsKey(customField)) {
                    customSearchOperators.remove(customField).getControl().dispose();
                }
                combo = new ComboViewer(customComposite, SWT.READ_ONLY | SWT.DROP_DOWN);
                combo.setContentProvider(new RedmineContentProvider(OPERATOR_TITLE));
                combo.setLabelProvider(labelProvider);
                combo.setInput(searchfield.getCompareOperators());
                combo.setSelection(new StructuredSelection(combo.getElementAt(0)));
                combo.addSelectionChangedListener(new RedmineCompareOperatorSelectionListener(control));
                customSearchOperators.put(customField, combo);
            }
        }
    }

    for (Composite old : oldComposites) {
        old.dispose();
    }

    for (IRedmineQueryField field : lstKeys) {
        lstCustomSearchValues.remove(field);
        customSearchOperators.remove(field);
    }
    for (IRedmineQueryField field : txtKeys) {
        txtCustomSearchValues.remove(field);
        customSearchOperators.remove(field);
    }

    RedmineGuiHelper.placeListElements(customComposite, 4, lstCustomSearchValues.keySet(),
            lstCustomSearchValues, customSearchOperators);
    RedmineGuiHelper.placeTextElements(customComposite, txtCustomSearchValues.keySet(), txtCustomSearchValues,
            customSearchOperators);
}

From source file:org.xwiki.eclipse.ui.dialogs.RenameAttachmentDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite mainComposite = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.fillDefaults().applyTo(mainComposite);

    Composite composite = new Composite(mainComposite, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(composite);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(composite);

    Label label = new Label(composite, SWT.NONE);
    label.setText("New space:");

    final ComboViewer comboViewer = new ComboViewer(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(comboViewer.getControl());
    comboViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            XWikiEclipseSafeRunnableWithResult<List<XWikiEclipseSpaceSummary>> runnable = new XWikiEclipseSafeRunnableWithResult<List<XWikiEclipseSpaceSummary>>() {

                public void run() throws Exception {
                    setResult(attachmentSummary.getDataManager().getSpaces());
                }//from  www. jav a 2  s . co m

            };
            SafeRunner.run(runnable);

            if (runnable.getResult() != null) {
                String[] elements = new String[runnable.getResult().size()];
                int i = 0;
                for (XWikiEclipseSpaceSummary spaceSummary : runnable.getResult()) {
                    elements[i] = spaceSummary.getData().getKey();
                    i++;
                }

                return elements;
            }

            return new Object[0];
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    comboViewer.setLabelProvider(new LabelProvider());
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                toSpace = (String) selection.getFirstElement();
            }
        }
    });
    comboViewer.getCombo().addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            toSpace = comboViewer.getCombo().getText();
        }

    });

    comboViewer.setInput(new Object());
    try {
        comboViewer.setSelection(new StructuredSelection(attachmentSummary.getDataManager()
                .getPage(attachmentSummary.getData().getPageId()).getData().getSpace()));
    } catch (XWikiEclipseException e1) {
        e1.printStackTrace();
    }

    label = new Label(composite, SWT.NONE);
    label.setText("New Page:");

    final ComboViewer comboViewer2 = new ComboViewer(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(comboViewer2.getControl());
    comboViewer2.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            XWikiEclipseSafeRunnableWithResult<List<XWikiEclipsePageSummary>> runnable = new XWikiEclipseSafeRunnableWithResult<List<XWikiEclipsePageSummary>>() {

                public void run() throws Exception {
                    setResult(attachmentSummary.getDataManager().getPages(toSpace));
                }

            };
            SafeRunner.run(runnable);

            if (runnable.getResult() != null) {
                String[] elements = new String[runnable.getResult().size()];
                int i = 0;
                for (XWikiEclipsePageSummary pageSummary : runnable.getResult()) {
                    elements[i] = pageSummary.getData().getId().split("\\.")[1];
                    i++;
                }

                return elements;
            }

            return new Object[0];
        }

        public void dispose() {
        }

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

    comboViewer2.setLabelProvider(new LabelProvider());
    comboViewer2.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                toPageName = (String) selection.getFirstElement();
            }
        }
    });
    comboViewer2.getCombo().addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            toPageName = comboViewer2.getCombo().getText();
        }

    });

    comboViewer2.setInput(new Object());
    comboViewer2
            .setSelection(new StructuredSelection(attachmentSummary.getPageSummary().getId().split("\\.")[1]));

    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                toSpace = (String) selection.getFirstElement();
            }
            comboViewer2.refresh();
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setText("New Attachment Name:");

    final Text name = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(name);

    name.setText(attachmentSummary.getData().getFileName());

    name.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            tofileName = name.getText();
        }

    });

    return composite;
}

From source file:org.xwiki.eclipse.ui.dialogs.RenamePageDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite mainComposite = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.fillDefaults().applyTo(mainComposite);

    Composite composite = new Composite(mainComposite, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(composite);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(composite);

    Label label = new Label(composite, SWT.NONE);
    label.setText("Wiki:");

    final Combo combo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN);
    List<XWikiEclipseWikiSummary> wikis = new ArrayList<XWikiEclipseWikiSummary>();
    try {//from  w w w  . j a v  a2s. c  om
        wikis = pageSummary.getDataManager().getWikis();
    } catch (XWikiEclipseStorageException e) {
        CoreLog.logError(String.format("Error getting wikis in rename page dialog"), e);
    }
    final String[] items = new String[wikis.size()];
    for (int i = 0; i < items.length; i++) {
        String wiki = wikis.get(i).getName();
        items[i] = wiki;
        if (wiki.equals(pageSummary.getWiki())) {
            combo.select(i);
        }
    }
    combo.setItems(items);

    for (int i = 0; i < items.length; i++) {
        String wiki = wikis.get(i).getName();
        if (wiki.equals(pageSummary.getWiki())) {
            combo.select(i);
            newWiki = pageSummary.getWiki();
        }
    }

    combo.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            newWiki = items[((Combo) e.getSource()).getSelectionIndex()];
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setText("New space:");

    final ComboViewer comboViewer = new ComboViewer(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(comboViewer.getControl());
    comboViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            XWikiEclipseSafeRunnableWithResult<List<XWikiEclipseSpaceSummary>> runnable = new XWikiEclipseSafeRunnableWithResult<List<XWikiEclipseSpaceSummary>>() {

                public void run() throws Exception {
                    setResult(pageSummary.getDataManager().getSpaces(pageSummary.getWiki()));
                }

            };
            SafeRunner.run(runnable);

            if (runnable.getResult() != null) {
                String[] elements = new String[runnable.getResult().size()];
                int i = 0;
                for (XWikiEclipseSpaceSummary spaceSummary : runnable.getResult()) {
                    elements[i] = spaceSummary.getName();
                    i++;
                }

                return elements;
            }

            return new Object[0];
        }

        public void dispose() {
            // TODO Auto-generated method stub

        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // TODO Auto-generated method stub
        }
    });
    comboViewer.setLabelProvider(new LabelProvider());
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                newSpace = (String) selection.getFirstElement();
            }
        }
    });
    comboViewer.getCombo().addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            newSpace = comboViewer.getCombo().getText();
        }

    });

    comboViewer.setInput(new Object());
    comboViewer.setSelection(new StructuredSelection(pageSummary.getSpace()));

    label = new Label(composite, SWT.NONE);
    label.setText("New name:");

    final Text name = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(name);

    if (pageSummary.getId().indexOf('.') != -1) {
        String[] components = pageSummary.getId().split("\\.");

        name.setText(components[1]);
    } else {
        name.setText(pageSummary.getTitle());
    }

    name.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            newPageName = name.getText();
        }

    });

    return composite;
}