KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > SourceElementWorkbenchAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.sourcelookup;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
17 import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.ui.ISharedImages;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.model.IWorkbenchAdapter;
22
23 /**
24  * Workbench adapter for source elements.
25  *
26  * @since 3.0
27  */

28 public class SourceElementWorkbenchAdapter implements IWorkbenchAdapter {
29     /* (non-Javadoc)
30      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
31      */

32     public Object JavaDoc[] getChildren(Object JavaDoc o) {
33         return null;
34     }
35     /* (non-Javadoc)
36      * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
37      */

38     public ImageDescriptor getImageDescriptor(Object JavaDoc o) {
39         if (o instanceof LocalFileStorage || o instanceof ZipEntryStorage) {
40             return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
41         }
42         return null;
43     }
44     /* (non-Javadoc)
45      * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
46      */

47     public String JavaDoc getLabel(Object JavaDoc o) {
48         if (o instanceof LocalFileStorage) {
49             LocalFileStorage storage = (LocalFileStorage) o;
50             IPath path = storage.getFullPath();
51             return getQualifiedName(path);
52         }
53         if (o instanceof ZipEntryStorage) {
54             ZipEntryStorage storage = (ZipEntryStorage)o;
55             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
56             buffer.append(storage.getZipEntry().getName());
57             buffer.append(" - "); //$NON-NLS-1$
58
buffer.append(storage.getArchive().getName());
59             return buffer.toString();
60         }
61         return ""; //$NON-NLS-1$
62
}
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
65      */

66     public Object JavaDoc getParent(Object JavaDoc o) {
67         return null;
68     }
69     
70     public static String JavaDoc getQualifiedName(IPath path) {
71         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
72         String JavaDoc[] segments = path.segments();
73         if (segments.length > 0) {
74             buffer.append(path.lastSegment());
75             if (segments.length > 1) {
76                 buffer.append(" - "); //$NON-NLS-1$
77
if (path.getDevice() != null) {
78                     buffer.append(path.getDevice());
79                 }
80                 for (int i = 0; i < segments.length - 1; i++) {
81                     buffer.append(File.separatorChar);
82                     buffer.append(segments[i]);
83                 }
84             }
85             return buffer.toString();
86         }
87         return ""; //$NON-NLS-1$
88
}
89 }
90
Popular Tags