View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.command.dnd;
19  
20  import java.util.List;
21  
22  import org.vectomatic.svg.edit.client.command.CommandFactories;
23  import org.vectomatic.svg.edit.client.command.DndCommandFactory.DropGesture;
24  import org.vectomatic.svg.edit.client.command.GenericRemoveCommand;
25  import org.vectomatic.svg.edit.client.command.ICommand;
26  import org.vectomatic.svg.edit.client.engine.SVGModel;
27  import org.vectomatic.svg.edit.client.model.ModelConstants;
28  import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
29  import org.vectomatic.svg.edit.client.model.svg.SVGNamedElementModel;
30  
31  import com.extjs.gxt.ui.client.util.Format;
32  
33  /**
34   * Class to manage intra-model reorder drag-and-drop interactions
35   * and inter-model move drag-and-drop interactions 
36   * @author laaglu
37   */
38  public class DndMoveHandler extends DndHandlerBase {
39  
40  	@Override
41  	public String getOperationCssAttr() {
42  		return "move";
43  	}
44  	
45  	@Override
46  	public String getMessage(List<SVGElementModel> sourceElements) {
47  		return Format.substitute(ModelConstants.INSTANCE.dndMove(), getSourceElementNames(sourceElements));
48  	}
49  
50  	@Override
51  	public void createCommands(List<SVGElementModel> sourceElements, SVGElementModel target, DropGesture dropGesture) {
52  		SVGModel src = sourceElements.get(0).getOwner();
53  		SVGModel dest = target.getOwner();
54  		if (src == dest) {
55  			ICommand command = new ReorderCommand(sourceElements, target, dropGesture);
56  			command.commit();
57  			src.getCommandStore().addCommand(command);
58  		} else {
59  			String description = null;
60  			switch(dropGesture) {
61  				case OnNode:
62  					description = ModelConstants.INSTANCE.dndMoveCmdDestIn();
63  					break;
64  				case BeforeNode:
65  					description = ModelConstants.INSTANCE.dndMoveCmdDestBefore();
66  					break;
67  				case AfterNode:
68  					description = ModelConstants.INSTANCE.dndMoveCmdDestAfter();
69  					break;
70  			}
71  			description = Format.substitute(description, SVGNamedElementModel.getNames(sourceElements), target.toString(), ((SVGNamedElementModel)src.getRoot()).getName());
72  			ICommand copyCommand = new CopyCommand(sourceElements, target, dropGesture, description);
73  			copyCommand.commit();
74  			ICommand removeCommand = new GenericRemoveCommand(CommandFactories.getDndCommandFactory(), sourceElements, Format.substitute(ModelConstants.INSTANCE.dndMoveCmdSrc(), SVGNamedElementModel.getNames(sourceElements), ((SVGNamedElementModel)dest.getRoot()).getName()));
75  			removeCommand.commit();
76  			dest.getCommandStore().addCommand(copyCommand);
77  			src.getCommandStore().addCommand(removeCommand);
78  		}
79  	}
80  }