2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import React from 'react';
19 import Common from '../../common/Common';
20 import Logger from '../../common/Logger';
21 import Diagram from '../diagram/Diagram';
22 import Dialog from '../dialog/Dialog';
23 import Editor from '../editor/Editor';
24 import Export from '../export/Export';
25 import Overlay from '../overlay/Overlay';
28 * Application controller, also a view.
30 export default class Application extends React.Component {
33 * Construct application view.
34 * @param props element properties.
35 * @param context react context.
37 constructor(props, context) {
38 super(props, context);
40 this.sequencer = Common.assertNotNull(props.sequencer);
41 this.model = this.sequencer.getModel();
42 this.metamodel = this.sequencer.getMetamodel();
43 this.options = props.options;
44 Logger.setLevel(this.options.unwrap().log.level);
48 this.showInfoDialog = this.showInfoDialog.bind(this);
49 this.showEditDialog = this.showEditDialog.bind(this);
50 this.showConfirmDialog = this.showConfirmDialog.bind(this);
51 this.hideOverlay = this.hideOverlay.bind(this);
52 this.onMouseMove = this.onMouseMove.bind(this);
53 this.onMouseUp = this.onMouseUp.bind(this);
56 // ///////////////////////////////////////////////////////////////////////////////////////////////
59 * Get application options.
60 * @returns JSON options, see Options.js.
63 return this.options.unwrap();
66 // ///////////////////////////////////////////////////////////////////////////////////////////////
70 * @param n diagram (human-readable) name.
73 this.diagram.setName(n);
76 // ///////////////////////////////////////////////////////////////////////////////////////////////
80 * @param model diagram instance.
84 Common.assertNotNull(model);
93 this.diagram.render();
97 // ///////////////////////////////////////////////////////////////////////////////////////////////
107 // ///////////////////////////////////////////////////////////////////////////////////////////////
114 return this.diagram.getSVG();
117 // ///////////////////////////////////////////////////////////////////////////////////////////////
120 * Get top-level widget. Provides the demo toolbar with access to the public API.
124 return this.sequencer;
127 // ///////////////////////////////////////////////////////////////////////////////////////////////
130 * Present info dialog.
131 * @param msg info message.
133 showInfoDialog(msg) {
134 this.dialog.showInfoDialog(msg);
137 // ///////////////////////////////////////////////////////////////////////////////////////////////
140 * Present error dialog.
141 * @param msg error message.
143 showErrorDialog(msg) {
144 this.dialog.showErrorDialog(msg);
147 // ///////////////////////////////////////////////////////////////////////////////////////////////
150 * Present confirmation dialog.
151 * @param msg info message.
152 * @param cb callback function to be invoked on OK.
154 showConfirmDialog(msg, cb) {
155 Common.assertType(cb, 'Function');
156 this.dialog.showConfirmDialog(msg, cb);
159 // ///////////////////////////////////////////////////////////////////////////////////////////////
162 * Present edit (textarea) dialog.
164 * @param text current edit text.
165 * @param cb callback function to be invoked on OK, taking the updated text
168 showEditDialog(msg, text, cb) {
169 this.dialog.showEditDialog(msg, text, cb);
172 // ///////////////////////////////////////////////////////////////////////////////////////////////
175 * Select lifeline by ID.
176 * @param id lifeline ID.
180 this.editor.selectLifeline(id);
183 this.diagram.selectLifeline(id);
187 // ///////////////////////////////////////////////////////////////////////////////////////////////
190 * Select message by ID.
191 * @param id message ID.
195 this.editor.selectMessage(id);
198 this.diagram.selectMessage(id);
202 // ///////////////////////////////////////////////////////////////////////////////////////////////
205 * (Re)render just the diagram.
208 this.diagram.redraw();
211 // ///////////////////////////////////////////////////////////////////////////////////////////////
214 * Show overlay between application and modal dialog.
218 this.overlay.setVisible(true);
222 // ///////////////////////////////////////////////////////////////////////////////////////////////
225 * Hide overlay between application and modal dialog.
229 this.overlay.setVisible(false);
233 // ///////////////////////////////////////////////////////////////////////////////////////////////
236 * Capture mouse move events, for resize.
237 * @param event move event.
241 this.editor.onMouseMove(event);
245 // ///////////////////////////////////////////////////////////////////////////////////////////////
248 * Propagate mouse event to the editor that manages the resize.
252 this.editor.onMouseUp();
256 // ///////////////////////////////////////////////////////////////////////////////////////////////
259 * Render current model state.
265 <div className="asdcs-control" onMouseMove={this.onMouseMove} onMouseUp={this.onMouseUp}>
267 <Editor application={this} ref={(r) => { this.editor = r; }} />
268 <Diagram application={this} ref={(r) => { this.diagram = r; }} />
269 <Dialog application={this} ref={(r) => { this.dialog = r; }} />
271 <Overlay application={this} ref={(r) => { this.overlay = r; }} />
279 /** React properties. */
280 Application.propTypes = {
281 options: React.PropTypes.object.isRequired,
282 sequencer: React.PropTypes.object.isRequired,