Java Code Examples for org.eclipse.draw2d.IFigure#getParent()

The following examples show how to use org.eclipse.draw2d.IFigure#getParent() . 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: NextElementEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void hideFeedback() {
	for (IFigure figure : figures) {
		if (figure != null && figure.getParent() != null) {
			layer.remove(figure);
			if(figure instanceof DraggableElement)
				((DraggableElement) figure).freeHandle();
			if(figure instanceof CustomConnectionHandle){
				((CustomConnectionHandle) figure).freeHandle();
			}
		}
	}
	figures.clear();

	for(Tool tool : tools){
		if(tool != null){
			if(tool instanceof BonitaUnspecifiedTypeCreationTool)
				tool.deactivate();
		}
	}
}
 
Example 2
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convenient method to translate bounds to Absolute coordinate
 *
 * @param owner
 * @param b
 */
public static void translateToAbsolute(final IFigure owner, final Rectangle b) {
    owner.translateToAbsolute(b);
    IFigure parentFigure = owner.getParent();
    while (parentFigure != null) {
        if (parentFigure instanceof Viewport) {
            final Viewport viewport = (Viewport) parentFigure;
            b.translate(
                    viewport.getHorizontalRangeModel().getValue(),
                    viewport.getVerticalRangeModel().getValue());
            parentFigure = parentFigure.getParent();
        }
        else {
            parentFigure = parentFigure.getParent();
        }
    }
}
 
Example 3
Source File: ListBandControlFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void paintFigure( Graphics graphics )
{
	// graphics.setBackgroundColor( ColorConstants.white );
	Rectangle rect = getBounds( ).getCopy( ).shrink( 6, 6 );
	graphics.fillRectangle( rect );

	IFigure parent = this;
	while ( ( parent = parent.getParent( ) ) != null )
	{
		if ( parent instanceof ReportShowFigure )
		{
			state = ( (ReportShowFigure) parent ).isControlShowing( );
			break;
		}
	}
	ReportFigureUtilities.paintExpandHandle( graphics,
			8,
			getBounds( ).getCenter( ),
			!state );
}
 
Example 4
Source File: SwitchPoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
private void showSelectionForAddTop() {
	if (!isOnTop()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp));
		f.setParent(getHostFigure());
		f.setSize(20, 20);



		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}

		f.setLocation(new Point(bounds.getTopLeft().x,bounds.getTop().y-20));
		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP));
		layer.add(f);
		figures.add(f);
	}
}
 
Example 5
Source File: RootFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void removeFigure(IFigure figure) {
	final IFigure parent = figure.getParent();
	parent.remove(figure);

	// TODO rather mark this area as damaged
	parent.revalidate();
}
 
Example 6
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
protected Point getPartAbsoluteCursorLocation() {
	org.eclipse.draw2d.geometry.Point toolLocation = null;
	try {
		Tool tool = selectedTargetEditPart.getViewer().getEditDomain().getActiveTool();
		AbstractTool aTool = (AbstractTool) tool;
		Method m = AbstractTool.class.getDeclaredMethod("getLocation"); //$NON-NLS-1$
		m.setAccessible(true);
		toolLocation = ((org.eclipse.draw2d.geometry.Point) m.invoke(aTool)).getCopy();

		IFigure parentFigure = selectedTargetEditPart.getFigure().getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				toolLocation.translate(viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			} else {
				parentFigure = parentFigure.getParent();
			}
		}

		return toolLocation;
	} catch (Exception e) {
		BonitaStudioLog.log("can't find exact location for pasting"); //$NON-NLS-1$
		return null;
	}
}
 
Example 7
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param zoom 
 * 
 */
private void showSelectionForAddTop(double zoom) {
	if (!isOnTop()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp));
		f.setParent(getHostFigure());
		f.setSize(20, 20);



		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}


		Point location = new Point(bounds.getTopLeft().x+20,bounds.getTopLeft().y-20) ;

		f.setLocation(location);
		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP));
		getLayer(LayerConstants.HANDLE_LAYER).add(f);
		figures.add(f);
	}
}
 
Example 8
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param zoom 
 * 
 */
private void showSelectionForAddBottom(double zoom) {
	if (!isOnBottom()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowDown));
		f.setSize(20, 20);

		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}

		Point location =new Point(bounds.getBottomLeft().x+20,bounds.getBottomLeft().y) ; 

		f.setLocation(location);

		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_BOTTOM));
		getLayer(LayerConstants.HANDLE_LAYER).add(f);
		figures.add(f);
	}
}
 
