|
|
|
Re: Row index concept [message #774656 is a reply to message #774610] |
Wed, 04 January 2012 10:51 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
I still don't get that if there's no row-object how did you manage to go
there with TAB/Arrow-Keys, if there's no row-object there's no TableItem
so you can't navigate to it.
I'm a little bit lost because I'm not sure what you are doing because
you are once talking about cells, then rows, ... .
I think it is best you create a small self-contained snippet which we
can run locally and describe exactly what one has to expect in which
situation. A good starting point of such a snippet is the collection in
http://wiki.eclipse.org/JFaceSnippets.
As outline before you can calculate the row-index from the event.x/y and:
a) Using the TableItem#getBounds(), TableItem#getBounds(int)
b) Using the RowHeight provided by the Table-Control itself and
TableColumn#getWidth().
Tom
Am 04.01.12 10:28, schrieb jlmueller5:
>
> Hi Tom,
>
> Many thanks for your reply.
>
> I will explain my problem once again.
>
> I am working to add a few functionalities in oneTable, in this Table, I
> have added cell editors(TextCellEditor) .
> When the rows of the table contains object and if I click on any cell of
> that rows then the Editors are working fine.
> But now My need is if I click on any empty cell of the rows, i.e. the
> cell which does not contain any objects, then also the cell Editors
> should be activated. And i should be able to edit it. How should I
> proceed to add this functinality ?"
>
> If I browse the table with TAB and Arrows keys , this is working. I
> implemented this functionality in first phase and now in second phase i
> will have to do with mouse click.
>
> I think if somehow i can find Row Index then this can be done. Whats
> your thought ?
> Please let me know if you have understood my problem ?
>
> Any hint will be highly appreciated.
>
> Best Regards,
> Julia
|
|
|
|
Re: Row index concept [message #774704 is a reply to message #774687] |
Wed, 04 January 2012 12:31 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Ok we are approaching it slowly. You can not activate a celleditor
unless you have created Row-Objects (wha are represented as
TableItem-Instances in the SWT) for it.
Beside that you CellEditor activation has to be done using the viewer
API by calling editElement(Object,int).
Given all those facts the only thing that makes sense is that if say the
table contains 5 rows and the user clicks in the 6th that you create a
row object, call viewer.add() and then viewer.editElement(Object,int).
You code could like this then (totally untested braindump):
viewer.getTable().addMouseListener(new MouseAdapter {
public void mouseDown(MouseEvent e) {
int count = viewer.getTable().getItemCount();
if( count > 0 ) {
TableItem last = viewer.getTable().getItem(count-1);
Rectangle rect = last.getBounds();
if( rect.y + rect.height < e.y ) {
createRowAndActivate(e);
}
} else {
createRowAndActivate(e);
}
}
void createRowAndActivate(MouseEvent e) {
MyRow m = new MyRow();
viewer.add(m);
viewer.editElement(m,getColumnIndex(e));
}
int getColumnIndex(MouseEvent e) {
for (int i = 0; i < viewer.getTable().getColumnCount(); i++)
{
x += viewer.getTable().getColumn(i).getWidth();
if (e.x <= x) {
rerturn i;
}
}
return 0;
}
}
Tom
Am 04.01.12 13:06, schrieb jlmueller5:
> Hi Tom,
>
> Thanking you once again for your detailed reply. I will check what you
> suggested.
> In between , i would like describe my task once again :
>
> When the rows of the table contains object then only I am able to
> traverse its cells with TAB/Arrow-Keys and also can edit them.
>
> My task is, "if a row does not contain objects then also if I click on
> its cells, then the corresponding cell Editor should be activated."
>
> With this code I am able to get in which column I clicked(i.e 1st column
> or 2nd column etc) but I am not able to get the corresponding Row.
> Or is there any other way to do that?
>
> viewer.getTable().addMouseListener(new MouseAdapter() {
>
> public void mouseDown(MouseEvent e) {
> int x = 0;
> int activeColumn = -1;
> // TableItem item = new TableItem(table, SWT.NONE);
>
> for (int i = 0; i <
> viewer.getTable().getColumnCount(); i++) {
> x +=
> viewer.getTable().getColumn(i).getWidth();
> if (e.x <= x) {
> activeColumn = i;
> break;
> }
> }
> CellEditor[] editor = viewer.getCellEditors();
> switch (activeColumn) {
> case 1:
> case 2:
> case 3:
> case 4:
>
> // item.setText(activeColumn, "column");
> editor[activeColumn].activate();
>
> }
> }
> });
>
> Please let me hear from you.
>
> Regards,
> Julia
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03873 seconds