False display of columnWidths after restore via natTable.loadState() [message #1053096] |
Thu, 02 May 2013 12:29 |
Franz-Josef Wiszniewsky Messages: 11 Registered: January 2013 |
Junior Member |
|
|
Hello,
I'm using natTable's handy loadState() method in order to reload a previously saved table configuration. All loaded data is applied correctly i.e. sort order, sort directions, hidden columns, filter row values, (renamed) header labels, column order. The corresponding values are shown and ordered correctly.
My current problem is that the column widths are loaded from the formerly saved properties, but not correctly displayed. The StructuralRefreshEvent fired by the dataLayer after columnWithConfig and rowHeightConfig were updated, seems to go unheard.
public class DataLayer extends AbstractLayer implements IUniqueIndexLayer {
...
public void loadState(String prefix, Properties properties) {
...
columnWidthConfig.loadState(prefix + PERSISTENCE_KEY_COLUMN_WIDTH, properties);
...
fireLayerEvent(new StructuralRefreshEvent(this));
}
...
}
After executing loadState() the user must either manually resize the whole window or at least the width of a random column in order to get the right visualization.
Without success I tried to refresh the table using (separately) each of the following lines
- natTable.refresh();
- natTable.redraw(); natTable.update();
- parent.redraw(); parent.update(); // where parent is the composite holding the table
- parent.layout();
- parent.layout(true);
- parent.layout(true, true);
- natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, column, natTable.getConfigRegistry(), new GCFactory(natTable))); // on every column
The dataLayer I'm referring to is the (base) dataLayer of my body layer stack. ColumnPercentageSizing is activated for this layer.
Please let me know how to get correctly sized columns.
Any help is appreciated.
|
|
|
|
|
|
|
|
|
|
|
Re: False display of columnWidths after restore via natTable.loadState() [message #1053793 is a reply to message #1053791] |
Tue, 07 May 2013 15:42 |
Dirk Fauth Messages: 2902 Registered: July 2012 |
Senior Member |
|
|
Have you checked out the sources from git? Otherwise the example might be not that helpful. Also you need to ensure to delete the nattable.properties in your examples workspace before starting as it may contain wrong values which will overload the settings on startup.
/*******************************************************************************
* Copyright (c) 2012 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Dirk Fauth
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.examples._300_Data;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.PersistentNatExampleWrapper;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.data.DummyModifiableBodyDataProvider;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack;
import org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class PersistentPercentageSizingDataLayerExample extends PersistentNatExampleWrapper {
public static void main(String[] args) throws Exception {
StandaloneNatExampleRunner.run(600, 650, new PersistentPercentageSizingDataLayerExample());
}
public PersistentPercentageSizingDataLayerExample() {
super(new Test());
}
}
class Test extends AbstractNatExample {
@Override
public Control createExampleControl(Composite parent) {
parent.setLayout(new GridLayout());
final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
DummyGridLayerStack gridLayer = new DummyGridLayerStack(dataProvider);
final DataLayer n5DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
n5DataLayer.setColumnWidthPercentageByPosition(0, 25);
n5DataLayer.setColumnWidthPercentageByPosition(1, 25);
n5DataLayer.setColumnWidthPercentageByPosition(2, 50);
n5DataLayer.setColumnPercentageSizing(true);
final NatTable n5 = new NatTable(parent, gridLayer, false);
n5.addConfiguration(new DefaultNatTableStyleConfiguration());
n5.addConfiguration(new HeaderMenuConfiguration(n5));
n5.configure();
GridDataFactory.fillDefaults().grab(true, false).applyTo(n5);
//add buttons
Button b1 = new Button(parent, SWT.PUSH);
b1.setText("change");
b1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
n5DataLayer.setColumnWidthPercentageByPosition(0, 50);
n5DataLayer.setColumnWidthPercentageByPosition(1, 25);
n5DataLayer.setColumnWidthPercentageByPosition(2, 25);
}
});
Button b2 = new Button(parent, SWT.PUSH);
b2.setText("default");
b2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
n5DataLayer.setColumnWidthPercentageByPosition(0, 25);
n5DataLayer.setColumnWidthPercentageByPosition(1, 25);
n5DataLayer.setColumnWidthPercentageByPosition(2, 50);
}
});
return n5;
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04676 seconds