Java Code Examples for org.eclipse.draw2d.PositionConstants#EAST

The following examples show how to use org.eclipse.draw2d.PositionConstants#EAST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellDragoicator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param reference
 * @param location
 */
public CellDragoicator( IFigure reference, int location )
{
	setReferenceFigure( reference );
	switch ( location & PositionConstants.NORTH_SOUTH )
	{
		case PositionConstants.SOUTH :
			relativeY = 1.0;
			break;
		default :
			relativeY = 0;
	}

	switch ( location & PositionConstants.EAST_WEST )
	{
		case PositionConstants.EAST :
			relativeX = 1.0;
			break;
		default :
			relativeX = 0;
	}
}
 
Example 2
Source File: CustomResizeHandle.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the handle with fill color and outline color dependent on the
 * primary selection status of the owner editpart.
 * 
 * @param g
 *            The graphics used to paint the figure.
 */
public void paintFigure(Graphics g) {
	Rectangle r = getBounds() ;
	switch (cursorDirection) {
	case PositionConstants.SOUTH_EAST:
		g.drawImage(Pics.getImage("resize_SE.gif"),r.getLocation()) ;
		break;
	case PositionConstants.NORTH:
		g.drawImage(Pics.getImage("resize_N.gif"),r.getLocation().translate(0, -2)) ;
		break;
	case PositionConstants.SOUTH:
		g.drawImage(Pics.getImage("resize_S.gif"),r.getLocation().translate(0, 5)) ;
		break;
	case PositionConstants.WEST:
		g.drawImage(Pics.getImage("resize_W.gif"),r.getLocation().translate(-2, 0)) ;
		break;
	case PositionConstants.EAST:
		g.drawImage(Pics.getImage("resize_E.gif"),r.getLocation().translate(5, 0)) ;
		break;
	default:
		break;
	}


}
 
Example 3
Source File: ReportResizeTracker.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private Dimension getFigureSize()
{
	IFigure figure = getOwner( ).getFigure( );
	Dimension dim = figure.getSize( );
	if (figure instanceof IOutsideBorder)
	{
		Border border = ((IOutsideBorder)figure).getOutsideBorder( );
		Insets insets = border.getInsets( figure );
		if (PositionConstants.EAST == getResizeDirection())
		{
			dim.width = dim.width - insets.right - insets.left;
		}
		else if (PositionConstants.SOUTH == getResizeDirection())
		{
			dim.height = dim.height - insets.bottom - insets.top;
		}
	}
	return dim;
}
 
Example 4
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines the relative to rectangle geographic location of a point.
 * Example: If shape is closer to the the top edge of the rectangle location
 * would be north.
 * Method used to determine which side of shape's bounding rectangle is closer
 * to connection's anchor point.
 * All geometric quantities must be in the same coordinate system.
 * 
 * @param anchorPoint location of the anchor point
 * @param rect bounding rectangle of the shape
 * @return
 */
private int getAnchorOffRectangleDirection(Point anchorPoint, Rectangle rect) {
    int position = PositionConstants.NORTH;
    int criteriaValue = Math.abs(anchorPoint.y - rect.y);
    int tempCriteria = Math.abs(anchorPoint.y - rect.y - rect.height);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.SOUTH;
    }

    tempCriteria = Math.abs(anchorPoint.x - rect.x);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.WEST;
    }

    tempCriteria = Math.abs(anchorPoint.x - rect.x - rect.width);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.EAST;
    }

    return position;
}
 
Example 5
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the coordinates of the connection anchor point the shape's rectangle and the
 * orientation of the first rectilinear connection segment that comes out from the anchor
 * point the method detemines on which geographic side of the rectangle the anchor point
 * is located on.
 * 
 * @param anchorPoint coordinates of the anchor point
 * @param rectangle the shape's bounding rectangle
 * @param segmentOrientation orinetation of the segment coming out from the anchor point
 * @return geographic position of the anchor point relative to the rectangle
 */
