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