Skip to content

Commit

Permalink
Enhance the expression builder with new descening sort option (#1714) (
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky authored Jun 4, 2024
1 parent 495f928 commit 1af1112
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,8 @@ LibraryExplorerTreeViewPage.toolTips.DragAndDropToOutlineORLayout=Drag and drop
ExpressionBuidler.Dialog.Title=Expression Builder (JavaScript)
ExpressionBuidler.Title=Expression Builder
ExpressionBuilder.tooltip.Sort=Sort
ExpressionBuilder.tooltip.Sort.Ascending=Sort ascending
ExpressionBuilder.tooltip.Sort.Descending=Sort descending
ExpressionBuilder.toolTipText.Button=Open Expression Builder

###########################################################
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ public interface IReportGraphicConstants {
/** icon property: alphabetic sort */
String ICON_ALPHABETIC_SORT = "AlphabeticSort"; //$NON-NLS-1$

/** icon property: alphabetic sort ascending */
String ICON_ALPHABETIC_SORT_ASCENDING = "AlphabeticSortAscending"; //$NON-NLS-1$

/** icon property: alphabetic sort descending */
String ICON_ALPHABETIC_SORT_DESCENDING = "AlphabeticSortDescending"; //$NON-NLS-1$

/** icon property: autotext */
String ICON_AUTOTEXT = "AutoText"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,12 @@ private final static void declareImages() {
declareImage(IReportGraphicConstants.ICON_DATA_COLUMN, ICONS_PATH + OBJ16_PATH + "data_column.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_INHERIT_COLUMN, ICONS_PATH + OBJ16_PATH + "inherit_column.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT, ICONS_PATH + OBJ16_PATH + "alpha_sort.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT_ASCENDING,
ICONS_PATH + OBJ16_PATH + "alpha_sort_ascending.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT_DESCENDING,
ICONS_PATH + OBJ16_PATH + "alpha_sort_descending.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_GROUP_SORT, ICONS_PATH + OBJ16_PATH + "group_sort.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_LOCAL_PROPERTIES, ICONS_PATH + OBJ16_PATH + "local_prop.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT, ICONS_PATH + OBJ16_PATH + "alpha_sort.gif"); //$NON-NLS-1$
declareImage(IReportGraphicConstants.ICON_EXPRESSION_OPERATOR, ICONS_PATH + OBJ16_PATH + "operator.gif"); //$NON-NLS-1$

declareImage(IReportGraphicConstants.ICON_EXPRESSION_GLOBAL, ICONS_PATH + OBJ16_PATH + "global.gif"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -87,6 +86,7 @@
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.ACC;
import org.eclipse.swt.accessibility.Accessible;
Expand Down Expand Up @@ -180,7 +180,9 @@ public class ExpressionBuilder extends BaseTitleAreaDialog {

private static final Object[] EMPTY = {};

private static final String SORTING_PREFERENCE_KEY = "ExpressionBuilder.preference.enable.sorting"; //$NON-NLS-1$
private static final String SORT_ASCENDING_PREFERENCE_KEY = "ExpressionBuilder.preference.enable.sorting"; //$NON-NLS-1$

private static final String SORT_DESCENDING_PREFERENCE_KEY = "ExpressionBuilder.preference.enable.sorting.descending"; //$NON-NLS-1$

private TableViewer categoryTable, functionTable;
private TreeViewer subCategoryTable;
Expand All @@ -197,7 +199,8 @@ public class ExpressionBuilder extends BaseTitleAreaDialog {
protected String expression = null;
protected String title;

private boolean useSorting = false;
private boolean useSortAscending = false;
private boolean useSortDescending = false;
private boolean showLeafOnlyInFunctionTable = false;
private Object[] defaultSelection;

Expand Down Expand Up @@ -286,11 +289,11 @@ && getAdapter().isExtendedDataItem((ReportElementHandle) inputElement)) {

List<LevelAttributeHandle> attribs = new ArrayList<>();

for (Iterator iterator = ((LevelHandle) inputElement).attributesIterator(); iterator.hasNext();) {
for (Iterator<?> iterator = ((LevelHandle) inputElement).attributesIterator(); iterator.hasNext();) {
attribs.add((LevelAttributeHandle) iterator.next());
}

if (useSorting) {
if (useSortAscending || useSortDescending) {
// sort attribute list
Collections.sort(attribs, new Comparator<LevelAttributeHandle>() {

Expand All @@ -309,7 +312,8 @@ public int compare(LevelAttributeHandle o1, LevelAttributeHandle o2) {
return new Object[] { inputElement };
}

if (useSorting && provider instanceof ISortableExpressionProvider) {
if ((useSortAscending || useSortDescending) && provider instanceof ISortableExpressionProvider) {
((ExpressionProvider) provider).setAscending(useSortAscending);
return ((ISortableExpressionProvider) provider).getSortedChildren(inputElement);
}

Expand Down Expand Up @@ -440,7 +444,7 @@ private void insertSelection(IStructuredSelection selection) {
handle.getModuleHandle().getCommandStack().startTrans(Messages.getString("DataEditPart.stackMsg.edit")); //$NON-NLS-1$
ColumnBindingDialog dialog = new ColumnBindingDialog(handle,
Messages.getString("DataColumBindingDialog.title.EditDataBinding")); //$NON-NLS-1$
if (dialog.open() == Dialog.OK) {
if (dialog.open() == Window.OK) {
handle.getModuleHandle().getCommandStack().commit();
functionTable.refresh();
} else {
Expand Down Expand Up @@ -722,16 +726,30 @@ public void widgetSelected(SelectionEvent e) {

private void initSorting() {
// read setting from preference
useSorting = PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault())
.getBoolean(SORTING_PREFERENCE_KEY);
useSortAscending = PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault())
.getBoolean(SORT_ASCENDING_PREFERENCE_KEY);

// read setting from preference
useSortDescending = PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault())
.getBoolean(SORT_DESCENDING_PREFERENCE_KEY);
}

private void toggleSorting(boolean sorted) {
useSorting = sorted;
private void toggleSorting(boolean sorted, String sortingType) {

if (sortingType == "asc") {
useSortAscending = sorted;
useSortDescending = false;
} else {
useSortDescending = sorted;
useSortAscending = false;
}

// update preference
PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault()).setValue(SORTING_PREFERENCE_KEY,
useSorting);
PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault()).setValue(
SORT_ASCENDING_PREFERENCE_KEY, useSortAscending);

PreferenceFactory.getInstance().getPreferences(ReportPlugin.getDefault())
.setValue(SORT_DESCENDING_PREFERENCE_KEY, useSortDescending);

functionTable.refresh();
}
Expand Down Expand Up @@ -787,23 +805,39 @@ public void keyTraversed(TraverseEvent e) {
ToolBar toolBar = new ToolBar(functionHeader, 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("ExpressionBuilder.tooltip.Sort")); //$NON-NLS-1$
sortBtn.addSelectionListener(new SelectionAdapter() {
final ToolItem sortBtnAsc = new ToolItem(toolBar, SWT.CHECK);
sortBtnAsc.setImage(ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT_ASCENDING));
sortBtnAsc.setToolTipText(Messages.getString("ExpressionBuilder.tooltip.Sort.Ascending")); //$NON-NLS-1$

final ToolItem sortBtnDesc = new ToolItem(toolBar, SWT.CHECK);
sortBtnDesc.setImage(ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_ALPHABETIC_SORT_DESCENDING));
sortBtnDesc.setToolTipText(Messages.getString("ExpressionBuilder.tooltip.Sort.Descending")); //$NON-NLS-1$

sortBtnAsc.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
toggleSorting(sortBtnAsc.getSelection(), "asc");
sortBtnDesc.setSelection(false);
}
});

sortBtnDesc.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
toggleSorting(sortBtn.getSelection());
toggleSorting(sortBtnDesc.getSelection(), "desc");
sortBtnAsc.setSelection(false);
}
});

if (provider instanceof ISortableExpressionProvider) {
initSorting();

sortBtn.setSelection(useSorting);
sortBtnAsc.setSelection(useSortAscending);
sortBtnDesc.setSelection(useSortDescending);
} else {
sortBtn.setEnabled(false);
sortBtnAsc.setEnabled(false);
}

int style = SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ public Object[] getSortedChildren(Object parentElement) {
return sortChildren(parentElement, getChildren(parentElement));
}

/**
* Set the sorting type to ascending or descending
*
* @param ascending sorting type
*/
public void setAscending(boolean ascending) {
innerComparator.setAscending(ascending);
}

protected Object[] sortElements(Object[] children) {
TreeMap<String, Object> map = new TreeMap<>(innerComparator);

Expand All @@ -364,10 +373,10 @@ protected Object[] sortChildren(Object parent, Object[] children) {
if (ALL.equals(parent)) {
// sort for all parameters
return sortElements(children);
} else {
// children for category, return original list
return children;
}
// children for category, return original list
return children;

} else if (parent instanceof IClassInfo) {
Object[] result = new Object[children.length];
System.arraycopy(children, 0, result, 0, children.length);
Expand Down

0 comments on commit 1af1112

Please sign in to comment.