Search in sources :

Example 1 with ActionRegistry

use of org.whole.lang.e4.ui.actions.ActionRegistry in project whole by wholeplatform.

the class ModelMergeViewer method createMergeArea.

protected Control createMergeArea(Composite parent) {
    IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    params.set(IImportAsModelDialogFactory.class, factory);
    viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, getContext(), params);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateSelection(E4Utils.createSelectionBindings(event, getContext()));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

        @SuppressWarnings("unchecked")
        @Override
        public void focusGained(FocusEvent event) {
            getContext().set(IEntityPartViewer.class, viewer);
            getContext().set(ActionRegistry.class, actionRegistry);
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
        }
    });
    viewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(getContext());
    keyHandler.setParent(new E4NavigationKeyHandler(getContext()));
    viewer.setKeyHandler(keyHandler);
    viewer.setEntityContents(createDefaultContents());
    getContext().set(IEntityPartViewer.class, viewer);
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, getContext());
    actionRegistry.registerWorkbenchActions();
    getContext().set(ActionRegistry.class, actionRegistry);
    JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, getContext());
    contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
    viewer.setContextMenu(new ContextMenuProvider(viewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            contextMenuProvider.populate(menuManager);
        }
    });
    return parent;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) JFaceMenuBuilder(org.whole.lang.e4.ui.menu.JFaceMenuBuilder) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) GridData(org.eclipse.swt.layout.GridData) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) IMenuManager(org.eclipse.jface.action.IMenuManager) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 2 with ActionRegistry

use of org.whole.lang.e4.ui.actions.ActionRegistry in project whole by wholeplatform.

the class ActionsE4InterpreterVisitor method createAction.

protected IAction createAction(Value kind, IEnablerPredicate enablerPredicate, IEntityTransformer transformer, IEntity prototype, String text) {
    // FIXME transformer always passed as null
    IEclipseContext context = (IEclipseContext) getBindings().wGetValue("context");
    ActionFactory actionRegistry = new ActionFactory(context);
    QueriesEntityFactory qf = QueriesEntityFactory.instance;
    IEntity predicate = enablerPredicate instanceof OpaqueEnablerPredicate ? ((OpaqueEnablerPredicate) enablerPredicate).value : qf.createBooleanLiteral(true);
    switch(kind.getOrdinal()) {
        case ActionKindEnum.REPLACE_ord:
            return actionRegistry.createReplaceFragmentAction(text, predicate, prototype);
        case ActionKindEnum.INSERT_ord:
            return actionRegistry.createAddFragmentAction(text, predicate, prototype);
        case ActionKindEnum.WRAP_ord:
            IEntity behavior = qf.createPointwiseUpdate(qf.createVariableRefStep("focusEntity"), CommonsEntityAdapterFactory.createStageUpFragment(QueriesEntityDescriptorEnum.Expression, prototype));
            return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, behavior);
        case ActionKindEnum.PERFORM_ord:
            return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, prototype);
        default:
            throw new IllegalArgumentException("not implemented yet");
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ActionFactory(org.whole.lang.e4.ui.actions.ActionFactory)

Example 3 with ActionRegistry

use of org.whole.lang.e4.ui.actions.ActionRegistry in project whole by wholeplatform.

the class E4Dialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    if (E4Utils.isLegacyApplication())
        HandlersBehavior.registerHandlers(handlerService);
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, params);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateSelection(E4Utils.createSelectionBindings(event, context));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

        @SuppressWarnings("unchecked")
        @Override
        public void focusGained(FocusEvent event) {
            context.set(IEntityPartViewer.class, viewer);
            context.set(ActionRegistry.class, actionRegistry);
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
        }
    });
    viewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
            context.activateBranch();
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    context.set(IEntityPartViewer.class, viewer);
    viewer.setKeyHandler(keyHandler);
    viewer.setEntityContents(createDefaultContents());
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    actionRegistry.registerWorkbenchActions();
    context.set(ActionRegistry.class, actionRegistry);
    JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, context);
    contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
    viewer.setContextMenu(new ContextMenuProvider(viewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            contextMenuProvider.populate(menuManager);
        }
    });
    return parent;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) JFaceMenuBuilder(org.whole.lang.e4.ui.menu.JFaceMenuBuilder) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) GridData(org.eclipse.swt.layout.GridData) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) IMenuManager(org.eclipse.jface.action.IMenuManager) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 4 with ActionRegistry

use of org.whole.lang.e4.ui.actions.ActionRegistry in project whole by wholeplatform.

the class AbstractE4Part method createPartControl.

@PostConstruct
public void createPartControl(Composite parent) {
    restoreState();
    registerHandlers();
    parent.setLayout(new FillLayout());
    viewer = createEntityViewer(parent);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateSelection(E4Utils.createSelectionBindings(event, context));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

        @Override
        @SuppressWarnings("unchecked")
        public void focusGained(FocusEvent event) {
            context.set(IEntityPartViewer.class, viewer);
            context.set(ActionRegistry.class, actionRegistry);
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
        }
    });
    viewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    context.set(IEntityPartViewer.class, viewer);
    viewer.setKeyHandler(keyHandler);
    viewer.setContents(modelInput, createDefaultContents());
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    actionRegistry.registerKeyActions(viewer.getKeyHandler());
    context.set(ActionRegistry.class, actionRegistry);
    configureContextMenu();
    if (!E4Utils.isLegacyApplication())
        viewer.getCommandStack().addCommandStackEventListener(new CommandStackEventListener() {

            @Override
            public void stackChanged(CommandStackEvent event) {
                if ((event.getDetail() & CommandStack.POST_MASK) != 0)
                    part.setDirty(viewer.isDirty());
            }
        });
    reloader = new LazyConfirmationDialogReloader(viewer.getControl(), new Runnable() {

        @Override
        public void run() {
            viewer.setContents(modelInput, null);
        }
    });
}
Also used : LazyConfirmationDialogReloader(org.whole.lang.ui.dialogs.LazyConfirmationDialogReloader) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) CommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) CommandStackEvent(org.eclipse.gef.commands.CommandStackEvent) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) PostConstruct(javax.annotation.PostConstruct)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FocusListener (org.eclipse.swt.events.FocusListener)3 ActionRegistry (org.whole.lang.e4.ui.actions.ActionRegistry)3 E4KeyHandler (org.whole.lang.e4.ui.actions.E4KeyHandler)3 E4NavigationKeyHandler (org.whole.lang.e4.ui.actions.E4NavigationKeyHandler)3 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)3 IPartFocusListener (org.whole.lang.ui.editparts.IPartFocusListener)3 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 GridData (org.eclipse.swt.layout.GridData)2 JFaceMenuBuilder (org.whole.lang.e4.ui.menu.JFaceMenuBuilder)2 E4GraphicalViewer (org.whole.lang.e4.ui.viewers.E4GraphicalViewer)2 PostConstruct (javax.annotation.PostConstruct)1 CommandStackEvent (org.eclipse.gef.commands.CommandStackEvent)1 CommandStackEventListener (org.eclipse.gef.commands.CommandStackEventListener)1