org.eclipse.gef.GraphicalEditPart Java Examples

The following examples show how to use org.eclipse.gef.GraphicalEditPart. 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: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected int getFeedbackIndexFor( Request request )
{
	Transposer transposer = new Transposer( );
	transposer.setEnabled( !isHorizontal( ) );

	List list = getHost( ).getChildren( );
	int size = list.size( ) - 1;
	int index = getFeedbackPosition( request );
	if ( size < 0 || index < 0 || index > size )
	{
		return index;
	}

	Rectangle rect = getAbsoluteBounds( (GraphicalEditPart) list.get( size ) );
	Point p = transposer.t( getLocationFromRequest( request ) );
	if ( p.y > rect.bottom( ) )
	{
		index = -1;
	}

	return index;
}
 
Example #2
Source File: TreeLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object getConstraintFor(ChangeBoundsRequest request,
		GraphicalEditPart child) {

	if (request instanceof AlignmentRequest) {
		return super.getConstraintFor(request, child);
	}
	final Rectangle rect = (Rectangle) super.getConstraintFor(request,
			child);
	final Rectangle cons = getCurrentConstraintFor(child);
	final int newTreePosition = TreeLayoutUtil.getNewTreeNodePosition(
			request.getLocation(),
			TreeLayoutUtil.getSiblings((IGraphicalEditPart) child));
	if (cons instanceof TreeLayoutConstraint) {
		final TreeLayoutConstraint treeLayoutConstraint = (TreeLayoutConstraint) cons;
		return new TreeLayoutConstraint(rect,
				treeLayoutConstraint.isRoot(), newTreePosition);
	}
	return new TreeLayoutConstraint(rect, false, newTreePosition);
}
 
Example #3
Source File: ReportNonResizableHandleKit.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fills the given List with handles at each corner of a figure.
 * 
 * @param part
 *            the handles' GraphicalEditPart
 * @param handles
 *            the List to add the four corner handles to
 * @param tracker
 *            the handles' DragTracker
 * @param cursor
 *            the handles' Cursor
 */
public static void addCornerHandles( GraphicalEditPart part, List handles,
		DragTracker tracker, Cursor cursor )
{
	handles.add( createHandle( part,
			PositionConstants.SOUTH_EAST,
			tracker,
			cursor ) );
	handles.add( createHandle( part,
			PositionConstants.SOUTH_WEST,
			tracker,
			cursor ) );
	handles.add( createHandle( part,
			PositionConstants.NORTH_WEST,
			tracker,
			cursor ) );
	handles.add( createHandle( part,
			PositionConstants.NORTH_EAST,
			tracker,
			cursor ) );
}
 
Example #4
Source File: ChangeBackgroundColorAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private Command createCommand(final List objects, final RGB rgb) {
    if (objects.isEmpty()) {
        return null;
    }

    if (!(objects.get(0) instanceof GraphicalEditPart)) {
        return null;
    }

    final CompoundCommand command = new CompoundCommand();

    for (int i = 0; i < objects.size(); i++) {
        final GraphicalEditPart part = (GraphicalEditPart) objects.get(i);
        final Object modelObject = part.getModel();

        if (modelObject instanceof ViewableModel) {
            command.add(new ChangeBackgroundColorCommand((ViewableModel) modelObject, rgb.red, rgb.green, rgb.blue));

        } else if (modelObject instanceof ConnectionElement) {
            command.add(new ChangeConnectionColorCommand((ConnectionElement) modelObject, rgb.red, rgb.green, rgb.blue));

        }
    }

    return command;
}
 
Example #5
Source File: TableCellKeyDelegate.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a connection on a node, this method finds the next (or the
 * previous) connection of that node.
 * 
 * @param node
 *            The EditPart whose connections are being traversed
 * @param current
 *            The connection relative to which the next connection has to be
 *            found
 * @param forward
 *            <code>true</code> if the next connection has to be found;
 *            false otherwise
 */
ConnectionEditPart findConnection( GraphicalEditPart node,
		ConnectionEditPart current, boolean forward )
{
	List connections = new ArrayList( node.getSourceConnections( ) );
	connections.addAll( node.getTargetConnections( ) );
	if ( connections.isEmpty( ) )
		return null;
	if ( forward )
		counter++;
	else
		counter--;
	while ( counter < 0 )
		counter += connections.size( );
	counter %= connections.size( );
	return (ConnectionEditPart) connections.get( counter
			% connections.size( ) );
}
 
