Search in sources :

Example 1 with IGraphicalEntityPart

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

the class FigureUtils method extractContainerEntityParts.

@SuppressWarnings("unchecked")
public static LinkedList<IGraphicalEntityPart> extractContainerEntityParts(LinkedList<IGraphicalEntityPart> entityParts) {
    ListIterator<IGraphicalEntityPart> iterator = entityParts.listIterator();
    // replace containers
    while (iterator.hasNext()) {
        IGraphicalEntityPart entityPart = iterator.next();
        if (!entityPart.getChildren().isEmpty()) {
            iterator.remove();
            LinkedList<IGraphicalEntityPart> children = new LinkedList<IGraphicalEntityPart>(entityPart.getChildren());
            for (IGraphicalEntityPart descendantPart : extractContainerEntityParts(children)) iterator.add(descendantPart);
        }
    }
    return entityParts;
}
Also used : IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) LinkedList(java.util.LinkedList)

Example 2 with IGraphicalEntityPart

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

the class FigureUtils method filterClosestHorizontally.

@SuppressWarnings("unchecked")
public static LinkedList<IGraphicalEntityPart> filterClosestHorizontally(List<IGraphicalEntityPart> entityParts, boolean before, Rectangle bounds) {
    int targetLimit = bounds.x * (before ? 1 : -1);
    int closestX = before ? 0 : -Integer.MAX_VALUE;
    LinkedList<IGraphicalEntityPart> closestHorizontally = new LinkedList<>();
    for (IGraphicalEntityPart entityPart : entityParts) {
        Rectangle partBounds = entityPart.getFigure().getBounds();
        if (partBounds.contains(bounds) && !entityPart.getChildren().isEmpty()) {
            LinkedList<IGraphicalEntityPart> filtered = filterClosestVertically(entityPart.getChildren(), before, bounds);
            if (!filtered.isEmpty())
                return filtered;
        } else {
            int limit = before ? partBounds.right() : partBounds.x;
            if (limit >= closestX && limit < targetLimit) {
                if (limit > closestX)
                    closestHorizontally.clear();
                closestHorizontally.add(entityPart);
                closestX = limit;
            }
        }
    }
    return extractContainerEntityParts(closestHorizontally);
}
Also used : IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) LinkedList(java.util.LinkedList)

Example 3 with IGraphicalEntityPart

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

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

the class E4NavigationKeyHandler method findSibling.

/**
 * Given an absolute point (pStart) and a list of EditParts, this method finds the closest
 * EditPart (except for the one to be excluded) in the given direction.
 *
 * @param	siblings	List of sibling EditParts
 * @param	pStart		The starting point (must be in absolute coordinates) from which
 * 						the next sibling is to be found.
 * @param	direction	PositionConstants
 * @param	exclude		The EditPart to be excluded from the search
 */
public IGraphicalEntityPart findSibling(List<?> siblings, Point pStart, int direction, EditPart exclude) {
    IGraphicalEntityPart epCurrent;
    IGraphicalEntityPart epFinal = null;
    IFigure figure;
    Point pCurrent;
    int distance = Integer.MAX_VALUE;
    Iterator<?> iter = siblings.iterator();
    while (iter.hasNext()) {
        epCurrent = (IGraphicalEntityPart) iter.next();
        if (epCurrent == exclude || !epCurrent.isSelectable())
            continue;
        figure = epCurrent.getFigure();
        pCurrent = getNavigationPoint(figure);
        figure.translateToAbsolute(pCurrent);
        if (pStart.getPosition(pCurrent) != direction)
            continue;
        Dimension difference = pCurrent.getDifference(pStart);
        int d = Math.abs(difference.width()) + Math.abs(difference.height());
        if (d < distance) {
            distance = d;
            epFinal = epCurrent;
        }
    }
    return epFinal;
}
Also used : IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with IGraphicalEntityPart

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

the class E4GraphicalViewer method setInteractive.

public void setInteractive(IEntity entity, boolean edit, boolean browse, boolean inherited) {
    Map<?, ?> mapping = getEditPartRegistry();
    IGraphicalEntityPart entityPart = (IGraphicalEntityPart) mapping.get(entity);
    if (entityPart != null) {
        IEntityFigure entityFigure = (IEntityFigure) entityPart.getFigure();
        entityFigure.setInteractiveEdit(edit);
        entityFigure.setInteractiveBrowse(browse);
        entityFigure.setInteractiveInherited(inherited);
    }
}
Also used : IEntityFigure(org.whole.lang.ui.figures.IEntityFigure) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart)

Aggregations

IGraphicalEntityPart (org.whole.lang.ui.editparts.IGraphicalEntityPart)14 IFigure (org.eclipse.draw2d.IFigure)5 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 LinkedList (java.util.LinkedList)4 IEntity (org.whole.lang.model.IEntity)4 Point (org.eclipse.draw2d.geometry.Point)3 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)3 EditPart (org.eclipse.gef.EditPart)2 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)2 IEntityFigure (org.whole.lang.ui.figures.IEntityFigure)2 EditPoint (org.whole.lang.ui.tools.EditPoint)2 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Collectors (java.util.stream.Collectors)1 Graphics (org.eclipse.draw2d.Graphics)1 PositionConstants (org.eclipse.draw2d.PositionConstants)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1