diff --git a/client/sprotty-ecore/src/di.config.ts b/client/sprotty-ecore/src/di.config.ts index 47a526b..36adff1 100644 --- a/client/sprotty-ecore/src/di.config.ts +++ b/client/sprotty-ecore/src/di.config.ts @@ -71,8 +71,8 @@ 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, SLabelNode, IconDataType, IconEnum, IconInterface, IconAbstract, IconClass} from "./model"; -import { ArrowEdgeView, ClassNodeView, CompositionEdgeView, IconView, InheritanceEdgeView, LabelNodeView, EcoreSLabelView } from "./views"; +import {ArrowEdge, CompositionEdge, InheritanceEdge, LabeledNode, SEditableLabel, IconDataType, IconEnum, IconInterface, IconAbstract, IconClass, SLabelNodeAttribute, SLabelNodeLiteral} from "./model"; +import { ArrowEdgeView, ClassNodeView, CompositionEdgeView, IconView, InheritanceEdgeView, LabelNodeView } from "./views"; export default (containerId: string) => { const classDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => { @@ -88,8 +88,8 @@ export default (containerId: string) => { configureModelElement(context, 'node:datatype', LabeledNode, ClassNodeView); configureModelElement(context, 'label:name', SEditableLabel, SLabelView); configureModelElement(context, 'label:edge', SEditableLabel, SLabelView); - configureModelElement(context, 'node:attribute', SLabelNode, LabelNodeView); - configureModelElement(context, 'node:enumliteral', SLabel, EcoreSLabelView); + configureModelElement(context, 'node:attribute', SLabelNodeAttribute, LabelNodeView); + configureModelElement(context, 'node:enumliteral', SLabelNodeLiteral, LabelNodeView); configureModelElement(context, 'node:operation', SNode, RectangularNodeView); configureModelElement(context, 'label:text', SLabel, SLabelView); configureModelElement(context, 'comp:comp', SCompartment, SCompartmentView); diff --git a/client/sprotty-ecore/src/model.ts b/client/sprotty-ecore/src/model.ts index b47afcb..38c1a14 100644 --- a/client/sprotty-ecore/src/model.ts +++ b/client/sprotty-ecore/src/model.ts @@ -96,6 +96,7 @@ export class IconDataType extends Icon { export class SLabelNode extends SLabel implements EditableLabel { hoverFeedback: boolean = false; + imageName: string; hasFeature(feature: symbol): boolean { return (feature === selectFeature || feature === editLabelFeature || feature === popupFeature || feature === deletableFeature || @@ -103,6 +104,14 @@ export class SLabelNode extends SLabel implements EditableLabel { } } +export class SLabelNodeAttribute extends SLabelNode { + imageName = "EAttribute.svg"; +} + +export class SLabelNodeLiteral extends SLabelNode { + imageName = "EEnumLiteral.svg"; +} + export class ArrowEdge extends SEdge { public readonly targetAnchorCorrection = 3.3; } diff --git a/client/sprotty-ecore/src/views.tsx b/client/sprotty-ecore/src/views.tsx index 633876b..9c578a9 100644 --- a/client/sprotty-ecore/src/views.tsx +++ b/client/sprotty-ecore/src/views.tsx @@ -27,7 +27,6 @@ import { setAttr, SLabelView, toDegrees, - SLabel, } from "sprotty/lib"; import { Icon, LabeledNode, SLabelNode } from "./model"; @@ -132,7 +131,7 @@ export class AggregationEdgeView extends DiamondEdgeView { @injectable() export class LabelNodeView extends SLabelView { render(labelNode: Readonly, context: RenderingContext): VNode { - const image = require("../images/EAttribute.svg"); + const image = require("../images/" + labelNode.imageName); const vnode = ( , context: RenderingContext): VNode { - const image = require("../images/EEnumLiteral.svg"); - - const vnode = ( - - - {labelNode.text} - - ); - - const subType = getSubType(labelNode); - if (subType) setAttr(vnode, "class", subType); - return vnode; - } -} - export function angle(x0: Point, x1: Point): number { return toDegrees(Math.atan2(x1.y - x0.y, x1.x - x0.x)); } diff --git a/server/ecore-glsp/src/main/java/com/eclipsesource/glsp/ecore/operationhandler/EcoreLabelEditOperationHandler.java b/server/ecore-glsp/src/main/java/com/eclipsesource/glsp/ecore/operationhandler/EcoreLabelEditOperationHandler.java index 6f01a63..15bdbb0 100644 --- a/server/ecore-glsp/src/main/java/com/eclipsesource/glsp/ecore/operationhandler/EcoreLabelEditOperationHandler.java +++ b/server/ecore-glsp/src/main/java/com/eclipsesource/glsp/ecore/operationhandler/EcoreLabelEditOperationHandler.java @@ -28,6 +28,7 @@ import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EEnumLiteral; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EcorePackage; @@ -84,6 +85,12 @@ public void execute(AbstractOperationAction action, GraphicalModelState graphica if (!attributeName.isEmpty()) { ((EAttribute) eObject).setName(attributeName); } + } else if (eObject instanceof EEnumLiteral) { + String inputText = editLabelAction.getText().trim(); + + if (!inputText.isEmpty()) { + ((EEnumLiteral) eObject).setName(inputText); + } } } else { Optional nodeOptinal = index.findElementByClass(editLabelAction.getLabelId(), GNode.class);