Bug 198260 - [Viewers] Provide possibility to set cell selection
Summary: [Viewers] Provide possibility to set cell selection
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 enhancement with 5 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-07-30 09:13 EDT by Michael Seele CLA
Modified: 2016-09-28 03:08 EDT (History)
13 users (show)

See Also:


Attachments
work in progress (4.95 KB, patch)
2008-02-20 14:02 EST, Thomas Schindl CLA
no flags Details | Diff
Snippet demonstrating workaround (10.69 KB, application/octet-stream)
2011-05-05 23:07 EDT, Boris Bokowski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Seele CLA 2007-07-30 09:13:45 EDT
Build ID:  I20070625-1500

please make the setFocusCell(ViewerCell focusCell) in TableViewerFocusCellManager public for programatically select a cell.
i need this in my 3.3 recode for jinto (http://guh-software.de/jinto.html) especially in the search function, which should select the cell with the founded text.
my workaround now is to override the class with my own in the same package. but this is a hack :-(
Comment 1 Thomas Schindl CLA 2007-07-30 09:24:06 EDT
Instead of Opening this API. I'd like to add API like StructuredSelection to set the selected Cell from the outside. 

Something like:
ColumnViewer#setSelection(new StructuredCellSelection())

If we make StructuredCellSelection extend from StructuredSelection you have access to this selection from anywhere you want. I think this would be the cleanest solution.
Comment 2 Michael Seele CLA 2007-07-30 09:39:39 EDT
> If we make StructuredCellSelection extend from StructuredSelection you have
> access to this selection from anywhere you want. I think this would be the
> cleanest solution.
> 
+1
Comment 3 Michael Seele CLA 2007-08-02 05:12:01 EDT
is there a chance to get it into on of the next releases (3.3.1, 3.3.2)? i know it's more an enhancement than a bug but for me it's useless to have this cool new TableViewer/Cell Selection API if i can't select cell's programatically... 
also my hack (i described in the first comment) doesn't work, cause i get an IllegalAccessError on runtime when i override the friendly method setFocusCell :-(
Comment 4 Thomas Schindl CLA 2007-08-02 09:25:59 EDT
(In reply to comment #3)
> is there a chance to get it into on of the next releases (3.3.1, 3.3.2)? i know
> it's more an enhancement than a bug but for me it's useless to have this cool
> new TableViewer/Cell Selection API if i can't select cell's programatically... 
> also my hack (i described in the first comment) doesn't work, cause i get an
> IllegalAccessError on runtime when i override the friendly method setFocusCell
> :-(
> 

No. New API is only added in new Major-Releases. May I suggest using Reflection!
Comment 5 Michael Seele CLA 2007-08-02 09:36:54 EDT
> May I suggest using Reflection!

sorry, what do you mean with this sentence?
Comment 6 Michael Seele CLA 2007-08-03 04:59:21 EDT
i tried 'everything' to load/invoke the method using reflection. can you give me a tip how i can invoke the setFocusCell(ViewerCell focusCell) method from my class/plugin. i also found this comment:

> The trick you tried (declaring a class in the same
> package) does not work at runtime, because your class is loaded by a
> different classloader (every plug-in has one) and so it is actually in a
> different package (though they share the same name).

so, is it generally possible to access the method from my overriding class?
Comment 7 Boris Bokowski CLA 2007-08-03 09:06:27 EDT
Michael, have you tried calling java.lang.Method.setAccessible(true) ?
Comment 8 Michael Seele CLA 2007-08-03 09:16:26 EDT
that works! :-) 
you made my day! thank's a lot!
Comment 9 Boris Bokowski CLA 2007-08-03 09:46:12 EDT
no problem :)
Comment 10 Thomas Schindl CLA 2008-02-20 14:02:12 EST
Created attachment 90236 [details]
work in progress

... started and a point to work on in future
Comment 11 Thomas Schindl CLA 2008-03-27 03:17:55 EDT
have to delay for 3.5
Comment 12 Thomas Schindl CLA 2009-05-05 12:07:27 EDT
removing 3.5
Comment 13 Thomas Schindl CLA 2010-01-28 17:12:33 EST
multi change because of intenion of stepping back as platform-ui committer
Comment 14 Adrian Stefanescu CLA 2010-02-16 09:44:45 EST
any news on this method:

SWTFocusCellManager.setFocusCell(ViewerCell)

How long until it's going to be public, I mean it's not a new API, it's 3 years old, just make it public and be done with it already.
Comment 15 Eric Moffatt CLA 2010-02-16 13:06:03 EST
Boris, do you think this is a small enough api change to slip it into M6 ?
Comment 16 Thomas Schindl CLA 2010-02-16 13:28:45 EST
I don't think this is simply an API change because you also have to trigger a SelectionChanged-Event. So there's a bit more involved than simply adding the public accessor!
Comment 17 Eric Moffatt CLA 2010-02-16 14:49:39 EST
Tom, thanks for the info!

Adrian, we simply don't have the cycles at this point to address this. If you would like to submit a patch I'd be more than happy to go over it.
Comment 18 Pavan Kumar Immaneni CLA 2011-05-03 23:56:36 EDT
Is there any work around for this problem ?

I am looking for a way to set focus on viewer cell that is part of table/tableviewer. 

I have tried all the following things that are commented out below and none of them work for me.

ViewerCell currentCell = getCurrentViewerCell();
if (currentCell != null) {
// tableViewer.getTable().showColumn(
// 	tableViewer.getTable().getColumn(
// 	currentCell.getColumnIndex()));
// tableViewer.getTable().select(
// 	currentCell.getColumnIndex());
// tableViewer.setSelection(
// 		new StructuredSelection(
// 		currentCell.getElement()));
// TableViewerEditor tableViewerEditor = 
// 		(TableViewerEditor)tableViewer.getColumnViewerEditor();
// TableViewerFocusCellManager focusCellManager = 
// 		tableViewerEditor.getFocusCellManager();
// tableViewerEditor.forceFocusCell(currentCell, focusCellManager);
// table.setFocus();
}
Comment 19 Boris Bokowski CLA 2011-05-05 23:07:44 EDT
Created attachment 194897 [details]
Snippet demonstrating workaround

This is ugly but should work with older versions of JFace. You can try it as a workaround for now.
Comment 20 Pavan Kumar Immaneni CLA 2011-05-06 17:02:39 EDT
Boris,

Thanks for providing the snippet with work around. It works for now.
Comment 21 Pavan Kumar Immaneni CLA 2011-05-13 16:27:08 EDT
Boris,

Using the snippet that you provided with the work around, I need to do something like this: When I type on the keyboard a letter, the TextCellEditor (and its Control : an instance of Text) must be in editing mode and the key pressed which is the source of an event must have its value in the field.

I modified the activation strategy to listen for any character entered as follows:

		ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
			protected boolean isEditorActivationEvent(
					ColumnViewerEditorActivationEvent event) {
							return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
							|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
							|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.F2)
							|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
					        || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.KEYPAD_CR)
							|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && Character.isSpaceChar(event.character))
						    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode > 31 && event.keyCode < 127) 
							|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;				
			}
		};

