Skip to content
Permalink
Browse files

remember column widths between runs

  • Loading branch information
ceki committed Jul 16, 2012
1 parent b186674 commit cf538d0be08fe36c6616e3238efe5709f38919f1
@@ -13,6 +13,9 @@

final public static int ICON_SIZE = 16;


final public static String COLUMN_SIZE_DIALOG_SETTINGS_PREFIX = "COLUMN_SIZE_DIALOG_SETTINGS_PREFIX_";

//public static int MAX = 20*1000;

//public static int CLEAN_COUNT = MAX / 10;
@@ -0,0 +1,44 @@
package ch.qos.logback.beagle.vista;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;

import ch.qos.logback.beagle.Activator;
import ch.qos.logback.beagle.Constants;

public class ColumnControlListener implements ControlListener {



final String columnName;
ColumnControlListener(String columnName) {
this.columnName = columnName;
}

@Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub

}

@Override
public void controlResized(ControlEvent e) {

GridColumn column = (GridColumn) e.widget;
System.out.println("ColumnControlListener new col width for "+columnName+" "+column.getWidth());

saveColumnSize(column.getWidth());


}

private void saveColumnSize(int width) {
if(Activator.INSTANCE == null)
return;
IDialogSettings dialogSettings = Activator.INSTANCE.getDialogSettings();
dialogSettings.put(Constants.COLUMN_SIZE_DIALOG_SETTINGS_PREFIX+columnName, width);
}

}
@@ -8,6 +8,7 @@
*/
package ch.qos.logback.beagle.vista;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
@@ -93,10 +94,10 @@ private void init() {
formData.bottom = new FormAttachment(toolbar, -5);

grid.setLayoutData(formData);
// GridColumn tableColumn = new GridColumn(grid, SWT.NULL);
// tableColumn.setText("");
// tableColumn.setWidth(100);
// tableColumn.pack();
// GridColumn tableColumn = new GridColumn(grid, SWT.NULL);
// tableColumn.setText("");
// tableColumn.setWidth(100);
// tableColumn.pack();
grid.setHeaderVisible(true);
grid.setLinesVisible(false);

@@ -110,8 +111,8 @@ private void init() {
classicTISBuffer.diffCue = diffCueLabel;
classicTISBuffer.jumpCue = jumpCueLabel;

preferencesChangeListenter = new BeaglePreferencesChangeListenter(converterFacade,
classicTISBuffer);
preferencesChangeListenter = new BeaglePreferencesChangeListenter(
converterFacade, classicTISBuffer);

// when the table is cleared visualElementBuffer's handleEvent method will
// re-populate the item
@@ -141,16 +142,18 @@ private void init() {
}

private void createColumns(Grid grid2) {
GridColumn column0 = new GridColumn(grid,SWT.NONE);
GridColumn column0 = new GridColumn(grid, SWT.NONE);
column0.setWidth(24);

for(Converter<ILoggingEvent> c: converterFacade.getConverterList()) {
GridColumn column = new GridColumn(grid,SWT.NONE);
column.setText(converterFacade.computeConverterName(c));
column.setWidth(100);
}

for (Converter<ILoggingEvent> c : converterFacade.getConverterList()) {
GridColumn column = new GridColumn(grid, SWT.NONE);
String columnName = converterFacade.computeConverterName(c);

column.setText(columnName);
column.setWidth(getColumnSizeDialogSetting(columnName, 100));
column.addControlListener(new ColumnControlListener(columnName));
}
}


int getBufferSize() {
int result = BeaglePreferencesPage.BUFFER_SIZE_PREFERENCE_DEFAULT_VALUE;
@@ -161,6 +164,20 @@ int getBufferSize() {
return result;
}

int getColumnSizeDialogSetting(String columnName, int defaultValue) {
if (Activator.INSTANCE == null)
return defaultValue;
IDialogSettings dialogSettings = Activator.INSTANCE.getDialogSettings();
try {
int val = dialogSettings.getInt(Constants.COLUMN_SIZE_DIALOG_SETTINGS_PREFIX
+ columnName);
System.out.println("width for "+columnName+": "+val);
return val;
} catch (NumberFormatException e) {
return defaultValue;
}
}

private void initConverterFacade() {
converterFacade.setContext(loggerContext);
String pattern = BeaglePreferencesPage.PATTERN_PREFERENCE_DEFAULT_VALUE;
@@ -169,9 +186,9 @@ private void initConverterFacade() {
pattern = pStore.getString(BeaglePreferencesPage.PATTERN_PREFERENCE);
}
// the layout should not print exceptions
if(!pattern.contains("%nopex"))
if (!pattern.contains("%nopex"))
pattern += "%nopex";
converterFacade.setPattern(pattern);
converterFacade.start();
}
}
}

0 comments on commit cf538d0

Please sign in to comment.
You can’t perform that action at this time.