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 all 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,14 @@ 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);
// increase padding left and right so we have space for the identifier icon
attributeNode.addArg('identifier', attribute.identifier).addLayoutOption('paddingLeft', 8).addLayoutOption('paddingRight', 8);
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
9 changes: 8 additions & 1 deletion packages/glsp-client/src/browser/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2024 CrossBreeze.
********************************************************************************/
/* eslint-disable react/no-unknown-property */
/* eslint-disable max-len */

import { GCompartmentView, RenderingContext, RoundedCornerNodeView, RoundedCornerWrapper, svg } from '@eclipse-glsp/client';
import { ReactNode } from '@theia/core/shared/react';
Expand All @@ -27,7 +28,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 @@ -37,6 +38,12 @@ export class AttributeCompartmentView extends GCompartmentView {
width={Math.max(compartment.size.width, 0)}
height={Math.max(compartment.size.height, 0)}
></rect>
{compartment.args?.identifier && (
<path
class-icon-path='icon-path'
d='M432-680q0-28 20-48t48-20q28 0 48 20t20 48q0 28-20 48t-48 20q-28 0-48-20t-20-48ZM490 0 337-167l64-88-64-88 60-75v-45q-60-32-98.5-85T260-680q0-100 70-170t170-70q100 0 170 70t70 170q0 72-34 124.5T603-463v350L490 0ZM320-680q0 58 38.5 110t98.5 66v108l-45 54 63 88-62 82 79 85 51-51v-366q66-19 101.5-66.5T680-680q0-75-52.5-127.5T500-860q-75 0-127.5 52.5T320-680Z'
></path>
)}
{context.renderChildren(compartment) as ReactNode}
</g>
) as any;
Expand Down
12 changes: 12 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 Expand Up @@ -131,3 +138,8 @@
.command-palette {
animation: none;
}

.attribute.identifier .icon-path {
transform: scale(0.0105) translate(-400px, 1375px);
fill: #000;
}
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