]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / wizards / buildpaths / CPVariableElementLabelProvider.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.wizards.buildpaths;
12
13import java.util.ArrayList;
14
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.graphics.Color;
17import org.eclipse.swt.graphics.Image;
18import org.eclipse.swt.widgets.Display;
19
20import org.eclipse.core.runtime.IPath;
21
22import org.eclipse.jface.resource.ImageRegistry;
23import org.eclipse.jface.viewers.DecorationOverlayIcon;
24import org.eclipse.jface.viewers.IColorProvider;
25import org.eclipse.jface.viewers.IDecoration;
26import org.eclipse.jface.viewers.LabelProvider;
27
28import org.eclipse.ui.ISharedImages;
29import org.eclipse.ui.PlatformUI;
30
31import org.eclipse.jdt.internal.corext.util.Messages;
32
33import org.eclipse.jdt.internal.ui.JavaPlugin;
34import org.eclipse.jdt.internal.ui.JavaPluginImages;
35import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
36import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
37
38
39public class CPVariableElementLabelProvider extends LabelProvider implements IColorProvider {
40
41 // shared, do not dispose:
42 private Image fJARImage;
43 private Image fFolderImage;
44 private Color fResolvedBackground;
45
46 private Image fDeprecatedJARImage;
47 private Image fDeprecatedFolderImage;
48
49 private boolean fHighlightReadOnly;
50
51 public CPVariableElementLabelProvider(boolean highlightReadOnly) {
52 ImageRegistry reg= JavaPlugin.getDefault().getImageRegistry();
53 fJARImage= reg.get(JavaPluginImages.IMG_OBJS_EXTJAR);
54 fFolderImage= PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
55
56 fDeprecatedJARImage= new DecorationOverlayIcon(fJARImage, JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_LEFT).createImage();
57 fDeprecatedFolderImage= new DecorationOverlayIcon(fFolderImage, JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_LEFT).createImage();
58
59 fHighlightReadOnly= highlightReadOnly;
60 fResolvedBackground= null;
61 }
62
63 /*
64 * @see LabelProvider#getImage(java.lang.Object)
65 */
66 @Override
67 public Image getImage(Object element) {
68 if (element instanceof CPVariableElement) {
69 CPVariableElement curr= (CPVariableElement) element;
70 IPath path= curr.getPath();
71 if (path.toFile().isFile()) {
72 return curr.isDeprecated() ? fDeprecatedJARImage : fJARImage;
73 }
74 return curr.isDeprecated() ? fDeprecatedFolderImage : fFolderImage;
75 }
76 return super.getImage(element);
77 }
78
79 /*
80 * @see LabelProvider#getText(java.lang.Object)
81 */
82 @Override
83 public String getText(Object element) {
84 if (element instanceof CPVariableElement) {
85 CPVariableElement curr= (CPVariableElement)element;
86 String name= curr.getName();
87 IPath path= curr.getPath();
88
89 String result= name;
90 ArrayList<String> restrictions= new ArrayList<String>(2);
91
92 if (curr.isReadOnly() && fHighlightReadOnly) {
93 restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_read_only);
94 }
95 if (curr.isDeprecated()) {
96 restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_deprecated);
97 }
98 if (restrictions.size() == 1) {
99 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_one_restriction, new Object[] {result, restrictions.get(0)});
100 } else if (restrictions.size() == 2) {
101 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_two_restrictions, new Object[] {result, restrictions.get(0), restrictions.get(1)});
102 }
103
104 if (path != null) {
105 String appendix;
106 if (!path.isEmpty()) {
107 appendix= BasicElementLabels.getPathLabel(path, true);
108 } else {
109 appendix= NewWizardMessages.CPVariableElementLabelProvider_empty;
110 }
111 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_appendix, new Object[] {result, appendix});
112 }
113
114 return result;
115 }
116
117
118 return super.getText(element);
119 }
120
121 /* (non-Javadoc)
122 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
123 */
124 public Color getForeground(Object element) {
125 return null;
126 }
127
128 /* (non-Javadoc)
129 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
130 */
131 public Color getBackground(Object element) {
132 if (element instanceof CPVariableElement) {
133 CPVariableElement curr= (CPVariableElement) element;
134 if (fHighlightReadOnly && curr.isReadOnly()) {
135 if (fResolvedBackground == null) {
136 Display display= Display.getCurrent();
137 fResolvedBackground= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
138 }
139 return fResolvedBackground;
140 }
141 }
142 return null;
143 }
144
145 /* (non-Javadoc)
146 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
147 */
148 @Override
149 public void dispose() {
150 super.dispose();
151 fDeprecatedFolderImage.dispose();
152 fDeprecatedJARImage.dispose();
153 }
154
155}