Search in sources :

Example 11 with IGraphicalEntityPart

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

the class TextualHilightEditPolicy method showCaret.

private void showCaret() {
    if (isTextToolActive()) {
        IBindingManager bm = getCurrentViewer().getContextBindings();
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart textualHost = getTextualHost();
        if (focusEntity != null && textualHost.getModelEntity() != focusEntity && !Matcher.match(CommonsEntityDescriptorEnum.RootFragment, focusEntity)) {
            // FIXME workaround for focusEntity == RootFragment after a focus lost
            IGraphicalEntityPart focusPart = (IGraphicalEntityPart) ModelObserver.getObserver(focusEntity, getCurrentViewer().getEditPartRegistry());
            if (focusPart != null) {
                int position = FigureUtils.getPositionOf(textualHost.getFigure(), focusPart.getFigure());
                textualHost.setCaretPosition(position == PositionConstants.EAST ? 0 : textualHost.getCaretPositions());
            }
        }
        textualHost.setCaretVisible(true);
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with IGraphicalEntityPart

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

the class FigureUtils method filterClosestVertically.

@SuppressWarnings("unchecked")
public static LinkedList<IGraphicalEntityPart> filterClosestVertically(List<IGraphicalEntityPart> entityParts, boolean above, Rectangle bounds) {
    int targetLimit = above ? bounds.y : bounds.bottom();
    int closestY = above ? 0 : Integer.MAX_VALUE;
    LinkedList<IGraphicalEntityPart> closestVertically = new LinkedList<>();
    for (IGraphicalEntityPart entityPart : entityParts) {
        if (!entityPart.getFigure().isVisible())
            continue;
        Rectangle partBounds = entityPart.getFigure().getBounds();
        if (partBounds.contains(bounds) && !entityPart.getChildren().isEmpty()) {
            LinkedList<IGraphicalEntityPart> filtered = filterClosestVertically(entityPart.getChildren(), above, bounds);
            if (!filtered.isEmpty())
                return filtered;
        } else {
            int limit = above ? partBounds.bottom() : partBounds.y;
            if ((above && limit >= closestY && limit < targetLimit) || (!above && limit <= closestY && limit > targetLimit)) {
                if (limit > closestY)
                    closestVertically.clear();
                closestVertically.add(entityPart);
                closestY = limit;
            }
        }
    }
    return extractContainerEntityParts(closestVertically);
}
Also used : IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) LinkedList(java.util.LinkedList)

Example 13 with IGraphicalEntityPart

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

the class FigureUtils method getClosestWrappingHorizontally.

public static IGraphicalEntityPart getClosestWrappingHorizontally(LinkedList<IGraphicalEntityPart> entityParts, boolean above, Rectangle bounds) {
    LinkedList<IGraphicalEntityPart> candidates = entityParts.stream().filter((p) -> p.getFigure().getBounds().x < bounds.x && bounds.x <= p.getFigure().getBounds().right()).collect(Collectors.toCollection(() -> new LinkedList<>()));
    candidates.sort((f, s) -> {
        Rectangle fb = f.getFigure().getBounds();
        Rectangle sb = s.getFigure().getBounds();
        return above ? fb.y - sb.y : sb.bottom() - fb.bottom();
    });
    if (!candidates.isEmpty())
        return candidates.getLast();
    return entityParts.stream().reduce((f, s) -> {
        Rectangle fb = f.getFigure().getBounds();
        Rectangle sb = s.getFigure().getBounds();
        int df = Math.min(Math.abs(fb.x - bounds.x), Math.abs(fb.right() - bounds.x));
        int ds = Math.min(Math.abs(sb.x - bounds.x), Math.abs(sb.right() - bounds.x));
        return df < ds ? f : s;
    }).orElse(null);
}
Also used : PositionConstants(org.eclipse.draw2d.PositionConstants) List(java.util.List) ListIterator(java.util.ListIterator) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) LinkedList(java.util.LinkedList) Collectors(java.util.stream.Collectors) IFigure(org.eclipse.draw2d.IFigure) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) LinkedList(java.util.LinkedList)

Example 14 with IGraphicalEntityPart

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

the class EditPartTransferDragSourceListener method dragStart.

@Override
public void dragStart(DragSourceEvent event) {
    EditPartViewer viewer = getViewer();
    List<EditPart> selectedEditParts = ClipboardUtils.getSelectedEditParts(viewer);
    if (selectedEditParts.isEmpty())
        event.doit = false;
    else
        event.image = dragSourceImage = WholeNonResizableEditPolicy.createFeedbackImage((IGraphicalEntityPart) selectedEditParts.get(0), FeedbackImageFigure.ALPHA, true, FitToScreenStrategy.instance());
    storeSelection(selectedEditParts);
    // this is an hack to allow drop enablement calculations
    // see the selected entities before the final drop event
    EditPartsTransfer.instance().setObject(getSelectedEditParts());
}
Also used : EditPart(org.eclipse.gef.EditPart) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) EditPartViewer(org.eclipse.gef.EditPartViewer)

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