[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Custom Widget Data Grid with Header and footer

Hello Folks,

I am working on a custom widget which will consist of a table (grid), titlebar (header) and a pagination control (footer). The way I thought to implement it is extend a composite and then add multiple (3) composites to it for these 3 sections.

I am very new to SWT/JFace and have run into an issue: The 3 sections get displayed fine but the contents of those composites (lable in titlebar and table in middle composite) do not show up when I run. I am pasting the code snippet below. Please let me know what am I doing wrong ?

Also, the reason why I am creating this custom widget is because we have to reuse this datagrid widget many times in our plugin (with different models) and we are trying to design a reusable component. Please advice if this is the right approach or am I missing something.

Thanks,
Arpit

public class CdetsDataGrid extends Composite {

	Table table;
	TableItem[] items = EMPTY_ITEMS;
	Composite mainComposite, titleBarComposite, paginationComposite,
			tableComposite;
	TableViewer tableViewer;

	static final TableItem[] EMPTY_ITEMS = new TableItem[0];
	static final String[] EMPTY_TEXTS = new String[0];

	public CdetsDataGrid(Composite parent, int style) {
		super(parent, SWT.NONE);
		createDisplay(parent, style);
		table = new Table(tableComposite, style | SWT.H_SCROLL | SWT.V_SCROLL);
		// tableViewer = new TableViewer(table);
		table.setVisible(true);

		setBackground(parent.getBackground());
		setForeground(parent.getForeground());
		setFont(parent.getFont());

		String[] titles = { "Col 1", "Col 2", "Col 3", "Col 4" };
		for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(titles[loopIndex]);
		}
		for (int i = 0; i < 8; i++) {
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText(0, "Item " + i);
			item.setText(1, "Yes");
			item.setText(2, "No");
			item.setText(3, "A table item");
		}

		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		table.redraw();

		tableComposite.redraw();
		paginationComposite.redraw();
		mainComposite.redraw();
	}

	private void createDisplay(Composite parent, int style) {
		mainComposite = this;
		mainComposite.setBounds(0, 0, 300, 200);

		FormLayout formLay = new FormLayout();
		formLay.marginHeight = 0;
		formLay.marginWidth = 0;

		mainComposite.setLayout(formLay);
		titleBarComposite = new Composite(mainComposite, SWT.BORDER);
		titleBarComposite.setBounds(0, 0, 300, 20);
		FormData frmData1 = new FormData();
		frmData1.top = new FormAttachment(0, 0);
		frmData1.width = 300;
		frmData1.bottom = new FormAttachment(tableComposite, 20);
		frmData1.height = 20;
		titleBarComposite.setLayoutData(frmData1);
		titleBarComposite.setToolTipText("TitleBar");

		tableComposite = new Composite(mainComposite, SWT.BORDER);
		tableComposite.setBounds(0, 25, 300, 100);
		FormData frmData2 = new FormData();
		frmData2.top = new FormAttachment(titleBarComposite, 0);
		frmData2.width = 300;
		frmData2.bottom = new FormAttachment(paginationComposite, 5);
		frmData2.height = 110;
		tableComposite.setLayoutData(frmData2);
		tableComposite.setToolTipText("Table");

		paginationComposite = new Composite(mainComposite, SWT.BORDER);
		paginationComposite.setBounds(0, 130, 300, 20);

		FormData frmData3 = new FormData();
		frmData3.top = new FormAttachment(tableComposite, 0);
		frmData3.width = 300;
		frmData3.height = 20;
		paginationComposite.setLayoutData(frmData3);
		paginationComposite.setToolTipText("pagination");

		Label l2 = new Label(paginationComposite, SWT.NONE);
		l2.setText("This is a test Label for Pagination");
	}
}	


public class View extends ViewPart { public static final String ID = "RCPTest.view";

	public void createPartControl(Composite parent) {
		Composite comp = new Composite(parent, SWT.BORDER);
		comp.setSize(400, 200);
		CdetsDataGrid grid = new CdetsDataGrid(comp, SWT.SINGLE | SWT.BORDER);
	}

	public void setFocus() {
		//Add code
	}
}