View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: AddNodeCommand.java
13   * Created: 2007-00-00
14   * Author: fox
15   * $Id: AddNodeCommand.java 3217 2009-08-19 12:00:08Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.command;
19  
20  
21  import org.eclipse.draw2d.geometry.Point;
22  import org.eclipse.gef.commands.Command;
23  import org.eclipse.osgi.util.NLS;
24  
25  import pl.edu.agh.cast.model.visual.backward.IDiagram;
26  import pl.edu.agh.cast.model.visual.backward.Node;
27  import pl.edu.agh.cast.util.Messages;
28  
29  /**
30   * Command for adding a {@link Node} to a diagram.
31   *
32   * @author AGH CAST Team
33   */
34  public class AddNodeCommand extends Command {
35  
36  	private IDiagram model;
37  
38  	private Point location;
39  
40  	private Node node;
41  
42  	private String imageId;
43  
44  	/**
45  	 * Creates new instance of command for adding a node to a diagram.
46  	 *
47  	 * @param model
48  	 *            the diagram
49  	 * @param node
50  	 *            the node to add
51  	 * @param location
52  	 *            location of the node
53  	 * @param imageId
54  	 *            id of node's icon image
55  	 */
56  	public AddNodeCommand(IDiagram model, Node node, Point location, String imageId) {
57  		this.model = model;
58  		this.location = location;
59  		this.imageId = imageId;
60  		this.node = node;
61  		setLabel(NLS.bind(Messages.SchemaCreationCommand_0, node.getLabel()));
62  	}
63  
64  	/**
65  	 * {@inheritDoc}
66  	 *
67  	 * @see org.eclipse.gef.commands.Command#execute()
68  	 */
69  	@Override
70  	public void execute() {
71  		node.setLocation(location);
72  		node.setImageId(imageId);
73  		model.addNode(node);
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 *
79  	 * @see org.eclipse.gef.commands.Command#undo()
80  	 */
81  	@Override
82  	public void undo() {
83  		model.removeNode(model.findNode(node.getId()));
84  	}
85  
86  }