|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.s60tools.imaker.internal.dialogs; |
|
18 |
|
19 import org.eclipse.jface.dialogs.IDialogConstants; |
|
20 import org.eclipse.jface.dialogs.TitleAreaDialog; |
|
21 import org.eclipse.jface.resource.ImageDescriptor; |
|
22 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
23 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.graphics.Image; |
|
26 import org.eclipse.swt.graphics.Point; |
|
27 import org.eclipse.swt.layout.GridData; |
|
28 import org.eclipse.swt.layout.GridLayout; |
|
29 import org.eclipse.swt.widgets.Button; |
|
30 import org.eclipse.swt.widgets.Composite; |
|
31 import org.eclipse.swt.widgets.Control; |
|
32 import org.eclipse.swt.widgets.Shell; |
|
33 |
|
34 import com.nokia.s60tools.imaker.IEnvironmentManager; |
|
35 import com.nokia.s60tools.imaker.IMakerPlugin; |
|
36 import com.nokia.s60tools.imaker.Messages; |
|
37 import com.nokia.s60tools.imaker.internal.managers.ProjectManager; |
|
38 import com.nokia.s60tools.imaker.internal.viewers.IMakerTabsViewer; |
|
39 |
|
40 public class LaunchIMakerDialog extends TitleAreaDialog { |
|
41 |
|
42 /** Keep track of the currently visible dialog instance */ |
|
43 private static LaunchIMakerDialog fgCurrentlyVisibleLaunchIMakerDialog; |
|
44 |
|
45 /** Id for 'Launch' button.*/ |
|
46 protected static final int ID_LAUNCH_BUTTON = IDialogConstants.CLIENT_ID + 1; |
|
47 |
|
48 /** Id for 'Close' button.*/ |
|
49 protected static final int ID_CLOSE_BUTTON = IDialogConstants.CLIENT_ID + 2; |
|
50 |
|
51 /** Id for 'Cancel' button.*/ |
|
52 protected static final int ID_CANCEL_BUTTON = IDialogConstants.CLIENT_ID + 3; |
|
53 |
|
54 /** |
|
55 * Constant specifying how wide this dialog is allowed to get (as a percentage of |
|
56 * total available screen width) as a result of tab labels in the edit area. |
|
57 */ |
|
58 protected static final float MAX_DIALOG_WIDTH_PERCENT = 0.75f; |
|
59 |
|
60 /** |
|
61 * Constant specifying how tall this dialog is allowed to get (as a percentage of |
|
62 * total available screen height) as a result of preferred tab size. |
|
63 */ |
|
64 protected static final float MAX_DIALOG_HEIGHT_PERCENT = 0.60f; |
|
65 |
|
66 /** |
|
67 * Size of this dialog if there is no preference specifying a size. |
|
68 */ |
|
69 protected static final Point DEFAULT_INITIAL_DIALOG_SIZE = new Point(540, 650); //(620, 690) |
|
70 |
|
71 |
|
72 /** |
|
73 * Returns the currently visible dialog |
|
74 * @return the currently visible launch dialog |
|
75 */ |
|
76 public static LaunchIMakerDialog getCurrentlyVisibleLaunchConfigurationDialog() { |
|
77 return fgCurrentlyVisibleLaunchIMakerDialog; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Sets which launch dialog is currently the visible one |
|
82 * @param dialog the dialog to set as the visible one |
|
83 */ |
|
84 public static void setCurrentlyVisibleLaunchConfigurationDialog(LaunchIMakerDialog dialog) { |
|
85 fgCurrentlyVisibleLaunchIMakerDialog = dialog; |
|
86 } |
|
87 |
|
88 /** |
|
89 * widgets |
|
90 */ |
|
91 private IMakerTabsViewer fTabViewer; |
|
92 private Image fBannerImage; |
|
93 |
|
94 private Button runButton; |
|
95 |
|
96 private IMakerTabsViewer imakerTabsViewer; |
|
97 |
|
98 private ProjectManager projectManager; |
|
99 |
|
100 private String filePath; |
|
101 |
|
102 private IEnvironmentManager environmentManager; |
|
103 |
|
104 public LaunchIMakerDialog(Shell parentShell, ProjectManager projectManager, IEnvironmentManager manager) { |
|
105 super(parentShell); |
|
106 this.projectManager = projectManager; |
|
107 this.environmentManager = manager; |
|
108 } |
|
109 |
|
110 public ProjectManager getProjectManager() { |
|
111 return projectManager; |
|
112 } |
|
113 |
|
114 @Override |
|
115 protected void configureShell(Shell shell) { |
|
116 super.configureShell(shell); |
|
117 shell.setText(getShellTitle()); |
|
118 } |
|
119 private String getShellTitle() { |
|
120 return Messages.getString("Project.name"); |
|
121 } |
|
122 |
|
123 @Override |
|
124 protected Control createDialogArea(Composite parent) { |
|
125 Composite dialogComp = (Composite)super.createDialogArea(parent); |
|
126 setTitle(Messages.getString("LaunchImakerDialog.title")); |
|
127 setMessage(Messages.getString("LaunchImakerDialog.message")); |
|
128 setImage(); |
|
129 |
|
130 addContent(dialogComp); |
|
131 return dialogComp; |
|
132 } |
|
133 |
|
134 public void initialize() { |
|
135 getTabViewer().initialize(); |
|
136 } |
|
137 /** |
|
138 * Adds content to the dialog area |
|
139 * |
|
140 * @param dialogComp |
|
141 */ |
|
142 protected void addContent(Composite dialogComp) { |
|
143 GridData gd; |
|
144 Composite topComp = new Composite(dialogComp, SWT.NONE); |
|
145 gd = new GridData(GridData.FILL_BOTH); |
|
146 topComp.setLayoutData(gd); |
|
147 GridLayout topLayout = new GridLayout(1, false); |
|
148 topComp.setLayout(topLayout); |
|
149 |
|
150 Composite editAreaComp = createPreferenceEditArea(topComp); |
|
151 gd = new GridData(GridData.FILL_BOTH); |
|
152 editAreaComp.setLayoutData(gd); |
|
153 |
|
154 dialogComp.layout(true); |
|
155 initialize(); |
|
156 applyDialogFont(dialogComp); |
|
157 } |
|
158 |
|
159 private void setImage() { |
|
160 setTitleImage(getBannerImage()); |
|
161 } |
|
162 |
|
163 private Image getBannerImage() { |
|
164 if (fBannerImage == null) { |
|
165 ImageDescriptor descriptor = IMakerPlugin.getImageDescriptor("icons/imaker_dialog.png"); |
|
166 if (descriptor != null) { |
|
167 fBannerImage = descriptor.createImage(); |
|
168 } |
|
169 } |
|
170 return fBannerImage; |
|
171 } |
|
172 |
|
173 private Composite createPreferenceEditArea(Composite parent) { |
|
174 imakerTabsViewer = new IMakerTabsViewer(parent,environmentManager, this); |
|
175 setTabViewer(imakerTabsViewer); |
|
176 getTabViewer().addSelectionChangedListener(new ISelectionChangedListener() { |
|
177 public void selectionChanged(SelectionChangedEvent event) { |
|
178 // handleTabSelectionChanged(); |
|
179 } |
|
180 }); |
|
181 return (Composite)getTabViewer().getControl(); |
|
182 } |
|
183 |
|
184 |
|
185 /** |
|
186 * A launch configuration dialog overrides this method |
|
187 * to create a custom set of buttons in the button bar. |
|
188 * This dialog has 'Launch' and 'Cancel' |
|
189 * buttons. |
|
190 * |
|
191 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
|
192 */ |
|
193 protected void createButtonsForButtonBar(Composite parent) { |
|
194 createButton(parent, IDialogConstants.OK_ID, Messages.getString("LaunchImakerDialog.run"), true); |
|
195 createButton(parent, ID_CLOSE_BUTTON, Messages.getString("LaunchImakerDialog.close"), false); |
|
196 } |
|
197 |
|
198 public Button getRunButton() { |
|
199 return runButton; |
|
200 } |
|
201 /** |
|
202 * Handle the 'close' & 'launch' buttons here, all others are handled |
|
203 * in <code>Dialog</code> |
|
204 * |
|
205 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) |
|
206 */ |
|
207 protected void buttonPressed(int buttonId) { |
|
208 if (buttonId == IDialogConstants.OK_ID) { |
|
209 setFilePath(imakerTabsViewer.handleRunPressed()); |
|
210 okPressed(); |
|
211 } else if (buttonId == ID_CLOSE_BUTTON) { |
|
212 // imakerTabsViewer.handleRunPressed(); |
|
213 cancelPressed(); |
|
214 } else { |
|
215 super.buttonPressed(buttonId); |
|
216 } |
|
217 } |
|
218 |
|
219 @Override |
|
220 protected Point getInitialSize() { |
|
221 return DEFAULT_INITIAL_DIALOG_SIZE; |
|
222 } |
|
223 |
|
224 /** |
|
225 * Sets the viewer used to display the tabs for a launch configuration. |
|
226 * |
|
227 * @param viewer the new view to set |
|
228 */ |
|
229 protected void setTabViewer(IMakerTabsViewer viewer) { |
|
230 fTabViewer = viewer; |
|
231 } |
|
232 |
|
233 /** |
|
234 * Returns the viewer used to display the tabs for a launch configuration. |
|
235 * |
|
236 * @return LaunchConfigurationTabGroupViewer |
|
237 */ |
|
238 protected IMakerTabsViewer getTabViewer() { |
|
239 return fTabViewer; |
|
240 } |
|
241 |
|
242 /** |
|
243 * @param filePath the filePath to set |
|
244 */ |
|
245 public void setFilePath(String path) { |
|
246 this.filePath = path; |
|
247 } |
|
248 |
|
249 /** |
|
250 * @return the filePath |
|
251 */ |
|
252 public String getFilePath() { |
|
253 return filePath; |
|
254 } |
|
255 |
|
256 |
|
257 } |