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);
}
}
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);
}
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);
}
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());
}
Aggregations