use of org.eclipse.jface.dialogs.DialogPage 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;
}
use of org.eclipse.jface.dialogs.DialogPage in project eclipse.platform.text by eclipse.
the class ChangeEncodingAction method run.
@Override
public void run() {
final IResource resource = getResource();
final Shell parentShell = getTextEditor().getSite().getShell();
final IEncodingSupport encodingSupport = getEncodingSupport();
if (resource == null && encodingSupport == null) {
MessageDialog.openInformation(parentShell, fDialogTitle, TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
return;
}
Dialog dialog = new Dialog(parentShell) {
private AbstractEncodingFieldEditor fEncodingEditor;
private IPreferenceStore store = null;
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(fDialogTitle);
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
GridData data = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(data);
composite.setFont(parent.getFont());
DialogPage page = new MessageDialogPage(composite) {
@Override
public void setErrorMessage(String newMessage) {
super.setErrorMessage(newMessage);
setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
setButtonEnabledState(APPLY_ID, newMessage == null);
}
private void setButtonEnabledState(int id, boolean state) {
Button button = getButton(id);
if (button != null)
button.setEnabled(state);
}
};
if (resource != null) {
// $NON-NLS-1$
fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null);
fEncodingEditor.setPage(page);
fEncodingEditor.load();
} else {
// $NON-NLS-1$
fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite);
store = new PreferenceStore();
String defaultEncoding = encodingSupport.getDefaultEncoding();
store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
String encoding = encodingSupport.getEncoding();
if (encoding != null)
store.setValue(ENCODING_PREF_KEY, encoding);
fEncodingEditor.setPreferenceStore(store);
fEncodingEditor.setPage(page);
fEncodingEditor.load();
if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
fEncodingEditor.loadDefault();
}
return composite;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
super.createButtonsForButtonBar(parent);
}
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == APPLY_ID)
apply();
else
super.buttonPressed(buttonId);
}
@Override
protected void okPressed() {
apply();
super.okPressed();
}
private void apply() {
fEncodingEditor.store();
if (resource == null) {
String encoding = fEncodingEditor.getPreferenceStore().getString(fEncodingEditor.getPreferenceName());
encodingSupport.setEncoding(encoding);
}
}
};
dialog.open();
}
Aggregations