2016-02-19 29 views
0

我正在更新现有的工作RCP 3应用程序从 开普勒火星。它是由另一个人写的,所以我不得不在学习关于RCP的很多内容。Eclipse定制视角改变方法开普勒火星

什么在开普勒的工作是这样的:

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,并且必须有更好的更加标准的方法来实现同样的效果,即控制缩减的视图集的显示。

有关如何实现此目的的任何想法?在某个地方可能有一个教程,我找到了沃格拉一个,但它是相当普遍的。

+0

*签名如何变化? – nitind

+0

从这个改变的签名: 'ShowViewDialog(窗口,新EDMUIViewRegistry(EDMUIConstants.CATEGORY_IDS))' 到 'ShowViewDialog(壳牌壳,MApplication应用,MWindow窗口, \t \t \t EModelService modelService,IEclipseContext上下文)' – Olddave

回答

0

ShowViewDialog内部对话框,所以它不应该在第一个地方使用。正如您发现内部对话框可以在不发出警告的情况下进行更改

它看起来像你的代码使用你自己的IViewRegistry实现。要坚持只使用官方API,您必须编写自己的show view对话框。这是一个相当简单的对话,使用FilteredTreeIViewRegistrygetCategoriesgetViews方法。

没有一个更标准的方法来做到这一点。

+0

寻找在ShowViewDialog中作为编写我自己的基础,并且它有很多内部对话框API导入。它看起来并不简单,只有500行。我想我需要发现的是控制你自己的观点到哪里去的角度的标准方式。这似乎是之前的开发人员重写ShowViewDialog的原因。内部ui进口用于许多方法中,例如, getDialogBoundsSettings,configureShell和createFilteredTreeViewer。那么我需要这些方法吗?还是我需要提供我自己的内部类的子类? – Olddave

+0

这些覆盖大部分都是ShowViewDialog扩展的JFace Dialog类中的方法 - 它们不是内部的。任何新的类也将基于对话框,你将不得不编写自己的createFilteredTreeViewer方法。 –