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: LabelCommand.java
13   * Created: 2007-00-00
14   * Author: njord, awos
15   * $Id: LabelCommand.java 3217 2009-08-19 12:00:08Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.command;
19  
20  import org.eclipse.gef.commands.Command;
21  import org.eclipse.osgi.util.NLS;
22  
23  import pl.edu.agh.cast.model.visual.backward.Node;
24  import pl.edu.agh.cast.util.Messages;
25  
26  /**
27   * Changes value of a single attribute of a given node. Used to change its label (produced by
28   * {@link pl.edu.agh.cast.policy.NodeDirectEditPolicy}).
29   *
30   * @author AGH CAST Team
31   */
32  public class LabelCommand extends Command {
33  
34  	private String oldName;
35  
36  	private String newName;
37  
38  	private Node node;
39  
40  	private String attribuedId;
41  
42  	/**
43  	 * Creates new instance of label command.
44  	 *
45  	 * @param node
46  	 *            {@link Node} to modify
47  	 * @param attributeId
48  	 *            id of the node's attribute to modify
49  	 * @param newValue
50  	 *            new value of the attribute
51  	 */
52  	public LabelCommand(Node node, String attributeId, String newValue) {
53  		this.node = node;
54  		this.attribuedId = attributeId;
55  		if (newValue != null) {
56  			newName = newValue;
57  		} else {
58  			newName = ""; //$NON-NLS-1$
59  		}
60  		setLabel(NLS.bind(Messages.LabelCommand_1, node.getLabel(), newName));
61  	}
62  
63  	/**
64  	 * {@inheritDoc}
65  	 *
66  	 * @see org.eclipse.gef.commands.Command#execute()
67  	 */
68  	@Override
69  	public void execute() {
70  		oldName = node.getLabel();
71  		node.setAttributeValue(attribuedId, newName);
72  	}
73  
74  	/**
75  	 * {@inheritDoc}
76  	 *
77  	 * @see org.eclipse.gef.commands.Command#undo()
78  	 */
79  	@Override
80  	public void undo() {
81  		node.setAttributeValue(attribuedId, oldName);
82  	}
83  
84  }