Example #6
Source File: ReportResizableHandleKit.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
static Handle createHandle( GraphicalEditPart owner, int direction,
		DragTracker tracker, Cursor cursor )
{
	ReportResizeHandle handle = new ReportResizeHandle( owner, direction );
	handle.setDragTracker( tracker );
	handle.setCursor( cursor );
	return handle;
}
 
Example #7
Source File: CrossflowTextNonResizableEditPolicy.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected List createSelectionHandles() {
	MoveHandle moveHandle = new MoveHandle((GraphicalEditPart) getHost());
	moveHandle.setBorder(null);
	moveHandle.setDragTracker(new DragEditPartsTrackerEx(getHost()));
	return Collections.singletonList(moveHandle);
}
 
Example #8
Source File: ERDiagramAlignmentAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of editparts which will participate in alignment.
 * 
 * @param request
 *            the alignment request
 * @return the list of parts which will be aligned
 */
@SuppressWarnings("unchecked")
protected List getOperationSet(Request request) {
	if (operationSet != null)
		return operationSet;
	List editparts = new ArrayList(getSelectedObjects());
	for (Iterator iter = editparts.iterator(); iter.hasNext();) {
		if (iter.next() instanceof NormalColumnEditPart) {
			iter.remove();
		}
	}

	if (editparts.isEmpty()
			|| !(editparts.get(0) instanceof GraphicalEditPart))
		return Collections.EMPTY_LIST;
	Object primary = editparts.get(editparts.size() - 1);
	editparts = ToolUtilities.getSelectionWithoutDependants(editparts);
	ToolUtilities.filterEditPartsUnderstanding(editparts, request);
	if (editparts.size() < 2 || !editparts.contains(primary))
		return Collections.EMPTY_LIST;
	EditPart parent = ((EditPart) editparts.get(0)).getParent();
	for (int i = 1; i < editparts.size(); i++) {
		EditPart part = (EditPart) editparts.get(i);
		if (part.getParent() != parent)
			return Collections.EMPTY_LIST;
	}
	return editparts;
}
 
Example #9
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
	if (evt.getPropertyName().equals(ProcessNode.CONNECTION))
		refreshConnections(evt);
	else {
		GraphicalEditPart part = (GraphicalEditPart) getViewer().getContents();
		IFigure figure = part.getFigure();
		figure.revalidate();
	}
}
 
Example #10
Source File: AbstractGuideHandle.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public AbstractGuideHandle( GraphicalEditPart owner, Locator loc )
{
	super( owner, loc );
	addMouseMotionListener( this );
	getLocator( ).relocate( this );

}
 
Example #11
Source File: XtextDirectEditManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param source
 * @param editorType
 * @param locator
 */
public XtextDirectEditManager(GraphicalEditPart source, Class<?> editorType, CellEditorLocator locator,
		Injector injector, int style) {
	super(source, editorType, locator);
	this.editorType = editorType;
	this.injector = injector;
	this.style = style;
}
 
Example #12
Source File: ERDiagramAlignmentAction.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of editparts which will participate in alignment.
 * 
 * @param request
 *            the alignment request
 * @return the list of parts which will be aligned
 */
@SuppressWarnings("unchecked")
protected List getOperationSet(final Request request) {
    if (operationSet != null)
        return operationSet;
    List editparts = new ArrayList(getSelectedObjects());
    for (final Iterator iter = editparts.iterator(); iter.hasNext();) {
        if (iter.next() instanceof NormalColumnEditPart) {
            iter.remove();
        }
    }

    if (editparts.isEmpty() || !(editparts.get(0) instanceof GraphicalEditPart))
        return Collections.EMPTY_LIST;
    final Object primary = editparts.get(editparts.size() - 1);
    editparts = ToolUtilities.getSelectionWithoutDependants(editparts);
    ToolUtilities.filterEditPartsUnderstanding(editparts, request);
    if (editparts.size() < 2 || !editparts.contains(primary))
        return Collections.EMPTY_LIST;
    final EditPart parent = ((EditPart) editparts.get(0)).getParent();
    for (int i = 1; i < editparts.size(); i++) {
        final EditPart part = (EditPart) editparts.get(i);
        if (part.getParent() != parent)
            return Collections.EMPTY_LIST;
    }
    return editparts;
}
 
