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.model.wspm.ui.profil.wizard.pointsInsert.PointsSourceChooserPage.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 *///  w  ww  .ja va 2  s . c om
@Override
public void createControl(final Composite parent) {
    final String sourceID = getDialogSettings().get(DLG_SETTINGS_SOURCE_ID);

    if (sourceID == null) {
        m_selectedSource = m_sources.length == 0 ? null : m_sources[0];
    } else {
        for (final IPointsSource source : m_sources) {
            if (sourceID.equals(source.getID())) {
                m_selectedSource = source;
                break;
            }
        }
    }

    final Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout(2, false));

    new Label(panel, SWT.NONE).setText(org.kalypso.model.wspm.ui.i18n.Messages
            .getString("org.kalypso.model.wspm.ui.profil.wizard.pointsInsert.PointsSourceChooserPage.1")); //$NON-NLS-1$

    final ComboViewer comboViewer = new ComboViewer(panel, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new LabelProvider());
    comboViewer.setInput(m_sources);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            setSelectedSource((IPointsSource) selection.getFirstElement());
        }
    });

    final Label sep = new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL);
    sep.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));

    m_sourceStack = new Group(panel, SWT.NONE);
    m_stackLayout = new StackLayout();
    m_sourceStack.setLayout(m_stackLayout);
    m_sourceStack.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));

    for (final IPointsSource source : m_sources) {
        source.createControl(m_sourceStack);
    }

    if (m_sources.length > 0) {
        comboViewer.setSelection(new StructuredSelection(m_selectedSource));
    }

    setControl(panel);
}

From source file:org.kalypso.model.wspm.ui.view.map.SelectProfileDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *//*from  w  w  w  . j  av  a2 s .  c  o  m*/
@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout());
    final GridData data = new GridData(GridData.FILL, GridData.FILL, true, true);
    data.heightHint = 300;
    data.widthHint = 100;

    composite.setLayoutData(data);

    final Label label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    label.setText(Messages.getString("org.kalypso.model.wspm.ui.view.map.SelectProfileDialog.2")); //$NON-NLS-1$

    final ComboViewer viewer = new ComboViewer(composite, SWT.READ_ONLY | SWT.BORDER);
    viewer.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {
        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(final Object element) {
            if (element instanceof EasyFeatureWrapper) {
                final EasyFeatureWrapper eft = (EasyFeatureWrapper) element;

                final Feature crossSection = eft.getFeature();

                final String name = FeatureUtils.getFeatureName(NS.GML3, crossSection);
                final QName qStation = new QName("org.kalypso.model.wspmprofile", "station"); //$NON-NLS-1$ //$NON-NLS-2$
                final BigDecimal station = (BigDecimal) crossSection.getProperty(qStation);

                final Feature waterbody = crossSection.getOwner();

                final String wn = FeatureUtils.getFeatureName(NS.GML3, waterbody);
                final String s = Messages.getString("org.kalypso.model.wspm.ui.view.map.SelectProfileDialog.3", //$NON-NLS-1$
                        name, station, wn);

                return s;
            }

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

    viewer.setInput(m_crossSections);

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            m_selection = (EasyFeatureWrapper) selection.getFirstElement();
        }
    });

    return composite;
}

From source file:org.kalypso.ogc.gml.movie.controls.MovieComposite.java

License:Open Source License

/**
 * This function creates the screen controls.
 * /* ww  w  . jav a2 s. com*/
 * @param parent
 *          The parent composite.
 * @return The screen controls.
 */
