Search in sources :

Example 26 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart 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 27 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class E4FindReplaceDialog method createReplaceArea.

protected Control createReplaceArea(Composite parent) {
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    replaceViewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, params);
    replaceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    replaceViewer.addSelectionChangedListener(new ISelectionChangedListener() {

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

        @Override
        public void focusLost(FocusEvent e) {
        }

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

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(replaceViewer.getSelectedEditParts(), replaceViewer, context));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    replaceViewer.setKeyHandler(keyHandler);
    replaceViewer.setEntityContents(createDefaultContents());
    context.set(IEntityPartViewer.class, replaceViewer);
    replaceActionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    replaceActionRegistry.registerWorkbenchActions();
    context.set(ActionRegistry.class, replaceActionRegistry);
    replaceViewer.setContextMenu(new ContextMenuProvider(replaceViewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            contextMenuProvider.populate(menuManager);
        }
    });
    return parent;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) 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) 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 28 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class HandlersBehavior method selectAll.

public static void selectAll(IBindingManager bm) {
    E4Utils.syncExec(bm, () -> {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity entityContents = viewer.getEntityContents();
        IEntityPart contents = viewer.getEditPartRegistry().get(entityContents);
        viewer.setSelection(new StructuredSelection(contents));
    });
}
Also used : IEntity(org.whole.lang.model.IEntity) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 29 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class HandlersBehavior method copyAsImage.

public static void copyAsImage(IBindingManager bm) {
    E4Utils.syncExec(bm, () -> {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity focusEntity = bm.wGet("focusEntity");
        IEntityPart part = viewer.getEditPartRegistry().get(focusEntity);
        String fileName = bm.wIsSet("fileName") ? bm.wStringValue("fileName") : ClipboardUtils.DEFAULT_OUTPUT_FILENAME;
        Clipboard.instance().setImageContents(fileName, (IGraphicalEntityPart) part);
    });
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 30 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class E4NavigationKeyHandler method navigateModel.

public boolean navigateModel(KeyEvent event, int direction) {
    EditPoint focusPoint = getEditPoint();
    if (!(focusPoint.focus.getParent() instanceof IEntityPart))
        return false;
    switch(direction) {
        case NORTH:
            IEntityPart parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            editPoint.focus = parentPart;
            break;
        case SOUTH:
            List<?> children = focusPoint.focus.getChildren();
            if (children.isEmpty())
                return false;
            editPoint.focus = (IEntityPart) children.get(0);
            break;
        case EAST:
            parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            List<?> siblings = parentPart.getChildren();
            int index = siblings.indexOf(editPoint.focus);
            if (index < siblings.size() - 1)
                editPoint.focus = findModelFirstChild((IEntityPart) siblings.get(index + 1));
            else
                editPoint.focus = parentPart;
            break;
        case WEST:
            parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            siblings = parentPart.getChildren();
            index = siblings.indexOf(editPoint.focus);
            if (index > 0)
                editPoint.focus = findModelLastChild((IEntityPart) siblings.get(index - 1));
            else
                editPoint.focus = parentPart;
            break;
    }
    editPoint.caret = 0;
    navigateTo(editPoint.focus, event);
    return true;
}
Also used : EditPoint(org.whole.lang.ui.tools.EditPoint) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint)

Aggregations

IEntityPart (org.whole.lang.ui.editparts.IEntityPart)49 IEntity (org.whole.lang.model.IEntity)21 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)12 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 ArrayList (java.util.ArrayList)6 EditPart (org.eclipse.gef.EditPart)6 Point (org.eclipse.draw2d.geometry.Point)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 FocusEvent (org.eclipse.swt.events.FocusEvent)4 FocusListener (org.eclipse.swt.events.FocusListener)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ActionRegistry (org.whole.lang.e4.ui.actions.ActionRegistry)4 E4KeyHandler (org.whole.lang.e4.ui.actions.E4KeyHandler)4 E4NavigationKeyHandler (org.whole.lang.e4.ui.actions.E4NavigationKeyHandler)4 IPartFocusListener (org.whole.lang.ui.editparts.IPartFocusListener)4 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)3