blob: 3758769da5258a0900bb3ae6134339afa788bd7c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*******************************************************************************
* Copyright (c) 2007, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.model;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUIImages;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.statushandlers.StatusManager;
/**
* Generic element that represents a provisioning element in
* a viewer.
*
* @since 3.4
*
*/
public abstract class ProvElement implements IWorkbenchAdapter, IAdaptable {
private Object parent;
public ProvElement(Object parent) {
this.parent = parent;
}
public Object getAdapter(Class adapter) {
if (adapter == IWorkbenchAdapter.class)
return this;
if ((adapter == IDeferredWorkbenchAdapter.class) && this instanceof IDeferredWorkbenchAdapter)
return this;
return null;
}
/**
* Return a string id of the image that should be used to show the specified
* object. Returning null indicates that no image should be used.
*
* @param obj
* the object whose image id is requested
* @return the string id of the image in the provisioning image registry, or
* <code>null</code> if no image should be shown.
*/
protected String getImageId(Object obj) {
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
*/
public ImageDescriptor getImageDescriptor(Object object) {
String id = getImageId(object);
if (id == null) {
return null;
}
ImageDescriptor desc = ProvUIImages.getImageDescriptor(id);
if (desc == null)
desc = JFaceResources.getImageRegistry().getDescriptor(id);
return desc;
}
/**
* Return the image that should be used to show the specfied object. The
* image is managed by an image registry and should not be freed.
*
* @param object
* the object whose image id is requested
* @return the string id of the image in the provisioning image registry
*
*/
public Image getImage(Object object) {
String id = getImageId(object);
if (id == null) {
return null;
}
Image img = ProvUIImages.getImage(id);
if (img == null)
img = JFaceResources.getImageRegistry().get(id);
return img;
}
protected void handleException(Exception e, String message) {
if (message == null) {
message = e.getMessage();
}
IStatus status = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, 0, message, e);
ProvUI.reportStatus(status, StatusManager.LOG);
}
public boolean hasChildren(Object o) {
if (this instanceof IDeferredWorkbenchAdapter)
return ((IDeferredWorkbenchAdapter) this).isContainer();
Object[] children = getChildren(o);
if (children == null) {
return false;
}
return children.length > 0;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
*/
public Object getParent(Object o) {
return parent;
}
}
|