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: RenameDiagramCommand.java
13   * Created: 2007-00-00
14   * Author: awos
15   * $Id: RenameDiagramCommand.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.gef.commands.Command;
22  import org.eclipse.osgi.util.NLS;
23  
24  import pl.edu.agh.cast.model.visual.backward.IDiagram;
25  import pl.edu.agh.cast.util.Messages;
26  
27  /**
28   * Command to rename a diagram.
29   *
30   * @author AGH CAST Team
31   */
32  public class RenameDiagramCommand extends Command {
33  
34  	private String newName;
35  
36  	private String oldName;
37  
38  	private IDiagram diagram;
39  
40  	/**
41  	 * Creates new instance of the diagram rename command.
42  	 *
43  	 * @param diagram
44  	 *            the diagram to rename
45  	 * @param newName
46  	 *            the new name of the diagram
47  	 */
48  	public RenameDiagramCommand(IDiagram diagram, String newName) {
49  		this.diagram = diagram;
50  		this.newName = newName;
51  		this.oldName = diagram.getDisplayName();
52  	}
53  
54  	/**
55  	 * {@inheritDoc}
56  	 *
57  	 * @see org.eclipse.gef.commands.Command#execute()
58  	 */
59  	@Override
60  	public void execute() {
61  		diagram.setDisplayName(newName);
62  	}
63  
64  	/**
65  	 * {@inheritDoc}
66  	 *
67  	 * @see org.eclipse.gef.commands.Command#undo()
68  	 */
69  	@Override
70  	public void undo() {
71  		diagram.setDisplayName(oldName);
72  	}
73  
74  	/**
75  	 * {@inheritDoc}
76  	 *
77  	 * @see org.eclipse.gef.commands.Command#getLabel()
78  	 */
79  	@Override
80  	public String getLabel() {
81  		return NLS.bind(Messages.RenameDiagramCommand_0, new Object[] { oldName, newName });
82  	}
83  
84  }