Search in sources :

Example 6 with IEntityPart

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

the class E4NavigationKeyHandler method getEditPoint.

public EditPoint getEditPoint() {
    if (editPoint == null)
        editPoint = new EditPoint((IEntityPart) getFocusEntityPart(), 0);
    else {
        IEntityPart focusPart = (IEntityPart) getFocusEntityPart();
        if (editPoint.focus != focusPart) {
            editPoint.focus = focusPart;
            editPoint.caret = 0;
        }
    }
    return editPoint;
}
Also used : EditPoint(org.whole.lang.ui.tools.EditPoint) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 7 with IEntityPart

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

the class E4NavigationKeyHandler method navigateNextSibling.

/**
 * Traverses to the closest EditPart in the given list that is also in the given direction.
 *
 * @param	event		the KeyEvent for the keys that were pressed to trigger this traversal
 * @param	direction	PositionConstants.* indicating the direction in which to traverse
 */
boolean navigateNextSibling(KeyEvent event, int direction, List<?> list) {
    IEntityPart epStart = getFocusEntityPart();
    if (epStart instanceof ITextualEntityPart) {
        ITextualEntityPart textualEntityPart = (ITextualEntityPart) epStart;
        ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
        String text = textualFigure.getText();
        int line = CaretUtils.getLineFromPosition(text, textualEntityPart.getCaretPosition());
        int lines = CaretUtils.getCaretLines(text);
        if ((direction == PositionConstants.WEST && textualEntityPart.getCaretPosition() > 0) || (direction == PositionConstants.EAST && textualEntityPart.getCaretPosition() < textualEntityPart.getCaretPositions())) {
            int position = textualEntityPart.getCaretPosition() + (direction == PositionConstants.WEST ? -1 : 1);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), position, true);
            return true;
        } else if ((direction == PositionConstants.NORTH && line > 0) || (direction == PositionConstants.SOUTH && line < lines)) {
            int dy = FigureUtilities.getFontMetrics(textualFigure.getFont()).getHeight() * (direction == PositionConstants.NORTH ? -1 : 1);
            Point location = textualFigure.getCaretBounds().getCenter().translate(0, dy);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), location, true);
            textualEntityPart.updateCaret(location);
            return true;
        }
    }
    if (!(epStart instanceof IGraphicalEntityPart))
        return false;
    IFigure figure = ((IGraphicalEntityPart) epStart).getFigure();
    Point pStart = getNavigationPoint(figure);
    figure.translateToAbsolute(pStart);
    // parent.findSibling(pStart, direction, epStart);
    EditPart next = findSibling(list, pStart, direction, epStart);
    while (next == null) {
        if (!(epStart.getParent() instanceof IGraphicalEntityPart))
            return false;
        epStart = (IGraphicalEntityPart) epStart.getParent();
        if (epStart == getViewer().getContents() || epStart.getParent() == getViewer().getContents() || epStart.getParent() == null)
            return false;
        list = epStart.getParent().getChildren();
        next = findSibling(list, pStart, direction, epStart);
    }
    // next = next.enter(pStart, direction, epStart);1+2
    navigateTo(next, event);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) IFigure(org.eclipse.draw2d.IFigure)

Example 8 with IEntityPart

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

the class DynamicPartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object modelEntity) {
    IEntityPart contextPart = (IEntityPart) context;
    IEntity entity = (IEntity) modelEntity;
    EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
    IOptionalPartFactoryMethod<DynamicPartFactory> factoryMethod = edFactoryMethodMap.get(ed);
    if (factoryMethod == null)
        factoryMethod = kindFactoryMethodMap.get(ed.getEntityKind());
    if (factoryMethod == null)
        return defaultPartFactory.createEditPart(contextPart, entity);
    return factoryMethod.apply(this, contextPart, entity).get();
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 9 with IEntityPart

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

the class WholeLayoutEditPolicy method getCreateCommand.

protected Command getCreateCommand(CreateRequest request) {
    // TODO incapsulate in command factory
    Object newObject = request.getNewObject();
    if (newObject instanceof IEntity) {
        IEntityPart hostPart = (IEntityPart) getHost();
        // TODO
        // return commandFactory.create(new
        // DnDOverPartRequest(PartRequest.MOVE_ADD_CHILD,
        // hostPart, ((GroupRequest)request).getEditParts()));
        ReplaceChildCommand cmd = new ReplaceChildCommand();
        cmd.setParent(hostPart.getParentModelEntity());
        cmd.setOldChild(hostPart.getModelEntity());
        cmd.setNewChild((IEntity) newObject);
        return cmd;
    }
    return null;
}
Also used : IEntity(org.whole.lang.model.IEntity) ReplaceChildCommand(org.whole.lang.ui.commands.ReplaceChildCommand) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 10 with IEntityPart

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

the class SyntaxTreesEditorKit method getParentPart.

public IEntityPart getParentPart(IEntityPart part) {
    IEntityPart parentPart = (IEntityPart) part.getParent();
    IEntity parent = parentPart.getModelEntity();
    return parent.wGetEntityDescriptor().equals(SyntaxTreesEntityDescriptorEnum.Nodes) ? (IEntityPart) parentPart.getParent() : parentPart;
}
Also used : IEntity(org.whole.lang.model.IEntity) 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