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

Commit

Permalink
Refactor GModelFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Ebel committed Jan 9, 2020
1 parent 3d3ec3c commit 173f826
Showing 1 changed file with 55 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.eclipsesource.glsp.ecore.util.EcoreConfig.Types;
import com.eclipsesource.glsp.graph.GEdge;
import com.eclipsesource.glsp.graph.GGraph;
import com.eclipsesource.glsp.graph.GLabel;
import com.eclipsesource.glsp.graph.GModelElement;
import com.eclipsesource.glsp.graph.GModelRoot;
import com.eclipsesource.glsp.graph.builder.impl.GEdgeBuilder;
Expand Down Expand Up @@ -105,113 +106,81 @@ private List<GModelElement> createEdges(EClass eClass) {
}

public GEdge create(EReference eReference) {
String labelMultiplicity = String.format("[%s..%s]", eReference.getLowerBound(),
eReference.getUpperBound() == -1 ? "*" : eReference.getUpperBound());
String labelName = eReference.getName();

String source = toId(eReference.getEContainingClass());

String target = toId(eReference.getEReferenceType());
String id = toId(eReference);

GEdgeBuilder builder = new GEdgeBuilder()
.id(id) //
.addCssClass(CSS.ECORE_EDGE) //
.addCssClass(eReference.isContainment() ? CSS.COMPOSITION : null) //
.sourceId(source) //
.targetId(target) //
.routerKind(GConstants.RouterKind.MANHATTAN);

if (eReference.getEOpposite() != null) {
return createBidirectionalEdge(eReference, source, target);
return createBidirectionalEdge(eReference, builder);
}

String id = toId(eReference);
return new GEdgeBuilder().type( eReference.isContainment() ? Types.COMPOSITION : Types.REFERENCE) //
.id(id) //
.addCssClass(CSS.ECORE_EDGE) //
.addCssClass(eReference.isContainment() ? CSS.COMPOSITION : null) //
.add(new GLabelBuilder(Types.LABEL_EDGE_MULTIPLICITY) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.BOTTOM)//
.position(0.5d)//
.offset(2d) //
.rotate(false) //
.build())//
.id(id + "_label_multiplicity") //
.text(labelMultiplicity).build())
.add(new GLabelBuilder(Types.LABEL_EDGE_NAME) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.TOP)//
.position(0.5d)//
.offset(2d) //
.rotate(false) //
.build())//
.id(id + "_label_name") //
.text(labelName).build())
.sourceId(source) //
.targetId(target) //
.routerKind(GConstants.RouterKind.MANHATTAN)//
String labelMultiplicity = createMultiplicity(eReference);
String labelName = eReference.getName();
return builder
.type(eReference.isContainment() ? Types.COMPOSITION : Types.REFERENCE) //
.add(createEdgeMultiplicityLabel(labelMultiplicity, id + "_label_multiplicity", 0.5d))
.add(createEdgeNameLabel(labelName, id + "_label_name", 0.5d))
.build();
}

private GEdge createBidirectionalEdge(EReference eReference, String source, String target) {
private GEdge createBidirectionalEdge(EReference eReference, GEdgeBuilder builder) {
Set<Integer> referenceSet = this.modelState.getIndex().getBidirectionalReferences();
if(!eReference.isContainment() && referenceSet.contains(eReference.getEOpposite().hashCode())) {

if (!eReference.isContainment() && referenceSet.contains(eReference.getEOpposite().hashCode())) {
return null;
}

referenceSet.add(eReference.hashCode());


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


String sourceLabelMultiplicity = String.format("[%s..%s]", eReference.getLowerBound(),
eReference.getUpperBound() == -1 ? "*" : eReference.getUpperBound());
String sourceLabelMultiplicity = createMultiplicity(eReference);
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_MULTIPLICITY) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(GConstants.EdgeSide.BOTTOM)//
.position(0.1d)//
.offset(2d) //
.rotate(false) //
.build())//
.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(2d) //
.rotate(false) //
.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)//

return builder
.type(eReference.isContainment() ? Types.BIDIRECTIONAL_COMPOSITION : Types.BIDIRECTIONAL_REFERENCE) //
.add(createEdgeMultiplicityLabel(sourceLabelMultiplicity, sourceId + "_sourcelabel_multiplicity", 0.1d))//
.add(createEdgeNameLabel(sourceLabelName, sourceId + "_sourcelabel_name", 0.1d))//
.add(createEdgeMultiplicityLabel(targetLabelMultiplicity, targetId + "_targetlabel_multiplicity", 0.9d))//
.add(createEdgeNameLabel(targetLabelName, targetId + "_targetlabel_name", 0.9d))//
.build();
}

private String createMultiplicity(EReference eReference) {
return String.format("[%s..%s]", eReference.getLowerBound(),
eReference.getUpperBound() == -1 ? "*" : eReference.getUpperBound());
}

private GLabel createEdgeMultiplicityLabel(String value, String id, double position) {
return createEdgeLabel(value, position, id, Types.LABEL_EDGE_MULTIPLICITY, GConstants.EdgeSide.BOTTOM);
}

private GLabel createEdgeNameLabel(String name, String id, double position) {
return createEdgeLabel(name, position, id, Types.LABEL_EDGE_NAME, GConstants.EdgeSide.TOP);
}

private GLabel createEdgeLabel(String name, double position, String id, String type, String side) {
return new GLabelBuilder(type) //
.edgePlacement(new GEdgePlacementBuilder()//
.side(side)//
.position(position)//
.offset(2d) //
.rotate(false) //
.build())//
.id(id) //
.text(name).build();
}

public GEdge create(EClass baseClass, EClass superClass) {
String sourceId = toId(baseClass);
Expand Down

0 comments on commit 173f826

Please sign in to comment.