Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » getSelectedObjects error in SelectionAction
getSelectedObjects error in SelectionAction [message #222435] Tue, 05 September 2006 13:37 Go to next message
Eclipse UserFriend
Originally posted by: paolo.reitelli.datamat.it

Hi all,

I created an action subclassing SelectionAction, I must use the method
getSelectedObjects to perform my action, the problem is:

getSelectedObjects() returns the correct list when used in the
"calculateEnabled" method , but when I use it in the "run" method (clicking
the action's button in the toolbar) it returns an empty list.

So when I select objects in my editor and then click to perform my action it
does nothing because it doesn't have objects to work on.

Thanks in advance,
Paolo.


P.S.

Here's some code snippets:

MY ACTION CLASS

public class AllineaSinistraAction extends SelectionAction {

static public String
ID="com.pr.deserver.editors.AllineaSinistraAction";
static public String TEXT="Allinea a sinistra";
static public String TOOLTIP="Allinea a sinistra i controlli
selezionati";

public AllineaSinistraAction(IWorkbenchPart part) {
super(part);
setLazyEnablementCalculation(false);
setId(AllineaSinistraAction.ID);
}

public void run()
{
System.out.println(getSelectedObjects()); -- just to see that
selected objets' list is empty
}


protected boolean calculateEnabled() {
return getSelectedObjects().size()>1; -- here the list is
not empty
}

}


MY EDITOR CLASS

public class DeServerEditor extends GraphicalEditorWithFlyoutPalette
implements CommandStackListener,
ISelectionListener{

....

protected void createActions() {

super.createActions();

ActionRegistry registry = getActionRegistry();
IAction action;

action = new AllineaSinistraAction((IWorkbenchPart) this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
}
....

}


MY EDITOR CONTRIBUTOR CLASS

public class DeServerEditorContributor extends ActionBarContributor {

private IEditorPart m_editor;
private AllineaSinistraAction m_allineaSinistra;

....

protected void buildActions() {
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());
addRetargetAction(new DeleteRetargetAction());
buildAlignmentActions();
addAction(m_allineaSinistra);
}

private void buildAlignmentActions() {

m_allineaSinistra=new AllineaSinistraAction(m_editor);
m_allineaSinistra.setToolTipText("Allinea a sinistra");
m_allineaSinistra.setId("com.pr.deserver.editors.AllineaSinistrAction ");
m_allineaSinistra.setImageDescriptor(create("icons/", "left_align.gif"));

}

....

}
Re: getSelectedObjects error in SelectionAction [message #222448 is a reply to message #222435] Tue, 05 September 2006 16:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: paolo.reitelli.datamat.it

I' ve noticed that, when the run() method is called , the almost all the
member of my action class are null:
It's not the same when the calculateEnabled() is called (they are not null)

Thanks.


"PaoloReitelli" <paolo.reitelli@datamat.it> ha scritto nel messaggio
news:edjuiu$o5n$1@utils.eclipse.org...
> Hi all,
>
> I created an action subclassing SelectionAction, I must use the method
> getSelectedObjects to perform my action, the problem is:
>
> getSelectedObjects() returns the correct list when used in the
> "calculateEnabled" method , but when I use it in the "run" method
> (clicking the action's button in the toolbar) it returns an empty list.
>
> So when I select objects in my editor and then click to perform my action
> it does nothing because it doesn't have objects to work on.
>
> Thanks in advance,
> Paolo.
>
>
> P.S.
>
> Here's some code snippets:
>
> MY ACTION CLASS
>
> public class AllineaSinistraAction extends SelectionAction {
>
> static public String
> ID="com.pr.deserver.editors.AllineaSinistraAction";
> static public String TEXT="Allinea a sinistra";
> static public String TOOLTIP="Allinea a sinistra i controlli
> selezionati";
>
> public AllineaSinistraAction(IWorkbenchPart part) {
> super(part);
> setLazyEnablementCalculation(false);
> setId(AllineaSinistraAction.ID);
> }
>
> public void run()
> {
> System.out.println(getSelectedObjects()); -- just to see that
> selected objets' list is empty
> }
>
>
> protected boolean calculateEnabled() {
> return getSelectedObjects().size()>1; -- here the list
> is not empty
> }
>
> }
>
>
> MY EDITOR CLASS
>
> public class DeServerEditor extends GraphicalEditorWithFlyoutPalette
> implements CommandStackListener,
> ISelectionListener{
>
> ...
>
> protected void createActions() {
>
> super.createActions();
>
> ActionRegistry registry = getActionRegistry();
> IAction action;
>
> action = new AllineaSinistraAction((IWorkbenchPart) this);
> registry.registerAction(action);
> getSelectionActions().add(action.getId());
> }
> ...
>
> }
>
>
> MY EDITOR CONTRIBUTOR CLASS
>
> public class DeServerEditorContributor extends ActionBarContributor {
>
> private IEditorPart m_editor;
> private AllineaSinistraAction m_allineaSinistra;
>
> ...
>
> protected void buildActions() {
> addRetargetAction(new UndoRetargetAction());
> addRetargetAction(new RedoRetargetAction());
> addRetargetAction(new DeleteRetargetAction());
> buildAlignmentActions();
> addAction(m_allineaSinistra);
> }
>
> private void buildAlignmentActions() {
>
> m_allineaSinistra=new AllineaSinistraAction(m_editor);
> m_allineaSinistra.setToolTipText("Allinea a sinistra");
> m_allineaSinistra.setId("com.pr.deserver.editors.AllineaSinistrAction ");
> m_allineaSinistra.setImageDescriptor(create("icons/", "left_align.gif"));
>
> }
>
> ...
>
> }
>
Re: getSelectedObjects error in SelectionAction [message #230443 is a reply to message #222435] Mon, 12 February 2007 18:06 Go to previous message
Eclipse UserFriend
Originally posted by: kvdijken.tiscali.nl

I also just discovered a problem with SelectionAction.getSelection(), see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=173895

Koen





PaoloReitelli wrote:
> Hi all,
>
> I created an action subclassing SelectionAction, I must use the method
> getSelectedObjects to perform my action, the problem is:
>
> getSelectedObjects() returns the correct list when used in the
> "calculateEnabled" method , but when I use it in the "run" method (clicking
> the action's button in the toolbar) it returns an empty list.
>
> So when I select objects in my editor and then click to perform my action it
> does nothing because it doesn't have objects to work on.
>
> Thanks in advance,
> Paolo.
>
>
> P.S.
>
> Here's some code snippets:
>
> MY ACTION CLASS
>
> public class AllineaSinistraAction extends SelectionAction {
>
> static public String
> ID="com.pr.deserver.editors.AllineaSinistraAction";
> static public String TEXT="Allinea a sinistra";
> static public String TOOLTIP="Allinea a sinistra i controlli
> selezionati";
>
> public AllineaSinistraAction(IWorkbenchPart part) {
> super(part);
> setLazyEnablementCalculation(false);
> setId(AllineaSinistraAction.ID);
> }
>
> public void run()
> {
> System.out.println(getSelectedObjects()); -- just to see that
> selected objets' list is empty
> }
>
>
> protected boolean calculateEnabled() {
> return getSelectedObjects().size()>1; -- here the list is
> not empty
> }
>
> }
>
>
> MY EDITOR CLASS
>
> public class DeServerEditor extends GraphicalEditorWithFlyoutPalette
> implements CommandStackListener,
> ISelectionListener{
>
> ...
>
> protected void createActions() {
>
> super.createActions();
>
> ActionRegistry registry = getActionRegistry();
> IAction action;
>
> action = new AllineaSinistraAction((IWorkbenchPart) this);
> registry.registerAction(action);
> getSelectionActions().add(action.getId());
> }
> ...
>
> }
>
>
> MY EDITOR CONTRIBUTOR CLASS
>
> public class DeServerEditorContributor extends ActionBarContributor {
>
> private IEditorPart m_editor;
> private AllineaSinistraAction m_allineaSinistra;
>
> ...
>
> protected void buildActions() {
> addRetargetAction(new UndoRetargetAction());
> addRetargetAction(new RedoRetargetAction());
> addRetargetAction(new DeleteRetargetAction());
> buildAlignmentActions();
> addAction(m_allineaSinistra);
> }
>
> private void buildAlignmentActions() {
>
> m_allineaSinistra=new AllineaSinistraAction(m_editor);
> m_allineaSinistra.setToolTipText("Allinea a sinistra");
> m_allineaSinistra.setId("com.pr.deserver.editors.AllineaSinistrAction ");
> m_allineaSinistra.setImageDescriptor(create("icons/", "left_align.gif"));
>
> }
>
> ...
>
> }
>
>
Previous Topic:Scrolling a graphical view
Next Topic:PrintAction in Mac
Goto Forum:
  


Current Time: Thu Apr 25 23:56:43 GMT 2024

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

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

Back to the top