|
|
|
|
Re: "Root" layout [message #1840837 is a reply to message #1840357] |
Mon, 26 April 2021 12:27 |
|
Hi Yoann,
Sorry for the delay. The way to use the ELK layouts is pretty simple and quick, you can see the detailed documentation on their own website [1].
You'll need the ELK tool installed or in you workspace for the runtime (from memory I used the 5.0 las time I tested this but I'd think this should still be functional).
Because there is a Papyrus editor connector and the GMF/EMF layer used you a should only need to implement the following steps to begin using the elk layouts (again, from memory).
1- registering your elk extension point:
<extension
point="org.eclipse.elk.core.service.layoutConnectors">
<setup class="org.eclipse.<yourpath>.PapyrusDiagramtemplateElkLayoutSetup">
</setup>
</extension>
2- Extend ELK's GMFLayoutSetup and GMFDiagramLayoutConnector:
public class PapyrusDiagramtemplateElkLayoutSetup extends GmfLayoutSetup {
// Use this class to add new customization options
/** Guice module for the generic GMF connector. */
public static class GmfLayoutModule implements Module {
@Override
public void configure(final Binder binder) {
binder.bind(IDiagramLayoutConnector.class).to(PapyrusDiagramtemplateELKLayoutConnector.class);
binder.bind(ILayoutConfigurationStore.Provider.class).to(GmfLayoutConfigurationStore.Provider.class);
}
}
}
public class PapyrusDiagramtemplateELKLayoutConnector extends GmfDiagramLayoutConnector {
// Use this class to add new customization options
}
Then you'll just have to set an interface through which you can call a custom layout configured with the required features, such as (and this might very well not be the best implementation of it ever ^^):
/**
* Helper method used to arrange recursively editparts
*
* @param editpart
* the editpart to process
*/
@SuppressWarnings("unchecked")
public static void arrangeDiagram(EditPart editPart) {
arrangeDiagramEditParts(editPart);
arrangeDiagramEditPartsWithELK(editPart);
arrangeConnectors((IGraphicalEditPart) editPart);
}
private static void arrangeDiagramEditParts(EditPart editPart) {
ArrangeRequest request = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED);
List<EditPart> listToArrange = new ArrayList<>();
listToArrange.addAll(editPart.getChildren());
if (!listToArrange.isEmpty()) {
for (Object element : editPart.getChildren()) {
if (element instanceof EditPart) {
arrangeDiagramEditParts((EditPart) element);
}
}
request.setViewAdaptersToArrange(listToArrange);
Command command = editPart.getCommand(request);
if (null != command && command.canExecute()) {
command.execute();
}
}
}
private static void arrangeDiagramEditPartsWithELK(EditPart editPart) {
LayoutConfigurator layoutConfigurator = new LayoutConfigurator();
// You might want or need to add new customized parameters to either ElkNodes or ElkEdges following the same template
layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.ALGORITHM, "org.eclipse.elk.layered");
layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.DIRECTION, Direction.DOWN);
layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 60.0);
layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.SEPARATE_CONNECTED_COMPONENTS, true);
DiagramLayoutEngine.Parameters params = new DiagramLayoutEngine.Parameters();
params.addLayoutRun(layoutConfigurator);
params.getGlobalSettings()
.setProperty(CoreOptions.ANIMATE, false)
.setProperty(CoreOptions.PROGRESS_BAR, false)
.setProperty(CoreOptions.LAYOUT_ANCESTORS, false)
.setProperty(CoreOptions.ZOOM_TO_FIT, false);
DiagramLayoutEngine.invokeLayout(getWorkbenchPart(), null, params);
}
private static IWorkbenchPart getWorkbenchPart() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
}
private static void arrangeConnectors(IGraphicalEditPart modelEditPart) {
DiagramTemplateSelectAction selectAction = new DiagramTemplateSelectAction(SelectAction.SELECT_ALL_CONNECTORS, Collections.singletonList(modelEditPart));
List<IGraphicalEditPart> list = selectAction.getAvailableConnectors();
LineStyleAction lineStyleAction = new LineStyleAction(LineStyleAction.RECTILINEAR, list);
Command RectilinearCommand = lineStyleAction.getCommand();
modelEditPart.getEditingDomain().getCommandStack().execute(new GEFtoEMFCommandWrapper(RectilinearCommand));
}
public class DiagramTemplateSelectAction extends SelectAction {
public DiagramTemplateSelectAction(String parameter, List<IGraphicalEditPart> selectedElements) {
super(parameter, selectedElements);
}
public List<IGraphicalEditPart> getAvailableConnectors() {
refreshAllEditParts(getDiagramEditPart());
System.err.println("getAvailableConnectors_getSelectableNodes: " + getSelectableNodes(getDiagramEditPart()).size());
System.err.println("getAvailableConnectors_getAllDiagramEditParts: " + DiagramEditPartsUtil.getAllEditParts(getDiagramEditPart()).size());
List<IGraphicalEditPart> connectorEditParts = getAllConnectors(DiagramEditPartsUtil.getAllEditParts(getDiagramEditPart()));
return connectorEditParts;
}
private void refreshAllEditParts(IGraphicalEditPart gEditPart) {
Iterator<IGraphicalEditPart> it = gEditPart.getChildren().iterator();
while (it.hasNext()) {
IGraphicalEditPart igep = it.next();
igep.refresh();
refreshAllEditParts(igep);
}
}
private List<IGraphicalEditPart> getAllConnectors(List<IGraphicalEditPart> allgEditParts) {
System.err.println("getAllConnectors:" + addSelectableConnections(allgEditParts).size());
return addSelectableConnections(allgEditParts);
}
}
HTH,
/Quentin
[1] https://www.eclipse.org/elk/documentation/tooldevelopers/usingeclipselayout.html
|
|
|
Powered by
FUDForum. Page generated in 0.02486 seconds