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

Google maps for models #80

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
0a44314
ui.view: Added null-checks to prevent NPE due to unconfigured child VCs
a-sr Oct 26, 2020
d19e882
lsp: diagram options predefined by the client are sent during
NiklasRentzCAU Oct 29, 2020
51f6da6
lsp: changed diagram-options from request-by-client to notify-by-server
NiklasRentzCAU Nov 3, 2020
adbde92
Merge remote-tracking branch 'origin/master' into nre/implementation
NiklasRentzCAU Nov 3, 2020
f5a3e70
lsp: changed image check messages to request/response messages. Only
NiklasRentzCAU Nov 5, 2020
3298223
lsp: synchronized option category state does not cause diagram update.
NiklasRentzCAU Nov 6, 2020
47ee096
lsp: removed possibility of ID collisions during text graph generation
NiklasRentzCAU Nov 6, 2020
fa15e91
lsp: Fixed handling of special placements of root renderings.
NiklasRentzCAU Nov 6, 2020
7f996bf
Changed default status handling to 'log'. (#76)
NiklasRentzCAU Nov 10, 2020
0414d8e
Merge branch 'master' into nre/lsp-diagramoptions
NiklasRentzCAU Nov 10, 2020
6160a17
lsp: forward status manager messages to the client.
NiklasRentzCAU Nov 12, 2020
c53a87f
lsp: moved static method from interface to class to fix maven build.
NiklasRentzCAU Nov 12, 2020
57f0657
lsp: escaped strings for HTML contain markdown-style newlines ('\'+'\n')
NiklasRentzCAU Nov 17, 2020
93b8246
Merge pull request #77 from kieler/nre/lsp-diagramoptions
NiklasRentzCAU Nov 17, 2020
6491287
fixed update site p2.index to include content.xml.xz
NiklasRentzCAU Mar 5, 2021
83c1bde
Add node title property to KTexts
Trayan7 Mar 12, 2021
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 1
metadata.repository.factory.order = content.xml,\!
artifact.repository.factory.order = artifacts.xml,\!
metadata.repository.factory.order = content.xml.xz,content.xml,\!
artifact.repository.factory.order = artifacts.xml.xz,artifacts.xml,\!

Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ import org.eclipse.lsp4j.jsonrpc.services.JsonSegment
@JsonSegment('keith/diagramOptions')
interface IDiagramOptionsLanguageServerExtension {

/**
* Method called by a client to get all options to modify a diagram via the sidebar. This includes all
* {@link ValuedSynthesisOption}s, all layout options, and the actions defined in an {@link IDiagramSynthesis}
* to be shown to the user.
*
* @param param Defines the {@code param.path} to the source model of that diagram.
* @return All synthesis options, layout options with their current values, and the actions if the diagram for
* {@code param.path} is opened, {@code null} otherwise.
*/
@JsonRequest('getOptions')
def CompletableFuture<GetOptionsResult> getOptions(GetOptionsParam param)

/**
* Method called by a client to set the {@link SynthesisOption}s of the diagram resolved by {@code param.uri} to
* the options given in {@code param.synthesisOptions}. Also updates the diagram.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import de.cau.cs.kieler.klighd.krendering.KRendering
import de.cau.cs.kieler.klighd.krendering.KRenderingLibrary
import de.cau.cs.kieler.klighd.krendering.KRenderingUtil
import de.cau.cs.kieler.klighd.krendering.KText
import de.cau.cs.kieler.klighd.lsp.model.ImageData
import de.cau.cs.kieler.klighd.lsp.model.SKEdge
import de.cau.cs.kieler.klighd.lsp.model.SKGraph
import de.cau.cs.kieler.klighd.lsp.model.SKLabel
Expand All @@ -43,6 +44,7 @@ import de.cau.cs.kieler.klighd.util.KlighdProperties
import de.cau.cs.kieler.klighd.util.RenderingContextData
import java.util.ArrayList
import java.util.HashMap
import java.util.HashSet
import java.util.List
import java.util.Map
import org.apache.log4j.Logger
Expand Down Expand Up @@ -108,10 +110,10 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
var Map<String, KText> textMapping

/**
* The {@link KImage}s contained in the view model.
* The data of all {@link KImage}s contained in the view model.
*/
@Accessors(PUBLIC_GETTER)
var List<KImage> images
var HashSet<ImageData> images

/**
* The root node of the translated {@link SGraph}.
Expand Down Expand Up @@ -177,7 +179,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
kGraphToSModelElementMap = new HashMap
textMapping = new HashMap
modelLabels = new ArrayList
images = new ArrayList
images = new HashSet
idGen = new KGraphElementIdGenerator
edgesToGenerate = new ArrayList

Expand Down Expand Up @@ -544,7 +546,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
*/
private def void findSpecialRenderings(KGraphData data) {
val List<SKLabel> dataLabels = newArrayList
var KImage dataImage = null
var ImageData imageData = null
if (data instanceof KText) {
// create a new Label with data as its text for each line in the original text.
// KTexts in Labels have their texts stored inside their ancestor KLabel, not in the KText itself
Expand Down Expand Up @@ -590,7 +592,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
} else if (data instanceof KContainerRendering) {
// KImages are container renderings themselves, so also look for their child renderings.
if (data instanceof KImage) {
dataImage = data
imageData = ImageData.of(data)
}

for (childData: data.children) {
Expand All @@ -606,8 +608,8 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
if (!dataLabels.empty) {
modelLabels.addAll(dataLabels)
}
if (dataImage !== null) {
images.add(dataImage)
if (imageData !== null) {
images.add(imageData)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2018,2019 by
* Copyright 2018,2020 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -21,6 +21,7 @@ import de.cau.cs.kieler.klighd.IAction
import de.cau.cs.kieler.klighd.IAction.ActionContext
import de.cau.cs.kieler.klighd.Klighd
import de.cau.cs.kieler.klighd.KlighdDataManager
import de.cau.cs.kieler.klighd.ViewContext
import de.cau.cs.kieler.klighd.kgraph.KLabel
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.krendering.KRendering
Expand All @@ -31,13 +32,16 @@ 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.ComputedTextBoundsAction
import de.cau.cs.kieler.klighd.lsp.model.LayoutOptionUIData
import de.cau.cs.kieler.klighd.lsp.model.PerformActionAction
import de.cau.cs.kieler.klighd.lsp.model.RefreshDiagramAction
import de.cau.cs.kieler.klighd.lsp.model.RefreshLayoutAction
import de.cau.cs.kieler.klighd.lsp.model.RequestTextBoundsAction
import de.cau.cs.kieler.klighd.lsp.model.SKGraph
import de.cau.cs.kieler.klighd.lsp.model.SetSynthesisAction
import de.cau.cs.kieler.klighd.lsp.model.StoreImagesAction
import de.cau.cs.kieler.klighd.lsp.model.UpdateDiagramOptionsAction
import de.cau.cs.kieler.klighd.lsp.model.ValuedSynthesisOption
import de.cau.cs.kieler.klighd.lsp.utils.KRenderingIdGenerator
import de.cau.cs.kieler.klighd.lsp.utils.SprottyProperties
import de.cau.cs.kieler.klighd.microlayout.Bounds
Expand All @@ -46,11 +50,16 @@ import java.io.FileNotFoundException
import java.io.InputStream
import java.util.ArrayList
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
import org.eclipse.elk.core.data.LayoutOptionData.Visibility
import org.eclipse.elk.graph.properties.IProperty
import org.eclipse.emf.ecore.EObject
import org.eclipse.sprotty.Action
import org.eclipse.sprotty.ActionMessage
Expand Down Expand Up @@ -144,6 +153,7 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer {
* for client-side cached images with the {@link CheckImagesAction}. If the corresponding response to the
* {@link CheckImagesAction} requires images to be sent, a {@link SendImagesAction} is sent first. After receiving
* the result back, updates the model with default Sprotty behavior via the {@link #updateModel} function.
* Also handles updating the diagram options on the client.
*
* @param newRoot the diagram to request the text sizes for.
*/
Expand All @@ -167,15 +177,18 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer {
}

// image handling
val images = diagramState.getImages(newRoot.id)
if (images === null) {
val imageData = diagramState.getImageData(newRoot.id)
if (imageData === null) {
throw new NullPointerException("The id of the SGraph was not found in the diagramState")
} else if (images.empty) {
} else if (imageData.empty) {
imagesUpdated = true
} else {
dispatch(new CheckImagesAction(images))
dispatch(new CheckImagesAction(imageData))
// the setOrUpdateModel is then executed after the client confirms it has all images cached.
}

// Update the diagram options with the current used values on the client.
updateDiagramOptions(newRoot.id)
} else {
setOrUpdateModel
}
Expand All @@ -186,6 +199,61 @@ class KGraphDiagramServer extends LanguageAwareDiagramServer {
}
}

/**
* Updates the diagram options on the client with the values from the currently used view context found under the
* given URI.
*
* @param uri The URI of the model to take the options from.
*/
def void updateDiagramOptions(String uri) {
synchronized (diagramState) {
val ViewContext viewContext = diagramState.getKGraphContext(uri)
if (viewContext !== null) {
val synthesisOptions = new ArrayList<ValuedSynthesisOption>
for (option : viewContext.displayedSynthesisOptions) {
var currentValue = viewContext.getOptionValue(option)
if (currentValue instanceof Enum) {
currentValue = currentValue.toString
}
synthesisOptions.add(new ValuedSynthesisOption(option, currentValue))
}
val layoutOptionUIData = calculateLayoutOptionUIData(viewContext.displayedLayoutOptions)
val actionData = viewContext.displayedActions
dispatch(new UpdateDiagramOptionsAction(synthesisOptions, layoutOptionUIData, actionData, uri))
}
}
}

/**
* Packs all data needed to display the layout options in any user interface into a single list of
* {@link LayoutOptionUIData}.
*
* @param displayedLayoutOptions The layout options that should be displayed.
*/
def calculateLayoutOptionUIData(List<org.eclipse.elk.core.util.Pair<IProperty<?>, List<?>>> displayedLayoutOptions) {
val List<LayoutOptionUIData> layoutOptionUIData = new ArrayList
for (pair : displayedLayoutOptions) {
var Object first
var Object second
if (pair.second instanceof Collection) {
val iterator = (pair.second as Collection<?>).iterator
first = if (iterator.hasNext) iterator.next else null
second = if (iterator.hasNext) iterator.next else null
}

val LayoutOptionData optionData = LayoutMetaDataService.instance.getOptionData(pair.first.id)
if (optionData.visibility !== Visibility.HIDDEN) {
if (first instanceof Number && second instanceof Number) {
layoutOptionUIData.add(new LayoutOptionUIData(optionData, (first as Number).floatValue,
(second as Number).floatValue, null))
} else {
layoutOptionUIData.add(new LayoutOptionUIData(optionData, null, null, pair.second))
}
}
}
return layoutOptionUIData
}

override void accept(ActionMessage message) {
try {
val clientId = getClientId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2018,2019 by
* Copyright 2018,2020 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -12,6 +12,7 @@
*/
package de.cau.cs.kieler.klighd.lsp

import com.google.gson.JsonElement
import com.google.inject.Singleton
import de.cau.cs.kieler.klighd.IViewer
import de.cau.cs.kieler.klighd.SynthesisOption
Expand All @@ -20,6 +21,7 @@ import de.cau.cs.kieler.klighd.internal.ISynthesis
import de.cau.cs.kieler.klighd.kgraph.KGraphElement
import de.cau.cs.kieler.klighd.krendering.KImage
import de.cau.cs.kieler.klighd.krendering.KText
import de.cau.cs.kieler.klighd.lsp.model.ImageData
import de.cau.cs.kieler.klighd.lsp.model.SKLabel
import java.net.URLDecoder
import java.util.HashMap
Expand Down Expand Up @@ -57,10 +59,10 @@ class KGraphDiagramState {
Map<String, Map<String, KGraphElement>> idToKGraphElementMap = new HashMap

/**
* A list containing all {@link KImage}s from the source KGraph.
* A set containing the image data for all {@link KImage}s from the source KGraph.
* Mapped by the URI this map belongs to.
*/
Map<String, List<KImage>> images = new HashMap
Map<String, Set<ImageData>> imageData = new HashMap

/**
* A list containing all texts from the source KGraph in Sprotty labels.
Expand Down Expand Up @@ -104,6 +106,11 @@ class KGraphDiagramState {
*/
Map<SynthesisOption, Object> recentSynthesisOptions = new HashMap

/**
* The options predefined by the client that should be used during syntheses and layout.
*/
JsonElement clientOptions

/**
* A map to map the Sprotty client id to the URI leading to the resource.
*/
Expand Down Expand Up @@ -169,22 +176,22 @@ class KGraphDiagramState {
}

/**
* Getter to access the value stored in the images map.
* Getter to access the value stored in the imageData map.
*
* @param uri The identifying URI of the graph to access the value in the map.
*/
def List<KImage> getImages(String uri) {
images.get(uri)
def Set<ImageData> getImageData(String uri) {
imageData.get(uri)
}

/**
* Put method to put a new value in the images map.
* Put method to put a new value in the imageData map.
*
* @param uri The identifying URI of the graph to access the map.
* @param value The value to be stored in the map.
*/
def putImages(String uri, List<KImage> value) {
images.put(uri, value)
def putImageData(String uri, Set<ImageData> value) {
imageData.put(uri, value)
}

/**
Expand Down Expand Up @@ -337,7 +344,21 @@ class KGraphDiagramState {
}

/**
* Add an option with its current value to the recently used options to be retreivable later via
* Sets the options defined by the client.
*/
def setClientOptions(JsonElement clientOptions) {
this.clientOptions = clientOptions
}

/**
* Returns all options defined by the client.
*/
def getClientOptions() {
return clientOptions
}

/**
* Add an option with its current value to the recently used options to be retrievable later via
* {@link #getRecentSynthesisOptions()}.
*/
def addRecentSynthesisOption(SynthesisOption option, Object value) {
Expand Down
Loading