Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Table Viewer Editing and Selection questions
Table Viewer Editing and Selection questions [message #525351] Tue, 06 April 2010 10:18 Go to next message
Catalin Gerea is currently offline Catalin Gerea
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

1. I have a table viewer with 1 column. The table lists only strings. Above the table are some buttons to control the contents of the table: 'add string', 'copy string', 'rename string' and 'delete string'.

a) When the 'add string' button is pressed a new entry should be added to the table with a predefined string (e.g.: PredefinedString) and the string should be editable with a distinct border around it.
How can I achieve this? I know that I should set the editing support for the table column but I do not know how to make the editing active only when the button is pressed and how to display the border around the text.

b) When the 'rename string' button is pressed the selected entry from the table becomes editable with a border around it.
It as almost the same as the above with the difference that the editing is done on a existing entry.

2. I have a table with three columns: the first column is a check box, the second displays a image and the third displays a string.
By default the check box is not 'checked' and no image is displayed in the second column. When the check box becomes 'checked' then the second column displays a image. When the user clicks on the image from the second column the image is changed to another one. (the second column displays only to images: ascending order and descending order ... i know that a workaround here is to use a check box but i do not want to do this).
Further more when the row is selected in the table (regardless of the 'checked' state of the check box) the selection is visible in the first and the third column.

a) How can I make the second column to become 'active' when the check box becomes 'checked'?
b) How can I make the second column change the displayed images?
c) How can I achieve the selection effect only for the first and the third column?

Sorry if I probably ask dumb and obviously questions but probably I am missing some basic things about the Jface viewers. I will provide more information if needed.

I will appreciate any help about this.


Time is what you make of it.
Re: Table Viewer Editing and Selection questions [message #525355 is a reply to message #525351] Tue, 06 April 2010 05:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5332
Registered: July 2009
Senior Member
Am 06.04.10 12:18, schrieb Catalin Gerea:
> 1. I have a table viewer with 1 column. The table lists only strings.
> Above the table are some buttons to control the contents of the table:
> 'add string', 'copy string', 'rename string' and 'delete string'.
>
> a) When the 'add string' button is pressed a new entry should be added
> to the table with a predefined string (e.g.: PredefinedString) and the
> string should be editable with a distinct border around it.
> How can I achieve this? I know that I should set the editing support for
> the table column but I do not know how to make the editing active only
> when the button is pressed and how to display the border around the text.
>

viewer.editElement(object,0) ?

> b) When the 'rename string' button is pressed the selected entry from
> the table becomes editable with a border around it.
> It as almost the same as the above with the difference that the editing
> is done on a existing entry.
>

viewer.editElement(((IStructuredSelection)viewer.getSelectio n()).getFirstElement(),0);

> 2. I have a table with three columns: the first column is a check box,
> the second displays a image and the third displays a string.
> By default the check box is not 'checked' and no image is displayed in
> the second column. When the check box becomes 'checked' then the second
> column displays a image. When the user clicks on the image from the
> second column the image is changed to another one. (the second column
> displays only to images: ascending order and descending order ... i know
> that a workaround here is to use a check box but i do not want to do this).
> Further more when the row is selected in the table (regardless of the
> 'checked' state of the check box) the selection is visible in the first
> and the third column.
>
> a) How can I make the second column to become 'active' when the check
> box becomes 'checked'?

What does active mean? You mean responding to clicks?

> b) How can I make the second column change the displayed images?

Update your model and call viewer.update(object);

> c) How can I achieve the selection effect only for the first and the
> third column?

make your LabelProvider check the current selection (and restore it) and
call viewer.update() twice (for the old selection and new selection) or
if your table is not really big viewer.refresh() when ever the selection
changes

>
> Sorry if I probably ask dumb and obviously questions but probably I am
> missing some basic things about the Jface viewers. I will provide more
> information if needed.
>
> I will appreciate any help about this.
Re: Table Viewer Editing and Selection questions [message #526273 is a reply to message #525355] Fri, 09 April 2010 12:36 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin Gerea
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

Hello Tom
Thank you for your hints.

1. a) With a little help from Lars Vogel's article http://www.vogella.de/articles/EclipseJFaceTable/article.htm l I successfully managed to edit the edit newly added entry in my table viewer.
And indeed viewer.editElement(object,0) was the missing line from my code.

Now I have two additional problems:
First: All my table entries are editable when I click in the table. I need to make them editable only when I click on the 'rename string' button or when the user clicks again in the selected table entry. Any clues how to achieve this?
Second: The border effect I needed around the edited text is not present. Instead I have the cell selection effect. Any clues were to achieve this?
The effect is the red border from http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet244.java?view=co (there are two words with red border around them). But again this border effect should be present only when the table entry is edited.

