1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.debug.core.DebugPlugin; 15 import org.eclipse.debug.core.ILaunchMode; 16 import org.eclipse.debug.internal.ui.DebugUIPlugin; 17 import org.eclipse.debug.internal.ui.DefaultLabelProvider; 18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 19 import org.eclipse.debug.internal.ui.SWTFactory; 20 import org.eclipse.debug.ui.IDebugUIConstants; 21 import org.eclipse.jface.dialogs.IDialogSettings; 22 import org.eclipse.jface.viewers.ArrayContentProvider; 23 import org.eclipse.jface.viewers.ISelectionChangedListener; 24 import org.eclipse.jface.viewers.SelectionChangedEvent; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.SelectionEvent; 27 import org.eclipse.swt.events.SelectionListener; 28 import org.eclipse.swt.graphics.Point; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Group; 33 import org.eclipse.swt.widgets.Text; 34 import org.eclipse.ui.PlatformUI; 35 import org.eclipse.ui.dialogs.ListDialog; 36 37 import com.ibm.icu.text.MessageFormat; 38 39 48 public class LaunchShortcutSelectionDialog extends ListDialog { 49 50 private static final String DIALOG_SETTINGS = IDebugUIConstants.PLUGIN_ID + ".SELECT_LAUNCH_SHORTCUT_DIALOG"; 52 55 private String fMode = null; 56 private IResource fResource = null; 57 private Text fDescriptionText = null; 58 59 65 public LaunchShortcutSelectionDialog(IResource resource, String mode) { 66 super(DebugUIPlugin.getShell()); 67 setShellStyle(getShellStyle() | SWT.RESIZE); 68 fResource = resource; 69 fMode = mode; 70 ILaunchMode lmode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(fMode); 71 String modename = fMode; 72 if (lmode != null) { 73 modename = DebugUIPlugin.removeAccelerators(lmode.getLabel()); 74 } 75 setTitle(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_0, new String [] {modename})); 76 setAddCancelButton(true); 77 if(fResource == null) { 78 setMessage(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_4, new String [] {modename.toLowerCase()})); 79 } 80 else { 81 setMessage(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_1, new String [] {modename.toLowerCase(), fResource.getName()})); 82 } 83 setLabelProvider(new DefaultLabelProvider()); 84 setContentProvider(new ArrayContentProvider()); 85 } 86 87 90 protected Control createContents(Composite parent) { 91 Composite comp = (Composite) super.createContents(parent); 92 PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugHelpContextIds.SELECT_LAUNCH_METHOD_DIALOG); 93 return comp; 94 } 95 96 99 protected IDialogSettings getDialogBoundsSettings() { 100 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 101 IDialogSettings section = settings.getSection(DIALOG_SETTINGS); 102 if (section == null) { 103 section = settings.addNewSection(DIALOG_SETTINGS); 104 } 105 return section; 106 } 107 108 111 protected Point getInitialSize() { 112 IDialogSettings settings = getDialogBoundsSettings(); 113 if(settings != null) { 114 try { 115 int width = settings.getInt("DIALOG_WIDTH"); int height = settings.getInt("DIALOG_HEIGHT"); if(width > 0 & height > 0) { 118 return new Point(width, height); 119 } 120 } 121 catch (NumberFormatException nfe) { 122 return new Point(450, 450); 123 } 124 } 125 return new Point(450, 450); 126 } 127 128 131 protected void createButtonsForButtonBar(Composite parent) { 132 super.createButtonsForButtonBar(parent); 133 getOkButton().setEnabled(false); 134 getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { 135 public void selectionChanged(SelectionChangedEvent event) { 136 getOkButton().setEnabled(!event.getSelection().isEmpty()); 137 } 138 }); 139 } 140 141 144 protected Control createDialogArea(Composite container) { 145 Composite comp = (Composite) super.createDialogArea(container); 146 Group group = SWTFactory.createGroup(comp, LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_2, 1, 1, GridData.FILL_BOTH); 147 GridData gd = (GridData) group.getLayoutData(); 148 gd.heightHint = 175; 149 fDescriptionText = SWTFactory.createText(group, SWT.WRAP | SWT.READ_ONLY, 1, GridData.FILL_BOTH); 150 fDescriptionText.setBackground(group.getBackground()); 151 getTableViewer().getTable().addSelectionListener(new SelectionListener() { 152 public void widgetDefaultSelected(SelectionEvent e) {} 153 public void widgetSelected(SelectionEvent e) { 154 Object o = e.item.getData(); 155 if(o instanceof LaunchShortcutExtension) { 156 String txt = ((LaunchShortcutExtension)o).getShortcutDescription(fMode); 157 fDescriptionText.setText((txt == null ? LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_3 : txt)); 158 } 159 } 160 }); 161 return comp; 162 } 163 } 164 | Popular Tags |