From 941eacda68ad7ce3578411cde2702445738cb925 Mon Sep 17 00:00:00 2001 From: Niklas Rentz Date: Wed, 13 Mar 2024 16:30:18 +0100 Subject: [PATCH] remove code duplications obsolete after Sprotty update --- .../klighd/lsp/KGraphDiagramServer.xtend | 185 ------------------ .../klighd/lsp/KGraphLayoutEngine.xtend | 23 ++- .../cs/kieler/klighd/lsp/model/Actions.xtend | 30 --- 3 files changed, 13 insertions(+), 225 deletions(-) diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphDiagramServer.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphDiagramServer.xtend index 5b9a9160d..514b381c8 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphDiagramServer.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphDiagramServer.xtend @@ -16,7 +16,6 @@ */ package de.cau.cs.kieler.klighd.lsp -import com.google.common.base.Strings import com.google.common.base.Throwables import com.google.common.io.ByteStreams import com.google.inject.Inject @@ -28,7 +27,6 @@ import de.cau.cs.kieler.klighd.ViewContext import de.cau.cs.kieler.klighd.kgraph.KNode import de.cau.cs.kieler.klighd.lsp.interactive.layered.LayeredInteractiveActionHandler import de.cau.cs.kieler.klighd.lsp.interactive.rectpacking.RectpackingInteractiveActionHandler -import de.cau.cs.kieler.klighd.lsp.launch.AbstractLanguageServer import de.cau.cs.kieler.klighd.lsp.model.CheckImagesAction import de.cau.cs.kieler.klighd.lsp.model.CheckedImagesAction import de.cau.cs.kieler.klighd.lsp.model.DisplayedActionUIData @@ -51,8 +49,6 @@ import java.util.Base64 import java.util.Collection import java.util.List import java.util.Map -import java.util.concurrent.CompletableFuture -import org.apache.log4j.Logger import org.eclipse.core.runtime.Platform import org.eclipse.elk.core.data.LayoutMetaDataService import org.eclipse.elk.core.data.LayoutOptionData @@ -68,10 +64,7 @@ import org.eclipse.sprotty.IDiagramSelectionListener import org.eclipse.sprotty.ILayoutEngine import org.eclipse.sprotty.IModelUpdateListener import org.eclipse.sprotty.IPopupModelFactory -import org.eclipse.sprotty.LayoutAction import org.eclipse.sprotty.RejectAction -import org.eclipse.sprotty.RequestBoundsAction -import org.eclipse.sprotty.RequestModelAction import org.eclipse.sprotty.SModelCloner import org.eclipse.sprotty.SModelElement import org.eclipse.sprotty.SModelRoot @@ -88,7 +81,6 @@ import org.eclipse.xtend.lib.annotations.Accessors * @author nre */ class KGraphDiagramServer extends LanguageAwareDiagramServer { - static val LOG = Logger.getLogger(KGraphDiagramServer) @Inject protected LayeredInteractiveActionHandler constraintActionHandler @@ -121,31 +113,6 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer { @Accessors(PUBLIC_GETTER) protected Object modelLock = new Object - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - protected String lastSubmittedModelType - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - protected int revision = 0 - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - new() { - currentRoot = new SModelRoot(); - currentRoot.setType("NONE"); - currentRoot.setId("ROOT"); - } - /** * Prepares the client side update of the model by processing the potentially needed images on the client. Checks * for client-side cached images with the {@link CheckImagesAction}. If the corresponding response to the @@ -269,149 +236,6 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer { notificationHandler.sendErrorAndThrow(e) } } - - /** - * Submit a new or updated model to the client. If client layout is required, a {@link RequestBoundsAction} - * is sent, otherwise either a {@link SetModelAction} or an {@link UpdateModelAction} is sent depending on - * the {@code update} parameter. - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override CompletableFuture submitModel(SModelRoot newRoot, boolean update, Action cause) { - if (needsClientLayout(newRoot)) { - if (!needsServerLayout(newRoot, cause)) { - // In this case the client won't send us the computed bounds - dispatch(new RequestBoundsAction(newRoot)); - val IModelUpdateListener listener = getModelUpdateListener(); - if (listener !== null) { - listener.modelSubmitted(newRoot, this); - } - } else { - return request(new RequestBoundsAction(newRoot)).handle([response, exception | { - if (exception !== null) { - LOG.error("RequestBoundsAction failed with an exception.", exception); - } else { - try { - var SModelRoot model = handle(response); - if (model !== null) - doSubmitModel(model, true, cause); - } catch (Exception exc) { - LOG.error("Exception while processing ComputedBoundsAction.", exc); - } - } - return null; - }]) - } - } else { - doSubmitModel(newRoot, update, cause); - } - return CompletableFuture.completedFuture(null); - } - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override CompletableFuture setModel(SModelRoot newRoot) { - if (newRoot === null) - throw new NullPointerException(); - synchronized(modelLock) { - newRoot.setRevision(revision + 1); - revision++ - currentRoot = newRoot; - } - return submitModel(newRoot, false, null); - } - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override CompletableFuture updateModel(SModelRoot newRoot) { - if (newRoot === null) - throw new IllegalArgumentException("updateModel() cannot be called with null"); - synchronized(modelLock) { - currentRoot = newRoot; - newRoot.setRevision(revision + 1); - revision++ - } - return submitModel(newRoot, true, null); - } - - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - def void doSubmitModel(SModelRoot newRoot, boolean update, Action cause) { - val ILayoutEngine layoutEngine = getLayoutEngine(); - if (needsServerLayout(newRoot, cause)) { - AbstractLanguageServer.addToMainThreadQueue([ - layoutEngine.layout(newRoot, cause) - ]) - } - synchronized (modelLock) { - if (newRoot.getRevision() == revision) { - var String modelType = newRoot.getType(); - if (cause instanceof RequestModelAction - && !Strings.isNullOrEmpty((cause as RequestModelAction).getRequestId())) { - var RequestModelAction request = cause as RequestModelAction; - var SetModelAction response = new SetModelAction(newRoot); - response.setResponseId(request.getRequestId()); - dispatch(response); - } else if (update && modelType !== null && modelType.equals(lastSubmittedModelType)) { - dispatch(new UpdateModelAction(newRoot)); - } else { - dispatch(new SetModelAction(newRoot)); - } - lastSubmittedModelType = modelType; - var IModelUpdateListener listener = getModelUpdateListener(); - if (listener !== null) { - listener.modelSubmitted(newRoot, this); - } - } - } - } - - /** - * Taken from {@code DefaultDiagramServer.handle(RequestModelAction)} to use this getModel. - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override protected handle(RequestModelAction request) { - if (diagramLanguageServer !== null) { - copyOptions(request) - diagramLanguageServer.diagramUpdater.updateDiagram(this, request) - } else { - super.handle(request) - } - } - - /** - * Taken from {@code DefaultDiagramServer.handle(LayoutAction)} to use this getModel. - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override void handle(LayoutAction action) { - if (needsServerLayout(model,action)) { - // Clone the current model, as it has already been sent to the client with the old revision - val SModelCloner cloner = getSModelCloner(); - val SModelRoot newRoot = cloner.clone(model); - synchronized(modelLock) { - newRoot.setRevision(revision + 1); - revision++ - currentRoot = newRoot; - } - // the actual layout is performed in doSubmitModel - doSubmitModel(newRoot, true, action); - } - } /** * Called when a {@link PerformActionAction} is received. @@ -632,15 +456,6 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer { } newModel = false } - - /** - * Needed for KeithUpdateModelAction - * - * FIXME Remove this if UpdateModelAction has a cause. - */ - override SModelRoot getModel() { - return currentRoot; - } // Repeat injection of multiple methods of the DefaultDiagramServer as the javax.inject->jakarta.inject transition // broke something here. diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphLayoutEngine.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphLayoutEngine.xtend index 68be39e76..ff598dc4e 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphLayoutEngine.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/KGraphLayoutEngine.xtend @@ -3,7 +3,7 @@ * * http://rtsys.informatik.uni-kiel.de/kieler * - * Copyright 2018-2023 by + * Copyright 2018-2024 by * + Kiel University * + Department of Computer Science * + Real-Time and Embedded Systems Group @@ -18,6 +18,7 @@ package de.cau.cs.kieler.klighd.lsp import com.google.inject.Inject import de.cau.cs.kieler.klighd.LightDiagramLayoutConfig +import de.cau.cs.kieler.klighd.lsp.launch.AbstractLanguageServer import de.cau.cs.kieler.klighd.lsp.utils.KGraphMappingUtil import de.cau.cs.kieler.klighd.lsp.utils.RenderingPreparer import java.io.ByteArrayOutputStream @@ -48,16 +49,18 @@ class KGraphLayoutEngine extends ElkLayoutEngine { public static val LOG = Logger.getLogger(KGraphLayoutEngine) override layout(SModelRoot root, Action cause) { - synchronized (diagramState) { - if (root instanceof SGraph) { - // The layout is executed on the KGraph, not the SGraph. So get the KGraph belonging to this SGraph from - // the KGraphContext. - onlyLayoutOnKGraph(root.id) - - // map layouted KGraph to SGraph - KGraphMappingUtil.mapLayout(diagramState.getKGraphToSModelElementMap(root.id)) + AbstractLanguageServer.addToMainThreadQueue([ + synchronized (diagramState) { + if (root instanceof SGraph) { + // The layout is executed on the KGraph, not the SGraph. So get the KGraph belonging to this SGraph from + // the KGraphContext. + onlyLayoutOnKGraph(root.id) + + // map layouted KGraph to SGraph + KGraphMappingUtil.mapLayout(diagramState.getKGraphToSModelElementMap(root.id)) + } } - } + ]) } /** diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/model/Actions.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/model/Actions.xtend index 75aa467b6..6682e4dbd 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/model/Actions.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/model/Actions.xtend @@ -239,36 +239,6 @@ class RefreshLayoutAction implements Action { } } -/** - * Updates the model and sends the cause to the client. - * Extends to UpdateModelAction. - * FIXME Remove this if the UpdateModelAction includes a cause. - * - * @author sdo - */ -@Accessors -@EqualsHashCode -@ToString(skipNulls = true) -public class KeithUpdateModelAction extends UpdateModelAction { - public static val KIND = 'updateModel' - String kind = KIND - - - SModelRoot newRoot - Boolean animate - Action cause - - new() {} - new(Consumer initializer) { - initializer.accept(this) - } - - new(SModelRoot newRoot, Action cause) { - this.newRoot = newRoot - this.cause = cause - } -} - /** * Sent from client to request a certain piece of the diagram. *