Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to add the align left, align middle and align right actions to the shapeEditor example
How to add the align left, align middle and align right actions to the shapeEditor example [message #221812] Sun, 20 August 2006 13:51 Go to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hallo newsgroup!

What do I have to do to add the "align right", "align middle" and "align
left" actions to the ShapeEditor example?

I have added the following code which shows the buttons, but they are always
inactive nomater howmany shapes I select:

....
class ShapesEditorActionBarContributer ....

protected void buildActions() {
addRetargetAction(new DeleteRetargetAction());
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());

// started to insert code here
addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
addRetargetAction(new
AlignmentRetargetAction(PositionConstants.CENTER));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
addRetargetAction(new
AlignmentRetargetAction(PositionConstants.MIDDLE));
addRetargetAction(new
AlignmentRetargetAction(PositionConstants.BOTTOM));
}

Thanks for your help!
Re: How to add the align left, align middle and align right actions to the shapeEditor example [message #221862 is a reply to message #221812] Mon, 21 August 2006 14:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

The actions are not active because your EditPolicies don't return an
executable command for a a specific type of request.

Here's the code you have to change, following one of my examples, this is
straightforward to apply to the Shapes example.

vlad

1) The container editpart the of the components that you will align must
have an XYLayoutEditPolicy, override:

protected Command createChangeConstraintCommand(
ChangeBoundsRequest request, EditPart child, Object constraint) {
if (/*child instanceof BlockEditPart &&*/ constraint instanceof Rectangle) {
// return a command that can move and/or resize a BlockComponent
return new BlockSetConstraintCommand((Block) child.getModel(),
request, (Rectangle) constraint);
}
return super.createChangeConstraintCommand(request, child, constraint);
}

2) Now the command itself:

public class BlockSetConstraintCommand extends Command {
.....

public boolean canExecute() {
Object type = request.getType();
// make sure the Request is of a type we support:
return (RequestConstants.REQ_MOVE.equals(type)
|| RequestConstants.REQ_MOVE_CHILDREN.equals(type)
|| RequestConstants.REQ_RESIZE.equals(type)
|| RequestConstants.REQ_RESIZE_CHILDREN.equals(type)
|| RequestConstants.REQ_ALIGN_CHILDREN
.equals(type));
}
....
}

2) In the actionBarContributor:
.....
protected void buildActions() {
addRetargetAction(new DeleteRetargetAction());
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());

addRetargetAction((RetargetAction) ActionFactory.CUT.create(getPage().getWorkbenchWindow()));
addRetargetAction((RetargetAction) ActionFactory.COPY.create(getPage().getWorkbenchWindow()));
addRetargetAction((RetargetAction) ActionFactory.PASTE.create(getPage().getWorkbenchWindow()));

addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));

}

/**
* @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGloba lActionKeys()
*/

/**
* @see org.eclipse.ui.part.EditorActionBarContributor#contributeToT oolBar(IToolBarManager)
*/
public void contributeToToolBar(IToolBarManager tbm) {
tbm.add(getAction(ActionFactory.UNDO.getId()));
tbm.add(getAction(ActionFactory.REDO.getId()));
tbm.add(getAction(ActionFactory.DELETE.getId()));

tbm.add(new Separator());
tbm.add(getAction(ActionFactory.CUT.getId()));
tbm.add(getAction(ActionFactory.COPY.getId()));
tbm.add(getAction(ActionFactory.PASTE.getId()));

tbm.add(new Separator());
tbm.add(getAction(GEFActionConstants.ALIGN_LEFT));
tbm.add(getAction(GEFActionConstants.ALIGN_CENTER));
tbm.add(getAction(GEFActionConstants.ALIGN_RIGHT));
tbm.add(new Separator());
tbm.add(getAction(GEFActionConstants.ALIGN_TOP));
tbm.add(getAction(GEFActionConstants.ALIGN_MIDDLE));
tbm.add(getAction(GEFActionConstants.ALIGN_BOTTOM));
tbm.add(new Separator());
tbm.add(new Action ("VHDL") { public void run () { VHDLGenerator.generateVHDL( getEditor().getPipeline() ); } });
}

.....


On Sun, 20 Aug 2006 15:51:06 +0200, Martin Tauber wrote:

> Hallo newsgroup!
>
> What do I have to do to add the "align right", "align middle" and "align
> left" actions to the ShapeEditor example?
>
> I have added the following code which shows the buttons, but they are always
> inactive nomater howmany shapes I select:
>
> ...
> class ShapesEditorActionBarContributer ....
>
> protected void buildActions() {
> addRetargetAction(new DeleteRetargetAction());
> addRetargetAction(new UndoRetargetAction());
> addRetargetAction(new RedoRetargetAction());
>
> // started to insert code here
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
> addRetargetAction(new
> AlignmentRetargetAction(PositionConstants.CENTER));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
> addRetargetAction(new
> AlignmentRetargetAction(PositionConstants.MIDDLE));
> addRetargetAction(new
> AlignmentRetargetAction(PositionConstants.BOTTOM));
> }
>
> Thanks for your help!
Re: How to add the align left, align middle and align right actions to the shapeEditor example [message #221927 is a reply to message #221862] Mon, 21 August 2006 19:16 Go to previous message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

Oops, I forgot the code that must be added to the editor:

protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction action;

action = new CopyAction (this);
registry.registerAction(action);
getSelectionActions().add(action.getId());


action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.LEFT);
registry.registerAction(action);
getSelectionActions().add(action.getId());

