11/*******************************************************************************
2- * Copyright (c) 2014, 2020 Red Hat Inc., and others
2+ * Copyright (c) 2014, 2026 Red Hat Inc., and others
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
1515 * Rüdiger Herrmann <ruediger.herrmann@gmx.de>
1616 * Patrik Suzzi <psuzzi@gmail.com> - Bug 500836
1717 * Lucas Bullen (Red Hat Inc.) - Bug 526490
18+ * IBM Corporation
1819 ******************************************************************************/
1920package org .eclipse .ui .internal .wizards .datatransfer ;
2021
8586import org .eclipse .swt .widgets .Link ;
8687import org .eclipse .swt .widgets .ToolBar ;
8788import org .eclipse .swt .widgets .ToolItem ;
89+ import org .eclipse .swt .widgets .TreeColumn ;
8890import org .eclipse .swt .widgets .TreeItem ;
8991import org .eclipse .ui .IWorkingSet ;
9092import org .eclipse .ui .PlatformUI ;
@@ -565,7 +567,7 @@ public CheckboxTreeViewer doCreateTreeViewer(Composite treeParent, int style) {
565567 };
566568 tree = (CheckboxTreeViewer ) filterTree .getViewer ();
567569 GridData treeGridData = new GridData (SWT .FILL , SWT .FILL , true , true );
568- treeGridData .heightHint = 90 ;
570+ treeGridData .heightHint = 150 ;
569571 tree .getControl ().setLayoutData (treeGridData );
570572 tree .setContentProvider (new ITreeContentProvider () {
571573 @ Override
@@ -589,12 +591,10 @@ public boolean hasChildren(Object element) {
589591 }
590592
591593 });
592- tree .setComparator (new ViewerComparator () {
593- @ Override
594- public int compare (Viewer v , Object o1 , Object o2 ) {
595- return ((File ) o1 ).getAbsolutePath ().compareTo (((File ) o2 ).getAbsolutePath ());
596- }
597- });
594+
595+ ProjectConfiguratorLabelProvider projectLP = new ProjectConfiguratorLabelProvider ();
596+ ImportsComparator comparator = new ImportsComparator (projectLP );
597+ tree .setComparator (comparator );
598598 tree .setCheckStateProvider (new ICheckStateProvider () {
599599 @ Override
600600 public boolean isGrayed (Object element ) {
@@ -625,10 +625,33 @@ public boolean isChecked(Object element) {
625625 tree .getTree ().getColumn (0 ).setText (DataTransferMessages .SmartImportProposals_folder );
626626 tree .getTree ().getColumn (0 ).setWidth (500 );
627627 ViewerColumn projectTypeColumn = new TreeViewerColumn (tree , SWT .NONE );
628- projectTypeColumn .setLabelProvider (new ProjectConfiguratorLabelProvider () );
628+ projectTypeColumn .setLabelProvider (projectLP );
629629 tree .getTree ().getColumn (1 ).setText (DataTransferMessages .SmartImportProposals_importAs );
630630 tree .getTree ().getColumn (1 ).setWidth (150 );
631+ TreeColumn folderCol = ((TreeViewerColumn ) pathColumn ).getColumn ();
632+ folderCol .addSelectionListener (new SelectionAdapter () {
633+ @ Override
634+ public void widgetSelected (SelectionEvent e ) {
635+ comparator .setColumn (0 );
636+ tree .getTree ().setSortColumn (folderCol );
637+ tree .getTree ().setSortDirection (comparator .getDirection ());
638+ tree .refresh ();
639+ }
640+ });
631641
642+ TreeColumn impAsCol = ((TreeViewerColumn ) projectTypeColumn ).getColumn ();
643+ impAsCol .addSelectionListener (new SelectionAdapter () {
644+ @ Override
645+ public void widgetSelected (SelectionEvent e ) {
646+ comparator .setColumn (1 );
647+ tree .getTree ().setSortColumn (impAsCol );
648+ tree .getTree ().setSortDirection (comparator .getDirection ());
649+ tree .refresh ();
650+ }
651+ });
652+ comparator .setColumn (0 );
653+ tree .getTree ().setSortColumn (folderCol );
654+ tree .getTree ().setSortDirection (SWT .UP );
632655 this .proposalSelectionDecorator = new ControlDecoration (tree .getTree (), SWT .TOP | SWT .LEFT );
633656 Image errorImage = FieldDecorationRegistry .getDefault ().getFieldDecoration (FieldDecorationRegistry .DEC_ERROR )
634657 .getImage ();
@@ -715,6 +738,55 @@ public void widgetSelected(SelectionEvent e) {
715738 return res ;
716739 }
717740
741+ private static final class ImportsComparator extends ViewerComparator {
742+ private int column = -1 ;
743+ private int direction = SWT .UP ;
744+ private final ProjectConfiguratorLabelProvider projectLP ;
745+
746+ public ImportsComparator (ProjectConfiguratorLabelProvider projectLP ) {
747+ this .projectLP = projectLP ;
748+ }
749+
750+ public void setColumn (int column ) {
751+ if (this .column == column ) {
752+ direction = (direction == SWT .UP ) ? SWT .DOWN : SWT .UP ;
753+ } else {
754+ this .column = column ;
755+ direction = SWT .UP ;
756+ }
757+ }
758+
759+ public int getDirection () {
760+ return direction ;
761+ }
762+
763+ @ Override
764+ public int compare (Viewer viewer , Object e1 , Object e2 ) {
765+ File f1 = (File ) e1 ;
766+ File f2 = (File ) e2 ;
767+
768+ int res = 0 ;
769+
770+ switch (column ) {
771+ case 0 :
772+ res = f1 .getAbsolutePath ().compareToIgnoreCase (f2 .getAbsolutePath ());
773+ break ;
774+
775+ case 1 :
776+ String t1 = getValue (projectLP .getText (f1 ));
777+ String t2 = getValue (projectLP .getText (f2 ));
778+ res = t1 .compareToIgnoreCase (t2 );
779+ break ;
780+ }
781+
782+ return direction == SWT .UP ? res : -res ;
783+ }
784+
785+ private String getValue (String s ) {
786+ return s == null ? "" : s ; //$NON-NLS-1$
787+ }
788+
789+ }
718790 protected boolean isExistingProject (File element ) {
719791 for (IProject project : ResourcesPlugin .getWorkspace ().getRoot ().getProjects ()) {
720792 IPath location = project .getLocation ();
0 commit comments