2009-06-07 20:59:43 +02:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
|
|
|
*/
|
|
|
|
|
|
|
|
mindplot.commands.DeleteTopicCommand = mindplot.Command.extend(
|
|
|
|
{
|
|
|
|
initialize: function(topicsIds)
|
|
|
|
{
|
|
|
|
core.assert(topicsIds, "topicsIds must be defined");
|
2010-12-22 23:34:24 +01:00
|
|
|
this._selectedObjectsIds = topicsIds;
|
2009-06-07 20:59:43 +02:00
|
|
|
this._deletedTopicModels = [];
|
|
|
|
this._parentTopicIds = [];
|
2010-12-13 15:07:20 +01:00
|
|
|
this._deletedRelationships = [];
|
2009-06-07 20:59:43 +02:00
|
|
|
this._id = mindplot.Command._nextUUID();
|
|
|
|
},
|
|
|
|
execute: function(commandContext)
|
|
|
|
{
|
2010-12-22 23:34:24 +01:00
|
|
|
var topics = commandContext.findTopics(this._selectedObjectsIds.nodes);
|
|
|
|
if(topics.length>0){
|
2009-06-07 20:59:43 +02:00
|
|
|
topics.forEach(
|
|
|
|
function(topic, index)
|
|
|
|
{
|
|
|
|
var model = topic.getModel().clone();
|
2010-12-13 15:07:20 +01:00
|
|
|
|
|
|
|
//delete relationships
|
|
|
|
var relationships = topic.getRelationships();
|
|
|
|
while(relationships.length>0){
|
|
|
|
var relationship = relationships[0];
|
|
|
|
this._deletedRelationships.push(relationship.getModel().clone());
|
|
|
|
commandContext.removeRelationship(relationship.getModel());
|
|
|
|
}
|
|
|
|
|
2009-06-07 20:59:43 +02:00
|
|
|
this._deletedTopicModels.push(model);
|
|
|
|
|
|
|
|
// Is connected?.
|
|
|
|
var outTopic = topic.getOutgoingConnectedTopic();
|
|
|
|
var outTopicId = null;
|
|
|
|
if (outTopic != null)
|
|
|
|
{
|
|
|
|
outTopicId = outTopic.getId();
|
|
|
|
}
|
|
|
|
this._parentTopicIds.push(outTopicId);
|
|
|
|
|
|
|
|
// Finally, delete the topic from the workspace...
|
|
|
|
commandContext.deleteTopic(topic);
|
|
|
|
|
|
|
|
}.bind(this)
|
2010-12-22 23:34:24 +01:00
|
|
|
); }
|
|
|
|
var lines = commandContext.findRelationships(this._selectedObjectsIds.relationshipLines);
|
|
|
|
if(lines.length>0){
|
|
|
|
lines.forEach(function(line,index){
|
|
|
|
if(line.isInWorkspace()){
|
|
|
|
this._deletedRelationships.push(line.getModel().clone());
|
|
|
|
commandContext.removeRelationship(line.getModel());
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
},
|
|
|
|
undoExecute: function(commandContext)
|
|
|
|
{
|
|
|
|
|
2010-12-22 23:34:24 +01:00
|
|
|
var topics = commandContext.findTopics(this._selectedObjectsIds);
|
2009-06-07 20:59:43 +02:00
|
|
|
var parent = commandContext.findTopics(this._parentTopicIds);
|
|
|
|
|
|
|
|
this._deletedTopicModels.forEach(
|
|
|
|
function(model, index)
|
|
|
|
{
|
|
|
|
var topic = commandContext.createTopic(model);
|
|
|
|
|
|
|
|
// Was the topic connected?
|
|
|
|
var parentTopic = parent[index];
|
|
|
|
if (parentTopic != null)
|
|
|
|
{
|
|
|
|
commandContext.connect(topic, parentTopic);
|
|
|
|
}
|
|
|
|
|
|
|
|
}.bind(this)
|
2010-12-13 15:07:20 +01:00
|
|
|
);
|
|
|
|
this._deletedRelationships.forEach(
|
|
|
|
function(relationship, index){
|
|
|
|
commandContext.createRelationship(relationship);
|
|
|
|
}.bind(this));
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
this._deletedTopicModels = [];
|
|
|
|
this._parentTopicIds = [];
|
2010-12-13 15:07:20 +01:00
|
|
|
this._deletedRelationships = [];
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
});
|