Skip to content

Commit

Permalink
- Summary: Cube Builder - Provide a way to change order
Browse files Browse the repository at this point in the history
- Description: Add a sort button, allow for dimension and measure group
to be listed in Alphabetical order.
  • Loading branch information
cchao committed Mar 19, 2012
1 parent 13c26c9 commit 6240866
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ GroupsPage.ArrowButton.Add.Tooltip=Add selected field
GroupsPage.ArrowButton.Remove.Tooltip=Remove selected field
GroupsPage.Label.DataField=Available Fields:
GroupsPage.Label.Group=Groups and Summaries:
GroupsPage.tooltip.Sort=Sort
GroupsPage.Primary.Dataset=(Primary)
GroupsPage.VirtualField.Measure=(Drop a field here to create a measure)
GroupsPage.VirtualField.Level=(Drop a field here to create a level)
Expand Down Expand Up @@ -223,3 +224,4 @@ LevelStaticAttributeDialog.Label.Expression=Condition &Expression:
LevelStaticAttributeDialog.Label.Member=&Member:

LevelPropertyDialog.Label.Alignment=Al&ignment:

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;
import org.eclipse.birt.report.designer.internal.ui.views.RenameInputDialog;
import org.eclipse.birt.report.designer.internal.ui.views.outline.ListenerElementVisitor;
import org.eclipse.birt.report.designer.ui.IReportGraphicConstants;
import org.eclipse.birt.report.designer.ui.ReportPlatformUIImages;
import org.eclipse.birt.report.designer.ui.ReportPlugin;
import org.eclipse.birt.report.designer.ui.cubebuilder.BuilderPlugin;
import org.eclipse.birt.report.designer.ui.cubebuilder.dialog.DateLevelDialog;
import org.eclipse.birt.report.designer.ui.cubebuilder.dialog.GroupDialog;
import org.eclipse.birt.report.designer.ui.cubebuilder.dialog.GroupRenameDialog;
Expand All @@ -38,6 +42,7 @@
import org.eclipse.birt.report.designer.ui.cubebuilder.util.UIHelper;
import org.eclipse.birt.report.designer.ui.cubebuilder.util.VirtualField;
import org.eclipse.birt.report.designer.ui.newelement.DesignElementFactory;
import org.eclipse.birt.report.designer.ui.preferences.PreferenceFactory;
import org.eclipse.birt.report.designer.ui.util.ExceptionUtil;
import org.eclipse.birt.report.designer.ui.views.ElementAdapterManager;
import org.eclipse.birt.report.designer.ui.widget.TreeViewerBackup;
Expand Down Expand Up @@ -109,13 +114,17 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.TreeItem;

public class CubeGroupContent extends Composite implements Listener
{

private TreeItem[] dragSourceItems = new TreeItem[1];

private boolean[] useSorting = new boolean[]{false};
private static final String SORTING_PREFERENCE_KEY = "ExpressionBuilder.preference.enable.sorting"; //$NON-NLS-1$

class CustomDragListener implements DragSourceListener
{

Expand Down Expand Up @@ -304,25 +313,66 @@ public void treeExpanded( TreeEvent e )

};



private void initSorting( )
{
// read setting from preference
useSorting[0] = PreferenceFactory.getInstance( )
.getPreferences( BuilderPlugin.getDefault( ) )
.getBoolean( SORTING_PREFERENCE_KEY );
}

private void toggleSorting( boolean sorted )
{
useSorting[0] = sorted;

// update preference
PreferenceFactory.getInstance( )
.getPreferences( BuilderPlugin.getDefault( ) )
.setValue( SORTING_PREFERENCE_KEY, useSorting[0] );

groupViewer.refresh( );
}

private void createGroupField( )
{
Composite groupField = new Composite( this, SWT.NONE );
groupField.setLayoutData( new GridData( GridData.FILL_BOTH ) );
groupField.setLayout( new GridLayout( ) );
GridLayout layout = new GridLayout( );
layout.numColumns = 2;
groupField.setLayout( layout );

Label groupLabel = new Label( groupField, SWT.NONE );
groupLabel.setText( Messages.getString( "GroupsPage.Label.Group" ) ); //$NON-NLS-1$

ToolBar toolBar = new ToolBar( groupField, SWT.FLAT );
toolBar.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );

final ToolItem sortBtn = new ToolItem( toolBar, SWT.CHECK );
sortBtn.setImage( ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_ALPHABETIC_SORT ) );
sortBtn.setToolTipText( Messages.getString( "GroupsPage.tooltip.Sort" ) ); //$NON-NLS-1$
sortBtn.addSelectionListener( new SelectionAdapter( ) {

@Override
public void widgetSelected( SelectionEvent e )
{
toggleSorting( sortBtn.getSelection( ) );
}
} );


