01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.nls;
11:
12: import org.eclipse.pde.core.plugin.IFragmentModel;
13: import org.eclipse.pde.core.plugin.IPluginModel;
14: import org.eclipse.pde.core.plugin.IPluginModelBase;
15: import org.eclipse.pde.internal.ui.PDELabelProvider;
16: import org.eclipse.pde.internal.ui.PDEPluginImages;
17: import org.eclipse.pde.internal.ui.PDEUIMessages;
18: import org.eclipse.swt.graphics.Image;
19:
20: public class ModelChangeLabelProvider extends PDELabelProvider {
21:
22: private Image manifestImage;
23: private Image xmlImage;
24:
25: public ModelChangeLabelProvider() {
26: xmlImage = PDEPluginImages.DESC_PLUGIN_MF_OBJ.createImage();
27: manifestImage = PDEPluginImages.DESC_PAGE_OBJ.createImage();
28: }
29:
30: public String getText(Object obj) {
31: if (obj instanceof ModelChange)
32: return getObjectText(((ModelChange) obj).getParentModel()
33: .getPluginBase());
34: if (obj instanceof ModelChangeFile)
35: return getObjectText((ModelChangeFile) obj);
36: return super .getText(obj);
37: }
38:
39: private String getObjectText(ModelChangeFile pair) {
40: StringBuffer text = new StringBuffer(pair.getFile().getName());
41: int count = pair.getNumChanges();
42: text.append(" ["); //$NON-NLS-1$
43: text.append(count);
44: if (count == 1)
45: text
46: .append(PDEUIMessages.ModelChangeLabelProvider_instance);
47: else
48: text
49: .append(PDEUIMessages.ModelChangeLabelProvider_instances);
50: text.append("]"); //$NON-NLS-1$
51:
52: return text.toString();
53: }
54:
55: public Image getImage(Object obj) {
56: if (obj instanceof ModelChange) {
57: IPluginModelBase model = ((ModelChange) obj)
58: .getParentModel();
59: if (model instanceof IPluginModel)
60: return getObjectImage(((IPluginModel) model)
61: .getPlugin(), false, false);
62: if (model instanceof IFragmentModel)
63: return getObjectImage(((IFragmentModel) model)
64: .getFragment(), false, false);
65: }
66: if (obj instanceof ModelChangeFile)
67: return getObjectImage((ModelChangeFile) obj);
68: return super .getImage(obj);
69: }
70:
71: private Image getObjectImage(ModelChangeFile file) {
72: String type = file.getFile().getFileExtension();
73: if ("xml".equalsIgnoreCase(type)) //$NON-NLS-1$
74: return xmlImage;
75: if ("MF".equalsIgnoreCase(type)) //$NON-NLS-1$
76: return manifestImage;
77: return null;
78: }
79:
80: public void dispose() {
81: if (manifestImage != null)
82: manifestImage.dispose();
83: if (xmlImage != null)
84: xmlImage.dispose();
85: super.dispose();
86: }
87: }
|