private int getAnchorLocationBasedOnSegmentOrientation(Point anchorPoint, Rectangle rectangle, int segmentOrientation) {
    if (segmentOrientation == PositionConstants.VERTICAL) {
        if (Math.abs(anchorPoint.y - rectangle.y) < Math.abs(anchorPoint.y - rectangle.y - rectangle.height)) {
            return PositionConstants.NORTH;
        } else {
            return PositionConstants.SOUTH;
        }
    } else if (segmentOrientation == PositionConstants.HORIZONTAL) {
        if (Math.abs(anchorPoint.x - rectangle.x) < Math.abs(anchorPoint.x - rectangle.x - rectangle.width)) {
            return PositionConstants.WEST;
        } else {
            return PositionConstants.EAST;
        }
    }
    return PositionConstants.NONE;
}
 
Example 6
Source File: DesignElementHandleAdapter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 *  Get the position from string
 * @param position
 * 	  The given string
 * @return
 *    The position
 */
public static int getPosition( String position )
{
	if ( DesignChoiceConstants.BACKGROUND_POSITION_LEFT.equals( position ) )
	{
		return PositionConstants.WEST;
	}
	if ( DesignChoiceConstants.BACKGROUND_POSITION_RIGHT.equals( position ) )
	{
		return PositionConstants.EAST;
	}
	if ( DesignChoiceConstants.BACKGROUND_POSITION_TOP.equals( position ) )
	{
		return PositionConstants.NORTH;
	}
	if ( DesignChoiceConstants.BACKGROUND_POSITION_BOTTOM.equals( position ) )
	{
		return PositionConstants.SOUTH;
	}
	return PositionConstants.CENTER;
}
 
Example 7
Source File: CrosstavCellDragHandle.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setBounds( Rectangle rect )
{
	if (start == end && cursorDirection == PositionConstants.SOUTH)
	{
		rect.y = rect.y - rect.height; 
	}
	else if (start == end && cursorDirection == PositionConstants.EAST)
	{
		rect.x = rect.x - rect.width;
	}
	super.setBounds( rect );
}
 
Example 8
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Point computeTargetLocation(final String pSourceElement, final int pOrientation) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pSourceElement);
    Assert.assertNotNull("Error: No Edit Part \'" + pSourceElement + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    switch (pOrientation) {
        case PositionConstants.NORTH:
            return graphicalEditPart.getFigure().getBounds().getTop().getCopy().translate(-30, -70);
        case PositionConstants.SOUTH:
            return graphicalEditPart.getFigure().getBounds().getBottom().getCopy().translate(-30, 70);
        case PositionConstants.WEST:
            return graphicalEditPart.getFigure().getBounds().getTopLeft().getCopy().translate(-140, 0);
        case PositionConstants.EAST:
            return graphicalEditPart.getFigure().getBounds().getTopRight().getCopy().translate(80, 0);
        case PositionConstants.NORTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getTopRight().getCopy().translate(80, -70);
        case PositionConstants.NORTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getTopLeft().getCopy().translate(-80, 70);
        case PositionConstants.SOUTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getBottomRight().getCopy().translate(-80, 70);
        case PositionConstants.SOUTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getBottomLeft().getCopy().translate(80, -70);
        default:
            throw new RuntimeException("Invalid position specified");
    }

}
 
Example 9
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a translation dimension for the anchor point. Translation dimension
 * translates the anchor point off the shape. The off shape direction
 * is specified by the relative to the shape geographic position of the anchor
 * 
 * @param position relative to the shape geographic position of the anchor
 * @param xFactorValue translation value along x-axis
 * @param yFactorValue translation value along y-axis
 * @return
 */
