Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Get LabelProvider from active View
Get LabelProvider from active View [message #498248] Mon, 16 November 2009 08:30 Go to next message
TW  is currently offline TW Friend
Messages: 62
Registered: November 2009
Member
Hi,

at the moment I´m having problems with my rcp application. I´m working on a copy handler for my application which should be able to copy informations from tree´s tables or other standard elements. The copied information should be well formatted to work with it in excel ... .

I began to write this copy handler and now it does work but doesn´t have the full functionality.

I get the active Control which is selected and check the type of it:

// get the focused object
    final Display display = Display.getCurrent();
    if( display == null )
    {
      return null;
    }
    final Control focusControl = display.getFocusControl();
    // initialize the stringBuilder
    sb = new StringBuilder();

    if( focusControl instanceof Table )
    {


After that i call some methods to format the table content.

My problem is, that there are some images in the tables which cannot be copied. The images represent booleans and have an active and inactive state. So i want to copy an "X" to the cell if the image is active or nothing if the image is inactive.

At the moment i hard coded the tables but this is no good solution because when i change the structure of the table (change the columns) my copy handler would not work anymore.

A better solution would be to get the label provider of the active table in the active view and collect the informations from the label provider.

But I don´t know how to get the active view or how to get the labelprovider from the selected table, tree ...

Could you help me.
Re: Get LabelProvider from active View [message #498360 is a reply to message #498248] Mon, 16 November 2009 15:12 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
TW wrote:
> Hi,
>
> at the moment I´m having problems with my rcp application. I´m working
> on a copy handler for my application which should be able to copy
> informations from tree´s tables or other standard elements. The copied
> information should be well formatted to work with it in excel ... .
>
> I began to write this copy handler and now it does work but doesn´t have
> the full functionality.
>
> I get the active Control which is selected and check the type of it:
>
> // get the focused object
> final Display display = Display.getCurrent();
> if( display == null )
> {
> return null;
> }
> final Control focusControl = display.getFocusControl();
> // initialize the stringBuilder
> sb = new StringBuilder();
>
> if( focusControl instanceof Table )
> {
>
>
> After that i call some methods to format the table content.
>
> My problem is, that there are some images in the tables which cannot be
> copied. The images represent booleans and have an active and inactive
> state. So i want to copy an "X" to the cell if the image is active or
> nothing if the image is inactive.
>
> At the moment i hard coded the tables but this is no good solution
> because when i change the structure of the table (change the columns) my
> copy handler would not work anymore.
>
> A better solution would be to get the label provider of the active table
> in the active view and collect the informations from the label provider.

I would rethink about that. What would you copy given a label provider,
which might not even return any text at all, but instead might return
check box images? Of-course you didn't explain well, what you consider
as a "copy" here, but assuming you mean something like a
copy-to-clipboard functionality as text, any images wouldn't help you
much.

> But I don´t know how to get the active view or how to get the
> labelprovider from the selected table, tree ...
> Could you help me.

There is no direct link between a view and a viewer. A lot of views
don't have any viewer at all, so it is impossible to get the viewer
directly from the IViewPart interface.

You could cast to the corresponding view (or to some reasonably defined
interface that could be named IViewerProvider and which your view should
implement).

A somewhat cleaner approach would be that your view part *adapts* to the
IViewerProvider interface. To realize this, override the getAdapter
function of the view part.

In any case: I would separate the viewer from the export/copy
functionality. It seems cleaner to me, that your view would
adapt/implement something like ICopySource which allows to access
the copy functionality without direct dependency to the viewer.
The implementation of the functionality could use the viewer API,
but that is not necessary.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Get LabelProvider from active View [message #498475 is a reply to message #498360] Tue, 17 November 2009 08:14 Go to previous messageGo to next message
TW  is currently offline TW Friend
Messages: 62
Registered: November 2009
Member
Hi,

I think I should have explained my problem better.

So lets give it a second try.

I have several tables and trees in my eclipse rcp. They are filled with text but some columns have images only. So its a mixture of text columns and image columns.

I want to implement a copy feature which adds the functionality of copying the selected rows to the clipboard, because i want to paste them to excel and every cell of my table in my eclipse rcp should be pasted in a cell of excel.

Another important thing is, that table in excel should consist of text only and has no images.

Because of the fact that the images in my eclipse table are things like a plus for "new", a minus for "delete", a stylus or "edit" ... I had the idea to replace the images with text (plus image should be replaced by "new" ...

In my opinion there are two solutions for doing that:

It is important to know, that I´ve already implemented a copyhandler which is able to copy all text elements of the table and ignores images at the moment.

Solution 1:
I could implement the replacement an image to text directly in the copyhandler. Therefore I check the type of objects which are in the table. Lets say i have a table with "Person" objects and the column "married" has a checked image or an image which is not checked.

What I would do is:

if (selectedItem instanceof Person){
if( column.getText().equals( "Married" ) )
    {
      final boolean married = ((Person)selectedItem.getData()).isMarried;
      if( married ) )
      {
        sb.append ("X");
      }
}
(


Everything is coded hard into the copyhandler and if someone changes the column header, it has to be changed in the copyhandler, too.

Soution 2:

Solution two would be to get the labelprovider and check if the person is married or not. This would be more flexible because if the table header changes, the copyhandler would not be affected.

I think i have to check my code and think about your propose.

Thanks and greetings from Stuttgart

TW
Re: Get LabelProvider from active View [message #498690 is a reply to message #498475] Wed, 18 November 2009 07:37 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
TW wrote:
> Hi,
>
> I think I should have explained my problem better.
>
> So lets give it a second try.
>
> I have several tables and trees in my eclipse rcp. They are filled with
> text but some columns have images only. So its a mixture of text columns
> and image columns.
>
> I want to implement a copy feature which adds the functionality of
> copying the selected rows to the clipboard, because i want to paste them
> to excel and every cell of my table in my eclipse rcp should be pasted
> in a cell of excel.

<nod> we have a similar APP. BuT I recommend to use a Java-API to
perform the Copy-To-Excel (like POI) because this eases to realize
special formatting options and discrimination of numbers and non-numbers.

> Another important thing is, that table in excel should consist of text
> only and has no images.

<nod> same thing for our tables.

> Because of the fact that the images in my eclipse table are things like
> a plus for "new", a minus for "delete", a stylus or "edit" ... I had the
> idea to replace the images with text (plus image should be replaced by
> "new" ...
> In my opinion there are two solutions for doing that:
>
> It is important to know, that I´ve already implemented a copyhandler
> which is able to copy all text elements of the table and ignores images
> at the moment.

This is IMO the root of the problem. I suggest to start with an approach
that is uncoupled to jface viewers (this also eases to support export
for Swing-based tables in the same manner), e.g. a set of interfaces
like IColLabelProvider and IColTextLabelProvider, like so

public interface ITextLabelProvider {

String getText(Object obj);

}

public interface IColTextLabelProvider {

ITextLabelProvider[] getColTextLabelProviders();

}

Now provide a *single* implementation for a text-export based on above
interfaces for SWT-Tables (using the text of the table items), but
support that users provide custom IColTextLabelProvider for special
columns that won't have the right text representation in the item
available). The whole machinery works in a way that the export/copy
functionality refers to the item-text where no IColTextLabelProvider
is available [I haven't mentioned one additional layer of complexity:
This may occur, if your column headers don't have a text-based
title, but only an image. You can support this by adding a further

public interface IColLabelProvider {

String[] getColumnLabels();

}

interface].

> Solution 1:
> I could implement the replacement an image to text directly in the
> copyhandler. Therefore I check the type of objects which are in the
> table. Lets say i have a table with "Person" objects and the column
> "married" has a checked image or an image which is not checked.
> What I would do is:
>
> if (selectedItem instanceof Person){
> if( column.getText().equals( "Married" ) )
> {
> final boolean married = ((Person)selectedItem.getData()).isMarried;
> if( married ) )
> {
> sb.append ("X");
> }
> }
> (
>
> Everything is coded hard into the copyhandler and if someone changes the
> column header, it has to be changed in the copyhandler, too.

Stay away from this, this is a big source for unnecessary coupling of
models and types in one location.

> Soution 2:
>
> Solution two would be to get the labelprovider and check if the person
> is married or not. This would be more flexible because if the table
> header changes, the copyhandler would not be affected.

I would stay away from the LabelProvider as well, because it is for the
same reason wrong as directly querying the text from the table item. Use
one indirection more and provide your own set of interfaces to
support export/copy functionality.

It is quite easy to ensure that your copy machinery get the required
interfaces from your viewer or views by requiring that either of these
implement or adapt to IColTextLabelProvider/IColLabelProvider.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:eclipse.exitdata in 3.5
Next Topic:rcp application and editor ...
Goto Forum:
  


Current Time: Fri Mar 29 22:23:07 GMT 2024

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

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

Back to the top