Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add identifier property to Entity attributes #59

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ entity:
- id: CustomerID
name: "CustomerID"
datatype: "Integer"
identifier: true
- id: Street
name: "Street"
datatype: "Text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ entity:
id: Customer
name: "Customer"
attributes:
- id: Id
name: "Id"
datatype: "Integer"
- id: FirstName
name: "FirstName"
datatype: "Text"
- id: LastName
name: "LastName"
datatype: "Text"
- id: City
name: "City"
datatype: "Text"
- id: Country
name: "Country"
datatype: "Text"
- id: Phone
name: "Phone"
datatype: "Text"
- id: BirthDate
name: "BirthDate"
datatype: "DateTime"
- id: Id
name: "Id"
datatype: "Integer"
identifier: true
- id: FirstName
name: "FirstName"
datatype: "Text"
- id: LastName
name: "LastName"
datatype: "Text"
- id: City
name: "City"
datatype: "Text"
- id: Country
name: "Country"
datatype: "Text"
- id: Phone
name: "Phone"
datatype: "Text"
- id: BirthDate
name: "BirthDate"
datatype: "DateTime"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ entity:
- id: Id
name: "Id"
datatype: "Integer"
identifier: true
- id: OrderDate
name: "OrderDate"
datatype: "Integer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ entity:
id: Country
name: "Country"
attributes:
- id: Code
name: "Code"
datatype: "Varchar"
- id: Name
name: "name"
datatype: "Varchar"
- id: Code
name: "Code"
datatype: "Varchar"
identifier: true
- id: Name
name: "Name"
datatype: "Varchar"
2 changes: 2 additions & 0 deletions extensions/crossmodel-lang/src/glsp-server/common/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class AttributeCompartmentBuilder extends GCompartmentBuilder<AttributeCo
.layout('hbox')
.addLayoutOption('paddingBottom', 3)
.addLayoutOption('paddingTop', 3)
.addLayoutOption('paddingLeft', 3)
.addLayoutOption('paddingRight', 3)
.addLayoutOption('hGap', 3);

