diff --git a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF index 5900aa1ca..4cbe0e1a2 100644 --- a/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF @@ -17,9 +17,9 @@ Require-Bundle: org.eclipse.core.expressions, org.eclipse.ui.genericeditor, org.eclipse.ui.ide, org.eclipse.e4.ui.css.swt.theme, - org.eclipse.tm4e.registry;bundle-version="0.6.5", - org.eclipse.tm4e.core;bundle-version="0.6.1", - org.eclipse.tm4e.ui;bundle-version="0.7.1", + org.eclipse.tm4e.registry;bundle-version="0.6.6", + org.eclipse.tm4e.core;bundle-version="0.6.2", + org.eclipse.tm4e.ui;bundle-version="0.7.2", com.google.gson;bundle-version="[2.10.1,3.0.0)" Bundle-Activator: org.eclipse.tm4e.languageconfiguration.LanguageConfigurationPlugin Export-Package: org.eclipse.tm4e.languageconfiguration, diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java index 51fa3c366..4426b663f 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/LanguageConfigurationPreferencePage.java @@ -48,11 +48,11 @@ import org.eclipse.tm4e.languageconfiguration.internal.registry.ILanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.registry.LanguageConfigurationRegistryManager; import org.eclipse.tm4e.languageconfiguration.internal.registry.WorkingCopyLanguageConfigurationRegistryManager; -import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnSelectionAdapter; -import org.eclipse.tm4e.languageconfiguration.internal.widgets.ColumnViewerComparator; import org.eclipse.tm4e.languageconfiguration.internal.widgets.LanguageConfigurationPreferencesWidget; import org.eclipse.tm4e.languageconfiguration.internal.wizards.LanguageConfigurationImportWizard; import org.eclipse.tm4e.ui.internal.utils.UI; +import org.eclipse.tm4e.ui.internal.widgets.ColumnSelectionAdapter; +import org.eclipse.tm4e.ui.internal.widgets.ColumnViewerComparator; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.osgi.service.prefs.BackingStoreException; @@ -152,7 +152,7 @@ private void createDefinitionsListContent(final Composite parent) { column.setText(label); final int minWidth = computeMinimumColumnWidth(gc, label); columnLayout.setColumnData(column, new ColumnWeightData(2, minWidth, true)); - column.addSelectionListener(new ColumnSelectionAdapter(column, definitionViewer, i, viewerComparator)); + column.addSelectionListener(new ColumnSelectionAdapter(definitionViewer, viewerComparator, 0)); if (i == 0) { // Specify default sorting diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java deleted file mode 100644 index f4002978c..000000000 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnSelectionAdapter.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.widgets; - -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -/** - * Sort the selected column and refresh the viewer. - * - */ -public final class ColumnSelectionAdapter extends SelectionAdapter { - - private final TableColumn fTableColumn; - private final TableViewer tableViewer; - private final int fColumnIndex; - private final ColumnViewerComparator viewerComparator; - - public ColumnSelectionAdapter(final TableColumn column, final TableViewer tableViewer, final int index, - final ColumnViewerComparator vc) { - fTableColumn = column; - this.tableViewer = tableViewer; - fColumnIndex = index; - viewerComparator = vc; - } - - @Override - public void widgetSelected(@Nullable final SelectionEvent e) { - viewerComparator.setColumn(fColumnIndex); - final int dir = viewerComparator.getDirection(); - final Table table = tableViewer.getTable(); - table.setSortDirection(dir); - table.setSortColumn(fTableColumn); - tableViewer.refresh(); - } -} diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java deleted file mode 100644 index 1be8af4df..000000000 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/widgets/ColumnViewerComparator.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2015-2017 Angelo ZERR. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - */ -package org.eclipse.tm4e.languageconfiguration.internal.widgets; - -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; - -/** - * Viewer compoarator which sort a given column. - * - */ -public final class ColumnViewerComparator extends ViewerComparator { - - private int fSortColumn = 0; - private int fSortOrder = 1; // 1 = asc, -1 = desc - - /** - * Returns the {@linkplain SWT} style constant for the sort direction. - * - * @return {@link SWT#DOWN} for asc sorting, {@link SWT#UP} otherwise - */ - public int getDirection() { - return fSortOrder == 1 ? SWT.DOWN : SWT.UP; - } - - /** - * Sets the sort column. If the newly set sort column equals the previous set - * sort column, the sort direction changes. - * - * @param column New sort column - */ - public void setColumn(final int column) { - if (column == fSortColumn) { - fSortOrder *= -1; - } else { - fSortColumn = column; - fSortOrder = 1; - } - } - - @Override - public int compare(@Nullable final Viewer viewer, @Nullable final Object e1, @Nullable final Object e2) { - if (viewer instanceof final TableViewer tableViewer) { - final IBaseLabelProvider baseLabel = tableViewer.getLabelProvider(); - final String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); - final String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); - final int sortResult = getComparator() - .compare(left != null ? left : "", right != null ? right : ""); //$NON-NLS-1$ //$NON-NLS-2$ - return sortResult * fSortOrder; - } - return super.compare(viewer, e1, e2); - } -} diff --git a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF index bbacd72a4..73a889825 100644 --- a/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui/META-INF/MANIFEST.MF @@ -15,14 +15,15 @@ Require-Bundle: org.eclipse.core.expressions, org.eclipse.ui.trace;resolution:=optional, org.eclipse.ui.workbench.texteditor, org.eclipse.e4.ui.css.swt.theme, - org.eclipse.tm4e.core;bundle-version="0.6.1", - org.eclipse.tm4e.registry;bundle-version="0.6.4", + org.eclipse.tm4e.core;bundle-version="0.6.2", + org.eclipse.tm4e.registry;bundle-version="0.6.6", com.google.gson;bundle-version="[2.10.1,3.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-17 Export-Package: org.eclipse.tm4e.ui, org.eclipse.tm4e.ui.internal.model;x-friends:="org.eclipse.tm4e.languageconfiguration,org.eclipse.tm4e.ui.tests", org.eclipse.tm4e.ui.internal.themes;x-friends:="org.eclipse.tm4e.ui.tests", org.eclipse.tm4e.ui.internal.utils;x-friends:="org.eclipse.tm4e.ui.tests,org.eclipse.tm4e.languageconfiguration", + org.eclipse.tm4e.ui.internal.widgets;x-friends:="org.eclipse.tm4e.languageconfiguration", org.eclipse.tm4e.ui.model, org.eclipse.tm4e.ui.text, org.eclipse.tm4e.ui.themes, diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index e04f35314..ee53e65f2 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -210,19 +210,19 @@ private void createGrammarListContent(final Composite parent) { column1.setText(TMUIMessages.GrammarPreferencePage_column_scopeName); int minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_scopeName); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - column1.addSelectionListener(new ColumnSelectionAdapter(column1, grammarViewer, 0, viewerComparator)); + column1.addSelectionListener(new ColumnSelectionAdapter(grammarViewer, viewerComparator)); final var column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.GrammarPreferencePage_column_path); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); - column2.addSelectionListener(new ColumnSelectionAdapter(column2, grammarViewer, 1, viewerComparator)); + column2.addSelectionListener(new ColumnSelectionAdapter(grammarViewer, viewerComparator, 0)); final var column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.GrammarPreferencePage_column_pluginId); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.GrammarPreferencePage_column_pluginId); columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true)); - column3.addSelectionListener(new ColumnSelectionAdapter(column3, grammarViewer, 2, viewerComparator)); + column3.addSelectionListener(new ColumnSelectionAdapter(grammarViewer, viewerComparator, 0)); gc.dispose(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TaskTagsPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TaskTagsPreferencePage.java index b00a8056d..beb4267c0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TaskTagsPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/TaskTagsPreferencePage.java @@ -247,17 +247,17 @@ public Object[] getElements(final @Nullable Object inputElement) { final var column1 = new TableColumn(table, SWT.NONE); column1.setText(TMUIMessages.TaskTagsPreferencePage_column_tag); column1.setWidth(computeMinimumColumnWidth("1234567890")); - column1.addSelectionListener(new ColumnSelectionAdapter(column1, markerConfigsTable, 0, tableColumnSorter)); + column1.addSelectionListener(new ColumnSelectionAdapter(markerConfigsTable, tableColumnSorter)); final var column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.TaskTagsPreferencePage_column_type); column2.setWidth(column1.getWidth()); - column2.addSelectionListener(new ColumnSelectionAdapter(column2, markerConfigsTable, 1, tableColumnSorter)); + column2.addSelectionListener(new ColumnSelectionAdapter(markerConfigsTable, tableColumnSorter, 0)); final var column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.TaskTagsPreferencePage_column_level); column3.setWidth(column1.getWidth()); - column3.addSelectionListener(new ColumnSelectionAdapter(column3, markerConfigsTable, 2, tableColumnSorter)); + column3.addSelectionListener(new ColumnSelectionAdapter(markerConfigsTable, tableColumnSorter, 0)); // Specify default sorting table.setSortColumn(column1); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index 491494cfd..653a25703 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -157,19 +157,19 @@ private void createThemesTableContent(final Composite parent) { column1.setText(TMUIMessages.ThemePreferencePage_column_name); int minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_name); columnLayout.setColumnData(column1, new ColumnWeightData(2, minWidth, true)); - column1.addSelectionListener(new ColumnSelectionAdapter(column1, themesTable, 0, viewerComparator)); + column1.addSelectionListener(new ColumnSelectionAdapter(themesTable, viewerComparator)); final var column2 = new TableColumn(table, SWT.NONE); column2.setText(TMUIMessages.ThemePreferencePage_column_path); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_path); columnLayout.setColumnData(column2, new ColumnWeightData(2, minWidth, true)); - column2.addSelectionListener(new ColumnSelectionAdapter(column2, themesTable, 1, viewerComparator)); + column2.addSelectionListener(new ColumnSelectionAdapter(themesTable, viewerComparator, 0)); final var column3 = new TableColumn(table, SWT.NONE); column3.setText(TMUIMessages.ThemePreferencePage_column_pluginId); minWidth = computeMinimumColumnWidth(gc, TMUIMessages.ThemePreferencePage_column_pluginId); columnLayout.setColumnData(column3, new ColumnWeightData(2, minWidth, true)); - column3.addSelectionListener(new ColumnSelectionAdapter(column3, themesTable, 2, viewerComparator)); + column3.addSelectionListener(new ColumnSelectionAdapter(themesTable, viewerComparator, 0)); gc.dispose(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java index d0e6e5719..0bda95157 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnSelectionAdapter.java @@ -24,26 +24,37 @@ */ public final class ColumnSelectionAdapter extends SelectionAdapter { - private final TableColumn fTableColumn; private final TableViewer tableViewer; - private final int fColumnIndex; private final ColumnViewerComparator viewerComparator; + private final int[] secondarySortColumns; - public ColumnSelectionAdapter(final TableColumn column, final TableViewer tableViewer, final int index, - final ColumnViewerComparator vc) { - fTableColumn = column; + public ColumnSelectionAdapter(final TableViewer tableViewer, + final ColumnViewerComparator vc, int... secondarySortColumns) { this.tableViewer = tableViewer; - fColumnIndex = index; viewerComparator = vc; + this.secondarySortColumns = secondarySortColumns; } @Override public void widgetSelected(@Nullable final SelectionEvent e) { - viewerComparator.setColumn(fColumnIndex); - final int dir = viewerComparator.getDirection(); - final Table table = tableViewer.getTable(); - table.setSortDirection(dir); - table.setSortColumn(fTableColumn); - tableViewer.refresh(); + if (e != null && e.getSource() instanceof TableColumn tableColumn) { + int columnIndex = -1; + TableColumn[] columns = tableViewer.getTable().getColumns(); + for (int i = 0; i < columns.length; i++) { + if (columns[i].equals(tableColumn)) { + columnIndex = i; + break; + } + } + if (columnIndex == -1) + return; + + viewerComparator.setColumns(columnIndex, secondarySortColumns); + final int dir = viewerComparator.getDirection(); + final Table table = tableViewer.getTable(); + table.setSortDirection(dir); + table.setSortColumn(tableColumn); + tableViewer.refresh(); + } } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java index bd867da7e..524e8068c 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ColumnViewerComparator.java @@ -11,8 +11,9 @@ */ package org.eclipse.tm4e.ui.internal.widgets; +import static org.eclipse.tm4e.core.internal.utils.StringUtils.nullToEmpty; + import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; @@ -25,8 +26,8 @@ */ public final class ColumnViewerComparator extends ViewerComparator { - private int fSortColumn = 0; - private int fSortOrder = 1; // 1 = asc, -1 = desc + private int[] sortColumns = { 0 }; + private int sortOrder = 1; // 1 = ascending, -1 = descending /** * Returns the {@linkplain SWT} style constant for the sort direction. @@ -34,35 +35,40 @@ public final class ColumnViewerComparator extends ViewerComparator { * @return {@link SWT#DOWN} for asc sorting, {@link SWT#UP} otherwise */ public int getDirection() { - return fSortOrder == 1 ? SWT.DOWN : SWT.UP; + return sortOrder == 1 ? SWT.DOWN : SWT.UP; } /** * Sets the sort column. If the newly set sort column equals the previous * set sort column, the sort direction changes. * - * @param column + * @param primaryColumn * New sort column */ - public void setColumn(final int column) { - if (column == fSortColumn) { - fSortOrder *= -1; + public void setColumns(final int primaryColumn, int... secondaryColumns) { + if (primaryColumn == sortColumns[0]) { + sortOrder *= -1; } else { - fSortColumn = column; - fSortOrder = 1; + sortColumns = new int[secondaryColumns.length + 1]; + System.arraycopy(secondaryColumns, 0, sortColumns, 1, secondaryColumns.length); + sortColumns[0] = primaryColumn; + sortOrder = 1; } } @Override public int compare(@Nullable final Viewer viewer, @Nullable final Object e1, @Nullable final Object e2) { - if (viewer instanceof final TableViewer tableViewer) { - final IBaseLabelProvider baseLabel = tableViewer.getLabelProvider(); - - final String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn); - final String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn); - final int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : ""); - return sortResult * fSortOrder; + if (viewer instanceof final TableViewer tableViewer + && tableViewer.getLabelProvider() instanceof ITableLabelProvider labelProvider) { + for (var column : sortColumns) { + final String left = labelProvider.getColumnText(e1, column); + final String right = labelProvider.getColumnText(e2, column); + final int sortResult = getComparator().compare(nullToEmpty(left), nullToEmpty(right)); + if (sortResult != 0) + return sortResult * sortOrder; + } + return 0; } return super.compare(viewer, e1, e2);