blob: 6154802020216aebf499b207e7aa1fc13788bc81 (
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*******************************************************************************
* Copyright (c) 2007, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Red Hat Inc. - Fix compiler problems from generified IAdaptable#getAdapter
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.model;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.ui.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
/**
* Element wrapper class for installed IU's. Used instead of the plain IU when
* there should be a parent profile available for operations.
*
* @since 3.4
*/
public class InstalledIUElement extends QueriedElement implements IIUElement {
String profileId;
IInstallableUnit iu;
boolean isPatch = false;
public InstalledIUElement(Object parent, String profileId, IInstallableUnit iu) {
super(parent);
this.profileId = profileId;
this.iu = iu;
this.isPatch = iu == null ? false : Boolean.valueOf(iu.getProperty(InstallableUnitDescription.PROP_TYPE_PATCH));
}
@Override
protected String getImageId(Object obj) {
return isPatch ? ProvUIImages.IMG_PATCH_IU : ProvUIImages.IMG_IU;
}
@Override
public String getLabel(Object o) {
return iu.getId();
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(Class<T> adapter) {
if (adapter == IInstallableUnit.class)
return (T) iu;
return super.getAdapter(adapter);
}
public String getProfileId() {
return profileId;
}
@Override
public IInstallableUnit getIU() {
return iu;
}
// TODO Later we might consider showing this in the installed views,
// but it is less important than before install.
@Override
public long getSize() {
return ProvUI.SIZE_UNKNOWN;
}
@Override
public boolean shouldShowSize() {
return false;
}
@Override
public void computeSize(IProgressMonitor monitor) {
// Should never be called, as long as shouldShowSize() returns false
}
@Override
public boolean shouldShowVersion() {
return true;
}
@Override
public Collection<IRequirement> getRequirements() {
return iu.getRequirements();
}
@Override
protected int getDefaultQueryType() {
return QueryProvider.INSTALLED_IUS;
}
@Override
public boolean shouldShowChildren() {
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof InstalledIUElement))
return false;
if (iu == null)
return false;
if (!iu.equals(((InstalledIUElement) obj).getIU()))
return false;
Object parent = getParent(this);
Object objParent = ((InstalledIUElement) obj).getParent(obj);
if (parent == this)
return objParent == obj;
else if (parent != null && objParent != null)
return parent.equals(objParent);
else if (parent == null && objParent == null)
return true;
return false;
}
@Override
public int hashCode() {
if (iu == null)
return 0;
return iu.hashCode();
}
@Override
public String toString() {
if (iu == null)
return "NULL"; //$NON-NLS-1$
return iu.toString();
}
}
|