Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamlined layout infrastructure #589

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 134 additions & 258 deletions plugins/org.eclipse.fordiac.ide.elk/plugin.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

import java.util.List;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.elk.core.service.DiagramLayoutEngine;
import org.eclipse.elk.core.service.IDiagramLayoutConnector;
Expand All @@ -33,13 +29,12 @@
import org.eclipse.fordiac.ide.application.editparts.SubAppForFBNetworkEditPart;
import org.eclipse.fordiac.ide.application.editparts.UnfoldedSubappContentEditPart;
import org.eclipse.fordiac.ide.elk.commands.LayoutCommand;
import org.eclipse.fordiac.ide.elk.handlers.ConnectionLayoutHandler;
import org.eclipse.fordiac.ide.elk.helpers.FordiacGraphBuilder;
import org.eclipse.fordiac.ide.elk.helpers.FordiacGraphDataHelper;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerService;

import com.google.inject.Injector;

Expand All @@ -64,29 +59,14 @@ public void applyLayout(final LayoutMapping mapping, final IPropertyHolder setti

// schedule as async to ensure the changes from the layout command have been
// processed
Display.getDefault().asyncExec(() -> {
final var handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
final var networkEditPart = fordiacMapping.getNetworkEditPart();

try {
if (networkEditPart instanceof UnfoldedSubappContentEditPart) {
final var event = new Event();
event.data = networkEditPart.getParent(); // pass to the handler
handlerService.executeCommand("org.eclipse.fordiac.ide.elk.expandedSubappConnectionLayout", event); //$NON-NLS-1$
} else {
handlerService.executeCommand("org.eclipse.fordiac.ide.elk.connectionLayout", null); //$NON-NLS-1$
}
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
e.printStackTrace();
}
});
Display.getDefault().asyncExec(() -> ConnectionLayoutHandler
.getLayoutCommandNonHierarchical(fordiacMapping.getWorkbenchPart()).execute());
}

public static void executeManually(final List<SubAppForFBNetworkEditPart> editParts) {
final var workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
final Injector injector = LayoutConnectorsService.getInstance().getInjector(workbenchPart, null);
final DiagramLayoutEngine engine = injector.getInstance(DiagramLayoutEngine.class);
final var handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);