groupViewer = new TreeViewer( groupField, SWT.SINGLE
| SWT.H_SCROLL
| SWT.V_SCROLL
| SWT.BORDER );
groupViewer.getTree( )
.setLayoutData( new GridData( GridData.FILL_BOTH ) );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.horizontalSpan = 2;
groupViewer.getTree( ).setLayoutData( gd );
( (GridData) groupViewer.getTree( ).getLayoutData( ) ).heightHint = 250;
( (GridData) groupViewer.getTree( ).getLayoutData( ) ).widthHint = 200;
groupViewer.setLabelProvider( getCubeLabelProvider( ) );
groupViewer.setContentProvider( new CubeContentProvider( ) );
groupViewer.setContentProvider( new CubeContentProvider( useSorting ) );
groupViewer.addSelectionChangedListener( new ISelectionChangedListener( ) {

public void selectionChanged( SelectionChangedEvent event )
Expand Down Expand Up @@ -1152,6 +1202,8 @@ else if ( newIndex > oldIndex )
}
} );

initSorting( );
sortBtn.setSelection( useSorting[0] );
}

private void createMoveButtonsField( )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package org.eclipse.birt.report.designer.ui.cubebuilder.provider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.eclipse.birt.report.designer.ui.cubebuilder.util.VirtualField;
Expand All @@ -26,6 +28,8 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.ibm.icu.text.Collator;

/**
* Tree viewer content provider adapter for resource browser.
*
Expand All @@ -34,6 +38,17 @@
public class CubeContentProvider implements ITreeContentProvider
{

private boolean[] useSorting;

public CubeContentProvider( )
{
}

public CubeContentProvider( boolean[] useSorting )
{
this.useSorting = useSorting;
}

public Object[] getChildren( Object parentElement )
{
if ( parentElement instanceof Object[] )
Expand Down Expand Up @@ -82,10 +97,29 @@ else if ( hierarchy.getLevelCount( ) > 0 )
VirtualField virtualDimsnion = new VirtualField( VirtualField.TYPE_DIMENSION );
virtualDimsnion.setModel( parentElement );
List dimensionList = new ArrayList( );
List<DimensionHandle> dimensions = new ArrayList<DimensionHandle>( );
if ( cube.getContentCount( CubeHandle.DIMENSIONS_PROP ) > 0 )
{
dimensionList.addAll( cube.getContents( CubeHandle.DIMENSIONS_PROP ) );
dimensions.addAll( cube.getContents( CubeHandle.DIMENSIONS_PROP ) );
}

if ( useSorting != null && useSorting[0] )
{
// sort attribute list
Collections.sort( dimensions,
new Comparator<DimensionHandle>( ) {

public int compare( DimensionHandle o1,
DimensionHandle o2 )
{
return Collator.getInstance( )
.compare( o1.getName( ),
o2.getName( ) );
}
} );
}

dimensionList.addAll( dimensions );
dimensionList.add( 0, virtualDimsnion );
return dimensionList.toArray( );

Expand All @@ -96,10 +130,27 @@ else if ( name.equals( ICubeModel.MEASURE_GROUPS_PROP ) )
VirtualField virtualMeasureGroup = new VirtualField( VirtualField.TYPE_MEASURE_GROUP );
virtualMeasureGroup.setModel( parentElement );
List measureGroupList = new ArrayList( );
List<MeasureGroupHandle> measures = new ArrayList<MeasureGroupHandle>( );
if ( cube.getContentCount( CubeHandle.MEASURE_GROUPS_PROP ) > 0 )
{
measureGroupList.addAll( cube.getContents( CubeHandle.MEASURE_GROUPS_PROP ) );
measures.addAll( cube.getContents( CubeHandle.MEASURE_GROUPS_PROP ) );
}
if ( useSorting != null && useSorting[0] )
{
// sort attribute list
Collections.sort( measures,
new Comparator<MeasureGroupHandle>( ) {

public int compare( MeasureGroupHandle o1,
MeasureGroupHandle o2 )
{
return Collator.getInstance( )
.compare( o1.getName( ),
o2.getName( ) );
}
} );
}
measureGroupList.addAll( measures );
measureGroupList.add( 0, virtualMeasureGroup );
return measureGroupList.toArray( );
}
Expand Down

0 comments on commit 6240866

Please sign in to comment.