private Composite createScreenControls(final Composite parent) {
    /* Create a composite. */
    final Composite composite = new Composite(parent, SWT.NONE);
    final GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);

    /* Create the image composite. */
    final Composite imageComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    final GridData imageData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    imageData.widthHint = m_resolution.getWidth();
    imageData.heightHint = m_resolution.getHeight();
    imageComposite.setLayoutData(imageData);

    /* Create the image canvas. */
    final Frame virtualFrame = SWT_AWT.new_Frame(imageComposite);
    virtualFrame.setLayout(new GridBagLayout());
    m_displayJAI = new DisplayJAI(createEmptyImage(m_resolution.getWidth(), m_resolution.getHeight()));
    virtualFrame.add(m_displayJAI, new GridBagConstraints(0, 0, 1, 1, 100, 100, GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    /* Create a progress bar. */
    m_progressBar = new ProgressBar(composite, SWT.NONE);
    m_progressBar.setMinimum(0);
    m_progressBar.setMaximum(m_player.getEndStep());
    m_progressBar.setSelection(m_player.getCurrentStep());
    m_progressBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));

    /* Create the progress label. */
    m_progressLabel = new Label(composite, SWT.NONE);
    m_progressLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    m_progressLabel.setText(""); //$NON-NLS-1$

    /* Create a combo box. */
    final ComboViewer resolutionViewer = new ComboViewer(composite, SWT.READ_ONLY);
    resolutionViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    resolutionViewer.setContentProvider(new ArrayContentProvider());
    resolutionViewer.setLabelProvider(new ResolutionLabelProvider());
    final MovieResolution[] input = MovieUtilities.getResolutions();
    resolutionViewer.setInput(input);
    resolutionViewer.setSelection(new StructuredSelection(input[1]));
    resolutionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        /**
         * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            final Object firstElement = ((StructuredSelection) selection).getFirstElement();
            m_resolution = (MovieResolution) firstElement;

            final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
            layoutData.widthHint = m_resolution.getWidth();
            layoutData.heightHint = m_resolution.getHeight();
            imageComposite.setLayoutData(layoutData);
            imageComposite.setSize(m_resolution.getWidth(), m_resolution.getHeight());

            m_displayJAI.set(createEmptyImage(m_resolution.getWidth(), m_resolution.getHeight()));

            MovieComposite.this.pack();
        }
    });

    /* Create a spinner. */
    final Spinner spinner = new Spinner(composite, SWT.BORDER);
    spinner.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    spinner.setMinimum(100);
    spinner.setIncrement(50);
    spinner.setMaximum(1000);
    spinner.setSelection(250);
    spinner.addSelectionListener(new SelectionAdapter() {
        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(final SelectionEvent e) {
            /* Spinner. */
            final Spinner source = (Spinner) e.getSource();

            /* Get the selection. */
            final int selection = source.getSelection();

            /* Update the frame relay. */
            m_player.updateFrameDelay(selection);
        }
    });

    return composite;
}

From source file:org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.java

License:Open Source License

private void renderProjectHistory(final Composite parent) {
    /* select version */
    final Group groupVersions = new Group(parent, SWT.NULL);
    groupVersions.setLayout(new GridLayout());
    groupVersions.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    groupVersions.setText(/*w w  w .j  a  v a  2s.  co  m*/
            Messages.getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.1", //$NON-NLS-1$
                    m_handler.getBean().getName()));

    final ComboViewer viewerVersions = new ComboViewer(groupVersions);
    viewerVersions.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    viewerVersions.setContentProvider(new ArrayContentProvider());
    viewerVersions.setLabelProvider(new LabelProvider() {
        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(final Object element) {
            if (element instanceof KalypsoProjectBean) {
                final KalypsoProjectBean project = (KalypsoProjectBean) element;

                return Messages.getString(
                        "org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.2", //$NON-NLS-1$
                        project.getProjectVersion(), project.getCreationDate());
            }

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

    viewerVersions.setInput(m_beans);

    final Group groupDetails = new Group(parent, SWT.NULL);
    groupDetails.setLayout(new GridLayout(2, false));
    groupDetails.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    groupDetails.setText(Messages
            .getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.3")); //$NON-NLS-1$

    /* version */
    new Label(groupDetails, SWT.NULL).setText(Messages
            .getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.4")); //$NON-NLS-1$

    final Text version = new Text(groupDetails, SWT.BORDER | SWT.READ_ONLY);
    version.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    if (m_isExpert) {
        /* type */
        new Label(groupDetails, SWT.NULL).setText(Messages
                .getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.5")); //$NON-NLS-1$

        final Text type = new Text(groupDetails, SWT.BORDER | SWT.READ_ONLY);
        type.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

        /* unix name */
        new Label(groupDetails, SWT.NULL).setText(Messages
                .getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.6")); //$NON-NLS-1$

        final Text unix = new Text(groupDetails, SWT.BORDER | SWT.READ_ONLY);
        unix.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

        /* server url */
        new Label(groupDetails, SWT.NULL).setText("Url:"); //$NON-NLS-1$

        final Text url = new Text(groupDetails, SWT.BORDER | SWT.READ_ONLY);
        url.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

        viewerVersions.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(final SelectionChangedEvent event) {
                final IStructuredSelection selection = (IStructuredSelection) viewerVersions.getSelection();
                final Object element = selection.getFirstElement();

                if (element instanceof KalypsoProjectBean)
                    try {
                        final KalypsoProjectBean project = (KalypsoProjectBean) element;

                        type.setText(project.getProjectType());
                        unix.setText(project.getUnixName());
                        url.setText(project.getUrl().toExternalForm());
                    } catch (final Exception e) {
                        KalypsoProjectDatabaseClient.getDefault().getLog()
                                .log(StatusUtilities.statusFromThrowable(e));
                    }
            }
        });
    }

    final Group groupChanges = new Group(parent, SWT.NULL);
    groupChanges.setLayout(new GridLayout());
    groupChanges.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    groupChanges.setText(Messages
            .getString("org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.8")); //$NON-NLS-1$

    final Text changes = new Text(groupChanges,
            SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.SCROLL_PAGE);
    changes.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    if (m_handler.getBean().getChanges() != null)
        changes.setText(m_handler.getBean().getChanges());

    /* change listener */
    viewerVersions.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) viewerVersions.getSelection();
            final Object element = selection.getFirstElement();

            if (element instanceof KalypsoProjectBean) {
                final KalypsoProjectBean project = (KalypsoProjectBean) element;

                version.setText(Messages.getString(
                        "org.kalypso.project.database.client.ui.project.wizard.info.RemoteInfoDialog.9", //$NON-NLS-1$
                        project.getProjectVersion(), project.getCreationDate()));

                if (project.getChanges() != null)
                    changes.setText(m_handler.getBean().getChanges());
            }
        }
    });

    viewerVersions.setSelection(new StructuredSelection(m_handler.getBean()));

}

