KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > ApplicationSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc fMode;
32     private Combo applicationCombo;
33     private String JavaDoc[] fApplicationNames;
34     private String JavaDoc fSelectedApplication;
35
36     public ApplicationSelectionDialog(Shell parentShell, String JavaDoc[] applicationNames, String JavaDoc mode) {
37         super(parentShell);
38         fMode = mode;
39         fApplicationNames = applicationNames;
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
44      */

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 JavaDoc 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); //
77
Dialog.applyDialogFont(container);
78         return container;
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
83      */

84     protected void okPressed() {
85         fSelectedApplication = applicationCombo.getText();
86         super.okPressed();
87     }
88     
89     public String JavaDoc getSelectedApplication() {
90         if (fSelectedApplication.equals(TargetPlatform.getDefaultApplication()))
91             return null;
92         return fSelectedApplication;
93     }
94     
95 }
96
Popular Tags