Replies: 3 comments 5 replies
-
I have updated the server-side
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="tasklistgraph" nsURI="http://www.eclipse.org/glsp/examples/tasklist/graph"
nsPrefix="tasklistgraph">
<eClassifiers xsi:type="ecore:EClass" name="WeightedTransition" eSuperTypes="glsp-graph.ecore#//GEdge">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="weight" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
</eClassifiers>
</ecore:EPackage>
public static class TransitionEdgeBuilder extends AbstractGEdgeBuilder<WeightedTransition, TransitionEdgeBuilder> {
...
public TransitionEdgeBuilder() {
super(TaskListModelTypes.WEIGHTED_TRANSITION);
// defined in TaskListModelTypes
// public static final String WEIGHTED_TRANSITION = "edge:weighted";
}
... updated protected GEdge createTransitionEdge(final Transition transition, final GGraph graph) {
String sourceId = transition.getSource().getId();
String targetId = transition.getTarget().getId();
GModelElement sourceNode = findGNodeById(graph.getChildren(), sourceId);
GModelElement targetNode = findGNodeById(graph.getChildren(), targetId);
TransitionEdgeBuilder transitionEdgeBuilder = new TransitionEdgeBuilder().source(sourceNode)
.target(targetNode)
.setWeight(0.5)
.id(idGenerator.getOrCreateId(transition));
applyEdgeData(transition, transitionEdgeBuilder);
return transitionEdgeBuilder.build();
}
private TransitionEdgeBuilder applyEdgeData(final EObject edgeElement, final TransitionEdgeBuilder builder) {
// TODO Auto-generated method stub
modelState.getIndex().getNotation(edgeElement, Edge.class)
.ifPresent(edge -> applyEdgeData(edge, builder));
return builder;
}
private static TransitionEdgeBuilder applyEdgeData(final Edge edge, final TransitionEdgeBuilder builder) {
if (edge.getBendPoints() != null) {
edge.getBendPoints().stream().map(GraphUtil::copy).forEachOrdered(builder::addRoutingPoint);
}
return builder;
} Registered client-sideconst tasklistDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => {
...
configureModelElement(context, 'edge:weighted', WeightedTransition, WeightedTransitionView);
}); Am I on the right path? What else needs to be updated? |
Beta Was this translation helpful? Give feedback.
-
Hi @ipa-hsd, In order to edit properties you will need a few things working together:
In the workflow example, we use two different ways to approach editing: You can edit the name directly on the label by double clicking it (using the generic label edit functionality) and you can edit properties of a task by right clicking a task and selecting "Direct Edit Task" (TaskEditor on the client, ApplyTaskEditOperationHandler on the server). Please note that currently there is no way to directly edit the weight of weighted edges but you could follow a similar approach as outlined before. Alternatively, you can also use an "external" UI such as a properties view or a tree view as done in the coffee editor example (online demonstration). On the server side you need a handler that handles the operation that you just sent. For the EMF case, the basic idea is that we do not manipulate the GModel directly (as, for instance, the generic label editing handler does) but instead we manipulate our EMF resources (semantic + notation) using EMF commands. After the operation is executed, the EMF resources are translated into a GModel using the GModelFactory where any properties that are stored in the EMF models can be translated into GModel elements or properties. For the task list example, there are two handlers for creation and deletion. Regarding the translation from EMF resources to the GModel we generically only apply basic shape data for nodes and translate bend points into routing points for edges. So for your use case that means that you should extend your EMF model with the weight property (e.g., Transition in the model.ecore in the example) and adapt the translation from the EMF model to the GModel to consider the new property. How you translate the weight really depends on your use case. If you use the label editing mechanism you probably will create a GLabel but if use another approach maybe simply adding an argument to the generic args map of an GEdge may be sufficient. After you configure the respective rendering on the client side you already have a static support for the weight property. For editing you then need to create an operation and operation handler. The handler will use the data to find the correct EMF model element from the index and apply an EMF command on it that adapts the weight. If the GModelFactory was already rendering the weight property correctly before nothing more needs to be done. |
Beta Was this translation helpful? Give feedback.
-
@ipa-hsd I can reproduce the problem and it seems to be a version conflict indeed. The current minimal-example uses Theia 1.20.0 but if you specify the dependency of "^1.0.0" you allow much newer versions of that package as well (+ all their dependencies), so there might be some Theia dependencies that are included several times in different versions (once in 1.20.0 and once in the latest version) causing the mismatch. You might even see warnings like:
If you specify the matching version of "1.20.0" for the property-view, I believe it should work. |
Beta Was this translation helpful? Give feedback.
-
If my source model is Ecore based, do I need to update the notation model as well similar to the graph model to add properties to the edges? I want to add properties (a struct) to my edge. Once I make a connection between source and target, how do I edit these properties?
Also, in the workflow example, how do I edit the edge properties to change the probability?
Beta Was this translation helpful? Give feedback.
All reactions