Perspectiveswitcher не создает объект команды для переключения перспективы - PullRequest
0 голосов
/ 25 марта 2019

Проблема в том, что объект команды в моем коде равен нулю, и я не знаю почему.

Я использую e4-перспективный переключатель от Ларса Фогеля вместе с вопросомотсюда Как добавить Perspective Bar Switcher в приложение rcp pure eclipse 4 .

public class PerspectiveSwitcher {

    @Inject
    private ECommandService commandService;

    @Inject
    private EHandlerService handlerService;


    @PostConstruct
    public void createControls(Composite parent, EModelService modelService) {
        Composite body = new Composite(parent, SWT.NONE);
        body.setLayout(new GridLayout());
        body.setBackground(parent.getBackground());

        Button button = new Button(body, SWT.PUSH);
        button.setText("switch");
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
        data.minimumHeight = 20;
        button.setLayoutData(data);
        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                List<MPerspective> perspectives = modelService.findElements(app,
                        PTApplicationConstants.PERSPECTIVE_ID_MANAGER, MPerspective.class, null);
                MPerspective perspective = perspectives.get(0);

                HashMap<String, Object> parameters = new HashMap<>(2);
                parameters.put(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID, perspective.getElementId());
                parameters.put(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW, "false");

                ParameterizedCommand command = commandService
                        .createCommand(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE, parameters);
                handlerService.executeHandler(command);

                partService.switchPerspective(perspective);

                super.widgetSelected(e);
            }
        });
    }
}
...