/* * Created on Jul 18, 2004 */ package com.windowtester.examples.gef.uml.policies; import org.eclipse.gef.commands.Command; import org.eclipse.gef.editpolicies.DirectEditPolicy; import org.eclipse.gef.requests.DirectEditRequest; import org.eclipse.jface.viewers.CellEditor; import com.realpersist.gef.command.ChangeTableNameCommand; import com.realpersist.gef.model.Table; import com.realpersist.gef.part.TablePart; /** * EditPolicy for the direct editing of table names * * @author Phil Zoio * * TODO: finish and wire up! * */ public class ClassElementDirectEditPolicy extends DirectEditPolicy { private String oldValue; /** * @see DirectEditPolicy#getDirectEditCommand(org.eclipse.gef.requests.DirectEditRequest) */ protected Command getDirectEditCommand(DirectEditRequest request) { ChangeTableNameCommand cmd = new ChangeTableNameCommand(); Table table = (Table) getHost().getModel(); cmd.setTable(table); cmd.setOldName(table.getName()); CellEditor cellEditor = request.getCellEditor(); cmd.setName((String) cellEditor.getValue()); return cmd; } /** * @see DirectEditPolicy#showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest) */ protected void showCurrentEditValue(DirectEditRequest request) { String value = (String) request.getCellEditor().getValue(); TablePart tablePart = (TablePart) getHost(); tablePart.handleNameChange(value); } /** * @param to * Saves the initial text value so that if the user's changes are not committed then */ protected void storeOldEditValue(DirectEditRequest request) { CellEditor cellEditor = request.getCellEditor(); oldValue = (String) cellEditor.getValue(); } /** * @param request */ protected void revertOldEditValue(DirectEditRequest request) { CellEditor cellEditor = request.getCellEditor(); cellEditor.setValue(oldValue); TablePart tablePart = (TablePart) getHost(); tablePart.revertNameChange(); } }