Skip to content

Commit

Permalink
initial population from theia-yang-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKoehnlein committed Aug 29, 2017
1 parent e0876ad commit e71e6de
Show file tree
Hide file tree
Showing 14 changed files with 987 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/
.nyc_output/
node_modules/
/lib/
/artifacts/
bundle.js
bundle.js.map
npm-debug.log
yarn-error.log
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "yang-sprotty",
"version": "0.0.1",
"description": "sprotty diagrams for the Yang DSL",
"author": "typefox.io",
"license": "Apache-2.0",
"keywords": [
"sprotty", "yang", "diagram"
],
"dependencies": {
"sprotty": "0.1.2"
},
"scripts": {
"clean": "rimraf lib && rimraf node_modules",
"lint": "tslint -c ../tslint.json --project ./tsconfig.json",
"build": "tsc && yarn run lint",
"watch": "tsc -w"
},
"devDependencies": {
"rimraf": "^2.6.1",
"ts-node": "^3.2.0",
"tslint": "^5.5.0",
"typescript": "^2.4.1"
},
"files": [
"lib",
"src",
"build"
]
}
88 changes: 88 additions & 0 deletions src/di.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { Container, ContainerModule } from "inversify"
import {
ClassNodeView, CompositionEdgeView, DashedEdgeView, ImportEdgeView, ModuleNodeView, NoteView,
ArrowEdgeView, ChoiceNodeView, CaseNodeView, TagView, HeaderCompartmentView, DashedArrowEdgeView, UsesNodeView
} from "./views"
import { YangDiagramFactory } from "./model-factory"
import { popupModelFactory } from "./popup"
import {
boundsModule,
ConsoleLogger,
defaultModule,
exportModule,
hoverModule,
HtmlRootView,
LogLevel,
moveModule,
overrideViewerOptions,
PolylineEdgeView,
PreRenderedView,
SCompartmentView,
selectModule,
SGraphView,
SLabelView,
TYPES,
undoRedoModule,
viewportModule,
ViewRegistry,
expandModule,
fadeModule,
openModule,
ExpandButtonHandler,
ExpandButtonView,
buttonModule
} from 'sprotty/lib'

const yangDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope()
rebind(TYPES.LogLevel).toConstantValue(LogLevel.log)
rebind(TYPES.IModelFactory).to(YangDiagramFactory).inSingletonScope()
bind(TYPES.PopupModelFactory).toConstantValue(popupModelFactory)
})

export default function createContainer(widgetId: string): Container {
const container = new Container()
container.load(defaultModule, selectModule, moveModule, boundsModule, undoRedoModule, viewportModule,
hoverModule, fadeModule, exportModule, expandModule, openModule, buttonModule, yangDiagramModule)
// container.bind(TYPES.ModelSource).to(TheiaDiagramServer).inSingletonScope()
overrideViewerOptions(container, {
needsClientLayout: true,
needsServerLayout: true,
baseDiv: widgetId
})

// Register views
const viewRegistry = container.get<ViewRegistry>(TYPES.ViewRegistry)
viewRegistry.register('graph', SGraphView)
viewRegistry.register('node:class', ClassNodeView)
viewRegistry.register('node:module', ModuleNodeView)
viewRegistry.register('node:choice', ChoiceNodeView)
viewRegistry.register('node:case', CaseNodeView)
viewRegistry.register('node:pill', UsesNodeView)
viewRegistry.register('node:note', NoteView)
viewRegistry.register('label:heading', SLabelView)
viewRegistry.register('label:text', SLabelView)
viewRegistry.register('ylabel:text', SLabelView)
viewRegistry.register('label:classHeader', SLabelView)
viewRegistry.register('label:classTag', TagView)
viewRegistry.register('comp:comp', SCompartmentView)
viewRegistry.register('comp:classHeader', HeaderCompartmentView)
viewRegistry.register('edge:straight', PolylineEdgeView)
viewRegistry.register('edge:composition', CompositionEdgeView)
viewRegistry.register('edge:dashed', DashedEdgeView)
viewRegistry.register('edge:import', ImportEdgeView)
viewRegistry.register('edge:uses', DashedArrowEdgeView)
viewRegistry.register('edge:augments', ArrowEdgeView)
viewRegistry.register('html', HtmlRootView)
viewRegistry.register('pre-rendered', PreRenderedView)
viewRegistry.register(ExpandButtonHandler.TYPE, ExpandButtonView)

return container
}
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/


// ------------------ Base ------------------

import createYangDiagramContainer from './di.config'
export { createYangDiagramContainer }
55 changes: 55 additions & 0 deletions src/model-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import {
SGraphFactory, SModelElementSchema, SModelRoot, SModelRootSchema, SParentElement, SChildElement,
getBasicType, HtmlRoot, HtmlRootSchema, PreRenderedElement, PreRenderedElementSchema, SLabelSchema,
getSubType
} from "sprotty/lib"
import { YangLabel, YangNode, ModuleNode } from './yang-models';

export class YangDiagramFactory extends SGraphFactory {

createElement(schema: SModelElementSchema, parent?: SParentElement): SChildElement {
if (this.isPreRenderedSchema(schema))
return this.initializeChild(new PreRenderedElement(), schema, parent)
else if (this.isNode(schema))
if (getSubType(schema) === 'module')
return this.initializeChild(new ModuleNode(), schema, parent)
else
return this.initializeChild(new YangNode(), schema, parent)
if (this.isYangLabelSchema(schema))
return this.initializeChild(new YangLabel(), schema, parent)
else
return super.createElement(schema, parent)
}

createRoot(schema: SModelRootSchema): SModelRoot {
if (this.isHtmlRootSchema(schema))
return this.initializeRoot(new HtmlRoot(), schema)
else
return super.createRoot(schema)
}

isHtmlRootSchema(schema: SModelElementSchema): schema is HtmlRootSchema {
return getBasicType(schema) === 'html'
}

isPreRenderedSchema(schema: SModelElementSchema): schema is PreRenderedElementSchema {
return getBasicType(schema) === 'pre-rendered'
}

isNode(schema: SModelElementSchema): schema is YangNode {
return getBasicType(schema) === 'node'
}

isYangLabelSchema(schema: SModelElementSchema): schema is SLabelSchema {
return getBasicType(schema) === 'ylabel'
}


}
34 changes: 34 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { SModelElementSchema, SModelRootSchema, RequestPopupModelAction, PreRenderedElementSchema } from "sprotty/lib"

export function popupModelFactory(request: RequestPopupModelAction, element?: SModelElementSchema): SModelRootSchema | undefined {
if (element !== undefined && (element.type === 'node:class' || element.type === 'node:note')) {
return {
type: 'html',
id: 'popup',
children: [
<PreRenderedElementSchema> {
type: 'pre-rendered',
id: 'popup-title',
code: `<div class="popup-title">Class ${element.id === 'node0' ? 'Foo' : 'Bar'}</div>`
},
<PreRenderedElementSchema> {
type: 'pre-rendered',
id: 'popup-body',
code: '<div class="popup-body">' +
'But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain ' +
'was ' +
'born and I will give you a complete account of the system, and expound the actual teachings of ' +
'the great explorer of the truth, the master-builder of human happiness.</div>'
}
]
}
}
return undefined
}
Loading

0 comments on commit e71e6de

Please sign in to comment.