private Dimension getTranslationValue(int position, int xFactorValue, int yFactorValue) {
    Dimension translationDimension = new Dimension();
    if (position == PositionConstants.EAST) {
        translationDimension.width = xFactorValue;
    } else if (position == PositionConstants.SOUTH) {
        translationDimension.height = yFactorValue;
    } else if (position == PositionConstants.WEST) {
        translationDimension.width = -xFactorValue;
    } else if (position == PositionConstants.NORTH) {
        translationDimension.height = -yFactorValue;
    }
    return translationDimension;
}
 
Example 10
Source File: CrosstavCellDragHandle.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected DragTracker createDragTracker( )
{
	CrosstabHandleAdapter adapter = ((CrosstabTableEditPart)getOwner( ).getParent( )).getCrosstabHandleAdapter( );
	if (cursorDirection == PositionConstants.EAST && 
			(adapter.getColumnOprationCell( start )!=null||adapter.getColumnOprationCell( end )!=null))
	{
		return new CrosstabColumnDragTracker(getOwner( ), start, end);
	}
	if (cursorDirection == PositionConstants.SOUTH && adapter.getRowOprationCell( start ) != null)
	{
		return new CrosstabRowDragTracker(getOwner( ), start, end);
	}
	//return null;
	return new ResizeTracker( getOwner( ), cursorDirection )
	{
		protected void showTargetFeedback() 
		{
			
		}
		protected void eraseTargetFeedback() 
		{
		
		}
		
		protected void showSourceFeedback( )
		{
		}
		
		protected void eraseSourceFeedback( )
		{
		}
		
		protected Command getCommand( )
		{
			return UnexecutableCommand.INSTANCE;
		}
	};
}
 
Example 11
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether the rectilinear line segment coming out of the shape should be
 * horizontal or vertical based on the anchor geographic position relative to the shape
 * 
 * @param anchorRelativeLocation
 * @return
 */
private int getOffShapeDirection(int anchorRelativeLocation) {
    if (anchorRelativeLocation == PositionConstants.EAST || anchorRelativeLocation == PositionConstants.WEST) {
        return PositionConstants.HORIZONTAL;
    } else if (anchorRelativeLocation == PositionConstants.NORTH || anchorRelativeLocation == PositionConstants.SOUTH) {
        return PositionConstants.VERTICAL;
    }
    return PositionConstants.NONE;
}
 
Example 12
Source File: ReportResizeTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ReportResizeTracker( GraphicalEditPart owner, int direction )
{
	super( owner, direction );
	if (PositionConstants.EAST == direction || PositionConstants.SOUTH == direction)
	{
		processor = new ShowDragInfomationProcessor(owner);
	}
}
 
Example 13
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates geographic position of a point located outside the given rectangle relative
 * to the rectangle
 * 
 * @param p point outside of rectangle
 * @param r the rectangle
 * @return geographic position of the point relative to the recatangle
 */
private int getOutisePointOffRectanglePosition(Point p, Rectangle r) {
    int position = PositionConstants.NONE;
    if (r.x > p.x) {
        position |= PositionConstants.WEST;
    } else if (r.x + r.width < p.x) {
        position |= PositionConstants.EAST;
    }
    if (r.y > p.y) {
        position |= PositionConstants.NORTH;
    } else if (r.y + r.height < p.y) {
        position |= PositionConstants.SOUTH;
    }
    return position;
}
 
Example 14
Source File: ReportRootEditPart.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns <code>true</code> if the given point is outside the
 * viewport or near its edge. Scrolls the viewport by a calculated (time
 * based) amount in the current direction.
 * 
 * todo: investigate if we should allow auto expose when the pointer is
 * outside the viewport
 * 
 * @see org.eclipse.gef.AutoexposeHelper#step(org.eclipse.draw2d.geometry.Point)
 */
