diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java | 371 |
1 files changed, 371 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java new file mode 100644 index 0000000..6d7c440 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java | |||
@@ -0,0 +1,371 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel 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 | * Intel - Initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.wizards.install; | ||
12 | |||
13 | import java.net.URI; | ||
14 | |||
15 | import org.eclipse.core.filesystem.URIUtil; | ||
16 | import org.eclipse.core.resources.IProject; | ||
17 | import org.eclipse.core.runtime.Path; | ||
18 | import org.eclipse.core.runtime.Platform; | ||
19 | import org.eclipse.jface.operation.IRunnableContext; | ||
20 | import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea; | ||
21 | import org.eclipse.ptp.remote.core.IRemoteFileManager; | ||
22 | import org.eclipse.swt.SWT; | ||
23 | import org.eclipse.swt.events.ModifyEvent; | ||
24 | import org.eclipse.swt.events.ModifyListener; | ||
25 | import org.eclipse.swt.events.SelectionAdapter; | ||
26 | import org.eclipse.swt.events.SelectionEvent; | ||
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.Group; | ||
33 | import org.eclipse.swt.widgets.Label; | ||
34 | import org.eclipse.swt.widgets.Text; | ||
35 | import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; | ||
36 | import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; | ||
37 | |||
38 | import java.net.URI; | ||
39 | |||
40 | import org.eclipse.core.filesystem.URIUtil; | ||
41 | import org.eclipse.core.resources.IProject; | ||
42 | import org.eclipse.core.runtime.Path; | ||
43 | import org.eclipse.core.runtime.Platform; | ||
44 | import org.eclipse.jface.operation.IRunnableContext; | ||
45 | import org.eclipse.ptp.rdt.ui.messages.Messages; | ||
46 | //import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider; | ||
47 | //import org.eclipse.ptp.rdt.core.serviceproviders. | ||
48 | import org.eclipse.ptp.remote.core.IRemoteConnection; | ||
49 | import org.eclipse.ptp.remote.core.IRemoteFileManager; | ||
50 | import org.eclipse.ptp.remote.core.IRemoteServices; | ||
51 | import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager; | ||
52 | import org.eclipse.ptp.remote.ui.IRemoteUIConstants; | ||
53 | import org.eclipse.ptp.remote.ui.IRemoteUIFileManager; | ||
54 | import org.eclipse.ptp.remote.ui.IRemoteUIServices; | ||
55 | import org.eclipse.ptp.remote.ui.RemoteUIServices; | ||
56 | import org.eclipse.ptp.remote.ui.widgets.RemoteConnectionWidget; | ||
57 | import org.eclipse.swt.SWT; | ||
58 | import org.eclipse.swt.events.ModifyEvent; | ||
59 | import org.eclipse.swt.events.ModifyListener; | ||
60 | import org.eclipse.swt.events.SelectionAdapter; | ||
61 | import org.eclipse.swt.events.SelectionEvent; | ||
62 | import org.eclipse.swt.layout.GridData; | ||
63 | import org.eclipse.swt.layout.GridLayout; | ||
64 | import org.eclipse.swt.widgets.Button; | ||
65 | import org.eclipse.swt.widgets.Composite; | ||
66 | import org.eclipse.swt.widgets.Control; | ||
67 | import org.eclipse.swt.widgets.Group; | ||
68 | import org.eclipse.swt.widgets.Label; | ||
69 | import org.eclipse.swt.widgets.Text; | ||
70 | import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; | ||
71 | import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; | ||
72 | |||
73 | |||
74 | public class BBCRemoteProjectContentsLocationArea { | ||
75 | |||
76 | /** | ||
77 | * IErrorMessageReporter is an interface for type that allow message | ||
78 | * reporting. | ||
79 | * | ||
80 | */ | ||
81 | public interface IErrorMessageReporter { | ||
82 | /** | ||
83 | * Report the error message | ||
84 | * | ||
85 | * @param errorMessage | ||
86 | * String or <code>null</code>. If the errorMessage is null | ||
87 | * then clear any error state. | ||
88 | * @param infoOnly | ||
89 | * the message is an informational message, but the dialog | ||
90 | * cannot continue | ||
91 | * | ||
92 | */ | ||
93 | public void reportError(String errorMessage, boolean infoOnly); | ||
94 | } | ||
95 | |||
96 | private static final String FILE_SCHEME = "file"; //$NON-NLS-1$ | ||
97 | |||
98 | private IProject fExistingProject; | ||
99 | |||
100 | private final IErrorMessageReporter fErrorReporter; | ||
101 | |||
102 | private final IRunnableContext fContext; | ||
103 | |||
104 | //private RemoteBuildServiceProvider fProvider; | ||
105 | |||
106 | private IRemoteConnection fSelectedConnection; | ||
107 | |||
108 | private String fProjectName = IDEResourceInfoUtils.EMPTY_STRING; | ||
109 | |||
110 | private Button fBrowseButton; | ||
111 | |||
112 | private Text fLocationText; | ||
113 | |||
114 | private RemoteConnectionWidget fRemoteConnectionWidget; | ||
115 | |||
116 | // public RemoteProjectContentsLocationArea(IServiceProvider provider, | ||
117 | // Composite composite) { | ||
118 | // if(provider instanceof RemoteBuildServiceProvider) | ||
119 | // fProvider = (RemoteBuildServiceProvider) provider; | ||
120 | // else | ||
121 | // throw new IllegalArgumentException(); // should never happen | ||
122 | // createContents(composite); | ||
123 | // } | ||
124 | /** | ||
125 | * @since 3.1 | ||
126 | */ | ||
127 | public BBCRemoteProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite, IRunnableContext context) { | ||
128 | fErrorReporter = reporter; | ||
129 | fContext = context; | ||
130 | createContents(composite); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Check if the entry in the widget location is valid. If it is valid return | ||
135 | * null. Otherwise return a string that indicates the problem. | ||
136 | * | ||
137 | * @return String | ||
138 | */ | ||
139 | public String checkValidLocation() { | ||
140 | |||
141 | String locationFieldContents = fLocationText.getText(); | ||
142 | if (locationFieldContents.length() == 0) { | ||
143 | return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty; | ||
144 | } | ||
145 | |||
146 | URI newPath = getProjectLocationURI(); | ||
147 | if (newPath == null) { | ||
148 | return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError; | ||
149 | } | ||
150 | |||
151 | if (fExistingProject != null) { | ||
152 | URI projectPath = fExistingProject.getLocationURI(); | ||
153 | if (projectPath != null && URIUtil.equals(projectPath, newPath)) { | ||
154 | return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | return null; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * Return the browse button. Usually referenced in order to set the layout | ||
163 | * data for a dialog. | ||
164 | * | ||
165 | * @return Button | ||
166 | */ | ||
167 | public Button[] getButtons() { | ||
168 | return new Button[] { fBrowseButton, fRemoteConnectionWidget.getButton() }; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Returns the name of the selected connection. | ||
173 | */ | ||
174 | public IRemoteConnection getConnection() { | ||
175 | return fSelectedConnection; | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Return the location for the project. | ||
180 | * | ||
181 | * @return String | ||
182 | */ | ||
183 | public String getProjectLocation() { | ||
184 | return fLocationText.getText(); | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * Get the URI for the location field if possible. | ||
189 | * | ||
190 | * @return URI or <code>null</code> if it is not valid. | ||
191 | */ | ||
192 | public URI getProjectLocationURI() { | ||
193 | if (fSelectedConnection == null) | ||
194 | return null; | ||
195 | return fSelectedConnection.getRemoteServices().getFileManager(fSelectedConnection).toURI(fLocationText.getText()); | ||
196 | } | ||
197 | |||
198 | public IRemoteConnection getRemoteConnection() { | ||
199 | return fSelectedConnection; | ||
200 | } | ||
201 | |||
202 | public IRemoteServices getRemoteServices() { | ||
203 | if (fSelectedConnection != null) | ||
204 | return fSelectedConnection.getRemoteServices(); | ||
205 | return null; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * Return whether or not we are currently showing the default location for | ||
210 | * the project. | ||
211 | * | ||
212 | * @return boolean | ||
213 | */ | ||
214 | public boolean isDefault() { | ||
215 | // return useDefaultsButton.getSelection(); | ||
216 | return false; | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Set the project to base the contents off of. | ||
221 | * | ||
222 | * @param existingProject | ||
223 | */ | ||
224 | public void setExistingProject(IProject existingProject) { | ||
225 | fProjectName = existingProject.getName(); | ||
226 | fExistingProject = existingProject; | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * Set the text to the default or clear it if not using the defaults. | ||
231 | * | ||
232 | * @param newName | ||
233 | * the name of the project to use. If <code>null</code> use the | ||
234 | * existing project name. | ||
235 | */ | ||
236 | public void updateProjectName(String newName) { | ||
237 | fProjectName = newName; | ||
238 | if (isDefault()) { | ||
239 | fLocationText.setText(getDefaultPathDisplayString()); | ||
240 | } | ||
241 | |||
242 | } | ||
243 | |||
244 | /** | ||
245 | * Attempt to open a connection. | ||
246 | */ | ||
247 | private void checkConnection() { | ||
248 | IRemoteUIConnectionManager mgr = getUIConnectionManager(); | ||
249 | if (mgr != null) { | ||
250 | mgr.openConnectionWithProgress(fRemoteConnectionWidget.getShell(), fContext, fSelectedConnection); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Return the path we are going to display. If it is a file URI then remove | ||
256 | * the file prefix. | ||
257 | * | ||
258 | * Only do this if the connection is open. Otherwise we will attempt to | ||
259 | * connect to the first machine in the list, which is annoying. | ||
260 | * | ||
261 | * @return String | ||
262 | */ | ||
263 | private String getDefaultPathDisplayString() { | ||
264 | if (getRemoteConnection() != null && getRemoteConnection().isOpen()) { | ||
265 | IRemoteFileManager fileMgr = fSelectedConnection.getRemoteServices().getFileManager(getRemoteConnection()); | ||
266 | URI defaultURI = fileMgr.toURI(getRemoteConnection().getWorkingDirectory()); | ||
267 | |||
268 | // Handle files specially. Assume a file if there is no project to | ||
269 | // query | ||
270 | if (defaultURI != null && defaultURI.getScheme().equals(FILE_SCHEME)) { | ||
271 | return Platform.getLocation().append(fProjectName).toOSString(); | ||
272 | } | ||
273 | if (defaultURI == null) { | ||
274 | return ""; //$NON-NLS-1$ | ||
275 | } | ||
276 | return new Path(defaultURI.getPath()).append(fProjectName).toOSString(); | ||
277 | } | ||
278 | return ""; //$NON-NLS-1$ | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * @return | ||
283 | */ | ||
284 | private IRemoteUIConnectionManager getUIConnectionManager() { | ||
285 | IRemoteUIConnectionManager connectionManager = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices()) | ||
286 | .getUIConnectionManager(); | ||
287 | return connectionManager; | ||
288 | } | ||
289 | |||
290 | private void handleConnectionSelected() { | ||
291 | fSelectedConnection = fRemoteConnectionWidget.getConnection(); | ||
292 | fLocationText.setText(getDefaultPathDisplayString()); | ||
293 | } | ||
294 | |||
295 | protected Control createContents(Composite parent) { | ||
296 | Group container = new Group(parent, SWT.SHADOW_ETCHED_IN); | ||
297 | |||
298 | GridLayout layout = new GridLayout(); | ||
299 | layout.numColumns = 3; | ||
300 | container.setLayout(layout); | ||
301 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); | ||
302 | container.setLayoutData(gd); | ||
303 | |||
304 | fRemoteConnectionWidget = new RemoteConnectionWidget(container, SWT.NONE, null, RemoteConnectionWidget.FLAG_FORCE_PROVIDER_SELECTION, null); | ||
305 | gd = new GridData(); | ||
306 | gd.horizontalSpan = 3; | ||
307 | fRemoteConnectionWidget.setLayoutData(gd); | ||
308 | fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { | ||
309 | @Override | ||
310 | public void widgetSelected(SelectionEvent e) { | ||
311 | handleConnectionSelected(); | ||
312 | } | ||
313 | }); | ||
314 | |||
315 | Label locationLabel = new Label(container, SWT.LEFT); | ||
316 | locationLabel.setText(Messages.getString("RemoteProjectContentsLocationArea.3")); //$NON-NLS-1$ | ||
317 | |||
318 | fLocationText = new Text(container, SWT.SINGLE | SWT.BORDER); | ||
319 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
320 | gd.horizontalSpan = 1; | ||
321 | gd.grabExcessHorizontalSpace = true; | ||
322 | gd.widthHint = 250; | ||
323 | fLocationText.setLayoutData(gd); | ||
324 | fLocationText.addModifyListener(new ModifyListener() { | ||
325 | public void modifyText(ModifyEvent e) { | ||
326 | fErrorReporter.reportError(checkValidLocation(), false); | ||
327 | } | ||
328 | }); | ||
329 | |||
330 | // new connection button | ||
331 | fBrowseButton = new Button(container, SWT.PUSH); | ||
332 | fBrowseButton.setText(Messages.getString("RemoteProjectContentsLocationArea.4")); //$NON-NLS-1$ | ||
333 | fBrowseButton.addSelectionListener(new SelectionAdapter() { | ||
334 | @Override | ||
335 | public void widgetSelected(SelectionEvent e) { | ||
336 | if (fSelectedConnection != null) { | ||
337 | checkConnection(); | ||
338 | if (fSelectedConnection.isOpen()) { | ||
339 | IRemoteUIServices remoteUIServices = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices()); | ||
340 | if (remoteUIServices != null) { | ||
341 | IRemoteUIFileManager fileMgr = remoteUIServices.getUIFileManager(); | ||
342 | if (fileMgr != null) { | ||
343 | fileMgr.setConnection(fSelectedConnection); | ||
344 | String correctPath = fLocationText.getText(); | ||
345 | String selectedPath = fileMgr.browseDirectory( | ||
346 | fLocationText.getShell(), | ||
347 | Messages.getString("RemoteProjectContentsLocationArea.5", fSelectedConnection.getName()), correctPath, IRemoteUIConstants.NONE); //$NON-NLS-1$ | ||
348 | if (selectedPath != null) { | ||
349 | fLocationText.setText(selectedPath); | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | }); | ||
357 | |||
358 | return container; | ||
359 | } | ||
360 | |||
361 | /* | ||
362 | * (non-Javadoc) | ||
363 | * | ||
364 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | ||
365 | */ | ||
366 | protected void okPressed() { | ||
367 | // set the connection | ||
368 | //fProvider.setRemoteToolsConnection(fSelectedConnection); | ||
369 | |||
370 | } | ||
371 | } | ||