Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349124 - java.lang.IllegalArgumentException thrown when selecting ToolEntryEditPart in PaletteStack
Summary: java.lang.IllegalArgumentException thrown when selecting ToolEntryEditPart in...
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy GEF (MVC) (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: 3.7.1 (Indigo SR1)   Edit
Assignee: Alexander Nyßen CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-11 11:35 EDT by CLA
Modified: 2014-05-22 03:41 EDT (History)
4 users (show)

See Also:


Attachments
Patch to show the bug (3.15 KB, text/plain)
2011-06-11 11:46 EDT, CLA
no flags Details
Patch for PaletteEditPart (930 bytes, text/plain)
2011-06-13 08:01 EDT, Alexander Nyßen CLA
no flags Details
Patch to show bug in Logic example (1.43 KB, text/plain)
2011-07-08 03:59 EDT, CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description CLA 2011-06-11 11:35:39 EDT
A regression introduced in GEF 3.7 now that EditParts have to be explicitly selectable when AbstractEditPart.setSelected(true) is called.

I have a GEF Editor with Pallete. The PaletteRoot class uses all of the new Marquee Selection Tools introduced in GEF 3.7 to create them in a PaletteStack in a PaletteToolbar. Like this:

    public PaletteToolbar createControlsGroup() {
        PaletteToolbar toolbar = new PaletteToolbar("Tools");
        
        PaletteStack stack = new PaletteStack("Marquee Selection Tools", "Selection Tools", null);
        toolbar.add(stack);
        
        MarqueeToolEntry marquee = new MarqueeToolEntry("Select contained nodes and related connections");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED_AND_RELATED_CONNECTIONS));
        stack.add(marquee);
        
        marquee = new MarqueeToolEntry("Select touched nodes and related connections");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED_AND_RELATED_CONNECTIONS));
        stack.add(marquee);
        
        marquee = new MarqueeToolEntry("Select contained connections");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED));
        stack.add(marquee);
        
        marquee = new MarqueeToolEntry("Select touched connections");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED));
        stack.add(marquee);
        
        marquee = new MarqueeToolEntry("Select contained nodes");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED));
        stack.add(marquee);
        
        marquee = new MarqueeToolEntry("Select touched nodes");
        marquee.setToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, 
                new Integer(MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED));
        stack.add(marquee);
        
        return toolbar;
    }



The problem occurs when the user selects a different Marquee selection tool from the PaletteStack:

java.lang.IllegalArgumentException: An EditPart has to be selectable (isSelectable() == true) in order to get selected.
	at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
	at org.eclipse.gef.editparts.AbstractEditPart.setSelected(AbstractEditPart.java:1060)
	at org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart.setSelected(ToolEntryEditPart.java:525)
	at org.eclipse.gef.SelectionManager.appendSelection(SelectionManager.java:75)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.appendSelection(AbstractEditPartViewer.java:190)
	at org.eclipse.gef.ui.actions.SetActivePaletteToolAction.run(SetActivePaletteToolAction.java:63)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at uk.ac.bolton.archimate.editor.Application.start(Application.java:59)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Comment 1 CLA 2011-06-11 11:46:55 EDT
Created attachment 197838 [details]
Patch to show the bug

Attached is a patch for the ShapesEditorPaletteFactory.java file in the Shapes example. This adds a PaletteStack with the Marquee Selection tools. Run it and create a Shapes example. Change the marquee selection tool in the PaletteStack a few times. Keep you eye on the Console for the exception...
Comment 2 CLA 2011-06-11 11:57:49 EDT
I changed the title of the bug because it happens with any ToolEntry in a PaletteStack and thus any ToolEntryEditPart.

My MarqueeToolEntry example still shows a good case of the bug, though.
Comment 3 CLA 2011-06-11 14:08:28 EDT
As this used to work in GEF 3.6, some debugging reveals changes in 3.7:

AbstractEditPart.setSelected() asserts the following:

Assert.isLegal(
		isSelectable() || value == SELECTED_NONE,
		"An EditPart has to be selectable (isSelectable() == true) in order to get selected."); //$NON-NLS-1$


New to 3.7 in AbstractGraphicalEditPart:

public boolean isSelectable() {
	return super.isSelectable() && getFigure() != null
			&& getFigure().isShowing();
}

So perhaps getFigure().isShowing() returns false?
Comment 4 Alexander Nyßen CLA 2011-06-12 15:43:34 EDT
Yes, the selection methods have been changed as part of bug #330859, to prevent graphical edit parts without visible figures from becoming selected. I will take a look on how to address this issue. 