public boolean step( Point where )
{
	Viewport port = findViewport( owner );

	Rectangle rect = Rectangle.SINGLETON;
	port.getClientArea( rect );
	port.translateToParent( rect );
	port.translateToAbsolute( rect );
	if ( !rect.contains( where )
			|| rect.crop( threshold ).contains( where ) )
		return false;

	// set scroll offset (speed factor)
	int scrollOffset = 0;

	// calculate time based scroll offset
	if ( lastStepTime == 0 )
		lastStepTime = System.currentTimeMillis( );

	DeferredGraphicalViewer.OriginStepData stepData = ( (DeferredGraphicalViewer) owner.getViewer( ) ).getOriginStepData( );
	long difference = System.currentTimeMillis( ) - lastStepTime;

	if ( difference > 0 )
	{
		scrollOffset = ( (int) difference / 3 );
		lastStepTime = System.currentTimeMillis( );
	}

	if ( scrollOffset == 0 )
		return true;

	rect.crop( threshold );

	int region = rect.getPosition( where );
	Point loc = port.getViewLocation( );

	if ( ( region & PositionConstants.SOUTH ) != 0 )
		loc.y += scrollOffset;
	else if ( ( region & PositionConstants.NORTH ) != 0 )
		loc.y -= scrollOffset;

	if ( ( region & PositionConstants.EAST ) != 0 )
		loc.x += scrollOffset;
	else if ( ( region & PositionConstants.WEST ) != 0 )
		loc.x -= scrollOffset;

	if ( stepData.minX > loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.maxX - stepData.extendX < loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.minY > loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	if ( stepData.maxY - stepData.extendY < loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	port.setViewLocation( loc );

	return true;
}
 
Example 15
Source File: Helper.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public static int convertPosition ( final String position, final int defaultValue )
{
    if ( "CENTER".equals ( position ) )
    {
        return PositionConstants.CENTER;
    }
    else if ( "LEFT".equals ( position ) )
    {
        return PositionConstants.LEFT;
    }
    else if ( "RIGHT".equals ( position ) )
    {
        return PositionConstants.RIGHT;
    }
    else if ( "TOP".equals ( position ) )
    {
        return PositionConstants.TOP;
    }
    else if ( "BOTTOM".equals ( position ) )
    {
        return PositionConstants.BOTTOM;
    }
    else if ( "EAST".equals ( position ) )
    {
        return PositionConstants.EAST;
    }
    else if ( "WEST".equals ( position ) )
    {
        return PositionConstants.WEST;
    }
    else if ( "NORTH".equals ( position ) )
    {
        return PositionConstants.NORTH;
    }
    else if ( "SOUTH".equals ( position ) )
    {
        return PositionConstants.SOUTH;
    }

    return defaultValue;
}
 
Example 16
Source File: CustomResizeHandle.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected DragTracker createDragTracker() {
	return new ResizeTracker(getOwner(), cursorDirection){
		@Override
		protected void updateSourceRequest() {
			ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
			Dimension d = getDragMoveDelta();

			Point location = new Point(getLocation());
			Point moveDelta = new Point(0, 0);
			Dimension resizeDelta = new Dimension(0, 0);

			if (getOwner() != null) {

				if(isContrained){
					request.setConstrainedResize(true);
					int origHeight = getOwner().getFigure().getBounds().height;
					int origWidth = getOwner().getFigure().getBounds().width;
					float ratio = 1;

					if (origWidth != 0 && origHeight != 0)
						ratio = ((float) origHeight / (float) origWidth);

					if (getResizeDirection() == PositionConstants.SOUTH_EAST) {
						if (d.height > (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_WEST) {
						if (d.height < (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_EAST) {
						if (-(d.height) > (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.SOUTH_WEST) {
						if (-(d.height) < (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					}
				}
			}else{
				request.setConstrainedResize(false);
			}

			request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

			if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.height -= d.height;
				}
				moveDelta.y += d.height;
				resizeDelta.height -= d.height;
			}
			if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.y -= d.height;
					resizeDelta.height += d.height;
				}
				resizeDelta.height += d.height;
			}
			if ((getResizeDirection() & PositionConstants.WEST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.width -= d.width;
				}
				moveDelta.x += d.width;
				resizeDelta.width -= d.width;
			}
			if ((getResizeDirection() & PositionConstants.EAST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.x -= d.width;
					resizeDelta.width += d.width;
				}
				resizeDelta.width += d.width;
			}

			request.setMoveDelta(moveDelta);
			request.setSizeDelta(resizeDelta);
			request.setLocation(location);
			request.setEditParts(getOperationSet());

			request.getExtendedData().clear();
		}

		@Override
		protected List<IGraphicalEditPart> createOperationSet() {
			ArrayList<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>();
			for (Object selection : getCurrentViewer().getSelectedEditParts()) {
				if (isResizable((IGraphicalEditPart)selection)) {
					res.add((IGraphicalEditPart)selection);
				}
			}
			return res;
		}
	};
}
 
Example 17
Source File: ReportElementResizablePolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
 */
protected List createSelectionHandles( )
{
	List list = new ArrayList( );

	if ( this.getResizeDirections( ) != -1 )
	{
		ReportResizableHandleKit.addMoveHandle( (GraphicalEditPart) getHost( ), list );
		if ( ( this.getResizeDirections( ) & PositionConstants.EAST ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.EAST );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH_EAST ) == PositionConstants.SOUTH_EAST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH_EAST );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH_WEST ) == PositionConstants.SOUTH_WEST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH_WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.WEST ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH_WEST ) == PositionConstants.NORTH_WEST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH_WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH_EAST ) == PositionConstants.NORTH_EAST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH_EAST );
	}
	else
		ReportResizableHandleKit.addHandles( (GraphicalEditPart) getHost( ), list );

	return list;
}
 
Example 18
Source File: TableFigure.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	if ( isOpaque( ) )
	{
		if ( getBorder( ) instanceof BaseBorder )
		{
			graphics.fillRectangle( getBounds( ).getCopy( )
					.crop( ( (BaseBorder) getBorder( ) ).getBorderInsets( ) ) );
		}
		else
		{
			graphics.fillRectangle( getBounds( ) );
		}
	}

	Image image = getImage( );
	if ( image == null )
	{
		return;
	}

	int x, y;
	Rectangle area = getBounds( );

	// Calculates X
	if ( position != null && position.x != -1 )
	{
		x = area.x + position.x;
	}
	else
	{
		switch ( alignment & PositionConstants.EAST_WEST )
		{
			case PositionConstants.EAST :
				x = area.x + area.width - size.width;
				break;
			case PositionConstants.WEST :
				x = area.x;
				break;
			default :
				x = ( area.width - size.width ) / 2 + area.x;
				break;
		}
	}

	// Calculates Y
	if ( position != null && position.y != -1 )
	{
		y = area.y + position.y;
	}
	else
	{
		switch ( alignment & PositionConstants.NORTH_SOUTH )
		{
			case PositionConstants.NORTH :
				y = area.y;
				break;
			case PositionConstants.SOUTH :
				y = area.y + area.height - size.height;
				break;
			default :
				y = ( area.height - size.height ) / 2 + area.y;
				break;
		}
	}

	ArrayList xyList = createImageList( x, y );

	Iterator iter = xyList.iterator( );
	while ( iter.hasNext( ) )
	{
		Point point = (Point) iter.next( );
		graphics.drawImage( image, point );
	}
	xyList.clear( );
}
 