for (final var ep : editParts) {
final FordiacLayoutMapping mapping = new FordiacLayoutMapping(workbenchPart, true,
Expand All @@ -101,16 +81,8 @@ public static void executeManually(final List<SubAppForFBNetworkEditPart> editPa
mapping.getCommandStack().execute(new LayoutCommand(mapping.getLayoutData()));
}

Display.getDefault().asyncExec(() -> {
final var event = new Event();
event.data = ep; // pass to the handler
try {
handlerService.executeCommand("org.eclipse.fordiac.ide.elk.expandedSubappConnectionLayout", event); //$NON-NLS-1$
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
e.printStackTrace();
}
});

Display.getDefault().asyncExec(() -> ConnectionLayoutHandler
.getLayoutCommand((UnfoldedSubappContentEditPart) ep.getContentEP()).execute());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@
import org.eclipse.elk.core.util.BasicProgressMonitor;
import org.eclipse.fordiac.ide.application.editparts.UnfoldedSubappContentEditPart;
import org.eclipse.fordiac.ide.elk.FordiacLayoutData;
import org.eclipse.fordiac.ide.elk.commands.ConnectionLayoutCommand;
import org.eclipse.fordiac.ide.elk.connection.ConnectionLayoutMapping;
import org.eclipse.fordiac.ide.elk.connection.ConnectionRoutingHelper;
import org.eclipse.fordiac.ide.ui.FordiacLogHelper;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbenchPart;

public abstract class AbstractConnectionLayoutHandler extends AbstractLayoutHandler {

protected static void executeCommand(final ExecutionEvent event, final IWorkbenchPart part,
final FordiacLayoutData data) {
final ConnectionLayoutCommand cmd = new ConnectionLayoutCommand(data);
protected static void executeCommand(final ExecutionEvent event, final IWorkbenchPart part, final Command cmd) {
if (isAutomaticLayout(event)) {
// passes the cmd back to the editor to be handled there
((Event) event.getTrigger()).data = cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
package org.eclipse.fordiac.ide.elk.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.fordiac.ide.application.editparts.UnfoldedSubappContentEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
Expand All @@ -32,4 +34,8 @@ public void setEnabled(final Object evaluationContext) {
}
}

protected static boolean isSubappLayout(final StructuredSelection selection) {
return selection != null && selection.getFirstElement() instanceof UnfoldedSubappContentEditPart;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Primetals Technologies Austria GmbH
* Copyright (c) 2022 - 2024 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -19,40 +19,65 @@
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.elk.alg.libavoid.server.LibavoidServerException;
import org.eclipse.fordiac.ide.elk.FordiacLayoutData;
import org.eclipse.fordiac.ide.application.editparts.UnfoldedSubappContentEditPart;
import org.eclipse.fordiac.ide.elk.Messages;
import org.eclipse.fordiac.ide.elk.commands.ConnectionLayoutCommand;
import org.eclipse.fordiac.ide.elk.connection.ConnectionLayoutMapping;
import org.eclipse.fordiac.ide.elk.connection.ConnectionRoutingHelper;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IEditorPart;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;

public class ConnectionLayoutHandler extends AbstractConnectionLayoutHandler {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart part = HandlerUtil.getActiveEditor(event);
if (null != part) {
try {
final ConnectionLayoutMapping mapping = run(part);
final FordiacLayoutData data = ConnectionRoutingHelper.calculateConnections(mapping);
runSubapps(mapping, data);
executeCommand(event, part, data);
} catch (final LibavoidServerException e) {
MessageDialog.openWarning(HandlerUtil.getActiveShell(event), Messages.ConnectionLayout_TimeoutTitle,
MessageFormat.format(Messages.ConnectionLayout_TimeoutMessage, e.getMessage()));
}
final var selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
final var part = HandlerUtil.getActiveEditor(event);

if (isSubappLayout(selection)) {
final var content = (UnfoldedSubappContentEditPart) selection.getFirstElement();
executeCommand(event, part, getLayoutCommand(content));
} else if (null != part) {
executeCommand(event, part, getLayoutCommandNonHierarchical(part));
}

return Status.OK_STATUS;
}

public static void executeManually(final IEditorPart part) {
final ConnectionLayoutMapping mapping = run(part);
final FordiacLayoutData data = ConnectionRoutingHelper.calculateConnections(mapping);
runSubapps(mapping, data);
new ConnectionLayoutCommand(data).execute();
public static Command getLayoutCommand(final IWorkbenchPart part) {
return getLayoutCommand(part, true);
}

public static Command getLayoutCommand(final UnfoldedSubappContentEditPart content) {
return getLayoutCommand(content, true);
}

public static Command getLayoutCommandNonHierarchical(final IWorkbenchPart part) {
return getLayoutCommand(part, false);
}

public static Command getLayoutCommandNonHierarchical(final UnfoldedSubappContentEditPart content) {
return getLayoutCommand(content, false);
}

private static Command getLayoutCommand(final Object obj, final boolean isHierarchical) {
try {
final var mapping = run(obj);
final var data = ConnectionRoutingHelper.calculateConnections(mapping);
if (isHierarchical) {
runSubapps(mapping, data);
}
return new ConnectionLayoutCommand(data);
} catch (final LibavoidServerException e) {
MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.ConnectionLayout_TimeoutTitle,
MessageFormat.format(Messages.ConnectionLayout_TimeoutMessage, e.getMessage()));
}
return UnexecutableCommand.INSTANCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,26 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Daniel Lindhuber
* - initial API and implementation and/or initial documentation
* Daniel Lindhuber - initial implementation and/or documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.elk.handlers;

import java.util.stream.Collectors;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.fordiac.ide.application.editparts.SubAppForFBNetworkEditPart;
import org.eclipse.fordiac.ide.elk.FordiacLayoutConnector;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.handlers.HandlerUtil;

public class NestedExpandedSubappHandler extends AbstractLayoutHandler {
public class ConnectionLayoutHandlerMule extends AbstractHandler {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final var selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
// @formatter:off
final var subapps = selection.stream()
.filter(SubAppForFBNetworkEditPart.class::isInstance)
.map(SubAppForFBNetworkEditPart.class::cast)
.filter(subapp -> subapp.getModel().isUnfolded())
.collect(Collectors.toList());
// @formatter:on
FordiacLayoutConnector.executeManually(subapps);
final var part = HandlerUtil.getActiveEditor(event);
final var mule = (Event) event.getTrigger();
mule.data = (part != null) ? ConnectionLayoutHandler.getLayoutCommandNonHierarchical(part)
: UnexecutableCommand.INSTANCE;
return Status.OK_STATUS;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Primetals Technologies Austria GmbH
* Copyright (c) 2021 - 2024 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,23 +13,32 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.elk.handlers;

import java.util.List;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.elk.core.service.DiagramLayoutEngine;
import org.eclipse.fordiac.ide.application.editparts.UnfoldedSubappContentEditPart;
import org.eclipse.fordiac.ide.elk.FordiacLayoutConnector;
import org.eclipse.fordiac.ide.elk.helpers.FordiacLayoutFactory;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

public class LayoutHandler extends AbstractLayoutHandler {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart part = HandlerUtil.getActiveEditor(event);
final var part = HandlerUtil.getActiveEditor(event);
final var selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);

if (null != part) {
if (isSubappLayout(selection)) {
final var content = (UnfoldedSubappContentEditPart) selection.getFirstElement();
FordiacLayoutConnector.executeManually(List.of(content.getParent()));
} else if (null != part) {
DiagramLayoutEngine.invokeLayout(part, null, FordiacLayoutFactory.createLayoutParams());
}

return Status.OK_STATUS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private static void handleSubappType(final FormEditor multiPageEditor, final Lib
final var breadcrumbEditor = multiPageEditor.getAdapter(AbstractBreadCrumbEditor.class);
multiPageEditor.setActiveEditor(breadcrumbEditor);
multiPageEditor.getAdapter(GraphicalViewer.class).flush();
ConnectionLayoutHandler.executeManually(multiPageEditor);
ConnectionLayoutHandler.getLayoutCommand(multiPageEditor).execute();

final List<EObject> elements = new ArrayList<>();
collectSubapps(elements, subappType.getFBNetwork());
Expand All @@ -300,7 +300,7 @@ private static void handleCompositeType(final FormEditor multiPageEditor, final
final var networkEditor = multiPageEditor.getAdapter(FBNetworkEditor.class);
multiPageEditor.setActiveEditor(networkEditor);
multiPageEditor.getAdapter(GraphicalViewer.class).flush();
ConnectionLayoutHandler.executeManually(multiPageEditor);
ConnectionLayoutHandler.getLayoutCommand(multiPageEditor).execute();

saveTypeEditor(multiPageEditor, typeEditable);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ private static void collectSubapps(final List<EObject> saveList, final FBNetwork
private static void layoutBreadcrumbEditor(final EObject refElement, final AbstractBreadCrumbEditor editor) {
editor.getBreadcrumb().setInput(refElement);
editor.getAdapter(GraphicalViewer.class).flush();
ConnectionLayoutHandler.executeManually(editor);
ConnectionLayoutHandler.getLayoutCommand(editor).execute();
}

private static EObject getBreadCrumbRefElement(final EObject sel) {
Expand Down
Loading
Loading