Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341422 - Marquee Selection Behavior Options
Summary: Marquee Selection Behavior Options
Status: REOPENED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.7.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-30 16:09 EDT by Rhett Hudson CLA
Modified: 2016-07-04 09:48 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rhett Hudson CLA 2011-03-30 16:09:35 EDT
Build Identifier: 

Graphiti's DiagramEditor provides a pallete of tools for that include some standard tools that cannot be changed by the client programmer. These include the PanningSelectionTool and the MarqueeSelectionTool. Currently, the drag tracker that is part of the PanningSelectionTool and the MarqueeSelectionTool itself are both created with a behavioral property that causes them to include only nodes when the user drags out a selection marquee.

To change the behavior to, for instance, include connections as well as nodes, the client programmer has to extend three or four internal classes just to call setMarqueeBehavior() on the selection tools during creation.

It would be nice if Graphiti supported an interface that allowed the client programmer to change the behavior. This would avoid having to extend those internal classes. It would also support an end user preference for including connections that are entirely inside the selection marquee or those which are touched by it.

Reproducible: Always
Comment 1 Michael Wenz CLA 2011-07-18 07:08:26 EDT
Out-of-scope for Juno, unless there are contributions in this area
Comment 2 Rhett Hudson CLA 2012-01-12 14:02:04 EST
I've had to revisit this after the 0.9 refactor. The default drag tracker for marquee selection is created by an anonymous class created in DiagramEditor's configureGraphicalViewer() method. This object is an instance of ScalableRootEditPartAnimated.

It would be nice if I could optionally provide a DragTracker factory that ScalableRootEditPartAnimated could use instead of its simple default implementation. That would allow me to set up the DragTracker in the manner that I desired.
Comment 3 Ignacio Ibanez CLA 2016-03-29 06:44:54 EDT
Any news on this issue? I´m looking into DiagramBehavior´s configureGraphicalViewer, is there a workaround to modify the marquee selection behavior as of today?
Comment 4 Michael Wenz CLA 2016-03-30 05:04:17 EDT
(In reply to Ignacio Ibanez from comment #3)
> Any news on this issue?

Sorry, no news. I simply did not have this on my radar. But as I wrote, I'm open for ideas and contributions here.

On the other hand I'm afraid that for the current dev cycle for Eclipse Neon and Graphiti 0.13.0 this is too late, since M6 has passed which means API freeze. but I can put tis on the topics list for the next Graphiti release as part of Eclipse O...

Michael
Comment 5 Ignacio Ibanez CLA 2016-03-30 05:40:08 EDT
Hi Michael,

I can tell you what I tried, though it might be perfectly useless.

Based on what I read around regarding GEF I tried something along these lines:

In my Diagram Behavior class, calling either in initializeGraphicalViewer() or elsewhere:

...

 updateToolEntryProperty(getPaletteBehavior().getPaletteRoot().getChildren(), GFMarqueeToolEntry.class,
                MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR, MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED_AND_RELATED_CONNECTIONS);
...


private static void updateToolEntryProperty(List<?> paletteContainerList, Class<? extends ToolEntry> toolEntryClass,
            Object property, Object value) {
        for (Object paletteEntry : paletteContainerList) {
            if (paletteEntry instanceof PaletteContainer) {
                updateToolEntryProperty(((PaletteContainer) paletteEntry).getChildren(), toolEntryClass, property,
                        value);
            }
            if (toolEntryClass.isInstance(paletteEntry)) {
                ((ToolEntry) paletteEntry).setToolProperty(property, value);
                return;
            }
        }
    }

Which did not work. The other option I thought of required extending/overriding classes/methods 3-4 layers deep into graphiti code iirc. 

This issue, in my scenario, seems to be related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=376714
as the selection behavior is not consistent between marquee and ctrl-A, and both are hard/impossible to customize without deep hack & slash.

Thanks for your time, any ideas/updates on these issues will be greatly appreciated.
Comment 6 Erwin De Ley CLA 2016-06-29 06:33:48 EDT
From Ignacio's hint, to override something in your own Diagram Behavior, I seem to have something that could work.
This is for cases where the user selects several diagram elements with the mouse drag to do a marquee selection.
I'm not using a palette marquee tool.

When trying it out, I indeed get the contained connections in the selection as well.

I'm overriding with :

  protected void configureGraphicalViewer() {

    ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getDiagramContainer().getGraphicalViewer();

    ScalableRootEditPartAnimated rootEditPart = new ScalableRootEditPartAnimated(viewer, getConfigurationProvider()) {
      protected GridLayer createGridLayer() {
        return new org.eclipse.graphiti.ui.internal.util.draw2d.GridLayer(
            (IConfigurationProviderInternal) getConfigurationProvider());
      }
      @Override
      public DragTracker getDragTracker(Request req) {
        GFMarqueeDragTracker trckr= new GFMarqueeDragTracker(this);
        trckr.setMarqueeBehavior(GFMarqueeSelectionTool.BEHAVIOR_NODES_AND_CONNECTIONS);
        return trckr;
      }
    };

    // configure ZoomManager
    viewer.setRootEditPart(rootEditPart); // support

    // animation of the zoom
    ZoomManager zoomManager = rootEditPart.getZoomManager();
    List<String> zoomLevels = new ArrayList<String>(3);
    zoomLevels.add(ZoomManager.FIT_ALL);
    zoomLevels.add(ZoomManager.FIT_WIDTH);
    zoomLevels.add(ZoomManager.FIT_HEIGHT);
    zoomManager.setZoomLevelContributions(zoomLevels);
    IToolBehaviorProvider toolBehaviorProvider = getConfigurationProvider().getDiagramTypeProvider()
        .getCurrentToolBehaviorProvider();
    zoomManager.setZoomLevels(toolBehaviorProvider.getZoomLevels());

    this.initActionRegistry(zoomManager);

    // set the keyhandler.
    viewer.setKeyHandler((new GraphicalViewerKeyHandler(viewer)).setParent(getCommonKeyHandler()));

    // settings for grid and guides
    Diagram diagram = getConfigurationProvider().getDiagram();

    boolean snapToGrid = diagram.isSnapToGrid();
    int horizontalGridUnit = diagram.getGridUnit();
    int verticalGridUnit = diagram.getVerticalGridUnit();
    if (verticalGridUnit == -1) {
      // No vertical grid unit set (or old diagram before 0.8): use
      // vertical grid unit
      verticalGridUnit = horizontalGridUnit;
    }
    boolean gridVisisble = (horizontalGridUnit > 0) && (verticalGridUnit > 0);

    viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, new Boolean(gridVisisble));
    viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, new Boolean(snapToGrid));
    viewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(horizontalGridUnit, verticalGridUnit));
    viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, toolBehaviorProvider.isShowGuides());

    // context button manager
    IConfigurationProviderInternal configurationProvider = (IConfigurationProviderInternal) this
        .getConfigurationProvider();
    configurationProvider.setContextButtonManager(new ContextButtonManagerForPad(this, configurationProvider
        .getResourceRegistry()));

  }