const leftPortId = createLeftPortId(attributeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ENTITY_NODE_TYPE, REFERENCE_CONTAINER_TYPE, REFERENCE_PROPERTY, REFEREN
import { ArgsUtil, GNode, GNodeBuilder } from '@eclipse-glsp/server';
import { EntityNode } from '../../../language-server/generated/ast.js';
import { getAttributes } from '../../../language-server/util/ast-util.js';
import { createAttributesCompartment, createHeader } from '../../common/nodes.js';
import { AttributeCompartment, AttributesCompartmentBuilder, createHeader } from '../../common/nodes.js';
import { SystemModelIndex } from './system-model-index.js';

export class GEntityNode extends GNode {
Expand Down Expand Up @@ -34,7 +34,13 @@ export class GEntityNodeBuilder extends GNodeBuilder<GEntityNode> {

// Add the children of the node
const attributes = getAttributes(node);
this.add(createAttributesCompartment(attributes, this.proxy.id, index));
const attributesCompartment = new AttributesCompartmentBuilder().set(this.proxy.id);
for (const attribute of attributes) {
const attributeNode = AttributeCompartment.builder().set(attribute, index);
attributeNode.addArg('identifier', attribute.identifier);
attributesCompartment.add(attributeNode.build());
}
this.add(attributesCompartment.build());

// The DiagramNode in the langium file holds the coordinates of node
this.layout('vbox')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const PROPERTY_ORDER = [
'id',
'name',
'datatype',
'identifier',
'description',
'entity',
'parent',
Expand Down Expand Up @@ -117,6 +118,9 @@ export class CrossModelSerializer implements Serializer<CrossModelRoot> {
if (Array.isArray(objValue) && objValue.length === 0) {
return;
}
if (objKey === 'identifier' && objValue === false) {
return;
}

const propKey = this.serializeKey(objKey);
const propValue = this.serializeValue(objValue, indentationLevel, propKey);
Expand Down
7 changes: 5 additions & 2 deletions extensions/crossmodel-lang/src/language-server/entity.langium
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ Entity:
interface Attribute {
id: string;
name: string;
datatype: string;
datatype: string;
description?: string;
}

interface EntityAttribute extends Attribute {}
interface EntityAttribute extends Attribute {
identifier?: boolean;
}

EntityAttribute returns EntityAttribute:
'id' ':' id=ID
'name' ':' name=STRING
'datatype' ':' datatype=STRING
(identifier?='identifier' ':' ('TRUE' | 'true'))?
('description' ':' description=STRING)?;
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export function isTargetObject(item: unknown): item is TargetObject {

export interface EntityAttribute extends Attribute {
readonly $type: 'EntityAttribute' | 'EntityNodeAttribute';
identifier: boolean
}

export const EntityAttribute = 'EntityAttribute';
Expand Down Expand Up @@ -521,6 +522,14 @@ export class CrossModelAstReflection extends AbstractAstReflection {
]
};
}
case 'EntityAttribute': {
return {
name: 'EntityAttribute',
mandatory: [
{ name: 'identifier', type: 'boolean' }
]
};
}
default: {
return {
name: type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ export const CrossModelGrammar = (): Grammar => loadedCrossModelGrammar ?? (load
"arguments": []
}
},
{
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "identifier",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "identifier"
}
},
{
"$type": "Keyword",
"value": ":"
},
{
"$type": "Alternatives",
"elements": [
{
"$type": "Keyword",
"value": "TRUE"
},
{
"$type": "Keyword",
"value": "true"
}
]
}
],
"cardinality": "?"
},
{
"$type": "Group",
"elements": [
Expand Down Expand Up @@ -2220,13 +2252,23 @@ export const CrossModelGrammar = (): Grammar => loadedCrossModelGrammar ?? (load
},
{
"$type": "Interface",
"attributes": [
{
"$type": "TypeAttribute",
"name": "identifier",
"isOptional": true,
"type": {
"$type": "SimpleType",
"primitiveType": "boolean"
}
}
],
"name": "EntityAttribute",
"superTypes": [
{
"$ref": "#/interfaces@0"
}
],
"attributes": []
]
},
{
"$type": "Interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "keyword.control.cross-model",
"match": "\\b(apply|attribute|attributes|child|conditions|cross-join|datatype|dependencies|description|diagram|edges|entity|expression|from|height|id|inner-join|join|left-join|mapping|mappings|name|nodes|parent|relationship|sourceNode|sources|systemDiagram|target|targetNode|type|width|x|y)\\b"
"match": "\\b(TRUE|apply|attribute|attributes|child|conditions|cross-join|datatype|dependencies|description|diagram|edges|entity|expression|from|height|id|identifier|inner-join|join|left-join|mapping|mappings|name|nodes|parent|relationship|sourceNode|sources|systemDiagram|target|targetNode|true|type|width|x|y)\\b"
},
{
"name": "string.quoted.double.cross-model",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ describe('CrossModelLexer', () => {

crossModelRoot.entity.attributes = [
{
identifier: false,
$container: crossModelRoot.entity,
$type: 'EntityAttribute',
id: 'Attribute1',
name: 'Attribute1',
datatype: 'Datatype Attribute 1'
},
{
identifier: false,
$container: crossModelRoot.entity,
$type: 'EntityAttribute',
id: 'Attribute2',
Expand All @@ -66,13 +68,15 @@ describe('CrossModelLexer', () => {
};
crossModelRootWithAttributesDifPlace.entity.attributes = [
{
identifier: false,
$container: crossModelRoot.entity,
$type: 'EntityAttribute',
id: 'Attribute1',
name: 'Attribute1',
datatype: 'Datatype Attribute 1'
},
{
identifier: false,
$container: crossModelRoot.entity,
$type: 'EntityAttribute',
id: 'Attribute2',
Expand Down
5 changes: 3 additions & 2 deletions packages/glsp-client/src/browser/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
********************************************************************************/

import { ATTRIBUTE_COMPARTMENT_TYPE } from '@crossbreeze/protocol';
import { GCompartment, GModelElement, Hoverable, Selectable, isSelectable } from '@eclipse-glsp/client';
import { Args, ArgsAware, GCompartment, GModelElement, Hoverable, Selectable, isSelectable } from '@eclipse-glsp/client';

export class AttributeCompartment extends GCompartment implements Selectable, Hoverable {
export class AttributeCompartment extends GCompartment implements Selectable, Hoverable, ArgsAware {
hoverFeedback: boolean;
selected: boolean;
args?: Args;

static is(element?: GModelElement): element is AttributeCompartment {
return !!element && isSelectable(element) && element.type === ATTRIBUTE_COMPARTMENT_TYPE;
Expand Down
11 changes: 10 additions & 1 deletion packages/glsp-client/src/browser/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AttributeCompartmentView extends GCompartmentView {
override render(compartment: Readonly<AttributeCompartment>, context: RenderingContext): VNode | undefined {
const translate = `translate(${compartment.bounds.x}, ${compartment.bounds.y})`;
const vnode: any = (
<g transform={translate}>
<g transform={translate} class-identifier={compartment.args?.identifier}>
<rect
class-attribute-compartment={true}
class-mouseover={compartment.hoverFeedback}
Expand All @@ -38,6 +38,15 @@ export class AttributeCompartmentView extends GCompartmentView {
height={Math.max(compartment.size.height, 0)}
></rect>
{context.renderChildren(compartment) as ReactNode}
{compartment.args?.identifier && (
<line
class-identifier={true}
x1={(compartment.layoutOptions?.paddingLeft as number | undefined) ?? 0}
y1={Math.max(compartment.size.height - 1, 0)}
x2={Math.max(compartment.size.width, 0) - ((compartment.layoutOptions?.paddingRight as number | undefined) ?? 0)}
y2={Math.max(compartment.size.height - 1, 0)}
/>
)}
</g>
) as any;

Expand Down
7 changes: 7 additions & 0 deletions packages/glsp-client/style/diagram.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
baseline-shift: 2px;
}

.sprotty line.identifier {
stroke: black;
stroke-width: 0.75px;
stroke-dasharray: none;
stroke-linecap: round;
}

.sprotty[id^='system-diagram'] .tool-palette {
top: 11px;
right: 11px;
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/src/model-service/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface Attribute extends CrossModelElement, Identifiable {
export const EntityAttributeType = 'EntityAttribute';
export interface EntityAttribute extends Attribute {
readonly $type: typeof EntityAttributeType;
identifier?: boolean;
}

export const RelationshipType = 'Relationship';
Expand Down
Loading
Loading