1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.HashSet ; 17 import java.util.Hashtable ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.IConfigurationElement; 25 import org.eclipse.core.runtime.IExtensionPoint; 26 import org.eclipse.core.runtime.IStatus; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.core.runtime.Status; 29 import org.eclipse.debug.core.DebugPlugin; 30 import org.eclipse.debug.core.ILaunchConfiguration; 31 import org.eclipse.debug.core.ILaunchConfigurationType; 32 import org.eclipse.debug.core.ILaunchDelegate; 33 import org.eclipse.debug.core.ILaunchManager; 34 import org.eclipse.debug.core.ILaunchMode; 35 import org.eclipse.debug.internal.core.IConfigurationElementConstants; 36 import org.eclipse.debug.internal.ui.DebugUIPlugin; 37 import org.eclipse.debug.internal.ui.LaunchConfigurationTabExtension; 38 import org.eclipse.debug.ui.IDebugUIConstants; 39 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; 40 import org.eclipse.ui.PlatformUI; 41 import org.eclipse.ui.activities.IWorkbenchActivitySupport; 42 import org.eclipse.ui.activities.WorkbenchActivityHelper; 43 44 import com.ibm.icu.text.MessageFormat; 45 46 49 public class LaunchConfigurationPresentationManager { 50 51 54 private static LaunchConfigurationPresentationManager fgDefault; 55 56 64 private Hashtable fTabGroupExtensions; 65 66 74 private Hashtable fContributedTabs; 75 76 80 private LaunchConfigurationPresentationManager() { 81 fgDefault = this; 82 } 83 84 87 public static LaunchConfigurationPresentationManager getDefault() { 88 if (fgDefault == null) { 89 fgDefault = new LaunchConfigurationPresentationManager(); 90 } 91 return fgDefault; 92 } 93 94 98 private void initializeTabGroupExtensions() { 99 if(fTabGroupExtensions == null) { 100 fTabGroupExtensions = new Hashtable (); 101 IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_LAUNCH_CONFIGURATION_TAB_GROUPS); 102 IConfigurationElement[] groups = extensionPoint.getConfigurationElements(); 103 LaunchConfigurationTabGroupExtension group = null; 104 String typeId = null; 105 Map map = null; 106 List modes = null; 107 for (int i = 0; i < groups.length; i++) { 108 group = new LaunchConfigurationTabGroupExtension(groups[i]); 109 typeId = group.getTypeIdentifier(); 110 map = (Map )fTabGroupExtensions.get(typeId); 111 if (map == null) { 112 map = new Hashtable (); 113 fTabGroupExtensions.put(typeId, map); 114 } 115 modes = group.getModes(); 116 if(modes.isEmpty()) { 117 map.put("*", group); } 119 for(Iterator iter = modes.iterator(); iter.hasNext();) { 120 map.put(iter.next(), group); 121 } 122 } 123 } 124 } 125 126 132 private void initializeContributedTabExtensions() { 133 fContributedTabs = new Hashtable (); 134 IExtensionPoint epoint = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_LAUNCH_TABS); 135 IConfigurationElement[] elements = epoint.getConfigurationElements(); 136 LaunchConfigurationTabExtension tab = null; 137 Hashtable element = null; 138 for(int i = 0; i < elements.length; i++) { 139 tab = new LaunchConfigurationTabExtension(elements[i]); 140 element = (Hashtable ) fContributedTabs.get(tab.getTabGroupId()); 141 if(element == null) { 142 element = new Hashtable (); 143 element.put(tab.getIdentifier(), tab); 144 fContributedTabs.put(tab.getTabGroupId(), element); 145 } 146 element.put(tab.getIdentifier(), tab); 147 } 148 } 149 150 158 public ILaunchConfigurationTabGroup getTabGroup(ILaunchConfigurationType type, String mode) throws CoreException { 159 HashSet modes = new HashSet (); 160 modes.add(mode); 161 LaunchConfigurationTabGroupExtension ext = getExtension(type.getIdentifier(), modes); 162 if (ext == null) { 163 IStatus status = new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, 164 MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationPresentationManager_No_tab_group_defined_for_launch_configuration_type__0__3, (new String [] {type.getIdentifier()})), null); 165 throw new CoreException(status); 166 } 167 return new LaunchConfigurationTabGroupWrapper(ext.newTabGroup(), ext.getIdentifier(), null); 168 } 169 170 178 public ILaunchConfigurationTabGroup getTabGroup(ILaunchConfiguration config, String mode) throws CoreException { 179 HashSet modes = new HashSet (); 180 modes.add(mode); 181 LaunchConfigurationTabGroupExtension ext = getExtension(config.getType().getIdentifier(), modes); 182 if (ext == null) { 183 IStatus status = new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, 184 MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationPresentationManager_No_tab_group_defined_for_launch_configuration_type__0__3, (new String [] {config.getType().getIdentifier()})), null); 185 throw new CoreException(status); 186 } 187 return new LaunchConfigurationTabGroupWrapper(ext.newTabGroup(), ext.getIdentifier(), config); 188 } 189 190 199 protected LaunchConfigurationTabExtension[] getTabExtensions(String groupid, ILaunchConfiguration config, String mode) throws CoreException { 200 initializeContributedTabExtensions(); 201 Hashtable tabs = (Hashtable ) fContributedTabs.get(groupid); 202 if(tabs != null) { 203 return filterLaunchTabExtensions((LaunchConfigurationTabExtension[]) tabs.values().toArray(new LaunchConfigurationTabExtension[tabs.size()]), config, mode); 204 } 205 return new LaunchConfigurationTabExtension[0]; 206 } 207 208 224 protected LaunchConfigurationTabExtension[] filterLaunchTabExtensions(LaunchConfigurationTabExtension[] tabs, ILaunchConfiguration config, String mode) throws CoreException { 225 IWorkbenchActivitySupport as = PlatformUI.getWorkbench().getActivitySupport(); 226 if(as == null || config == null) { 227 return tabs; 228 } 229 HashSet set = new HashSet (); 230 for(int i = 0; i < tabs.length; i ++) { 231 if(!WorkbenchActivityHelper.filterItem(new LaunchTabContribution(tabs[i]))) { 233 HashSet modes = (HashSet ) config.getModes(); 235 modes.add(mode); 236 ILaunchDelegate delegate = config.getPreferredDelegate(modes); 237 if(delegate == null) { 238 delegate = config.getType().getPreferredDelegate(modes); 239 } 240 Set delegateSet = tabs[i].getDelegateSet(); 241 if(delegate != null) { 242 if(delegateSet.isEmpty() || delegateSet.contains(delegate.getId())) { 243 set.add(tabs[i]); 244 } 245 } 246 else { 247 ILaunchDelegate[] delegates = config.getType().getDelegates(modes); 249 for(int j = 0; j < delegates.length; j++) { 250 if(delegateSet.size() == 0 || delegateSet.contains(delegates[j].getId())) { 251 set.add(tabs[i]); 253 } 254 } 255 } 256 } 257 } 258 return (LaunchConfigurationTabExtension[]) set.toArray(new LaunchConfigurationTabExtension[set.size()]); 259 } 260 261 269 protected LaunchConfigurationTabGroupExtension getExtension(String type, Set modes) { 270 initializeTabGroupExtensions(); 271 Map map = (Map )fTabGroupExtensions.get(type); 272 if (map != null) { 273 Object extension = map.get(modes); 274 if (extension == null) { 275 extension = map.get("*"); } 278 return (LaunchConfigurationTabGroupExtension)extension; 279 } 280 return null; 281 } 282 283 294 public String getHelpContext(ILaunchConfigurationType type, String mode) throws CoreException { 295 HashSet modes = new HashSet (); 296 modes.add(mode); 297 LaunchConfigurationTabGroupExtension ext = getExtension(type.getIdentifier(), modes); 298 if (ext == null) { 299 IStatus status = new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, 300 MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationPresentationManager_No_tab_group_defined_for_launch_configuration_type__0__3, (new String [] {type.getIdentifier()})), null); 301 throw new CoreException(status); 302 } 303 return ext.getHelpContextId(); 304 } 305 306 314 public String getDescription(ILaunchConfigurationType configType, String mode) { 315 HashSet modes = new HashSet (); 316 modes.add(mode); 317 LaunchConfigurationTabGroupExtension extension = getExtension(configType.getAttribute(IConfigurationElementConstants.ID), modes); 318 return (extension != null ? extension.getDescription(modes) : null); 319 } 320 321 327 public List getLaunchModeNames(Set modes) { 328 List names = new ArrayList (); 329 Iterator iterator = modes.iterator(); 330 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 331 while (iterator.hasNext()) { 332 String id = (String ) iterator.next(); 333 ILaunchMode mode = manager.getLaunchMode(id); 334 if (mode == null) { 335 names.add(id); 336 } else { 337 names.add(DebugUIPlugin.removeAccelerators(mode.getLabel())); 338 } 339 } 340 Collections.sort(names); 341 return names; 342 } 343 344 350 public String getLaunchModeLabel(String modeid) { 351 String mode = null; 352 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 353 ILaunchMode lmode = manager.getLaunchMode(modeid); 354 if(lmode != null) { 355 return lmode.getLabel(); 356 } 357 return mode; 358 } 359 360 } 361 362 | Popular Tags |