1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.text.MessageFormat ; 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationListener; 21 import org.eclipse.debug.core.ILaunchConfigurationType; 22 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 23 import org.eclipse.debug.core.ILaunchMode; 24 import org.eclipse.debug.internal.ui.DebugPluginImages; 25 import org.eclipse.debug.internal.ui.DebugUIPlugin; 26 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 27 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 28 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 29 import org.eclipse.debug.ui.DebugUITools; 30 import org.eclipse.debug.ui.IDebugUIConstants; 31 import org.eclipse.jface.dialogs.Dialog; 32 import org.eclipse.swt.SWT; 33 import org.eclipse.swt.events.ControlAdapter; 34 import org.eclipse.swt.events.ControlEvent; 35 import org.eclipse.swt.events.SelectionAdapter; 36 import org.eclipse.swt.events.SelectionEvent; 37 import org.eclipse.swt.graphics.Image; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Button; 41 import org.eclipse.swt.widgets.Combo; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Label; 44 import org.eclipse.ui.IPerspectiveDescriptor; 45 import org.eclipse.ui.IPerspectiveRegistry; 46 import org.eclipse.ui.PlatformUI; 47 48 51 public class PerspectivesTab extends AbstractLaunchConfigurationTab implements ILaunchConfigurationListener { 52 53 56 private ILaunchConfigurationType fType = null; 57 58 61 private String [] fModeIds = null; 62 63 66 private String [] fPerspectiveLabels = null; 67 68 71 private Map fPerspectiveIds = null; 72 73 76 private Combo[] fCombos = null; 77 78 private Button fRestoreDefaults; 79 80 83 private SelectionAdapter fSelectionAdapter= new SelectionAdapter() { 84 public void widgetSelected(SelectionEvent e) { 85 Object source= e.getSource(); 86 if (source == fRestoreDefaults) { 87 handleRestoreDefaultsSelected(); 88 } 89 updateLaunchConfigurationDialog(); 90 } 91 private void handleRestoreDefaultsSelected() { 92 for (int i = 0; i < fCombos.length; i++) { 93 String mode = (String )fCombos[i].getData(); 94 String def = DebugUIPlugin.getDefault().getPerspectiveManager().getDefaultLaunchPerspective(getLaunchConfigurationType(), mode); 95 if (def == null) { 96 fCombos[i].setText(LaunchConfigurationsMessages.PerspectivesTab_1); } else { 98 IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry(); 99 IPerspectiveDescriptor descriptor = registry.findPerspectiveWithId(def); 100 fCombos[i].setText(descriptor.getLabel()); 101 } 102 } 103 } 104 }; 105 106 110 private boolean fInitializing = false; 111 112 115 public void dispose() { 116 super.dispose(); 117 DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this); 118 } 119 120 123 public void launchConfigurationAdded(ILaunchConfiguration configuration) { 124 } 125 126 129 public void launchConfigurationChanged(ILaunchConfiguration configuration) { 130 if (!configuration.isWorkingCopy()) { 131 if (configuration.getName().startsWith(getLaunchConfigurationType().getIdentifier())) { 132 for (int i = 0; i < fModeIds.length; i++) { 133 String mode = fModeIds[i]; 134 try { 135 String persp = configuration.getAttribute(mode, (String )null); 136 if (persp == null) { 137 persp = IDebugUIConstants.PERSPECTIVE_DEFAULT; 139 } 140 DebugUITools.setLaunchPerspective(getLaunchConfigurationType(), mode, persp); 141 } catch (CoreException e) { 142 DebugUIPlugin.log(e); 143 } 144 } 145 } 146 } 147 } 148 149 152 public void launchConfigurationRemoved(ILaunchConfiguration configuration) { 153 } 154 155 160 public PerspectivesTab(ILaunchConfigurationType type) { 161 super(); 162 fType = type; 163 DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this); 164 } 165 166 169 public Image getImage() { 170 return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJS_PERSPECTIVE_TAB); 171 } 172 173 176 public void createControl(Composite parent) { 177 final Composite composite = new Composite(parent, SWT.NONE); 178 setControl(composite); 179 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_PERSPECTIVE_TAB); 180 final GridLayout layout = new GridLayout(2, false); 181 composite.setLayout(layout); 182 GridData gd = new GridData(GridData.FILL_BOTH); 183 composite.setLayoutData(gd); 184 composite.setFont(parent.getFont()); 185 186 Label label = new Label(composite, SWT.LEFT + SWT.WRAP); 187 label.setFont(parent.getFont()); 188 label.setText(MessageFormat.format(LaunchConfigurationsMessages.PerspectivesTab_0, new String []{getLaunchConfigurationType().getName()})); final GridData finalGd = new GridData(); 190 finalGd.horizontalSpan = 2; 191 label.setLayoutData(finalGd); 192 composite.addControlListener(new ControlAdapter(){ 193 public void controlResized(ControlEvent e){ 194 finalGd.widthHint = composite.getClientArea().width - 2*layout.marginWidth; 195 composite.layout(true); 196 } 197 }); 198 199 200 ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes(); 202 ArrayList supported = new ArrayList (); 203 for (int i = 0; i < modes.length; i++) { 204 ILaunchMode mode = modes[i]; 205 if (getLaunchConfigurationType().supportsMode(mode.getIdentifier())) { 206 supported.add(mode.getIdentifier()); 207 } 208 } 209 fModeIds = (String [])supported.toArray(new String [supported.size()]); 210 211 IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry(); 213 IPerspectiveDescriptor[] descriptors = registry.getPerspectives(); 214 fPerspectiveLabels = new String [descriptors.length + 1]; 215 fPerspectiveLabels[0] = LaunchConfigurationsMessages.PerspectivesTab_1; fPerspectiveIds = new HashMap (descriptors.length); 217 for (int i = 0; i < descriptors.length; i++) { 218 IPerspectiveDescriptor descriptor = descriptors[i]; 219 fPerspectiveLabels[i + 1] = descriptor.getLabel(); 220 fPerspectiveIds.put(descriptor.getLabel(), descriptor.getId()); 221 } 222 223 createVerticalSpacer(composite, 2); 225 226 fCombos = new Combo[fModeIds.length]; 227 for (int i = 0; i < fModeIds.length; i++) { 228 label = new Label(composite, SWT.NONE); 229 label.setFont(composite.getFont()); 230 gd = new GridData(GridData.BEGINNING); 231 gd.horizontalSpan= 1; 232 label.setLayoutData(gd); 233 String text = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(fModeIds[i]).getLabel(); 234 label.setText(MessageFormat.format(LaunchConfigurationsMessages.PerspectivesTab_2, new String []{text})); 236 Combo combo = new Combo(composite, SWT.READ_ONLY); 237 combo.setFont(composite.getFont()); 238 combo.setItems(fPerspectiveLabels); 239 combo.setData(fModeIds[i]); 240 gd = new GridData(GridData.BEGINNING); 241 combo.setLayoutData(gd); 242 fCombos[i] = combo; 243 combo.addSelectionListener(fSelectionAdapter); 244 } 245 246 createVerticalSpacer(composite, 2); 247 248 fRestoreDefaults = createPushButton(composite, LaunchConfigurationsMessages.PerspectivesTab_3, null); gd= new GridData(GridData.FILL_BOTH); 250 gd.horizontalSpan= 2; 251 gd.horizontalAlignment= SWT.END; 252 gd.verticalAlignment= SWT.END; 253 fRestoreDefaults.setLayoutData(gd); 254 fRestoreDefaults.addSelectionListener(fSelectionAdapter); 255 256 Dialog.applyDialogFont(composite); 257 } 258 259 262 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 263 for (int i = 0; i < fModeIds.length; i++) { 264 String mode = fModeIds[i]; 265 configuration.setAttribute(mode, (String )null); 267 } 268 } 269 270 273 public void initializeFrom(ILaunchConfiguration configuration) { 274 fInitializing = true; 276 IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry(); 277 for (int i = 0; i < fModeIds.length; i++) { 278 String mode = fModeIds[i]; 279 String persp; 280 try { 281 persp = configuration.getAttribute(mode, (String )null); 282 if (persp == null) { 283 persp = DebugUITools.getLaunchPerspective(getLaunchConfigurationType(), mode); 285 } 286 if (IDebugUIConstants.PERSPECTIVE_NONE.equals(persp)) { 287 persp = null; 288 } 289 IPerspectiveDescriptor descriptor = null; 290 if (persp != null) { 291 descriptor = registry.findPerspectiveWithId(persp); 292 } 293 if (descriptor == null) { 294 fCombos[i].setText(LaunchConfigurationsMessages.PerspectivesTab_1); } else { 297 fCombos[i].setText(descriptor.getLabel()); 298 } 299 } catch (CoreException e) { 300 DebugUIPlugin.log(e); 301 } 302 } 303 fInitializing = false; 304 305 } 306 307 310 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 311 for (int i = 0; i < fCombos.length; i++) { 312 updateConfigFromCombo(fCombos[i], configuration); 313 } 314 } 315 316 324 protected void updateConfigFromCombo(Combo combo, ILaunchConfigurationWorkingCopy workingCopy) { 325 if (!fInitializing) { 326 String mode = (String )combo.getData(); 327 String persp = combo.getText(); 328 if (persp.equals(LaunchConfigurationsMessages.PerspectivesTab_1)) { persp = IDebugUIConstants.PERSPECTIVE_NONE; 330 } else { 331 persp = (String )fPerspectiveIds.get(persp); 332 } 333 String def = DebugUIPlugin.getDefault().getPerspectiveManager().getDefaultLaunchPerspective(getLaunchConfigurationType(), mode); 335 if (def == null) { 336 def = IDebugUIConstants.PERSPECTIVE_NONE; 337 } 338 if (persp.equals(def)) { 339 persp = null; 340 } 341 workingCopy.setAttribute(mode, persp); 342 } 343 } 344 345 348 public String getName() { 349 return LaunchConfigurationsMessages.PerspectivesTab_7; } 351 352 357 protected ILaunchConfigurationType getLaunchConfigurationType() { 358 return fType; 359 } 360 361 364 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 365 } 367 368 371 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 372 } 374 375 381 public String getMessage() { 382 String description = super.getMessage(); 383 if(fType != null) { 384 String mode = getLaunchConfigurationDialog().getMode(); 385 LaunchConfigurationPresentationManager manager = LaunchConfigurationPresentationManager.getDefault(); 386 LaunchConfigurationTabGroupExtension extension = manager.getExtension(fType.getAttribute("id"), mode); description = extension.getDescription(mode); 388 } 389 return description; 390 } 391 392 } 393 | Popular Tags |