Search in sources :

Example 1 with IEntityPart

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

the class StyledTreePartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object modelEntity) {
    IEntityPart contextPart = (IEntityPart) context;
    IEntity entity = (IEntity) modelEntity;
    EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
    if (ed.equals(CommonsEntityDescriptorEnum.Resolver))
        return new PlaceHolderPart();
    else {
        IEntityStyling entityStyling = notationStyling.getEntityStyling(this, contextPart, entity);
        switch(ed.getEntityKind()) {
            case SIMPLE:
                return new SimpleEntityStyledTreePart(this, entityStyling);
            case COMPOSITE:
                return new CompositeEntityStyledTreePart(this, entityStyling);
            default:
            case DATA:
                // TODO test
                if (entity.wGetEntityDescriptor().getName().equals("SimpleName") && entity.wGetParent().wGetEntityDescriptor().getName().equals("Feature"))
                    entity.wGetEntityDescriptor();
                switch(notationStyling.getEmbeddingStyle(this, contextPart, entity)) {
                    case TABLE_CELL:
                        switch(// TODO replace with styling features
                        ed.getDataKind()) {
                            case STRING:
                                return new LiteralTextualEntityPart();
                            default:
                                return new LiteralDataEntityPart();
                        }
                    case NONE:
                    default:
                        return new DataEntityStyledTreePart(this, entityStyling);
                }
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) LiteralDataEntityPart(org.whole.lang.ui.editparts.LiteralDataEntityPart) IEntityStyling(org.whole.lang.ui.notations.styledtree.styling.IEntityStyling) PlaceHolderPart(org.whole.lang.ui.editparts.PlaceHolderPart) LiteralTextualEntityPart(org.whole.lang.ui.editparts.LiteralTextualEntityPart) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 2 with IEntityPart

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

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

the class CommandFactory method create.

public Command create(PartRequest request) {
    IPartRequestHandler handler;
    // tries to handle operation with custom handlers
    List<IPartRequestHandler> handlerList = handlersMap.get(request.getRequestType());
    if (handlerList != null && !handlerList.isEmpty()) {
        Iterator<IPartRequestHandler> handlerIterator = handlerList.iterator();
        while (handlerIterator.hasNext()) {
            handler = (IPartRequestHandler) handlerIterator.next();
            if (handler.canHandlePartRequest(request))
                return handler.handlePartRequest(request);
        }
    }
    // handle basic requests
    if (EntityUtils.isComposite(request.getModelEntity()) && request.getRequestType() == PartRequest.MOVE_CHILD)
        return moveIndexedFeature.create(request);
    if (request.getRequestType() == PartRequest.MOVE_ORPHAN_CHILD) {
        if (EntityUtils.isComposite(request.getModelEntity()))
            return orphanIndexedFeature.create(request);
        else
            return orphanFeature.create(request);
    }
    if (request.getRequestType() == PartRequest.DELETE) {
        if (EntityUtils.isComposite(request.getParentModelEntity()))
            return removeIndexedFeature.create(request);
        else
            // was else if (EntityUtils.isSimple(request.getParentModelEntity()))
            return removeFeature.create(request);
    }
    // handle composite and simple requests
    if (isDnDRequest(request)) {
        boolean isCompositeAddCommand, isReplaceCommand;
        isCompositeAddCommand = isReplaceCommand = request.size() > 0;
        IEntity targetEntity = request.getModelEntity();
        boolean isCloneRequest = request.getRequestType() == PartRequest.CLONE_CHILD;
        HashSet<IEntity> targetEntityAncestors = new HashSet<IEntity>();
        GenericTraversalFactory tf = GenericTraversalFactory.instance;
        IBinaryVisitor ancestorsVisitor = tf.ancestors(tf.collect(tf.identity(), targetEntityAncestors));
        ancestorsVisitor.visit(targetEntity);
        for (IEntityPart dndPart : request) {
            IEntity dndEntity = dndPart.getModelEntity();
            if (targetEntityAncestors.contains(dndEntity) && !isCloneRequest)
                return UnexecutableCommand.INSTANCE;
            EntityDescriptor<?> dndEntityDescriptor = dndEntity.wGetEntityDescriptor();
            isCompositeAddCommand &= EntityUtils.isAddable(targetEntity, dndEntityDescriptor) || EntityUtils.isComposite(targetEntity);
            isReplaceCommand &= EntityUtils.isReplaceable(targetEntity, dndEntityDescriptor);
        }
        if (isCompositeAddCommand)
            return createCompositeAddCommand(request);
        else if (isReplaceCommand)
            return createReplaceCommand(request);
        else
            return UnexecutableCommand.INSTANCE;
    }
    return null;
}
Also used : IEntity(org.whole.lang.model.IEntity) GenericTraversalFactory(org.whole.lang.visitors.GenericTraversalFactory) IBinaryVisitor(org.whole.lang.visitors.IBinaryVisitor) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) HashSet(java.util.HashSet)

Example 4 with IEntityPart

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

the class CaretUtils method getCaretPositions.

public static int getCaretPositions(IEntityPartViewer viewer, IEntity entity) {
    IEntityPart entityPart = viewer.getEditPartRegistry().get(entity);
    if (!(entityPart instanceof ITextualEntityPart))
        throw new IllegalArgumentException("the entity part is not textual");
    ITextualEntityPart targetPart = (ITextualEntityPart) entityPart;
    return targetPart.getCaretPositions();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 5 with IEntityPart

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

the class ActivateToolAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    boolean clearCaret = Tools.TEXTUAL != tool && Tools.TEXTUAL.isActive(viewer);
    if (tool.ensureActive(viewer) && clearCaret) {
        IEntity focusEntity = bm.wGet("focusEntity");
        IEntityPart focusPart = viewer.getEditPartRegistry().get(focusEntity);
        if (focusPart instanceof ITextualEntityPart) {
            ITextualEntityPart textualPart = (ITextualEntityPart) focusPart;
            textualPart.setCaretVisible(false);
            viewer.setSelection(new StructuredSelection(textualPart));
        }
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

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