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

Source Code of org.eclipse.sapphire.ui.swt.gef.commands.MoveConnectionLabelCommand

/******************************************************************************
* 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.commands;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.eclipse.sapphire.ui.swt.gef.parts.DiagramConnectionLabelEditPart;
import org.eclipse.sapphire.ui.swt.gef.parts.SapphireMidpointLocator;

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

public class MoveConnectionLabelCommand extends Command {
 
  private DiagramConnectionLabelEditPart editPart;
  private Rectangle rectangle;

  public MoveConnectionLabelCommand(DiagramConnectionLabelEditPart editPart, Rectangle rectangle) {
    this.editPart = editPart;
    this.rectangle = rectangle;
  }

  @Override
  public void execute() {
    int x = rectangle.x;
    int y = rectangle.y;
    Connection connection = (Connection)editPart.getFigure().getParent();
    SapphireMidpointLocator location = new SapphireMidpointLocator(editPart.getConfigurationManager(), connection);
    Point midpoint = location.getMidpoint();
    midpoint = editPart.getConfigurationManager().getDiagramEditor().calculateRealMouseLocation(midpoint);
    org.eclipse.sapphire.ui.Point newPos = new org.eclipse.sapphire.ui.Point(x - midpoint.x, y - midpoint.y);
    editPart.getDiagramConnectionPart().setLabelPosition(newPos);
  }
 
}
TOP

Related Classes of org.eclipse.sapphire.ui.swt.gef.commands.MoveConnectionLabelCommand

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.