1 /******************************************************************************* |
|
2 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 *******************************************************************************/ |
|
19 package org.symbian.tools.wrttools.debug.ui.launch; |
|
20 |
|
21 import java.util.LinkedList; |
|
22 |
|
23 import org.eclipse.core.resources.IProject; |
|
24 import org.eclipse.core.resources.IResource; |
|
25 import org.eclipse.core.resources.ResourcesPlugin; |
|
26 import org.eclipse.core.runtime.CoreException; |
|
27 import org.eclipse.debug.core.ILaunchConfiguration; |
|
28 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
29 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
|
30 import org.eclipse.jface.viewers.ArrayContentProvider; |
|
31 import org.eclipse.jface.viewers.ComboViewer; |
|
32 import org.eclipse.jface.viewers.ISelection; |
|
33 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
34 import org.eclipse.jface.viewers.IStructuredSelection; |
|
35 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
36 import org.eclipse.jface.viewers.StructuredSelection; |
|
37 import org.eclipse.swt.SWT; |
|
38 import org.eclipse.swt.graphics.Image; |
|
39 import org.eclipse.swt.layout.FormAttachment; |
|
40 import org.eclipse.swt.layout.FormData; |
|
41 import org.eclipse.swt.layout.FormLayout; |
|
42 import org.eclipse.swt.widgets.Composite; |
|
43 import org.eclipse.swt.widgets.Label; |
|
44 import org.eclipse.ui.model.WorkbenchLabelProvider; |
|
45 import org.symbian.tools.wrttools.debug.internal.Activator; |
|
46 import org.symbian.tools.wrttools.debug.internal.ChromeDebugUtils; |
|
47 import org.symbian.tools.wrttools.debug.internal.IConstants; |
|
48 import org.symbian.tools.wrttools.debug.internal.Images; |
|
49 import org.symbian.tools.wrttools.util.ProjectUtils; |
|
50 |
|
51 public class WidgetBasicTab extends AbstractLaunchConfigurationTab { |
|
52 private ComboViewer project; |
|
53 private boolean canSave; |
|
54 |
|
55 @Override |
|
56 public Image getImage() { |
|
57 return Images.getWrtIconImage(); |
|
58 } |
|
59 |
|
60 public void createControl(Composite parent) { |
|
61 Composite root = new Composite(parent, SWT.NONE); |
|
62 FormLayout layout = new FormLayout(); |
|
63 layout.marginWidth = 5; |
|
64 layout.marginHeight = 5; |
|
65 layout.spacing = 5; |
|
66 root.setLayout(layout); |
|
67 |
|
68 Label label = new Label(root, SWT.NONE); |
|
69 label.setText("WRT Widget Project:"); |
|
70 |
|
71 project = new ComboViewer(root, SWT.READ_ONLY); |
|
72 project.setContentProvider(new ArrayContentProvider()); |
|
73 project.setLabelProvider(new WorkbenchLabelProvider()); |
|
74 |
|
75 FormData formData = new FormData(); |
|
76 formData.left = new FormAttachment(label); |
|
77 formData.right = new FormAttachment(100, 0); |
|
78 project.getControl().setLayoutData(formData); |
|
79 |
|
80 project.setInput(getWidgetProjects()); |
|
81 project.addSelectionChangedListener(new ISelectionChangedListener() { |
|
82 public void selectionChanged(SelectionChangedEvent event) { |
|
83 setDirty(true); |
|
84 validate(); |
|
85 } |
|
86 }); |
|
87 setControl(root); |
|
88 } |
|
89 |
|
90 private IProject[] getWidgetProjects() { |
|
91 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot() |
|
92 .getProjects(); |
|
93 LinkedList<IProject> filtered = new LinkedList<IProject>(); |
|
94 for (IProject p : projects) { |
|
95 if (ProjectUtils.hasWrtNature(p)) { |
|
96 filtered.add(p); |
|
97 } |
|
98 } |
|
99 return filtered.toArray(new IProject[filtered.size()]); |
|
100 } |
|
101 |
|
102 public String getName() { |
|
103 return "WRT Widget"; |
|
104 } |
|
105 |
|
106 public void initializeFrom(ILaunchConfiguration configuration) { |
|
107 project.setSelection(getSelectedProject(configuration), true); |
|
108 validate(); |
|
109 setErrorMessage(null); |
|
110 } |
|
111 |
|
112 private ISelection getSelectedProject(ILaunchConfiguration configuration) { |
|
113 ISelection selected = StructuredSelection.EMPTY; |
|
114 try { |
|
115 String projectName = configuration.getAttribute( |
|
116 IConstants.PROP_PROJECT_NAME, (String) null); |
|
117 if (projectName != null) { |
|
118 IProject p = ResourcesPlugin.getWorkspace().getRoot() |
|
119 .getProject(projectName); |
|
120 if (p.isAccessible()) { |
|
121 selected = new StructuredSelection(p); |
|
122 } |
|
123 } |
|
124 } catch (CoreException e) { |
|
125 Activator.log(e); |
|
126 } |
|
127 return selected; |
|
128 } |
|
129 |
|
130 @Override |
|
131 public boolean canSave() { |
|
132 return canSave; |
|
133 } |
|
134 |
|
135 private void validate() { |
|
136 String error = null; |
|
137 if (getWidgetProjects().length == 0) { |
|
138 error = "No WRT widget projects found in the workspace"; |
|
139 } else if (project.getSelection().isEmpty()) { |
|
140 error = "Select WRT widget project to debug"; |
|
141 } else if (ChromeDebugUtils.getChromeExecutible() == null) { |
|
142 error = "No Chrome browser configured in the preferences"; |
|
143 } |
|
144 canSave = error == null; |
|
145 setErrorMessage(error); |
|
146 getLaunchConfigurationDialog().updateButtons(); |
|
147 } |
|
148 |
|
149 public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
|
150 ISelection selection = project.getSelection(); |
|
151 if (selection.isEmpty()) { |
|
152 setDefaults(configuration); |
|
153 } else { |
|
154 IProject p = (IProject) ((IStructuredSelection) selection) |
|
155 .getFirstElement(); |
|
156 configuration.setAttribute(IConstants.PROP_PROJECT_NAME, p |
|
157 .getName()); |
|
158 configuration.setMappedResources(new IResource[] { p }); |
|
159 } |
|
160 } |
|
161 |
|
162 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
|
163 configuration.removeAttribute(IConstants.PROP_PROJECT_NAME); |
|
164 } |
|
165 |
|
166 @Override |
|
167 public boolean isValid(ILaunchConfiguration launchConfig) { |
|
168 return !getSelectedProject(launchConfig).isEmpty(); |
|
169 } |
|
170 } |
|