For the first half one I think that the code bellow solves the problem:
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(
        tableViewer, new FocusCellOwnerDrawHighlighter(tableViewer));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
        tableViewer) {
      protected boolean isEditorActivationEvent(
          ColumnViewerEditorActivationEvent event) {
        return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
      }
    };

    TableViewerEditor.create(tableViewer, focusCellManager, actSupport,
        ColumnViewerEditor.DEFAULT);

Is the above code correct? If yes what needs to be added in order to edit the table entry when the user clicks again on the current selected entry?
But for the border effect I think I have to create a new class that extends FocusCellHighlighter but I have no clue how get the border effect in it only when the table entry is edited.


2. a) Yes. Active means respond to clicks. Only when the check box from the first column becomes 'checked' then the cell from the second column should respond to clicks. Do I need to add a listener on the cell from the second column? If yes, what type of listener?

I hope that you understood now what I am trying to achieve. If not let me know and I will try to make it more clear.


Time is what you make of it.
Re: Table Viewer Editing and Selection questions [message #526315 is a reply to message #526273] Fri, 09 April 2010 15:39 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5332
Registered: July 2009
Senior Member
Am 09.04.10 14:36, schrieb Catalin Gerea:
> Hello Tom
> Thank you for your hints.
>
> 1. a) With a little help from Lars Vogel's article
> http://www.vogella.de/articles/EclipseJFaceTable/article.htm l I
> successfully managed to edit the edit newly added entry in my table viewer.
> And indeed viewer.editElement(object,0) was the missing line from my code.
>
> Now I have two additional problems:
> First: All my table entries are editable when I click in the table. I
> need to make them editable only when I click on the 'rename string'
> button or when the user clicks again in the selected table entry. Any
> clues how to achieve this?
> Second: The border effect I needed around the edited text is not
> present. Instead I have the cell selection effect. Any clues were to
> achieve this?
> The effect is the red border from
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet244.java?view=co
> (there are two words with red border around them). But again this border
> effect should be present only when the table entry is edited.
>
> For the first half one I think that the code bellow solves the problem:
>
> TableViewerFocusCellManager focusCellManager = new
> TableViewerFocusCellManager(
> tableViewer, new FocusCellOwnerDrawHighlighter(tableViewer));
> ColumnViewerEditorActivationStrategy actSupport = new
> ColumnViewerEditorActivationStrategy(
> tableViewer) {
> protected boolean isEditorActivationEvent(
> ColumnViewerEditorActivationEvent event) {
> return event.eventType ==
> ColumnViewerEditorActivationEvent.PROGRAMMATIC;
> }
> };
>
> TableViewerEditor.create(tableViewer, focusCellManager, actSupport,
> ColumnViewerEditor.DEFAULT);
>
> Is the above code correct? If yes what needs to be added in order to
> edit the table entry when the user clicks again on the current selected
> entry? But for the border effect I think I have to create a new class
> that extends FocusCellHighlighter but I have no clue how get the border
> effect in it only when the table entry is edited.

Yes. For the red border you need to create your own CellEditor which
uses a StyledText-Control instead of a simple Text-Widget. I guess
simply copying the TextCellEditor and exchange Text through StyledText
should be enough.

>
>
> 2. a) Yes. Active means respond to clicks. Only when the check box from
> the first column becomes 'checked' then the cell from the second column
> should respond to clicks. Do I need to add a listener on the cell from
> the second column? If yes, what type of listener?

You should overload EditingSupport#canEdit() and respond with false in
case the checkbox is not on.

>
> I hope that you understood now what I am trying to achieve. If not let
> me know and I will try to make it more clear.
Re: Table Viewer Editing and Selection questions [message #713249 is a reply to message #526273] Mon, 08 August 2011 09:09 Go to previous message
malek.mahersi is currently offline malek.mahersi
Messages: 2
Registered: August 2011
Junior Member
Good Question:
First: All my table entries are editable when I click in the table. I need to make them editable only when I click on the 'rename string' button or when the user clicks again in the selected table entry. Any clues how to achieve this?
Second: The border effect I needed around the edited text is not present. Instead I have the cell selection effect. Any clues were to achieve this?

Did you manage to solve it?
Please Let me know if you did because I have the same problem

Thanks a lot
Previous Topic:What is .option file for?
Next Topic:One (network) workspace - many logins/users - SVN
Goto Forum:
  


Current Time: Wed Sep 24 04:31:19 GMT 2014

Powered by FUDForum. Page generated in 0.16161 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software