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 Logger from '../../common/Logger';
20 import Common from '../../common/Common';
21 import Designer from './components/designer/Designer';
22 import Toolbar from './components/toolbar/Toolbar';
23 import Source from './components/source/Source';
26 * Editor view, aggregating the designer, the code editor, the toolbar.
28 export default class Editor extends React.Component {
30 // ///////////////////////////////////////////////////////////////////////////////////////////////
33 * Construct React view.
34 * @param props properties.
35 * @param context context.
37 constructor(props, context) {
38 super(props, context);
40 this.application = Common.assertNotNull(props.application);
41 this.demo = this.application.getOptions().demo;
45 this.selectMessage = this.selectMessage.bind(this);
46 this.selectLifeline = this.selectLifeline.bind(this);
48 this.onMouseDown = this.onMouseDown.bind(this);
49 this.onMouseUp = this.onMouseUp.bind(this);
50 this.onMouseMove = this.onMouseMove.bind(this);
53 // ///////////////////////////////////////////////////////////////////////////////////////////////
56 * Select message by ID.
57 * @param id message ID.
61 this.designer.selectMessage(id);
65 // ///////////////////////////////////////////////////////////////////////////////////////////////
68 * Select lifeline by ID.
69 * @param id lifeline ID.
73 this.designer.selectLifeline(id);
77 // ///////////////////////////////////////////////////////////////////////////////////////////////
80 * Record that we're dragging.
85 initialWidth: this.editor.offsetWidth,
86 initialPageX: undefined,
91 // ///////////////////////////////////////////////////////////////////////////////////////////////
94 * Record that we're not dragging.
97 this.resize = undefined;
100 // ///////////////////////////////////////////////////////////////////////////////////////////////
103 * Record mouse movement.
108 if (this.resize.initialPageX) {
109 const deltaX = event.pageX - this.resize.initialPageX;
110 const newWidth = this.resize.initialWidth + deltaX;
111 const newWidthBounded = Math.min(800, Math.max(400, newWidth));
112 this.editor.style.width = `${newWidthBounded}px`;
114 this.resize.initialPageX = event.pageX;
120 // ///////////////////////////////////////////////////////////////////////////////////////////////
127 Logger.info('Editor.jsx - render()');
132 className="asdcs-editor"
133 ref={(r) => { this.editor = r; }}
136 <Toolbar application={this.props.application} editor={this} />
138 <div className="asdcs-editor-content">
139 <Source application={this.props.application} />
141 application={this.props.application}
144 this.designer = r.getDecoratedComponentInstance();
146 this.designer = null;
152 <div className="asdcs-editor-statusbar">
153 <div className="asdcs-editor-status"></div>
154 <div className="asdcs-editor-validation"></div>
158 className="asdcs-editor-resize-handle"
159 onMouseDown={this.onMouseDown}
160 onMouseUp={this.onMouseUp}
168 /** Element properties. */
170 application: React.PropTypes.object.isRequired,