|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2026 IBM Corporation and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * IBM Corporation - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.debug.internal.ui.launchConfigurations; |
| 15 | + |
| 16 | +import org.eclipse.debug.internal.ui.DebugUIPlugin; |
| 17 | +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; |
| 18 | +import org.eclipse.debug.ui.DebugUITools; |
| 19 | +import org.eclipse.debug.ui.IDebugUIConstants; |
| 20 | +import org.eclipse.jface.action.Action; |
| 21 | +import org.eclipse.jface.action.IAction; |
| 22 | +import org.eclipse.jface.preference.IPreferenceStore; |
| 23 | +import org.eclipse.jface.resource.ImageDescriptor; |
| 24 | +import org.eclipse.jface.viewers.TreeViewer; |
| 25 | +import org.eclipse.ui.model.WorkbenchViewerComparator; |
| 26 | + |
| 27 | +/** |
| 28 | + * provides the implementation for sorting the launch configurations within the |
| 29 | + * Launch Configuration Dialog |
| 30 | + * |
| 31 | + */ |
| 32 | +public class SortLaunchConfigurationAction extends Action { |
| 33 | + |
| 34 | + /** |
| 35 | + * Action identifier for IDebugView#getAction(String) |
| 36 | + */ |
| 37 | + public static final String ID_SORT_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_SORT_ACTION"; //$NON-NLS-1$ |
| 38 | + |
| 39 | + LaunchConfigurationFilteredTree fTree; |
| 40 | + |
| 41 | + public SortLaunchConfigurationAction(LaunchConfigurationFilteredTree tree) { |
| 42 | + super(LaunchConfigurationsMessages.SortLaunchConfigurationAction, IAction.AS_CHECK_BOX); |
| 43 | + fTree = tree; |
| 44 | + setChecked(DebugUIPlugin.getDefault().getPreferenceStore() |
| 45 | + .getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT)); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void run() { |
| 50 | + TreeViewer viewer = fTree.getViewer(); |
| 51 | + IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore(); |
| 52 | + boolean isSortByRecent = prefStore.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT); |
| 53 | + if (!isSortByRecent) { |
| 54 | + viewer.setComparator(new LaunchConfigurationComparator(fTree.getLaunchGroup().getIdentifier())); |
| 55 | + prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, true); |
| 56 | + } else { |
| 57 | + viewer.setComparator(new WorkbenchViewerComparator()); |
| 58 | + prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, false); |
| 59 | + } |
| 60 | + viewer.refresh(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String getDescription() { |
| 65 | + return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public ImageDescriptor getImageDescriptor() { |
| 70 | + return DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_LCL_DETAIL_PANE_HIDE); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String getToolTipText() { |
| 75 | + return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc; |
| 76 | + } |
| 77 | +} |
0 commit comments