The important part in here is the getDragTracker() change, that sets the selection mode for each created marquee selection tool.
The rest of the method implementation is just copied over from the base class, except that I had to remove :

		/* sw: make scroll bars always visible */
		if (getDiagramScrollingBehavior() == DiagramScrollingBehavior.SCROLLBARS_ALWAYS_VISIBLE) {
			GFFigureCanvas figureCanvas = getGFFigureCanvas();
			if (figureCanvas != null) {
				figureCanvas.setScrollBarVisibility(FigureCanvas.ALWAYS);
			}
		}

as this uses private methods. As it was marked as deprecated I hope this is not a problem!?
Comment 7 Michael Wenz CLA 2016-06-30 05:01:31 EDT
Erwin,

thanks for this proposal. Without checking if there are further changes in your code snippet for that method, it would be a rather easy change to extract the getDragDracker method and make it overridable. Would that already help?

Regardsing the decprecated stuff: removing should not be an issue as long as your tool does not use that mode.

Thanks,
Michael
Comment 8 Erwin De Ley CLA 2016-06-30 05:23:08 EDT
Hi Michael,

An overridable method getDragtracker() on DiagramBehavior would indeed make this easier and would also provide better separation from the other things done in the configureGraphicalViewer() method. Which would reduce maintainability risks when upgrading to future Graphiti versions.

So yes, that would be great!

On the other hand, the approach above is not yet complete I guess. I.e. any other places where marquee selections can be triggered (where instances of the DragTracker or even of GFMarqueeSelectionTool are created/used) still stick to the default BEHAVIOR_NODES_CONTAINED. I guess this would be the case for e.g. editors using the palette marquee tool?

I also haven't figured out yet what to do for the select-all behaviour.

If there would be a way to set a general "selection behavior" for marquee tool, drag and select-all that would be ideal...

(Can you point me to where to look for the select-all behavior?)

And while I'm dreaming ;-) as it seems some users/developers prefer to select model elements without connections while others want to include connections : why not make both possible via a modifier key or so? E.g. Alt drag or so doesn't pick connections and plain drag does; Ctrl-A selects everything and Ctrl-Alt-A no connections etc? (but such choice is not needed in Triquetrum, we always want to copy connections along)

cheers
erwin
Comment 9 Ignacio Ibanez CLA 2016-06-30 05:55:18 EDT
Hi agree, word by word, with erwin´s last comment.
Comment 10 Michael Wenz CLA 2016-07-04 09:47:58 EDT
Merged for Oxygen M1 and Graphiti 0.14.0
Comment 11 Michael Wenz CLA 2016-07-04 09:48:46 EDT
(In reply to Michael Wenz from comment #10)
> Merged for Oxygen M1 and Graphiti 0.14.0

Sorry, wrong bug