1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import org.eclipse.debug.core.ILaunchManager; 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.jface.dialogs.TrayDialog; 17 import org.eclipse.pde.core.plugin.TargetPlatform; 18 import org.eclipse.pde.internal.ui.PDEUIMessages; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.layout.GridLayout; 22 import org.eclipse.swt.widgets.Combo; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.swt.widgets.Shell; 27 28 29 public class ApplicationSelectionDialog extends TrayDialog { 30 31 private String fMode; 32 private Combo applicationCombo; 33 private String [] fApplicationNames; 34 private String fSelectedApplication; 35 36 public ApplicationSelectionDialog(Shell parentShell, String [] applicationNames, String mode) { 37 super(parentShell); 38 fMode = mode; 39 fApplicationNames = applicationNames; 40 } 41 42 45 protected void createButtonsForButtonBar(Composite parent) { 46 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 47 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true); 48 } 49 50 protected Control createDialogArea(Composite parent) { 51 Composite container = (Composite) super.createDialogArea(parent); 52 GridLayout layout = new GridLayout(); 53 layout.numColumns = 2; 54 layout.marginWidth = layout.marginHeight = 9; 55 container.setLayout(layout); 56 GridData gd = new GridData(GridData.FILL_BOTH); 57 gd.heightHint = 100; 58 container.setLayoutData(gd); 59 60 Label label = new Label(container, SWT.NONE); 61 if (fMode.equals(ILaunchManager.DEBUG_MODE)) 62 label.setText(PDEUIMessages.ApplicationSelectionDialog_debug); 63 else 64 label.setText(PDEUIMessages.ApplicationSelectionDialog_run); 65 66 applicationCombo = new Combo(container, SWT.READ_ONLY|SWT.DROP_DOWN); 67 applicationCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 68 applicationCombo.setItems(fApplicationNames); 69 70 String defaultApp = TargetPlatform.getDefaultApplication(); 71 if (applicationCombo.indexOf(defaultApp) == -1) 72 applicationCombo.add(defaultApp); 73 74 applicationCombo.setText(applicationCombo.getItem(0)); 75 76 getShell().setText(fMode.equals(ILaunchManager.DEBUG_MODE) ? PDEUIMessages.ApplicationSelectionDialog_dtitle : PDEUIMessages.ApplicationSelectionDialog_rtitle); Dialog.applyDialogFont(container); 78 return container; 79 } 80 81 84 protected void okPressed() { 85 fSelectedApplication = applicationCombo.getText(); 86 super.okPressed(); 87 } 88 89 public String getSelectedApplication() { 90 if (fSelectedApplication.equals(TargetPlatform.getDefaultApplication())) 91 return null; 92 return fSelectedApplication; 93 } 94 95 } 96 | Popular Tags |