KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchShortcutSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 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.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 /**
40  * Specialized dialog for showing/selecting a specific launch shortcut extension, and allowing it
41  * to be marked to be set as the default
42  *
43  * @see {@link org.eclipse.debug.internal.ui.actions.ContextLaunchingAction}
44  *
45  * @since 3.3
46  * CONTEXTLAUNCHING
47  */

48 public class LaunchShortcutSelectionDialog extends ListDialog {
49
50     private static final String JavaDoc DIALOG_SETTINGS = IDebugUIConstants.PLUGIN_ID + ".SELECT_LAUNCH_SHORTCUT_DIALOG"; //$NON-NLS-1$;
51

52     /**
53      * The list of input for the dialog
54      */

55     private String JavaDoc fMode = null;
56     private IResource fResource = null;
57     private Text fDescriptionText = null;
58     
59     /**
60      * Constructor
61      * @param input
62      * @param resource
63      * @param mode
64      */

65     public LaunchShortcutSelectionDialog(IResource resource, String JavaDoc 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 JavaDoc modename = fMode;
72         if (lmode != null) {
73             modename = DebugUIPlugin.removeAccelerators(lmode.getLabel());
74         }
75         setTitle(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_0, new String JavaDoc[] {modename}));
76         setAddCancelButton(true);
77         if(fResource == null) {
78             setMessage(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_4, new String JavaDoc[] {modename.toLowerCase()}));
79         }
80         else {
81             setMessage(MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_1, new String JavaDoc[] {modename.toLowerCase(), fResource.getName()}));
82         }
83         setLabelProvider(new DefaultLabelProvider());
84         setContentProvider(new ArrayContentProvider());
85     }
86
87     /**
88      * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
89      */

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     /**
97      * @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings()
98      */

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     /* (non-Javadoc)
109      * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
110      */

111     protected Point getInitialSize() {
112         IDialogSettings settings = getDialogBoundsSettings();
113         if(settings != null) {
114             try {
115                 int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
116
int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
117
if(width > 0 & height > 0) {
118                     return new Point(width, height);
119                 }
120             }
121             catch (NumberFormatException JavaDoc nfe) {
122                 return new Point(450, 450);
123             }
124         }
125         return new Point(450, 450);
126     }
127     
128     /**
129      * @see org.eclipse.ui.dialogs.ListDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
130      */

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     /**
142      * @see org.eclipse.ui.dialogs.ListDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
143      */

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 JavaDoc o = e.item.getData();
155                 if(o instanceof LaunchShortcutExtension) {
156                     String JavaDoc 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