Search in sources :

Example 1 with EnumContentProvider

use of eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider in project hale by halestudio.

the class AbstractWFSCapabilitiesPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // capabilities field
    location = new WFSCapabilitiesFieldEditor("location", "GetCapabilities URL", page) {

        @Override
        protected WFSVersion getWFSVersion() {
            if (versionSelect != null) {
                ISelection sel = versionSelect.getSelection();
                if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                    Object selected = ((IStructuredSelection) sel).getFirstElement();
                    if (NoObject.NONE.equals(selected)) {
                        return null;
                    }
                    return (WFSVersion) selected;
                }
            }
            return super.getWFSVersion();
        }
    };
    location.setPage(this);
    location.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                update();
            }
        }
    });
    String currentValue = getCapabilitiesURL(getWizard().getConfiguration());
    if (currentValue != null) {
        location.setValue(currentValue);
    }
    // version field
    Label vLabel = new Label(page, SWT.NONE);
    vLabel.setText("WFS version");
    versionSelect = new ComboViewer(page, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(versionSelect.getControl());
    versionSelect.setContentProvider(new EnumContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            Object[] values = super.getElements(inputElement);
            // add a NoObject
            values = Arrays.copyOf(values, values.length + 1, Object[].class);
            values[values.length - 1] = NoObject.NONE;
            return values;
        }
    });
    versionSelect.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof NoObject) {
                return "Based on URL / server default";
            }
            return super.getText(element);
        }
    });
    versionSelect.setInput(WFSVersion.class);
    versionSelect.setSelection(new StructuredSelection(NoObject.NONE));
    versionSelect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            location.revalidate();
        }
    });
    setControl(page);
    update();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion) EnumContentProvider(eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

WFSVersion (eu.esdihumboldt.hale.io.wfs.WFSVersion)1 EnumContentProvider (eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1