summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorning.zhang2012-06-19 05:29:25 (EDT)
committer dgao2012-06-19 05:29:25 (EDT)
commitbbfb1963c7c62b6ccae074ac3bba31c05760aec3 (patch)
treebc92482cc1eaf8d8adcd4967a2389b6940dbe091
parent7005ba9aed3dccf1ae58f8c34ab912d2c45c362a (diff)
downloadorg.eclipse.birt-bbfb1963c7c62b6ccae074ac3bba31c05760aec3.zip
org.eclipse.birt-bbfb1963c7c62b6ccae074ac3bba31c05760aec3.tar.gz
org.eclipse.birt-bbfb1963c7c62b6ccae074ac3bba31c05760aec3.tar.bz2
Supported sorting the Element Names table in the preference page.
-rw-r--r--UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/ui/preferences/ElementNamesConfigurationBlock.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/ui/preferences/ElementNamesConfigurationBlock.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/ui/preferences/ElementNamesConfigurationBlock.java
index d1d36d2..967b911 100644
--- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/ui/preferences/ElementNamesConfigurationBlock.java
+++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/ui/preferences/ElementNamesConfigurationBlock.java
@@ -23,7 +23,10 @@ import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
@@ -112,6 +115,8 @@ public class ElementNamesConfigurationBlock extends OptionsConfigurationBlock
itemContentList = new ItemContentList( this, getKeys( ) );
tableViewer.setInput( itemContentList );
+ sortTable(tableViewer.getTable().getColumn(0), true);
+
return pageContent;
}
@@ -151,6 +156,24 @@ public class ElementNamesConfigurationBlock extends OptionsConfigurationBlock
column = new TableColumn( table, SWT.NONE, i );
column.setText( elementNames[i] );
column.setWidth( columnWidth );
+
+ column.addSelectionListener(new SelectionListener( ) {
+ boolean asc = true;
+ public void widgetSelected( final SelectionEvent e )
+ {
+ TableColumn selectedColumn = (TableColumn)e.widget;
+ if(table.getSortColumn() == selectedColumn)
+ {
+ asc = !asc;
+ }
+ sortTable(selectedColumn, asc);
+ }
+
+ public void widgetDefaultSelected( SelectionEvent e )
+ {
+ widgetSelected( e );
+ }
+ } );
}
}
@@ -196,6 +219,33 @@ public class ElementNamesConfigurationBlock extends OptionsConfigurationBlock
tableViewer.setCellModifier( new ElementNamesCellModifier( this ) );
}
+ private void sortTable(final TableColumn column, final boolean asc)
+ {
+ Table table = tableViewer.getTable();
+ table.setSortColumn(column);
+ table.setSortDirection(asc? SWT.UP : SWT.DOWN);
+ tableViewer.setSorter(new ViewerSorter() {
+ public int compare(Viewer viewer, Object o1, Object o2)
+ {
+ int result;
+ switch(tableViewer.getTable().indexOf(column))
+ {
+ case 0: default:
+ result = ( (ItemContent) o1 ).getDisplayName().compareTo(( (ItemContent) o2 ).getDisplayName());
+ break;
+ case 1:
+ result = ( (ItemContent) o1 ).getCustomName().compareTo(( (ItemContent) o2 ).getCustomName());
+ break;
+ case 2:
+ result = ( (ItemContent) o1 ).getDescription().compareTo(( (ItemContent) o2 ).getDescription());
+ break;
+ }
+ return asc? result : result * -1;
+ }
+ });
+
+ }
+
/**
* Get the list of elementNames
*