문제

I was searching for way to add link in Eclipse Preferences page. I quickly found How to create a hyperlink in Eclipse plugin preferences page? . The solution however does not fit

public class GradlePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    ...

    final Link link = new Link(getFieldEditorParent(), SWT.NONE);
    link.setText("link");
    link.setLayoutData(getFieldEditorParent().getLayout());

    link.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(final SelectionEvent event)
      {
            int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.STATUS;
            IWebBrowser browser;
            try {
                browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "NodeclipsePluginsListID", "NodeclipsePluginsList", "Nodeclipse Plugins List");
                browser.openURL(new URL("http://www.nodeclipse.org/updates"));
            } catch (PartInitException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
      }
    });     

However I cannot addField(link); as

The method addField(FieldEditor) in the type FieldEditorPreferencePage is not applicable for the arguments (Link)

Is there as way to add link in FieldEditorPreferencePage ? e.g. to compose FieldEditor from several part (label, link, Text) ?

도움이 되었습니까?

해결책

You don't need to call addField to just add a normal control to the field editor preference page. The code you have is sufficient. addField is only needed for FieldEditor derived classes.

Update: Your setLayoutData is incorrect, use something like:

link.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1));

You may have to adjust the number of columns depending on the rest of your page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top