From source file:org.kalypso.project.database.client.ui.view.ViewManageServerProjects.java

License:Open Source License

protected void update() {
    if (m_parent.isDisposed())
        return;/*from w  ww  .j  a  v  a  2s  .c o m*/

    if (m_body != null) {
        if (!m_body.isDisposed()) {
            m_body.dispose();
        }
    }

    m_body = m_toolkit.createComposite(m_parent);
    m_body.setLayout(new GridLayout());
    m_body.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

    final Group grModelType = new Group(m_body, SWT.NONE);
    grModelType.setText(
            Messages.getString("org.kalypso.project.database.client.ui.view.ViewManageServerProjects.1")); //$NON-NLS-1$
    grModelType.setLayout(new GridLayout());
    grModelType.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    m_toolkit.adapt(grModelType);

    final ComboViewer viewerType = new ComboViewer(grModelType, SWT.BORDER | SWT.READ_ONLY);
    viewerType.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    viewerType.setContentProvider(new ArrayContentProvider());
    viewerType.setLabelProvider(new LabelProvider());

    final IProjectDatabase service = KalypsoProjectDatabaseClient.getService();
    if (service == null) {
        m_toolkit.createLabel(m_body,
                Messages.getString("org.kalypso.project.database.client.ui.view.ViewManageServerProjects.2")); //$NON-NLS-1$
        return;
    }

    final String[] types = service.getProjectTypes();

    viewerType.setInput(types);

    if (m_selectedType != null) {
        viewerType.setSelection(new StructuredSelection(m_selectedType));

        final Group grDetails = new Group(m_body, SWT.NONE);
        grDetails.setText(
                Messages.getString("org.kalypso.project.database.client.ui.view.ViewManageServerProjects.3")); //$NON-NLS-1$
        grDetails.setLayout(new GridLayout());
        grDetails.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
        m_toolkit.adapt(grDetails);

        if (m_manager != null) {
            m_manager.dispose();
        }

        m_manager = new ManageRemoteProjects(m_toolkit, grDetails, m_selectedType);
        m_manager.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    }

    viewerType.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) viewerType.getSelection();
            final Object element = selection.getFirstElement();
            if (element instanceof String) {
                m_selectedType = (String) element;

                new UIJob("") //$NON-NLS-1$
                {
                    @Override
                    public IStatus runInUIThread(final IProgressMonitor monitor) {
                        update();
                        return Status.OK_STATUS;
                    }
                }.schedule();
            }
        }
    });

    m_body.layout();
    m_parent.layout();
}

