【问题标题】:Open Run Configuration... dialog in a eclipse application在 Eclipse 应用程序中打开运行配置...对话框
【发布时间】:2013-10-08 21:33:49
【问题描述】:

我想创建一个按钮来启动“运行配置...”对话框。我怎样才能做到这一点?我在 Spy 中看到 Active shell 类是 LaunchConfigurationsDialog 但我不知道如何使用这些信息。

【问题讨论】:

    标签: eclipse plugins jface


    【解决方案1】:

    LaunchConfigurationsDialog 在内部包中,因此不应直接使用。

    DebugUIPlugin 提供了这个方法来打开这个对话框:

    int openLaunchConfigurationsDialog(Shell shell, IStructuredSelection selection, String groupIdentifier, boolean setDefaults)
    

    Javadoc:

    Opens the LaunchConfigurationsDialog on the given selection for the given group. A status can be provided or null and the dialog can initialize the given ILaunchConfiguration to its defaults when opening as well - as long as the specified configuration is an ILaunchConfigurationWorkingCopy.
    
    Parameters:
    shell the shell to open the dialog on
    selection the non-null selection to show when the dialog opens
    groupIdentifier the identifier of the launch group to open the dialog on
    setDefaults if the default values should be set on the opened configuration - if there is one
    Returns:
    the return code from the dialog.open() call
    

    DebugUIPlugin 也在内部包中。

    “运行配置”菜单的命令 ID 是 org.eclipse.debug.ui.commands.OpenRunConfigurations,因此您可以使用以下命令执行该命令:

    IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
    handlerService.executeCommand("org.eclipse.debug.ui.commands.OpenRunConfigurations", null);
    

    【讨论】:

    • 我使用这个代码:DebugUITools.openLaunchConfigurationDialog(getShell(), DebugUITools.getLastLaunch(IDebugUIConstants.ID_RUN_LAUNCH_GROUP ), IDebugUIConstants.ID_RUN_LAUNCH_GROUP , null); 但它只显示一个带有单个启动配置的对话框。我需要准确显示单击 Run->Run Configurations... 命令时显示的内容。
    • 其实DebugUIPlugin也在一个内部包里所以这个也不应该用。
    • 在答案中添加了如何调用菜单项的命令。
    • 我已将IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class); handlerService.executeCommand("org.eclipse.debug.ui.commands.OpenRunConfigurations", null); 用于按钮的选择侦听器,但出现错误:The method getSite() is undefined for the type new SelectionListener(){}。我该如何解决?
    • getSite() 方法定义在视图或编辑器部分,您需要将其传递给您的代码。
    【解决方案2】:

    另一种方法是使用org.eclipse.debug.ui.actions.OpenLaunchDialogAction 并且可以在构造函数中指定组IDebugUIConstants.ID_RUN_LAUNCH_GROUP
    供您参考,您还可以创建自己的组并仅显示该组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 2016-01-24
      • 1970-01-01
      相关资源
      最近更新 更多