|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2003 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2004 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials! |
3 |
* All rights reserved. This program and the accompanying materials! |
| 4 |
* are made available under the terms of the Common Public License v1.0 |
4 |
* are made available under the terms of the Common Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-35
Link Here
|
| 10 |
* Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog |
10 |
* Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog |
| 11 |
* font should be activated and used by other components. |
11 |
* font should be activated and used by other components. |
| 12 |
************************************************************************/ |
12 |
************************************************************************/ |
| 13 |
|
|
|
| 14 |
package org.eclipse.ui.internal.ide.dialogs; |
13 |
package org.eclipse.ui.internal.ide.dialogs; |
| 15 |
|
14 |
|
| 16 |
import java.text.Collator; |
|
|
| 17 |
import java.util.ArrayList; |
| 18 |
import java.util.Arrays; |
| 19 |
import java.util.Collection; |
| 20 |
import java.util.Collections; |
| 21 |
import java.util.Comparator; |
| 22 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
| 23 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
| 24 |
import java.util.Locale; |
|
|
| 25 |
import java.util.Map; |
17 |
import java.util.Map; |
| 26 |
|
18 |
|
| 27 |
import org.eclipse.core.runtime.CoreException; |
19 |
import org.eclipse.core.runtime.CoreException; |
| 28 |
import org.eclipse.core.runtime.IPluginDescriptor; |
20 |
import org.eclipse.core.runtime.IBundleGroup; |
| 29 |
import org.eclipse.core.runtime.IPluginRegistry; |
|
|
| 30 |
import org.eclipse.core.runtime.NullProgressMonitor; |
21 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 31 |
import org.eclipse.core.runtime.Platform; |
22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 32 |
|
23 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
|
24 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 25 |
import org.eclipse.jface.window.Window; |
| 33 |
import org.eclipse.swt.SWT; |
26 |
import org.eclipse.swt.SWT; |
| 34 |
import org.eclipse.swt.custom.BusyIndicator; |
27 |
import org.eclipse.swt.custom.BusyIndicator; |
| 35 |
import org.eclipse.swt.custom.StyledText; |
28 |
import org.eclipse.swt.custom.StyledText; |
|
Lines 37-43
Link Here
|
| 37 |
import org.eclipse.swt.events.DisposeListener; |
30 |
import org.eclipse.swt.events.DisposeListener; |
| 38 |
import org.eclipse.swt.events.SelectionAdapter; |
31 |
import org.eclipse.swt.events.SelectionAdapter; |
| 39 |
import org.eclipse.swt.events.SelectionEvent; |
32 |
import org.eclipse.swt.events.SelectionEvent; |
| 40 |
import org.eclipse.swt.events.SelectionListener; |
|
|
| 41 |
import org.eclipse.swt.graphics.Cursor; |
33 |
import org.eclipse.swt.graphics.Cursor; |
| 42 |
import org.eclipse.swt.graphics.Font; |
34 |
import org.eclipse.swt.graphics.Font; |
| 43 |
import org.eclipse.swt.graphics.Image; |
35 |
import org.eclipse.swt.graphics.Image; |
|
Lines 51-93
Link Here
|
| 51 |
import org.eclipse.swt.widgets.Table; |
43 |
import org.eclipse.swt.widgets.Table; |
| 52 |
import org.eclipse.swt.widgets.TableColumn; |
44 |
import org.eclipse.swt.widgets.TableColumn; |
| 53 |
import org.eclipse.swt.widgets.TableItem; |
45 |
import org.eclipse.swt.widgets.TableItem; |
| 54 |
|
|
|
| 55 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 56 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 57 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 58 |
|
| 59 |
import org.eclipse.ui.help.WorkbenchHelp; |
46 |
import org.eclipse.ui.help.WorkbenchHelp; |
| 60 |
|
47 |
import org.eclipse.ui.internal.ide.AboutBundleGroupData; |
| 61 |
import org.eclipse.ui.internal.AboutInfo; |
48 |
import org.eclipse.ui.internal.ide.AboutData; |
| 62 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
49 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
| 63 |
import org.eclipse.ui.internal.ide.IHelpContextIds; |
50 |
import org.eclipse.ui.internal.ide.IHelpContextIds; |
| 64 |
|
|
|
| 65 |
import org.eclipse.update.configuration.IConfiguredSite; |
51 |
import org.eclipse.update.configuration.IConfiguredSite; |
| 66 |
import org.eclipse.update.configuration.IInstallConfiguration; |
52 |
import org.eclipse.update.configuration.IInstallConfiguration; |
| 67 |
import org.eclipse.update.configuration.ILocalSite; |
53 |
import org.eclipse.update.configuration.ILocalSite; |
| 68 |
import org.eclipse.update.core.IFeature; |
54 |
import org.eclipse.update.core.IFeature; |
| 69 |
import org.eclipse.update.core.IFeatureReference; |
55 |
import org.eclipse.update.core.IFeatureReference; |
| 70 |
import org.eclipse.update.core.IPluginEntry; |
|
|
| 71 |
import org.eclipse.update.core.IURLEntry; |
56 |
import org.eclipse.update.core.IURLEntry; |
| 72 |
import org.eclipse.update.core.SiteManager; |
57 |
import org.eclipse.update.core.SiteManager; |
| 73 |
import org.eclipse.update.core.VersionedIdentifier; |
58 |
import org.osgi.framework.Bundle; |
| 74 |
|
59 |
|
| 75 |
/** |
60 |
/** |
| 76 |
* Displays information about the product plugins. |
61 |
* Displays information about the product plugins. |
| 77 |
* |
62 |
* |
| 78 |
* @private |
63 |
* @private |
| 79 |
* This class is internal to the workbench and must not be called outside the workbench |
64 |
* This class is internal to the workbench and must not be called outside |
|
|
65 |
* the workbench. |
| 80 |
*/ |
66 |
*/ |
| 81 |
public class AboutFeaturesDialog extends ProductInfoDialog { |
67 |
public class AboutFeaturesDialog extends ProductInfoDialog { |
| 82 |
|
68 |
|
| 83 |
/** |
69 |
/** |
| 84 |
* Table height in dialog units (value 150). |
70 |
* Table height in dialog units (value 150). |
| 85 |
*/ |
71 |
*/ |
| 86 |
private static final int TABLE_HEIGHT = 150; |
72 |
private static final int TABLE_HEIGHT = 150; |
| 87 |
private static final int INFO_HEIGHT = 100; |
73 |
private static final int INFO_HEIGHT = 100; |
| 88 |
|
74 |
private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; |
| 89 |
private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; |
75 |
private final static int PLUGINS_ID = IDialogConstants.CLIENT_ID + 2; |
| 90 |
private final static int PLUGINS_ID = IDialogConstants.CLIENT_ID + 2; |
|
|
| 91 |
|
76 |
|
| 92 |
private Table table; |
77 |
private Table table; |
| 93 |
private Label imageLabel; |
78 |
private Label imageLabel; |
|
Lines 96-113
Link Here
|
| 96 |
|
81 |
|
| 97 |
private Map cachedImages = new HashMap(); |
82 |
private Map cachedImages = new HashMap(); |
| 98 |
|
83 |
|
| 99 |
private String columnTitles[] = { IDEWorkbenchMessages.getString("AboutFeaturesDialog.provider"), //$NON-NLS-1$ |
84 |
private String columnTitles[] = { |
|
|
85 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.provider"), //$NON-NLS-1$ |
| 100 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureName"), //$NON-NLS-1$ |
86 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureName"), //$NON-NLS-1$ |
| 101 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.version"), //$NON-NLS-1$ |
87 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.version"), //$NON-NLS-1$ |
| 102 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureId"), //$NON-NLS-1$ |
88 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureId"), //$NON-NLS-1$ |
| 103 |
}; |
89 |
}; |
| 104 |
|
90 |
|
| 105 |
private AboutInfo[] featureInfos; |
91 |
private String productName; |
| 106 |
private AboutInfo primaryInfo; |
92 |
private AboutBundleGroupData[] bundleGroupInfos; |
| 107 |
|
93 |
|
| 108 |
private int lastColumnChosen = 0; // initially sort by provider |
94 |
private int lastColumnChosen = 0; // initially sort by provider |
| 109 |
private boolean reverseSort = false; // initially sort ascending |
95 |
private boolean reverseSort = false; // initially sort ascending |
| 110 |
private AboutInfo lastSelection = null; |
96 |
private AboutBundleGroupData lastSelection = null; |
| 111 |
private Button moreButton; |
97 |
private Button moreButton; |
| 112 |
private Button pluginsButton; |
98 |
private Button pluginsButton; |
| 113 |
|
99 |
|
|
Lines 116-268
Link Here
|
| 116 |
/** |
102 |
/** |
| 117 |
* Constructor for AboutFeaturesDialog |
103 |
* Constructor for AboutFeaturesDialog |
| 118 |
*/ |
104 |
*/ |
| 119 |
public AboutFeaturesDialog( |
105 |
public AboutFeaturesDialog(Shell parentShell, String productName, |
| 120 |
Shell parentShell, |
106 |
AboutBundleGroupData[] bundleGroupInfos) { |
| 121 |
AboutInfo primaryInfo, |
107 |
super(parentShell); |
| 122 |
AboutInfo[] featureInfos) { |
108 |
setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL); |
| 123 |
super(parentShell); |
109 |
|
| 124 |
setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL); |
110 |
this.productName = productName; |
| 125 |
|
111 |
this.bundleGroupInfos = bundleGroupInfos; |
| 126 |
this.primaryInfo = primaryInfo; |
112 |
|
| 127 |
this.featureInfos = featureInfos; |
113 |
AboutData.sortByProvider(reverseSort, bundleGroupInfos); |
| 128 |
|
114 |
} |
| 129 |
sortByProvider(); |
115 |
|
| 130 |
} |
116 |
/** |
| 131 |
|
117 |
* The More Info button was pressed. Open a browser with the license for the |
| 132 |
/* (non-Javadoc) |
118 |
* selected item or an information dialog if there is no license, or the browser |
| 133 |
* Method declared on Dialog. |
119 |
* cannot be opened. |
| 134 |
*/ |
120 |
*/ |
| 135 |
protected void buttonPressed(int buttonId) { |
121 |
private void handleMoreInfoPressed() { |
| 136 |
switch (buttonId) { |
122 |
TableItem[] items = table.getSelection(); |
| 137 |
case MORE_ID : |
123 |
if (items.length <= 0) |
| 138 |
{ |
124 |
return; |
| 139 |
TableItem[] items = table.getSelection(); |
125 |
|
| 140 |
if (items.length > 0) { |
126 |
AboutBundleGroupData info = (AboutBundleGroupData) items[0].getData(); |
| 141 |
AboutInfo info = (AboutInfo) items[0].getData(); |
127 |
IFeature feature = getFeatureFor(info); |
| 142 |
IFeature feature = getFeatureFor(info); |
128 |
IURLEntry entry = feature == null ? null : feature.getLicense(); |
| 143 |
IURLEntry entry = feature == null ? null : feature.getLicense(); |
129 |
if (feature == null || entry == null || !openBrowser(entry.getURL())) { |
| 144 |
if (feature == null || entry == null |
130 |
MessageDialog.openInformation(getShell(), IDEWorkbenchMessages |
| 145 |
|| !openBrowser(entry.getURL())) |
131 |
.getString("AboutFeaturesDialog.noInfoTitle"), //$NON-NLS-1$ |
| 146 |
MessageDialog |
132 |
IDEWorkbenchMessages |
| 147 |
.openInformation( |
133 |
.getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ |
| 148 |
getShell(), |
134 |
} |
| 149 |
IDEWorkbenchMessages |
135 |
} |
| 150 |
.getString("AboutFeaturesDialog.noInfoTitle"), //$NON-NLS-1$ |
136 |
|
| 151 |
IDEWorkbenchMessages |
137 |
/** |
| 152 |
.getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ |
138 |
* The Plugins button was pressed. Open an about dialog on the plugins for |
| 153 |
} |
139 |
* the selected feature. |
| 154 |
return; |
140 |
*/ |
| 155 |
} |
141 |
private void handlePluginInfoPressed() { |
| 156 |
case PLUGINS_ID : |
142 |
TableItem[] items = table.getSelection(); |
| 157 |
{ |
143 |
if (items.length <= 0) |
| 158 |
TableItem[] items = table.getSelection(); |
144 |
return; |
| 159 |
if (items.length > 0) { |
145 |
|
| 160 |
AboutInfo info = (AboutInfo) items[0].getData(); |
146 |
AboutBundleGroupData info = (AboutBundleGroupData) items[0].getData(); |
| 161 |
IFeature feature = getFeatureFor(info); |
147 |
IBundleGroup bundleGroup = info.getBundleGroup(); |
| 162 |
IPluginDescriptor[] descriptors; |
148 |
Bundle[] bundles = bundleGroup == null ? new Bundle[0] : bundleGroup |
| 163 |
if (feature == null) |
149 |
.getBundles(); |
| 164 |
descriptors = new IPluginDescriptor[0]; |
150 |
|
| 165 |
else |
151 |
AboutPluginsDialog d = new AboutPluginsDialog(getShell(), productName, |
| 166 |
descriptors = getPluginsFor(feature); |
152 |
bundles, IDEWorkbenchMessages |
| 167 |
AboutPluginsDialog d = |
153 |
.getString("AboutFeaturesDialog.pluginInfoTitle"), //$NON-NLS-1$ |
| 168 |
new AboutPluginsDialog( |
154 |
IDEWorkbenchMessages.format( |
| 169 |
getShell(), |
155 |
"AboutFeaturesDialog.pluginInfoMessage", //$NON-NLS-1$ |
| 170 |
primaryInfo, |
156 |
new Object[] { bundleGroup.getIdentifier()}), |
| 171 |
descriptors, |
157 |
IHelpContextIds.ABOUT_FEATURES_PLUGINS_DIALOG); |
| 172 |
IDEWorkbenchMessages.getString( |
158 |
d.open(); |
| 173 |
"AboutFeaturesDialog.pluginInfoTitle"), //$NON-NLS-1$ |
159 |
} |
| 174 |
IDEWorkbenchMessages.format( |
160 |
|
| 175 |
"AboutFeaturesDialog.pluginInfoMessage", //$NON-NLS-1$ |
161 |
/* |
| 176 |
new Object[] { info.getFeatureLabel()}), |
162 |
* (non-Javadoc) Method declared on Dialog. |
| 177 |
IHelpContextIds.ABOUT_FEATURES_PLUGINS_DIALOG); |
163 |
*/ |
| 178 |
d.open(); |
164 |
protected void buttonPressed(int buttonId) { |
| 179 |
} |
165 |
switch (buttonId) { |
| 180 |
return; |
166 |
case MORE_ID: |
| 181 |
} |
167 |
handleMoreInfoPressed(); |
| 182 |
} |
168 |
break; |
| 183 |
super.buttonPressed(buttonId); |
169 |
case PLUGINS_ID: |
| 184 |
} |
170 |
handlePluginInfoPressed(); |
|
|
171 |
break; |
| 172 |
default: |
| 173 |
super.buttonPressed(buttonId); |
| 174 |
break; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/* |
| 179 |
* (non-Javadoc) Method declared on Window. |
| 180 |
*/ |
| 181 |
protected void configureShell(Shell newShell) { |
| 182 |
super.configureShell(newShell); |
| 183 |
if (productName != null) |
| 184 |
newShell.setText(IDEWorkbenchMessages.format( |
| 185 |
"AboutFeaturesDialog.shellTitle", //$NON-NLS-1$ |
| 186 |
new Object[] { productName })); |
| 187 |
|
| 188 |
WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_FEATURES_DIALOG); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Add buttons to the dialog's button bar. |
| 193 |
* |
| 194 |
* Subclasses should override. |
| 195 |
* |
| 196 |
* @param parent |
| 197 |
* the button bar composite |
| 198 |
*/ |
| 199 |
protected void createButtonsForButtonBar(Composite parent) { |
| 200 |
parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 201 |
|
| 202 |
moreButton = createButton(parent, MORE_ID, IDEWorkbenchMessages |
| 203 |
.getString("AboutFeaturesDialog.moreInfo"), false); //$NON-NLS-1$ |
| 204 |
pluginsButton = createButton(parent, PLUGINS_ID, IDEWorkbenchMessages |
| 205 |
.getString("AboutFeaturesDialog.pluginsInfo"), false); //$NON-NLS-1$ |
| 206 |
|
| 207 |
Label l = new Label(parent, SWT.NONE); |
| 208 |
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 209 |
GridLayout layout = (GridLayout) parent.getLayout(); |
| 210 |
layout.numColumns++; |
| 211 |
layout.makeColumnsEqualWidth = false; |
| 212 |
|
| 213 |
Button b = createButton(parent, IDialogConstants.OK_ID, |
| 214 |
IDialogConstants.OK_LABEL, true); |
| 215 |
b.setFocus(); |
| 216 |
|
| 217 |
TableItem[] items = table.getSelection(); |
| 218 |
if (items.length > 0) |
| 219 |
updateButtons((AboutBundleGroupData) items[0].getData()); |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Create the contents of the dialog (above the button bar). |
| 224 |
* |
| 225 |
* Subclasses should overide. |
| 226 |
* |
| 227 |
* @param the |
| 228 |
* parent composite to contain the dialog area |
| 229 |
* @return the dialog area control |
| 230 |
*/ |
| 231 |
protected Control createDialogArea(Composite parent) { |
| 232 |
setHandCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_HAND)); |
| 233 |
setBusyCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT)); |
| 234 |
getShell().addDisposeListener(new DisposeListener() { |
| 235 |
public void widgetDisposed(DisposeEvent e) { |
| 236 |
if (getHandCursor() != null) |
| 237 |
getHandCursor().dispose(); |
| 238 |
if (getBusyCursor() != null) |
| 239 |
getBusyCursor().dispose(); |
| 240 |
} |
| 241 |
}); |
| 242 |
|
| 243 |
Composite outer = (Composite) super.createDialogArea(parent); |
| 244 |
|
| 245 |
createTable(outer); |
| 246 |
createInfoArea(outer); |
| 247 |
|
| 248 |
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL, |
| 249 |
GridData.VERTICAL_ALIGN_FILL, true, true); |
| 250 |
gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); |
| 251 |
table.setLayoutData(gridData); |
| 185 |
|
252 |
|
| 186 |
/* (non-Javadoc) |
253 |
return outer; |
| 187 |
* Method declared on Window. |
254 |
} |
| 188 |
*/ |
|
|
| 189 |
protected void configureShell(Shell newShell) { |
| 190 |
super.configureShell(newShell); |
| 191 |
String title = null; |
| 192 |
if (primaryInfo != null) { |
| 193 |
title = primaryInfo.getProductName(); |
| 194 |
} |
| 195 |
if (title != null) { |
| 196 |
newShell.setText(IDEWorkbenchMessages.format("AboutFeaturesDialog.shellTitle", //$NON-NLS-1$ |
| 197 |
new Object[] { title })); |
| 198 |
} |
| 199 |
WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_FEATURES_DIALOG); |
| 200 |
} |
| 201 |
/** |
| 202 |
* Add buttons to the dialog's button bar. |
| 203 |
* |
| 204 |
* Subclasses should override. |
| 205 |
* |
| 206 |
* @param parent the button bar composite |
| 207 |
*/ |
| 208 |
protected void createButtonsForButtonBar(Composite parent) { |
| 209 |
parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 210 |
|
255 |
|
| 211 |
moreButton = createButton(parent, MORE_ID, IDEWorkbenchMessages.getString("AboutFeaturesDialog.moreInfo"), false); //$NON-NLS-1$ |
256 |
/** |
| 212 |
pluginsButton = createButton(parent, PLUGINS_ID, IDEWorkbenchMessages.getString("AboutFeaturesDialog.pluginsInfo"), false); //$NON-NLS-1$ |
|
|
| 213 |
|
| 214 |
Label l = new Label(parent, SWT.NONE); |
| 215 |
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 216 |
GridLayout layout = (GridLayout) parent.getLayout(); |
| 217 |
layout.numColumns++; |
| 218 |
layout.makeColumnsEqualWidth = false; |
| 219 |
|
| 220 |
Button b = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); |
| 221 |
b.setFocus(); |
| 222 |
|
| 223 |
TableItem[] items = table.getSelection(); |
| 224 |
if (items.length > 0) |
| 225 |
updateButtons((AboutInfo) items[0].getData()); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Create the contents of the dialog (above the button bar). |
| 230 |
* |
| 231 |
* Subclasses should overide. |
| 232 |
* |
| 233 |
* @param the parent composite to contain the dialog area |
| 234 |
* @return the dialog area control |
| 235 |
*/ |
| 236 |
protected Control createDialogArea(Composite parent) { |
| 237 |
setHandCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_HAND)); |
| 238 |
setBusyCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT)); |
| 239 |
getShell().addDisposeListener(new DisposeListener() { |
| 240 |
public void widgetDisposed(DisposeEvent e) { |
| 241 |
if (getHandCursor() != null) |
| 242 |
getHandCursor().dispose(); |
| 243 |
if (getBusyCursor() != null) |
| 244 |
getBusyCursor().dispose(); |
| 245 |
} |
| 246 |
}); |
| 247 |
|
| 248 |
Composite outer = (Composite) super.createDialogArea(parent); |
| 249 |
|
| 250 |
createTable(outer); |
| 251 |
createColumns(); |
| 252 |
createInfoArea(outer); |
| 253 |
|
| 254 |
GridData gridData = |
| 255 |
new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); |
| 256 |
gridData.grabExcessVerticalSpace = true; |
| 257 |
gridData.grabExcessHorizontalSpace = true; |
| 258 |
|
| 259 |
// suggest a height for the table |
| 260 |
gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); |
| 261 |
table.setLayoutData(gridData); |
| 262 |
|
| 263 |
return outer; |
| 264 |
} |
| 265 |
/** |
| 266 |
* Create the info area containing the image and text |
257 |
* Create the info area containing the image and text |
| 267 |
*/ |
258 |
*/ |
| 268 |
protected void createInfoArea(Composite parent) { |
259 |
protected void createInfoArea(Composite parent) { |
|
Lines 303-309
Link Here
|
| 303 |
|
294 |
|
| 304 |
TableItem[] items = table.getSelection(); |
295 |
TableItem[] items = table.getSelection(); |
| 305 |
if (items.length > 0) |
296 |
if (items.length > 0) |
| 306 |
updateInfoArea((AboutInfo) items[0].getData()); |
297 |
updateInfoArea((AboutBundleGroupData) items[0].getData()); |
| 307 |
} |
298 |
} |
| 308 |
|
299 |
|
| 309 |
/** |
300 |
/** |
|
Lines 312-786
Link Here
|
| 312 |
* @param the parent composite to contain the dialog area |
303 |
* @param the parent composite to contain the dialog area |
| 313 |
*/ |
304 |
*/ |
| 314 |
protected void createTable(Composite parent) { |
305 |
protected void createTable(Composite parent) { |
| 315 |
table = |
306 |
table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE |
| 316 |
new Table( |
307 |
| SWT.FULL_SELECTION | SWT.BORDER); |
| 317 |
parent, |
308 |
table.setHeaderVisible(true); |
| 318 |
SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); |
309 |
table.setLinesVisible(true); |
| 319 |
table.setHeaderVisible(true); |
310 |
table.setFont(parent.getFont()); |
| 320 |
table.setLinesVisible(true); |
311 |
table.addSelectionListener(new SelectionAdapter() { |
| 321 |
table.setFont(parent.getFont()); |
|
|
| 322 |
|
| 323 |
SelectionListener listener = new SelectionAdapter() { |
| 324 |
public void widgetSelected(SelectionEvent e) { |
312 |
public void widgetSelected(SelectionEvent e) { |
| 325 |
AboutInfo info = (AboutInfo) e.item.getData(); |
313 |
AboutBundleGroupData info = (AboutBundleGroupData) e.item.getData(); |
| 326 |
updateInfoArea(info); |
314 |
updateInfoArea(info); |
| 327 |
updateButtons(info); |
315 |
updateButtons(info); |
| 328 |
} |
316 |
} |
| 329 |
}; |
|
|
| 330 |
table.addSelectionListener(listener); |
| 331 |
} |
| 332 |
/** |
| 333 |
* @see Window#close() |
| 334 |
*/ |
| 335 |
public boolean close() { |
| 336 |
Collection values = cachedImages.values(); |
| 337 |
for (Iterator iter = values.iterator(); iter.hasNext();) { |
| 338 |
Image image = (Image) iter.next(); |
| 339 |
image.dispose(); |
| 340 |
} |
| 341 |
return super.close(); |
| 342 |
} |
| 343 |
/** |
| 344 |
* Returns a mapping from feature id to feature |
| 345 |
*/ |
| 346 |
private Map getFeaturesMap() { |
| 347 |
if (featuresMap != null) |
| 348 |
return featuresMap; |
| 349 |
|
| 350 |
featuresMap = new HashMap(); |
| 351 |
|
| 352 |
IPluginRegistry reg = Platform.getPluginRegistry(); |
| 353 |
if (reg == null) { |
| 354 |
MessageDialog.openError(getShell(), IDEWorkbenchMessages.getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ |
| 355 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ |
| 356 |
return featuresMap; |
| 357 |
} |
| 358 |
|
| 359 |
final ILocalSite[] localSiteArray = new ILocalSite[1]; |
| 360 |
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { |
| 361 |
public void run() { |
| 362 |
// this may take a few seconds |
| 363 |
try { |
| 364 |
localSiteArray[0] = SiteManager.getLocalSite(); |
| 365 |
} catch (CoreException e) { |
| 366 |
MessageDialog.openError(getShell(), IDEWorkbenchMessages.getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ |
| 367 |
IDEWorkbenchMessages.getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ |
| 368 |
} |
| 369 |
} |
| 370 |
}); |
317 |
}); |
| 371 |
if (localSiteArray[0] == null) |
|
|
| 372 |
return featuresMap; |
| 373 |
|
| 374 |
IInstallConfiguration installConfiguration = localSiteArray[0].getCurrentConfiguration(); |
| 375 |
IConfiguredSite[] configuredSites = installConfiguration.getConfiguredSites(); |
| 376 |
|
| 377 |
for (int i = 0; i < configuredSites.length; i++) { |
| 378 |
IFeatureReference[] featureReferences = configuredSites[i].getConfiguredFeatures(); |
| 379 |
for (int j = 0; j < featureReferences.length; j++) { |
| 380 |
IFeature feature; |
| 381 |
try { |
| 382 |
feature = featureReferences[j].getFeature(new NullProgressMonitor()); |
| 383 |
} catch (CoreException e) { |
| 384 |
// just skip it |
| 385 |
break; |
| 386 |
} |
| 387 |
String key = feature.getVersionedIdentifier().toString(); |
| 388 |
featuresMap.put(key, feature); |
| 389 |
} |
| 390 |
} |
| 391 |
return featuresMap; |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Return the feature for the given info |
| 396 |
*/ |
| 397 |
private IFeature getFeatureFor(AboutInfo info) { |
| 398 |
Map map = getFeaturesMap(); |
| 399 |
if (map == null) |
| 400 |
return null; |
| 401 |
String key = info.getFeatureId() + "_" + info.getVersionId(); //$NON-NLS-1$ |
| 402 |
return (IFeature) map.get(key); |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Return the plugins for the given feature |
| 407 |
*/ |
| 408 |
private IPluginDescriptor[] getPluginsFor(IFeature feature) { |
| 409 |
IPluginRegistry reg = Platform.getPluginRegistry(); |
| 410 |
if (reg == null) |
| 411 |
return new IPluginDescriptor[0]; |
| 412 |
IPluginEntry[] pluginEntries = feature.getPluginEntries(); |
| 413 |
ArrayList plugins = new ArrayList(); |
| 414 |
for (int k = 0; k < pluginEntries.length; k++) { |
| 415 |
VersionedIdentifier id = pluginEntries[k].getVersionedIdentifier(); |
| 416 |
|
| 417 |
IPluginDescriptor desc = reg.getPluginDescriptor(id.getIdentifier(), id.getVersion()); |
| 418 |
if (desc != null) |
| 419 |
plugins.add(desc); |
| 420 |
} |
| 421 |
return (IPluginDescriptor[]) plugins.toArray(new IPluginDescriptor[plugins.size()]); |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Update the button enablement |
| 426 |
*/ |
| 427 |
private void updateButtons(AboutInfo info) { |
| 428 |
if (info == null) { |
| 429 |
moreButton.setEnabled(false); |
| 430 |
pluginsButton.setEnabled(false); |
| 431 |
return; |
| 432 |
} |
| 433 |
boolean shouldEnable = true; // by default enable |
| 434 |
// Avoid creating the map just to determine enablement |
| 435 |
if (featuresMap != null) { |
| 436 |
IFeature feature = getFeatureFor(info); |
| 437 |
shouldEnable = feature != null && feature.getLicense() != null; |
| 438 |
} |
| 439 |
moreButton.setEnabled(shouldEnable); |
| 440 |
|
| 441 |
// Assume there is at least one plugin |
| 442 |
shouldEnable = true; // by default enable |
| 443 |
if (featuresMap != null) { |
| 444 |
IFeature feature = getFeatureFor(info); |
| 445 |
shouldEnable = feature != null; |
| 446 |
} |
| 447 |
pluginsButton.setEnabled(shouldEnable); |
| 448 |
} |
| 449 |
|
| 450 |
/** |
| 451 |
* Update the info area |
| 452 |
*/ |
| 453 |
private void updateInfoArea(AboutInfo info) { |
| 454 |
if (info == null) { |
| 455 |
imageLabel.setImage(null); |
| 456 |
text.setText(""); //$NON-NLS-1$ |
| 457 |
return; |
| 458 |
} |
| 459 |
ImageDescriptor desc = info.getFeatureImage(); |
| 460 |
Image image = (Image) cachedImages.get(desc); |
| 461 |
if (image == null && desc != null) { |
| 462 |
image = desc.createImage(); |
| 463 |
cachedImages.put(desc, image); |
| 464 |
} |
| 465 |
imageLabel.setImage(image); |
| 466 |
String aboutText = info.getAboutText(); |
| 467 |
setItem(null); |
| 468 |
if (aboutText != null) { |
| 469 |
// get an about item |
| 470 |
setItem(scan(aboutText)); |
| 471 |
} |
| 472 |
if (getItem() == null) |
| 473 |
text.setText(IDEWorkbenchMessages.getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ |
| 474 |
else { |
| 475 |
text.setText(getItem().getText()); |
| 476 |
text.setCursor(null); |
| 477 |
setLinkRanges(text, getItem().getLinkRanges()); |
| 478 |
} |
| 479 |
} |
| 480 |
|
318 |
|
| 481 |
/** |
319 |
int[] columnWidths = { |
| 482 |
* Select the initial selection |
320 |
convertHorizontalDLUsToPixels(120), |
| 483 |
* |
321 |
convertHorizontalDLUsToPixels(120), |
| 484 |
*/ |
322 |
convertHorizontalDLUsToPixels(70), |
| 485 |
public void setInitialSelection(AboutInfo info) { |
323 |
convertHorizontalDLUsToPixels(130) |
| 486 |
lastSelection = info; |
324 |
}; |
| 487 |
} |
|
|
| 488 |
|
325 |
|
| 489 |
/** |
|
|
| 490 |
* Populate the table with plugin info obtained from the registry. |
| 491 |
* |
| 492 |
* @param the parent composite to contain the dialog area |
| 493 |
*/ |
| 494 |
protected void createColumns() { |
| 495 |
/* create table headers */ |
| 496 |
int[] columnWidths = |
| 497 |
{ |
| 498 |
convertHorizontalDLUsToPixels(120), |
| 499 |
convertHorizontalDLUsToPixels(180), |
| 500 |
convertHorizontalDLUsToPixels(70), |
| 501 |
convertHorizontalDLUsToPixels(70)}; |
| 502 |
for (int i = 0; i < columnTitles.length; i++) { |
326 |
for (int i = 0; i < columnTitles.length; i++) { |
| 503 |
TableColumn tableColumn = new TableColumn(table, SWT.NULL); |
327 |
TableColumn tableColumn = new TableColumn(table, SWT.NULL); |
| 504 |
tableColumn.setWidth(columnWidths[i]); |
328 |
tableColumn.setWidth(columnWidths[i]); |
| 505 |
tableColumn.setText(columnTitles[i]); |
329 |
tableColumn.setText(columnTitles[i]); |
| 506 |
final int columnIndex = i; |
330 |
final int columnIndex = i; |
| 507 |
tableColumn.addSelectionListener(new SelectionAdapter() { |
331 |
tableColumn.addSelectionListener(new SelectionAdapter() { |
| 508 |
public void widgetSelected(SelectionEvent e) { |
332 |
public void widgetSelected(SelectionEvent e) { |
| 509 |
sort(columnIndex); |
333 |
sort(columnIndex); |
| 510 |
} |
334 |
} |
| 511 |
}); |
335 |
}); |
| 512 |
|
336 |
} |
| 513 |
} |
337 |
|
|
|
338 |
// create a table row for each bundle group |
| 339 |
String selId = lastSelection == null ? null : lastSelection.getId(); |
| 340 |
int sel = 0; |
| 341 |
for (int i = 0; i < bundleGroupInfos.length; i++) { |
| 342 |
if (bundleGroupInfos[i].getId().equals(selId)) |
| 343 |
sel = i; |
| 514 |
|
344 |
|
| 515 |
int initialSelectionIndex = 0; |
|
|
| 516 |
/* fill each row of the table with feature info */ |
| 517 |
for (int i = 0; i < featureInfos.length; i++) { |
| 518 |
if (featureInfos[i] == lastSelection) |
| 519 |
initialSelectionIndex = i; |
| 520 |
String provider = featureInfos[i].getProviderName(); |
| 521 |
String featureName = featureInfos[i].getFeatureLabel(); |
| 522 |
String versionId = featureInfos[i].getVersionId(); |
| 523 |
String featureId = featureInfos[i].getFeatureId(); |
| 524 |
if (provider == null) |
| 525 |
provider = ""; //$NON-NLS-1$ |
| 526 |
if (featureName == null) |
| 527 |
featureName = ""; //$NON-NLS-1$ |
| 528 |
if (versionId == null) |
| 529 |
versionId = ""; //$NON-NLS-1$ |
| 530 |
if (featureId == null) |
| 531 |
featureId = ""; //$NON-NLS-1$ |
| 532 |
String[] row = { provider, featureName, versionId, featureId }; |
| 533 |
TableItem item = new TableItem(table, SWT.NULL); |
345 |
TableItem item = new TableItem(table, SWT.NULL); |
| 534 |
item.setText(row); |
346 |
item.setText(createRow(bundleGroupInfos[i])); |
| 535 |
item.setData(featureInfos[i]); |
347 |
item.setData(bundleGroupInfos[i]); |
| 536 |
} |
|
|
| 537 |
|
| 538 |
// set initial selection |
| 539 |
if (featureInfos.length > 0) { |
| 540 |
table.setSelection(initialSelectionIndex); |
| 541 |
} |
348 |
} |
| 542 |
} |
|
|
| 543 |
|
349 |
|
| 544 |
/** |
350 |
// if an item was specified during construction, it should be |
| 545 |
* Sort the rows of the table based on the selected column. |
351 |
// selected when the table is created |
| 546 |
* |
352 |
if (bundleGroupInfos.length > 0) { |
| 547 |
* @param column index of table column selected as sort criteria |
353 |
table.setSelection(sel); |
| 548 |
*/ |
|
|
| 549 |
private void sort(int column) { |
| 550 |
// Choose new sort algorithm |
| 551 |
if (lastColumnChosen == column) { |
| 552 |
reverseSort = !reverseSort; |
| 553 |
} else { |
| 554 |
reverseSort = false; |
| 555 |
lastColumnChosen = column; |
| 556 |
} |
| 557 |
|
| 558 |
if (table.getItemCount() <= 1) |
| 559 |
return; |
| 560 |
|
| 561 |
// Remember the last selection |
| 562 |
int idx = table.getSelectionIndex(); |
| 563 |
if (idx != -1) |
| 564 |
lastSelection = featureInfos[idx]; |
| 565 |
|
| 566 |
switch (column) { |
| 567 |
case 0 : |
| 568 |
sortByProvider(); |
| 569 |
break; |
| 570 |
case 1 : |
| 571 |
sortByName(); |
| 572 |
break; |
| 573 |
case 2 : |
| 574 |
sortByVersion(); |
| 575 |
break; |
| 576 |
case 3 : |
| 577 |
sortByFeatureId(); |
| 578 |
break; |
| 579 |
} |
| 580 |
|
| 581 |
refreshTable(column); |
| 582 |
} |
| 583 |
|
| 584 |
/** |
| 585 |
* Refresh the rows of the table based on the selected column. |
| 586 |
* Maintain selection from before sort action request. |
| 587 |
* |
| 588 |
* @param items the old state table items |
| 589 |
*/ |
| 590 |
private void refreshTable(int col) { |
| 591 |
TableItem[] items = table.getItems(); |
| 592 |
int idx = -1; // the new index of the selection |
| 593 |
// Create new order of table items |
| 594 |
for (int i = 0; i < items.length; i++) { |
| 595 |
String provider = featureInfos[i].getProviderName(); |
| 596 |
String featureName = featureInfos[i].getFeatureLabel(); |
| 597 |
String versionId = featureInfos[i].getVersionId(); |
| 598 |
String featureId = featureInfos[i].getFeatureId(); |
| 599 |
if (provider == null) |
| 600 |
provider = ""; //$NON-NLS-1$ |
| 601 |
if (featureName == null) |
| 602 |
featureName = ""; //$NON-NLS-1$ |
| 603 |
if (versionId == null) |
| 604 |
versionId = ""; //$NON-NLS-1$ |
| 605 |
if (featureId == null) |
| 606 |
featureId = ""; //$NON-NLS-1$ |
| 607 |
String[] row = { provider, featureName, versionId, featureId }; |
| 608 |
items[i].setText(row); |
| 609 |
items[i].setData(featureInfos[i]); |
| 610 |
} |
| 611 |
// Maintain the original selection |
| 612 |
if (lastSelection != null) { |
| 613 |
for (int k = 0; k < featureInfos.length; k++) { |
| 614 |
if (lastSelection == featureInfos[k]) |
| 615 |
idx = k; |
| 616 |
} |
| 617 |
table.setSelection(idx); |
| 618 |
table.showSelection(); |
354 |
table.showSelection(); |
| 619 |
} |
355 |
} |
| 620 |
|
|
|
| 621 |
updateInfoArea(lastSelection); |
| 622 |
} |
356 |
} |
| 623 |
/** |
|
|
| 624 |
* Sort the rows of the table based on the plugin provider. |
| 625 |
* Secondary criteria is unique plugin id. |
| 626 |
*/ |
| 627 |
private void sortByProvider() { |
| 628 |
/* If sorting in reverse, info array is already sorted forward by |
| 629 |
* key so the info array simply needs to be reversed. |
| 630 |
*/ |
| 631 |
if (reverseSort) { |
| 632 |
java.util.List infoList = Arrays.asList(featureInfos); |
| 633 |
Collections.reverse(infoList); |
| 634 |
for (int i = 0; i < featureInfos.length; i++) { |
| 635 |
featureInfos[i] = (AboutInfo) infoList.get(i); |
| 636 |
} |
| 637 |
} else { |
| 638 |
// Sort ascending |
| 639 |
Arrays.sort(featureInfos, new Comparator() { |
| 640 |
Collator coll = Collator.getInstance(Locale.getDefault()); |
| 641 |
public int compare(Object a, Object b) { |
| 642 |
AboutInfo i1, i2; |
| 643 |
String provider1, provider2, name1, name2; |
| 644 |
i1 = (AboutInfo) a; |
| 645 |
provider1 = i1.getProviderName(); |
| 646 |
name1 = i1.getFeatureLabel(); |
| 647 |
if (provider1 == null) |
| 648 |
provider1 = ""; //$NON-NLS-1$ |
| 649 |
if (name1 == null) |
| 650 |
name1 = ""; //$NON-NLS-1$ |
| 651 |
i2 = (AboutInfo) b; |
| 652 |
provider2 = i2.getProviderName(); |
| 653 |
name2 = i2.getFeatureLabel(); |
| 654 |
if (provider2 == null) |
| 655 |
provider2 = ""; //$NON-NLS-1$ |
| 656 |
if (name2 == null) |
| 657 |
name2 = ""; //$NON-NLS-1$ |
| 658 |
if (provider1.equals(provider2)) |
| 659 |
return coll.compare(name1, name2); |
| 660 |
else |
| 661 |
return coll.compare(provider1, provider2); |
| 662 |
} |
| 663 |
}); |
| 664 |
} |
| 665 |
} |
| 666 |
/** |
| 667 |
* Sort the rows of the table based on unique plugin id. |
| 668 |
*/ |
| 669 |
private void sortByName() { |
| 670 |
/* If sorting in reverse, info array is already sorted forward by |
| 671 |
* key so the info array simply needs to be reversed. |
| 672 |
*/ |
| 673 |
if (reverseSort) { |
| 674 |
java.util.List infoList = Arrays.asList(featureInfos); |
| 675 |
Collections.reverse(infoList); |
| 676 |
for (int i = 0; i < featureInfos.length; i++) { |
| 677 |
featureInfos[i] = (AboutInfo) infoList.get(i); |
| 678 |
} |
| 679 |
} else { |
| 680 |
// Sort ascending |
| 681 |
Arrays.sort(featureInfos, new Comparator() { |
| 682 |
Collator coll = Collator.getInstance(Locale.getDefault()); |
| 683 |
public int compare(Object a, Object b) { |
| 684 |
AboutInfo i1, i2; |
| 685 |
String name1, name2; |
| 686 |
i1 = (AboutInfo) a; |
| 687 |
name1 = i1.getFeatureLabel(); |
| 688 |
i2 = (AboutInfo) b; |
| 689 |
name2 = i2.getFeatureLabel(); |
| 690 |
if (name1 == null) |
| 691 |
name1 = ""; //$NON-NLS-1$ |
| 692 |
if (name2 == null) |
| 693 |
name2 = ""; //$NON-NLS-1$ |
| 694 |
return coll.compare(name1, name2); |
| 695 |
} |
| 696 |
}); |
| 697 |
} |
| 698 |
|
357 |
|
| 699 |
} |
|
|
| 700 |
/** |
| 701 |
* Sort the rows of the table based on the plugin version. |
| 702 |
* Secondary criteria is unique plugin id. |
| 703 |
*/ |
| 704 |
private void sortByVersion() { |
| 705 |
/* If sorting in reverse, info array is already sorted forward by |
| 706 |
* key so the info array simply needs to be reversed. |
| 707 |
*/ |
| 708 |
if (reverseSort) { |
| 709 |
java.util.List infoList = Arrays.asList(featureInfos); |
| 710 |
Collections.reverse(infoList); |
| 711 |
for (int i = 0; i < featureInfos.length; i++) { |
| 712 |
featureInfos[i] = (AboutInfo) infoList.get(i); |
| 713 |
} |
| 714 |
} else { |
| 715 |
// Sort ascending |
| 716 |
Arrays.sort(featureInfos, new Comparator() { |
| 717 |
Collator coll = Collator.getInstance(Locale.getDefault()); |
| 718 |
public int compare(Object a, Object b) { |
| 719 |
AboutInfo i1, i2; |
| 720 |
String version1, version2, name1, name2; |
| 721 |
i1 = (AboutInfo) a; |
| 722 |
version1 = i1.getVersionId(); |
| 723 |
name1 = i1.getFeatureLabel(); |
| 724 |
if (version1 == null) |
| 725 |
version1 = ""; //$NON-NLS-1$ |
| 726 |
if (name1 == null) |
| 727 |
name1 = ""; //$NON-NLS-1$ |
| 728 |
i2 = (AboutInfo) b; |
| 729 |
version2 = i2.getVersionId(); |
| 730 |
name2 = i2.getFeatureLabel(); |
| 731 |
if (version2 == null) |
| 732 |
version2 = ""; //$NON-NLS-1$ |
| 733 |
if (name2 == null) |
| 734 |
name2 = ""; //$NON-NLS-1$ |
| 735 |
if (version1.equals(version2)) |
| 736 |
return coll.compare(name1, name2); |
| 737 |
else |
| 738 |
return coll.compare(version1, version2); |
| 739 |
} |
| 740 |
}); |
| 741 |
} |
| 742 |
} |
| 743 |
/** |
358 |
/** |
| 744 |
* Sort the rows of the table based on the feature Id. |
359 |
* @see Window#close() |
| 745 |
* Secondary criteria is unique plugin id. |
360 |
*/ |
| 746 |
*/ |
361 |
public boolean close() { |
| 747 |
private void sortByFeatureId() { |
362 |
boolean ret = super.close(); |
| 748 |
/* If sorting in reverse, info array is already sorted forward by |
363 |
|
| 749 |
* key so the info array simply needs to be reversed. |
364 |
Iterator iter = cachedImages.values().iterator(); |
| 750 |
*/ |
365 |
while (iter.hasNext()) { |
| 751 |
if (reverseSort) { |
366 |
Image image = (Image) iter.next(); |
| 752 |
java.util.List infoList = Arrays.asList(featureInfos); |
367 |
image.dispose(); |
| 753 |
Collections.reverse(infoList); |
368 |
} |
| 754 |
for (int i = 0; i < featureInfos.length; i++) { |
369 |
|
| 755 |
featureInfos[i] = (AboutInfo) infoList.get(i); |
370 |
return ret; |
| 756 |
} |
371 |
} |
| 757 |
} else { |
372 |
|
| 758 |
// Sort ascending |
373 |
/** |
| 759 |
Arrays.sort(featureInfos, new Comparator() { |
374 |
* Returns a mapping from feature id to feature. |
| 760 |
Collator coll = Collator.getInstance(Locale.getDefault()); |
375 |
*/ |
| 761 |
public int compare(Object a, Object b) { |
376 |
private Map getFeaturesMap() { |
| 762 |
AboutInfo i1, i2; |
377 |
if (featuresMap != null) return featuresMap; |
| 763 |
String featureId1, featureId2, name1, name2; |
378 |
|
| 764 |
i1 = (AboutInfo) a; |
379 |
featuresMap = new HashMap(); |
| 765 |
featureId1 = i1.getFeatureId(); |
380 |
|
| 766 |
name1 = i1.getFeatureLabel(); |
381 |
final ILocalSite[] localSiteArray = new ILocalSite[1]; |
| 767 |
if (featureId1 == null) |
382 |
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { |
| 768 |
featureId1 = ""; //$NON-NLS-1$ |
383 |
public void run() { |
| 769 |
if (name1 == null) |
384 |
// this may take a few seconds |
| 770 |
name1 = ""; //$NON-NLS-1$ |
385 |
try { |
| 771 |
i2 = (AboutInfo) b; |
386 |
localSiteArray[0] = SiteManager.getLocalSite(); |
| 772 |
featureId2 = i2.getFeatureId(); |
387 |
} catch (CoreException e) { |
| 773 |
name2 = i2.getFeatureLabel(); |
388 |
MessageDialog |
| 774 |
if (featureId2 == null) |
389 |
.openError( |
| 775 |
featureId2 = ""; //$NON-NLS-1$ |
390 |
getShell(), |
| 776 |
if (name2 == null) |
391 |
IDEWorkbenchMessages |
| 777 |
name2 = ""; //$NON-NLS-1$ |
392 |
.getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ |
| 778 |
if (featureId1.equals(featureId2)) |
393 |
IDEWorkbenchMessages |
| 779 |
return coll.compare(name1, name2); |
394 |
.getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ |
| 780 |
else |
395 |
} |
| 781 |
return coll.compare(featureId1, featureId2); |
396 |
} |
| 782 |
} |
397 |
}); |
| 783 |
}); |
398 |
if (localSiteArray[0] == null) |
| 784 |
} |
399 |
return featuresMap; |
| 785 |
} |
400 |
|
| 786 |
} |
401 |
IInstallConfiguration installConfiguration = localSiteArray[0] |
|
|
402 |
.getCurrentConfiguration(); |
| 403 |
IConfiguredSite[] configuredSites = installConfiguration |
| 404 |
.getConfiguredSites(); |
| 405 |
|
| 406 |
for (int i = 0; i < configuredSites.length; i++) { |
| 407 |
IFeatureReference[] featureReferences = configuredSites[i] |
| 408 |
.getConfiguredFeatures(); |
| 409 |
|
| 410 |
for (int j = 0; j < featureReferences.length; j++) { |
| 411 |
try { |
| 412 |
IFeature feature = featureReferences[j] |
| 413 |
.getFeature(new NullProgressMonitor()); |
| 414 |
|
| 415 |
String key = feature.getVersionedIdentifier().toString(); |
| 416 |
featuresMap.put(key, feature); |
| 417 |
} catch (CoreException e) { |
| 418 |
// do nothing |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
return featuresMap; |
| 424 |
} |
| 425 |
|
| 426 |
/** |
| 427 |
* Return the feature for the given bundle group. |
| 428 |
*/ |
| 429 |
private IFeature getFeatureFor(AboutBundleGroupData info) { |
| 430 |
Map map = getFeaturesMap(); |
| 431 |
if (map == null) |
| 432 |
return null; |
| 433 |
|
| 434 |
String key = info.getId() + "_" + info.getVersion(); //$NON-NLS-1$ |
| 435 |
return (IFeature) map.get(key); |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* Update the button enablement |
| 440 |
*/ |
| 441 |
private void updateButtons(AboutBundleGroupData info) { |
| 442 |
if (info == null) { |
| 443 |
moreButton.setEnabled(false); |
| 444 |
pluginsButton.setEnabled(false); |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
// Creating the feature map is too much just to determine enablement, so if |
| 449 |
// it doesn't already exist, just enable the buttons. If this was the wrong |
| 450 |
// choice, then when the button is actually pressed an dialog will be opened. |
| 451 |
if(featuresMap == null) { |
| 452 |
moreButton.setEnabled(true); |
| 453 |
pluginsButton.setEnabled(true); |
| 454 |
return; |
| 455 |
} |
| 456 |
|
| 457 |
IFeature feature = getFeatureFor(info); |
| 458 |
moreButton.setEnabled(feature != null && feature.getLicense() != null); |
| 459 |
pluginsButton.setEnabled(feature != null); |
| 460 |
} |
| 461 |
|
| 462 |
/** |
| 463 |
* Update the info area |
| 464 |
*/ |
| 465 |
private void updateInfoArea(AboutBundleGroupData info) { |
| 466 |
if (info == null) { |
| 467 |
imageLabel.setImage(null); |
| 468 |
text.setText(""); //$NON-NLS-1$ |
| 469 |
return; |
| 470 |
} |
| 471 |
|
| 472 |
ImageDescriptor desc = info.getFeatureImage(); |
| 473 |
Image image = (Image) cachedImages.get(desc); |
| 474 |
if (image == null && desc != null) { |
| 475 |
image = desc.createImage(); |
| 476 |
cachedImages.put(desc, image); |
| 477 |
} |
| 478 |
imageLabel.setImage(image); |
| 479 |
|
| 480 |
String aboutText = info.getAboutText(); |
| 481 |
setItem(null); |
| 482 |
if (aboutText != null) |
| 483 |
setItem(scan(aboutText)); |
| 484 |
|
| 485 |
if (getItem() == null) |
| 486 |
text.setText(IDEWorkbenchMessages |
| 487 |
.getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ |
| 488 |
else { |
| 489 |
text.setText(getItem().getText()); |
| 490 |
text.setCursor(null); |
| 491 |
setLinkRanges(text, getItem().getLinkRanges()); |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* Select the initial selection |
| 497 |
*/ |
| 498 |
public void setInitialSelection(AboutBundleGroupData info) { |
| 499 |
lastSelection = info; |
| 500 |
} |
| 501 |
|
| 502 |
/** |
| 503 |
* Sort the rows of the table based on the selected column. |
| 504 |
* |
| 505 |
* @param column |
| 506 |
* index of table column selected as sort criteria |
| 507 |
*/ |
| 508 |
private void sort(int column) { |
| 509 |
if (lastColumnChosen == column) |
| 510 |
reverseSort = !reverseSort; |
| 511 |
else { |
| 512 |
reverseSort = false; |
| 513 |
lastColumnChosen = column; |
| 514 |
} |
| 515 |
|
| 516 |
if (table.getItemCount() <= 1) |
| 517 |
return; |
| 518 |
|
| 519 |
// Remember the last selection |
| 520 |
int sel = table.getSelectionIndex(); |
| 521 |
if (sel != -1) |
| 522 |
lastSelection = bundleGroupInfos[sel]; |
| 523 |
|
| 524 |
switch (column) { |
| 525 |
case 0: |
| 526 |
AboutData.sortByProvider(reverseSort, bundleGroupInfos); |
| 527 |
break; |
| 528 |
case 1: |
| 529 |
AboutData.sortByName(reverseSort, bundleGroupInfos); |
| 530 |
break; |
| 531 |
case 2: |
| 532 |
AboutData.sortByVersion(reverseSort, bundleGroupInfos); |
| 533 |
break; |
| 534 |
case 3: |
| 535 |
AboutData.sortById(reverseSort, bundleGroupInfos); |
| 536 |
break; |
| 537 |
} |
| 538 |
|
| 539 |
refreshTable(column); |
| 540 |
} |
| 541 |
|
| 542 |
/** |
| 543 |
* Refresh the rows of the table based on the selected column. Maintain |
| 544 |
* selection from before sort action request. |
| 545 |
*/ |
| 546 |
private void refreshTable(int col) { |
| 547 |
TableItem[] items = table.getItems(); |
| 548 |
|
| 549 |
// create new order of table items |
| 550 |
for (int i = 0; i < items.length; i++) { |
| 551 |
items[i].setText(createRow(bundleGroupInfos[i])); |
| 552 |
items[i].setData(bundleGroupInfos[i]); |
| 553 |
} |
| 554 |
|
| 555 |
// Maintain the original selection |
| 556 |
int sel = -1; |
| 557 |
if (lastSelection != null) { |
| 558 |
String oldId = lastSelection.getId(); |
| 559 |
for (int k = 0; k < bundleGroupInfos.length; k++) |
| 560 |
if (oldId.equalsIgnoreCase(bundleGroupInfos[k].getId())) |
| 561 |
sel = k; |
| 562 |
|
| 563 |
table.setSelection(sel); |
| 564 |
table.showSelection(); |
| 565 |
} |
| 566 |
|
| 567 |
updateInfoArea(lastSelection); |
| 568 |
} |
| 569 |
|
| 570 |
/** |
| 571 |
* Return an array of strings containing the argument's information in the |
| 572 |
* proper order for this table's columns. |
| 573 |
* |
| 574 |
* @param info |
| 575 |
* the source information for the new row, must not be null |
| 576 |
*/ |
| 577 |
private static String[] createRow(AboutBundleGroupData info) { |
| 578 |
return new String[] { info.getProviderName(), info.getName(), |
| 579 |
info.getVersion(), info.getId()}; |
| 580 |
} |
| 581 |
} |