Search in sources :

Example 1 with WFSVersion

use of eu.esdihumboldt.hale.io.wfs.WFSVersion 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)

Example 2 with WFSVersion

use of eu.esdihumboldt.hale.io.wfs.WFSVersion in project hale by halestudio.

the class WFSTarget method updateConfiguration.

@Override
public boolean updateConfiguration(WFSWriter provider) {
    if (targetURL.isValid()) {
        final URI url = targetURL.getURI();
        provider.setTarget(new LocatableOutputSupplier<OutputStream>() {

            @Override
            public OutputStream getOutput() throws IOException {
                return null;
            }

            @Override
            public URI getLocation() {
                return url;
            }
        });
        // WFS version
        ISelection versionSel = selectVersion.getSelection();
        if (!versionSel.isEmpty() && versionSel instanceof IStructuredSelection) {
            Object sel = ((IStructuredSelection) versionSel).getFirstElement();
            if (sel instanceof WFSVersion) {
                provider.setWFSVersion((WFSVersion) sel);
            }
        }
        return true;
    }
    return false;
}
Also used : OutputStream(java.io.OutputStream) ISelection(org.eclipse.jface.viewers.ISelection) IOException(java.io.IOException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(java.net.URI) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion)

Example 3 with WFSVersion

use of eu.esdihumboldt.hale.io.wfs.WFSVersion in project hale by halestudio.

the class WFSTarget method createControls.

@Override
public void createControls(Composite parent) {
    getPage().setMessage("Please specify the WFS Transaction URL");
    GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // target URL field
    targetURL = new URIFieldEditor("targetURL", "Transaction URL", parent) {

        // the following methods are overridden so the capabilities button
        // may appear on the same line
        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + 1;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - 1);
        }
    };
    targetURL.setPage(getPage());
    targetURL.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState();
            }
        }
    });
    // button to determine from capabilities
    Button capButton = new Button(parent, SWT.PUSH);
    capButton.setText("...");
    capButton.setToolTipText("Determine based on WFS Capabilities");
    capButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            WFSTransactionConfig config = new WFSTransactionConfig();
            ISelection versionSel = selectVersion.getSelection();
            if (!versionSel.isEmpty() && versionSel instanceof IStructuredSelection) {
                WFSVersion version = (WFSVersion) ((IStructuredSelection) versionSel).getFirstElement();
                config.setVersion(version);
            }
            WFSTransactionWizard wizard = new WFSTransactionWizard(config);
            HaleWizardDialog dialog = new HaleWizardDialog(Display.getCurrent().getActiveShell(), wizard);
            if (dialog.open() == WizardDialog.OK) {
                WFSTransactionConfig result = wizard.getConfiguration();
                // apply result
                targetURL.setStringValue(result.getTransactionUri().toString());
                if (result.getVersion() != null) {
                    selectVersion.setSelection(new StructuredSelection(result.getVersion()));
                } else {
                    selectVersion.setSelection(new StructuredSelection());
                }
            }
        }
    });
    // select version
    Label versionLabel = new Label(parent, SWT.NONE);
    versionLabel.setText("WFS Version");
    selectVersion = new ComboViewer(parent);
    GridDataFactory.swtDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(selectVersion.getControl());
    selectVersion.setContentProvider(EnumContentProvider.getInstance());
    selectVersion.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof WFSVersion) {
                return ((WFSVersion) element).versionString;
            }
            return super.getText(element);
        }
    });
    selectVersion.setInput(WFSVersion.class);
    selectVersion.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateState();
        }
    });
    // fixed content type
    setContentType(HalePlatform.getContentTypeManager().getContentType(CONTENT_TYPE_ID_WFST));
    // initial state update
    updateState();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion) URIFieldEditor(eu.esdihumboldt.hale.ui.util.io.URIFieldEditor) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 4 with WFSVersion

use of eu.esdihumboldt.hale.io.wfs.WFSVersion in project hale by halestudio.

the class WFSCapabilitiesFieldEditor method getValidState.

private boolean getValidState() {
    String value = getValue();
    DialogPage page = getPage();
    // try to create a URL
    try {
        new URI(value);
    } catch (Exception e) {
        if (page != null) {
            page.setErrorMessage(e.getLocalizedMessage());
        }
        return false;
    }
    // try to get capabilities
    try {
        URIBuilder builder = new URIBuilder(value);
        // add fixed parameters
        boolean requestPresent = false;
        boolean servicePresent = false;
        String versionParam = null;
        for (NameValuePair param : builder.getQueryParams()) {
            String name = param.getName().toLowerCase();
            if (name.equals("request"))
                requestPresent = true;
            if (name.equals("service"))
                servicePresent = true;
            if (name.equals("version"))
                versionParam = param.getName();
        }
        if (!requestPresent) {
            builder.addParameter("REQUEST", "GetCapabilities");
        }
        if (!servicePresent) {
            builder.addParameter("SERVICE", "WFS");
        }
        WFSVersion version = getWFSVersion();
        if (version != null) {
            if (versionParam == null) {
                versionParam = "VERSION";
            }
            builder.setParameter(versionParam, version.toString());
        }
        usedUrl = builder.build().toURL();
        try (InputStream in = usedUrl.openStream()) {
            capabilities = CapabilitiesHelper.loadCapabilities(in);
        }
    } catch (Exception e) {
        if (page != null) {
            page.setErrorMessage(e.getLocalizedMessage());
        }
        return false;
    }
    // passed all tests
    if (page != null) {
        page.setErrorMessage(null);
    }
    return true;
}
Also used : NameValuePair(org.apache.http.NameValuePair) DialogPage(org.eclipse.jface.dialogs.DialogPage) InputStream(java.io.InputStream) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion)

Aggregations

WFSVersion (eu.esdihumboldt.hale.io.wfs.WFSVersion)4 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 URI (java.net.URI)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 URIFieldEditor (eu.esdihumboldt.hale.ui.util.io.URIFieldEditor)1 EnumContentProvider (eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1