KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > nls > ModelChangeLabelProvider


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.pde.internal.ui.nls;
12
13 import org.eclipse.pde.core.plugin.IFragmentModel;
14 import org.eclipse.pde.core.plugin.IPluginModel;
15 import org.eclipse.pde.core.plugin.IPluginModelBase;
16 import org.eclipse.pde.internal.ui.PDELabelProvider;
17 import org.eclipse.pde.internal.ui.PDEPluginImages;
18 import org.eclipse.pde.internal.ui.PDEUIMessages;
19 import org.eclipse.swt.graphics.Image;
20
21 public class ModelChangeLabelProvider extends PDELabelProvider {
22     
23     private Image manifestImage;
24     private Image xmlImage;
25     
26     public ModelChangeLabelProvider() {
27         xmlImage = PDEPluginImages.DESC_PLUGIN_MF_OBJ.createImage();
28         manifestImage = PDEPluginImages.DESC_PAGE_OBJ.createImage();
29     }
30     
31     public String JavaDoc getText(Object JavaDoc obj) {
32         if (obj instanceof ModelChange)
33             return getObjectText(((ModelChange) obj).getParentModel().getPluginBase());
34         if (obj instanceof ModelChangeFile)
35             return getObjectText((ModelChangeFile)obj);
36         return super.getText(obj);
37     }
38     
39     private String JavaDoc getObjectText(ModelChangeFile pair) {
40         StringBuffer JavaDoc text = new StringBuffer JavaDoc(pair.getFile().getName());
41         int count = pair.getNumChanges();
42         text.append(" ["); //$NON-NLS-1$
43
text.append(count);
44         if (count == 1)
45             text.append(PDEUIMessages.ModelChangeLabelProvider_instance);
46         else
47             text.append(PDEUIMessages.ModelChangeLabelProvider_instances);
48         text.append("]"); //$NON-NLS-1$
49

50         return text.toString();
51     }
52
53     public Image getImage(Object JavaDoc obj) {
54         if (obj instanceof ModelChange) {
55             IPluginModelBase model = ((ModelChange)obj).getParentModel();
56             if (model instanceof IPluginModel)
57                 return getObjectImage(((IPluginModel) model).getPlugin(), false, false);
58             if (model instanceof IFragmentModel)
59                 return getObjectImage(((IFragmentModel) model).getFragment(), false, false);
60         }
61         if (obj instanceof ModelChangeFile)
62             return getObjectImage((ModelChangeFile)obj);
63         return super.getImage(obj);
64     }
65
66     private Image getObjectImage(ModelChangeFile file) {
67         String JavaDoc type = file.getFile().getFileExtension();
68         if ("xml".equalsIgnoreCase(type)) //$NON-NLS-1$
69
return xmlImage;
70         if ("MF".equalsIgnoreCase(type)) //$NON-NLS-1$
71
return manifestImage;
72         return null;
73     }
74     
75     public void dispose() {
76         if (manifestImage != null)
77             manifestImage.dispose();
78         if (xmlImage != null)
79             xmlImage.dispose();
80         super.dispose();
81     }
82 }
83
Popular Tags