Now with the above change, Lets say I am on the cell which has a character "A" and as soon as I enter any key (e.g. "Z") the cell changes into Edit mode but the text in the cell still appears to be "A" as opposed to "Z" which I expected. 

Am I missing something. How can this be accomplished ?
Comment 22 Arnaud CLA 2013-02-20 12:06:09 EST
Hi, still this bug status is NEW ? (since 2007 oh, that's prehistoric! ).

I've tested proposed workaround in eclipse 4.2.2, workaround didn't fix the problem: right cell is drawn focused but focus rectangle is stick at old row, then key up/down is applied to focus rectangle not to focused cell.

I raise this defect again as I can see it in eclipse 4.2.2 on a CheckboxTreeViewer.

Thanks.
Comment 23 Paul Webster CLA 2013-02-23 14:32:21 EST
No one is looking at this area at the moment, but I can have a look at a solid patch.  See http://wiki.eclipse.org/Platform_UI/How_to_Contribute

PW
Comment 24 Arnaud CLA 2013-02-25 03:03:12 EST
Thanks for reply.
No need, to work on this. As I found simple workaround that fit my needs: change backgorund of cell.
Comment 25 bisoyi J CLA 2016-09-28 03:08:11 EDT
@Arnaud : Could you please elaborate on what you mean by "change backgorund of cell." ??
May be a pseudo-code will suffice.