Context menu via viewListener

The main documentation says to use doMouseUp to implement a context menu. Is there any reason why I can’t just do:

[code]public class ContextMenuController implements JGoViewListener {
public void viewChanged(JGoViewEvent e) {
boolean rightClick = (e.getModifiers() & SWT.BUTTON3) != 0;

    switch (e.getHint()) {
    case JGoViewEvent.CLICKED:
        JGoObject obj=e.getJGoObject().getTopLevelObject();

        if (rightClick) {
            if (obj instanceof RMNode) {

                Menu contextMenu = new Menu(view);
    blah blah blah
                 contextMenu.setLocation(view.toDisplay(e.getPointViewCoords( )));
                contextMenu.setVisible(true);                        
            }    
        }
        break;
    }
}

}

[/code]

My code won’t work ever sense I refactored it into this controller class, wondering if this is why.

Second related question: how do I disable the default right-selection behavior (sticky two click bounded selection, rather than single click-n-drag bounded selection)? This seemed to work but was interfering with other right click stuff like the above, I think.

[code] public boolean doMouseDown(int modifiers, Point dc, Point vc)
{
boolean rightClick = (modifiers & SWT.BUTTON3) != 0;

    if (rightClick) return false;
    
    // otherwise implement the default behavior
    return super.doMouseDown(modifiers, dc, vc);

}[/code]

Well, for the second question, I think you need to override JGoView.startDragBoxSelection to return false if BUTTON3 is being used.
Separate issue: I wonder if checking ((modifiers & SWT.BUTTON3) == SWT.BUTTON3) wouldn’t be safer and more correct. I think it’s a moot point here.
I’m not sure about your first question. I suspect that the JGoView’s mouse state, JGoView.getState(), isn’t MouseStateSelection then. But I haven’t verified this.

Re. context menu.

I copied the viewChanged method into my view class and made my view implement viewlistener and add itself as a listener, for the purposes of debugging. This viewChanged method is NOT receiving right click events. I assume this is also why the refactored class was broken. Here is the only place I have touched the mouse methods. Am I doing something stupid to prevent right clicks from percolating up?

[code] public boolean doMouseDown(int modifiers, Point dc, Point vc) {
boolean ctrl = ((modifiers & SWT.CTRL) != 0);
boolean shift = ((modifiers & SWT.SHIFT) != 0);
boolean alt = ((modifiers & SWT.ALT) != 0);
boolean rightClick = (modifiers & SWT.BUTTON3) != 0;
boolean leftClick = (modifiers & SWT.BUTTON1) != 0;

    if (sketcher.isSketching()) {
        if (leftClick) {
            if (shift) {
                sketcher.createNodeThenHover(dc);
            } else {
                sketcher.createNode(dc);
            }
            return true; //left click is for sketcher use only, don't allow default behavior
        }
        //other sketcher hooks here - i.e. middle click or something
        //i wouldn't assign right click, leave that for context menus
    }
    return super.doMouseDown(modifiers, dc, vc);
}
public void doCancelMouse() {
    sketcher.reset();
    super.doCancelMouse();
    getSelection().clearSelection();
}[/code]

I just modified MinimalApp.java to have the MinimalApp class implement JGoViewListener, to have the init() method do:
myView.addViewListener(this);
and implement the following method:
public void viewChanged(JGoViewEvent e) {
if (e.getHint() == JGoViewEvent.CLICKED)
System.err.println("CLICKED " + Integer.toHexString(e.getModifiers()));
}
When I run this, it prints CLICKED 80000 for left mouse clicks and CLICKED 200000 for right mouse clicks.

Can you think of any possible reasons that right clicks might not be percolating through? If you wanted to trap them, how would you do it (thinking backwards)?

this is the problem method. is there an alternate way to kill right-selection? this is the way you told me to in your original response to this post.

i also don’t understand why this kills right click behavior, maybe a misfeature?

[code] protected boolean startDragBoxSelection(int modifiers, Point dc, Point vc) {
if (sketcher.isSketching()) {
return false; //no selection at all if in sketch mode.
}

    boolean rightClick = (modifiers & SWT.BUTTON3) != 0;
    if (rightClick) return false; //DIE
    return super.startDragBoxSelection(modifiers, dc, vc); //left selection is OK in any other mode
}[/code]

OK, I have modified MinimalApp slightly further, replacing the JGoView that it declares and creates, with a CustomView instead, defined as follows:
public class CustomView extends JGoView {
public CustomView(Composite parent, int style) {
super(parent, style);
}
protected boolean startDragBoxSelection(int modifiers, Point dc, Point vc) {
boolean rightClick = (modifiers & SWT.BUTTON3) != 0;
if (rightClick) return false; //DIE
return super.startDragBoxSelection(modifiers, dc, vc); //left selection is OK in any other mode
}
}
This too works as I believe you intend. Left click operations work just as normal. Right click occurs on nodes and links as the viewChanged listener/handler testifies, although it does not actually implement a popup menu. Right click or right drag in the background has no effect at all, as I think you want, due to the override of JGoView.startDragBoxSelection. I am assuming “sketching” mode.
So I’m sorry, but I can’t explain the behavior you see. There must be something else in your application that is causing a problem. Unless what I’m doing to extend MinimalApp is different from what you wanted…

Thank you for looking into it - I’ll go duplicate what you did to convince myself.