簡體   English   中英

Eclipse自定義視角改變了開普勒對火星的態度

[英]Eclipse custom perspective changed approach Kepler to Mars

我正在將現有的RCP 3應用程序從開普勒更新到火星。 它是由另一個人寫的,所以我在學習過程中必須學習很多有關RCP的知識。

在開普勒工作的是:

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

但是現在ShowViewDialog簽名已更改。 原始作者還聲明,他的方法基於ShowViewHandler,並且必須有更好的標准方法來實現相同的效果,即控制我們縮小的視圖集的顯示。

關於如何實現這一目標的任何想法? 在某處可能有一個教程,我找到了Vogella,但它相當籠統。

ShowViewDialog是一個內部對話框,因此不應首先使用它。 如您所見,內部對話框可以更改而不會發出警告。

看起來您的代碼正在使用自己的IViewRegistry實現。 要堅持只使用官方API,您必須編寫自己的show view對話框版本。 這是一個非常簡單的對話框,使用FilteredTree以及IViewRegistry getCategoriesgetViews方法。

沒有更標准的方法可以做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM