1 11 12 package org.eclipse.ui.views.bookmarkexplorer; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.resource.JFaceResources; 18 import org.eclipse.jface.viewers.ITableLabelProvider; 19 import org.eclipse.jface.viewers.LabelProvider; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 23 import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages; 24 25 28 class BookmarkLabelProvider extends LabelProvider implements 29 ITableLabelProvider { 30 31 private Image image; 32 private ImageDescriptor desc; 33 34 final static int COLUMN_ICON = 0; 35 36 final static int COLUMN_DESCRIPTION = 1; 37 38 final static int COLUMN_RESOURCE = 2; 39 40 final static int COLUMN_FOLDER = 3; 41 42 final static int COLUMN_LOCATION = 4; 43 44 public BookmarkLabelProvider(BookmarkNavigator view) { 45 desc = IDEWorkbenchPlugin.getIDEImageDescriptor("obj16/bkmrk_tsk.gif"); image = JFaceResources.getResources().createImageWithDefault(desc); 47 } 48 49 52 public void dispose() { 53 if (image != null) { 54 JFaceResources.getResources().destroyImage(desc); 55 image = null; 56 } 57 } 58 59 62 public Image getImage(Object element) { 63 return image; 64 } 65 66 public String getColumnText(Object element, int columnIndex) { 67 if (!(element instanceof IMarker)) { 68 return ""; } 70 IMarker marker = (IMarker) element; 71 72 switch (columnIndex) { 73 case COLUMN_DESCRIPTION: 74 return marker.getAttribute(IMarker.MESSAGE, ""); case COLUMN_RESOURCE: 76 return marker.getResource().getName(); 77 case COLUMN_FOLDER: 78 return getContainerName(marker); 79 case COLUMN_LOCATION: { 80 int line = marker.getAttribute(IMarker.LINE_NUMBER, -1); 81 if (line == -1) { 82 return ""; } 84 return NLS.bind(BookmarkMessages.LineIndicator_text, String.valueOf(line)); 85 } 86 } 87 return ""; } 89 90 public Image getColumnImage(Object element, int index) { 91 if (index == COLUMN_ICON) { 92 return image; 93 } 94 return null; 95 } 96 97 100 public static String getContainerName(IMarker marker) { 101 IPath path = marker.getResource().getFullPath(); 102 int n = path.segmentCount() - 1; 103 if (n <= 0) { 105 return ""; } 107 int len = 0; 108 for (int i = 0; i < n; ++i) { 109 len += path.segment(i).length(); 110 } 111 if (n > 1) { 113 len += n - 1; 114 } 115 StringBuffer sb = new StringBuffer (len); 116 for (int i = 0; i < n; ++i) { 117 if (i != 0) { 118 sb.append('/'); 119 } 120 sb.append(path.segment(i)); 121 } 122 return sb.toString(); 123 } 124 } 125 | Popular Tags |