diff options
author | Michael Rennie | 2007-01-25 15:55:15 +0000 |
---|---|---|
committer | Michael Rennie | 2007-01-25 15:55:15 +0000 |
commit | c2e66ad7317314064d10282813f3ff2682fe2872 (patch) | |
tree | ff239fbbbe2c3a31301c5eedf263734b50dad9a0 | |
parent | ec3c90c691cfafab291246da23a5d063fe508aab (diff) | |
download | eclipse.platform.debug-c2e66ad7317314064d10282813f3ff2682fe2872.tar.gz eclipse.platform.debug-c2e66ad7317314064d10282813f3ff2682fe2872.tar.xz eclipse.platform.debug-c2e66ad7317314064d10282813f3ff2682fe2872.zip |
Bug 74480
[launching] Simplify the launch experience for less technical users of Eclipse
32 files changed, 2185 insertions, 146 deletions
diff --git a/org.eclipse.debug.ui/plugin.properties b/org.eclipse.debug.ui/plugin.properties index 861da32bd..f4524d050 100644 --- a/org.eclipse.debug.ui/plugin.properties +++ b/org.eclipse.debug.ui/plugin.properties @@ -27,6 +27,19 @@ ContextViewBindingsName=Context View Bindings BreakpointOrganizersName=Breakpoint Organizers VariableValueEditorsName=Variable Value Editors +ContextLaunchingRunMenu.name=&Run +ContextLaunchingRunMenu.tooltip=Run the selected item + +ContextLaunchingDebugMenu.name=&Debug +ContextLaunchingDebugMenu.tooltip=Debug the selected item + +ContextLaunchingProfileMenu.name=&Profile +ContextLaunchingProfileMenu.tooltip=Profile the selected item + +ContextualLaunchingPrefPage.name=Contextual Launching + +DefaultLaunchConfigurationsPropPage.name=Run/Debug Settings + BreakpointActionSet.label=Breakpoints CollapseAll.label=Collapse All CollapseAll.tooltip= Collapse All @@ -330,6 +343,7 @@ preferenceKeywords.viewManagement=views preferenceKeywords.perspective=perspectives switching assign automatic run debug preferenceKeywords.launchConfigurations=filters launch migration configurations run debug preferenceKeywords.launchDelegates=launch delegate duplicate run debug profile mode configuration launchers launcher modes +preferenceKeywords.contextLaunching=run debug profile launch contextual delegate configuration execute exportBreakpoints.label=E&xport Breakpoints... importBreakpoints.label=I&mport Breakpoints... diff --git a/org.eclipse.debug.ui/plugin.xml b/org.eclipse.debug.ui/plugin.xml index 1eb56d343..4d55e94b6 100644 --- a/org.eclipse.debug.ui/plugin.xml +++ b/org.eclipse.debug.ui/plugin.xml @@ -155,6 +155,15 @@ id="org.eclipse.debug.ui.launchDelegatesKeywords"> </keywordReference> </page> + <page + category="org.eclipse.debug.ui.DebugPreferencePage" + class="org.eclipse.debug.internal.ui.preferences.ContextLaunchingPreferencePage" + id="org.eclipse.debug.ui.contextualLaunchingPage" + name="%ContextualLaunchingPrefPage.name"> + <keywordReference + id="org.eclipse.debug.ui.contextLaunching"> + </keywordReference> + </page> </extension> <extension point="org.eclipse.ui.actionSets"> <actionSet @@ -382,12 +391,12 @@ menubarPath="org.eclipse.ui.run/runGroup"> </action> <action - label="%RunWithConfigurationAction.label" - style="pulldown" - helpContextId="run_with_configuration_action_context" class="org.eclipse.debug.internal.ui.actions.RunAsAction" + helpContextId="run_with_configuration_action_context" + id="org.eclipse.debug.internal.ui.actions.RunWithConfigurationAction" + label="%RunWithConfigurationAction.label" menubarPath="org.eclipse.ui.run/runGroup" - id="org.eclipse.debug.internal.ui.actions.RunWithConfigurationAction"> + style="pulldown"> </action> <action label="%RunHistoryMenuAction.label" @@ -874,7 +883,12 @@ id="org.eclipse.debug.ui.contextualLaunch.profile.submenu"> </action> <enablement> - <test property="org.eclipse.debug.ui.launchable" value="profile"/> + <and> + <test property="org.eclipse.debug.ui.launchable" value="profile"/> + <not> + <test property="org.eclipse.debug.ui.contextlaunch" /> + </not> + </and> </enablement> </objectContribution> <objectContribution @@ -889,7 +903,12 @@ id="org.eclipse.debug.ui.contextualLaunch.debug.submenu"> </action> <enablement> - <test property="org.eclipse.debug.ui.launchable" value="debug"/> + <and> + <test property="org.eclipse.debug.ui.launchable" value="debug"/> + <not> + <test property="org.eclipse.debug.ui.contextlaunch" /> + </not> + </and> </enablement> </objectContribution> <objectContribution @@ -904,10 +923,83 @@ id="org.eclipse.debug.ui.contextualLaunch.run.submenu"> </action> <enablement> - <test property="org.eclipse.debug.ui.launchable" value="run"/> + <and> + <test property="org.eclipse.debug.ui.launchable" value="run"/> + <not> + <test property="org.eclipse.debug.ui.contextlaunch" /> + </not> + </and> </enablement> </objectContribution> + <objectContribution + id="org.eclipse.debug.ui.contextlaunch.debugas" + objectClass="org.eclipse.core.runtime.IAdaptable"> + <action + class="org.eclipse.debug.internal.ui.contextlaunching.DebugContextLaunchingAction" + enablesFor="1" + icon="icons/full/etool16/debug_exc.gif" + id="org.eclipse.debug.ui.contextlaunch.debugas" + label="%ContextLaunchingDebugMenu.name" + menubarPath="additions" + tooltip="%ContextLaunchingDebugMenu.tooltip"> + </action> + <enablement> + <and> + <test + property="org.eclipse.debug.ui.resource" + /> + <test + property="org.eclipse.debug.ui.contextlaunch" + /> + <test property="org.eclipse.debug.ui.launchable" value="debug"/> + </and> + </enablement> + </objectContribution> + <objectContribution + id="org.eclipse.debug.ui.contextlaunch.profileas" + objectClass="org.eclipse.core.runtime.IAdaptable"> + <action + class="org.eclipse.debug.internal.ui.contextlaunching.ProfileContextLaunchingAction" + enablesFor="1" + icon="icons/full/etool16/profile_exc.gif" + id="org.eclipse.debug.ui.contextlaunch.profileas" + label="%ContextLaunchingProfileMenu.name" + menubarPath="additions" + tooltip="%ContextLaunchingProfileMenu.tooltip"> + </action> + <enablement> + <and> + <test + property="org.eclipse.debug.ui.resource" + /> + <test property="org.eclipse.debug.ui.contextlaunch" /> + <test property="org.eclipse.debug.ui.launchable" value="profile"/> + </and> + </enablement> + </objectContribution> <!-- console additions --> + <objectContribution + id="org.eclipse.debug.ui.contextlaunch.runas" + objectClass="org.eclipse.core.runtime.IAdaptable"> + <action + class="org.eclipse.debug.internal.ui.contextlaunching.RunContextLaunchingAction" + enablesFor="1" + icon="icons/full/etool16/run_exc.gif" + id="org.eclipse.debug.ui.contextlaunch.runas" + label="%ContextLaunchingRunMenu.name" + menubarPath="additions" + tooltip="%ContextLaunchingRunMenu.tooltip"> + </action> + <enablement> + <and> + <test property="org.eclipse.debug.ui.contextlaunch" /> + <test + property="org.eclipse.debug.ui.resource" + /> + <test property="org.eclipse.debug.ui.launchable" value="run"/> + </and> + </enablement> + </objectContribution> <viewerContribution targetID="org.eclipse.debug.ui.ProcessConsoleType.#ContextMenu" id="org.eclipse.debug.ui.processConsoleContextMenu"> @@ -1394,6 +1486,29 @@ </or> </enabledWhen> </page> + <page + class="org.eclipse.debug.internal.ui.preferences.RunDebugPropertiesPage" + id="org.eclipse.debug.ui.properties.defaultLaunchConfigurations" + name="%DefaultLaunchConfigurationsPropPage.name" + > + <enabledWhen> + <and> + <adapt + type="org.eclipse.core.resources.IResource"> + </adapt> + <test + property="org.eclipse.debug.ui.contextlaunch" + /> + <test + property="org.eclipse.debug.ui.contextlaunchable" + > + </test> + <test + property="org.eclipse.debug.ui.resource"> + </test> + </and> + </enabledWhen> + </page> </extension> <!-- commands and their bindings NOTE: @@ -2032,7 +2147,7 @@ M4 = Platform-specific fourth key </propertyTester> <propertyTester namespace="org.eclipse.debug.ui" - properties="launchable" + properties="launchable, resource, contextlaunch, contextlaunchable" type="java.lang.Object" class="org.eclipse.debug.internal.ui.actions.LaunchablePropertyTester" id="org.eclipse.debug.ui.propertyTesters.launchable"> @@ -2240,6 +2355,10 @@ M4 = Platform-specific fourth key id="org.eclipse.debug.ui.launchDelegatesKeywords" label="%preferenceKeywords.launchDelegates"> </keyword> + <keyword + id="org.eclipse.debug.ui.contextLaunching" + label="%preferenceKeywords.contextLaunching"> + </keyword> </extension> <extension point="org.eclipse.ui.importWizards"> diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java index 03585e4d5..9de5c5e39 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java @@ -26,9 +26,7 @@ public class DebugUIPreferenceInitializer extends AbstractPreferenceInitializer super(); } - /* - * (non-Javadoc) - * + /** * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() */ public void initializeDefaultPreferences() { @@ -51,6 +49,11 @@ public class DebugUIPreferenceInitializer extends AbstractPreferenceInitializer prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_BREAKPOINTS, true); prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_BREAKPOINTS_FROM_CONTAINER, true); + //contextual launching preference page + prefs.setDefault(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, false); + prefs.setDefault(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, MessageDialogWithToggle.PROMPT); + prefs.setDefault(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, MessageDialogWithToggle.PROMPT); + //View Management preference page prefs.setDefault(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES, IDebugUIConstants.ID_DEBUG_PERSPECTIVE); prefs.setDefault(IInternalDebugUIConstants.PREF_TRACK_VIEWS, true); @@ -111,10 +114,12 @@ public class DebugUIPreferenceInitializer extends AbstractPreferenceInitializer prefs.setDefault(IDebugUIConstants.PREF_DEFAULT_EBCDIC_CODE_PAGE, IDebugPreferenceConstants.DEFAULT_EBCDIC_CP); - if (MemoryViewUtil.isLinuxGTK()) + if (MemoryViewUtil.isLinuxGTK()) { prefs.setDefault(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM, false); - else + } + else { prefs.setDefault(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM, true); + } prefs.setDefault(IDebugPreferenceConstants.PREF_TABLE_RENDERING_PAGE_SIZE, IDebugPreferenceConstants.DEFAULT_PAGE_SIZE); prefs.setDefault(IDebugPreferenceConstants.PREF_RESET_MEMORY_BLOCK, IDebugPreferenceConstants.RESET_VISIBLE); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DefaultLabelProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DefaultLabelProvider.java index 584cd5084..881984db5 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DefaultLabelProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DefaultLabelProvider.java @@ -39,6 +39,7 @@ import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.core.model.IWatchExpression; import org.eclipse.debug.core.model.IWatchpoint; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.resource.ImageDescriptor; @@ -69,6 +70,9 @@ public class DefaultLabelProvider implements ILabelProvider { } return null; } + if(element instanceof LaunchShortcutExtension) { + return ((LaunchShortcutExtension)element).getImageDescriptor().createImage(); + } return DebugPluginImages.getImage(key); } @@ -155,7 +159,7 @@ public class DefaultLabelProvider implements ILabelProvider { DebugUIPlugin.log(e); return null; } - } + } } return null; } @@ -206,6 +210,8 @@ public class DefaultLabelProvider implements ILabelProvider { name = delegate.getContributorName(); } label.append(name); + } else if(element instanceof LaunchShortcutExtension) { + label.append(((LaunchShortcutExtension)element).getLabel()); } else if (element instanceof String) { label.append(element); } else { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java index 4f91d2736..8945c8516 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java @@ -86,6 +86,7 @@ public interface IDebugHelpContextIds { public static final String LAUNCH_CONFIGURATION_PREFERENCE_PAGE = PREFIX + "launch_configuration_preference_page_context"; //$NON-NLS-1$ public static final String VIEW_MANAGEMENT_PREFERENCE_PAGE = PREFIX + "view_management_preference_page_context"; //$NON-NLS-1$ public static final String LAUNCH_DELEGATES_PREFERENCE_PAGE = PREFIX + "launch_delegate_preference_page_context"; //$NON-NLS-1$ + public static final String CONTEXTUAL_LAUNCHING_PREFERENCE_PAGE = PREFIX + "contextual_launch_preference_page"; //$NON-NLS-1$ // Dialogs public static final String LAUNCH_CONFIGURATION_DIALOG = PREFIX + "launch_configuration_dialog"; //$NON-NLS-1$ @@ -112,10 +113,12 @@ public interface IDebugHelpContextIds { public static final String SELECT_LAUNCH_MODES_DIALOG = PREFIX + "select_launch_modes_dialog"; //$NON-NLS-1$ public static final String SELECT_LAUNCHERS_DIALOG = PREFIX + "select_launchers_dialog"; //$NON-NLS-1$ public static final String SELECT_RESOURCES_TO_SAVE_DIALOG = PREFIX + "select_resources_to_save_dialog"; //$NON-NLS-1$ + public static final String SELECT_LAUNCH_METHOD_DIALOG = PREFIX + "select_launch_method_dialog"; //$NON-NLS-1$ // Property pages public static final String PROCESS_PROPERTY_PAGE = PREFIX + "process_property_page_context"; //$NON-NLS-1$ public static final String PROCESS_PAGE_RUN_AT = PREFIX + "process_page_run_at_time_widget"; //$NON-NLS-1$ + public static final String DEFAULT_LAUNCHCONFIGURATION_PROPERTY_PAGE = PREFIX + "default_launchconfiguration_property_page"; //$NON-NLS-1$ // Launch configuration dialog pages public static final String LAUNCH_CONFIGURATION_DIALOG_COMMON_TAB = PREFIX + "launch_configuration_dialog_common_tab"; //$NON-NLS-1$ @@ -132,9 +135,5 @@ public interface IDebugHelpContextIds { //Editor public static final String NO_SOURCE_EDITOR = PREFIX + "debugger_editor_no_source_common";//$NON-NLS-1$ - - - - } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java index 4f4650305..c767cc431 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -131,7 +131,7 @@ public interface IInternalDebugUIConstants { public static final String IMG_ADD_SRC_DIR_WIZ = "IMG_ADD_SRC_DIRECTORY"; //$NON-NLS-1$ public static final String IMG_EDIT_SRC_DIR_WIZ = "IMG_EDIT_SRC_DIRECTORY"; //$NON-NLS-1$ - // internal preferenes + // internal preferences /** * XML for perspective settings - see PerspectiveManager. * @since 3.0 @@ -145,14 +145,14 @@ public interface IInternalDebugUIConstants { public static final String EMPTY_STRING = ""; //$NON-NLS-1$ /** - * Preference for enabling/disabling launch configuration filtering based on project accessibilty status + * Preference for enabling/disabling launch configuration filtering based on project accessibility status * * @since 3.2 */ public static final String PREF_FILTER_LAUNCH_CLOSED = IDebugUIConstants.PLUGIN_ID + ".PREF_FILTER_LAUNCH_CLOSED"; //$NON-NLS-1$ /** - * Preference for enabling/disabling launch configuraiton filtering based on project context + * Preference for enabling/disabling launch configuration filtering based on project context * * @since 3.2 */ @@ -172,7 +172,7 @@ public interface IInternalDebugUIConstants { public static final String PREF_FILTER_LAUNCH_TYPES = IDebugUIConstants.PLUGIN_ID + ".PREF_FILTER_LAUNCH_TYPES"; //$NON-NLS-1$ /** - * Preference that saves which launch configuration types have been checked on the Launch Configuraitons pref page + * Preference that saves which launch configuration types have been checked on the Launch Configurations pref page * @since 3.2 */ public static final String PREF_FILTER_TYPE_LIST = IDebugUIConstants.PLUGIN_ID + ".PREF_FILTER_TYPE_LIST"; //$NON-NLS-1$ @@ -202,6 +202,33 @@ public interface IInternalDebugUIConstants { public static final String DETAIL_PANE_FONT= "org.eclipse.debug.ui.DetailPaneFont"; //$NON-NLS-1$ /** + * Boolean preference indicating if contextual launch options should be visible + * to the user rather than the "run as" menu. + * + * @since 3.3 + * CONTEXTLAUNCHING + */ + public static final String PREF_USE_CONTEXTUAL_LAUNCH= IDebugUIConstants.PLUGIN_ID + ".UseContextualLaunch"; //$NON-NLS-1$ + + /** + * always/never/prompt preference indicating the action for the event when there is no context to launch during context launching + * + * @since 3.3 + * + * CONTEXTLAUNCHING + */ + public static final String PREF_ALWAYS_RUN_LAST_LAUNCH = IDebugUIConstants.PLUGIN_ID + ".AlwaysRunLastLaunch"; //$NON-NLS-1$ + + /** + * always/never/prompt preference indicating the action to take when an un-runnable file is the context + * + * @since 3.3 + * + * CONTEXTLAUNCHING + */ + public static final String PREF_ALWAYS_RUN_PROJECT_CONFIGURATION = IDebugUIConstants.PLUGIN_ID + ".ALwaysRunProjectConfiguration"; //$NON-NLS-1$ + + /** * String preference controlling whether editors are saved before launching. * Valid values are either "always", "never", or "prompt". * If "always" or "never", launching will save editors (or not) automatically. @@ -212,7 +239,7 @@ public interface IInternalDebugUIConstants { public static final String PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH = IDebugUIConstants.PLUGIN_ID + ".save_dirty_editors_before_launch"; //$NON-NLS-1$ /** - * Preference specifiying that all launches should be DEBUG_MODE if breakpoints exist in the workspace + * Preference specifying that all launches should be DEBUG_MODE if breakpoints exist in the workspace * @since 3.0 */ public static final String PREF_RELAUNCH_IN_DEBUG_MODE = IDebugUIConstants.PLUGIN_ID + ".relaunch_in_debug_mode"; //$NON-NLS-1$ @@ -341,7 +368,7 @@ public interface IInternalDebugUIConstants { /** * This constant is used as a "quick-fix" for the issue of breakpoint to working set - * persistance when the state of a project changes. + * persistence when the state of a project changes. * * @since 3.2 */ @@ -349,7 +376,7 @@ public interface IInternalDebugUIConstants { /** * This constant is used as a "quick-fix" for the issue of breakpoint to working set - * persistance when the state of a project changes. + * persistence when the state of a project changes. * * @since 3.2 */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchablePropertyTester.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchablePropertyTester.java index 30239c800..ebc402f38 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchablePropertyTester.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchablePropertyTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,8 +11,13 @@ package org.eclipse.debug.internal.ui.actions; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; import org.eclipse.debug.ui.actions.ILaunchable; /** @@ -20,16 +25,45 @@ import org.eclipse.debug.ui.actions.ILaunchable; */ public class LaunchablePropertyTester extends PropertyTester { - /* (non-Javadoc) + /** * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) */ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (property.equals("launchable")) { //$NON-NLS-1$ - if (DebugUIPlugin.getDefault().getLaunchConfigurationManager().launchModeAvailable((String)expectedValue)) { - return Platform.getAdapterManager().hasAdapter(receiver, ILaunchable.class.getName()); + if ("launchable".equals(property)) { //$NON-NLS-1$ + if (DebugUIPlugin.getDefault().getLaunchConfigurationManager().launchModeAvailable((String)expectedValue)) { + return Platform.getAdapterManager().hasAdapter(receiver, ILaunchable.class.getName()); + } + } + if("resource".equals(property)) { //$NON-NLS-1$ + IResource res = getResource(receiver); + if(res != null) { + return res.isAccessible(); } } + if("contextlaunch".equals(property)) { //$NON-NLS-1$ + return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH); + } + if("contextlaunchable".equals(property)) { //$NON-NLS-1$ + try { + return ContextRunner.getDefault().getLaunchShortcuts(getResource(receiver)).size() > 0 && ContextRunner.getDefault().isSharedConfig(receiver) == null; + } + catch (CoreException e) {return false;} + } return false; } + /** + * Returns the resource this property page is open on. + * + * @return resource + */ + protected IResource getResource(Object element) { + IResource resource = null; + if (element instanceof IResource) { + resource = (IResource) element; + } else if (element instanceof IAdaptable) { + resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class); + } + return resource; + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingAction.java new file mode 100644 index 000000000..4e18b69a7 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingAction.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; + +/** + * A universal context launching action for popup menus. + * This action gets its immediate context from what was right-clicked + * on to present the action. + * + * @see {@link ContextRunner} + * @see {@link IActionDelegate2} + * @see {@link RunContextLaunchingAction} + * @see {@link DebugContextLaunchingAction} + * @see {@link ProfileContextLaunchingAction} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class ContextLaunchingAction implements IActionDelegate2 { + + /** + * the mode the action is created on + */ + private String fMode = null; + + /** + * Constructor + * @param mode + */ + public ContextLaunchingAction(String mode) { + fMode = mode; + } + + /** + * @see org.eclipse.ui.IActionDelegate2#dispose() + */ + public void dispose() {} + + /** + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init(IAction action) {} + + /** + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) + */ + public void runWithEvent(IAction action, Event event) { + ContextRunner.getDefault().launch(fMode); + } + + /** + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + //not called + } + + /** + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) {} +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingToolbarAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingToolbarAction.java new file mode 100644 index 000000000..db7c9b913 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingToolbarAction.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +/** + * A wrapper class for a context launching toolbar action + * + * @see {@link ContextRunner} + * @see {@link ContextLaunchingAction} + * @see {@link Action} + * @see {@link IWorkbenchWindowActionDelegate} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class ContextLaunchingToolbarAction extends Action implements IWorkbenchWindowActionDelegate { + + /** + * The mode this action applies to + */ + private String fMode = null; + + /** + * Constructor + * @param id + */ + public ContextLaunchingToolbarAction(String id) { + LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(id); + if (extension != null) { + fMode = extension.getMode(); + setText(extension.getLabel()); + setImageDescriptor(extension.getImageDescriptor()); + } + } + + /** + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() {} + + /** + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) {} + + /** + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) {} + + /** + * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) + */ + public void runWithEvent(Event event) { + ContextRunner.getDefault().launch(fMode); + } + + /** + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + //do nothing + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java new file mode 100644 index 000000000..66cfd492f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java @@ -0,0 +1,31 @@ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.osgi.util.NLS; + +/** + * NLS'd messages for context launching artifacts + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class ContextMessages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.contextlaunching.ContextMessages"; //$NON-NLS-1$ + + public static String ContextRunner_0; + public static String ContextRunner_1; + public static String ContextRunner_2; + public static String ContextRunner_3; + public static String ContextRunner_4; + public static String ContextRunner_5; + public static String ContextRunner_6; + + public static String ContextRunner_7; + public static String OpenLaunchDialogAction_0; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, ContextMessages.class); + } + + private ContextMessages() { + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties new file mode 100644 index 000000000..df1c01a55 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties @@ -0,0 +1,9 @@ +ContextRunner_0=Unable To Launch +ContextRunner_1=There is no way to launch the currently selected context, would you like to run the last thing you launched? +ContextRunner_2=Always perform this action +ContextRunner_3=Not Runnable +ContextRunner_4={0} is not runnable, would you like to check its'' parent project for a way to run it? (pressing Cancel will end the attempt to launch)? +ContextRunner_5=Cannot Launch +ContextRunner_6=Neither the selected resource or its'' associated project are launchable. +ContextRunner_7=The current context cannot be launched, and there are no recent launches. +OpenLaunchDialogAction_0=Open {0} Dialog diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java new file mode 100644 index 000000000..5eac6c75c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java @@ -0,0 +1,490 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchListener; +import org.eclipse.debug.internal.core.LaunchManager; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchGroup; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; + +import com.ibm.icu.text.MessageFormat; + +/** + * Static runner for context launching to provide the base capability of context + * launching to more than one form of action (drop down, toolbar, view, etc) + * + * @see {@link ContextLaunchingAction} + * @see {@link ContextLaunchingToolbarAction} + * @see {@link ILaunchListener} + * @see {@link org.eclipse.debug.core.ILaunchManager} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class ContextRunner implements ILaunchListener { + + private static ContextRunner fgInstance = null; + + /** + * Returns the singleton instance of <code>ContextRunner</code> + * @return the singleton instance of <code>ContextRunner</code> + */ + public static ContextRunner getDefault() { + if(fgInstance == null) { + fgInstance = new ContextRunner(); + } + return fgInstance; + } + + /** + * The underlying resource that is derived from the object context of the + * run(Object, String) method + */ + private IResource fBackingResource = null; + private boolean fMakeResourceDefault = false; + private boolean fMakeProjectDefault = false; + + /** + * Performs the context launching given the object context and the mode to launch in. + * @param mode the mode to launch in + */ + public void launch(String mode) { + try { + Object context = getCurrentContext(); + ILaunchConfiguration config = isSharedConfig(context); + if(config != null) { + DebugUITools.launch(config, mode); + return; + } + config = isSharedConfigEditorInput(context); + if(config != null) { + DebugUITools.launch(config, mode); + return; + } + if(context instanceof IAdaptable) { + IAdaptable adapt = (IAdaptable) context; + //try to get the ILaunchConfiguration adapter first + config = (ILaunchConfiguration) adapt.getAdapter(ILaunchConfiguration.class); + if(config != null) { + DebugUITools.launch(config, mode); + return; + } + else { + //try to get the resource adapter from the context + IResource resource = (IResource) adapt.getAdapter(IResource.class); + if(resource != null) { + fBackingResource = resource; + config = getLaunchManager().getDefaultConfiguration(resource); + if(config != null && config.exists()) { + //the default config is available + DebugUITools.launch(config, mode); + return; + } + else { + //there is no default config + getLaunchManager().setDefaultConfiguration(resource, null); + selectAndLaunch(fBackingResource, mode); + return; + } + } + else { + handleUnknownContext(mode); + } + } + } + else { + handleUnknownContext(mode); + } + } + catch(CoreException ce) {DebugUIPlugin.log(ce);} + } + + /** + * Handles the case where the context is unknown: Meaning that nothing can be launched. + * @param mode the mode + */ + protected void handleUnknownContext(String mode) { + ILaunchConfiguration config = getLastLaunch(mode); + if(config == null) { + MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); + } + else { + String prompt = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH); + if(MessageDialogWithToggle.PROMPT.equals(prompt)) { + MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, + ContextMessages.ContextRunner_1, ContextMessages.ContextRunner_2, + false, null, null); + int ret = mdwt.getReturnCode(); + boolean checked = mdwt.getToggleState(); + if(ret == IDialogConstants.YES_ID) { + //get launch history for the given mode and do it + DebugUITools.launch(config, mode); + if(checked) { + DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, MessageDialogWithToggle.ALWAYS); + } + } + } + else if(MessageDialogWithToggle.ALWAYS.equals(prompt)) { + DebugUITools.launch(config, mode); + } + } + } + + /** + * Returns the last thing launched from the launch history + * @param mode the mode + * @return the last <code>ILaunchConfiguration</code> launched or <code>null</code> if none + */ + protected ILaunchConfiguration getLastLaunch(String mode) { + ILaunchGroup group = resolveLaunchGroup(mode); + if(group != null) { + LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(group.getIdentifier()); + if(history != null) { + return history.getRecentLaunch(); + } + } + return null; + } + + /** + * This method return if the editor input is from a shared java launch configuration file or not + * @param receiver the editor input to examine + * @return true if the editor input is from a shared launch configuration file, false otherwise. + */ + public ILaunchConfiguration isSharedConfigEditorInput(Object receiver) { + if(receiver instanceof IFileEditorInput) { + IFileEditorInput input = (IFileEditorInput) receiver; + return isSharedConfig(input.getFile()); + } + return null; + } + + /** + * Returns the launch group that corresponds to the specified mode + * @param mode the mode to find the launch group + * @return the launch group that corresponds to the specified mode + */ + protected ILaunchGroup resolveLaunchGroup(String mode) { + //TODO might not return the group we want + ILaunchGroup[] groups = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroups(); + for(int i = 0; i < groups.length; i++) { + if(groups[i].getMode().equals(mode) && groups[i].getCategory() == null) { + return groups[i]; + } + } + return null; + } + + /** + * Returns the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config + * @param receiver + * @return the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config + */ + public ILaunchConfiguration isSharedConfig(Object receiver) { + if(receiver instanceof IFile) { + IFile file = (IFile) receiver; + String ext = file.getFileExtension(); + if(ext == null) { + return null; + } + if(ext.equals("launch")) { //$NON-NLS-1$ + ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file); + if(config != null && config.exists()) { + return config; + } + } + } + return null; + } + + /** + * Prompts the user to select a way of launching the current resource, where a 'way' + * is defined as a launch shortcut, and returns if a launch took place + * @param adapt the adaptable type the specified resource was derived from + * @param resource + * @return if the context was launched in the given mode or not + * @throws CoreException + */ + protected boolean selectAndLaunch(IResource resource, String mode) throws CoreException { + boolean launched = false; + if(launchDefault(resource, mode)) { + return true; + } + List exts = getLaunchShortcuts(resource); + if(exts.size() == 1) { + //just launch it and set it as the default + LaunchShortcutExtension ext = (LaunchShortcutExtension) exts.get(0); + ext.launch(new StructuredSelection(resource), mode); + return true; + } + else if(exts.size() < 1) { + //prompt to try the parent containers + String prompt = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION); + if(MessageDialogWithToggle.ALWAYS.equals(prompt)) { + //go ahead and check + selectAndLaunch(resource.getProject(), mode); + } + else if(MessageDialogWithToggle.PROMPT.equals(prompt)) { + MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_3, + MessageFormat.format(ContextMessages.ContextRunner_4, new String[] {fBackingResource.getName()}), + ContextMessages.ContextRunner_2, false, null, null); + int ret = mdwt.getReturnCode(); + boolean checked = mdwt.getToggleState(); + if(ret == IDialogConstants.YES_ID) { + if(checked) { + DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, MessageDialogWithToggle.ALWAYS); + } + selectAndLaunch(resource.getProject(), mode); + } + } + return false; + } + else { + boolean project = resource instanceof IProject; + if(exts.isEmpty()) { + MessageDialog.openError(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_5, ContextMessages.ContextRunner_6); + } + else { + LaunchShortcutSelectionDialog dialog = new LaunchShortcutSelectionDialog(resource, mode, !project, project); + if (dialog.open() == Window.OK) { + Object[] result = dialog.getResult(); + if(result.length > 0) { + fMakeProjectDefault = dialog.makeProjectDefault(); + fMakeResourceDefault = dialog.makeDefault(); + if(fMakeProjectDefault || fMakeResourceDefault) { + getLaunchManager().addLaunchListener(this); + } + LaunchShortcutExtension method = (LaunchShortcutExtension) result[0]; + if(method != null) { + method.launch(new StructuredSelection(resource), mode); + } + } + } + } + } + return launched; + } + + /** + * Creates a listing of the launch shortcut extensions that are applicable to the underlying resource + * @param resource the underlying resource + * @return a listing of applicable launch shortcuts + * @throws CoreException + */ + public List getLaunchShortcuts(IResource resource) throws CoreException { + List list = new ArrayList(); + List sc = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts(); + List ctxt = new ArrayList(); + ctxt.add(resource); + IEvaluationContext context = new EvaluationContext(null, ctxt); + context.addVariable("selection", ctxt); //$NON-NLS-1$ + LaunchShortcutExtension ext = null; + for(Iterator iter = sc.iterator(); iter.hasNext();) { + ext = (LaunchShortcutExtension) iter.next(); + if(ext.evalEnablementExpression(context, ext.getContextualLaunchEnablementExpression())) { + if(!list.contains(ext)) { + list.add(ext); + } + } + } + return list; + } + + /** + * Returns the current context to be considered for launching. + * The returned object will be one of: + * <ol> + * <li>{@link IEditorInput}</li> + * <li>{@link Object}, where <i>object</i> is the first element in the selection obtained from the + * selection provider of the currently selected workbench part</li> + * </ol> + * @return the currently selected context to consider for launching, or <code>null</code>. + * + */ + public Object getCurrentContext() { + IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); + if(window != null) { + IWorkbenchPage page = window.getActivePage(); + if(page!= null) { + IWorkbenchPart part = page.getActivePart(); + if(part != null) { + if(part instanceof IEditorPart) { + return ((IEditorPart)part).getEditorInput(); + } + IWorkbenchPartSite site = part.getSite(); + if(site != null) { + ISelectionProvider provider = site.getSelectionProvider(); + if(provider != null) { + ISelection sel = provider.getSelection(); + if(sel instanceof IStructuredSelection) { + StructuredSelection ss = (StructuredSelection) sel; + if(ss.isEmpty()) { + return part; + } + else { + return ss.getFirstElement(); + } + } + else if(sel instanceof ITextSelection) { + return part; + } + return sel; + } + else { + //default to returning the part, which can be further queried for adapters + return part; + } + } + } + } + + } + return null; + } + + /** + * Returns the name of the currently selected context, or the empty string. + * This method can return null in the event the contributor of the selected context returns <code>null</code> + * as the resource name. + * @return the name of the currently selected context or the empty string. + */ + public String getContextName() { + Object o = getCurrentContext(); + ILaunchConfiguration config = isSharedConfig(o); + if(config != null) { + return config.getName(); + } + else { + config = isSharedConfigEditorInput(o); + if(config != null) { + return config.getName(); + } + else { + if(o instanceof IAdaptable) { + IAdaptable adapt = (IAdaptable) o; + Object a = adapt.getAdapter(ILaunchConfiguration.class); + if(a != null) { + return ((ILaunchConfiguration) a).getName(); + } + else { + a = adapt.getAdapter(IResource.class); + if(a != null) { + IResource res = (IResource) a; + return (res.isAccessible() ? res.getName() : ""); //$NON-NLS-1$ + } + } + } + } + } + return ""; //$NON-NLS-1$ + } + + /** + * Returns if context launching is enabled + * @return if context launching is enabled + */ + public static boolean isContextLaunchEnabled() { + return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH); + } + + /** + * Returns the launch manager + * @return the launch manager + */ + protected LaunchManager getLaunchManager() { + return (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); + } + + /** + * @see org.eclipse.debug.core.ILaunchListener#launchAdded(org.eclipse.debug.core.ILaunch) + */ + public void launchAdded(ILaunch launch) { + if(fBackingResource != null) { + try { + if(fMakeResourceDefault) { + getLaunchManager().setDefaultConfiguration(fBackingResource, launch.getLaunchConfiguration()); + } + if(fMakeProjectDefault) { + getLaunchManager().setDefaultConfiguration(fBackingResource.getProject(), launch.getLaunchConfiguration()); + } + getLaunchManager().removeLaunchListener(this); + fMakeProjectDefault = false; + fMakeResourceDefault = false; + } + catch(CoreException ce) {DebugUIPlugin.log(ce);} + } + } + + /** + * Handles launching the default launch configuration for the specified resource, if there is no default + * this method delegates to the <code>handleUnknownContext</code> method to figure out what to do + * @param res the resource to find the default configuration for + * @param mode the mode to launch it in + * @return true if the method launched something false otherwise + * @throws CoreException + */ + protected boolean launchDefault(IResource res, String mode) throws CoreException { + ILaunchConfiguration config = getLaunchManager().getDefaultConfiguration(res); + if(config != null && config.exists()) { + DebugUITools.launch(config, mode); + return true; + } + else { + return false; + } + } + + /** + * @see org.eclipse.debug.core.ILaunchListener#launchChanged(org.eclipse.debug.core.ILaunch) + */ + public void launchChanged(ILaunch launch) {} + + /** + * @see org.eclipse.debug.core.ILaunchListener#launchRemoved(org.eclipse.debug.core.ILaunch) + */ + public void launchRemoved(ILaunch launch) {} + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/DebugContextLaunchingAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/DebugContextLaunchingAction.java new file mode 100644 index 000000000..432282ed0 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/DebugContextLaunchingAction.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.debug.core.ILaunchManager; + +/** + * Specialization of <code>ContextLaunchingAction</code> for debug mode + * + * @see {@link ContextLaunchingAction} + * @see {@link ILaunchManager} + * @see {@link RunContextLaunchingAction} + * @see {@link ProfileContextLaunchingAction} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class DebugContextLaunchingAction extends ContextLaunchingAction { + + /** + * Constructor + */ + public DebugContextLaunchingAction() { + super(ILaunchManager.DEBUG_MODE); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ProfileContextLaunchingAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ProfileContextLaunchingAction.java new file mode 100644 index 000000000..9e6cfcb76 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ProfileContextLaunchingAction.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.debug.core.ILaunchManager; + +/** + * Specialization of <code>ContextLaunchingAction</code> for profile mode + * + * @see {@link ContextLaunchingAction} + * @see {@link ILaunchManager} + * @see {@link RunContextLaunchingAction} + * @see {@link DebugContextLaunchingAction} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class ProfileContextLaunchingAction extends ContextLaunchingAction { + + /** + * Constructor + */ + public ProfileContextLaunchingAction() { + super(ILaunchManager.PROFILE_MODE); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/RunContextLaunchingAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/RunContextLaunchingAction.java new file mode 100644 index 000000000..d9294c6ed --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/RunContextLaunchingAction.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contextlaunching; + +import org.eclipse.debug.core.ILaunchManager; + +/** + * Specialization of <code>ContextLaunchingAction</code> for run mode + * + * @see {@link ContextLaunchingAction} + * @see {@link ILaunchManager} + * @see {@link DebugContextLaunchingAction} + * @see {@link ProfileContextLaunchingAction} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class RunContextLaunchingAction extends ContextLaunchingAction { + + /** + * Constructor + */ + public RunContextLaunchingAction() { + super(ILaunchManager.RUN_MODE); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationComparator.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationComparator.java new file mode 100644 index 000000000..ba0fabc38 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationComparator.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.ui.model.WorkbenchViewerComparator; + +/** + * Groups configurations by type. + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class LaunchConfigurationComparator extends WorkbenchViewerComparator { + + /** + * the map of categories of <code>ILaunchConfigurationType</code>s to <code>Integer</code>s entries + */ + private static Map fgCategories; + + /** + * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object) + */ + public int category(Object element) { + Map map = getCategories(); + if (element instanceof ILaunchConfiguration) { + ILaunchConfiguration configuration = (ILaunchConfiguration) element; + try { + Integer i = (Integer) map.get(configuration.getType()); + if (i != null) { + return i.intValue(); + } + } catch (CoreException e) { + } + } + return map.size(); + } + + /** + * Returns the map of categories + * @return the map of categories + */ + private Map getCategories() { + if (fgCategories == null) { + fgCategories = new HashMap(); + List types = Arrays.asList(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes()); + Collections.sort(types, new Comparator() { + public int compare(Object o1, Object o2) { + ILaunchConfigurationType t1 = (ILaunchConfigurationType) o1; + ILaunchConfigurationType t2 = (ILaunchConfigurationType) o2; + return t1.getName().compareTo(t2.getName()); + } + + }); + Iterator iterator = types.iterator(); + int i = 0; + while (iterator.hasNext()) { + fgCategories.put(iterator.next(), new Integer(i)); + i++; + } + } + return fgCategories; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java index 65dc0d990..72337de3c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,6 +32,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ISaveContext; @@ -56,6 +58,7 @@ import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.internal.core.IConfigurationElementConstants; +import org.eclipse.debug.internal.core.LaunchManager; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; @@ -216,7 +219,7 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici /** * Returns a listing of <code>IlaunchDeleagtes</code> that does not contain any delegates from disabled activities * @param delegates the raw listing of delegates to filter - * @return the filtered listing of <code>ILaunchDelegate</code>s or an empty array, nevere <code>null</code>. + * @return the filtered listing of <code>ILaunchDelegate</code>s or an empty array, never <code>null</code>. * @since 3.3 * * EXPERIMENTAL @@ -311,7 +314,8 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici * @return the most recent, un-filtered launch */ public ILaunchConfiguration getFilteredLastLaunch(String groupId) { - LaunchHistory history = getLaunchHistory(groupId);if (history != null) { + LaunchHistory history = getLaunchHistory(groupId); + if (history != null) { ILaunchConfiguration[] filterConfigs = filterConfigs(history.getHistory()); if (filterConfigs.length > 0) { return filterConfigs[0]; @@ -352,7 +356,7 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici /** * Returns the history listing as XML - * @return the history loisting as XML + * @return the history listing as XML * @throws CoreException * @throws ParserConfigurationException * @throws TransformerException @@ -594,11 +598,52 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici } return fLaunchShortcuts; } + + /** + * Returns a listing of all of the <code>ILaunchConfigurationType</code>s that apply to the currently + * specified <code>IResource</code>. + * + * @param resource the resource context + * @return a listing of applicable <code>ILaunchConfigurationType</code>s, or an empty list, never <code>null</code> + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ + public List getApplicableConfigurationTypes(IResource resource) { + List types = new ArrayList(); + try { + List exts = getLaunchShortcuts(); + LaunchShortcutExtension ext = null; + List list = new ArrayList(); + list.add(resource); + IEvaluationContext context = new EvaluationContext(null, list); + context.addVariable("selection", list); //$NON-NLS-1$ + HashSet set = new HashSet(); + for(Iterator iter = exts.iterator(); iter.hasNext();) { + ext = (LaunchShortcutExtension) iter.next(); + if(ext.evalEnablementExpression(context, ext.getContextualLaunchEnablementExpression())) { + set.addAll(ext.getAssociatedConfigurationTypes()); + } + } + LaunchManager lm = (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfigurationType type = null; + for(Iterator iter = set.iterator(); iter.hasNext();) { + type = lm.getLaunchConfigurationType((String)iter.next()); + if(type != null) { + if(!types.contains(type) && type.isPublic() && !"org.eclipse.ui.externaltools.builder".equals(type.getCategory())) { //$NON-NLS-1$ + types.add(type); + } + } + } + } + catch(CoreException ce) {DebugUIPlugin.log(ce);} + return types; + } /** * Returns a listing of all applicable <code>LaunchShortcutExtension</code>s for the given * launch configuration type id. - * @param typeid the id of the launch configuraiton + * @param typeid the id of the launch configuration * @return a listing of <code>LaunchShortcutExtension</code>s that are associated with the specified launch configuration * type id or an empty list, never <code>null</code> * @@ -695,6 +740,7 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici * @since 3.3 * * EXPERIMENTAL + * CONTEXTLAUNCHING */ public LaunchShortcutExtension getLaunchShortcut(String id) { loadLaunchShortcuts(); @@ -800,6 +846,7 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici * @since 3.3 * * EXPERIMENTAL + * CONTEXTLAUNCHING */ public void setDefaultLaunchShortcut(IResource resource, LaunchShortcutExtension shortcut) throws CoreException { IProject project = resource.getProject(); @@ -826,12 +873,13 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici * * @see {@link ILaunchManager#getDefaultConfiguration(IResource)} * @param resource the resource - * @return the corresponding <code>LaunchShortcutExtension</code> for the guven <code>IResource</code>, + * @return the corresponding <code>LaunchShortcutExtension</code> for the given <code>IResource</code>, * or <code>null</code> if there is not one. * * @since 3.3 * * EXPERIMENTAL + * CONTEXTLAUNCHING */ public LaunchShortcutExtension getDefaultLaunchShortcut(IResource resource) { IProject project = resource.getProject(); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationPresentationManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationPresentationManager.java index 5aebe62f6..63fa2a01c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationPresentationManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationPresentationManager.java @@ -349,5 +349,22 @@ public class LaunchConfigurationPresentationManager { Collections.sort(names); return names; } + + /** + * Returns the label of the mode id with all accelerators removed + * @param modeid the id of the mode i.e. 'run' + * @return the formatted label of the specified mode id with all accelerators removed, or <code>null</code> if no label is available + * @since 3.3 + */ + public String getLaunchModeLabel(String modeid) { + String mode = null; + ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchMode lmode = manager.getLaunchMode(modeid); + if(lmode != null) { + return lmode.getLabel(); + } + return mode; + } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java index 623c9cefe..29878c97d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java @@ -360,7 +360,7 @@ public class LaunchConfigurationTabGroupViewer extends Viewer { /** * Creates some help text for the tab group launch types - * @param parent thep arent composite + * @param parent the parent composite * @since 3.2 */ private void createGettingStarted(Composite parent) { @@ -492,7 +492,14 @@ public class LaunchConfigurationTabGroupViewer extends Viewer { ILaunchConfigurationTab[] tabs = getTabs(); if (tabs != null) { // update the working copy from the active tab + boolean newwc = !getWorkingCopy().isDirty(); getActiveTab().performApply(getWorkingCopy()); + if(getOriginal() instanceof ILaunchConfigurationWorkingCopy && newwc) { + try { + getWorkingCopy().doSave(); + } + catch (CoreException e) {DebugUIPlugin.log(e);} + } updateButtons(); // update error ticks CTabItem item = null; @@ -948,6 +955,9 @@ public class LaunchConfigurationTabGroupViewer extends Viewer { if (workingCopy == null) { return false; } + if(workingCopy.getParent() != null) { + return !workingCopy.getParent().contentsEqual(workingCopy); + } // Working copy hasn't been saved if (workingCopy.getOriginal() == null) { return true; @@ -1111,7 +1121,7 @@ public class LaunchConfigurationTabGroupViewer extends Viewer { /** * Determines if the currently showing launch configuration has multiple launch delegates for the same mode set, but does not care * if there has been a default selected yet or not - * @return true if the current launch configuraiton has multiple launch delegates, false otherwise + * @return true if the current launch configuration has multiple launch delegates, false otherwise */ private boolean hasMultipleDelegates() { ILaunchConfiguration config = getWorkingCopy(); @@ -1354,8 +1364,8 @@ public class LaunchConfigurationTabGroupViewer extends Viewer { try { if(fTabGroup != null) { fTabGroup.initializeFrom(fOriginal); - fWorkingCopy = fOriginal.getWorkingCopy(); fNameWidget.setText(fOriginal.getName()); + fWorkingCopy = fOriginal.getWorkingCopy(); refreshStatus(); } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java index 9045cd019..96f7a6e10 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java @@ -851,7 +851,10 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun * @return the shell title */ protected String getShellTitle() { - String title = DebugUIPlugin.removeAccelerators(getLaunchGroup().getLabel()); + String title = null; + if(getLaunchGroup() != null) { + title = DebugUIPlugin.removeAccelerators(getLaunchGroup().getLabel()); + } if (title == null) { title = LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_Configurations_18; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java index 801cae778..2cb70d0e2 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java @@ -106,6 +106,14 @@ public class LaunchConfigurationsMessages extends NLS { public static String LaunchConfigurationTabGroupViewer_13; public static String LaunchConfigurationView_0; + + public static String LaunchShortcutSelectionDialog_0; + + public static String LaunchShortcutSelectionDialog_1; + + public static String LaunchShortcutSelectionDialog_2; + + public static String LaunchShortcutSelectionDialog_3; public static String PerspectiveManager_Error_1; public static String PerspectiveManager_Unable_to_switch_perpsectives_as_specified_by_launch___0__4; public static String PerspectiveManager_Unable_to_switch_to_perspective___0__2; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties index 852efb4ed..7e922e57a 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties @@ -102,6 +102,10 @@ PerspectiveManager_Error_1=Error PerspectiveManager_Unable_to_switch_perpsectives_as_specified_by_launch___0__4=Unable to open perspectives as specified by launch: {0} PerspectiveManager_Unable_to_switch_to_perspective___0__2=Unable to open perspective: {0} LaunchShortcutExtension_Error_4=Error +LaunchShortcutSelectionDialog_0={0} As... +LaunchShortcutSelectionDialog_1=&Select how to {0} {1}: +LaunchShortcutSelectionDialog_2=&Make generated settings the default for [{0}] +LaunchShortcutSelectionDialog_3=Ma&ke generated settings the default for project [{0}] LaunchShortcutExtension_Unable_to_use_launch_shortcut_5=Unable to use launch shortcut LaunchConfigurationPropertiesDialog_Edit_launch_configuration_properties_1=Edit launch configuration properties diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutSelectionDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutSelectionDialog.java new file mode 100644 index 000000000..e0af87df4 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutSelectionDialog.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchMode; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.DefaultLabelProvider; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.SWTUtil; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.ListDialog; + +import com.ibm.icu.text.MessageFormat; + +/** + * Specialized dialog for showing/selecting a specific launch shortcut extension, and allowing it + * to be marked to be set as the default + * + * @see {@link org.eclipse.debug.internal.ui.actions.ContextLaunchingAction} + * + * @since 3.3 + * EXPERIMENTAL + * CONTEXTLAUNCHING + */ +public class LaunchShortcutSelectionDialog extends ListDialog { + + private static final String DIALOG_SETTINGS = IDebugUIConstants.PLUGIN_ID + ".SELECT_LAUNCH_SHORTCUT_DIALOG"; //$NON-NLS-1$; + + /** + * The list of input for the dialog + */ + private String fMode = null; + private IResource fResource = null; + private boolean fChecked = false; + private boolean fProject = false; + private boolean fShowProject = false; + private boolean fShowResource = false; + + /** + * Constructor + * @param input + * @param resource + * @param mode + */ + public LaunchShortcutSelectionDialog(IResource resource, String mode, boolean showresource, boolean showproject) { + super(DebugUIPlugin.getShell()); + setShellStyle(getShellStyle() | SWT.RESIZE); + fResource = resource; + fMode = mode; + fShowProject = showproject; + fShowResource = showresource; + ILaunchMode lmode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(fMode); + String modename = fMode; + if (lmode != null) { + modename = DebugUIPlugin.removeAccelerators(lmode.getLabel()); + } + setTitle(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_0, new String[] {modename})); + setAddCancelButton(true); + setMessage(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_1, new String[] {fMode, fResource.getName()})); + setLabelProvider(new DefaultLabelProvider()); + setContentProvider(new ArrayContentProvider()); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + Composite comp = (Composite) super.createContents(parent); + PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugHelpContextIds.SELECT_LAUNCH_METHOD_DIALOG); + return comp; + } + + /** + * @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings() + */ + protected IDialogSettings getDialogBoundsSettings() { + IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); + IDialogSettings section = settings.getSection(DIALOG_SETTINGS); + if (section == null) { + section = settings.addNewSection(DIALOG_SETTINGS); + } + return section; + } + + /** + * @see org.eclipse.ui.dialogs.ListDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) + */ + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + getOkButton().setEnabled(false); + getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + getOkButton().setEnabled(!event.getSelection().isEmpty()); + } + }); + } + + /** + * @see org.eclipse.ui.dialogs.ListDialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite container) { + Composite comp = (Composite) super.createDialogArea(container); + try { + List input = new ArrayList(ContextRunner.getDefault().getLaunchShortcuts(fResource)); + Button butt = null; + if(!input.isEmpty()) { + if(fShowResource) { + butt = SWTUtil.createCheckButton(comp, MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_2, new String[] {fResource.getName()}), null, fChecked); + butt.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + fChecked = ((Button)e.getSource()).getSelection(); + } + }); + } + if(fShowProject) { + butt = SWTUtil.createCheckButton(comp, MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_3, new String[] {fResource.getProject().getName()}), null, false); + butt.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + fProject = ((Button)e.getSource()).getSelection(); + } + }); + } + } + getTableViewer().setInput(input); + } + catch(CoreException ce) {DebugUIPlugin.log(ce);} + return comp; + } + + /** + * Returns if the launched config from the selected shortcut should be made the default for the underlying resource + * @return if the launched config should be made the default + */ + public boolean makeDefault() { + return fChecked; + } + + /** + * Returns if the launched config from the selected shortcut should be made the default for the underlying resources' associated project + * @return if the launched config from the selected shortcut should be made the default for the underlying resources' associated project + */ + public boolean makeProjectDefault() { + return fProject; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ContextLaunchingPreferencePage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ContextLaunchingPreferencePage.java new file mode 100644 index 000000000..0e19f5a60 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ContextLaunchingPreferencePage.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.preferences; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.SWTUtil; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PlatformUI; + +/** + * A preference page for configuring launching preferences. + * + * @since 3.3 + */ +public class ContextLaunchingPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + /** + * a list of the field editors + */ + private List fFieldEditors; + + /** + * The default constructor + */ + public ContextLaunchingPreferencePage() { + super(); + setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore()); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + super.createControl(parent); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.CONTEXTUAL_LAUNCHING_PREFERENCE_PAGE); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + fFieldEditors = new ArrayList(); + Composite comp = SWTUtil.createComposite(parent, 1, 1, GridData.FILL_BOTH); + + SWTUtil.createWrapLabel(comp, DebugPreferencesMessages.ContextualLaunchPreferencePage_0, 1, 300); + SWTUtil.createVerticalSpacer(comp, 2); + //use contextual launch + FieldEditor edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, DebugPreferencesMessages.ContextualLaunchPreferencePage_1, comp); + fFieldEditors.add(edit); + + edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, DebugPreferencesMessages.ContextLaunchingPreferencePage_0, 3, + new String[][] {{DebugPreferencesMessages.LaunchingPreferencePage_3, MessageDialogWithToggle.ALWAYS}, + {DebugPreferencesMessages.LaunchingPreferencePage_5, MessageDialogWithToggle.PROMPT}}, + comp, true); + fFieldEditors.add(edit); + edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, DebugPreferencesMessages.ContextLaunchingPreferencePage_1, 3, + new String[][] {{DebugPreferencesMessages.LaunchingPreferencePage_7, MessageDialogWithToggle.ALWAYS}, + {DebugPreferencesMessages.LaunchingPreferencePage_9, MessageDialogWithToggle.PROMPT}}, + comp, true); + fFieldEditors.add(edit); + //init the field editors + FieldEditor editor; + for(int i = 0; i < fFieldEditors.size(); i++) { + editor = (FieldEditor)fFieldEditors.get(i); + editor.setPreferenceStore(getPreferenceStore()); + editor.load(); + } + return comp; + } + + /** + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + public void init(IWorkbench workbench) {} + + /** + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + protected void performDefaults() { + for(int i = 0; i < fFieldEditors.size(); i++) { + ((FieldEditor)fFieldEditors.get(i)).loadDefault(); + } + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + public boolean performOk() { + for(int i = 0; i < fFieldEditors.size(); i++) { + ((FieldEditor)fFieldEditors.get(i)).store(); + } + return super.performOk(); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java index 603068671..90aa91a29 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java @@ -32,6 +32,14 @@ public class DebugPreferencesMessages extends NLS { public static String ConsolePreferencePage_12; public static String ConsolePreferencePage_13; + public static String ContextLaunchingPreferencePage_0; + + public static String ContextLaunchingPreferencePage_1; + + public static String ContextualLaunchPreferencePage_0; + + public static String ContextualLaunchPreferencePage_1; + public static String DebugPreferencePage_1; public static String DebugPreferencePage_2; @@ -51,6 +59,32 @@ public class DebugPreferencesMessages extends NLS { public static String DebugPreferencePage_26; public static String DebugPreferencePage_27; + public static String DefaultLaunchConfigurationsPropertiesPage_0; + + public static String DefaultLaunchConfigurationsPropertiesPage_1; + + public static String DefaultLaunchConfigurationsPropertiesPage_10; + + public static String DefaultLaunchConfigurationsPropertiesPage_11; + + public static String DefaultLaunchConfigurationsPropertiesPage_12; + + public static String DefaultLaunchConfigurationsPropertiesPage_2; + + public static String DefaultLaunchConfigurationsPropertiesPage_3; + + public static String DefaultLaunchConfigurationsPropertiesPage_4; + + public static String DefaultLaunchConfigurationsPropertiesPage_5; + + public static String DefaultLaunchConfigurationsPropertiesPage_6; + + public static String DefaultLaunchConfigurationsPropertiesPage_7; + + public static String DefaultLaunchConfigurationsPropertiesPage_8; + + public static String DefaultLaunchConfigurationsPropertiesPage_9; + public static String LaunchDelegatesPreferencePage_0; public static String LaunchDelegatesPreferencePage_1; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties index 0cda21b10..a3483a05f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties @@ -16,6 +16,10 @@ ConsolePreferencePage_Standard_Error__3=Standard &Error text color: ConsolePreferencePage_Standard_In__4=Standard &In text color: ConsolePreferencePage_Standard_Out__2=Standard &Out text color: ConsolePreferencePage_Wrap_text_1=Fixed &width console +ContextualLaunchPreferencePage_0=This page is used to edit contextual launching options (EXPERIMENTAL). +ContextualLaunchPreferencePage_1=&Enable contextual launching. +ContextLaunchingPreferencePage_0=Launch previous when no context available +ContextLaunchingPreferencePage_1=Launch project of un-runnable context ConsolePreferencePage_Console_width=&Maximum character width: ConsolePreferencePage_Limit_console_output_1=&Limit console output ConsolePreferencePage_Console_buffer_size__characters___2=Console &buffer size (characters): @@ -127,3 +131,16 @@ LaunchDelegatesPreferencePage_0=Default Launcher LaunchDelegatesPreferencePage_4=Launcher Description LaunchPerspectivePreferencePage_0=There is no perspective information available to change. LaunchPerspectivePreferencePage_1=The selected types/launchers do not have any common mode sets. +DefaultLaunchConfigurationsPropertiesPage_0=This page allows you to select a default way to launch the currently selected resource. +DefaultLaunchConfigurationsPropertiesPage_1=&Select default configuration for {0}: +DefaultLaunchConfigurationsPropertiesPage_2=&New... +DefaultLaunchConfigurationsPropertiesPage_3=Create new launch configuration +DefaultLaunchConfigurationsPropertiesPage_4=Du&plicate +DefaultLaunchConfigurationsPropertiesPage_5=Duplicate selected launch configuration +DefaultLaunchConfigurationsPropertiesPage_6=&Edit... +DefaultLaunchConfigurationsPropertiesPage_7=Edit selected launch configuration +DefaultLaunchConfigurationsPropertiesPage_8=De&lete +DefaultLaunchConfigurationsPropertiesPage_9=Delete selected launch configuration +DefaultLaunchConfigurationsPropertiesPage_10=Configuration must be located in project {0} +DefaultLaunchConfigurationsPropertiesPage_11=Select Configuration Type +DefaultLaunchConfigurationsPropertiesPage_12=&Select the configuration type to create: diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/RunDebugPropertiesPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/RunDebugPropertiesPage.java new file mode 100644 index 000000000..2ccb2d592 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/RunDebugPropertiesPage.java @@ -0,0 +1,506 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.preferences; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.core.LaunchManager; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.DefaultLabelProvider; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.SWTUtil; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationComparator; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.ListDialog; +import org.eclipse.ui.dialogs.PropertyPage; + +import com.ibm.icu.text.MessageFormat; + +/** + * Displays default launch configuration settings for a selected resource - associated launch configurations. + * + * @see {@link PropertyPage} + * @see {@link ILaunchConfiguration} + * @see {@link org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog} + * @see {@link IDebugHelpContextIds#DEFAULT_LAUNCHCONFIGURATION_PROPERTY_PAGE} + * + * EXPERIMENTAL + * CONTEXTLAUNCHING + * + * @since 3.3 + */ +public class RunDebugPropertiesPage extends PropertyPage { + /** + * Set of configurations to be deleted + */ + private Set fDeletedConfigurations = new HashSet(); + + /** + * Set of original default candidates for the resource + */ + private Set fOriginalCandidates; + + /** + * List of the applicable launch config types for the backing resource + */ + private List fTypeCandidates = null; + + //widgets + private CheckboxTableViewer fViewer; + private Button fNewButton = null; + private Button fEditButton = null; + private Button fDuplicateButton = null; + private Button fDeleteButton = null; + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugHelpContextIds.DEFAULT_LAUNCHCONFIGURATION_PROPERTY_PAGE); + collectConfigCandidates(getResource()); + Composite topComposite = SWTUtil.createComposite(parent, 2, 1, GridData.FILL_BOTH); + + SWTUtil.createWrapLabel(topComposite, DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_0, 2, 300); + SWTUtil.createVerticalSpacer(topComposite, 2); + SWTUtil.createWrapLabel(topComposite, MessageFormat.format(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_1, new String[]{getResource().getName()}), 2, 300); + fViewer = createViewer(topComposite); + + Composite buttonComp = SWTUtil.createComposite(topComposite, 1, 1, GridData.FILL_VERTICAL); + GridLayout layout = (GridLayout) buttonComp.getLayout(); + layout.marginHeight = 0; + fNewButton = SWTUtil.createPushButton(buttonComp, DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_2, null); + fNewButton.setToolTipText(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_3); + fNewButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + handleNew(); + } + }); + + fDuplicateButton = SWTUtil.createPushButton(buttonComp, DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_4, null); + fDuplicateButton.setToolTipText(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_5); + fDuplicateButton.setEnabled(false); + fDuplicateButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + handleCopy(); + } + }); + fEditButton = SWTUtil.createPushButton(buttonComp, DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_6, null); + fEditButton.setToolTipText(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_7); + fEditButton.setEnabled(false); + fEditButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + handleEdit(); + } + }); + fDeleteButton = SWTUtil.createPushButton(buttonComp, DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_8, null); + fDeleteButton.setToolTipText(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_9); + fDeleteButton.setEnabled(false); + fDeleteButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + handleDelete(); + } + }); + + fViewer.setSelection(new StructuredSelection()); + applyDialogFont(topComposite); + return topComposite; + } + + /** + * Creates and returns the viewer that will display the possible default configurations. + * + * @param parent parent composite to create the viewer in + * @return viewer viewer that will display possible default configurations + */ + protected CheckboxTableViewer createViewer(Composite parent){ + CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + viewer.setLabelProvider(new DefaultLabelProvider()); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setComparator(new LaunchConfigurationComparator()); + viewer.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + if (event.getChecked()) { + fViewer.setCheckedElements(new Object[] {event.getElement()}); + } + else{ + fViewer.setCheckedElements(new Object[] {}); + } + } + }); + Table builderTable = viewer.getTable(); + GridData tableGridData = new GridData(GridData.FILL_BOTH); + tableGridData.heightHint = 300; + builderTable.setLayoutData(tableGridData); + + IResource resource = getResource(); + viewer.setInput(collectConfigCandidates(resource)); + try { + ILaunchConfiguration configuration = getLaunchManager().getDefaultConfiguration(resource); + if (configuration != null) { + Iterator iterator = fOriginalCandidates.iterator(); + while (iterator.hasNext()) { + ILaunchConfigurationWorkingCopy wc = (ILaunchConfigurationWorkingCopy) iterator.next(); + if (configuration.equals(wc.getOriginal())) { + viewer.setChecked(wc, true); + break; + } + } + } + } catch (CoreException e) {setErrorMessage(e.getMessage());} + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + boolean empty = event.getSelection().isEmpty(); + fEditButton.setEnabled(!empty); + fDuplicateButton.setEnabled(!empty); + fDeleteButton.setEnabled(!empty); + } + }); + + return viewer; + } + + /** + * Returns the viewer displaying possible default configurations. + * + * @return viewer + */ + protected CheckboxTableViewer getViewer() { + return fViewer; + } + + /** + * Returns the launch manager + * @return the launch manager + */ + protected LaunchManager getLaunchManager() { + return (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); + } + + /** + * Collects the applicable launch configuration types for the backing resource. + * Default implementation uses the launch shortcut evaluation expressions and leverages the + * mapping of launch shortcut to config type id to derive the applicable types. + * @return the listing of applicable launch configuration types for the backing resource + */ + protected List collectTypeCandidates() { + if(fTypeCandidates == null) { + fTypeCandidates = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getApplicableConfigurationTypes(getResource()); + Collections.sort(fTypeCandidates, new Comparator() { + public int compare(Object o1, Object o2) { + ILaunchConfigurationType t1 = (ILaunchConfigurationType) o1; + ILaunchConfigurationType t2 = (ILaunchConfigurationType) o2; + return t1.getName().compareTo(t2.getName()); + } + }); + } + return fTypeCandidates; + } + + /** + * Returns a set of potential default configurations candidates for the given + * resource. The configurations are working copies. + * + * @param resource resource + * @return list of default candidates + */ + protected Set collectConfigCandidates(IResource resource) { + if(fOriginalCandidates == null) { + fOriginalCandidates = new HashSet(); + IPath resourcePath = resource.getFullPath(); + try { + List types = collectTypeCandidates(); + List configs = new ArrayList(); + ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations(); + for(int i = 0; i < configurations.length; i++) { + if(types.contains(configurations[i].getType())) { + if(configurations[i].isMigrationCandidate()) { + configurations[i].migrate(); + } + configs.add(configurations[i]); + } + } + ILaunchConfiguration configuration = null; + IResource[] resources = null; + for (Iterator iter = configs.iterator(); iter.hasNext();) { + configuration = (ILaunchConfiguration) iter.next(); + if(acceptConfiguration(configuration)) { + if(configuration.contentsEqual(getLaunchManager().getDefaultConfiguration(resource))) { + fOriginalCandidates.add(configuration.getWorkingCopy()); + } + else { + resources = configuration.getMappedResources(); + if (resources != null) { + for (int j = 0; j < resources.length; j++) { + if (resource.equals(resources[j]) || resourcePath.isPrefixOf(resources[j].getFullPath())) { + fOriginalCandidates.add(configuration.getWorkingCopy()); + break; + } + } + } + else { + //in the event the config has no mapping + fOriginalCandidates.add(configuration.getWorkingCopy()); + } + } + } + } + } catch (CoreException e) { + fOriginalCandidates.clear(); + DebugPlugin.log(e); + } + } + return fOriginalCandidates; + } + + /** + * Returns if the specified configuration should be considered as a potential candidate + * @param config + * @return if the specified configuration should be considered as a potential candidate + * @throws CoreException + */ + private boolean acceptConfiguration(ILaunchConfiguration config) throws CoreException { + if(config != null && !DebugUITools.isPrivate(config)) { + if(!"org.eclipse.ui.externaltools".equals(config.getType().getCategory())) { //$NON-NLS-1$ + return true; + } + else { + IResource[] res = config.getMappedResources(); + if(res != null) { + return true; + } + } + } + return false; + } + + /** + * Returns the resource this property page is open on. + * + * @return resource + */ + protected IResource getResource() { + Object element = getElement(); + IResource resource = null; + if (element instanceof IResource) { + resource = (IResource) element; + } else if (element instanceof IAdaptable) { + resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class); + } + return resource; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + public boolean performOk() { + Object[] checked = fViewer.getCheckedElements(); + try { + ILaunchConfiguration def = null; + if (checked.length == 1) { + def = (ILaunchConfiguration) checked[0]; + def = ((ILaunchConfigurationWorkingCopy)def).doSave(); + } + DebugPlugin.getDefault().getLaunchManager().setDefaultConfiguration(getResource(), def); + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + return false; + } + //delete + Iterator iter = fDeletedConfigurations.iterator(); + while (iter.hasNext()) { + ILaunchConfigurationWorkingCopy currentConfig = (ILaunchConfigurationWorkingCopy) iter.next(); + try{ + if (currentConfig.getOriginal() != null){ + currentConfig.getOriginal().delete(); + } + } catch (CoreException e) { + DebugPlugin.logMessage("Problem deleting configuration " + currentConfig.getName(), e); //$NON-NLS-1$ + } + } + //add + iter = fOriginalCandidates.iterator(); + while (iter.hasNext()) { + ILaunchConfigurationWorkingCopy currentConfig = (ILaunchConfigurationWorkingCopy) iter.next(); + if (currentConfig.isDirty()){ + try{ + currentConfig.doSave(); + } catch (CoreException e) { + DebugPlugin.logMessage("Problem saving changes to configuration " + currentConfig.getName(), e); //$NON-NLS-1$ + } + } + } + + return super.performOk(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + protected void performDefaults() { + fViewer.setAllChecked(false); + setErrorMessage(null); + setValid(true); + super.performDefaults(); + } + + /** + * Returns the names of the launch configurations passed in as original input to the tree viewer + * @return the names of the original launch configurations + */ + private Set getConfigurationNames() { + Set names = new HashSet(); + Iterator iter = fOriginalCandidates.iterator(); + Object o = null; + while (iter.hasNext()) { + o = iter.next(); + if(o instanceof ILaunchConfiguration) { + names.add(((ILaunchConfiguration)o).getName()); + } + } + return names; + } + + /** + * Returns selected configurations. + * + * @return selected configurations + */ + private ILaunchConfigurationWorkingCopy[] getSelectedConfigurations() { + IStructuredSelection ss = (IStructuredSelection) fViewer.getSelection(); + return (ILaunchConfigurationWorkingCopy[]) ss.toList().toArray(new ILaunchConfigurationWorkingCopy[ss.size()]); + } + + /** + * Copy the selection + */ + private void handleCopy() { + ILaunchConfigurationWorkingCopy configuration = getSelectedConfigurations()[0]; + try { + ILaunchConfigurationWorkingCopy copy = configuration.copy( + ((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).generateUniqueLaunchConfigurationNameFrom(configuration.getName(), getConfigurationNames())); + copy.setAttributes(configuration.getAttributes()); + fOriginalCandidates.add(copy); + fViewer.refresh(); + fViewer.setSelection(new StructuredSelection(copy)); + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + } + } + + /** + * Delete the selection + */ + private void handleDelete() { + Table table = fViewer.getTable(); + int[] indices = table.getSelectionIndices(); + Arrays.sort(indices); + ILaunchConfiguration[] configurations = getSelectedConfigurations(); + for (int i = 0; i < configurations.length; i++) { + fDeletedConfigurations.add(configurations[i]); + fOriginalCandidates.remove(configurations[i]); + } + fViewer.refresh(); + if (indices[0] < table.getItemCount()) { + fViewer.setSelection(new StructuredSelection(table.getItem(indices[0]).getData())); + } else if (table.getItemCount() > 0) { + fViewer.setSelection(new StructuredSelection(table.getItem(table.getItemCount() - 1).getData())); + } + } + + /** + * Edit the selection + */ + private void handleEdit() { + edit(getSelectedConfigurations()[0]); + fViewer.refresh(); + } + + /** + * Edits the given configuration as a nested working copy. + * Returns the code from the dialog used to edit the configuration. + * + * @param configuration + * @return dialog return code - OK or CANCEL + */ + private int edit(ILaunchConfigurationWorkingCopy configuration) { + return DebugUIPlugin.openLaunchConfigurationPropertiesDialog(getShell(), configuration, IDebugUIConstants.ID_RUN_LAUNCH_GROUP, getConfigurationNames(), null); + } + + /** + * Create a new configuration + */ + private void handleNew() { + ListDialog dialog = new ListDialog(getShell()); + dialog.setTitle(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_11); + dialog.setContentProvider(new ArrayContentProvider()); + dialog.setLabelProvider(new DefaultLabelProvider()); + dialog.setAddCancelButton(true); + dialog.setMessage(DebugPreferencesMessages.DefaultLaunchConfigurationsPropertiesPage_12); + dialog.setInput(collectTypeCandidates()); + if (dialog.open() == Window.OK) { + Object[] result = dialog.getResult(); + if (result.length == 1) { + ILaunchConfigurationType type = (ILaunchConfigurationType) result[0]; + try { + ILaunchConfigurationWorkingCopy wc = type.newInstance(null, + ((LaunchManager)DebugPlugin.getDefault().getLaunchManager()). + generateUniqueLaunchConfigurationNameFrom("New_configuration", getConfigurationNames())); //$NON-NLS-1$ + if (edit(wc) == Window.OK) { + fOriginalCandidates.add(wc); + fViewer.refresh(); + fViewer.setSelection(new StructuredSelection(wc)); + } + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + } + } + } + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsolePageParticipant.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsolePageParticipant.java index 113d4cc8a..92788bf6d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsolePageParticipant.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsolePageParticipant.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java index 2bc1e3f4b..1472595ac 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.ILaunchHistoryChangedListener; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; import org.eclipse.jface.action.ActionContributionItem; @@ -183,18 +184,22 @@ public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPul */ protected String getToolTip(ILaunchConfiguration configuration) { String launchName= configuration.getName(); - String mode= getMode(); - String label; + String label = null; + //CONTEXTLAUNCHING + if(ContextRunner.isContextLaunchEnabled()) { + launchName = ContextRunner.getDefault().getContextName(); + } + String mode = getMode(); if (mode.equals(ILaunchManager.RUN_MODE)) { - label= ActionMessages.AbstractLaunchHistoryAction_1; + label = ActionMessages.AbstractLaunchHistoryAction_1; } else if (mode.equals(ILaunchManager.DEBUG_MODE)){ - label= ActionMessages.AbstractLaunchHistoryAction_2; + label = ActionMessages.AbstractLaunchHistoryAction_2; } else if (mode.equals(ILaunchManager.PROFILE_MODE)){ - label= ActionMessages.AbstractLaunchHistoryAction_3; + label = ActionMessages.AbstractLaunchHistoryAction_3; } else { - label= ActionMessages.AbstractLaunchHistoryAction_4; + label = ActionMessages.AbstractLaunchHistoryAction_4; } - return MessageFormat.format(ActionMessages.AbstractLaunchHistoryAction_0, new String[] {label, launchName}); + return MessageFormat.format(ActionMessages.AbstractLaunchHistoryAction_0, new String[] {label, launchName}); } /** @@ -337,6 +342,9 @@ public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPul if (fAction == null) { initialize(action); } + if(ContextRunner.isContextLaunchEnabled()) { + updateTooltip(); + } } /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java index 1cd7addf0..9afa51dbd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,8 @@ package org.eclipse.debug.ui.actions; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.contextlaunching.ContextLaunchingToolbarAction; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; import org.eclipse.debug.internal.ui.launchConfigurations.OrganizeFavoritesAction; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.action.IAction; @@ -54,8 +56,15 @@ public class AbstractLaunchToolbarAction extends AbstractLaunchHistoryAction { if (menu.getItemCount() > 0) { addSeparator(menu); } - - addToMenu(menu, new LaunchShortcutsAction(getLaunchGroupIdentifier()), -1); + //CONTEXTLAUNCHING + if(!getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$ + if(ContextRunner.isContextLaunchEnabled()) { + addToMenu(menu, new ContextLaunchingToolbarAction(getLaunchGroupIdentifier()), -1); + } + else { + addToMenu(menu, new LaunchShortcutsAction(getLaunchGroupIdentifier()), -1); + } + } addToMenu(menu, getOpenDialogAction(), -1); addToMenu(menu, new OrganizeFavoritesAction(getLaunchGroupIdentifier()), -1); } @@ -67,18 +76,24 @@ public class AbstractLaunchToolbarAction extends AbstractLaunchHistoryAction { protected IAction getOpenDialogAction() { return new OpenLaunchDialogAction(getLaunchGroupIdentifier()); } - + /** * Launch the last launch, or open the launch config dialog if none. * * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { - ILaunchConfiguration configuration = getLastLaunch(); - if (configuration == null) { - DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(), getLaunchGroupIdentifier()); - } else { - DebugUITools.launch(configuration, getMode()); + //CONTEXTLAUNCHING + if(ContextRunner.isContextLaunchEnabled()) { + ContextRunner.getDefault().launch(getMode()); + } + else { + ILaunchConfiguration configuration = getLastLaunch(); + if (configuration == null) { + DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(), getLaunchGroupIdentifier()); + } else { + DebugUITools.launch(configuration, getMode()); + } } } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java index 98b8c662b..b7f747b38 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,6 +28,7 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction; import org.eclipse.debug.internal.ui.actions.SharedLaunchConfigAction; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; import org.eclipse.debug.ui.DebugUITools; @@ -53,7 +54,7 @@ import org.eclipse.ui.activities.WorkbenchActivityHelper; * An action delegate that builds a context menu with applicable launch shortcuts * for a specific launch mode. * <p> - * This class can be subclassed and contributed as an object contribution pop-up + * This class can be sub-classed and contributed as an object contribution pop-up * menu extension action. When invoked, it becomes a sub-menu that dynamically * builds a list of applicable launch shortcuts for the current selection. * Each launch shortcut may have optional information to support a context menu action. @@ -167,49 +168,13 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I } action.setEnabled(false); } - - /** - * This method is used to determine if the selected object is in fact a shared launch - * configuration that can be launched - * @return true if the item is a shared ocnfig , false otherwise - * @since 3.3 - */ - private boolean isSharedConfig(Object receiver) { - if(receiver instanceof IFile) { - IFile file = (IFile) receiver; - String ext = file.getFileExtension(); - if(ext == null) { - return false; - } - if(ext.equals("launch")) { //$NON-NLS-1$ - ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file); - if(config != null && config.exists()) { - return true; - } - } - } - return false; - } - - /** - * This method return if the editor input is from a shared java launch configuration file or not - * @param receiver the editor input to examine - * @return true if the editor input is from a shared launch configuration file, false otherwise. - */ - private boolean isSharedConfigEditorInput(Object receiver) { - if(receiver instanceof IFileEditorInput) { - IFileEditorInput input = (IFileEditorInput) receiver; - return isSharedConfig(input.getFile()); - } - return false; - } /** * Returns the launch manager * @return the launch manager * @since 3.3 */ - private ILaunchManager getLaunchManager() { + protected ILaunchManager getLaunchManager() { return DebugPlugin.getDefault().getLaunchManager(); } @@ -240,27 +205,22 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I if (fSelection == null) { return; } - IEvaluationContext context = createContext(); - //add in any selected shared configs before the rest of the items to launch as //feature fix for + //CONTEXTLAUNCHING if(!fSelection.isEmpty()) { Object obj = fSelection.getFirstElement(); - if(isSharedConfig(obj)) { + if(ContextRunner.getDefault().isSharedConfig(obj) != null) { prepareSharedConfigAction((IFile)obj, menu); new MenuItem(menu, SWT.SEPARATOR); } - else if(isSharedConfigEditorInput(obj)) { + else if(ContextRunner.getDefault().isSharedConfigEditorInput(obj) != null) { prepareSharedConfigAction(((IFileEditorInput) obj).getFile(), menu); new MenuItem(menu, SWT.SEPARATOR); } } - - // gather all shortcuts and run their filters so that we only run the - // filters one time for each shortcut. Running filters can be expensive. - // Also, only *LOADED* plug-ins get their filters run. - List /* <LaunchShortcutExtension> */ allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts(); + List allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts(); Iterator iter = allShortCuts.iterator(); List filteredShortCuts = new ArrayList(10); while (iter.hasNext()) { @@ -269,9 +229,8 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I if (!WorkbenchActivityHelper.filterItem(ext) && isApplicable(ext, context)) { filteredShortCuts.add(ext); } - } catch (CoreException e) { - // not supported - } + } + catch (CoreException e) {DebugUIPlugin.log(e);} } iter = filteredShortCuts.iterator(); int accelerator = 1; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/OpenLaunchDialogAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/OpenLaunchDialogAction.java index 8c38edc0c..8835b8210 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/OpenLaunchDialogAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/OpenLaunchDialogAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,19 +16,28 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.contextlaunching.ContextMessages; +import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; +import com.ibm.icu.text.MessageFormat; + /** * Opens the launch configuration dialog in the context of a launch group. * <p> @@ -37,7 +46,7 @@ import org.eclipse.ui.PlatformUI; * </p> * @since 2.1 */ -public class OpenLaunchDialogAction extends Action implements IWorkbenchWindowActionDelegate { +public class OpenLaunchDialogAction extends Action implements IPropertyChangeListener, IActionDelegate2, IWorkbenchWindowActionDelegate { /** * Launch group identifier @@ -45,9 +54,9 @@ public class OpenLaunchDialogAction extends Action implements IWorkbenchWindowAc private String fIdentifier; /** - * The action used to render this delegate. + * The underlying <code>IAction</code> for this delegate */ - private IAction fAction; + private IAction fBackingAction = null; /** * Constructs an action that opens the launch configuration dialog in @@ -57,14 +66,9 @@ public class OpenLaunchDialogAction extends Action implements IWorkbenchWindowAc */ public OpenLaunchDialogAction(String identifier) { fIdentifier = identifier; - LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(identifier); - if (extension != null) { - setText(extension.getLabel() + "..."); //$NON-NLS-1$ - setImageDescriptor(extension.getImageDescriptor()); - } - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION); + updateActionState(); } - + /** * @see org.eclipse.jface.action.IAction#run() */ @@ -80,44 +84,59 @@ public class OpenLaunchDialogAction extends Action implements IWorkbenchWindowAc int result = DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, fIdentifier); notifyResult(result == Window.OK); } - /** - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() - */ - public void dispose() { - } - - /** - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) */ - public void init(IWorkbenchWindow window) { + public void runWithEvent(IAction action, Event event) { + run(); } - - /** + + /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { run(); } - + /** - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ - public void selectionChanged(IAction action, ISelection selection) { - if (fAction == null) { - initialize(action); - } + public void dispose() { + DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init(IAction action) { + fBackingAction = action; + DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION); + updateActionState(); } /** - * Set the enabled state of the underlying action based on whether there are any - * registered launch configuration types that understand how to launch in the - * mode of this action. + * Updates the action state (label and image descriptor) + * @since 3.3 + * CONTEXTLAUNCHING */ - private void initialize(IAction action) { - fAction = action; - action.setEnabled(existsConfigTypesForMode()); - } - + protected void updateActionState() { + LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier); + if(fBackingAction == null) { + //there is no backing action, like a toolbar action delegate + if(ContextRunner.isContextLaunchEnabled() && !"org.eclipse.ui.externaltools.launchGroup".equals(fIdentifier)) { //$NON-NLS-1$ + setText(MessageFormat.format(ContextMessages.OpenLaunchDialogAction_0, new String[] {extension.getLabel()})); + setImageDescriptor(null); + } + else { + setText(extension.getLabel() + "..."); //$NON-NLS-1$ + setImageDescriptor(extension.getImageDescriptor()); + } + setEnabled(existsConfigTypesForMode()); + } + } + /** * Return whether there are any registered launch configuration types for * the mode of this action. @@ -136,6 +155,25 @@ public class OpenLaunchDialogAction extends Action implements IWorkbenchWindowAc return false; } + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) {} + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + if (IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH.equals(event.getProperty())){ + updateActionState(); + } + } + + /** + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) {} + /** * Returns the launch mode for this action. * |