Bug 176198 - [Field Assist] - API - ControlDecoration should provide mouse events
Summary: [Field Assist] - API - ControlDecoration should provide mouse events
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Susan McCourt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 81334
Blocks:
  Show dependency tree
 
Reported: 2007-03-02 12:06 EST by Susan McCourt CLA
Modified: 2007-03-20 10:48 EDT (History)
7 users (show)

See Also:


Attachments
Notification area is custom drawn (58.32 KB, image/jpeg)
2007-03-15 10:07 EDT, Alex Bernstein CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Susan McCourt CLA 2007-03-02 12:06:44 EST
Opening this bug to separate out this feature request which was made in Bug #162770 by Alex Bernstein:

2. It would be nice if there was a way to detect when user clicks mouse on the
decoration, or on the area reserved for decoration(s) (along left or right
edge)
Comment 1 Susan McCourt CLA 2007-03-02 12:07:56 EST
Note:  The original request was to provide mouse click notification in order to enable bookmark-style navigation:
(from bug #162770):
"The editor(s) in our product are form-based editors. They display multiple
controls/widgets. These widgets allow user to view/edit or otherwise modify
some data attribute. 
There are various additional properties that can be associated with most
attributes, generic, like errors, bookmarks and tasks, and product-specific
such as data correlation sites. All of these are displayed in various forms of
text styles inside StyledText-based attributes (other widgets also have some
way of displaying them). 
Because the editor is form based editor, we want these attributes to be 
displayed along the left (and right) edges of the widget to which they
"belong". We already do it now, using our own mechanism. The ultimate goal is
to have annotation areas associated with a widget, as opposed to the entire
editor.
User should be able to click on the little decorations to navigate directly to
the location inside an attribute."
Comment 2 Susan McCourt CLA 2007-03-02 12:17:11 EST
The original use case suggests that use of a ruler-type mechanism rather than ControlDecoration might be more suitable.  However, additional requests have been received for mouse click functionality:
- a click event to be interpreted by the application 
- an event for triggering a context menu

After discussing the various use cases, we think the best approach is to provide:
- a selection event notification for click-select
- a selection event (default select) for double-click
- a menu detect event for menu popup gesture 

At this time we won't provide a visual such as selection animation or mouse cursor change.  We are trying to supply the minimum function needed for this first iteration.  

We noted that the Windows XP notification area shows small icons that support app-defined click and context menu behavior, without showing a visual indication that these actions are available.  
Comment 3 Susan McCourt CLA 2007-03-02 12:19:03 EST
cc'ing interested parties from Bug #162770. 
Comment 4 Susan McCourt CLA 2007-03-09 10:41:23 EST
API REQUEST:
Add API to add and remove untyped listeners to ControlDecoration, supporting SWT.Selection, SWT.DefaultSelection, and SWT.MenuDetect.  Listeners are untyped because the underlying SWT.MenuDetect event is untyped, and we want to treat all ControlDecorationEvents consistently.  It also allows for future addition of event types if necessary.

RISKS:
None 

PERFORMANCE IMPACT:
Negligible.  For simplicity, the underlying SWT events (mouse down, mouse double click, menu detect) are hooked when other events are hooked, but no work is done on receipt of these events unless a client has registered a listener.  We are already listening to hover/enter/exit events to support the hover help.

OTHER IMPACTS:
Field assist example will be updated to demonstrate use.

JAVADOC:
/**
 * Adds the listener to the collection of listeners who will be notified
 * when an event of the given type occurs. When the event does occur in the
 * decoration, the listener is notified by sending it the
 * <code>handleEvent()</code> message. The event type describes the type
 * of event of interest.
 * <p>
 * When listeners are notified, the event data field will contain the
 * decoration. The widget field will contain the composite on which the
 * decoration is rendered. For <code>SWT.Selection</code> and
 * <code>SWT.DefaultSelection</code> events, the x and y fields will
 * describe where the event occurred in coordinates relative to the
 * composite on which the decoration is rendered, not relative to the
 * decoration itself. For the <code>SWT.MenuDetect</code> event, the x and
 * y fields are in display relative coordinates.
 * 
 * @param eventType
 *            the type of event to listen for. It should be one of
 *            <code>SWT.Selection</code>,
 *            <code>SWT.DefaultSelection</code>, or
 *            <code>SWT.MenuDetect</code>. All other event types are
 *            ignored.
 * 
 * @param listener
 *            the listener which should be notified when the event occurs
 * 
 * @see org.eclipse.swt.widgets.Listener
 * @see #removeListener
 */

/**
 * Removes the listener from the collection of listeners who will be
 * notified when an event of the given type occurs. The event type describes
 * the event of interest.
 * 
 * @param eventType
 *            the type of event to listen for. It should be one of
 *            <code>SWT.Selection</code>,
 *            <code>SWT.DefaultSelection</code>, or
 *            <code>SWT.MenuDetect</code>.
 * @param listener
 *            the listener which should no longer be notified when the event
 *            occurs. This message has no effect if the listener was not
 *            previously added to the receiver.
 * 
 * @see org.eclipse.swt.widgets.Listener
 * @see #addListener
 */


Comment 5 Mike Wilson CLA 2007-03-09 11:00:34 EST
+1
Comment 6 Susan McCourt CLA 2007-03-12 17:49:48 EDT
fixed in HEAD >20070312 (should be in the IBuild).
Modified example to show its usage.

A prettier (semantic) example, such as quick fix, might be nice for the future, but not necessary for M6.
Comment 7 Alex Bernstein CLA 2007-03-15 10:05:53 EDT
I was not sure if this was discussed before, or was taken care of, but there is one more thing:

I think it will be useful to have a way to custom paint (or/and just have an access to) the area (composite?) where the icons are placed. 

I am adding a screenshot from my editor. Notice the yellow background in "notification" area. This is a visual clue to the user that "data-correlation" can be performed in that field. Blue areas in the notification area correspond with the areas inside related widgets.
Comment 8 Alex Bernstein CLA 2007-03-15 10:07:06 EDT
Created attachment 60939 [details]
Notification area is custom drawn
Comment 9 Susan McCourt CLA 2007-03-15 12:06:06 EDT
Alex, you mentioned this feature request in #162770, which also addressed mouse behavior and custom positioning.  I suggest you open up a new bug for the owner draw capability or else it's likely to get lost in the other bug.  

We don't plan to add any more functionality to decorations in 3.3, but we should track that request for the future.
Comment 10 Susan McCourt CLA 2007-03-16 12:13:07 EDT
Reopening bug.  In bug #81334, SWT is now adding a typed listener for MenuDetect.  This eliminates the rationale for untyped listeners in JFace discussed in comment #4.  Given SWT is adding a typed MenuDetect event, we should expose those typed events for selection and menu detect in JFace rather than using the untyped.
Comment 11 Kevin McGuire CLA 2007-03-16 13:08:51 EDT
(In reply to comment #10)

Agree, makes sense. Originally we wanted typed, but also wanted consistency with SWT, and now we can have both.  A bit late coming but oh well lets do it right.
Comment 12 Susan McCourt CLA 2007-03-16 14:38:56 EDT
API REQUEST:  change the listeners to typed listeners
RISKS:  None, this is new API
PERFORMANCE IMPACTS:  This is actually a slight improvement in calling listeners.  Now that SWT documents a MenuDetectEvent we don't have to copy all relevant fields from an untyped event to a new untyped event object.  We can use the SWT constructors to copy only the relevant fields.

REMOVE:  the untyped add/remove listener calls from comment #4
ADD 4 METHODS:
/**
 * Adds the listener to the collection of listeners who will be notified
 * when the platform-specific context menu trigger has occurred, by sending
 * it one of the messages defined in the <code>MenuDetectListener</code>
 * interface.
 * <p>
 * The <code>widget</code> field in the SelectionEvent will contain the
 * Composite on which the decoration is rendered that received the click.
 * The <code>x</code> and <code>y</code> fields will be in coordinates
 * relative to the display. The <code>data</code> field will contain the
 * decoration that received the event.
 * </p>
 * 
 * @param listener
 *            the listener which should be notified
 * 
 * @see org.eclipse.swt.events.MenuDetectListener
 * @see org.eclipse.swt.events.MenuDetectEvent
 * @see #removeMenuDetectListener
 */
public void addMenuDetectListener(MenuDetectListener listener) 

/**
 * Removes the listener from the collection of listeners who will be
 * notified when the platform-specific context menu trigger has occurred.
 * 
 * @param listener
 *            the listener which should no longer be notified. This message
 *            has no effect if the listener was not previously added to the
 *            receiver.
 * 
 * @see org.eclipse.swt.events.MenuDetectListener
 * @see #addMenuDetectListener
 */
public void removeMenuDetectListener(MenuDetectListener listener) 

/**
 * Adds the listener to the collection of listeners who will be notified
 * when the decoration is selected, by sending it one of the messages
 * defined in the <code>SelectionListener</code> interface.
 * <p>
 * <code>widgetSelected</code> is called when the decoration is selected
 * (by mouse click). <code>widgetDefaultSelected</code> is called when the
 * decoration is double-clicked.
 * </p>
 * <p>
 * The <code>widget</code> field in the SelectionEvent will contain the
 * Composite on which the decoration is rendered that received the click.
 * The <code>x</code> and <code>y</code> fields will be in coordinates
 * relative to that widget. The <code>data</code> field will contain the
 * decoration that received the event.
 * </p>
 * 
 * @param listener
 *            the listener which should be notified
 * 
 * @see org.eclipse.swt.events.SelectionListener
 * @see org.eclipse.swt.events.SelectionEvent
 * @see #removeSelectionListener
 */
public void addSelectionListener(SelectionListener listener)

/**
 * Removes the listener from the collection of listeners who will be
 * notified when the decoration is selected.
 * 
 * @param listener
 *            the listener which should no longer be notified. This message
 *            has no effect if the listener was not previously added to the
 *            receiver.
 * 
 * @see org.eclipse.swt.events.SelectionListener
 * @see #addSelectionListener
 */
public void removeSelectionListener(SelectionListener listener)
Comment 13 Mike Wilson CLA 2007-03-16 16:11:10 EDT
+1.
Comment 14 Susan McCourt CLA 2007-03-16 16:16:40 EDT
Fixed (again).
Available >20070316.

Note you have to load the latest SWT to load JFace until the next build.  I will send a notice to platform-ui-dev
Comment 15 Susan McCourt CLA 2007-03-20 10:48:15 EDT
verified I20070320-0010, WinXP using FieldAssist example.