diff options
author | Darin Wright | 2003-10-27 21:51:57 +0000 |
---|---|---|
committer | Darin Wright | 2003-10-27 21:51:57 +0000 |
commit | 57742ebedf05a1eea09170da70e070af863434bf (patch) | |
tree | 3d8d2a76ac7d986c8bdab48aae4a5880a8b42e51 /org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java | |
parent | 6d32640e0f435541c4d81a6d0d228e253d02873f (diff) | |
download | eclipse.platform.debug-57742ebedf05a1eea09170da70e070af863434bf.tar.gz eclipse.platform.debug-57742ebedf05a1eea09170da70e070af863434bf.tar.xz eclipse.platform.debug-57742ebedf05a1eea09170da70e070af863434bf.zip |
Bug 44099 - organize favorites...
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java new file mode 100644 index 000000000..120722683 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.actions; + + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.ui.actions.SelectionListenerAction; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Adds the selected launch configuration to the launch favorites. + */ +public class AddToFavoritesAction extends SelectionListenerAction { + + private ILaunchConfiguration fConfiguration = null; + private String fMode =null; + private LaunchGroupExtension fGroup = null; + + /** + * Constructs a new action. + */ + public AddToFavoritesAction() { + super(""); //$NON-NLS-1$ + setEnabled(false); + WorkbenchHelp.setHelp(this, IDebugHelpContextIds.EDIT_LAUNCH_CONFIGURATION_ACTION); + } + + /** + * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + protected boolean updateSelection(IStructuredSelection selection) { + setLaunchConfiguration(null); + setMode(null); + if (selection.size() == 1) { + Object object = selection.getFirstElement(); + ILaunch launch = null; + if (object instanceof IAdaptable) { + launch = (ILaunch)((IAdaptable)object).getAdapter(ILaunch.class); + } + if (launch == null) { + if (object instanceof ILaunch) { + launch = (ILaunch)object; + } else if (object instanceof IDebugElement) { + launch = ((IDebugElement)object).getLaunch(); + } else if (object instanceof IProcess) { + launch = ((IProcess)object).getLaunch(); + } + } + if (launch != null) { + ILaunchConfiguration configuration = launch.getLaunchConfiguration(); + if (configuration != null) { + setLaunchConfiguration(configuration); + setMode(launch.getLaunchMode()); + setGroup(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configuration, getMode())); + setText(MessageFormat.format(ActionMessages.getString("AddToFavoritesAction.1"), new String[]{getGroup().getLabel()})); //$NON-NLS-1$ + } + } + } + + // Disable the action if the launch config is private + ILaunchConfiguration config = getLaunchConfiguration(); + if (config == null) { + return false; + } else { + if (DebugUITools.isPrivate(config)) { + return false; + } + } + + if (getGroup() != null) { + try { + List groups = config.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, (List)null); + if (groups != null) { + return !groups.contains(getGroup().getIdentifier()); + } + return true; + } catch (CoreException e) { + } + + } + + return false; + } + + protected void setLaunchConfiguration(ILaunchConfiguration configuration) { + fConfiguration = configuration; + } + + protected ILaunchConfiguration getLaunchConfiguration() { + return fConfiguration; + } + + protected void setMode(String mode) { + fMode = mode; + } + + protected String getMode() { + return fMode; + } + + protected void setGroup(LaunchGroupExtension group) { + fGroup = group; + } + + protected LaunchGroupExtension getGroup() { + return fGroup; + } + + /** + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + final CoreException[] ex = new CoreException[1]; + BusyIndicator.showWhile(DebugUIPlugin.getStandardDisplay(), new Runnable() { + public void run() { + try { + List list = getLaunchConfiguration().getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, (List)null); + if (list == null) { + list = new ArrayList(); + } + list.add(getGroup().getIdentifier()); + ILaunchConfigurationWorkingCopy copy = getLaunchConfiguration().getWorkingCopy(); + copy.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, list); + copy.doSave(); + setEnabled(false); + } catch (CoreException e) { + ex[0] = e; + } + } + }); + if (ex[0] != null) { + DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.getString("AddToFavoritesAction.2"), ActionMessages.getString("AddToFavoritesAction.3"), ex[0].getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + +} |