Skip to content

Commit

Permalink
Added support for literal editing
Browse files Browse the repository at this point in the history
Added subclasses of SLabelNode for attributes and literals.
Changed EcoreLabelOperationHandler to support server side editing.
Resolves:eclipsesource#61
Signed-off-by: leodennis <[email protected]>
  • Loading branch information
leodennis committed Dec 20, 2019
1 parent 8e1b95e commit d566917
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions client/sprotty-ecore/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -88,8 +88,8 @@ export default (containerId: string) => {
configureModelElement(context, 'node:datatype', LabeledNode, ClassNodeView);
configureModelElement(context, 'label:name', SEditableLabel, SLabelView);
configureModelElement(context, 'label:edge', SLabel, 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);
Expand Down
9 changes: 9 additions & 0 deletions client/sprotty-ecore/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,22 @@ 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 ||
feature === hoverFeedbackFeature || super.hasFeature(feature));
}
}

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;
}
Expand Down
21 changes: 1 addition & 20 deletions client/sprotty-ecore/src/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
setAttr,
SLabelView,
toDegrees,
SLabel,
} from "sprotty/lib";

import { Icon, LabeledNode, SLabelNode } from "./model";
Expand Down Expand Up @@ -132,7 +131,7 @@ export class AggregationEdgeView extends DiamondEdgeView {
@injectable()
export class LabelNodeView extends SLabelView {
render(labelNode: Readonly<SLabelNode>, context: RenderingContext): VNode {
const image = require("../images/EAttribute.svg");
const image = require("../images/" + labelNode.imageName);

const vnode = (
<g
Expand All @@ -151,24 +150,6 @@ export class LabelNodeView extends SLabelView {
}
}

@injectable()
export class EcoreSLabelView extends SLabelView {
render(labelNode: Readonly<SLabel>, context: RenderingContext): VNode {
const image = require("../images/EEnumLiteral.svg");

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

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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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.EcorePackage;

Expand Down Expand Up @@ -79,6 +80,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 { // Main Label of a Node
GNode node = getOrThrow(index.findElementByClass(editLabelAction.getLabelId(), GNode.class),
Expand Down

0 comments on commit d566917

Please sign in to comment.