Example 19
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static void selectElementInContextualPaletteAndDragIt(final SWTBotGefEditor gmfEditor,
        final String selectedElementName, final int elementIndex,
        final int position) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(selectedElementName);
    Assert.assertNotNull("Error: No Edit Part \'" + selectedElementName + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final NextElementEditPolicy nextElementEditPolicy = (NextElementEditPolicy) graphicalEditPart
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);

    final IFigure toolbarFigure = nextElementEditPolicy.getFigure(elementIndex);
    Point dropLocation = null;

    final int xPaletteDelta = computeXPaletteDelta(elementIndex);
    final int yPaletteDelta = computeYPaletteDelta(elementIndex);

    final Rectangle bounds = graphicalEditPart.getFigure().getBounds();
    switch (position) {
        case PositionConstants.NORTH:
            dropLocation = bounds.getTop().getCopy().translate(xPaletteDelta, -Y_MARGIN);
            break;
        case PositionConstants.SOUTH:
            dropLocation = bounds.getBottom().getCopy().translate(xPaletteDelta, Y_MARGIN);
            break;
        case PositionConstants.WEST:
            dropLocation = bounds.getLeft().getCopy().translate(-X_MARGIN, yPaletteDelta);
            break;
        case PositionConstants.EAST:
            dropLocation = bounds.getRight().getCopy().translate(X_MARGIN, yPaletteDelta);
            break;
        case PositionConstants.NORTH_EAST:
            dropLocation = bounds.getTopRight().getCopy().translate(X_MARGIN, -Y_MARGIN);
            break;
        case PositionConstants.NORTH_WEST:
            dropLocation = bounds.getTopLeft().getCopy().translate(-X_MARGIN, Y_MARGIN);
            break;
        case PositionConstants.SOUTH_EAST:
            dropLocation = bounds.getBottomRight().getCopy().translate(X_MARGIN, Y_MARGIN);
            break;
        case PositionConstants.SOUTH_WEST:
            dropLocation = bounds.getBottomLeft().getCopy().translate(-X_MARGIN, -Y_MARGIN);
            break;
        default:
            throw new RuntimeException("Invalid position specified");
    }

    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);

    gmfEditor.drag(location.x, location.y, dropLocation.x, dropLocation.y);
}
 
