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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/*******************************************************************************
* Copyright (c) 2008, 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.p2.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.ui.*;
import org.eclipse.equinox.internal.p2.ui.actions.*;
import org.eclipse.equinox.internal.p2.ui.dialogs.*;
import org.eclipse.equinox.internal.p2.ui.viewers.IUColumnConfig;
import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.SameShellProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.about.InstallationPage;
import org.eclipse.ui.menus.AbstractContributionFactory;
import org.eclipse.ui.statushandlers.StatusManager;
/**
* InstalledSoftwarePage displays a profile's IInstallableUnits in
* an Installation Page. Clients can use this class as the implementation
* class for an installationPages extension.
*
* @see InstallationPage
*
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 2.0
*
*/
public class InstalledSoftwarePage extends InstallationPage implements ICopyable {
private static final int UPDATE_ID = IDialogConstants.CLIENT_ID;
private static final int UNINSTALL_ID = IDialogConstants.CLIENT_ID + 1;
private static final int PROPERTIES_ID = IDialogConstants.CLIENT_ID + 2;
private static final String BUTTON_ACTION = "org.eclipse.equinox.p2.ui.buttonAction"; //$NON-NLS-1$
AbstractContributionFactory factory;
Text detailsArea;
InstalledIUGroup installedIUGroup;
String profileId;
Button updateButton, uninstallButton, propertiesButton;
ProvisioningUI ui;
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
initializeDialogUnits(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IProvHelpContextIds.INSTALLED_SOFTWARE);
ui = ProvisioningUI.getDefaultUI();
profileId = ui.getProfileId();
if (profileId == null) {
IStatus status = ui.getPolicy().getNoProfileChosenStatus();
if (status != null)
ProvUI.reportStatus(status, StatusManager.LOG);
Text text = new Text(parent, SWT.WRAP | SWT.READ_ONLY);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
text.setText(ProvUIMessages.InstalledSoftwarePage_NoProfile);
setControl(text);
return;
}
Composite composite = new Composite(parent, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
int width = getDefaultWidth(composite);
gd.widthHint = width;
composite.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
// Table of installed IU's
installedIUGroup = new InstalledIUGroup(ui, composite, JFaceResources.getDialogFont(), profileId, getColumnConfig());
// we hook selection listeners on the viewer in createPageButtons because we
// rely on the actions we create there getting selection events before we use
// them to update button enablement.
CopyUtils.activateCopy(this, installedIUGroup.getStructuredViewer().getControl());
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_DESCRIPTION_HEIGHT);
gd.widthHint = width;
detailsArea = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY | SWT.WRAP);
detailsArea.setBackground(detailsArea.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
detailsArea.setLayoutData(gd);
setControl(composite);
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.about.InstallationPage#createPageButtons(org.eclipse.swt.widgets.Composite)
*/
public void createPageButtons(Composite parent) {
if (profileId == null)
return;
// For the update action, we create a custom selection provider that will interpret no
// selection as checking for updates to everything.
// We also override the run method to close the containing dialog
// if we successfully try to resolve. This is done to ensure that progress
// is shown properly.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=236495
UpdateAction updateAction = new UpdateAction(ui, new ISelectionProvider() {
public void addSelectionChangedListener(ISelectionChangedListener listener) {
installedIUGroup.getStructuredViewer().addSelectionChangedListener(listener);
}
public ISelection getSelection() {
StructuredViewer viewer = installedIUGroup.getStructuredViewer();
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
final Object[] all = ((IStructuredContentProvider) viewer.getContentProvider()).getElements(viewer.getInput());
return new StructuredSelection(all);
}
return selection;
}
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
installedIUGroup.getStructuredViewer().removeSelectionChangedListener(listener);
}
public void setSelection(ISelection selection) {
installedIUGroup.getStructuredViewer().setSelection(selection);
}
}, profileId, true) {
public void run() {
super.run();
if (getReturnCode() == Window.OK)
getPageContainer().closeModalContainers();
}
};
updateAction.setSkipSelectionPage(true);
updateButton = createButton(parent, UPDATE_ID, updateAction.getText());
updateButton.setData(BUTTON_ACTION, updateAction);
// Uninstall action
Action uninstallAction = new UninstallAction(ui, installedIUGroup.getStructuredViewer(), profileId) {
public void run() {
super.run();
if (getReturnCode() == Window.OK)
getPageContainer().closeModalContainers();
}
};
uninstallButton = createButton(parent, UNINSTALL_ID, uninstallAction.getText());
uninstallButton.setData(BUTTON_ACTION, uninstallAction);
// Properties action
PropertyDialogAction action = new PropertyDialogAction(new SameShellProvider(getShell()), installedIUGroup.getStructuredViewer());
propertiesButton = createButton(parent, PROPERTIES_ID, action.getText());
propertiesButton.setData(BUTTON_ACTION, action);
// We rely on the actions getting selection events before we do, because
// we rely on the enablement state of the action. So we don't hook
// the selection listener on our table until after actions are created.
installedIUGroup.getStructuredViewer().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateDetailsArea();
updateEnablement();
}
});
updateEnablement();
}
void updateDetailsArea() {
IInstallableUnit[] selected = installedIUGroup.getSelectedIUs();
if (selected.length == 1) {
String description = selected[0].getProperty(IInstallableUnit.PROP_DESCRIPTION, null);
if (description != null) {
detailsArea.setText(description);
return;
}
}
detailsArea.setText(""); //$NON-NLS-1$
}
void updateEnablement() {
if (updateButton == null || updateButton.isDisposed())
return;
Button[] buttons = {updateButton, uninstallButton, propertiesButton};
for (int i = 0; i < buttons.length; i++) {
Action action = (Action) buttons[i].getData(BUTTON_ACTION);
if (action == null || !action.isEnabled())
buttons[i].setEnabled(false);
else
buttons[i].setEnabled(true);
}
}
private IUColumnConfig[] getColumnConfig() {
return new IUColumnConfig[] {new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, IUColumnConfig.COLUMN_NAME, ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH), new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, IUColumnConfig.COLUMN_VERSION, ILayoutConstants.DEFAULT_SMALL_COLUMN_WIDTH), new IUColumnConfig(ProvUIMessages.ProvUI_IdColumnTitle, IUColumnConfig.COLUMN_ID, ILayoutConstants.DEFAULT_COLUMN_WIDTH)};
}
private int getDefaultWidth(Control control) {
IUColumnConfig[] columns = getColumnConfig();
int totalWidth = 0;
for (int i = 0; i < columns.length; i++) {
totalWidth += columns[i].getWidthInPixels(control);
}
return totalWidth + 20; // buffer for surrounding composites
}
/*
* (non-Javadoc)
* @see org.eclipse.equinox.p2.ui.ICopyable#copyToClipboard(org.eclipse.swt.widgets.Control)
*/
public void copyToClipboard(Control activeControl) {
Object[] elements = installedIUGroup.getSelectedIUElements();
if (elements.length == 0)
return;
String text = CopyUtils.getIndentedClipboardText(elements, new IUDetailsLabelProvider(null, getColumnConfig(), null));
Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
clipboard.setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
clipboard.dispose();
}
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case UPDATE_ID :
((Action) updateButton.getData(BUTTON_ACTION)).run();
break;
case UNINSTALL_ID :
((Action) uninstallButton.getData(BUTTON_ACTION)).run();
break;
case PROPERTIES_ID :
((Action) propertiesButton.getData(BUTTON_ACTION)).run();
break;
default :
super.buttonPressed(buttonId);
break;
}
}
}
|