Search in sources :

Example 1 with StringDialogField

use of org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField 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;
    }
}
Also used : IDialogFieldListener(org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener) ModifyDialog(org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Composite(org.eclipse.swt.widgets.Composite) TabFolder(org.eclipse.swt.widgets.TabFolder) Method(java.lang.reflect.Method) StringDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField) Field(java.lang.reflect.Field) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StringDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) IModifyDialogTabPage(org.eclipse.jdt.internal.ui.preferences.formatter.IModifyDialogTabPage) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IModifyDialogTabPage (org.eclipse.jdt.internal.ui.preferences.formatter.IModifyDialogTabPage)1 ModifyDialog (org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog)1 DialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)1 IDialogFieldListener (org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener)1 StringDialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 TabFolder (org.eclipse.swt.widgets.TabFolder)1 TabItem (org.eclipse.swt.widgets.TabItem)1