2 import React from 'react';
4 import Common from '../../common/Common';
5 import Logger from '../../common/Logger';
6 import Diagram from '../diagram/Diagram';
7 import Dialog from '../dialog/Dialog';
8 import Editor from '../editor/Editor';
9 import Export from '../export/Export';
10 import Overlay from '../overlay/Overlay';
13 * Application controller, also a view.
15 export default class Application extends React.Component {
18 * Construct application view.
19 * @param props element properties.
20 * @param context react context.
22 constructor(props, context) {
23 super(props, context);
25 this.sequencer = Common.assertNotNull(props.sequencer);
26 this.model = this.sequencer.getModel();
27 this.metamodel = this.sequencer.getMetamodel();
28 this.options = props.options;
29 Logger.setLevel(this.options.unwrap().log.level);
33 this.showInfoDialog = this.showInfoDialog.bind(this);
34 this.showEditDialog = this.showEditDialog.bind(this);
35 this.showConfirmDialog = this.showConfirmDialog.bind(this);
36 this.hideOverlay = this.hideOverlay.bind(this);
37 this.onMouseMove = this.onMouseMove.bind(this);
38 this.onMouseUp = this.onMouseUp.bind(this);
41 // ///////////////////////////////////////////////////////////////////////////////////////////////
44 * Get application options.
45 * @returns JSON options, see Options.js.
48 return this.options.unwrap();
51 // ///////////////////////////////////////////////////////////////////////////////////////////////
55 * @param n diagram (human-readable) name.
58 this.diagram.setName(n);
61 // ///////////////////////////////////////////////////////////////////////////////////////////////
65 * @param model diagram instance.
69 Common.assertNotNull(model);
78 this.diagram.render();
82 // ///////////////////////////////////////////////////////////////////////////////////////////////
92 // ///////////////////////////////////////////////////////////////////////////////////////////////
99 return this.diagram.getSVG();
102 // ///////////////////////////////////////////////////////////////////////////////////////////////
105 * Get top-level widget. Provides the demo toolbar with access to the public API.
109 return this.sequencer;
112 // ///////////////////////////////////////////////////////////////////////////////////////////////
115 * Present info dialog.
116 * @param msg info message.
118 showInfoDialog(msg) {
119 this.dialog.showInfoDialog(msg);
122 // ///////////////////////////////////////////////////////////////////////////////////////////////
125 * Present error dialog.
126 * @param msg error message.
128 showErrorDialog(msg) {
129 this.dialog.showErrorDialog(msg);
132 // ///////////////////////////////////////////////////////////////////////////////////////////////
135 * Present confirmation dialog.
136 * @param msg info message.
137 * @param cb callback function to be invoked on OK.
139 showConfirmDialog(msg, cb) {
140 Common.assertType(cb, 'Function');
141 this.dialog.showConfirmDialog(msg, cb);
144 // ///////////////////////////////////////////////////////////////////////////////////////////////
147 * Present edit (textarea) dialog.
149 * @param text current edit text.
150 * @param cb callback function to be invoked on OK, taking the updated text
153 showEditDialog(msg, text, cb) {
154 this.dialog.showEditDialog(msg, text, cb);
157 // ///////////////////////////////////////////////////////////////////////////////////////////////
160 * Select lifeline by ID.
161 * @param id lifeline ID.
165 this.editor.selectLifeline(id);
168 this.diagram.selectLifeline(id);
172 // ///////////////////////////////////////////////////////////////////////////////////////////////
175 * Select message by ID.
176 * @param id message ID.
180 this.editor.selectMessage(id);
183 this.diagram.selectMessage(id);
187 // ///////////////////////////////////////////////////////////////////////////////////////////////
190 * (Re)render just the diagram.
193 this.diagram.redraw();
196 // ///////////////////////////////////////////////////////////////////////////////////////////////
199 * Show overlay between application and modal dialog.
203 this.overlay.setVisible(true);
207 // ///////////////////////////////////////////////////////////////////////////////////////////////
210 * Hide overlay between application and modal dialog.
214 this.overlay.setVisible(false);
218 // ///////////////////////////////////////////////////////////////////////////////////////////////
221 * Capture mouse move events, for resize.
222 * @param event move event.
226 this.editor.onMouseMove(event);
230 // ///////////////////////////////////////////////////////////////////////////////////////////////
233 * Propagate mouse event to the editor that manages the resize.
237 this.editor.onMouseUp();
241 // ///////////////////////////////////////////////////////////////////////////////////////////////
244 * Render current model state.
250 <div className="asdcs-control" onMouseMove={this.onMouseMove} onMouseUp={this.onMouseUp}>
252 <Editor application={this} ref={(r) => { this.editor = r; }} />
253 <Diagram application={this} ref={(r) => { this.diagram = r; }} />
254 <Dialog application={this} ref={(r) => { this.dialog = r; }} />
256 <Overlay application={this} ref={(r) => { this.overlay = r; }} />
264 /** React properties. */
265 Application.propTypes = {
266 options: React.PropTypes.object.isRequired,
267 sequencer: React.PropTypes.object.isRequired,