blob: c1695de52daca1075cd09c1e489f52135c92ef6f [file] [log] [blame]
/**
*
*/
package org.eclipse.epf.diagramming.base.policies;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.epf.diagramming.base.commands.EditNameCommand;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.DirectEditRequest;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
import org.eclipse.gmf.runtime.gef.ui.internal.parts.TextCellEditorEx;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ObjectNode;
/**
* @author Shashidhar Kannoori
*
*/
public class ViewLabelDirectEditPolicy extends LabelDirectEditPolicy {
protected Command getDirectEditCommand(DirectEditRequest edit) {
Command command;
command = super.getDirectEditCommand(edit);
// stitch the uma command to change the name on uma side.
if (command != null) {
if (edit.getCellEditor() instanceof TextCellEditorEx)
if (!((TextCellEditorEx) edit.getCellEditor())
.hasValueChanged())
return null;
String labelText = (String) edit.getCellEditor().getValue();
ITextAwareEditPart compartment = (ITextAwareEditPart) getHost();
EObject model = (EObject) compartment.getModel();
EObject umlObject = null;
if (model instanceof View) {
View view = (View) model;
umlObject = ViewUtil.resolveSemanticElement(view);
if (umlObject instanceof ActivityNode) {
command = command.chain(new EditNameCommand(
(ActivityNode) umlObject, labelText));
}
if (umlObject instanceof ObjectNode) {
command = command.chain(new EditNameCommand(
(ObjectNode) umlObject, labelText));
}
}
}
return command;
}
}