Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TableColumnLayout problem on mac os
TableColumnLayout problem on mac os [message #1052581] Tue, 30 April 2013 05:05
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Hello,

I'm using Eclipse Indigo SR2.

I wanted to have a table viewer with two columns: a column with a fixed size and a column which has the same with as its largest cell (so you don't have to resize the column to fully see its content). If the column is too large and goes outside the range of the TableViewer, then an horizontal scroll bar appears on the table viewer.

I have the following piece of code which works fine on windows but doesn't work on mac: the second column is always a couple of pixels wide and thus you can only see the 2 first characters followed by "..."

(The code is taken from a custom view)
	class ViewContentProvider implements IStructuredContentProvider {
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
		}

		public void dispose() {
		}

		public Object[] getElements(Object parent) {
			if (parent instanceof Object[]) {
				return (Object[]) parent;
			}
			return new Object[0];
		}
	}

	class ViewLabelProvider extends ColumnLabelProvider {

		private int columnIndex;

		public ViewLabelProvider(int colIndex) {
			columnIndex = colIndex;
		}

		@Override
		public String getText(Object element) {
			if (columnIndex == 0) {
				return "";
			}
			return super.getText(element);
		}
	}

	public void createPartControl(Composite parent) {
		TableColumnLayout tableLayout = new TableColumnLayout();
		parent.setLayout(tableLayout);

		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL);
		viewer.setContentProvider(new ViewContentProvider());
		viewer.setLabelProvider(new ViewLabelProvider(0));
		// Provide the input to the ContentProvider
		viewer.setInput(new String[] { "One", "Two",
				"A loooooooooooooooooooooooooooooooooooooooooooooooooooooong string" });

		createColumns(viewer, tableLayout);
		refreshViewer();
	}


	private void createColumns(TableViewer viewer, TableColumnLayout tableLayout) {
		TableViewerColumn firstColumn = new TableViewerColumn(viewer, SWT.FILL);
		firstColumn.getColumn().setResizable(false);
		ViewLabelProvider labelProvider = new ViewLabelProvider(0);
		firstColumn.setLabelProvider(labelProvider);

		TableViewerColumn secondColumn = new TableViewerColumn(viewer, SWT.FILL);
		secondColumn.getColumn().setResizable(false);
		labelProvider = new ViewLabelProvider(1);
		secondColumn.setLabelProvider(labelProvider);

		tableLayout.setColumnData(firstColumn.getColumn(),
				new ColumnWeightData(0, 22));
		tableLayout.setColumnData(secondColumn.getColumn(),
				new ColumnWeightData(100, 100));
		viewer.getTable().setLinesVisible(false);
		viewer.getTable().setHeaderVisible(false);
	}

	protected void refreshViewer() {
		viewer.refresh();
		Table table = viewer.getTable();
		for (TableColumn column : table.getColumns()) {
			column.pack();
		}
	}


To make it easier to test, I attached a sample project which creates a sample view a TableViewer showing the problem.

Thanks,
C├ędric
Previous Topic:Modifying ProjectionDrawingStrategy
Next Topic:Position-preserving undo/redo
Goto Forum:
  


Current Time: Wed Jul 23 03:56:50 EDT 2014

Powered by FUDForum. Page generated in 0.03200 seconds