1 11 package org.eclipse.ant.internal.ui.views; 12 13 import org.eclipse.ant.internal.ui.model.AntImageDescriptor; 14 import org.eclipse.ant.internal.ui.model.AntUIImages; 15 import org.eclipse.ant.internal.ui.model.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.views.elements.ProjectNode; 17 import org.eclipse.ant.internal.ui.views.elements.TargetNode; 18 import org.eclipse.jface.resource.CompositeImageDescriptor; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.viewers.IColorProvider; 21 import org.eclipse.jface.viewers.ILabelProvider; 22 import org.eclipse.jface.viewers.ILabelProviderListener; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.graphics.Color; 25 import org.eclipse.swt.graphics.Image; 26 import org.eclipse.swt.widgets.Display; 27 28 32 public class AntViewLabelProvider implements ILabelProvider, IColorProvider { 33 34 37 public Image getImage(Object element) { 38 if (element instanceof ProjectNode) { 39 ProjectNode project= (ProjectNode) element; 40 int flags = 0; 41 if (project.isErrorNode()) { 42 flags = flags | AntImageDescriptor.HAS_ERRORS; 43 } 44 CompositeImageDescriptor descriptor = new AntImageDescriptor(AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_PROJECT), flags); 45 return AntUIImages.getImage(descriptor); 46 } else if (element instanceof TargetNode) { 47 TargetNode target= (TargetNode) element; 48 int flags = 0; 49 ImageDescriptor base = null; 50 if (target.equals(target.getProject().getDefaultTarget())){ 51 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_DEFAULT_TARGET); 52 } else if (target.getDescription() == null) { 53 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET_INTERNAL); 54 } else { 55 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET); 56 } 57 if (target.isErrorNode()) { 58 flags = flags | AntImageDescriptor.HAS_ERRORS; 59 } 60 return AntUIImages.getImage(new AntImageDescriptor(base, flags)); 61 } 62 return null; 63 } 64 65 68 public String getText(Object element) { 69 if (element instanceof TargetNode) { 70 TargetNode node= (TargetNode)element; 71 StringBuffer name= new StringBuffer (node.getName()); 72 if (node.getName().equals(node.getProject().getDefaultTargetName())) { 73 name.append(AntViewMessages.getString("TargetNode.default")); } 75 return name.toString(); 76 } else if (element instanceof ProjectNode) { 77 ProjectNode project= (ProjectNode) element; 78 StringBuffer buffer= new StringBuffer (project.getName()); 79 String defaultTarget= project.getDefaultTargetName(); 80 if (defaultTarget != null) { 81 buffer.append(" [").append(defaultTarget).append(']'); } 83 return buffer.toString(); 84 } else { 85 return element.toString(); 86 } 87 } 88 89 92 public void addListener(ILabelProviderListener listener) { 93 } 94 95 98 public void dispose() { 99 } 100 101 104 public boolean isLabelProperty(Object element, String property) { 105 return false; 106 } 107 108 111 public void removeListener(ILabelProviderListener listener) { 112 } 113 114 117 public Color getForeground(Object element) { 118 if (element instanceof TargetNode) { 119 TargetNode target= (TargetNode)element; 120 if (target == target.getProject().getDefaultTarget()) { 121 return Display.getDefault().getSystemColor(SWT.COLOR_BLUE); 122 } 123 } 124 return null; 125 } 126 127 130 public Color getBackground(Object element) { 131 return null; 132 } 133 } 134 | Popular Tags |