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

Commit

Permalink
Add Datatype to server's nodeTypeHints and Add Instance Type Editing …
Browse files Browse the repository at this point in the history
…of EdataType

Signed-off-by: Jonas Ebel <[email protected]>
  • Loading branch information
Jonas Ebel authored and eneufeld committed Jan 16, 2020
1 parent 37bc38d commit 2ac0473
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
17 changes: 16 additions & 1 deletion client/sprotty-ecore/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,21 @@ import { Container, ContainerModule } from "inversify";
import {EditLabelUIAutocomplete} from "./features/edit-label-autocomplete";
import { EditLabelUI } from "sprotty/lib";
import { LabelSelectionFeedback } from "./feedback";
import {ArrowEdge, CompositionEdge, InheritanceEdge, LabeledNode, SEditableLabel, IconDataType, IconEnum, IconInterface, IconAbstract, IconClass, SLabelNodeAttribute, SLabelNodeLiteral} from "./model";
import {
ArrowEdge,
CompositionEdge,
InheritanceEdge,
LabeledNode,
SEditableLabel,
IconDataType,
IconEnum,
IconInterface,
IconAbstract,
IconClass,
SLabelNodeAttribute,
SLabelNodeLiteral,
SLabelNode
} from "./model";
import { ArrowEdgeView, ClassNodeView, CompositionEdgeView, IconView, InheritanceEdgeView, LabelNodeView } from "./views";

export default (containerId: string) => {
Expand All @@ -89,6 +103,7 @@ export default (containerId: string) => {
configureModelElement(context, 'label:name', SEditableLabel, SLabelView);
configureModelElement(context, 'label:edge-name', SEditableLabel, SLabelView);
configureModelElement(context, 'label:edge-multiplicity', SEditableLabel, SLabelView);
configureModelElement(context, 'label:instancename', SLabelNode, LabelNodeView);
configureModelElement(context, 'node:attribute', SLabelNodeAttribute, LabelNodeView);
configureModelElement(context, 'node:enumliteral', SLabelNodeLiteral, LabelNodeView);
configureModelElement(context, 'node:operation', SNode, RectangularNodeView);
Expand Down
9 changes: 6 additions & 3 deletions client/sprotty-ecore/src/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,19 @@ export class AggregationEdgeView extends DiamondEdgeView {
@injectable()
export class LabelNodeView extends SLabelView {
render(labelNode: Readonly<SLabelNode>, context: RenderingContext): VNode {
const image = require("../images/" + labelNode.imageName);
let image;
if (labelNode.imageName) {
image = require("../images/" + labelNode.imageName);
}

const vnode = (
<g
class-selected={labelNode.selected}
class-mouseover={labelNode.hoverFeedback}
class-sprotty-label-node={true}
>
<image class-sprotty-icon={true} href={image} y={-4} width={13} height={8}></image>
<text class-sprotty-label={true} x={20}>{labelNode.text}</text>
{ !!image && <image class-sprotty-icon={true} href={image} y={-4} width={13} height={8}></image> }
<text class-sprotty-label={true} x={!!image ? 20 : 0}>{labelNode.text}</text>
</g>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public EdgeTypeHint createDefaultEdgeTypeHint(String elementId) {
public List<ShapeTypeHint> getNodeTypeHints() {
List<ShapeTypeHint> hints = new ArrayList<>();
hints.add(new ShapeTypeHint(DefaultTypes.GRAPH, false, false, false, false,
List.of(Types.ECLASS, Types.ABSTRACT, Types.INTERFACE, Types.ENUM)));
List.of(Types.ECLASS, Types.ABSTRACT, Types.INTERFACE, Types.ENUM, Types.DATATYPE)));
hints.add(new ShapeTypeHint(Types.ECLASS, true, true, false, false, List.of(Types.ATTRIBUTE, Types.OPERATION)));
hints.add(new ShapeTypeHint(Types.ENUM, true, true, false, false, List.of(Types.ENUMLITERAL)));
hints.add(new ShapeTypeHint(Types.DATATYPE, true, true, false, true));
Expand Down Expand Up @@ -120,6 +120,7 @@ public Map<String, EClass> getTypeMappings() {
mappings.put(Types.ATTRIBUTE, GraphPackage.Literals.GLABEL);
mappings.put(Types.OPERATION, GraphPackage.Literals.GLABEL);
mappings.put(Types.ENUMLITERAL, GraphPackage.Literals.GLABEL);
mappings.put(Types.LABEL_INSTANCE, GraphPackage.Literals.GLABEL);
return mappings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public GNode create(EDataType eDataType) {
.hAlign(GConstants.HAlign.CENTER) //
.resizeContainer(true) //
.build()) //
.add(new GLabelBuilder(Types.LABEL_TEXT) //
.addCssClass(CSS.ITALIC).id(toId(eDataType) + "_typeLabel")//
.add(new GLabelBuilder(Types.LABEL_INSTANCE) //
.addCssClass(CSS.ITALIC)//
.id(toId(eDataType) + Types.LABEL_INSTANCE)//
.text(eDataType.getInstanceClassName()) //
.build())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void execute(AbstractOperationAction action, GraphicalModelState graphica
ApplyLabelEditOperationAction editLabelAction = (ApplyLabelEditOperationAction) action;
EcoreFacade facade = EcoreModelState.getEcoreFacade(graphicalModelState);
EcoreModelIndex index = EcoreModelState.getModelState(graphicalModelState).getIndex();

Optional<String> type = index.findElementByClass(editLabelAction.getLabelId(), GModelElement.class).map(e -> e.getType());
if (type.isPresent()) {
switch (type.get()) {
Expand All @@ -81,7 +80,16 @@ public void execute(AbstractOperationAction action, GraphicalModelState graphica
shape.setSemanticElement(facade.createProxy(node_semantic));
}
break;
case Types.LABEL_INSTANCE:
node = getOrThrow(index.findElementByClass(editLabelAction.getLabelId(), GNode.class),
"No parent Node for element with id " + editLabelAction.getLabelId() + " found");

node_semantic = getOrThrow(index.getSemantic(node),
"No semantic element for labelContainer with id " + node.getId() + " found");
if (node_semantic instanceof EClassifier) {
((EClassifier) node_semantic).setInstanceClassName(editLabelAction.getText().trim());
}
break;
case Types.ATTRIBUTE:
EAttribute attribute_semantic = (EAttribute) getOrThrow(index.getSemantic(editLabelAction.getLabelId()),
"No semantic element for label with id " + editLabelAction.getLabelId() + " found");
Expand Down Expand Up @@ -138,7 +146,6 @@ public void execute(AbstractOperationAction action, GraphicalModelState graphica
throw new GLSPServerException("Multiplicity of reference with id " + editLabelAction.getLabelId() + " has a wrong input format", new IllegalArgumentException());
}
break;

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static final class Types {
public static final String INHERITANCE = "edge:inheritance";
public static final String ABSTRACT = "node:class:abstract";
public static final String INTERFACE = "node:class:interface";
public static final String LABEL_INSTANCE = "label:instancename";

private Types() {
};
Expand Down

0 comments on commit 2ac0473

Please sign in to comment.