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: NodeDirectEditPolicy.java
13   * Created: 2007-00-00
14   * Author: awos
15   * $Id: NodeDirectEditPolicy.java 3217 2009-08-19 12:00:08Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.policy;
19  
20  import org.eclipse.gef.EditPart;
21  import org.eclipse.gef.commands.Command;
22  import org.eclipse.gef.editpolicies.DirectEditPolicy;
23  import org.eclipse.gef.requests.DirectEditRequest;
24  
25  import pl.edu.agh.cast.backward.command.LabelCommand;
26  import pl.edu.agh.cast.model.attributes.Attribute;
27  import pl.edu.agh.cast.model.visual.backward.Node;
28  
29  /**
30   * Provides a direct edit policy for an edit part. The edit part must have a model of type {@link Node}.
31   *
32   * @author AGH CAST Team
33   */
34  public class NodeDirectEditPolicy extends DirectEditPolicy {
35  
36  	public static final String EDITED_ATTRIBUTE_ID = "EDITED_ATTRIBUTE_ID"; //$NON-NLS-1$
37  
38  	/**
39  	 * {@inheritDoc}
40  	 *
41  	 * @see org.eclipse.gef.editpolicies.DirectEditPolicy
42  	 *      #getDirectEditCommand(org.eclipse.gef.requests.DirectEditRequest)
43  	 */
44  	@Override
45  	protected Command getDirectEditCommand(DirectEditRequest edit) {
46  		String labelText = (String)edit.getCellEditor().getValue();
47  		EditPart editPart = getHost();
48  		Node node = (Node)editPart.getModel();
49  
50  		/**
51  		 * Find first isShowAsLabel attribute of the node to set the value from DirectEditRequest. This is the only
52  		 * possible case in which this can happen - this must be ensured by SchemaNodeEditPart's performRequest.
53  		 */
54  		Attribute labelAttrib = null;
55  		for (Attribute a : node.getAttributeManager().getAttributes()) {
56  			if (a.isShowAsLabel()) {
57  				labelAttrib = a;
58  				break;
59  			}
60  		}
61  
62  		LabelCommand command = new LabelCommand(node, labelAttrib.getName(), labelText);
63  		return command;
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 *
69  	 * @see org.eclipse.gef.editpolicies.DirectEditPolicy
70  	 *      #showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest)
71  	 */
72  	@Override
73  	protected void showCurrentEditValue(DirectEditRequest request) {
74  		// do nothing; the editor covers the figure anyway, and the value
75  		// is shown there
76  	}
77  
78  }