blob: 4c569cfcd26589a3c0ae2110433ec05ea48307d4 (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2007 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;
import java.io.File;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.IWorkbenchAdapter;
/**
* Workbench adapter for source elements.
*
* @since 3.0
*/
public class SourceElementWorkbenchAdapter implements IWorkbenchAdapter {
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object o) {
if (o instanceof LocalFileStorage || o instanceof ZipEntryStorage) {
return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
}
return null;
}
@Override
public String getLabel(Object o) {
if (o instanceof LocalFileStorage) {
LocalFileStorage storage = (LocalFileStorage) o;
IPath path = storage.getFullPath();
return getQualifiedName(path);
}
if (o instanceof ZipEntryStorage) {
ZipEntryStorage storage = (ZipEntryStorage)o;
StringBuilder buffer = new StringBuilder();
buffer.append(storage.getZipEntry().getName());
buffer.append(" - "); //$NON-NLS-1$
buffer.append(storage.getArchive().getName());
return buffer.toString();
}
return IInternalDebugCoreConstants.EMPTY_STRING;
}
@Override
public Object getParent(Object o) {
return null;
}
public static String getQualifiedName(IPath path) {
StringBuilder buffer = new StringBuilder();
String[] segments = path.segments();
if (segments.length > 0) {
buffer.append(path.lastSegment());
if (segments.length > 1) {
buffer.append(" - "); //$NON-NLS-1$
if (path.getDevice() != null) {
buffer.append(path.getDevice());
}
for (int i = 0; i < segments.length - 1; i++) {
buffer.append(File.separatorChar);
buffer.append(segments[i]);
}
}
return buffer.toString();
}
return IInternalDebugCoreConstants.EMPTY_STRING;
}
}
|