简体   繁体   English

Eclipse自定义视角改变了开普勒对火星的态度

[英]Eclipse custom perspective changed approach Kepler to Mars

I am updating an existing working RCP 3 app from Kepler to Mars. 我正在将现有的RCP 3应用程序从开普勒更新到火星。 It was written by another guy so having to learn a lot about RCP as I go. 它是由另一个人写的,所以我在学习过程中必须学习很多有关RCP的知识。

What worked in Kepler was this: 在开普勒工作的是:

public class ShowSelectViewDialogHandler extends DialogHandler {

/**
 * The name of the parameter providing the view identifier.
 */
private static final String VIEW_ID_COMMAND_PARAMETER_NAME = "org.eclipse.ui.views.showView.viewId"; //$NON-NLS-1$
private static final String MAKE_FAST_COMMAND_PARAMETER_NAME = "org.eclipse.ui.views.showView.makeFast"; //$NON-NLS-1$

private final IHandler handler;

/**
 * Creates a new ShowViewHandler that will open the view in its default location.
 */
public ShowSelectViewDialogHandler (final IHandler handler) {
    this.handler = handler;
}

@Override
public final Object execute(final ExecutionEvent event) throws ExecutionException {
    Object result = null;

    IWorkbenchWindow window = EDMUIApplication.instance().getWorkbenchAdvisor().getWorkbenchWindowAdvisor().getWindow();

    Map<String, String> parameters = event.getParameters();
    String viewId = parameters.get(ShowSelectViewDialogHandler.VIEW_ID_COMMAND_PARAMETER_NAME);
    String makeFast = parameters.get(ShowSelectViewDialogHandler.MAKE_FAST_COMMAND_PARAMETER_NAME);

    if (viewId == null) {
        ShowViewDialog dialog = new ShowViewDialog(window, new EDMUIViewRegistry(EDMUIConstants.CATEGORY_IDS));
        if (dialog.open() == Window.OK) {
            for (IViewDescriptor viewDescriptor : dialog.getSelection()) {
                result = this.openView(window, viewDescriptor.getId(), makeFast);
            }
        }
    } else {
        result = this.openView(window, viewId, makeFast);
    }

    return result;
}

/**
 * Opens the view with the given ID.
 * 
 * @param window - workbench window of the view.
 * @param viewId - id of the view to open.
 * @param makeFast - command parameter.
 * @return result of the handler execution.
 * @throws ExecutionException - if default handler execution fails.
 */
private Object openView(final IWorkbenchWindow window, final String viewId, final String makeFast) throws ExecutionException {
    Object result = null;
    try {
        Parameterization[] parameterization = this.createParameterization(viewId, makeFast, IWorkbenchCommandConstants.VIEWS_SHOW_VIEW);
        result = this.executeDefaultHandler(this.handler, window, parameterization, IWorkbenchCommandConstants.VIEWS_SHOW_VIEW);
    } catch (NotDefinedException ex) {
        throw new ExecutionException(ex.getMessage(), ex);
    }

    return result;
}

/**
 * Creates parameterization for the command.
 * 
 * @param viewId - view id parameter value.
 * @param makeFast - make fast parameter value.
 * @param commandId - id of the command.
 * @return created parameterization.
 * @throws NotDefinedException - if there is no such parameter.
 */
private Parameterization[] createParameterization(final String viewId, final String makeFast, final String commandId) throws NotDefinedException {
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = commandService.getCommand(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW);

    IParameter viewIdParameter = command.getParameter(ShowSelectViewDialogHandler.VIEW_ID_COMMAND_PARAMETER_NAME);
    IParameter makeFastParameter = command.getParameter(ShowSelectViewDialogHandler.MAKE_FAST_COMMAND_PARAMETER_NAME);
    return new Parameterization[] { new Parameterization(viewIdParameter, viewId), new Parameterization(makeFastParameter, makeFast) };
}

But now ShowViewDialog signature has changed. 但是现在ShowViewDialog签名已更改。 Also the original author made the statement that his approach was based on ShowViewHandler and there must be a better more standard way of achieving the same affect, ie controlling the display of our reduced set of views. 原始作者还声明,他的方法基于ShowViewHandler,并且必须有更好的标准方法来实现相同的效果,即控制我们缩小的视图集的显示。

Any ideas on how to achieve this? 关于如何实现这一目标的任何想法? There might be a tutorial somewhere, I found the Vogella one, but it is fairly general. 在某处可能有一个教程,我找到了Vogella,但它相当笼统。

ShowViewDialog is an internal dialog so it should not have been used in the first place. ShowViewDialog是一个内部对话框,因此不应首先使用它。 As you have found internal dialogs can be changed without warning. 如您所见,内部对话框可以更改而不会发出警告。

It looks like your code is using your own implementation of IViewRegistry . 看起来您的代码正在使用自己的IViewRegistry实现。 To stick to using only official APIs you would have to write your own version of the show view dialog. 要坚持只使用官方API,您必须编写自己的show view对话框版本。 This is a fairly simple dialog using FilteredTree and the IViewRegistry getCategories and getViews methods. 这是一个非常简单的对话框,使用FilteredTree以及IViewRegistry getCategoriesgetViews方法。

There isn't a more standard way of doing this. 没有更标准的方法可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM