use of org.eclipse.gmf.runtime.diagram.ui.services.layout.ILayoutNode in project elk by eclipse.
the class ElkLayoutProvider method layoutLayoutNodes.
@Override
@SuppressWarnings("rawtypes")
public Runnable layoutLayoutNodes(final List layoutNodes, final boolean offsetFromBoundingBox, final IAdaptable layoutHint) {
// fetch general settings from preferences
final boolean zoomToFit = Platform.getPreferencesService().getBoolean("org.eclipse.elk.core.ui", "org.eclipse.elk.zoomToFit", false, null);
final boolean progressDialog = Platform.getPreferencesService().getBoolean("org.eclipse.elk.core.ui", "org.eclipse.elk.progressDialog", false, null);
// determine the elements to process
final Object diagramPart;
if (layoutNodes.isEmpty()) {
diagramPart = layoutHint.getAdapter(IGraphicalEditPart.class);
} else {
List<IGraphicalEditPart> partList = new ArrayList<IGraphicalEditPart>(layoutNodes.size());
IGraphicalEditPart parent = (IGraphicalEditPart) layoutHint.getAdapter(IGraphicalEditPart.class);
if (parent != null) {
Iterator<?> nodeIter = layoutNodes.iterator();
while (nodeIter.hasNext()) {
ILayoutNode layoutNode = (ILayoutNode) nodeIter.next();
IGraphicalEditPart editPart = findEditPart(parent, layoutNode.getNode());
if (editPart != null) {
partList.add(editPart);
}
}
}
diagramPart = partList;
}
return new Runnable() {
public void run() {
DiagramLayoutEngine.invokeLayout(null, diagramPart, false, progressDialog, false, zoomToFit);
}
};
}
use of org.eclipse.gmf.runtime.diagram.ui.services.layout.ILayoutNode in project elk by eclipse.
the class ElkLayoutProvider method canLayoutNodes.
/**
* {@inheritDoc}<br>
* <br>
* This method returns <code>true</code> only for {@link IGraphicalEditPart IGraphicalEditParts}
* whose figures are visible and that contain at least a {@link ShapeNodeEditPart}, which is not
* an {@link AbstractBorderItemEditPart} or an {@link AbstractImageEditPart}.<br>
* <br>
* In short, returns only true if the provided edit part contains children that can be layouted.
*/
@SuppressWarnings("rawtypes")
public boolean canLayoutNodes(final List layoutNodes, final boolean shouldOffsetFromBoundingBox, final IAdaptable layoutHint) {
Object o = layoutHint.getAdapter(IGraphicalEditPart.class);
if (!(o instanceof IGraphicalEditPart)) {
return false;
}
final IGraphicalEditPart parent = (IGraphicalEditPart) o;
// computing layout on the element wouldn't make sense otherwise
if (layoutNodes.isEmpty()) {
return Iterables.any((List<?>) parent.getChildren(), new Predicate<Object>() {
public boolean apply(final Object o) {
return o instanceof ShapeNodeEditPart && !(o instanceof AbstractBorderItemEditPart) && !(o instanceof AbstractImageEditPart);
}
});
} else {
return Iterables.any((List<?>) layoutNodes, new Predicate<Object>() {
public boolean apply(final Object o) {
ILayoutNode layoutNode = (ILayoutNode) o;
IGraphicalEditPart editPart = findEditPart(parent, layoutNode.getNode());
return editPart instanceof ShapeNodeEditPart && !(editPart instanceof AbstractBorderItemEditPart) && !(editPart instanceof AbstractImageEditPart);
}
});
}
}
Aggregations