blob: 76fa7ffcee9b317f2f86a66bdaa4be7235c09850 (
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
|
/*******************************************************************************
* Copyright (c) 2007 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.p2.ui.viewers;
import java.util.EventObject;
import org.eclipse.equinox.p2.core.eventbus.SynchronousProvisioningListener;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.ui.IProvisioningProperties;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.widgets.Display;
/**
* ProvisioningListener which updates a structured viewer based on
* provisioning changes
*
* @since 3.4
*/
public class StructuredViewerProvisioningListener implements SynchronousProvisioningListener, IPropertyChangeListener {
// TODO this should be replaced with actual event topic ids from the event API once they are defined
// TODO the IPropertyChangeListener implementation should also disappear once repo events are supported
public static final int PROV_EVENT_REPOSITORY = 0x0001;
public static final int PROV_EVENT_IU = 0x0002;
public static final int PROV_EVENT_PROFILE = 0x0004;
int eventTypes = 0;
StructuredViewer viewer;
Display display;
public StructuredViewerProvisioningListener(StructuredViewer viewer, int eventTypes) {
this.viewer = viewer;
this.eventTypes = eventTypes;
this.display = viewer.getControl().getDisplay();
}
public void notify(EventObject o) {
// Commit operations on a profile will refresh the structure of the profile
if (o instanceof CommitOperationEvent && (((eventTypes & PROV_EVENT_PROFILE) == PROV_EVENT_PROFILE) || (eventTypes & PROV_EVENT_IU) == PROV_EVENT_IU)) {
CommitOperationEvent event = (CommitOperationEvent) o;
final Profile profile = event.getProfile();
display.asyncExec(new Runnable() {
public void run() {
viewer.refresh(profile);
}
});
} else if (o instanceof ProfileEvent && ((eventTypes & PROV_EVENT_IU) == PROV_EVENT_IU)) {
// We assume for now that it was either an add or remove of a
// profile, so rather than update a profile, we update everything.
display.asyncExec(new Runnable() {
public void run() {
viewer.refresh();
}
});
}
}
public void propertyChange(final PropertyChangeEvent event) {
// Currently we only support repo events
if ((eventTypes & PROV_EVENT_REPOSITORY) == PROV_EVENT_REPOSITORY) {
String property = event.getProperty();
if (property.equals(IProvisioningProperties.REPO_NAME)) {
display.asyncExec(new Runnable() {
public void run() {
viewer.update(event.getSource(), null);
}
});
} else if (property.equals(IProvisioningProperties.REPO_ADDED) || (property.equals(IProvisioningProperties.REPO_REMOVED))) {
display.asyncExec(new Runnable() {
public void run() {
viewer.refresh();
}
});
}
}
}
// TODO temporary for use by ProvUIActivator
public int getEventTypes() {
return eventTypes;
}
}
|