47 import org.symbian.tools.tmw.debug.internal.ChromeDebugUtils; |
47 import org.symbian.tools.tmw.debug.internal.ChromeDebugUtils; |
48 import org.symbian.tools.tmw.debug.internal.IConstants; |
48 import org.symbian.tools.tmw.debug.internal.IConstants; |
49 import org.symbian.tools.tmw.debug.internal.Images; |
49 import org.symbian.tools.tmw.debug.internal.Images; |
50 |
50 |
51 public class WidgetBasicTab extends AbstractLaunchConfigurationTab { |
51 public class WidgetBasicTab extends AbstractLaunchConfigurationTab { |
52 private ComboViewer project; |
52 private ComboViewer project; |
53 private boolean canSave; |
53 private boolean canSave; |
54 |
54 |
55 @Override |
55 @Override |
56 public Image getImage() { |
56 public Image getImage() { |
57 return Images.getWrtIconImage(); |
57 return Images.getWrtIconImage(); |
58 } |
58 } |
59 |
59 |
60 public void createControl(Composite parent) { |
60 public void createControl(Composite parent) { |
61 Composite root = new Composite(parent, SWT.NONE); |
61 Composite root = new Composite(parent, SWT.NONE); |
62 FormLayout layout = new FormLayout(); |
62 FormLayout layout = new FormLayout(); |
63 layout.marginWidth = 5; |
63 layout.marginWidth = 5; |
64 layout.marginHeight = 5; |
64 layout.marginHeight = 5; |
65 layout.spacing = 5; |
65 layout.spacing = 5; |
66 root.setLayout(layout); |
66 root.setLayout(layout); |
67 |
67 |
68 Label label = new Label(root, SWT.NONE); |
68 Label label = new Label(root, SWT.NONE); |
69 label.setText("WRT Widget Project:"); |
69 label.setText("WRT Widget Project:"); |
70 |
70 |
71 project = new ComboViewer(root, SWT.READ_ONLY); |
71 project = new ComboViewer(root, SWT.READ_ONLY); |
72 project.setContentProvider(new ArrayContentProvider()); |
72 project.setContentProvider(new ArrayContentProvider()); |
73 project.setLabelProvider(new WorkbenchLabelProvider()); |
73 project.setLabelProvider(new WorkbenchLabelProvider()); |
74 |
74 |
75 FormData formData = new FormData(); |
75 FormData formData = new FormData(); |
76 formData.left = new FormAttachment(label); |
76 formData.left = new FormAttachment(label); |
77 formData.right = new FormAttachment(100, 0); |
77 formData.right = new FormAttachment(100, 0); |
78 project.getControl().setLayoutData(formData); |
78 project.getControl().setLayoutData(formData); |
79 |
79 |
80 project.setInput(getWidgetProjects()); |
80 project.setInput(getWidgetProjects()); |
81 project.addSelectionChangedListener(new ISelectionChangedListener() { |
81 project.addSelectionChangedListener(new ISelectionChangedListener() { |
82 public void selectionChanged(SelectionChangedEvent event) { |
82 public void selectionChanged(SelectionChangedEvent event) { |
83 setDirty(true); |
83 setDirty(true); |
84 validate(); |
84 validate(); |
85 } |
85 } |
86 }); |
86 }); |
87 setControl(root); |
87 setControl(root); |
88 } |
88 } |
89 |
89 |
90 private IProject[] getWidgetProjects() { |
90 private IProject[] getWidgetProjects() { |
91 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot() |
91 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); |
92 .getProjects(); |
92 LinkedList<IProject> filtered = new LinkedList<IProject>(); |
93 LinkedList<IProject> filtered = new LinkedList<IProject>(); |
93 for (IProject p : projects) { |
94 for (IProject p : projects) { |
|
95 if (TMWCore.create(p) != null) { |
94 if (TMWCore.create(p) != null) { |
96 filtered.add(p); |
95 filtered.add(p); |
97 } |
96 } |
98 } |
97 } |
99 return filtered.toArray(new IProject[filtered.size()]); |
98 return filtered.toArray(new IProject[filtered.size()]); |
100 } |
99 } |
101 |
100 |
102 public String getName() { |
101 public String getName() { |
103 return "WRT Widget"; |
102 return "WRT Widget"; |
104 } |
103 } |
105 |
104 |
106 public void initializeFrom(ILaunchConfiguration configuration) { |
105 public void initializeFrom(ILaunchConfiguration configuration) { |
107 project.setSelection(getSelectedProject(configuration), true); |
106 project.setSelection(getSelectedProject(configuration), true); |
108 validate(); |
107 validate(); |
109 setErrorMessage(null); |
108 setErrorMessage(null); |
110 } |
109 } |
111 |
110 |
112 private ISelection getSelectedProject(ILaunchConfiguration configuration) { |
111 private ISelection getSelectedProject(ILaunchConfiguration configuration) { |
113 ISelection selected = StructuredSelection.EMPTY; |
112 ISelection selected = StructuredSelection.EMPTY; |
114 try { |
113 try { |
115 String projectName = configuration.getAttribute( |
114 String projectName = configuration.getAttribute(IConstants.PROP_PROJECT_NAME, (String) null); |
116 IConstants.PROP_PROJECT_NAME, (String) null); |
115 if (projectName != null) { |
117 if (projectName != null) { |
116 IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); |
118 IProject p = ResourcesPlugin.getWorkspace().getRoot() |
117 if (p.isAccessible()) { |
119 .getProject(projectName); |
118 selected = new StructuredSelection(p); |
120 if (p.isAccessible()) { |
119 } |
121 selected = new StructuredSelection(p); |
120 } |
122 } |
121 } catch (CoreException e) { |
123 } |
122 Activator.log(e); |
124 } catch (CoreException e) { |
123 } |
125 Activator.log(e); |
124 return selected; |
126 } |
125 } |
127 return selected; |
|
128 } |
|
129 |
126 |
130 @Override |
127 @Override |
131 public boolean canSave() { |
128 public boolean canSave() { |
132 return canSave; |
129 return canSave; |
133 } |
130 } |
134 |
131 |
135 private void validate() { |
132 private void validate() { |
136 String error = null; |
133 String error = null; |
137 if (getWidgetProjects().length == 0) { |
134 if (getWidgetProjects().length == 0) { |
138 error = "No WRT widget projects found in the workspace"; |
135 error = "No WRT widget projects found in the workspace"; |
139 } else if (project.getSelection().isEmpty()) { |
136 } else if (project.getSelection().isEmpty()) { |
140 error = "Select WRT widget project to debug"; |
137 error = "Select WRT widget project to debug"; |
141 } else if (ChromeDebugUtils.getChromeExecutible() == null) { |
138 } else if (ChromeDebugUtils.getChromeExecutible() == null) { |
142 error = "No Chrome browser configured in the preferences"; |
139 error = "No Chrome browser configured in the preferences"; |
143 } |
140 } |
144 canSave = error == null; |
141 canSave = error == null; |
145 setErrorMessage(error); |
142 setErrorMessage(error); |
146 getLaunchConfigurationDialog().updateButtons(); |
143 getLaunchConfigurationDialog().updateButtons(); |
147 } |
144 } |
148 |
145 |
149 public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
146 public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
150 ISelection selection = project.getSelection(); |
147 ISelection selection = project.getSelection(); |
151 if (selection.isEmpty()) { |
148 if (selection.isEmpty()) { |
152 setDefaults(configuration); |
149 setDefaults(configuration); |
153 } else { |
150 } else { |
154 IProject p = (IProject) ((IStructuredSelection) selection) |
151 IProject p = (IProject) ((IStructuredSelection) selection).getFirstElement(); |
155 .getFirstElement(); |
152 configuration.setAttribute(IConstants.PROP_PROJECT_NAME, p.getName()); |
156 configuration.setAttribute(IConstants.PROP_PROJECT_NAME, p |
153 configuration.setMappedResources(new IResource[] { p }); |
157 .getName()); |
154 } |
158 configuration.setMappedResources(new IResource[] { p }); |
155 } |
159 } |
|
160 } |
|
161 |
156 |
162 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
157 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
163 configuration.removeAttribute(IConstants.PROP_PROJECT_NAME); |
158 configuration.removeAttribute(IConstants.PROP_PROJECT_NAME); |
164 } |
159 } |
165 |
160 |
166 @Override |
161 @Override |
167 public boolean isValid(ILaunchConfiguration launchConfig) { |
162 public boolean isValid(ILaunchConfiguration launchConfig) { |
168 return !getSelectedProject(launchConfig).isEmpty(); |
163 return !getSelectedProject(launchConfig).isEmpty(); |
169 } |
164 } |
170 } |
165 } |