Example 9
Source File: UpdateSizeLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mousePressed(final MouseEvent me) {
    try {

        final IFigure  f = ((CustomMainProcessEditPart) laneEditPart.getParent().getParent().getParent()).getFigure() ;
        IFigure p = f ;
        while(!(p instanceof Viewport)){
            p = p.getParent();
        }

        final int y = ((Viewport)p).getVerticalRangeModel().getValue() ;

        IGraphicalEditPart targetEp = laneEditPart;
        if(type.equals(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT)||type.equals(UpdateSizePoolSelectionEditPolicy.REMOVE_RIGHT)){
            targetEp = getPoolEditPart();
        }

        final IUndoableOperation c = new UpdatePoolSizeCommand(targetEp, type);
        OperationHistoryFactory.getOperationHistory().execute(c,null,null);
        me.consume();
        laneEditPart.getViewer().setSelection(new StructuredSelection(targetEp));
        refresh();
        laneEditPart.getViewer().setSelection(new StructuredSelection(getHost()));
        ((Viewport)p).setVerticalLocation(y);


    } catch (final ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convenient method to translate bounds to Absolute coordinate
 *
 * @param owner
 * @param p
 */
public static void translateToAbsolute(IFigure owner, final Point p) {
    while (owner != null) {
        if (owner instanceof Viewport) {
            final Viewport viewport = (Viewport) owner;
            p.translate(
                    viewport.getHorizontalRangeModel().getValue(),
                    viewport.getVerticalRangeModel().getValue());
            owner = owner.getParent();
        }
        else {
            owner = owner.getParent();
        }
    }
}
 
Example 11
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isFigureVisible( IFigure fig )
{
	Rectangle figBounds = fig.getBounds( ).getCopy( );
	IFigure walker = fig.getParent( );
	while ( !figBounds.isEmpty( ) && walker != null )
	{
		walker.translateToParent( figBounds );
		figBounds.intersect( walker.getBounds( ) );
		walker = walker.getParent( );
	}
	return !figBounds.isEmpty( );
}
 
Example 12
Source File: ListBandControlFigure.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void mousePressed( MouseEvent me )
{
	state = !state;
	IFigure parent = this;
	while ( ( parent = parent.getParent( ) ) != null )
	{
		if ( parent instanceof ReportShowFigure )
		{
			( (ReportShowFigure) parent ).setShowing( state );
			getOwner( ).markDirty( true );
			break;
		}
	}

}
 
Example 13
Source File: TableUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the given figure is visible.
 * 
 * @param fig
 * @return
 */
private static boolean isFigureVisible( IFigure fig )
{
	Rectangle figBounds = fig.getBounds( ).getCopy( );
	IFigure walker = fig.getParent( );
	while ( !figBounds.isEmpty( ) && walker != null )
	{
		walker.translateToParent( figBounds );
		figBounds.intersect( walker.getBounds( ) );
		walker = walker.getParent( );
	}
	return !figBounds.isEmpty( );
}
 
Example 14
Source File: UpdateSizePoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent me) {
    try {

        IFigure  f = ((CustomMainProcessEditPart) poolEditPart.getParent()).getFigure() ;
        IFigure p = f ;
        while(!(p instanceof Viewport)){
            p = p.getParent();
        }

        int y = ((Viewport)p).getVerticalRangeModel().getValue() ;
        int x = ((Viewport)p).getHorizontalRangeModel().getValue() ;


        IUndoableOperation c = new UpdatePoolSizeCommand(poolEditPart, type);
        OperationHistoryFactory.getOperationHistory().execute(c,null,null);
        me.consume();


        poolEditPart.getViewer().setSelection(new StructuredSelection(poolEditPart));
        refresh();
        poolEditPart.getViewer().setSelection(new StructuredSelection(getHost()));

        if(type.equals(ADD_RIGHT)){
            ((Viewport)p).setHorizontalLocation(x+150);
        }

        ((Viewport)p).setVerticalLocation(y);


    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 15
Source File: RailroadSelectionLinker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void selectFigure(IFigure selectedFigure) {
	while (selectedFigure != null && !(selectedFigure instanceof IEObjectReferer))
		selectedFigure = selectedFigure.getParent();
	if (selectedFigure != null) {
		if (currentSelectedNode != null)
			currentSelectedNode.setSelected(false);
		if (selectedFigure instanceof ISelectable) {
			((ISelectable) selectedFigure).setSelected(true);
			currentSelectedNode = (ISelectable) selectedFigure;
		} else {
			currentSelectedNode = null;
		}
	}
}
 
Example 16
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static boolean captureLayout(IFigure root) {

		RECORDING = true;

		while (!(root instanceof Viewport)) {
			root = root.getParent();
		}
		viewport = (Viewport) root;
		while (root.getParent() != null) {
			root = root.getParent();
		}

		initialStates = new HashMap<>();
		finalStates = new HashMap<>();

		// This part records all layout results.
		root.validate();
		Iterator<IFigure> iter = initialStates.keySet().iterator();
		if (!iter.hasNext()) {
			// Nothing layed out, so abort the animation
			RECORDING = false;
			return false;
		}
		while (iter.hasNext()) {
			recordFinalState(iter.next());
		}

		start = System.currentTimeMillis();
		finish = start + DURATION;
		current = start + 20;

		RECORDING = false;
		PLAYBACK = true;
		return true;
	}
 
Example 17
Source File: ReportFocusTraverseManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the IFigure that will receive focus upon a 'shift-tab' traverse event.
 * 
 * @param root The {@link LightweightSystem LightweightSystem's} root figure
 * @param focusOwner The IFigure who currently owns focus 
 * @return the previous focusable figure
 */
public IFigure getPreviousFocusableFigure(IFigure root, IFigure focusOwner) {
	
	IFigure nextFocusOwner = focusOwner;
	if (focusOwner == null) {
		if (root.getChildren().size() != 0) {
			nextFocusOwner = findDeepestRightmostChildOf(root);
			if (isFocusEligible(nextFocusOwner))
				return nextFocusOwner;
		} else
			return null;
	}
	
	boolean found = false;
	
 	while (!found) {
 		IFigure parent = nextFocusOwner.getParent();
		
		/* 
		 * At root, return null to indicate traversal
		 * is complete.
		 */
		if (parent == null)
			return null;
		
		List siblings = parent.getChildren();
		int siblingPos = siblings.indexOf(nextFocusOwner);
		
		/*		
		 * Figure traversal is implemented using the post-order right to left 
		 * tree traversal algorithm.
		 * 
		 * Find the rightmost child.
		 * If this child is focusable, return it
		 * If not focusable, traverse to its sibling and repeat.
		 * If there is no sibling, traverse its parent.
		 */
		if (siblingPos != 0) {
			IFigure child = 
					findDeepestRightmostChildOf((IFigure)siblings.get(siblingPos - 1));
			if (isFocusEligible(child)) {
				found = true;
				nextFocusOwner = child;
			} else if (child.equals(nextFocusOwner)) {
				if (isFocusEligible(nextFocusOwner))
					found = true;
			} else
				nextFocusOwner = child;			
		} else {
			nextFocusOwner = parent;
				if (isFocusEligible(nextFocusOwner))
					found = true;
		}
	}
	return nextFocusOwner;
}
 
Example 18
Source File: ReportFocusTraverseManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the IFigure that will receive focus upon a 'shift-tab' traverse event.
 * 
 * @param root The {@link LightweightSystem LightweightSystem's} root figure
 * @param focusOwner The IFigure who currently owns focus 
 * @return the previous focusable figure
 */
public IFigure getPreviousFocusableFigureInSameOrder(IFigure root, IFigure focusOwner) {
	
	IFigure nextFocusOwner = focusOwner;
	if (focusOwner == null) {
		if (root.getChildren().size() != 0) {
			nextFocusOwner = findDeepestRightmostChildOf(root);
			if (isFocusEligible(nextFocusOwner))
				return nextFocusOwner;
		} else
			return null;
	}
	
	boolean found = false;
	ArrayList list = new ArrayList();
 	while (!found) {
 		IFigure parent = nextFocusOwner.getParent();
		
		/* 
		 * At root, return null to indicate traversal
		 * is complete.
		 */
		if (parent == null)
			return null;
		
		List siblings = parent.getChildren();
		int siblingPos = siblings.indexOf(nextFocusOwner);
		
		/*		
		 * Figure traversal is implemented using the post-order right to left 
		 * tree traversal algorithm.
		 * 
		 * Find the rightmost child.
		 * If this child is focusable, return it
		 * If not focusable, traverse to its sibling and repeat.
		 * If there is no sibling, traverse its parent.
		 */
		if (siblingPos != 0) {
			nextFocusOwner = ((IFigure)(siblings.get(siblingPos - 1)));
			list.add( nextFocusOwner );
			if (isFocusEligible(nextFocusOwner))
				found = true;
			
			
		}
		else if (siblings.size() == 1)
		{
			nextFocusOwner = ((IFigure)(siblings.get(0)));
			if (isFocusEligible(nextFocusOwner))
			{
				found = true;
			}
			else
			{
				return null;
			}
		}
		else {
			
			nextFocusOwner = ((IFigure)(siblings.get(siblings.size() - 1)));
			if (isFocusEligible(nextFocusOwner))
			{
				found = true;
			}
			else if (list.contains( nextFocusOwner ))
			{
				return null;
			}
			else
			{
				list.add( nextFocusOwner );
			}
			
			
		}
	}
	return nextFocusOwner;
}
 
Example 19
Source File: ReportFocusTraverseManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the IFigure that will receive focus upon a 'tab' traverse event.
 * 
 * @param root the {@link LightweightSystem LightweightSystem's} root figure
 * @param focusOwner the IFigure who currently owns focus
 * @return the next focusable figure
 */
public IFigure getNextFocusableFigureInSameOrder(IFigure root, IFigure focusOwner) {
	boolean found = false;
	IFigure nextFocusOwner = focusOwner;
	
	/* If no Figure currently has focus,
	 * apply focus to root figure's first focusable child
	 */
	if (focusOwner == null) {
		if (root.getChildren().size() != 0) {
			nextFocusOwner = ((IFigure)root.getChildren().get(0));
			if (isFocusEligible(nextFocusOwner))
				return nextFocusOwner;
		} else
			return null;
	}
	ArrayList list = new ArrayList();
	while (!found) {
		IFigure parent = nextFocusOwner.getParent();
		
		/*
		 * Figure traversal is implemented using the pre-order left to right
		 * tree traversal algorithm.
		 *  
		 * If the focused sibling has children, traverse to its leftmost child.
		 * If the focused sibling has no children, traverse to the sibling
		 * to its right.
		 * If there is no sibling to the right, go up the tree until a node
		 * with untraversed siblings is found.
		 */
		List siblings = parent.getChildren();
		int siblingPos = siblings.indexOf(nextFocusOwner);		
		if (siblingPos < siblings.size() - 1) {
			nextFocusOwner = ((IFigure)(siblings.get(siblingPos + 1)));
			list.add( nextFocusOwner );
			if (isFocusEligible(nextFocusOwner))
				found = true;
		}
		else if (siblings.size() == 1)
		{
			nextFocusOwner = ((IFigure)(siblings.get(0)));
			
			if (isFocusEligible(nextFocusOwner))
			{
				found = true;
			}
			else
			{
				return null;
			}
		}
		else {
			nextFocusOwner = ((IFigure)(siblings.get(0)));
			
			if (isFocusEligible(nextFocusOwner))
			{
				found = true;
			}
			else if (list.contains( nextFocusOwner ))
			{
				return null;
			}
			else
			{
				list.add(nextFocusOwner);
			}
			
		}		
	}
	return nextFocusOwner;
}
 
Example 20
Source File: ReportFocusTraverseManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the IFigure that will receive focus upon a 'tab' traverse event.
 * 
 * @param root the {@link LightweightSystem LightweightSystem's} root figure
 * @param focusOwner the IFigure who currently owns focus
 * @return the next focusable figure
 */
public IFigure getNextFocusableFigure(IFigure root, IFigure focusOwner) {
	boolean found = false;
	IFigure nextFocusOwner = focusOwner;
	
	/* If no Figure currently has focus,
	 * apply focus to root figure's first focusable child
	 */
	if (focusOwner == null) {
		if (root.getChildren().size() != 0) {
			nextFocusOwner = ((IFigure)root.getChildren().get(0));
			if (isFocusEligible(nextFocusOwner))
				return nextFocusOwner;
		} else
			return null;
	}
	while (!found) {
		IFigure parent = nextFocusOwner.getParent();
		
		/*
		 * Figure traversal is implemented using the pre-order left to right
		 * tree traversal algorithm.
		 *  
		 * If the focused sibling has children, traverse to its leftmost child.
		 * If the focused sibling has no children, traverse to the sibling
		 * to its right.
		 * If there is no sibling to the right, go up the tree until a node
		 * with untraversed siblings is found.
		 */
		List siblings = parent.getChildren();
		int siblingPos = siblings.indexOf(nextFocusOwner);		

		if (nextFocusOwner.getChildren().size() != 0) {
			nextFocusOwner = ((IFigure)(nextFocusOwner.getChildren().get(0)));		
			if (isFocusEligible(nextFocusOwner))				
				found = true;	
		} else if (siblingPos < siblings.size() - 1) {
			nextFocusOwner = ((IFigure)(siblings.get(siblingPos + 1)));
			if (isFocusEligible(nextFocusOwner))
				found = true;
		} else {
			boolean untraversedSiblingFound = false;			
			while (!untraversedSiblingFound) {
				IFigure p = nextFocusOwner.getParent();	
				IFigure gp = p.getParent();
				
				if (gp != null) {
					int parentSiblingCount = gp.getChildren().size();
					int parentIndex = gp.getChildren().indexOf(p);
					if (parentIndex < parentSiblingCount - 1) {
						nextFocusOwner = ((IFigure)p.getParent()
													.getChildren()
													.get(parentIndex + 1));
						untraversedSiblingFound = true;
						if (isFocusEligible(nextFocusOwner))		
							found = true;
					} else
						nextFocusOwner = p;
				} else {
					nextFocusOwner = null;
					untraversedSiblingFound = true;
					found = true;
				}
			}
		}		
	}
	return nextFocusOwner;
}