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';
21 import Lifeline from './Lifeline';
22 import LifelineNew from './LifelineNew';
25 * Lifeline container, facilitating DND.
26 * @param props lifeline element properties.
30 export default class Lifelines extends React.Component {
32 // ///////////////////////////////////////////////////////////////////////////////////////////////
36 * @param props element properties.
37 * @param context react context.
39 constructor(props, context) {
40 super(props, context);
41 this.setHoverIndex = this.setHoverIndex.bind(this);
42 this.getHoverIndex = this.getHoverIndex.bind(this);
43 this.onDrop = this.onDrop.bind(this);
46 // ///////////////////////////////////////////////////////////////////////////////////////////////
49 * Record last hover index as non-state.
52 setHoverIndex(index) {
53 this.hoverIndex = index;
56 // ///////////////////////////////////////////////////////////////////////////////////////////////
59 * Get last recorded hover index.
63 return this.hoverIndex;
66 // ///////////////////////////////////////////////////////////////////////////////////////////////
70 * @param dragIndex dragged item index; undefined if new.
71 * @param hoverIndex drop index.
73 onDrop(dragIndex, hoverIndex) {
74 if (hoverIndex >= 0) {
75 const application = this.props.application;
76 const model = application.getModel();
77 if (Common.isNumber(dragIndex)) {
78 if (dragIndex !== hoverIndex) {
79 model.reorderLifelines(dragIndex, hoverIndex);
82 model.addLifeline(hoverIndex);
85 application.renderDiagram();
89 // ///////////////////////////////////////////////////////////////////////////////////////////////
96 const model = this.props.application.getModel();
97 const metamodel = model.getMetamodel();
98 const diagram = model.unwrap().diagram;
100 const lifelines = [];
101 for (const lifeline of diagram.lifelines) {
102 lifelines.push(<Lifeline
103 key={`l${lifeline.id}`}
104 application={this.props.application}
105 designer={this.props.designer}
107 active={this.props.activeLifelineId === lifeline.id}
109 metamodel={metamodel}
111 index={lifelines.length}
115 lifelines.push(<LifelineNew
117 designer={this.props.designer}
122 <div className="asdcs-designer-lifelines">
130 * Declare properties.
132 Lifelines.propTypes = {
133 application: React.PropTypes.object.isRequired,
134 designer: React.PropTypes.object.isRequired,
135 activeLifelineId: React.PropTypes.string,