action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.RIGHT);
registry.registerAction(action);
getSelectionActions().add(action.getId());

action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.TOP);
registry.registerAction(action);
getSelectionActions().add(action.getId());

action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.BOTTOM);
registry.registerAction(action);
getSelectionActions().add(action.getId());

action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.CENTER);
registry.registerAction(action);
getSelectionActions().add(action.getId());

action = new AlignmentAction((IWorkbenchPart) this,
PositionConstants.MIDDLE);
registry.registerAction(action);
getSelectionActions().add(action.getId());
}


On Mon, 21 Aug 2006 10:29:30 -0400, Vlad Ciubotariu wrote:

> The actions are not active because your EditPolicies don't return an
> executable command for a a specific type of request.
>
> Here's the code you have to change, following one of my examples, this is
> straightforward to apply to the Shapes example.
>
> vlad
>
> 1) The container editpart the of the components that you will align must
> have an XYLayoutEditPolicy, override:
>
> protected Command createChangeConstraintCommand(
> ChangeBoundsRequest request, EditPart child, Object constraint) {
> if (/*child instanceof BlockEditPart &&*/ constraint instanceof Rectangle) {
> // return a command that can move and/or resize a BlockComponent
> return new BlockSetConstraintCommand((Block) child.getModel(),
> request, (Rectangle) constraint);
> }
> return super.createChangeConstraintCommand(request, child, constraint);
> }
>
> 2) Now the command itself:
>
> public class BlockSetConstraintCommand extends Command {
> ....
>
> public boolean canExecute() {
> Object type = request.getType();
> // make sure the Request is of a type we support:
> return (RequestConstants.REQ_MOVE.equals(type)
> || RequestConstants.REQ_MOVE_CHILDREN.equals(type)
> || RequestConstants.REQ_RESIZE.equals(type)
> || RequestConstants.REQ_RESIZE_CHILDREN.equals(type)
> || RequestConstants.REQ_ALIGN_CHILDREN
> .equals(type));
> }
> ...
> }
>
> 2) In the actionBarContributor:
> ....
> protected void buildActions() {
> addRetargetAction(new DeleteRetargetAction());
> addRetargetAction(new UndoRetargetAction());
> addRetargetAction(new RedoRetargetAction());
>
> addRetargetAction((RetargetAction) ActionFactory.CUT.create(getPage().getWorkbenchWindow()));
> addRetargetAction((RetargetAction) ActionFactory.COPY.create(getPage().getWorkbenchWindow()));
> addRetargetAction((RetargetAction) ActionFactory.PASTE.create(getPage().getWorkbenchWindow()));
>
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
> addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
>
> }
>
> /**
> * @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGloba lActionKeys()
> */
>
> /**
> * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToT oolBar(IToolBarManager)
> */
> public void contributeToToolBar(IToolBarManager tbm) {
> tbm.add(getAction(ActionFactory.UNDO.getId()));
> tbm.add(getAction(ActionFactory.REDO.getId()));
> tbm.add(getAction(ActionFactory.DELETE.getId()));
>
> tbm.add(new Separator());
> tbm.add(getAction(ActionFactory.CUT.getId()));
> tbm.add(getAction(ActionFactory.COPY.getId()));
> tbm.add(getAction(ActionFactory.PASTE.getId()));
>
> tbm.add(new Separator());
> tbm.add(getAction(GEFActionConstants.ALIGN_LEFT));
> tbm.add(getAction(GEFActionConstants.ALIGN_CENTER));
> tbm.add(getAction(GEFActionConstants.ALIGN_RIGHT));
> tbm.add(new Separator());
> tbm.add(getAction(GEFActionConstants.ALIGN_TOP));
> tbm.add(getAction(GEFActionConstants.ALIGN_MIDDLE));
> tbm.add(getAction(GEFActionConstants.ALIGN_BOTTOM));
> tbm.add(new Separator());
> tbm.add(new Action ("VHDL") { public void run () { VHDLGenerator.generateVHDL( getEditor().getPipeline() ); } });
> }
>
> ....
>
>
> On Sun, 20 Aug 2006 15:51:06 +0200, Martin Tauber wrote:
>
>> Hallo newsgroup!
>>
>> What do I have to do to add the "align right", "align middle" and "align
>> left" actions to the ShapeEditor example?
>>
>> I have added the following code which shows the buttons, but they are always
>> inactive nomater howmany shapes I select:
>>
>> ...
>> class ShapesEditorActionBarContributer ....
>>
>> protected void buildActions() {
>> addRetargetAction(new DeleteRetargetAction());
>> addRetargetAction(new UndoRetargetAction());
>> addRetargetAction(new RedoRetargetAction());
>>
>> // started to insert code here
>> addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
>> addRetargetAction(new
>> AlignmentRetargetAction(PositionConstants.CENTER));
>> addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
>> addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
>> addRetargetAction(new
>> AlignmentRetargetAction(PositionConstants.MIDDLE));
>> addRetargetAction(new
>> AlignmentRetargetAction(PositionConstants.BOTTOM));
>> }
>>
>> Thanks for your help!
Previous Topic:How to manage a CellEditor
Next Topic:Problem using tool in view
Goto Forum:
  


Current Time: Fri Apr 26 12:31:27 GMT 2024

Powered by FUDForum. Page generated in 0.03261 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top