use of org.eclipse.jdt.internal.ui.preferences.formatter.IModifyDialogTabPage in project xtext-xtend by eclipse.
the class FormatterModifyDialog method create.
@Override
public void create() {
if (isOldAPIVersion()) {
super.create();
return;
}
// copied from Eclipse Oxygen to support old dialog in Eclipse Photon
super.create();
int lastFocusNr = 0;
try {
lastFocusNr = fDialogSettings.getInt(fKeyLastFocus);
if (lastFocusNr < 0)
lastFocusNr = 0;
if (lastFocusNr > fTabPages.size() - 1)
lastFocusNr = fTabPages.size() - 1;
} catch (NumberFormatException x) {
lastFocusNr = 0;
}
try {
// use reflection to not break API
Field fNewProfile = ModifyDialog.class.getDeclaredField("fNewProfile");
fNewProfile.setAccessible(true);
if (!fNewProfile.getBoolean(this)) {
fTabFolder.setSelection(lastFocusNr);
((IModifyDialogTabPage) fTabFolder.getSelection()[0].getData()).setInitialFocus();
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
XtendActivator.getInstance().getLog().log(new Status(IStatus.ERROR, XtendActivator.PLUGIN_ID, e.getMessage(), e));
}
}
use of org.eclipse.jdt.internal.ui.preferences.formatter.IModifyDialogTabPage in project xtext-xtend by eclipse.
the class FormatterModifyDialog method createDialogArea.
@Override
@SuppressWarnings("rawtypes")
protected Control createDialogArea(Composite parent) {
if (isOldAPIVersion()) {
return super.createDialogArea(parent);
}
try {
// copied from Eclipse Oxygen to support old dialog in Eclipse Photon
final Composite composite = new Composite(parent, 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);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
applyDialogFont(composite);
Composite nameComposite = new Composite(composite, SWT.NONE);
nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
nameComposite.setLayout(new GridLayout(3, false));
// use reflection to not break API
Field fProfileNameField = ModifyDialog.class.getDeclaredField("fProfileNameField");
fProfileNameField.setAccessible(true);
StringDialogField f = new StringDialogField();
fProfileNameField.set(this, f);
f.setLabelText("&Profile name:");
f.setText(fProfile.getName());
f.getLabelControl(nameComposite).setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
f.getTextControl(nameComposite).setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
f.setDialogFieldListener(new IDialogFieldListener() {
@Override
public void dialogFieldChanged(DialogField field) {
try {
Method doValidate = ModifyDialog.class.getDeclaredMethod("doValidate");
doValidate.setAccessible(true);
doValidate.invoke(FormatterModifyDialog.this);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
XtendActivator.getInstance().getLog().log(new Status(IStatus.ERROR, XtendActivator.PLUGIN_ID, e.getMessage(), e));
}
}
});
// use reflection to not break API
Field fSaveButton = ModifyDialog.class.getDeclaredField("fSaveButton");
fSaveButton.setAccessible(true);
fSaveButton.set(this, createButton(nameComposite, IDialogConstants.CLIENT_ID + 1, "E&xport...", false));
fTabFolder = new TabFolder(composite, SWT.NONE);
fTabFolder.setFont(composite.getFont());
fTabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// use reflection to not break API
Field fWorkingValues = ModifyDialog.class.getDeclaredField("fWorkingValues");
fWorkingValues.setAccessible(true);
addPages((Map) fWorkingValues.get(this));
applyDialogFont(composite);
fTabFolder.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
final TabItem tabItem = (TabItem) e.item;
final IModifyDialogTabPage page = (IModifyDialogTabPage) tabItem.getData();
fDialogSettings.put(fKeyLastFocus, fTabPages.indexOf(page));
page.makeVisible();
}
});
// use reflection to not break API
Method doValidate = ModifyDialog.class.getDeclaredMethod("doValidate");
doValidate.setAccessible(true);
doValidate.invoke(this);
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, getHelpContextId());
return composite;
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
XtendActivator.getInstance().getLog().log(new Status(IStatus.ERROR, XtendActivator.PLUGIN_ID, e.getMessage(), e));
return null;
}
}
Aggregations