Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: effaf6b9640e85297f23ffb1db224968b96dfecb (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
/*******************************************************************************
 *  Copyright (c) 2007, 2011 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 java.util.*;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector;

/**
 * Element class for profile snapshots
 * 
 * @since 3.5
 */
public class ProfileSnapshots extends ProvElement implements IDeferredWorkbenchAdapter {

	String profileId;
	ProvisioningSession session;

	public ProfileSnapshots(String profileId, ProvisioningSession session) {
		super(null);
		this.profileId = profileId;
		this.session = session;
	}

	public String getProfileId() {
		return profileId;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
	 */
	public Object[] getChildren(Object o) {
		IProfileRegistry registry = ProvUI.getProfileRegistry(session);
		long[] timestamps = registry.listProfileTimestamps(profileId);

		// find out which profile states we should hide
		Map<String, String> hidden = registry.getProfileStateProperties(profileId, IProfile.PROP_HIDDEN);
		List<RollbackProfileElement> elements = new ArrayList<RollbackProfileElement>();

		for (int i = 0; i < timestamps.length; i++) {
			if (hidden.containsKey(String.valueOf(timestamps[i])))
				continue;
			RollbackProfileElement element = new RollbackProfileElement(this, profileId, timestamps[i]);
			elements.add(element);

			// Eliminate the first in the list (earliest) if there was no content at all.
			// This doesn't always happen, but can, and we don't want to offer the user an empty profile to
			// revert to. Just reset the list since it only has one element.
			if (i == 0 && element.getChildren(element).length == 0)
				elements.clear();
		}
		// current profile is the last one in the list
		if (elements.size() > 0)
			elements.get(elements.size() - 1).setIsCurrentProfile(true);
		return elements.toArray(new RollbackProfileElement[elements.size()]);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
	 */
	public String getLabel(Object o) {
		return ProvUIMessages.ProfileSnapshots_Label;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) {
		Object[] children = getChildren(object);
		collector.add(children, monitor);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#getRule(java.lang.Object)
	 */
	public ISchedulingRule getRule(Object object) {
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer()
	 */
	public boolean isContainer() {
		return false;
	}
}

Back to the top