Example #13
Source File: NodeElementSelectionEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void addHandles(final GraphicalEditPart part, final List handles) {
    handles.add(new ERDiagramMoveHandle(part));
    handles.add(createHandle(part, PositionConstants.EAST));
    handles.add(createHandle(part, PositionConstants.SOUTH_EAST));
    handles.add(createHandle(part, PositionConstants.SOUTH));
    handles.add(createHandle(part, PositionConstants.SOUTH_WEST));
    handles.add(createHandle(part, PositionConstants.WEST));
    handles.add(createHandle(part, PositionConstants.NORTH_WEST));
    handles.add(createHandle(part, PositionConstants.NORTH));
    handles.add(createHandle(part, PositionConstants.NORTH_EAST));
}
 
Example #14
Source File: PreferredSizeHandlerEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public PreferredSizeSquareHandle(GraphicalEditPart editpart) {
	super(editpart, new RelativeLocator(getHostFigure(), 0.75, 1) {
		protected Rectangle getReferenceBox() {
			IFigure f = getReferenceFigure();
			if (f instanceof HandleBounds)
				return ((HandleBounds) f).getHandleBounds();
			return super.getReferenceBox();
		}
	});
}
 
Example #15
Source File: EditExcelAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean calculateEnabled() {
	List objects = this.getSelectedObjects();

	if (objects.isEmpty()) {
		return false;
	}

	if (!(objects.get(0) instanceof GraphicalEditPart)) {
		return false;
	}

	return true;
}
 
Example #16
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a list including all of the children of the edit part passed in.
 */
private List getAllChildren( EditPart editPart, List allChildren )
{
	List children = editPart.getChildren( );
	for ( int i = 0; i < children.size( ); i++ )
	{
		GraphicalEditPart child = (GraphicalEditPart) children.get( i );
		allChildren.add( child );
		getAllChildren( child, allChildren );
	}
	return allChildren;
}
 
Example #17
Source File: CustomTextDirectEditManager.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static Class getTextCellEditorClass(GraphicalEditPart source) {
    if (!Platform.getOS().equals(Platform.OS_MACOSX)){
        return CustomWrapTextCellEditor.class;
    }else{
        return TextDirectEditManager.getTextCellEditorClass(source);
    }
}
 
Example #18
Source File: AreaEditPart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private int getHeight(DimensionHandle handle)
{
	if ( DesignChoiceConstants.UNITS_PERCENTAGE.equals( handle.getUnits( ) ) )
	{
		return (int)(((GraphicalEditPart)getParent( )).getFigure( ).getClientArea( ).height*handle.getMeasure( )/100);
	}
	return (int) DEUtil.convertoToPixel( handle );
}
 
Example #19
Source File: MultipleEditPart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private GraphicalEditPart getTrueHost()
{
	GraphicalEditPart parent = (GraphicalEditPart)getHost( );
	List list = parent.getChildren( );
	if (list.size( ) == 0)
	{
		return parent;
	}
	return (GraphicalEditPart)list.get( 0 );
}
 
Example #20
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private List calculateNewSelection( )
{

	List newSelections = new ArrayList( );
	List children = getAllChildren( );

	// Calculate new selections based on which children fall
	// inside the marquee selection rectangle. Do not select
	// children who are not visible
	for ( int i = 0; i < children.size( ); i++ )
	{
		EditPart child = (EditPart) children.get( i );
		if ( !child.isSelectable( ) || isInTable( child ) )
			continue;
		IFigure figure = ( (GraphicalEditPart) child ).getFigure( );
		Rectangle r = figure.getBounds( ).getCopy( );
		figure.translateToAbsolute( r );

		if ( getMarqueeSelectionRectangle( ).contains( r.getTopLeft( ) )
				&& getMarqueeSelectionRectangle( ).contains( r.getBottomRight( ) )
				&& figure.isShowing( )
				&& child.getTargetEditPart( MARQUEE_REQUEST ) == child
				&& isFigureVisible( figure ) )
			newSelections.add( child );

	}
	return newSelections;
}
 
Example #21
Source File: TableResizeEditPolice.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected List createSelectionHandles( )
{
	List list = new ArrayList( );
	ReportResizableHandleKit.addMoveHandle( (GraphicalEditPart) getHost( ),
			list );
	if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH_EAST ) == PositionConstants.SOUTH_EAST )
		ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
				list,
				PositionConstants.SOUTH_EAST );

	return list;
}
 
Example #22
Source File: ChangeBackgroundColorAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final List<?> objects = getSelectedObjects();
    if (objects.isEmpty()) {
        return false;
    }
    if (!(objects.get(0) instanceof GraphicalEditPart)) {
        return false;
    }
    return true;
}
 