I will take a look at the problem to identify what is the best solution to deal with this in ToolEntryEditParts.
Comment 5 CLA 2011-06-12 15:47:32 EDT
(In reply to comment #4)
> Yes, the selection methods have been changed as part of bug #330859, to prevent
> graphical edit parts without visible figures from becoming selected. I will
> take a look on how to address this issue. 
> 
> I will take a look at the problem to identify what is the best solution to deal
> with this in ToolEntryEditParts.

Thanks, Alexander.

I would be very happy if a solution could be found. GEF 3.7 looks good so far, fixing many things on Mac ;-) but this issue has broken our Palettes in our proposed Archi application version 2.0 (http://archi.cetis.ac.uk). If it is not possible to fix this soon, I would be happy to help with a workaround.

Regards,

Phil
Comment 6 Alexander Nyßen CLA 2011-06-13 08:01:56 EDT
Created attachment 197881 [details]
Patch for PaletteEditPart

I think the best solution will probably be to overwrite isSelectable within PaletteEditPart. I have attached a patch that demonstrates this. However, 3.7 is already frozen, so we may not apply this before 3.7.1.
Comment 7 CLA 2011-06-13 08:41:59 EDT
OK. I can understand the freeze on 3.7.

As a workaround that doesn't require patching GEF itself I created this class:

public class TempPaletteEditPartFactory extends PaletteEditPartFactory {

    @Override
    protected EditPart createEntryEditPart(EditPart parentEditPart, Object model) {
        return new ToolEntryEditPart((PaletteEntry) model) {
            @Override
            public boolean isSelectable() {
                return getFigure() != null;
            }
        };
    }
}

Then in my GraphicalEditorWithFlyoutPalette instance over-ride createPaletteViewerProvider():

    @Override
    protected PaletteViewerProvider createPaletteViewerProvider() {
        return new PaletteViewerProvider(getEditDomain()) {
            @Override
            protected void hookPaletteViewer(PaletteViewer viewer) {
                viewer.setEditPartFactory(new TempPaletteEditPartFactory());
                super.hookPaletteViewer(viewer);
            }
        };
    }

So far this works. Do you see any problems with this?
Comment 8 Alexander Nyßen CLA 2011-06-13 09:15:14 EDT
No, looks as a good temporary workaround until 3.7 RC1 is out.
Comment 9 Alexander Nyßen CLA 2011-06-13 09:15:39 EDT
(In reply to comment #8)
> No, looks as a good temporary workaround until 3.7 RC1 is out.
I meant 3.7 SR1 of course :-).
Comment 10 CLA 2011-07-07 12:55:14 EDT
Is there a current 3.7.1 development stream open now that this could be fixed in?
Comment 11 Alexander Nyßen CLA 2011-07-07 16:38:02 EDT
(In reply to comment #10)
> Is there a current 3.7.1 development stream open now that this could be fixed
> in?

Yes, we can add it to the 3.7 maintenance branch, but ... I was quite sure I could reproduce it with the logic editor, which I am currently not able to do? Is it reproducible for you, using the logic example?
Comment 12 CLA 2011-07-08 03:59:22 EDT
Created attachment 199310 [details]
Patch to show bug in Logic example

It only throws the exception if the PaletteStack is a child of a PaletteToolbar.

Patch attached to show this. Select different marquee tools until the exception is thrown.
Comment 13 Alexander Nyßen CLA 2011-07-20 16:11:58 EDT
isSelected() is now overwritten within PaletteEditPart to ensure PaletteEditParts are always selectable by default. Committed changes to R_3_7_maintenance branch as well as HEAD. Resolving as fixed.
Comment 14 Martin Oberhuber CLA 2011-07-21 14:20:22 EDT
This fix looks important, but I don't see any consumable 3.7.1 builds yet ?
Will these be made available anytime soon ?
Comment 15 Alexander Nyßen CLA 2011-07-21 16:31:21 EDT
Well, maybe we could run an integration build tomorrow. Anthony?
Comment 16 CLA 2011-07-29 17:19:16 EDT
(In reply to comment #15)
> Well, maybe we could run an integration build tomorrow. Anthony?

+1
Comment 17 Alexander Nyßen CLA 2014-05-22 03:41:59 EDT
Comment on attachment 199310 [details]
Patch to show bug in Logic example

This patch was only used to reproduce the issue. Marking it as obsolete.