1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
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  
35  
36  
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  }