Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3029f726d44d9b1e0112b67988d3a2486801251c (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
/*******************************************************************************
 * Copyright (c) 2003, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.sourcelookup.browsers;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

/**
 * The browser for adding an external archive.
 * @since 3.0
 */
public class ExternalArchiveSourceContainerBrowser extends AbstractSourceContainerBrowser {

	private static final String ROOT_DIR = ExternalArchiveSourceContainerBrowser.class.getName() + ".rootDir";   //$NON-NLS-1$

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.sourcelookup.ISourceContainerBrowser#createSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.ILaunchConfiguration)
	 */
	@Override
	public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
		FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI | SWT.SHEET);
		String rootDir = DebugUIPlugin.getDefault().getDialogSettings().get(ROOT_DIR);
		dialog.setText(SourceLookupUIMessages.ExternalArchiveSourceContainerBrowser_2);
		dialog.setFilterExtensions(new String[]{"*.jar;*.zip"});  //$NON-NLS-1$
		if (rootDir != null) {
			dialog.setFilterPath(rootDir);
		}
		dialog.open();
		String[] fileNames= dialog.getFileNames();
		int nChosen= fileNames.length;
		if (nChosen > 0) {
			rootDir = dialog.getFilterPath();
			IPath filterPath= new Path(rootDir);
			ISourceContainer[] containers= new ISourceContainer[nChosen];
			for (int i= 0; i < nChosen; i++) {
				IPath path= filterPath.append(fileNames[i]).makeAbsolute();
				// TODO: configure auto-detect
				containers[i]= new ExternalArchiveSourceContainer(path.toOSString(), true);
			}
			DebugUIPlugin.getDefault().getDialogSettings().put(ROOT_DIR, rootDir);
			return containers;
		}
		return new ISourceContainer[0];
	}

}

Back to the top