Java 类org.eclipse.gef.tools.AbstractTool 实例源码

项目:d-case_editor    文件:ModuleUtil.java   
/**
 * Returns the current cursor location for Diagram.
 * 
 * @param argumentEditPart
 *            the argument edit part.
 * @return the current point.
 */
public static Point getCurrentLocation(ArgumentEditPart argumentEditPart) {
    IDiagramGraphicalViewer viewer = DcaseEditorUtil
            .getCurrentDcaseEditor().getDiagramGraphicalViewer();
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
    // the position of scrollable diagram.
    Point viewPoint = canvas.getViewport().getViewLocation();
    Tool tool = argumentEditPart.getViewer().getEditDomain()
            .getActiveTool();
    AbstractTool aTool = (AbstractTool) tool;
    Point toolLocation = null;
    try {
        Method method = AbstractTool.class.getDeclaredMethod("getLocation"); //$NON-NLS-1$
        method.setAccessible(true);
        toolLocation = ((org.eclipse.draw2d.geometry.Point) method
                .invoke(aTool)).getCopy();
    } catch (Exception e) {
        MessageWriter.writeMessageToConsole(
                Messages.AddPatternContributionItem_0,
                MessageTypeImpl.CREATE_PATTERN_FAILED);
        return new Point(0, 0);
    }
    return new Point(viewPoint.x + toolLocation.x, viewPoint.y
            + toolLocation.y);
}