Example 20
Source File: DiagramWalkerSelectionEditPolicy.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected List<Object> createSelectionHandles() {
    final List<Object> selectedEditParts = getHost().getViewer().getSelectedEditParts();
    if (selectedEditParts.size() == 1) {
        final ViewableModel currentElement = (ViewableModel) getHost().getModel();
        if (!(currentElement instanceof Category) && !(currentElement instanceof ModelProperties)) {
            // #for_erflute maybe unneeded, already linkage between main and virtual by jflute
            //final ERDiagram diagram = ERModelUtil.getDiagram(getHost().getRoot().getContents());
            //ViewableModel targetElement = currentElement;
            //if (currentElement instanceof ERVirtualTable) {
            //    targetElement = ((ERVirtualTable) currentElement).getRawTable();
            //}
            //final List<NodeElement> nodeElementList = diagram.getDiagramContents().getContents().getNodeElementList();
            //nodeElementList.remove(targetElement);
            //nodeElementList.add((NodeElement) targetElement);
            getHost().getRoot().getContents().refresh();
        }
    }

    final List<Object> list = new ArrayList<>();
    final int directions = getResizeDirections();
    if (directions == 0) {
        // #willanalyze what is this? by jflute
        //NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(), list);
    } else if (directions != -1) {
        // 0
        list.add(new ERDiagramMoveHandle((GraphicalEditPart) getHost()));

        // 1
        if ((directions & PositionConstants.EAST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        }

        // 2
        if ((directions & PositionConstants.SOUTH_EAST) == PositionConstants.SOUTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        }

        // 3
        if ((directions & PositionConstants.SOUTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        }

        // 4
        if ((directions & PositionConstants.SOUTH_WEST) == PositionConstants.SOUTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        }

        // 5
        if ((directions & PositionConstants.WEST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        }

        // 6
        if ((directions & PositionConstants.NORTH_WEST) == PositionConstants.NORTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        }

        // 7
        if ((directions & PositionConstants.NORTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        }

        // 8
        if ((directions & PositionConstants.NORTH_EAST) == PositionConstants.NORTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        }
    } else {
        addHandles((GraphicalEditPart) getHost(), list);
    }
    return list;
}