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
|
/*******************************************************************************
* 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 com.ibm.icu.text.DateFormat;
import java.util.Date;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.ui.*;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.query.IQueryable;
/**
* Element class for a profile snapshot
*
* @since 3.4
*/
public class RollbackProfileElement extends RemoteQueriedElement {
private String profileId;
private long timestamp;
private IProfile snapshot;
private boolean isCurrent = false;
private String profileTag;
public RollbackProfileElement(Object parent, String profileId, long timestamp) {
this(parent, profileId, timestamp, null);
}
public RollbackProfileElement(Object parent, String profileId, long timestamp, String profileTag) {
super(parent);
this.timestamp = timestamp;
this.profileId = profileId;
this.profileTag = profileTag;
}
@Override
protected String getImageId(Object obj) {
return ProvUIImages.IMG_PROFILE;
}
@Override
public String getLabel(Object o) {
if (isCurrent)
return ProvUIMessages.RollbackProfileElement_CurrentInstallation;
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date(timestamp));
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(Class<T> adapter) {
if (adapter == IProfile.class)
return (T) getProfileSnapshot(new NullProgressMonitor());
return super.getAdapter(adapter);
}
public IProfile getProfileSnapshot(IProgressMonitor monitor) {
if (snapshot == null) {
snapshot = ProvUI.getProfileRegistry(getProvisioningUI().getSession()).getProfile(profileId, timestamp);
setQueryable(snapshot);
}
return snapshot;
}
public long getTimestamp() {
return timestamp;
}
public void setIsCurrentProfile(boolean current) {
this.isCurrent = current;
}
public boolean isCurrentProfile() {
return isCurrent;
}
public String getProfileId() {
return profileId;
}
public String getProfileTag() {
return profileTag;
}
public void setProfileTag(String profileTag) {
this.profileTag = profileTag;
}
@Override
protected int getDefaultQueryType() {
return QueryProvider.INSTALLED_IUS;
}
@Override
public IQueryable<?> getQueryable() {
return getProfileSnapshot(new NullProgressMonitor());
}
}
|