From source file:org.kalypso.risk.model.simulation.statistics.StatisticCalculationShapePage.java

License:Open Source License

private void createShapeFileControl(final Composite parent) {
    final String tooltip = Messages.getString("StatisticCalculationShapePage_3"); //$NON-NLS-1$

    final Label label = new Label(parent, SWT.NONE);
    label.setText(Messages.getString("StatisticCalculationShapePage_4")); //$NON-NLS-1$
    label.setToolTipText(tooltip);//from   w  ww  .j a  va2  s  .com

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

    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new FileLabelProvider());

    comboViewer.setInput(m_data.getAvailableShapeFiles());

    /* Binding */
    final IViewerObservableValue targetSelection = ViewersObservables.observeSinglePostSelection(comboViewer);
    final IObservableValue modelSelection = BeansObservables.observeValue(m_data,
            StatisticCalculationData.PROPERTY_SELECTED_SHAPE);
    m_binding.bindValue(targetSelection, modelSelection);
}

From source file:org.kalypso.risk.model.simulation.statistics.StatisticCalculationShapePage.java

License:Open Source License

private void createShapeAttributeControl(final Composite parent) {
    final String tooltip = Messages.getString("StatisticCalculationShapePage_5"); //$NON-NLS-1$

    final Label label = new Label(parent, SWT.NONE);
    label.setText(Messages.getString("StatisticCalculationShapePage_6")); //$NON-NLS-1$
    label.setToolTipText(tooltip);/*from w w w .  j ava2s.  c om*/

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

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

    /* Binding */
    final IObservableValue targetInput = ViewersObservables.observeInput(comboViewer);
    final IObservableValue modelInput = BeansObservables.observeValue(m_data,
            StatisticCalculationData.PROPERTY_SHAPE_ATTRIBUTES);
    final IValidator finishValidator = new ShapeAttributesValidValidator();
    m_binding.bindValue(targetInput, modelInput, finishValidator, finishValidator);

    final IViewerObservableValue targetSelection = ViewersObservables.observeSinglePostSelection(comboViewer);
    final IObservableValue modelSelection = BeansObservables.observeValue(m_data,
            StatisticCalculationData.PROPERTY_SELECTED_ATTRIBUTE);
    m_binding.bindValue(targetSelection, modelSelection);
}

From source file:org.kalypso.ui.addlayer.internal.wms.CapabilitiesComposite.java

License:Open Source License

private void createImageProviderControls() {
    final String toolTipText = Messages.getString("org.kalypso.ui.wizard.wms.pages.ImportWmsWizardPage.5"); //$NON-NLS-1$

    final Label label = new Label(this, SWT.NONE);
    // TODO: better label?
    label.setText(Messages.getString("CapabilitiesComposite.0")); //$NON-NLS-1$
    label.setToolTipText(toolTipText);// ww w  .j a  va  2 s  .c o  m

    final ComboViewer imageProviderViewer = new ComboViewer(this, SWT.READ_ONLY);
    final GridData urlComboData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
    urlComboData.widthHint = 100;
    urlComboData.minimumWidth = 100;
    imageProviderViewer.getCombo().setLayoutData(urlComboData);
    // TODO: bad tooltip
    imageProviderViewer.getCombo().setToolTipText(toolTipText);

    final Map<String, String> imageProviders = ImageProviderExtensions.getImageProviders();

    imageProviderViewer.setContentProvider(new ArrayContentProvider());
    imageProviderViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(final Object element) {
            final String id = (String) element;
            return imageProviders.get(id);
        }
    });

    /* Set the input. */
    final String[] providerIDS = imageProviders.keySet().toArray(new String[imageProviders.size()]);
    imageProviderViewer.setInput(providerIDS);

    /**
     * Binding
     */
    final IViewerObservableValue targetImageProvider = ViewersObservables
            .observeSingleSelection(imageProviderViewer);
    final IObservableValue modelImageProvider = BeansObservables.observeValue(m_data,
            ImportWmsData.PROPERTY_IMAGE_PROVIDER);
    m_binding.bindValue(targetImageProvider, modelImageProvider);
}

