Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Fixed column(s) in tableviewer
Fixed column(s) in tableviewer [message #304503] Thu, 08 June 2006 13:57 Go to next message
Eclipse UserFriend
Originally posted by: fhellerhoff.yahoo.de

Is there a way to fix one or more columns in a tableviewer so that they
will remain on the left side while the user scrolls to the right?

thx, Friedhelm
Re: Fixed column(s) in tableviewer [message #304504 is a reply to message #304503] Thu, 08 June 2006 14:32 Go to previous messageGo to next message
Roland Tepp is currently offline Roland TeppFriend
Messages: 336
Registered: July 2009
Senior Member
Last I looked, it was not possible...

Friedhelm Hellerhoff kirjutas mulle midagi seesugust:
> Is there a way to fix one or more columns in a tableviewer so that they
> will remain on the left side while the user scrolls to the right?
>
> thx, Friedhelm

--
Roland Tepp
Re: Fixed column(s) in tableviewer [message #304506 is a reply to message #304503] Thu, 08 June 2006 14:49 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
No. But what about 2 Tables:

1st Table with 2 Columns
2nd Table with n Columns

You only have to synchronize if the second table is scrolled up/downwards.

tableViewer1.getTable().setTopIndex(tableViewer2.getTable(). getTopIndex());

Tom


Friedhelm Hellerhoff schrieb:
> Is there a way to fix one or more columns in a tableviewer so that they
> will remain on the left side while the user scrolls to the right?
>
> thx, Friedhelm
Re: Fixed column(s) in tableviewer [message #304511 is a reply to message #304506] Thu, 08 June 2006 15:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fhellerhoff.yahoo.de

Thanks! This is a great idea!
I have synchronized the 2 viewers.
Wondering if it is possible to hide the vertical scrollbar of the left
viewer and to make it look as if it is just one table...
Re: Fixed column(s) in tableviewer [message #304514 is a reply to message #304511] Thu, 08 June 2006 15:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fhellerhoff.yahoo.de

just found that:

table1.getVerticalBar().setVisible(false);

But unfortunately, it does not hide the scrollbar
Re: Fixed column(s) in tableviewer [message #304523 is a reply to message #304514] Thu, 08 June 2006 22:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
Hi,

did you by chance saw this:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet234 .java

Tom

Friedhelm wrote:
> just found that:
> table1.getVerticalBar().setVisible(false);
>
> But unfortunately, it does not hide the scrollbar
>
Re: Fixed column(s) in tableviewer [message #304526 is a reply to message #304523] Thu, 08 June 2006 23:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
Tom Schindl wrote:
> Hi,
>
> did you by chance saw this:
> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet234 .java
>
> Tom
>
> Friedhelm wrote:
>
>>just found that:
>>table1.getVerticalBar().setVisible(false);
>>
>>But unfortunately, it does not hide the scrollbar
>>

This is a very sample implementation for a FixedColumnViewer. I'll keep
it in my samples area and try to make it behave better if I have time.

---------------------8<---------------------

package at.bestsolution.viewers;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;

public class FixedTableViewer extends Composite {
private TableViewer v1;

private TableViewer v2;

public FixedTableViewer(Composite parent, int style) {
super(parent, SWT.NONE);
setLayout(new FormLayout());

v2 = new TableViewer(this,style);
v2.getTable().setHeaderVisible(true);
v2.getTable().getVerticalBar().addListener(SWT.Selection, new Listener() {

public void handleEvent(Event event) {
v1.getTable().setTopIndex(v2.getTable().getTopIndex());
}
});

v1 = new TableViewer(this,style);
v1.getTable().setHeaderVisible(true);
v1.getTable().getHorizontalBar().setEnabled(false);

v1.addSelectionChangedListener(new ISelectionChangedListener() {

public void selectionChanged(SelectionChangedEvent event) {
v2.getTable().setSelection(v1.getTable().getSelectionIndices ());
}
});

v2.addSelectionChangedListener(new ISelectionChangedListener() {

public void selectionChanged(SelectionChangedEvent event) {
v1.getTable().setSelection(v2.getTable().getSelectionIndices ());
}

});

Listener eraseListener = new Listener() {
public void handleEvent(Event event) {
if((event.detail & SWT.SELECTED) != 0) {
GC gc = event.gc;
Rectangle rect = event.getBounds();

gc.setForeground(v1.getTable().getShell().getDisplay().getSy stemColor(SWT.COLOR_LIST_SELECTION_TEXT));

gc.setBackground(v1.getTable().getShell().getDisplay().getSy stemColor(SWT.COLOR_LIST_SELECTION));
gc.fillRectangle(rect);
event.detail &= ~SWT.SELECTED;
}
}
};

v1.getTable().addListener(SWT.EraseItem, eraseListener);
v2.getTable().addListener(SWT.EraseItem, eraseListener);
}

public TableColumn createFixedColumn(int width, int style) {
TableColumn column = new TableColumn(v1.getTable(),style);
column.setWidth(width);
return column;
}

public TableColumn createColumn(int style) {
return new TableColumn(v2.getTable(),style);
}

public void setContentProvider(IStructuredContentProvider provider) {
v1.setContentProvider(provider);
v2.setContentProvider(provider);
}

public void setInput(Object input) {
v1.setInput(input);
v2.setInput(input);
init();
}

public void init() {
TableColumn[] columns = v1.getTable().getColumns();
int width = 0;
for( int i = 0; i < columns.length; i++ ) {
width += columns[i].getWidth();
}

int sWidth = v1.getTable().getVerticalBar().getSize().x;

FormData data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0);
data.right = new FormAttachment(0,width+sWidth);
data.bottom = new FormAttachment(100);
v1.getTable().setLayoutData(data);

data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(v1.getTable(),-sWidth-2);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(100);
v2.getTable().setLayoutData(data);
}
}
---------------------8<---------------------

Did you by change took a look at KTable or the Nebula Grid Control maybe
they provide what you want?

Tom
Re: Fixed column(s) in tableviewer [message #304534 is a reply to message #304526] Fri, 09 June 2006 08:07 Go to previous message
Eclipse UserFriend
Originally posted by: fhellerhoff.yahoo.de

> Tom Schindl wrote:
>> Hi,
>>
>> did you by chance saw this:
>>
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet234 .java
>>
I have recently run it and it is the same what I had quickly build on my
own.

> This is a very sample implementation for a FixedColumnViewer. I'll keep
> it in my samples area and try to make it behave better if I have time.
That looks interesting!

> Did you by change took a look at KTable or the Nebula Grid Control maybe
> they provide what you want?

I have ssen KTable before, but now it seems to have a lot of new features.
This makes it worth to check out if I could use it

Thanks, Friedhelm

> Tom
Previous Topic:include source into PDE headless build
Next Topic:Plugin dependency cycle and optional dependencies
Goto Forum:
  


Current Time: Sun Nov 23 00:07:29 GMT 2014

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

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