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';
18 import { DragSource, DropTarget } from 'react-dnd';
20 import Common from '../../../../../../common/Common';
22 import Icon from '../../../../../icons/Icon';
23 import iconHandle from '../../../../../../../../../../res/ecomp/asdc/sequencer/sprites/icons/handle.svg';
24 import iconDelete from '../../../../../../../../../../res/ecomp/asdc/sequencer/sprites/icons/delete.svg';
27 * LHS lifeline row view.
29 class Lifeline extends React.Component {
31 // ///////////////////////////////////////////////////////////////////////////////////////////////
34 * Construct editor view.
35 * @param props element properties.
36 * @param context react context.
38 constructor(props, context) {
39 super(props, context);
43 name: props.lifeline.name,
46 const metamodel = Common.assertNotNull(this.props.metamodel).unwrap();
47 this.canReorder = metamodel.diagram.lifelines.constraints.reorder;
48 this.canDelete = metamodel.diagram.lifelines.constraints.delete;
52 this.onChangeName = this.onChangeName.bind(this);
53 this.onBlurName = this.onBlurName.bind(this);
54 this.onClickDelete = this.onClickDelete.bind(this);
55 this.onMouseEnter = this.onMouseEnter.bind(this);
56 this.onMouseLeave = this.onMouseLeave.bind(this);
59 // ///////////////////////////////////////////////////////////////////////////////////////////////
63 * @param event change event.
66 this.setState({ name: event.target.value });
69 // ///////////////////////////////////////////////////////////////////////////////////////////////
73 * @param event change event.
76 const options = this.props.application.getOptions();
77 const sanitized = Common.sanitizeText(event.target.value, options, 'lifeline');
79 id: this.props.lifeline.id,
82 this.props.designer.updateLifeline(props);
83 this.setState({ name: sanitized });
86 // ///////////////////////////////////////////////////////////////////////////////////////////////
89 * Handle lifeline delete.
92 this.props.designer.deleteLifeline(this.props.lifeline.id);
95 // ///////////////////////////////////////////////////////////////////////////////////////////////
98 * Handle mouseover event.
101 this.setState({ active: true });
102 this.props.designer.onMouseEnterLifeline(this.props.lifeline.id);
105 // ///////////////////////////////////////////////////////////////////////////////////////////////
108 * Handle mouseleave event.
111 this.setState({ active: false });
112 this.props.designer.onMouseLeaveLifeline(this.props.lifeline.id);
115 // ///////////////////////////////////////////////////////////////////////////////////////////////
118 * Get whether metadata permits reorder.
119 * @returns true if reorderable.
122 return this.canReorder;
125 // ///////////////////////////////////////////////////////////////////////////////////////////////
128 * Get whether metadata permits delete.
129 * @returns true if lifeline can be deleted.
132 return this.canDelete;
135 // ///////////////////////////////////////////////////////////////////////////////////////////////
143 const id = this.props.lifeline.id;
144 const activeClass = (this.props.active === true) ? 'asdcs-active' : '';
145 const { connectDragSource, connectDropTarget } = this.props;
146 return connectDragSource(connectDropTarget(
149 className={`asdcs-designer-lifeline ${activeClass}`}
151 onMouseEnter={this.onMouseEnter}
152 onMouseLeave={this.onMouseLeave}
154 <table className="asdcs-designer-layout asdcs-designer-lifeline-row1">
158 <div className="asdcs-designer-sort asdcs-designer-icon">
159 <Icon glyph={iconHandle} />
163 <div className="asdcs-designer-lifeline-index">{this.props.lifeline.index}.</div>
166 <div className="asdcs-designer-lifeline-name">
169 className="asdcs-editable"
170 placeholder="Unnamed"
171 value={this.state.name}
172 onChange={this.onChangeName}
173 onBlur={this.onBlurName}
178 <div className="asdcs-designer-delete asdcs-designer-icon" onClick={this.onClickDelete}>
179 <Icon glyph={iconDelete} />
191 * Declare properties.
193 Lifeline.propTypes = {
194 application: React.PropTypes.object.isRequired,
195 designer: React.PropTypes.object.isRequired,
196 lifeline: React.PropTypes.object.isRequired,
197 active: React.PropTypes.bool.isRequired,
198 metamodel: React.PropTypes.object.isRequired,
199 id: React.PropTypes.any.isRequired,
200 index: React.PropTypes.number.isRequired,
201 lifelines: React.PropTypes.object.isRequired,
202 isDragging: React.PropTypes.bool.isRequired,
203 connectDragSource: React.PropTypes.func.isRequired,
204 connectDropTarget: React.PropTypes.func.isRequired,
218 const sourceCollect = function collection(connect, monitor) {
220 connectDragSource: connect.dragSource(),
221 isDragging: monitor.isDragging(),
227 drop(props, monitor, component) {
228 Common.assertNotNull(props);
229 Common.assertNotNull(monitor);
230 const decorated = component.getDecoratedComponentInstance();
232 const lifelines = decorated.props.lifelines;
234 const dragIndex = monitor.getItem().index;
235 const hoverIndex = lifelines.getHoverIndex();
236 lifelines.onDrop(dragIndex, hoverIndex);
240 hover(props, monitor, component) {
241 Common.assertNotNull(props);
242 Common.assertNotNull(monitor);
244 const decorated = component.getDecoratedComponentInstance();
246 const lifelines = decorated.props.lifelines;
248 lifelines.setHoverIndex(decorated.props.index);
256 function targetCollect(connect, monitor) {
258 connectDropTarget: connect.dropTarget(),
259 isOver: monitor.isOver(),
263 const wrapper1 = DragSource('lifeline', source, sourceCollect)(Lifeline);
264 export default DropTarget(['lifeline', 'lifeline-new'], target, targetCollect)(wrapper1);