From source file:org.kalypso.ui.addlayer.ThemeAndPropertyChooserGroup.java

License:Open Source License

public Group createControl(final Composite parent) {
    final Group group = new Group(parent, SWT.NONE);
    group.setLayout(new GridLayout(1, false));

    /* theme chooser */
    final ComboViewer themeComboViewer = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    themeComboViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    themeComboViewer.setContentProvider(new ArrayContentProvider());
    themeComboViewer.setLabelProvider(new LabelProvider());
    themeComboViewer.setSorter(new ViewerSorter());
    final IKalypsoTheme[] polygoneThemes = MapModellHelper.filterThemes(m_modell, m_themeFilter);
    themeComboViewer.setInput(polygoneThemes);
    themeComboViewer.getControl().setEnabled(polygoneThemes.length > 0);

    /* Property choosers */
    final Map<PropertyDescriptor, Control[]> propertyControls = new HashMap<>();
    final Map<PropertyDescriptor, ComboViewer> propertyCombos = new HashMap<>();

    for (final PropertyDescriptor pd : m_properties.keySet()) {
        createPropertyChooser(group, pd, propertyControls, propertyCombos);
    }/* w  ww .j a v  a 2  s .com*/

    themeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            handleSelectionChanged((IStructuredSelection) event.getSelection(), propertyCombos,
                    propertyControls);
        }
    });

    IStructuredSelection themeSelection = polygoneThemes.length > 0 ? new StructuredSelection(polygoneThemes[0])
            : StructuredSelection.EMPTY;

    for (final PropertyDescriptor pd : propertyCombos.keySet()) {
        final ComboViewer viewer = propertyCombos.get(pd);

        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(final SelectionChangedEvent event) {
                handlePropertyChanged((IStructuredSelection) event.getSelection(), pd);
            }
        });
    }

    // TRICKY: because setting the selection to the themes changes
    // the dialog-settings of the poly- and value property we have to read them immediately
    IDialogSettings propertySetting = null;
    if (m_dialogSettings != null) {
        final String themeSetting = m_dialogSettings.get(SETTINGS_THEME);

        propertySetting = m_dialogSettings.getSection(SETTINGS_PROPERTIES);

        if (themeSetting != null) {
            for (final IKalypsoTheme theme : polygoneThemes) {
                if (StringUtils.equals(themeSetting, theme.getName().getValue())) {
                    themeSelection = new StructuredSelection(theme);
                    break;
                }
            }
        }
    }

    themeComboViewer.setSelection(themeSelection);

    /* Apply dialog settings */
    final Map<PropertyDescriptor, IStructuredSelection> propertySelection = new HashMap<>();

    if (m_dialogSettings != null) {
        if (propertySetting != null) {
            for (final PropertyDescriptor pd : m_properties.keySet()) {
                final String lastProp = propertySetting.get(pd.label);
                if (lastProp != null) {
                    final IPropertyType[] pts = (IPropertyType[]) propertyCombos.get(pd).getInput();
                    for (final IPropertyType pt : pts) {
                        if (lastProp.equals(pt.getQName().toString())) {
                            propertySelection.put(pd, new StructuredSelection(pt));
                            break;
                        }
                    }
                }
            }
        }
    }

    for (final PropertyDescriptor pd : m_properties.keySet()) {
        final IStructuredSelection selection = propertySelection.get(pd);
        if (selection != null) {
            propertyCombos.get(pd).setSelection(selection);
        }
    }

    return group;
}

From source file:org.kalypso.ui.addlayer.ThemeAndPropertyChooserGroup.java

License:Open Source License

private void createPropertyChooser(final Group group, final PropertyDescriptor pd,
        final Map<PropertyDescriptor, Control[]> propertyControls,
        final Map<PropertyDescriptor, ComboViewer> propertyCombos) {
    /* Geo-Property chooser */
    final Label label = new Label(group, SWT.NONE);
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label.setText(pd.label);/*  w ww. ja va 2  s  .  c om*/

    final ComboViewer comboViewer = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new FeatureTypeLabelProvider());
    comboViewer.setSorter(new ViewerSorter());
    comboViewer.setInput(new IPropertyType[] {});

    propertyCombos.put(pd, comboViewer);
    propertyControls.put(pd, new Control[] { label, comboViewer.getControl() });
}