Example #23
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 #24
Source File: ActivityDecoratorProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * getDecoratorTargetClassifier Utility method to determine if the
 * decoratorTarget is a supported type for this decorator and return the
 * associated EditPart element.
 * 
 * @param decoratorTarget
 *            IDecoratorTarget to check and return valid Classifier target.
 * @return node GraphicalEditPart if IDecoratorTarget can be supported, null
 *         otherwise.
 */
public static GraphicalEditPart getDecoratorTargetNode(IDecoratorTarget decoratorTarget) {
    if(decoratorTarget == null){
        return null;
    }
    ShapeNodeEditPart node = (ShapeNodeEditPart) decoratorTarget.getAdapter(ShapeNodeEditPart.class);
    if(node != null ){
        return node ;
    }

    return null;

}
 
Example #25
Source File: DiagramWalkerEditPart.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshVisuals() {
    final DiagramWalker element = (DiagramWalker) getModel();
    setVisible();
    final Rectangle rectangle = getRectangle();
    final GraphicalEditPart parent = (GraphicalEditPart) getParent();
    final IFigure figure = getFigure();
    final int[] color = element.getColor();
    if (color != null) {
        final Color bgColor = DesignResources.getColor(color);
        figure.setBackgroundColor(bgColor);
    }
    parent.setLayoutConstraint(this, figure, rectangle);
}
 
Example #26
Source File: DiagramWalkerSelectionEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static void addHandles(GraphicalEditPart part, List<Object> handles) {
    handles.add(new ERDiagramMoveHandle(part));
    handles.add(createHandle(part, PositionConstants.EAST));
    handles.add(createHandle(part, PositionConstants.SOUTH_EAST));
    handles.add(createHandle(part, PositionConstants.SOUTH));
    handles.add(createHandle(part, PositionConstants.SOUTH_WEST));
    handles.add(createHandle(part, PositionConstants.WEST));
    handles.add(createHandle(part, PositionConstants.NORTH_WEST));
    handles.add(createHandle(part, PositionConstants.NORTH));
    handles.add(createHandle(part, PositionConstants.NORTH_EAST));
}
 
Example #27
Source File: ChangeBackgroundColorAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
	List objects = this.getSelectedObjects();

	if (objects.isEmpty()) {
		return false;
	}

	if (!(objects.get(0) instanceof GraphicalEditPart)) {
		return false;
	}

	return true;
}
 
Example #28
Source File: AutomaticOrManualTransitionContribution.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setSelection(ISelection selection) {
    if(((IStructuredSelection)selection).getFirstElement() instanceof GraphicalEditPart){
        editPart = (GraphicalEditPart) ((IStructuredSelection)selection).getFirstElement() ;
    }

}
 
Example #29
Source File: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param request
 * @param child
 * @param constraintFor
 * @return
 */
protected Command createChangeConstraintCommand(
		ChangeBoundsRequest request, GraphicalEditPart child,
		Object constraintFor )
{

	ReportItemHandle handle = (ReportItemHandle) child.getModel( );

	SetConstraintCommand command = new SetConstraintCommand( );

	command.setModel( handle );

	int direction = request.getResizeDirection( );
	Dimension size = new Dimension( ( (Rectangle) constraintFor ).getSize( ) );

	if ( direction == PositionConstants.EAST
			|| direction == PositionConstants.WEST )
	{
		size.height = -1;
	}
	else if ( direction == PositionConstants.SOUTH
			|| direction == PositionConstants.NORTH )
	{
		size.width = -1;
	}

	command.setSize( size );

	return command;
}
 
Example #30
Source File: TableCellKeyDelegate.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method traverses to the closest child of the currently focused
 * EditPart, if it has one.
 */
void navigateIntoContainer( KeyEvent event )
{
	GraphicalEditPart focus = getFocusEditPart( );
	List childList = focus.getChildren( );
	Point tl = focus.getContentPane( ).getBounds( ).getTopLeft( );

	int minimum = Integer.MAX_VALUE;
	int current;
	GraphicalEditPart closestPart = null;

	for ( int i = 0; i < childList.size( ); i++ )
	{
		GraphicalEditPart ged = (GraphicalEditPart) childList.get( i );
		if ( !ged.isSelectable( ) )
			continue;
		Rectangle childBounds = ged.getFigure( ).getBounds( );

		current = ( childBounds.x - tl.x ) + ( childBounds.y - tl.y );
		if ( current < minimum )
		{
			minimum = current;
			closestPart = ged;
		}
	}
	if ( closestPart != null )
		navigateTo( closestPart, event );
}