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