orchestra
Rev 5841 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/**
* Bull SAS / OW2 Orchestra
* Copyright (C) 2010 Bull S.A.S, and individual contributors as indicated
* by the @authors tag.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
/*
* Generated by Gas3 v2.2.0 (Granite Data Services).
*
* NOTE: this file is only generated if it does not exist. You may safely put
* your custom code here.
*/
package org.ow2.orchestra.designer.bpmn.model {
import flash.utils.IDataInput;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
[Bindable]
[RemoteClass(alias="org.ow2.orchestra.designer.bpmn.model.ProcessModel")]
public class ProcessModel extends ProcessModelBase {
public function ProcessModel() {
super();
elements.addEventListener(CollectionEvent.COLLECTION_CHANGE, elementsModified);
}
// Add event listener for elements changes
public override function readExternal(input:IDataInput):void {
super.readExternal(input);
elements.addEventListener(CollectionEvent.COLLECTION_CHANGE, elementsModified);
for each (var element:AbstractElement in elements) {
element.onDeserializationComplete();
}
}
/**
* Listener for process element changes.
* Deletes sequence flow when the source or target element is removed.
* @param collectionEvent
*/
public function elementsModified(collectionEvent:CollectionEvent):void {
// model elements changed.
var changedElements:Array = collectionEvent.items;
if (collectionEvent.kind == CollectionEventKind.REMOVE) {
for each (var removedElement:Object in changedElements) {
if (removedElement is AbstractElementWithPosition) {
// remove sequenceFlow elements attached to the element to delete
// iterate on a copy of the elements list to avoid concurrent modifications
// (sequenceFlow are removed from the elements list)
var elementsCopy:ArrayCollection = new ArrayCollection();
elementsCopy.addAll(elements);
for each (var element:Object in elementsCopy) {
if (element is SequenceFlowModel) {
var sequenceFlowModel:SequenceFlowModel = element as SequenceFlowModel;
if (sequenceFlowModel.sourceElement == removedElement || sequenceFlowModel.targetElement == removedElement) {
// remove sequence flow
elements.removeItemAt(elements.getItemIndex(sequenceFlowModel));
}
}
}
if (removedElement is EventModel) {
// remove operation if element is deleted
EventModel(removedElement).operation = null;
} else if (removedElement is PoolModel) {
for each (var abstractElement:AbstractElement in this.elements) {
//Check tasks related to this pool
if ((abstractElement is TaskModel) &&
TaskModel(abstractElement).operation != null &&
TaskModel(abstractElement).operation.interfaceModel != null &&
PoolModel(removedElement).interfaces.containsValue(
TaskModel(abstractElement).operation.interfaceModel)) {
TaskModel(abstractElement).operation = null;
}
}
}
} else if (removedElement is SequenceFlowModel) {
var removedSequenceFlowModel:SequenceFlowModel = removedElement as SequenceFlowModel;
// Remove from old source outgoing sequence flows list
var oldSource:AbstractElementWithPosition = removedSequenceFlowModel.sourceElement;
if (oldSource != null) {
var srcIndex:int = oldSource.outgoingSequenceFlows.getItemIndex(removedSequenceFlowModel);
if (srcIndex != -1) {
oldSource.outgoingSequenceFlows.removeItemAt(srcIndex);
}
}
// Remove from old target incoming sequence flows list
var oldTarget:AbstractElementWithPosition = removedSequenceFlowModel.targetElement;
if (oldTarget != null) {
var targetIndex:int = oldTarget.incomingSequenceFlows.getItemIndex(removedSequenceFlowModel);
if (targetIndex != -1) {
oldTarget.incomingSequenceFlows.removeItemAt(targetIndex);
}
}
}
}
}
}
}
}