Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 55a9f2d3e798dc084ce9a761064fb25f7ba49070 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2007, 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - Initial API and implementation
 *     Markus Schorn - Adapted for TCF remote service
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.remote.ui;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.window.Window;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.ui.IRemoteUIFileService;
import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.te.tcf.remote.core.TCFFileStore;

public class TCFUIFileService implements IRemoteUIFileService {
	private IRemoteConnection fConnection = null;
	private boolean fShowConnections = false;
	private final IRemoteConnectionType fConnectionType;

	public TCFUIFileService(IRemoteConnectionType connectionType) {
		fConnectionType = connectionType;
	}

	@Override
	public IRemoteConnectionType getConnectionType() {
		return fConnectionType;
	}

	@Override
	public String browseDirectory(Shell shell, String message, String filterPath, int flags) {
		RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.SINGLE);
		browser.setType(RemoteResourceBrowser.DIRECTORY_BROWSER);
		browser.setInitialPath(filterPath);
		browser.setTitle(message);
		browser.showConnections(fShowConnections);
		browser.setConnection(fConnection);
		if (browser.open() == Window.CANCEL) {
			return null;
		}
		fConnection = browser.getConnection();
		IFileStore resource = browser.getResource();
		if (resource == null) {
			return null;
		}
		return TCFFileStore.toPath(resource.toURI());
	}

	@Override
	public String browseFile(Shell shell, String message, String filterPath, int flags) {
		RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.SINGLE);
		browser.setType(RemoteResourceBrowser.FILE_BROWSER);
		browser.setInitialPath(filterPath);
		browser.setTitle(message);
		browser.showConnections(fShowConnections);
		browser.setConnection(fConnection);
		if (browser.open() == Window.CANCEL) {
			return null;
		}
		fConnection = browser.getConnection();
		IFileStore resource = browser.getResource();
		if (resource == null) {
			return null;
		}
		return TCFFileStore.toPath(resource.toURI());
	}

	@Override
	public List<String> browseFiles(Shell shell, String message, String filterPath, int flags) {
		RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.MULTI);
		browser.setType(RemoteResourceBrowser.FILE_BROWSER);
		browser.setInitialPath(filterPath);
		browser.setTitle(message);
		browser.showConnections(fShowConnections);
		browser.setConnection(fConnection);
		if (browser.open() == Window.CANCEL) {
			return null;
		}
		fConnection = browser.getConnection();
		List<String> paths = new ArrayList<String>();
		for (IFileStore store : browser.getResources()) {
			paths.add(TCFFileStore.toPath(store.toURI()));
		}
		return paths;
	}

	@Override
	public IRemoteConnection getConnection() {
		return fConnection;
	}

	@Override
	public void setConnection(IRemoteConnection connection) {
		this.fConnection = connection;
	}

	@Override
	public void showConnections(boolean enable) {
		fShowConnections = enable;
	}
}

Back to the top