Package org.eclipse.sapphire.ui.swt.gef.policies

Source Code of org.eclipse.sapphire.ui.swt.gef.policies.NodeLabelDirectEditPolicy

/******************************************************************************
* Copyright (c) 2014 Oracle
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    Ling Hao - initial implementation and ongoing maintenance
******************************************************************************/

package org.eclipse.sapphire.ui.swt.gef.policies;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.requests.DirectEditRequest;
import org.eclipse.sapphire.ui.diagram.editor.TextPart;
import org.eclipse.sapphire.ui.swt.gef.commands.LabelNodeCommand;
import org.eclipse.sapphire.ui.swt.gef.parts.DiagramNodeEditPart;

/**
* @author <a href="mailto:ling.hao@oracle.com">Ling Hao</a>
*/

public class NodeLabelDirectEditPolicy extends DirectEditPolicy {

  /**
   * @see DirectEditPolicy#getDirectEditCommand(DirectEditRequest)
   */
  protected Command getDirectEditCommand(DirectEditRequest edit) {
    String labelText = (String) edit.getCellEditor().getValue();
    TextPart textPart = (TextPart)edit.getExtendedData().get(DiagramNodeEditPart.DIRECT_EDIT_REQUEST_PARAM);
    if (textPart != null)
    {
      LabelNodeCommand command = new LabelNodeCommand(textPart, labelText);
      return command;
    }
    return null;
  }

  /**
   * @see DirectEditPolicy#showCurrentEditValue(DirectEditRequest)
   */
  protected void showCurrentEditValue(DirectEditRequest request) {
    // hack to prevent async layout from placing the cell editor twice.
    getHostFigure().getUpdateManager().performUpdate();

  }

}
TOP

Related Classes of org.eclipse.sapphire.ui.swt.gef.policies.NodeLabelDirectEditPolicy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.