Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338044

Summary: Default column width for template preference is too small
Product: [Modeling] TMF Reporter: Samantha Chan <chanskw>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jan, mkomor, sebastian.zarnekow, sven.efftinge
Version: 1.0.1Flags: sven.efftinge: indigo+
Target Milestone: SR1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Samantha Chan CLA 2011-02-23 22:26:52 EST
Opening the preferences page for templates, it is not possible to read the names of the templates as the column width is only about 4 characters long. 

I believe this is because the table columns are packed before it is populated.
Need to consider putting a longer default size for the name column.
Comment 1 Mary Komor CLA 2011-06-23 19:24:57 EDT
We would like to ask for this to be considered for 2.0 SR1.
Comment 2 Jan Koehnlein CLA 2011-07-06 07:28:43 EDT
Unfortunately, JFace does not export the essential parts it uses to do the layouting. The column width is determined in the superclass

org.eclipse.ui.texteditor.templates.TemplatePreferencePage.createContents(Composite)

but neither the used ColumnLayout nor the method 

org.eclipse.ui.texteditor.templates.TemplatePreferencePage.computeMinimumColumnWidth(GC, String)

is exported. Furthermore, the minimum width depends on the width of the column title only.

You can override createContents in a customized implementation of the XtextTemplatePreferencePage/AdvancedTemplatePreferencePage and use another layout, similar to this snippet:

	@Override
	protected Control createContents(Composite ancestor) {
		Control contents = super.createContents(ancestor);
		Table table = getTableViewer().getTable();
		Composite tableComposite = table.getParent();
		TableColumnLayout tableColumnLayout = new TableColumnLayout();
		tableColumnLayout.setColumnData(table.getColumn(0), new ColumnWeightData(2, 10, true));
		tableColumnLayout.setColumnData(table.getColumn(1), new ColumnWeightData(1, 10, true));
		tableColumnLayout.setColumnData(table.getColumn(2), new ColumnWeightData(1, 10, true));
		tableColumnLayout.setColumnData(table.getColumn(3), new ColumnPixelData(10, true));
		tableComposite.setLayout(tableColumnLayout);
		return contents;
	}

This will give the first column more "weight". 

As this looks more like hack, I'd rather not apply that to the Xtext codebase, but still you can try the workaround given above.
Comment 3 Sebastian Zarnekow CLA 2011-07-17 15:27:47 EDT
I found the template page looking nicely with

@Override
protected Control createContents(Composite ancestor) {
	Control result = super.createContents(ancestor);
	ancestor.layout();
	return result;
}

@Override
public void createControl(Composite parent) {
	super.createControl(parent);
	getTableViewer().getTable().getColumns()[0].pack();
}

Pushed to master.
Comment 4 Karsten Thoms CLA 2017-09-19 17:31:11 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:42:22 EDT
Closing all bugs that were set to RESOLVED before Neon.0