|
Lines 12-672
Link Here
|
| 12 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 13 |
package org.eclipse.ui.internal.dialogs; |
13 |
package org.eclipse.ui.internal.dialogs; |
| 14 |
|
14 |
|
| 15 |
import java.io.IOException; |
|
|
| 16 |
import java.net.URL; |
| 17 |
import java.util.ArrayList; |
| 18 |
import java.util.HashMap; |
| 19 |
import java.util.LinkedList; |
| 20 |
import java.util.List; |
| 21 |
import java.util.Map; |
| 22 |
|
| 23 |
import org.eclipse.core.runtime.IPath; |
| 24 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 25 |
import org.eclipse.core.runtime.IStatus; |
| 26 |
import org.eclipse.core.runtime.Path; |
| 27 |
import org.eclipse.core.runtime.Platform; |
| 28 |
import org.eclipse.core.runtime.Status; |
| 29 |
import org.eclipse.core.runtime.jobs.Job; |
| 30 |
import org.eclipse.jface.dialogs.DialogTray; |
| 31 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 32 |
import org.eclipse.jface.internal.ConfigureColumnsDialog; |
| 33 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
| 34 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
| 35 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 37 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 38 |
import org.eclipse.jface.viewers.LabelProvider; |
| 39 |
import org.eclipse.jface.viewers.LabelProviderChangedEvent; |
| 40 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 41 |
import org.eclipse.jface.viewers.TableViewer; |
| 42 |
import org.eclipse.jface.viewers.Viewer; |
| 43 |
import org.eclipse.jface.viewers.ViewerComparator; |
| 44 |
import org.eclipse.osgi.util.NLS; |
15 |
import org.eclipse.osgi.util.NLS; |
| 45 |
import org.eclipse.swt.SWT; |
|
|
| 46 |
import org.eclipse.swt.events.SelectionAdapter; |
| 47 |
import org.eclipse.swt.events.SelectionEvent; |
| 48 |
import org.eclipse.swt.graphics.Image; |
| 49 |
import org.eclipse.swt.layout.GridData; |
| 50 |
import org.eclipse.swt.layout.GridLayout; |
| 51 |
import org.eclipse.swt.widgets.Button; |
| 52 |
import org.eclipse.swt.widgets.Composite; |
| 53 |
import org.eclipse.swt.widgets.Control; |
| 54 |
import org.eclipse.swt.widgets.Label; |
| 55 |
import org.eclipse.swt.widgets.Shell; |
16 |
import org.eclipse.swt.widgets.Shell; |
| 56 |
import org.eclipse.swt.widgets.TableColumn; |
|
|
| 57 |
import org.eclipse.ui.PlatformUI; |
| 58 |
import org.eclipse.ui.internal.IWorkbenchGraphicConstants; |
| 59 |
import org.eclipse.ui.internal.IWorkbenchHelpContextIds; |
| 60 |
import org.eclipse.ui.internal.WorkbenchImages; |
| 61 |
import org.eclipse.ui.internal.WorkbenchMessages; |
17 |
import org.eclipse.ui.internal.WorkbenchMessages; |
| 62 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
18 |
import org.eclipse.ui.internal.about.AboutPluginsPage; |
| 63 |
import org.eclipse.ui.internal.about.AboutBundleData; |
|
|
| 64 |
import org.eclipse.ui.internal.misc.StatusUtil; |
| 65 |
import org.eclipse.ui.internal.util.BundleUtility; |
| 66 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 67 |
import org.eclipse.ui.statushandlers.StatusManager; |
| 68 |
import org.osgi.framework.Bundle; |
19 |
import org.osgi.framework.Bundle; |
|
|
20 |
import org.eclipse.ui.internal.about.ProductInfoDialog; |
| 69 |
|
21 |
|
| 70 |
/** |
22 |
/** |
| 71 |
* Displays information about the product plugins. |
23 |
* Displays information about the product plugins. |
| 72 |
* |
24 |
* |
| 73 |
* PRIVATE |
25 |
* PRIVATE this class is internal to the ide |
| 74 |
* this class is internal to the ide |
|
|
| 75 |
*/ |
26 |
*/ |
| 76 |
public class AboutPluginsDialog extends ProductInfoDialog { |
27 |
public class AboutPluginsDialog extends ProductInfoDialog { |
| 77 |
|
|
|
| 78 |
public class BundleTableLabelProvider extends LabelProvider implements ITableLabelProvider { |
| 79 |
|
| 80 |
/** |
| 81 |
* Queue containing bundle signing info to be resolved. |
| 82 |
*/ |
| 83 |
private LinkedList resolveQueue = new LinkedList(); |
| 84 |
|
| 85 |
/** |
| 86 |
* Queue containing bundle data that's been resolve and needs updating. |
| 87 |
*/ |
| 88 |
private List updateQueue = new ArrayList(); |
| 89 |
|
| 90 |
/* |
| 91 |
* this job will attempt to discover the signing state of a given bundle |
| 92 |
* and then send it along to the update job |
| 93 |
*/ |
| 94 |
private Job resolveJob= new Job(AboutPluginsDialog.class.getName()) { |
| 95 |
{ |
| 96 |
setSystem(true); |
| 97 |
setPriority(Job.SHORT); |
| 98 |
} |
| 99 |
|
| 100 |
protected IStatus run(IProgressMonitor monitor) { |
| 101 |
while (true) { |
| 102 |
Shell dialogShell = getShell(); |
| 103 |
// the shell has gone down since we were asked to render |
| 104 |
if (dialogShell == null || dialogShell.isDisposed()) |
| 105 |
return Status.OK_STATUS; |
| 106 |
AboutBundleData data = null; |
| 107 |
synchronized (resolveQueue) { |
| 108 |
if (resolveQueue.isEmpty()) |
| 109 |
return Status.OK_STATUS; |
| 110 |
data = (AboutBundleData) resolveQueue.removeFirst(); |
| 111 |
} |
| 112 |
try { |
| 113 |
// following is an expensive call |
| 114 |
data.isSigned(); |
| 115 |
|
| 116 |
synchronized (updateQueue) { |
| 117 |
updateQueue.add(data); |
| 118 |
} |
| 119 |
// start the update job |
| 120 |
updateJob.schedule(); |
| 121 |
} catch (IllegalStateException e) { |
| 122 |
// the bundle we're testing has been unloaded. Do nothing. |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
/* |
| 129 |
* this job is responsible for feeding label change events into the |
| 130 |
* viewer as they become available from the resolve job |
| 131 |
*/ |
| 132 |
private Job updateJob= new WorkbenchJob(getShell().getDisplay(), AboutPluginsDialog.class.getName()) { |
| 133 |
{ |
| 134 |
setSystem(true); |
| 135 |
setPriority(Job.DECORATE); |
| 136 |
} |
| 137 |
|
| 138 |
/* (non-Javadoc) |
| 139 |
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) |
| 140 |
*/ |
| 141 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
| 142 |
while (true) { |
| 143 |
Shell dialogShell = getShell(); |
| 144 |
// the shell has gone down since we were asked to render |
| 145 |
if (dialogShell == null || dialogShell.isDisposed()) |
| 146 |
return Status.OK_STATUS; |
| 147 |
AboutBundleData[] data = null; |
| 148 |
synchronized (updateQueue) { |
| 149 |
if (updateQueue.isEmpty()) |
| 150 |
return Status.OK_STATUS; |
| 151 |
|
| 152 |
data = (AboutBundleData[]) updateQueue |
| 153 |
.toArray(new AboutBundleData[updateQueue.size()]); |
| 154 |
updateQueue.clear(); |
| 155 |
|
| 156 |
} |
| 157 |
fireLabelProviderChanged(new LabelProviderChangedEvent( |
| 158 |
BundleTableLabelProvider.this, data)); |
| 159 |
} |
| 160 |
} |
| 161 |
}; |
| 162 |
|
| 163 |
/* (non-Javadoc) |
| 164 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) |
| 165 |
*/ |
| 166 |
public Image getColumnImage(Object element, int columnIndex) { |
| 167 |
if (columnIndex == 0) { |
| 168 |
if (element instanceof AboutBundleData) { |
| 169 |
final AboutBundleData data = (AboutBundleData) element; |
| 170 |
if (data.isSignedDetermined()) { |
| 171 |
return WorkbenchImages |
| 172 |
.getImage(data.isSigned() ? IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_YES |
| 173 |
: IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_NO); |
| 174 |
} |
| 175 |
|
| 176 |
synchronized (resolveQueue) { |
| 177 |
resolveQueue.add(data); |
| 178 |
} |
| 179 |
resolveJob.schedule(); |
| 180 |
|
| 181 |
return WorkbenchImages |
| 182 |
.getImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_UNKNOWN); |
| 183 |
} |
| 184 |
} |
| 185 |
return null; |
| 186 |
} |
| 187 |
|
| 188 |
/* (non-Javadoc) |
| 189 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) |
| 190 |
*/ |
| 191 |
public String getColumnText(Object element, int columnIndex) { |
| 192 |
if (element instanceof AboutBundleData) { |
| 193 |
AboutBundleData data = (AboutBundleData) element; |
| 194 |
switch (columnIndex) { |
| 195 |
case 1: |
| 196 |
return data.getProviderName(); |
| 197 |
case 2: |
| 198 |
return data.getName(); |
| 199 |
case 3: |
| 200 |
return data.getVersion(); |
| 201 |
case 4: |
| 202 |
return data.getId(); |
| 203 |
} |
| 204 |
} |
| 205 |
return ""; //$NON-NLS-1$ |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Table height in dialog units (value 200). |
| 211 |
*/ |
| 212 |
private static final int TABLE_HEIGHT = 200; |
| 213 |
|
| 214 |
private static final IPath baseNLPath = new Path("$nl$"); //$NON-NLS-1$ |
| 215 |
|
| 216 |
private static final String PLUGININFO = "about.html"; //$NON-NLS-1$ |
| 217 |
|
| 218 |
private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; |
| 219 |
private final static int SIGNING_ID = MORE_ID + 1; |
| 220 |
private final static int COLUMNS_ID = MORE_ID + 2; |
| 221 |
|
| 222 |
private static final int PLUGIN_NAME_COLUMN_INDEX = 2; |
| 223 |
|
| 224 |
private TableViewer vendorInfo; |
| 225 |
|
| 226 |
private Button moreInfo, signingInfo; |
| 227 |
|
| 228 |
private String title; |
| 229 |
|
| 230 |
private String message; |
| 231 |
|
| 232 |
private String helpContextId; |
| 233 |
|
| 234 |
private String columnTitles[] = { |
| 235 |
WorkbenchMessages.AboutPluginsDialog_signed, |
| 236 |
WorkbenchMessages.AboutPluginsDialog_provider, |
| 237 |
WorkbenchMessages.AboutPluginsDialog_pluginName, |
| 238 |
WorkbenchMessages.AboutPluginsDialog_version, |
| 239 |
WorkbenchMessages.AboutPluginsDialog_pluginId, |
| 240 |
|
| 241 |
}; |
| 242 |
|
| 243 |
private String productName; |
| 244 |
|
| 245 |
private AboutBundleData[] bundleInfos; |
| 246 |
|
| 247 |
/** |
| 248 |
* Constructor for AboutPluginsDialog. |
| 249 |
* |
| 250 |
* @param parentShell the parent shell |
| 251 |
* @param productName the product name |
| 252 |
*/ |
| 253 |
public AboutPluginsDialog(Shell parentShell, String productName) { |
| 254 |
this(parentShell, productName, WorkbenchPlugin.getDefault() |
| 255 |
.getBundles(), null, null, IWorkbenchHelpContextIds.ABOUT_PLUGINS_DIALOG); |
| 256 |
WorkbenchPlugin.class.getSigners(); |
| 257 |
} |
| 258 |
|
| 259 |
/** |
| 260 |
* Constructor for AboutPluginsDialog. |
| 261 |
* |
| 262 |
* @param parentShell |
| 263 |
* the parent shell |
| 264 |
* @param productName |
| 265 |
* must not be null |
| 266 |
* @param bundles |
| 267 |
* must not be null |
| 268 |
* @param title |
| 269 |
* the title |
| 270 |
* @param message |
| 271 |
* the message |
| 272 |
* @param helpContextId |
| 273 |
* the help context id |
| 274 |
*/ |
| 275 |
public AboutPluginsDialog(Shell parentShell, String productName, |
28 |
public AboutPluginsDialog(Shell parentShell, String productName, |
| 276 |
Bundle[] bundles, String title, String message, String helpContextId) { |
29 |
Bundle[] bundles, String title, String message, String helpContextId) { |
| 277 |
super(parentShell); |
30 |
super(parentShell); |
| 278 |
this.title = title; |
31 |
AboutPluginsPage page = new AboutPluginsPage(); |
| 279 |
this.message = message; |
32 |
page.setHelpContextId(helpContextId); |
| 280 |
this.helpContextId = helpContextId; |
33 |
page.setBundles(bundles); |
| 281 |
this.productName = productName; |
34 |
page.setMessage(message); |
| 282 |
|
35 |
if (title == null && page.getProductName() != null) |
| 283 |
// create a data object for each bundle, remove duplicates, and include only resolved bundles (bug 65548) |
36 |
title = NLS.bind(WorkbenchMessages.AboutPluginsDialog_shellTitle, productName); |
| 284 |
Map map = new HashMap(); |
37 |
initializeDialog(page, title, helpContextId); |
| 285 |
for (int i = 0; i < bundles.length; ++i) { |
|
|
| 286 |
AboutBundleData data = new AboutBundleData(bundles[i]); |
| 287 |
if (BundleUtility.isReady(data.getState()) && !map.containsKey(data.getVersionedId())) { |
| 288 |
map.put(data.getVersionedId(), data); |
| 289 |
} |
| 290 |
} |
| 291 |
bundleInfos = (AboutBundleData[]) map.values().toArray( |
| 292 |
new AboutBundleData[0]); |
| 293 |
} |
| 294 |
|
| 295 |
/* |
| 296 |
* (non-Javadoc) Method declared on Dialog. |
| 297 |
*/ |
| 298 |
protected void buttonPressed(int buttonId) { |
| 299 |
switch (buttonId) { |
| 300 |
case MORE_ID: |
| 301 |
handleMoreInfoPressed(); |
| 302 |
break; |
| 303 |
case SIGNING_ID: |
| 304 |
handleSigningInfoPressed(); |
| 305 |
break; |
| 306 |
case COLUMNS_ID: |
| 307 |
handleColumnsPressed(); |
| 308 |
break; |
| 309 |
default: |
| 310 |
super.buttonPressed(buttonId); |
| 311 |
break; |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* |
| 317 |
*/ |
| 318 |
private void handleColumnsPressed() { |
| 319 |
ConfigureColumnsDialog d = new ConfigureColumnsDialog(this, vendorInfo.getTable()); |
| 320 |
d.open(); |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
*/ |
| 325 |
private void handleSigningInfoPressed() { |
| 326 |
DialogTray existingTray = getTray(); |
| 327 |
if (existingTray instanceof BundleSigningTray) { |
| 328 |
// hide |
| 329 |
getButton(SIGNING_ID).setText(WorkbenchMessages.AboutPluginsDialog_signingInfo_show); |
| 330 |
closeTray(); |
| 331 |
} |
| 332 |
else { |
| 333 |
//show |
| 334 |
getButton(SIGNING_ID).setText(WorkbenchMessages.AboutPluginsDialog_signingInfo_hide); |
| 335 |
if (existingTray != null) |
| 336 |
closeTray(); |
| 337 |
AboutBundleData bundleInfo = (AboutBundleData) ((IStructuredSelection) vendorInfo |
| 338 |
.getSelection()).getFirstElement(); |
| 339 |
BundleSigningTray tray = new BundleSigningTray(this); |
| 340 |
tray.setData(bundleInfo); |
| 341 |
openTray(tray); |
| 342 |
} |
| 343 |
|
| 344 |
} |
| 345 |
|
| 346 |
/* |
| 347 |
* (non-Javadoc) Method declared on Window. |
| 348 |
*/ |
| 349 |
protected void configureShell(Shell newShell) { |
| 350 |
super.configureShell(newShell); |
| 351 |
|
| 352 |
//signImage = new Image( this.getParentShell().getDisplay(), AboutPluginsDialog.class.getResourceAsStream("Signed.gif")); //$NON-NLS-1$ |
| 353 |
|
| 354 |
if (title == null && productName != null) { |
| 355 |
title = NLS.bind(WorkbenchMessages.AboutPluginsDialog_shellTitle, productName); |
| 356 |
} |
| 357 |
|
| 358 |
if (title != null) { |
| 359 |
newShell.setText(title); |
| 360 |
} |
| 361 |
|
| 362 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, |
| 363 |
helpContextId); |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Add buttons to the dialog's button bar. |
| 368 |
* |
| 369 |
* Subclasses should override. |
| 370 |
* |
| 371 |
* @param parent |
| 372 |
* the button bar composite |
| 373 |
*/ |
| 374 |
protected void createButtonsForButtonBar(Composite parent) { |
| 375 |
parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 376 |
|
| 377 |
moreInfo = createButton(parent, MORE_ID, WorkbenchMessages.AboutPluginsDialog_moreInfo, false); |
| 378 |
moreInfo.setEnabled(false); |
| 379 |
|
| 380 |
signingInfo = createButton(parent, SIGNING_ID, WorkbenchMessages.AboutPluginsDialog_signingInfo_show, false); |
| 381 |
signingInfo.setEnabled(false); |
| 382 |
|
| 383 |
createButton(parent, COLUMNS_ID, WorkbenchMessages.AboutPluginsDialog_columns, false); |
| 384 |
|
| 385 |
Label l = new Label(parent, SWT.NONE); |
| 386 |
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 387 |
GridLayout layout = (GridLayout) parent.getLayout(); |
| 388 |
layout.numColumns++; |
| 389 |
layout.makeColumnsEqualWidth = false; |
| 390 |
|
| 391 |
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
| 392 |
true); |
| 393 |
} |
| 394 |
|
| 395 |
/** |
| 396 |
* Create the contents of the dialog (above the button bar). |
| 397 |
* |
| 398 |
* Subclasses should overide. |
| 399 |
* |
| 400 |
* @param parent |
| 401 |
* the parent composite to contain the dialog area |
| 402 |
* @return the dialog area control |
| 403 |
*/ |
| 404 |
protected Control createDialogArea(Composite parent) { |
| 405 |
Composite outer = (Composite) super.createDialogArea(parent); |
| 406 |
|
| 407 |
if (message != null) { |
| 408 |
Label label = new Label(outer, SWT.NONE); |
| 409 |
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 410 |
label.setFont(parent.getFont()); |
| 411 |
label.setText(message); |
| 412 |
} |
| 413 |
|
| 414 |
createTable(outer); |
| 415 |
|
| 416 |
return outer; |
| 417 |
} |
| 418 |
|
| 419 |
/** |
| 420 |
* Create the table part of the dialog. |
| 421 |
* |
| 422 |
* @param parent |
| 423 |
* the parent composite to contain the dialog area |
| 424 |
*/ |
| 425 |
protected void createTable(Composite parent) { |
| 426 |
vendorInfo = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE |
| 427 |
| SWT.FULL_SELECTION | SWT.BORDER); |
| 428 |
vendorInfo.setUseHashlookup(true); |
| 429 |
vendorInfo.getTable().setHeaderVisible(true); |
| 430 |
vendorInfo.getTable().setLinesVisible(true); |
| 431 |
vendorInfo.getTable().setFont(parent.getFont()); |
| 432 |
vendorInfo.addSelectionChangedListener(new ISelectionChangedListener() { |
| 433 |
|
| 434 |
public void selectionChanged(SelectionChangedEvent event) { |
| 435 |
// enable if there is an item selected and that |
| 436 |
// item has additional info |
| 437 |
IStructuredSelection selection = (IStructuredSelection) event.getSelection(); |
| 438 |
if (selection.getFirstElement() instanceof AboutBundleData) { |
| 439 |
AboutBundleData selected = (AboutBundleData) selection.getFirstElement(); |
| 440 |
moreInfo.setEnabled(selectionHasInfo(selected)); |
| 441 |
signingInfo.setEnabled(true); |
| 442 |
if (getTray() instanceof BundleSigningTray) { |
| 443 |
((BundleSigningTray)getTray()).setData(selected); |
| 444 |
} |
| 445 |
} |
| 446 |
else { |
| 447 |
moreInfo.setEnabled(false); |
| 448 |
signingInfo.setEnabled(false); |
| 449 |
} |
| 450 |
}}); |
| 451 |
|
| 452 |
final TableComparator comparator = new TableComparator(); |
| 453 |
vendorInfo.setComparator(comparator); |
| 454 |
int[] columnWidths = { |
| 455 |
convertHorizontalDLUsToPixels(30), //signature |
| 456 |
convertHorizontalDLUsToPixels(120), |
| 457 |
convertHorizontalDLUsToPixels(120), |
| 458 |
convertHorizontalDLUsToPixels(70), |
| 459 |
convertHorizontalDLUsToPixels(130), |
| 460 |
}; |
| 461 |
|
| 462 |
|
| 463 |
// create table headers |
| 464 |
for (int i = 0; i < columnTitles.length; i++) { |
| 465 |
TableColumn column = new TableColumn(vendorInfo.getTable(), SWT.NULL); |
| 466 |
if (i == PLUGIN_NAME_COLUMN_INDEX) { // prime initial sorting |
| 467 |
updateTableSorting(i); |
| 468 |
} |
| 469 |
column.setWidth(columnWidths[i]); |
| 470 |
column.setText(columnTitles[i]); |
| 471 |
final int columnIndex = i; |
| 472 |
column.addSelectionListener(new SelectionAdapter() { |
| 473 |
public void widgetSelected(SelectionEvent e) { |
| 474 |
updateTableSorting(columnIndex); |
| 475 |
} |
| 476 |
}); |
| 477 |
} |
| 478 |
|
| 479 |
vendorInfo.setContentProvider(new ArrayContentProvider()); |
| 480 |
vendorInfo.setLabelProvider(new BundleTableLabelProvider()); |
| 481 |
|
| 482 |
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, |
| 483 |
true); |
| 484 |
gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); |
| 485 |
vendorInfo.getTable().setLayoutData(gridData); |
| 486 |
|
| 487 |
vendorInfo.setInput(bundleInfos); |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Update the sort information on both the comparator and the table. |
| 492 |
* |
| 493 |
* @param columnIndex |
| 494 |
* the index to sort by |
| 495 |
* @since 3.4 |
| 496 |
*/ |
| 497 |
private void updateTableSorting(final int columnIndex) { |
| 498 |
TableComparator comparator = (TableComparator) vendorInfo |
| 499 |
.getComparator(); |
| 500 |
// toggle direction if it's the same column |
| 501 |
if (columnIndex == comparator.getSortColumn()) { |
| 502 |
comparator.setAscending(!comparator.isAscending()); |
| 503 |
} |
| 504 |
comparator.setSortColumn(columnIndex); |
| 505 |
vendorInfo.getTable().setSortColumn( |
| 506 |
vendorInfo.getTable().getColumn(columnIndex)); |
| 507 |
vendorInfo.getTable().setSortDirection( |
| 508 |
comparator.isAscending() ? SWT.UP : SWT.DOWN); |
| 509 |
vendorInfo.refresh(false); |
| 510 |
} |
| 511 |
|
| 512 |
/** |
| 513 |
* Check if the currently selected plugin has additional information to |
| 514 |
* show. |
| 515 |
* @param bundleInfo |
| 516 |
* |
| 517 |
* @return true if the selected plugin has additional info available to |
| 518 |
* display |
| 519 |
*/ |
| 520 |
private boolean selectionHasInfo(AboutBundleData bundleInfo) { |
| 521 |
|
| 522 |
URL infoURL = getMoreInfoURL(bundleInfo, false); |
| 523 |
|
| 524 |
// only report ini problems if the -debug command line argument is used |
| 525 |
if (infoURL == null && WorkbenchPlugin.DEBUG) { |
| 526 |
WorkbenchPlugin.log("Problem reading plugin info for: " //$NON-NLS-1$ |
| 527 |
+ bundleInfo.getName()); |
| 528 |
} |
| 529 |
|
| 530 |
return infoURL != null; |
| 531 |
} |
| 532 |
|
| 533 |
/** |
| 534 |
* The More Info button was pressed. Open a browser showing the license information |
| 535 |
* for the selected bundle or an error dialog if the browser cannot be opened. |
| 536 |
*/ |
| 537 |
protected void handleMoreInfoPressed() { |
| 538 |
if (vendorInfo == null) { |
| 539 |
return; |
| 540 |
} |
| 541 |
|
| 542 |
if (vendorInfo.getSelection().isEmpty()) |
| 543 |
return; |
| 544 |
|
| 545 |
AboutBundleData bundleInfo = (AboutBundleData) ((IStructuredSelection) vendorInfo |
| 546 |
.getSelection()).getFirstElement(); |
| 547 |
|
| 548 |
if (!openBrowser(getMoreInfoURL(bundleInfo, true))) { |
| 549 |
String message = NLS.bind( |
| 550 |
WorkbenchMessages.AboutPluginsDialog_unableToOpenFile, |
| 551 |
PLUGININFO, bundleInfo.getId()); |
| 552 |
StatusUtil.handleStatus( |
| 553 |
WorkbenchMessages.AboutPluginsDialog_errorTitle |
| 554 |
+ ": " + message, StatusManager.SHOW, getShell()); //$NON-NLS-1$ |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
/** |
| 559 |
* Return an url to the plugin's about.html file (what is shown when "More info" is |
| 560 |
* pressed) or null if no such file exists. The method does nl lookup to allow for |
| 561 |
* i18n. |
| 562 |
* |
| 563 |
* @param bundleInfo the bundle info |
| 564 |
* @param makeLocal whether to make the about content local |
| 565 |
* @return the url or <code>null</code> |
| 566 |
*/ |
| 567 |
private URL getMoreInfoURL(AboutBundleData bundleInfo, boolean makeLocal) { |
| 568 |
Bundle bundle = Platform.getBundle(bundleInfo.getId()); |
| 569 |
if (bundle == null) { |
| 570 |
return null; |
| 571 |
} |
| 572 |
|
| 573 |
URL aboutUrl = Platform.find(bundle, baseNLPath.append(PLUGININFO), null); |
| 574 |
if (!makeLocal) { |
| 575 |
return aboutUrl; |
| 576 |
} |
| 577 |
if (aboutUrl != null) { |
| 578 |
try { |
| 579 |
URL result = Platform.asLocalURL(aboutUrl); |
| 580 |
try { |
| 581 |
// Make local all content in the "about" directory. |
| 582 |
// This is needed to handle jar'ed plug-ins. |
| 583 |
// See Bug 88240 [About] About dialog needs to extract subdirs. |
| 584 |
URL about = new URL(aboutUrl, "about_files"); //$NON-NLS-1$ |
| 585 |
if (about != null) { |
| 586 |
Platform.asLocalURL(about); |
| 587 |
} |
| 588 |
} catch (IOException e) { |
| 589 |
// skip the about dir if its not found or there are other problems. |
| 590 |
} |
| 591 |
return result; |
| 592 |
} catch(IOException e) { |
| 593 |
// do nothing |
| 594 |
} |
| 595 |
} |
| 596 |
return null; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
class TableComparator extends ViewerComparator { |
| 602 |
|
| 603 |
private int sortColumn = 0; |
| 604 |
private boolean ascending = true; |
| 605 |
|
| 606 |
/* (non-Javadoc) |
| 607 |
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
| 608 |
*/ |
| 609 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 610 |
if (sortColumn == 0 && e1 instanceof AboutBundleData && e2 instanceof AboutBundleData) { |
| 611 |
AboutBundleData d1= (AboutBundleData) e1; |
| 612 |
AboutBundleData d2= (AboutBundleData) e2; |
| 613 |
int diff= getSignedSortValue(d1) - getSignedSortValue(d2); |
| 614 |
return ascending ? diff : -diff; |
| 615 |
} |
| 616 |
if (viewer instanceof TableViewer) { |
| 617 |
TableViewer tableViewer = (TableViewer) viewer; |
| 618 |
IBaseLabelProvider baseLabel = tableViewer.getLabelProvider(); |
| 619 |
if (baseLabel instanceof ITableLabelProvider) { |
| 620 |
ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel; |
| 621 |
String e1p = tableProvider.getColumnText(e1, sortColumn); |
| 622 |
String e2p = tableProvider.getColumnText(e2, sortColumn); |
| 623 |
int result = getComparator().compare(e1p, e2p); |
| 624 |
return ascending ? result : (-1) * result; |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
return super.compare(viewer, e1, e2); |
| 629 |
} |
| 630 |
|
| 631 |
/** |
| 632 |
* @param data |
| 633 |
* @return a sort value depending on the signed state |
| 634 |
*/ |
| 635 |
private int getSignedSortValue(AboutBundleData data) { |
| 636 |
if (! data.isSignedDetermined()) { |
| 637 |
return 0; |
| 638 |
} else if (data.isSigned()) { |
| 639 |
return 1; |
| 640 |
} else { |
| 641 |
return -1; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
/** |
| 646 |
* @return Returns the sortColumn. |
| 647 |
*/ |
| 648 |
public int getSortColumn() { |
| 649 |
return sortColumn; |
| 650 |
} |
| 651 |
|
| 652 |
/** |
| 653 |
* @param sortColumn The sortColumn to set. |
| 654 |
*/ |
| 655 |
public void setSortColumn(int sortColumn) { |
| 656 |
this.sortColumn = sortColumn; |
| 657 |
} |
| 658 |
|
| 659 |
/** |
| 660 |
* @return Returns the ascending. |
| 661 |
*/ |
| 662 |
public boolean isAscending() { |
| 663 |
return ascending; |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* @param ascending The ascending to set. |
| 668 |
*/ |
| 669 |
public void setAscending(boolean ascending) { |
| 670 |
this.ascending = ascending; |
| 671 |
} |
38 |
} |
| 672 |
} |
39 |
} |