Fixed column(s) in tableviewer [message #304503] |
Thu, 08 June 2006 13:57 |
Eclipse User |
|
|
|
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 #304511 is a reply to message #304506] |
Thu, 08 June 2006 15:47 |
Eclipse User |
|
|
|
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 #304526 is a reply to message #304523] |
Thu, 08 June 2006 23:27 |
Thomas Schindl Messages: 6651 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03879 seconds