001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.launcher;
011:
012: import org.eclipse.debug.core.ILaunchManager;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.jface.dialogs.IDialogConstants;
015: import org.eclipse.jface.dialogs.TrayDialog;
016: import org.eclipse.pde.core.plugin.TargetPlatform;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.layout.GridData;
020: import org.eclipse.swt.layout.GridLayout;
021: import org.eclipse.swt.widgets.Combo;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Control;
024: import org.eclipse.swt.widgets.Label;
025: import org.eclipse.swt.widgets.Shell;
026:
027: public class ApplicationSelectionDialog extends TrayDialog {
028:
029: private String fMode;
030: private Combo applicationCombo;
031: private String[] fApplicationNames;
032: private String fSelectedApplication;
033:
034: public ApplicationSelectionDialog(Shell parentShell,
035: String[] applicationNames, String mode) {
036: super (parentShell);
037: fMode = mode;
038: fApplicationNames = applicationNames;
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
043: */
044: protected void createButtonsForButtonBar(Composite parent) {
045: createButton(parent, IDialogConstants.OK_ID,
046: IDialogConstants.OK_LABEL, true);
047: createButton(parent, IDialogConstants.CANCEL_ID,
048: IDialogConstants.CANCEL_LABEL, true);
049: }
050:
051: protected Control createDialogArea(Composite parent) {
052: Composite container = (Composite) super
053: .createDialogArea(parent);
054: GridLayout layout = new GridLayout();
055: layout.numColumns = 2;
056: layout.marginWidth = layout.marginHeight = 9;
057: container.setLayout(layout);
058: GridData gd = new GridData(GridData.FILL_BOTH);
059: gd.heightHint = 100;
060: container.setLayoutData(gd);
061:
062: Label label = new Label(container, SWT.NONE);
063: if (fMode.equals(ILaunchManager.DEBUG_MODE))
064: label
065: .setText(PDEUIMessages.ApplicationSelectionDialog_debug);
066: else
067: label.setText(PDEUIMessages.ApplicationSelectionDialog_run);
068:
069: applicationCombo = new Combo(container, SWT.READ_ONLY
070: | SWT.DROP_DOWN);
071: applicationCombo.setLayoutData(new GridData(
072: GridData.FILL_HORIZONTAL));
073: applicationCombo.setItems(fApplicationNames);
074:
075: String defaultApp = TargetPlatform.getDefaultApplication();
076: if (applicationCombo.indexOf(defaultApp) == -1)
077: applicationCombo.add(defaultApp);
078:
079: applicationCombo.setText(applicationCombo.getItem(0));
080:
081: getShell()
082: .setText(
083: fMode.equals(ILaunchManager.DEBUG_MODE) ? PDEUIMessages.ApplicationSelectionDialog_dtitle
084: : PDEUIMessages.ApplicationSelectionDialog_rtitle); //
085: Dialog.applyDialogFont(container);
086: return container;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.eclipse.jface.dialogs.Dialog#okPressed()
091: */
092: protected void okPressed() {
093: fSelectedApplication = applicationCombo.getText();
094: super .okPressed();
095: }
096:
097: public String getSelectedApplication() {
098: if (fSelectedApplication.equals(TargetPlatform
099: .getDefaultApplication()))
100: return null;
101: return fSelectedApplication;
102: }
103:
104: }
|