Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
Adapt for label editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Ebel committed Jan 9, 2020
1 parent 53c312f commit 3d3ec3c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,59 @@ private GEdge createBidirectionalEdge(EReference eReference, String source, Stri
}

referenceSet.add(eReference.hashCode());
String targetLabel = String.format("[%s..%s] %s", eReference.getEOpposite().getLowerBound(),
eReference.getEOpposite().getUpperBound() == -1 ? "*" :
eReference.getEOpposite().getUpperBound(), eReference.getEOpposite().getName());

String sourceLabel = String.format("[%s..%s] %s", eReference.getLowerBound(),
eReference.getUpperBound() == -1 ? "*" : eReference.getUpperBound(), eReference.getName());

String targetLabelMultiplicity = String.format("[%s..%s]", eReference.getEOpposite().getLowerBound(),
eReference.getEOpposite().getUpperBound() == -1 ? "*" : eReference.getEOpposite().getUpperBound());
String targetLabelName = eReference.getEOpposite().getName();
String targetId = toId(eReference.getEOpposite());


String sourceLabelMultiplicity = String.format("[%s..%s]", eReference.getLowerBound(),
eReference.getUpperBound() == -1 ? "*" : eReference.getUpperBound());
String sourceLabelName = eReference.getName();
String sourceId = toId(eReference);

return new GEdgeBuilder().type(eReference.isContainment() ? Types.BIDIRECTIONAL_COMPOSITION : Types.BIDIRECTIONAL_REFERENCE) //
.id(toId(eReference)) //
.addCssClass(CSS.ECORE_EDGE) //
.addCssClass(eReference.isContainment() ? CSS.COMPOSITION : null) //
.add(new GLabelBuilder(Types.LABEL_EDGE) //
.add(new GLabelBuilder(Types.LABEL_EDGE_MULTIPLICITY) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.BOTTOM)//
.position(0.1d)//
.offset(1) //
.offset(2d) //
.rotate(false) //
.build())//
.id(toId(eReference) + "_sourcelabel") //
.text(sourceLabel).build())
.add(new GLabelBuilder(Types.LABEL_EDGE) //
.id(sourceId + "_sourcelabel_multiplicity") //
.text(sourceLabelMultiplicity).build())
.add(new GLabelBuilder(Types.LABEL_EDGE_NAME) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.TOP)//
.position(0.1d)//
.offset(2d) //
.rotate(false) //
.build())//
.id(sourceId + "_sourcelabel_name") //
.text(sourceLabelName).build())
.add(new GLabelBuilder(Types.LABEL_EDGE_MULTIPLICITY) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.BOTTOM)//
.position(0.9d)//
.offset(0) //
.offset(2d) //
.rotate(false) //
.build())//
.id(toId(eReference) + "_targetlabel") //
.text(targetLabel).build())
.id(targetId + "_targetlabel_multiplicity") //
.text(targetLabelMultiplicity).build())
.add(new GLabelBuilder(Types.LABEL_EDGE_NAME) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.TOP)//
.position(0.9d)//
.offset(2d) //
.rotate(false) //
.build())//
.id(targetId + "_targetlabel_name") //
.text(targetLabelName).build())//
.sourceId(source) //
.targetId(target) //
.routerKind(GConstants.RouterKind.MANHATTAN)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ public void execute(AbstractOperationAction action, GraphicalModelState graphica
break;

case Types.LABEL_EDGE_NAME:
GEdge edge = getOrThrow(index.findElementByClass(editLabelAction.getLabelId(), GEdge.class),
"No edge for label with id " + editLabelAction.getLabelId() + " found");
EReference reference_semantic = (EReference) getOrThrow(index.getSemantic(edge),
"No semantic element for labelContainer with id " + edge.getId() + " found");
String edgeId = editLabelAction.getLabelId().split("_")[0];
EReference reference_semantic = (EReference) getOrThrow(
index.getSemantic(edgeId),
"No semantic element for labelContainer with id " + edgeId + " found");
reference_semantic.setName(editLabelAction.getText().trim());
break;

case Types.LABEL_EDGE_MULTIPLICITY:
edge = getOrThrow(index.findElementByClass(editLabelAction.getLabelId(), GEdge.class),
"No edge for label with id " + editLabelAction.getLabelId() + " found");
reference_semantic = (EReference) getOrThrow(index.getSemantic(edge),
"No semantic element for labelContainer with id " + edge.getId() + " found");
edgeId = editLabelAction.getLabelId().split("_")[0];
reference_semantic = (EReference) getOrThrow(
index.getSemantic(edgeId),
"No semantic element for labelContainer with id " + edgeId + " found");
Pattern pattern = Pattern.compile("\\s*\\[\\s*(\\d+)\\s*\\.+\\s*(\\*|\\d+|\\-1)\\s*\\]\\s*");
Matcher matcher = pattern.matcher(editLabelAction.getText());
if (matcher.matches()) {
Expand Down

0 comments on commit 3d3ec3c

Please sign in to comment.