Community
Participate
Working Groups
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Build Identifier: M20080911-1700 1) Create Table with multiple colums. 2) Add Items to the table. 3) Create Table Editors containing a Combo box and attach this to the one of the Table Item Columns. ( The idea is to have a Tavle with a column contiang Combo Editor.); 4) Create two butons "ADD" and "REMOVE" to add new Items or delete the selected table Items. Whenever a new table item is add corresponding item column is attached with a combo editor. 5) Inorder to increase the size of the "Cells", add a Listener for MeasureItem event. Problems: 1) Initially when the Table is displayed, it takes few seconds to paint/layout the combo editors after resizing the cells which is a significant delay. 2) When a table item is added to enable the vertical scrollbar (when the number of items size is more than the clientarea), paint event does not paint/layout the combo editors. 3) On resize of the Workbench/View contianing the table, custom table editors are not layedout properly. Reproducible: Always Steps to Reproduce: 1) Create Table with multiple colums. 2) Add Items to the table. 3) Create Table Editors containing a Combo box and attach this to the one of the Table Item Columns. ( The idea is to have a Tavle with a column contiang Combo Editor.); 4) Create two butons "ADD" and "REMOVE" to add new Items or delete the selected table Items. Whenever a new table item is add corresponding item column is attached with a combo editor. 5) Inorder to increase the size of the "Cells", add a Listener for MeasureItem event. import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; public class TableSample { static String [] columnTitles = {"Name", "Type", "Size", "Modified" }; static String[][] tableData = {{"classes","databases","images","classes"}, {"0","1","2","3"}, {"today","tomorrow","yesterday","today"} }; /** * @param args */ public static void main(String[] args) { Display display = new Display(); Shell shell=new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell,SWT.NONE); comp.setLayout(new GridLayout()); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true) ); final Group grp =new Group(comp, SWT.NONE); grp.setLayout(new GridLayout()); grp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true) ); final Table t = new Table(grp, SWT.BORDER| SWT.FULL_SELECTION); t.setLinesVisible(true); TableColumn tc1 = new TableColumn(t, SWT.CENTER); TableColumn tc2 = new TableColumn(t, SWT.CENTER); TableColumn tc3 = new TableColumn(t, SWT.CENTER); tc1.setText("First Name"); tc2.setText("Last Name"); tc3.setText("Address"); tc1.setWidth(70); tc2.setWidth(70); tc3.setWidth(80); t.setHeaderVisible(true); TableItem item1 = new TableItem(t, SWT.NONE); item1.setText(new String[] { "Tim", "Hatton", "Kentucky" }); final TableItem item2 = new TableItem(t, SWT.NONE); item2.setText(new String[] { "Caitlyn", "Warner", "Ohio" }); final TableItem item3 = new TableItem(t, SWT.NONE); item3.setText(new String[] { "Reese", "Miller", "Ohio" }); final TableItem item4 = new TableItem(t, SWT.NONE); item4.setText(new String[] { "Caitlyn", "Warner", "Ohio" }); final TableItem item5 = new TableItem(t, SWT.NONE); item5.setText(new String[] { "Reese", "Miller", "Ohio" }); TableItem item6 = new TableItem(t, SWT.NONE); item6.setText(new String[] { "Tim", "Hatton", "Kentucky" }); for(int i=0;i<6;i++){ TableEditor editor = new TableEditor(t); CCombo combo = new CCombo(t, SWT.NONE); combo.setText("CCombo"); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = false; editor.grabVertical = false; editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.CENTER; editor.minimumWidth = 50; editor.minimumHeight = 15; editor.setEditor(combo, t.getItem(i), 1); } t.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { event.height=30; } }); t.setLayout(new GridLayout()); t.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); Button add =new Button(grp, SWT.NONE); add.setText("ADD"); add.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e) { TableItem item=new TableItem(t, SWT.NONE); item.setText(new String[]{"abc","123","xyz"}); TableEditor editor = new TableEditor(t); CCombo combo = new CCombo(t, SWT.NONE); combo.setText(item.getText(2)); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = false; editor.grabVertical = false; editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.CENTER; editor.minimumWidth = 50; editor.minimumHeight = 15; editor.setEditor(combo, item, 1); } }); Button btn =new Button(grp, SWT.NONE); btn.setText("DELETE"); btn.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e) { TableItem it=t.getSelection()[0]; if(it!=null){ it.dispose(); for(int i=0;i<t.getItemCount();i++){ TableEditor editor = new TableEditor(t); CCombo combo = new CCombo(t, SWT.NONE); combo.setText("CCombo"); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = false; editor.grabVertical = false; editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.CENTER; editor.minimumWidth = 50; editor.minimumHeight = 15; editor.setEditor(combo, t.getItem(i), 1); } } } }); shell.open(); while(!shell.isDisposed()){ if (!display.readAndDispatch()) display.sleep(); } shell.dispose(); } }
Please try this out on a recent 3.6 build and let us know if you are still seeing this. Thanks!
(In reply to comment #1) > Please try this out on a recent 3.6 build and let us know if you are still > seeing this. Thanks! Yes.. These Problems are exist in 3.6 M1 Build too.. Thanks Pradeep
The example is wrong, most of the problem is caused by this line: t.setLayout(new GridLayout()); The TableEditor is responsible by laying out the editor (ccombo), adding a GridLayout to the table makes no sense here. The first problem happens because the TableEditors are added to the Table before the table is resized (they eventually jump to the right place because of internal timer in table editor). The fix is to add the TableEditor after shell.open(). Closing as INVALID.
(In reply to comment #3) > The example is wrong, most of the problem is caused by this line: > t.setLayout(new GridLayout()); > > > The TableEditor is responsible by laying out the editor (ccombo), adding a > GridLayout to the table makes no sense here. > > > The first problem happens because the TableEditors are added to the Table > before the table is resized (they eventually jump to the right place because of > internal timer in table editor). The fix is to add the TableEditor after > shell.open(). > > > Closing as INVALID. Hallo Fellipe Thanks for the response. 1) removing the t.setLayout(new GridLayout()); has solved the layoput problems on resize. 2) adding the editors after the shell after opening seems to be easy here in this SWT example. But if I am doing this in the eclipse RCP view, how can I know whether my view is opened completely, so that I can add the table editors.( Currently setting the table editors in the view setFocus() method is solving the problem. Is this correct ? or can i do this in some other place? )
Do you have that problem in your RCP app ? I'd not expect so. Try calling table.pack() or table.getParent().layout() or whatever makes sense in your case. Basically you need the table to have its final size before you add the editors.
Problem: In RCP view - When custom widgets like combo are added to the table cells using table editors (in createPartControl()), there is a noticable delay (5 to 10 seconds) in layout of combos in the table cells. Please look at the images attached for better understanding of the problem. This happens only on the initial view creation, any further table editors setting happens with out any dealy. So should we set the table editors in a different method from createPartControl() ? If so, in which method() ?
Created attachment 153215 [details] Combo Control in table cell - state1
Created attachment 153216 [details] Combo Control in table cell - state2 (after 5 to 10 seconds delay)
(In reply to comment #6) > Problem: > So should we set the table editors in a different method from > createPartControl() ? If so, in which method() ? You will need to ask that in the jface/ui newsgroups. createPartControl() is not SWT and I don't the answer.