0
|
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 |
|
|
18 |
package com.nokia.s60tools.imaker.internal.viewers;
|
|
19 |
|
|
20 |
import java.lang.reflect.InvocationTargetException;
|
|
21 |
import java.util.List;
|
|
22 |
|
|
23 |
import org.eclipse.core.resources.IResource;
|
|
24 |
import org.eclipse.jface.dialogs.Dialog;
|
|
25 |
import org.eclipse.jface.resource.ColorRegistry;
|
|
26 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
27 |
import org.eclipse.jface.resource.JFaceResources;
|
|
28 |
import org.eclipse.jface.viewers.ISelection;
|
|
29 |
import org.eclipse.jface.viewers.Viewer;
|
|
30 |
import org.eclipse.swt.SWT;
|
|
31 |
import org.eclipse.swt.custom.CTabFolder;
|
|
32 |
import org.eclipse.swt.custom.ViewForm;
|
|
33 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
34 |
import org.eclipse.swt.events.SelectionEvent;
|
|
35 |
import org.eclipse.swt.events.SelectionListener;
|
|
36 |
import org.eclipse.swt.graphics.Color;
|
|
37 |
import org.eclipse.swt.graphics.Image;
|
|
38 |
import org.eclipse.swt.layout.GridData;
|
|
39 |
import org.eclipse.swt.layout.GridLayout;
|
|
40 |
import org.eclipse.swt.widgets.Button;
|
|
41 |
import org.eclipse.swt.widgets.Combo;
|
|
42 |
import org.eclipse.swt.widgets.Composite;
|
|
43 |
import org.eclipse.swt.widgets.Control;
|
|
44 |
import org.eclipse.swt.widgets.Label;
|
|
45 |
import org.eclipse.ui.IWorkbenchPreferenceConstants;
|
|
46 |
import org.eclipse.ui.PlatformUI;
|
|
47 |
|
|
48 |
import com.nokia.s60tools.imaker.IEnvironmentManager;
|
|
49 |
import com.nokia.s60tools.imaker.IMakerPlugin;
|
|
50 |
import com.nokia.s60tools.imaker.Messages;
|
|
51 |
import com.nokia.s60tools.imaker.SWTFactory;
|
|
52 |
import com.nokia.s60tools.imaker.internal.dialogs.LaunchIMakerDialog;
|
|
53 |
import com.nokia.s60tools.imaker.internal.managers.ProjectManager;
|
|
54 |
import com.nokia.s60tools.imaker.internal.model.IObserver;
|
|
55 |
import com.nokia.s60tools.imaker.internal.model.ImakerProperties;
|
|
56 |
|
|
57 |
public class IMakerTabsViewer extends Viewer implements IObserver {
|
|
58 |
/**
|
|
59 |
* This view's control, which contains a composite area of controls
|
|
60 |
*/
|
|
61 |
private Composite fViewerControl;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Tab folder
|
|
65 |
*/
|
|
66 |
private CTabFolder fTabFolder;
|
|
67 |
|
|
68 |
private Button fRevertButton;
|
|
69 |
|
|
70 |
/**
|
|
71 |
* A place holder for switching between the tabs for a config and the getting started tab
|
|
72 |
* @since 3.2
|
|
73 |
*/
|
|
74 |
private Composite fTabPlaceHolder = null;
|
|
75 |
private ViewForm fViewform;
|
|
76 |
private IEnvironmentManager environmentManager;
|
|
77 |
private PreferencesTab tabPreferences;
|
|
78 |
private Button fRestoreButton;
|
|
79 |
private SettingsTab tabSettings;
|
|
80 |
private Combo fConfigWidget;
|
|
81 |
private Button deleteButton;
|
|
82 |
private DebugTab tabDebug;
|
|
83 |
private PlatsimTab tabPlatsim;
|
|
84 |
private LaunchIMakerDialog dialog;
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Constructs a viewer in the given composite, contained by the given
|
|
88 |
* launch configuration dialog.
|
|
89 |
*
|
|
90 |
* @param parent composite containing this viewer
|
|
91 |
* @param manager
|
|
92 |
* @param launchIMakerDialog
|
|
93 |
* @param dialog containing launch configuration dialog
|
|
94 |
* @param selection
|
|
95 |
* @throws InterruptedException
|
|
96 |
*/
|
|
97 |
public IMakerTabsViewer(Composite parent, IEnvironmentManager manager, LaunchIMakerDialog dialog){
|
|
98 |
super();
|
|
99 |
this.environmentManager = manager;
|
|
100 |
this.dialog = dialog;
|
|
101 |
createControl(parent);
|
|
102 |
}
|
|
103 |
|
|
104 |
public void initialize() {
|
|
105 |
ImakerProperties run = environmentManager.getActiveEnvironment().getRunProperties();
|
|
106 |
String file = run.getActiveFile();
|
|
107 |
if(file!=null) {
|
|
108 |
displayImakerFile(file);
|
|
109 |
} else {
|
|
110 |
displayImakerFile(ProjectManager.NEW_ITEM);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* @throws InterruptedException
|
|
116 |
*
|
|
117 |
*/
|
|
118 |
private void displayImakerFile(String item){
|
|
119 |
populateConfigurations(item);
|
|
120 |
try {
|
|
121 |
tabPreferences.loadImakerFile(item);
|
|
122 |
} catch (InvocationTargetException e) {}
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
*
|
|
127 |
*/
|
|
128 |
public void populateConfigurations(String selection) {
|
|
129 |
fConfigWidget.removeAll();
|
|
130 |
List<IResource> files = getProjectManager().getImakerFiles();
|
|
131 |
fConfigWidget.add(ProjectManager.NEW_ITEM);
|
|
132 |
fConfigWidget.select(0);
|
|
133 |
for (int i = 0; i < files.size(); i++) {
|
|
134 |
String item = files.get(i).getLocation().toString();
|
|
135 |
fConfigWidget.add(item);
|
|
136 |
if(item.equals(selection)) {
|
|
137 |
fConfigWidget.select(i+1);
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
public IEnvironmentManager getEnvironmentManager() {
|
|
144 |
return environmentManager;
|
|
145 |
}
|
|
146 |
public ProjectManager getProjectManager() {
|
|
147 |
return dialog.getProjectManager();
|
|
148 |
}
|
|
149 |
|
|
150 |
@Override
|
|
151 |
public Control getControl() {
|
|
152 |
return fViewerControl;
|
|
153 |
}
|
|
154 |
|
|
155 |
@Override
|
|
156 |
public Object getInput() {
|
|
157 |
return null;
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
|
161 |
public ISelection getSelection() {
|
|
162 |
return null;
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
public void refresh() {}
|
|
167 |
|
|
168 |
@Override
|
|
169 |
public void setInput(Object input) {
|
|
170 |
|
|
171 |
}
|
|
172 |
|
|
173 |
@Override
|
|
174 |
public void setSelection(ISelection selection, boolean reveal) {
|
|
175 |
|
|
176 |
}
|
|
177 |
/**
|
|
178 |
* Creates this viewer's control This area displays the name of the launch
|
|
179 |
* configuration currently being edited, as well as a tab folder of tabs
|
|
180 |
* that are applicable to the launch configuration.
|
|
181 |
*
|
|
182 |
* @return the composite used for launch configuration editing
|
|
183 |
*/
|
|
184 |
private void createControl(Composite parent) {
|
|
185 |
fViewerControl = new Composite(parent, SWT.NONE);
|
|
186 |
GridLayout layout = new GridLayout(1,false);
|
|
187 |
layout.marginHeight = 0;
|
|
188 |
layout.marginWidth = 0;
|
|
189 |
layout.horizontalSpacing = 0;
|
|
190 |
layout.verticalSpacing = 0;
|
|
191 |
fViewerControl.setLayout(layout);
|
|
192 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
193 |
fViewerControl.setLayoutData(gd);
|
|
194 |
|
|
195 |
fViewform = new ViewForm(fViewerControl, SWT.FLAT | SWT.BORDER);
|
|
196 |
layout = new GridLayout(1, false);
|
|
197 |
layout.horizontalSpacing = 0;
|
|
198 |
layout.verticalSpacing = 0;
|
|
199 |
fViewform.setLayout(layout);
|
|
200 |
gd = new GridData(GridData.FILL_BOTH);
|
|
201 |
fViewform.setLayoutData(gd);
|
|
202 |
fViewform.setTopLeft(null);
|
|
203 |
|
|
204 |
Composite mainComp = new Composite(fViewform, SWT.FLAT);
|
|
205 |
layout = new GridLayout(1, false);
|
|
206 |
layout.marginHeight = 0;
|
|
207 |
layout.marginWidth = 0;
|
|
208 |
layout.verticalSpacing = 0;
|
|
209 |
layout.horizontalSpacing = 0;
|
|
210 |
mainComp.setLayout(layout);
|
|
211 |
fViewform.setContent(mainComp);
|
|
212 |
|
|
213 |
Composite comboComp = new Composite(mainComp, SWT.NONE);
|
|
214 |
comboComp.setLayout(new GridLayout(3, false));
|
|
215 |
comboComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
216 |
|
|
217 |
Label fNameLabel = new Label(comboComp, SWT.HORIZONTAL | SWT.LEFT);
|
|
218 |
fNameLabel.setText(Messages.getString("IMakerTabsViewer.1"));
|
|
219 |
fNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
|
|
220 |
|
|
221 |
fConfigWidget = new Combo(comboComp, SWT.NONE);
|
|
222 |
fConfigWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
223 |
fConfigWidget.addSelectionListener(new SelectionListener() {
|
|
224 |
|
|
225 |
// @Override
|
|
226 |
public void widgetSelected(SelectionEvent se) {
|
|
227 |
try {
|
|
228 |
tabPreferences.loadImakerFile(getSelectedItem());
|
|
229 |
} catch (InvocationTargetException e) {
|
|
230 |
e.printStackTrace();
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
// @Override
|
|
235 |
public void widgetDefaultSelected(SelectionEvent se) {
|
|
236 |
widgetSelected(se);
|
|
237 |
}
|
|
238 |
});
|
|
239 |
|
|
240 |
fConfigWidget.setToolTipText(Messages.getString("IMakerTabsViewer.2"));
|
|
241 |
deleteButton = new Button(comboComp, SWT.PUSH);
|
|
242 |
deleteButton.setText("Delete");
|
|
243 |
deleteButton.setEnabled(false);
|
|
244 |
deleteButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
|
|
245 |
|
|
246 |
fTabPlaceHolder = new Composite(mainComp, SWT.NONE);
|
|
247 |
layout = new GridLayout(1, false);
|
|
248 |
layout.marginHeight = 0;
|
|
249 |
layout.marginWidth = 0;
|
|
250 |
fTabPlaceHolder.setLayout(layout);
|
|
251 |
gd = new GridData(GridData.FILL_BOTH);
|
|
252 |
fTabPlaceHolder.setLayoutData(gd);
|
|
253 |
|
|
254 |
createTabFolder(fTabPlaceHolder);
|
|
255 |
|
|
256 |
|
|
257 |
Composite buttonComp = new Composite(mainComp, SWT.NONE);
|
|
258 |
GridLayout buttonCompLayout = new GridLayout();
|
|
259 |
buttonCompLayout.numColumns = 2;
|
|
260 |
buttonComp.setLayout(buttonCompLayout);
|
|
261 |
gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
262 |
buttonComp.setLayoutData(gd);
|
|
263 |
|
|
264 |
fRestoreButton = new Button(buttonComp, SWT.PUSH);
|
|
265 |
fRestoreButton.setText(Messages.getString("IMakerTabsViewer.0")); //$NON-NLS-1$
|
|
266 |
fRestoreButton.setToolTipText(Messages.getString("IMakerTabsViewer.11")); //$NON-NLS-1$
|
|
267 |
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
|
|
268 |
fRestoreButton.setLayoutData(gd);
|
|
269 |
SWTFactory.setButtonWidthHint(fRestoreButton);
|
|
270 |
fRestoreButton.addSelectionListener(new SelectionAdapter() {
|
|
271 |
public void widgetSelected(SelectionEvent evt) {
|
|
272 |
handleRestorePressed();
|
|
273 |
}
|
|
274 |
});
|
|
275 |
|
|
276 |
Dialog.applyDialogFont(parent);
|
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
protected void handleNameModified() {
|
|
281 |
if(!fConfigWidget.getText().equals("")) {
|
|
282 |
deleteButton.setEnabled(true);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
private void handleRestorePressed() {
|
|
287 |
tabPreferences.restore();
|
|
288 |
}
|
|
289 |
|
|
290 |
protected void handleRevertPressed() {
|
|
291 |
if(fTabFolder.getSelection() == tabSettings) {
|
1
|
292 |
tabPreferences.refreshSettingsTab(null);
|
0
|
293 |
} else {
|
|
294 |
// tabPreferences.revert();
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Creates the tab folder for displaying config instances
|
|
300 |
* @param parent
|
|
301 |
*/
|
|
302 |
private void createTabFolder(Composite parent) {
|
|
303 |
if (fTabFolder == null) {
|
|
304 |
Composite tabComposite = new Composite(parent, SWT.NONE);
|
|
305 |
GridLayout layout = new GridLayout(1, false);
|
|
306 |
layout.marginHeight = 0;
|
|
307 |
layout.marginWidth = 0;
|
|
308 |
tabComposite.setLayout(layout);
|
|
309 |
tabComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
310 |
ColorRegistry reg = JFaceResources.getColorRegistry();
|
|
311 |
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
|
|
312 |
c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
|
|
313 |
fTabFolder = new CTabFolder(tabComposite, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT);
|
|
314 |
|
|
315 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
316 |
gd.horizontalSpan = 2;
|
|
317 |
fTabFolder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true);
|
|
318 |
fTabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
|
|
319 |
fTabFolder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
|
|
320 |
fTabFolder.setLayoutData(gd);
|
|
321 |
fTabFolder.setBorderVisible(true);
|
|
322 |
fTabFolder.setFont(tabComposite.getFont());
|
|
323 |
fTabFolder.addSelectionListener(new SelectionListener() {
|
|
324 |
|
|
325 |
// @Override
|
|
326 |
public void widgetSelected(SelectionEvent e) {
|
|
327 |
if(e.item instanceof DebugTab) {
|
|
328 |
tabDebug.refesh();
|
|
329 |
}
|
|
330 |
}
|
|
331 |
|
|
332 |
// @Override
|
|
333 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
334 |
widgetSelected(e);
|
|
335 |
}
|
|
336 |
});
|
|
337 |
createTabs(fTabFolder);
|
|
338 |
fTabFolder.setSelection(0);
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
private void createTabs(CTabFolder tabFolder) {
|
|
343 |
tabPreferences = new PreferencesTab(tabFolder, SWT.NONE, this);
|
|
344 |
PreferencesTab.currentPreferencesTab = tabPreferences;
|
|
345 |
tabPreferences.setText(Messages.getString("IMakerTabsViewer.3")); //$NON-NLS-1$
|
|
346 |
tabPreferences.setToolTipText(Messages.getString("IMakerTabsViewer.4"));
|
|
347 |
tabPreferences.setImage(getTabImage(1));
|
|
348 |
tabSettings = new SettingsTab(tabFolder, SWT.NONE);
|
|
349 |
tabSettings.setText(Messages.getString("IMakerTabsViewer.5")); //$NON-NLS-1$
|
|
350 |
tabSettings.setToolTipText(Messages.getString("IMakerTabsViewer.6"));
|
|
351 |
tabSettings.setImage(getTabImage(2));
|
|
352 |
tabDebug = new DebugTab(tabFolder, SWT.NONE, this, tabPreferences);
|
|
353 |
tabDebug.setImage(getTabImage(3));
|
|
354 |
tabDebug.setText(Messages.getString("IMakerTabsViewer.7")); //$NON-NLS-1$
|
|
355 |
tabDebug.setToolTipText(Messages.getString("IMakerTabsViewer.8"));
|
|
356 |
|
|
357 |
tabPlatsim = new PlatsimTab(tabFolder, SWT.NONE);
|
|
358 |
tabPlatsim.setImage(getTabImage(4));
|
|
359 |
tabPlatsim.setText(Messages.getString("IMakerTabsViewer.9")); //$NON-NLS-1$
|
|
360 |
tabPlatsim.setToolTipText(Messages.getString("IMakerTabsViewer.10"));
|
|
361 |
|
|
362 |
tabPreferences.setSettings(tabSettings);
|
|
363 |
tabPreferences.setDebug(tabDebug);
|
|
364 |
tabPreferences.setPlatsim(tabPlatsim);
|
|
365 |
}
|
|
366 |
|
|
367 |
private Image getTabImage(int tab) {
|
|
368 |
ImageDescriptor descriptor = null;
|
|
369 |
switch (tab) {
|
|
370 |
case 1:
|
|
371 |
descriptor = IMakerPlugin.getImageDescriptor("icons/preferences.gif");
|
|
372 |
return descriptor.createImage();
|
|
373 |
case 2:
|
|
374 |
descriptor = IMakerPlugin.getImageDescriptor("icons/settings.gif"); //$NON-NLS-1$
|
|
375 |
return descriptor.createImage();
|
|
376 |
case 3:
|
1
|
377 |
descriptor = IMakerPlugin.getImageDescriptor("icons/content.gif"); //$NON-NLS-1$
|
0
|
378 |
return descriptor.createImage();
|
|
379 |
case 4:
|
|
380 |
descriptor = IMakerPlugin.getImageDescriptor("icons/platsim.png"); //$NON-NLS-1$
|
|
381 |
return descriptor.createImage();
|
|
382 |
default:
|
|
383 |
break;
|
|
384 |
}
|
|
385 |
return null;
|
|
386 |
}
|
|
387 |
|
|
388 |
public void update(Object selection) {
|
|
389 |
if(selection!=null) {
|
|
390 |
setNameField((ImakerProperties) selection);
|
|
391 |
deleteButton.setEnabled(false);
|
|
392 |
} else {
|
|
393 |
fConfigWidget.setText("");
|
|
394 |
deleteButton.setEnabled(false);
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
private void setNameField(ImakerProperties prop) {
|
|
399 |
// fConfigWidget.setText(prop.getFilename());
|
|
400 |
}
|
|
401 |
|
|
402 |
public String handleRunPressed() {
|
|
403 |
String item = getSelectedItem();
|
|
404 |
tabPreferences.runPressed(item);
|
|
405 |
return item;
|
|
406 |
}
|
|
407 |
|
|
408 |
public String getSelectedItem() {
|
|
409 |
int index = fConfigWidget.getSelectionIndex();
|
|
410 |
return fConfigWidget.getItem(index);
|
|
411 |
}
|
|
412 |
|
|
413 |
public Button getFRevertButton() {
|
|
414 |
return fRevertButton;
|
|
415 |
}
|
|
416 |
|
|
417 |
}
|