Eclipse插件开发 - 如何在FieldEditorPreferencePage上添加超链接

时间:2014-03-15 14:22:41

标签: java eclipse eclipse-rcp eclipse-plugin

我正在寻找在Eclipse Preferences页面中添加链接的方法。我很快找到了How to create a hyperlink in Eclipse plugin preferences page?。然而,解决方案不适合

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

但我不能addField(link);作为

  

FieldEditorPreferencePage类型中的方法addField(FieldEditor)不适用于参数(链接)

是否可以在FieldEditorPreferencePage中添加链接?例如从几个部分(标签,链接,文本)撰写FieldEditor

1 个答案:

答案 0 :(得分:1)

您无需调用addField即可将常规控件添加到字段编辑器首选项页面。您拥有的代码就足够了。仅addField派生类才需要FieldEditor

更新:您的setLayoutData不正确,请使用以下内容:

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

您可能需要根据页面的其余部分调整列数。