Home » Eclipse Projects » Eclipse Platform » Re: PLEASE HELP: ColumnViewer.editElement() doesn't work with Editor Support in 3.3 API
Re: PLEASE HELP: ColumnViewer.editElement() doesn't work with Editor Support in 3.3 API [message #330892] |
Fri, 15 August 2008 13:55 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Rene Oschatz wrote:
> Hi all.
>
> I am using the new TableViewer editing support in 3.3 using
> TableViewerColumn.setEditingSupport(EditingSupport). I can't figure
> out how to activate a specific cell's editor programmatically. I have
> a toolItem at the top of the table to add a new record. When you press
> this toolItem I add a new blank row in the table and I want to put the
> cursor in the first cell editor of that row ready to enter data. I know
> I have to call tableEditor.editElement(), but the method doesn't works.
First, I'm copying this to the eclipse.platform group because it is not
actually an SWT question (JFace sits on top of SWT).
To answer the question:
You probably don't want to call the insert() method to add a new row.
Look at this part of the Javadoc for AbstractTableViewer.insert():
"* This method should be called (by the content provider) when elements
have been added to the model, in order to cause the viewer to accurately
reflect the model. This method only affects the viewer, not the model."
You should add the item to the model of your table viewer's content
provider. I do this, and the editElement() method works fine.
Hope this helps,
Eric
>
> For better overview, here is my code:
>
>> TableViewerFocusCellManager focusCellManager = new
>> TableViewerFocusCellManager(tableViewer,new
>> FocusCellOwnerDrawHighlighter(tableViewer));
>> ColumnViewerEditorActivationStrategy actSupport = new
>> ColumnViewerEditorActivationStrategy(tableViewer) {
>> protected boolean
>> isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
>> return event.eventType ==
>> ColumnViewerEditorActivationEvent.TRAVERSAL
>> || event.eventType ==
>> ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
>> || (event.eventType ==
>> ColumnViewerEditorActivationEvent.KEY_PRESSED && ( event.keyCode ==
>> SWT.CR || event.keyCode == SWT.F2 || event.character == ' ' ))
>> || event.eventType ==
>> ColumnViewerEditorActivationEvent.PROGRAMMATIC;
>> }};
>> TableViewerEditor.create(tableViewer, focusCellManager, actSupport,
>> ColumnViewerEditor.TABBING_HORIZONTAL
>> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
>> | ColumnViewerEditor.TABBING_VERTICAL |
>> ColumnViewerEditor.KEYBOARD_ACTIVATION);
>
> And then...
>
>> final ToolItem addArtikelTI = new ToolItem(toolBar, SWT.PUSH);
>> addArtikelTI.setText("Add");
>> addArtikelTI.addSelectionListener(new SelectionAdapter() {
>> public void widgetSelected(SelectionEvent e) {
>> NewPriceTableData item = new NewPriceTableData(null, null);
>> input.add(item);
>> tableViewer.insert(item, input.size()-1);
>> tableViewer.editElement(item, 0);
>>
>> }
>>
>> });
>
> Please help me. I have no idea, why this solution sucks.
|
|
|
Re: PLEASE HELP: ColumnViewer.editElement() doesn't work with Editor Support in 3.3 API [message #330895 is a reply to message #330892] |
Fri, 15 August 2008 16:04 |
Eclipse User |
|
|
|
Originally posted by: rene.ec-soft.de
Thanks for the quick hint. But it doesn't helps. I have changed my code
how you said, but the damn celleditor isn't active after the new data is
added to the model.
Maybe it's helpful, to see the whole listing.
Ok, first I define the column with the editing support...
> TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE, 0);
> column.getColumn().setText("barcode");
> column.getColumn().setWidth(80);
> column.setLabelProvider(new ColumnLabelProvider() {
> public String getText(Object element) {
> NewPriceTableData tableData = (NewPriceTableData)element;
> if(tableData.getWare() != null)
> return tableData.getWare().getBarcode();
> else
> return "Please insert the article barcode!";
> }
> });
> column.setEditingSupport(new EditingSupport(tableViewer) {
>
> private TextCellEditor cellEditor = new TextCellEditor(table);
>
> protected boolean canEdit(Object element) {
> return true;
> }
>
> protected CellEditor getCellEditor(Object element) {
> return cellEditor;
> }
>
> protected Object getValue(Object element) {
> if(((NewPriceTableData)element).getWare() != null )
> return ((NewPriceTableData)element).getWare().getBarcode();
> else
> return "";
> }
>
> protected void setValue(Object element, Object value) {
> //determine the article by the input and insert it to the element
> String wnr = (String) value;
> IWare ware = BestandsSystem.getInstance().getWare(wnr);
> if (ware != null) {
> NewPriceTableData tableData = (NewPriceTableData)element;
> tableData.setWare(ware);
> waren.add(ware); //that's not the input of the tableViewer
> List<IWare> list = new ArrayList<IWare>(1);
> list.add(ware);
> Hashtable<IWare, BigDecimal> newPriceList = changePriceProcess.calculateNewPrice(list);
> tableData.setBetrag(newPriceList.get(ware));
> }
> tableViewer.update(element, null);
> }
> });
Here I define the rest...
> final TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(tableViewer,new FocusCellOwnerDrawHighlighter(tableViewer));
> ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tableViewer) {
> protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
> return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
> || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
> || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && ( event.keyCode == SWT.CR || event.keyCode == SWT.F2 || event.character == ' ' ))
> || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
> }
> };
>
> TableViewerEditor.create(tableViewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
> | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
Here is the code, that will be run after pressing the ADD-Button to
insert a new data to the model (and the tableViewer).
> final ToolItem addArtikelTI = new ToolItem(toolBar, SWT.PUSH);
> addArtikelTI.setText("Add");
> addArtikelTI.addSelectionListener(new SelectionAdapter() {
>
> @Override
> public void widgetSelected(SelectionEvent e) {
> NewPriceTableData item = new NewPriceTableData(null, BigDecimal.ZERO);
> tableViewerInput.add(item);
> tableViewer.refresh();
> tableViewer.editElement(item, 0);
> }
> });
If someone has an idea what's going wrong here, please let me know. It's
really very important.
|
|
|
Re: PLEASE HELP: ColumnViewer.editElement() doesn't work with Editor Support in 3.3 API [message #330908 is a reply to message #330895] |
Sat, 16 August 2008 14:10 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
My wild wild guess is that refresh() loads your items from the
datasource and hence the viewer can locate the "item" you are passing to
the editElement-call (why do you call refresh()?).
Tom
Rene Oschatz schrieb:
> Thanks for the quick hint. But it doesn't helps. I have changed my code
> how you said, but the damn celleditor isn't active after the new data is
> added to the model.
>
> Maybe it's helpful, to see the whole listing.
> Ok, first I define the column with the editing support...
>
>> TableViewerColumn column = new TableViewerColumn(tableViewer,
>> SWT.NONE, 0);
>> column.getColumn().setText("barcode");
>> column.getColumn().setWidth(80);
>> column.setLabelProvider(new ColumnLabelProvider() {
>> public String getText(Object element) {
>> NewPriceTableData tableData = (NewPriceTableData)element;
>> if(tableData.getWare() != null)
>> return tableData.getWare().getBarcode();
>> else
>> return "Please insert the article barcode!";
>> }
>> });
>> column.setEditingSupport(new EditingSupport(tableViewer) {
>>
>> private TextCellEditor cellEditor = new TextCellEditor(table);
>>
>> protected boolean canEdit(Object element) {
>> return true;
>> }
>>
>> protected CellEditor getCellEditor(Object element) {
>> return cellEditor;
>> }
>>
>> protected Object getValue(Object element) {
>> if(((NewPriceTableData)element).getWare() != null )
>> return ((NewPriceTableData)element).getWare().getBarcode();
>> else
>> return "";
>> }
>>
>> protected void setValue(Object element, Object value) {
>> //determine the article by the input and insert it to the element
>> String wnr = (String) value;
>> IWare ware = BestandsSystem.getInstance().getWare(wnr);
>> if (ware != null) {
>> NewPriceTableData tableData =
>> (NewPriceTableData)element;
>> tableData.setWare(ware);
>> waren.add(ware); //that's not the input of the
>> tableViewer
>> List<IWare> list = new ArrayList<IWare>(1);
>> list.add(ware);
>> Hashtable<IWare, BigDecimal> newPriceList =
>> changePriceProcess.calculateNewPrice(list);
>> tableData.setBetrag(newPriceList.get(ware));
>> }
>> tableViewer.update(element, null);
>> }
>> });
>
> Here I define the rest...
>
>> final TableViewerFocusCellManager focusCellManager = new
>> TableViewerFocusCellManager(tableViewer,new
>> FocusCellOwnerDrawHighlighter(tableViewer));
>> ColumnViewerEditorActivationStrategy actSupport = new
>> ColumnViewerEditorActivationStrategy(tableViewer) {
>> protected boolean
>> isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
>> return event.eventType ==
>> ColumnViewerEditorActivationEvent.TRAVERSAL
>> || event.eventType ==
>> ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
>> || (event.eventType ==
>> ColumnViewerEditorActivationEvent.KEY_PRESSED && ( event.keyCode ==
>> SWT.CR || event.keyCode == SWT.F2 || event.character == ' ' ))
>> || event.eventType ==
>> ColumnViewerEditorActivationEvent.PROGRAMMATIC;
> > }
> > };
> >
>> TableViewerEditor.create(tableViewer, focusCellManager, actSupport,
>> ColumnViewerEditor.TABBING_HORIZONTAL
>> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
>> | ColumnViewerEditor.TABBING_VERTICAL |
>> ColumnViewerEditor.KEYBOARD_ACTIVATION);
>
>
> Here is the code, that will be run after pressing the ADD-Button to
> insert a new data to the model (and the tableViewer).
>
>> final ToolItem addArtikelTI = new ToolItem(toolBar, SWT.PUSH);
>> addArtikelTI.setText("Add");
>> addArtikelTI.addSelectionListener(new SelectionAdapter() {
>>
>> @Override
>> public void widgetSelected(SelectionEvent e) {
>> NewPriceTableData item = new NewPriceTableData(null,
>> BigDecimal.ZERO);
>> tableViewerInput.add(item);
>> tableViewer.refresh();
>> tableViewer.editElement(item, 0);
>> }
>> });
>
> If someone has an idea what's going wrong here, please let me know. It's
> really very important.
>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Re: PLEASE HELP: ColumnViewer.editElement() doesn't work with Editor Support in 3.3 API [message #330913 is a reply to message #330908] |
Sat, 16 August 2008 14:33 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
I'm 99 % sure that it is something specific to your setup. I'd say you
should:
a) Step through the code with a debugger and see where you fail
b) Modify one of our snippets so that it reproduces the problem (or
package your code as a snippet and attach it to this thread)
Tom
Tom Schindl schrieb:
> My wild wild guess is that refresh() loads your items from the
> datasource and hence the viewer can locate the "item" you are passing to
> the editElement-call (why do you call refresh()?).
>
> Tom
>
> Rene Oschatz schrieb:
>> Thanks for the quick hint. But it doesn't helps. I have changed my
>> code how you said, but the damn celleditor isn't active after the new
>> data is added to the model.
>>
>> Maybe it's helpful, to see the whole listing.
>> Ok, first I define the column with the editing support...
>>
>>> TableViewerColumn column = new TableViewerColumn(tableViewer,
>>> SWT.NONE, 0);
>>> column.getColumn().setText("barcode");
>>> column.getColumn().setWidth(80);
>>> column.setLabelProvider(new ColumnLabelProvider() {
>>> public String getText(Object element) {
>>> NewPriceTableData tableData = (NewPriceTableData)element;
>>> if(tableData.getWare() != null)
>>> return tableData.getWare().getBarcode();
>>> else
>>> return "Please insert the article barcode!";
>>> }
>>> });
>>> column.setEditingSupport(new EditingSupport(tableViewer) {
>>> private TextCellEditor cellEditor = new
>>> TextCellEditor(table);
>>>
>>> protected boolean canEdit(Object element) {
>>> return true;
>>> }
>>>
>>> protected CellEditor getCellEditor(Object element) {
>>> return cellEditor;
>>> }
>>>
>>> protected Object getValue(Object element) {
>>> if(((NewPriceTableData)element).getWare() != null )
>>> return ((NewPriceTableData)element).getWare().getBarcode();
>>> else
>>> return "";
>>> }
>>>
>>> protected void setValue(Object element, Object value) {
>>> //determine the article by the input and insert it to the
>>> element
>>> String wnr = (String) value;
>>> IWare ware = BestandsSystem.getInstance().getWare(wnr);
>>> if (ware != null) {
>>> NewPriceTableData tableData =
>>> (NewPriceTableData)element;
>>> tableData.setWare(ware);
>>> waren.add(ware); //that's not the input of the
>>> tableViewer
>>> List<IWare> list = new ArrayList<IWare>(1);
>>> list.add(ware);
>>> Hashtable<IWare, BigDecimal> newPriceList =
>>> changePriceProcess.calculateNewPrice(list);
>>> tableData.setBetrag(newPriceList.get(ware));
>>> }
>>> tableViewer.update(element, null);
>>> }
>>> });
>>
>> Here I define the rest...
>>
>>> final TableViewerFocusCellManager focusCellManager = new
>>> TableViewerFocusCellManager(tableViewer,new
>>> FocusCellOwnerDrawHighlighter(tableViewer));
>>> ColumnViewerEditorActivationStrategy actSupport = new
>>> ColumnViewerEditorActivationStrategy(tableViewer) {
>>> protected boolean
>>> isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
>>> return event.eventType ==
>>> ColumnViewerEditorActivationEvent.TRAVERSAL
>>> || event.eventType ==
>>> ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
>>> || (event.eventType ==
>>> ColumnViewerEditorActivationEvent.KEY_PRESSED && ( event.keyCode ==
>>> SWT.CR || event.keyCode == SWT.F2 || event.character == ' ' ))
>>> || event.eventType ==
>>> ColumnViewerEditorActivationEvent.PROGRAMMATIC;
>> > }
>> > };
>> >
>>> TableViewerEditor.create(tableViewer, focusCellManager, actSupport,
>>> ColumnViewerEditor.TABBING_HORIZONTAL
>>> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
>>> | ColumnViewerEditor.TABBING_VERTICAL |
>>> ColumnViewerEditor.KEYBOARD_ACTIVATION);
>>
>>
>> Here is the code, that will be run after pressing the ADD-Button to
>> insert a new data to the model (and the tableViewer).
>>
>>> final ToolItem addArtikelTI = new ToolItem(toolBar, SWT.PUSH);
>>> addArtikelTI.setText("Add");
>>> addArtikelTI.addSelectionListener(new SelectionAdapter() {
>>>
>>> @Override
>>> public void widgetSelected(SelectionEvent e) {
>>> NewPriceTableData item = new NewPriceTableData(null,
>>> BigDecimal.ZERO);
>>> tableViewerInput.add(item);
>>> tableViewer.refresh();
>>> tableViewer.editElement(item, 0);
>>> }
>>> });
>>
>> If someone has an idea what's going wrong here, please let me know.
>> It's really very important.
>>
>
>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Goto Forum:
Current Time: Sat Nov 09 05:10:44 GMT 2024
Powered by FUDForum. Page generated in 0.03345 seconds
|