Bug 227687 - An edit part's focus state is not updated properly
Summary: An edit part's focus state is not updated properly
Status: RESOLVED WONTFIX
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy GEF (MVC) (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-17 20:25 EDT by Keith Chong CLA
Modified: 2008-10-15 14:15 EDT (History)
4 users (show)

See Also:


Attachments
Apply to org.eclipse.gef (805 bytes, patch)
2008-04-17 20:25 EDT, Keith Chong CLA
no flags Details | Diff
Shapes example with fix (2.05 KB, image/png)
2008-04-22 10:14 EDT, Keith Chong CLA
no flags Details
Logic Sample - Circuit in focus (15.17 KB, image/png)
2008-04-22 10:16 EDT, Keith Chong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Chong CLA 2008-04-17 20:25:09 EDT
Created attachment 96532 [details]
Apply to org.eclipse.gef

An edit part's focus state is not updated properly which may result in no visible focus feedback in the viewer.

This problem will surface if GEF's SelectionManager is used.

The SelectionManager's focusPart is not updated properly, and consequently, each edit part's focus state is not also.

Looks like null is always passed to the graphical viewer's setFocus method.  This results in the selection manager's setFocus method to not update the current and new editparts' focus states.

See patch.

With this fix, my edit part's setFocus method gets called.
Comment 1 Keith Chong CLA 2008-04-17 20:28:37 EDT
This could be related to bug 143046.
Comment 2 Keith Chong CLA 2008-04-22 10:14:12 EDT
Created attachment 97021 [details]
Shapes example with fix

Here is an example of the shapes diagram with the fix.  Three ellipse figures are selected but one is in focus.  Compared, visually, to what happens without the fix, the focus border is not drawn.
Comment 3 Keith Chong CLA 2008-04-22 10:16:57 EDT
Created attachment 97022 [details]
Logic Sample - Circuit in focus
Comment 4 Keith Chong CLA 2008-04-22 10:25:44 EDT
Other notes:

The multiple selection behaviour would be consistent with say selecting multiple files in the Project Explorer.  (While holding down the shift key, select different files).  There will always be one with a focus border.

In the Logic diagram, try tabbing between the logic diagram with the palette.  The focus will change, but the selection remains.
Comment 5 Anthony Hunter CLA 2008-04-22 14:20:16 EDT
We cannot simply apply this change to GEF as it will affect all clients.

For example, GMF does not want the extra focus "dotted lines" as shown in the example screenshots. GMF already indicates the selected shape with black connections anchors. Then again, so does the GEF shapes example so I am not sure why this fix is even needed.
Comment 6 Anthony Hunter CLA 2008-04-22 15:51:03 EDT
(In reply to comment #5)
> We cannot simply apply this change to GEF as it will affect all clients.
> 
> For example, GMF does not want the extra focus "dotted lines" as shown in the
> example screenshots. GMF already indicates the selected shape with black
> connections anchors. Then again, so does the GEF shapes example so I am not
> sure why this fix is even needed.
> 

I take this back, when using the keyboard, GMF does indeed show focus feedback on the shapes. Focus feedback does not appear when selecting with the mouse.

I will test some more when I get a chance to see which editors hit this line of code. 
Comment 7 Randy Hudson CLA 2008-04-24 10:01:25 EDT
> I take this back, when using the keyboard, GMF does indeed show focus feedback
> on the shapes. Focus feedback does not appear when selecting with the mouse.

That's it exactly. SelectEditPartTracker does *not* set focus on the editpart when it is selected with the mouse, for the reason you mentioned (the black handles already indicate the last part selected).  Similarly, when de-selecting with the mouse (CTRL+Click), it would be annoying to see a focus rectangle left behind after a mouse gesture.

The KeyHandler on the other hand always sets focus to be displayed because the user performed the change using CTRL+SPACE or CTRL+ARROW (for navigating without selecting). These differences in behavior are intended.
Comment 8 Keith Chong CLA 2008-04-29 16:11:18 EDT
Here are some examples, to compare behaviour:

1. Eclipse Color palette.

(Window->Preferences->General->Appearance->Colors and Fonts)

If you mouse click/select one of the basic color squares, you see the focus border as well as the selection rectangle.  Using the arrow keys actually changes the focus...you have to press the spacebar to select the color.

2. In Windows, if you select any of your desktop icons, you don't see a focus border.

3. In Windows Explorer, if you view as icons or as list or details, you do see the focus border around the text.  (And if you do a CTRL-left click, the selection goes away, but the focus border remains).

4. IE's tabs have focus borders.

So, it's debatable whether the focus border should be there or not, it depends on the application/client.  In my example, I need my edit parts to have their focus states updated, so that showFocus will be called.  

Here are some details of what I'm seeing:

I'm extending SelectionEditPolicy, so when my editpart gets selected, its setFocus is called:

protected void addSelectionListener() {
	selectionListener = new EditPartListener.Stub() {
		public void selectedStateChanged(EditPart part) {
			setSelectedState(part.getSelected());
-->			setFocus(part.hasFocus());
		}
	};
	getHost().addEditPartListener(selectionListener);
}

but because the editpart's focus state never gets updated (hasFocus always returns false), the showFocus method (which I override) never gets called from here:

protected void setFocus(boolean value) {
	if (focus == value)
		return;  <-- it'll always return here
	focus = value;
	if (focus)
-->		showFocus();
	else
		hideFocus();
}

I think clients can decide whether to draw the focus border or not in this showFocus method.

Yes, unfortunately, it will affect a lot of clients that use or extend this edit policy and use the SelectionManager.  In particular, the shapes, logic, and flow samples use the Resizable and NonResizable edit policies, where there is already existing code in place to draw the focusBorder.


Comment 9 Randy Hudson CLA 2008-05-08 12:46:42 EDT
> but because the editpart's focus state never gets updated (hasFocus always
> returns false), the showFocus method (which I override) never gets called from
> here:

That shouldn't be the case.  Try selecting your part with the mouse and pressing CTRL+SPACE. It should have focus at that point. Does it not?
Comment 10 Anthony Hunter CLA 2008-10-15 14:15:01 EDT
We do not have enough to go on here without breaking clients, so resolving as WONTFIX.

Keith, you will have to reopen and continue the discussion if you feel strongly otherwise.