Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 9219 Details for
Bug 54548
[About] About dialog should obtain info from IProduct and IBundleGroup instead of platform configuration
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch
ide.2 (text/plain), 107.63 KB, created by
Andrew Eidsness
on 2004-04-05 12:31:42 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Andrew Eidsness
Created:
2004-04-05 12:31:42 EDT
Size:
107.63 KB
patch
obsolete
>Index: src/org/eclipse/ui/internal/ide/messages.properties >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v >retrieving revision 1.20 >diff -u -r1.20 messages.properties >--- src/org/eclipse/ui/internal/ide/messages.properties 25 Mar 2004 21:43:15 -0000 1.20 >+++ src/org/eclipse/ui/internal/ide/messages.properties 5 Apr 2004 16:12:50 -0000 >@@ -361,6 +361,7 @@ > AboutDialog.platformInfo = Built with Eclipse technology > AboutDialog.systemInfo = &Configuration Details > AboutDialog.notSpecified= Not Specified >+AboutDialog.defaultProductName = Eclipse-based Product > ProductInfoDialog.errorTitle = Problems Opening Link > ProductInfoDialog.unableToOpenWebBrowser = Unable to open web browser. > AboutPluginsDialog.shellTitle = About {0} Plug-ins >Index: src/org/eclipse/ui/internal/ide/actions/AboutAction.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/AboutAction.java,v >retrieving revision 1.4 >diff -u -r1.4 AboutAction.java >--- src/org/eclipse/ui/internal/ide/actions/AboutAction.java 11 Nov 2003 04:48:20 -0000 1.4 >+++ src/org/eclipse/ui/internal/ide/actions/AboutAction.java 5 Apr 2004 16:12:50 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,14 +10,14 @@ > *******************************************************************************/ > package org.eclipse.ui.internal.ide.actions; > >+import org.eclipse.core.runtime.IBundleGroupProvider; >+import org.eclipse.core.runtime.IProduct; >+import org.eclipse.core.runtime.Platform; > import org.eclipse.jface.action.Action; >-// @issue org.eclipse.ui.internal.AboutInfo - illegal reference to generic workbench internals >-import org.eclipse.ui.internal.AboutInfo; > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.actions.ActionFactory; > import org.eclipse.ui.help.WorkbenchHelp; > import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; >-import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; > import org.eclipse.ui.internal.ide.IHelpContextIds; > import org.eclipse.ui.internal.ide.dialogs.AboutDialog; > >@@ -44,14 +44,12 @@ > this.workbenchWindow = window; > > // use message with no fill-in >- AboutInfo primaryInfo = IDEWorkbenchPlugin.getDefault().getPrimaryInfo(); >+ IProduct product = Platform.getProduct(); > String productName = null; >- if (primaryInfo != null) { >- productName = primaryInfo.getProductName(); >- } >- if (productName == null) { >+ if (product != null) >+ productName = product.getName(); >+ if (productName == null) > productName = ""; //$NON-NLS-1$ >- } > setText(IDEWorkbenchMessages.format("AboutAction.text", new Object[] { productName })); //$NON-NLS-1$ > setToolTipText(IDEWorkbenchMessages.format("AboutAction.toolTip", new Object[] { productName})); //$NON-NLS-1$ > setId("about"); //$NON-NLS-1$ >@@ -63,22 +61,15 @@ > * Method declared on IAction. > */ > public void run() { >- if (workbenchWindow == null) { >- // action has been disposed >- return; >- } >- AboutInfo primaryInfo = IDEWorkbenchPlugin.getDefault().getPrimaryInfo(); >- AboutInfo[] featureInfos = IDEWorkbenchPlugin.getDefault().getFeatureInfos(); >-// if (primaryInfo == null) { >-// // @issue illegal to pass null status to openError >-// ErrorDialog.openError( >-// workbenchWindow.getShell(), >-// IDEWorkbenchMessages.format("AboutAction.errorDialogTitle", new Object[] {getText()}), //$NON-NLS-1$ >-// IDEWorkbenchMessages.getString("AboutInfo.infoReadError"), //$NON-NLS-1$ >-// null); >-// return; >-// } >- new AboutDialog(workbenchWindow, primaryInfo, featureInfos).open(); >+ >+ // make sure action is not disposed >+ if (workbenchWindow == null) >+ return; >+ >+ IProduct product = Platform.getProduct(); >+ IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); >+ >+ new AboutDialog(workbenchWindow, product, providers).open(); > } > > /* (non-Javadoc) >Index: src/org/eclipse/ui/internal/ide/dialogs/AboutDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/AboutDialog.java,v >retrieving revision 1.5 >diff -u -r1.5 AboutDialog.java >--- src/org/eclipse/ui/internal/ide/dialogs/AboutDialog.java 27 Feb 2004 04:11:17 -0000 1.5 >+++ src/org/eclipse/ui/internal/ide/dialogs/AboutDialog.java 5 Apr 2004 16:12:50 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at >@@ -8,12 +8,14 @@ > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >- > package org.eclipse.ui.internal.ide.dialogs; > > import java.util.ArrayList; >-import java.util.List; >+import java.util.LinkedList; > >+import org.eclipse.core.runtime.IBundleGroup; >+import org.eclipse.core.runtime.IBundleGroupProvider; >+import org.eclipse.core.runtime.IProduct; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.swt.SWT; >@@ -32,9 +34,9 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Shell; >-import org.eclipse.ui.internal.AboutInfo; > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.help.WorkbenchHelp; >+import org.eclipse.ui.internal.ide.AboutBundleGroupData; > import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; > import org.eclipse.ui.internal.ide.IHelpContextIds; > >@@ -42,7 +44,7 @@ > * Displays information about the product. > * > * @private >- * This class is internal to the workbench and must not be called outside the workbench >+ * this class is internal to the ide > */ > public class AboutDialog extends ProductInfoDialog { > private final static int MAX_IMAGE_WIDTH_FOR_TEXT = 250; >@@ -50,108 +52,123 @@ > private final static int PLUGINS_ID = IDialogConstants.CLIENT_ID + 2; > private final static int INFO_ID = IDialogConstants.CLIENT_ID + 3; > >- /** >- * About info for the primary feature. >- * Private field used in inner class. >- * @issue org.eclipse.ui.internal.AboutInfo - illegal reference to generic workbench internals >- */ >- /* package */ AboutInfo primaryInfo; >- >- /** >- * About info for the all features. >- * Private field used in inner class. >- * @issue org.eclipse.ui.internal.AboutInfo - illegal reference to generic workbench internals >- */ >- /* package */ AboutInfo[] featureInfos; >- private Image image; //image to display on dialog >+ private String productName; >+ private AboutBundleGroupData[] bundleGroupInfos; > > private ArrayList images = new ArrayList(); >+ private AboutFeaturesButtonManager buttonManager = new AboutFeaturesButtonManager(); >+ >+ // TODO should the styled text be disposed? if not then it likely >+ // doesn't need to be a member > private StyledText text; > > /** > * Create an instance of the AboutDialog > */ >- public AboutDialog( >- IWorkbenchWindow window, >- AboutInfo primaryInfo, >- AboutInfo[] featureInfos) { >- super(window.getShell()); >- this.primaryInfo = primaryInfo; >- this.featureInfos = featureInfos; >+ public AboutDialog(IWorkbenchWindow window, IProduct product, >+ IBundleGroupProvider[] providers) { >+ super(window.getShell()); >+ >+ String productId = ""; //$NON-NLS-1$ >+ if (product == null) >+ productName = IDEWorkbenchMessages >+ .getString("AboutDialog.defaultProductName"); //$NON-NLS-1$ >+ else { >+ productId = product.getId(); >+ productName = product.getName(); >+ } >+ >+ // create a descriptive object for each BundleGroup, putting the primary >+ // first if it can be found >+ LinkedList groups = new LinkedList(); >+ if (providers != null) >+ for (int i = 0; i < providers.length; ++i) { >+ IBundleGroup[] bundleGroups = providers[i].getBundleGroups(); >+ for (int j = 0; j < bundleGroups.length; ++j) { >+ AboutBundleGroupData info = new AboutBundleGroupData( >+ bundleGroups[j]); >+ >+ // if there's a bundle with the same id as the product, >+ // assume its the primary bundle and put it first >+ if (info.getId().equals(productId)) >+ groups.addFirst(info); >+ else >+ groups.add(info); >+ } >+ } >+ bundleGroupInfos = (AboutBundleGroupData[]) groups >+ .toArray(new AboutBundleGroupData[0]); > } > >- /* (non-Javadoc) >- * Method declared on Dialog. >- */ >- protected void buttonPressed(int buttonId) { >- switch (buttonId) { >- case FEATURES_ID : >- new AboutFeaturesDialog(getShell(), primaryInfo, featureInfos) >- .open(); >- return; >- case PLUGINS_ID : >- new AboutPluginsDialog(getShell(), primaryInfo).open(); >- return; >- case INFO_ID : >- new SystemSummaryDialog(getShell()).open(); >- return; >- } >- >- super.buttonPressed(buttonId); >- } >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected void buttonPressed(int buttonId) { >+ switch (buttonId) { >+ case FEATURES_ID: >+ new AboutFeaturesDialog(getShell(), productName, bundleGroupInfos).open(); >+ break; >+ case PLUGINS_ID: >+ new AboutPluginsDialog(getShell(), productName).open(); >+ break; >+ case INFO_ID: >+ new SystemSummaryDialog(getShell()).open(); >+ break; >+ default: >+ super.buttonPressed(buttonId); >+ break; >+ } >+ } > > public boolean close() { >- //get rid of the image that was displayed on the left-hand side of the Welcome dialog >- if (image != null) { >- image.dispose(); >- } >- for (int i = 0; i < images.size(); i++) { >- ((Image) images.get(i)).dispose(); >- } >- return super.close(); >- } >- /* (non-Javadoc) >- * Method declared on Window. >- */ >- protected void configureShell(Shell newShell) { >- super.configureShell(newShell); >- String name = null; >- if (primaryInfo != null) { >- name = primaryInfo.getProductName(); >- } >- if (name != null) { >- newShell.setText(IDEWorkbenchMessages.format("AboutDialog.shellTitle", new Object[] { name })); //$NON-NLS-1$ >- } >- WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_DIALOG); >- } >+ // dispose all images >+ for (int i = 0; i < images.size(); ++i) { >+ Image image = (Image) images.get(i); >+ image.dispose(); >+ } >+ >+ return super.close(); >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Window. >+ */ >+ protected void configureShell(Shell newShell) { >+ super.configureShell(newShell); >+ newShell.setText(IDEWorkbenchMessages.format("AboutDialog.shellTitle", //$NON-NLS-1$ >+ new Object[] { productName })); >+ WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_DIALOG); >+ } >+ > /** >- * Add buttons to the dialog's button bar. >- * >- * Subclasses should override. >- * >- * @param parent the button bar composite >- */ >- protected void createButtonsForButtonBar(Composite parent) { >- parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ * Add buttons to the dialog's button bar. >+ * >+ * Subclasses should override. >+ * >+ * @param parent >+ * the button bar composite >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ createButton(parent, FEATURES_ID, IDEWorkbenchMessages >+ .getString("AboutDialog.featureInfo"), false); //$NON-NLS-1$ >+ createButton(parent, PLUGINS_ID, IDEWorkbenchMessages >+ .getString("AboutDialog.pluginInfo"), false); //$NON-NLS-1$ >+ createButton(parent, INFO_ID, IDEWorkbenchMessages >+ .getString("AboutDialog.systemInfo"), false); //$NON-NLS-1$ >+ >+ Label l = new Label(parent, SWT.NONE); >+ l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ GridLayout layout = (GridLayout) parent.getLayout(); >+ layout.numColumns++; >+ layout.makeColumnsEqualWidth = false; >+ >+ Button b = createButton(parent, IDialogConstants.OK_ID, >+ IDialogConstants.OK_LABEL, true); >+ b.setFocus(); >+ } > >- createButton(parent, FEATURES_ID, IDEWorkbenchMessages.getString("AboutDialog.featureInfo"), false); //$NON-NLS-1$ >- createButton(parent, PLUGINS_ID, IDEWorkbenchMessages.getString("AboutDialog.pluginInfo"), false); //$NON-NLS-1$ >- createButton(parent, INFO_ID, IDEWorkbenchMessages.getString("AboutDialog.systemInfo"), false); //$NON-NLS-1$ >- >- Label l = new Label(parent, SWT.NONE); >- l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- GridLayout layout = (GridLayout) parent.getLayout(); >- layout.numColumns++; >- layout.makeColumnsEqualWidth = false; >- >- Button b = >- createButton( >- parent, >- IDialogConstants.OK_ID, >- IDialogConstants.OK_LABEL, >- true); >- b.setFocus(); >- } > /** > * Creates and returns the contents of the upper part > * of the dialog (above the button bar). >@@ -162,37 +179,42 @@ > * @return the dialog area control > */ > protected Control createDialogArea(Composite parent) { >- setHandCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_HAND)); >- setBusyCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT)); >- getShell().addDisposeListener(new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- if (getHandCursor() != null) { >- getHandCursor().dispose(); >- } >- if (getBusyCursor() != null) { >- getBusyCursor().dispose(); >- } >- } >- }); >- >- ImageDescriptor imageDescriptor = null; >- if (primaryInfo != null) { >- imageDescriptor = primaryInfo.getAboutImage(); // may be null >- } >- if (imageDescriptor != null) { >- image = imageDescriptor.createImage(); >- } >- if (image == null >- || image.getBounds().width <= MAX_IMAGE_WIDTH_FOR_TEXT) { >- // show text >- String aboutText = null; >- if (primaryInfo != null) { >- aboutText = primaryInfo.getAboutText(); // may be null >- } >- if (aboutText != null) { >- // get an about item >- setItem(scan(aboutText)); >- } >+ final Cursor hand = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); >+ final Cursor busy = new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT); >+ setHandCursor(hand); >+ setBusyCursor(busy); >+ getShell().addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ setHandCursor(null); >+ hand.dispose(); >+ setBusyCursor(null); >+ busy.dispose(); >+ } >+ }); >+ >+ // if there is product info (index 0), then brand the about box >+ Image aboutImage = null; >+ if (bundleGroupInfos.length > 0) { >+ AboutBundleGroupData productInfo = bundleGroupInfos[0]; >+ >+ ImageDescriptor imageDescriptor = null; >+ if (productInfo != null) >+ imageDescriptor = productInfo.getAboutImage(); >+ if (imageDescriptor != null) >+ aboutImage = imageDescriptor.createImage(); >+ >+ // if the about image is small enough, then show the text >+ if (aboutImage == null >+ || aboutImage.getBounds().width <= MAX_IMAGE_WIDTH_FOR_TEXT) { >+ String aboutText = null; >+ if (productInfo != null) >+ aboutText = productInfo.getAboutText(); >+ if (aboutText != null) >+ setItem(scan(aboutText)); >+ } >+ >+ if(aboutImage != null) >+ images.add(aboutImage); > } > > // page group >@@ -205,7 +227,7 @@ > // the image & text > Composite topContainer = new Composite(outer, SWT.NONE); > layout = new GridLayout(); >- layout.numColumns = (image == null || getItem() == null ? 1 : 2); >+ layout.numColumns = (aboutImage == null || getItem() == null ? 1 : 2); > layout.marginWidth = 0; > topContainer.setLayout(layout); > GridData data = new GridData(); >@@ -214,14 +236,14 @@ > topContainer.setLayoutData(data); > > //image on left side of dialog >- if (image != null) { >+ if (aboutImage != null) { > Label imageLabel = new Label(topContainer, SWT.NONE); > data = new GridData(); > data.horizontalAlignment = GridData.FILL; > data.verticalAlignment = GridData.BEGINNING; > data.grabExcessHorizontalSpace = false; > imageLabel.setLayoutData(data); >- imageLabel.setImage(image); >+ imageLabel.setImage(aboutImage); > } > > if (getItem() != null) { >@@ -247,45 +269,8 @@ > data.horizontalAlignment = GridData.FILL; > bar.setLayoutData(data); > >- // feature images >- Composite featureContainer = new Composite(outer, SWT.NONE); >- RowLayout rowLayout = new RowLayout(); >- rowLayout.wrap = true; >- featureContainer.setLayout(rowLayout); >- data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- featureContainer.setLayoutData(data); >- >- final AboutInfo[] infoArray = getFeaturesWithImages(); >- for (int i = 0; i < infoArray.length; i++) { >- ImageDescriptor desc = infoArray[i].getFeatureImage(); >- Image featureImage = null; >- if (desc != null) { >- Button button = >- new Button(featureContainer, SWT.FLAT | SWT.PUSH); >- button.setData(infoArray[i]); >- featureImage = desc.createImage(); >- images.add(featureImage); >- button.setImage(featureImage); >- String name = infoArray[i].getProviderName(); >- if (name == null) { >- name = ""; //$NON-NLS-1$ >- } >- button.setToolTipText(name); >- button.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent event) { >- AboutFeaturesDialog d = >- new AboutFeaturesDialog( >- getShell(), >- primaryInfo, >- featureInfos); >- d.setInitialSelection( >- (AboutInfo) event.widget.getData()); >- d.open(); >- } >- }); >- } >- } >+ // add image buttons for bundle groups that have them >+ createFeatureImageButtonRow(outer); > > // spacer > bar = new Label(outer, SWT.NONE); >@@ -296,51 +281,49 @@ > return outer; > } > >- /** >- * Returns the feature info for non-primary features with a feature image. >- * If several features share the same image bitmap, include only one per >- * provider. >- */ >- private AboutInfo[] getFeaturesWithImages() { >- // quickly exclude any that do not have a provider name and image >- List infoList = new ArrayList(featureInfos.length + 1); >- >- // make sure primary is first >- if (primaryInfo != null && primaryInfo.getProviderName() != null >- && primaryInfo.getFeatureImageName() != null) { >- infoList.add(primaryInfo); >- } >+ private void createFeatureImageButtonRow(Composite parent) { >+ // feature images >+ Composite featureContainer = new Composite(parent, SWT.NONE); >+ RowLayout rowLayout = new RowLayout(); >+ rowLayout.wrap = true; >+ featureContainer.setLayout(rowLayout); >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ featureContainer.setLayoutData(data); > >- for (int i = 0; i < featureInfos.length; i++) { >- if (featureInfos[i].getProviderName() != null >- && featureInfos[i].getFeatureImageName() != null) { >- infoList.add(featureInfos[i]); >- } >- } >- List keepers = new ArrayList(infoList.size()); >+ // create buttons for all the rest >+ for (int i = 0; i < bundleGroupInfos.length; i++) >+ createFeatureButton(featureContainer, bundleGroupInfos[i]); >+ } > >- // precompute CRCs of all the feature images >- long[] featureImageCRCs = new long[infoList.size()]; >- for (int i = 0; i < infoList.size(); i++) { >- AboutInfo info = (AboutInfo) infoList.get(i); >- featureImageCRCs[i] = info.getFeatureImageCRC().longValue(); >- } >- for (int i = 0; i < infoList.size(); i++) { >- AboutInfo outer = (AboutInfo) infoList.get(i); >- boolean found = false; >- // see whether we already have one for same provider and same image >- for (int j = 0; j < keepers.size(); j++) { >- AboutInfo k = (AboutInfo) keepers.get(j); >- if (k.getProviderName().equals(outer.getProviderName()) >- && featureImageCRCs[j] == featureImageCRCs[i]) { >- found = true; >- break; >- } >- } >- if (!found) { >- keepers.add(outer); >- } >- } >- return (AboutInfo[]) keepers.toArray(new AboutInfo[keepers.size()]); >+ private Button createFeatureButton(Composite parent, >+ final AboutBundleGroupData info) { >+ if (!buttonManager.add(info)) >+ return null; >+ >+ ImageDescriptor desc = info.getFeatureImage(); >+ Image featureImage = null; >+ >+ Button button = new Button(parent, SWT.FLAT | SWT.PUSH); >+ button.setData(info); >+ featureImage = desc.createImage(); >+ images.add(featureImage); >+ button.setImage(featureImage); >+ button.setToolTipText(info.getProviderName()); >+ button.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent event) { >+ AboutBundleGroupData[] groupInfos = buttonManager >+ .getRelatedInfos(info); >+ AboutBundleGroupData selection = (AboutBundleGroupData) event.widget >+ .getData(); >+ >+ AboutFeaturesDialog d = new AboutFeaturesDialog(getShell(), >+ productName, groupInfos); >+ d.setInitialSelection(selection); >+ d.open(); >+ } >+ }); >+ >+ return button; > } > } >Index: src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesDialog.java,v >retrieving revision 1.5 >diff -u -r1.5 AboutFeaturesDialog.java >--- src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesDialog.java 15 Mar 2004 16:39:30 -0000 1.5 >+++ src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesDialog.java 5 Apr 2004 16:12:50 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials! > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,26 +10,19 @@ > * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog > * font should be activated and used by other components. > ************************************************************************/ >- > package org.eclipse.ui.internal.ide.dialogs; > >-import java.text.Collator; >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.Collection; >-import java.util.Collections; >-import java.util.Comparator; > import java.util.HashMap; > import java.util.Iterator; >-import java.util.Locale; > import java.util.Map; > > import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IPluginDescriptor; >-import org.eclipse.core.runtime.IPluginRegistry; >+import org.eclipse.core.runtime.IBundleGroup; > import org.eclipse.core.runtime.NullProgressMonitor; >-import org.eclipse.core.runtime.Platform; >- >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.window.Window; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.BusyIndicator; > import org.eclipse.swt.custom.StyledText; >@@ -37,7 +30,6 @@ > import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.graphics.Cursor; > import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.graphics.Image; >@@ -51,43 +43,36 @@ > import org.eclipse.swt.widgets.Table; > import org.eclipse.swt.widgets.TableColumn; > import org.eclipse.swt.widgets.TableItem; >- >-import org.eclipse.jface.dialogs.IDialogConstants; >-import org.eclipse.jface.dialogs.MessageDialog; >-import org.eclipse.jface.resource.ImageDescriptor; >- > import org.eclipse.ui.help.WorkbenchHelp; >- >-import org.eclipse.ui.internal.AboutInfo; >+import org.eclipse.ui.internal.ide.AboutBundleGroupData; >+import org.eclipse.ui.internal.ide.AboutData; > import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; > import org.eclipse.ui.internal.ide.IHelpContextIds; >- > import org.eclipse.update.configuration.IConfiguredSite; > import org.eclipse.update.configuration.IInstallConfiguration; > import org.eclipse.update.configuration.ILocalSite; > import org.eclipse.update.core.IFeature; > import org.eclipse.update.core.IFeatureReference; >-import org.eclipse.update.core.IPluginEntry; > import org.eclipse.update.core.IURLEntry; > import org.eclipse.update.core.SiteManager; >-import org.eclipse.update.core.VersionedIdentifier; >+import org.osgi.framework.Bundle; > > /** > * Displays information about the product plugins. > * > * @private >- * This class is internal to the workbench and must not be called outside the workbench >+ * This class is internal to the workbench and must not be called outside >+ * the workbench. > */ > public class AboutFeaturesDialog extends ProductInfoDialog { > >- /** >- * Table height in dialog units (value 150). >- */ >- private static final int TABLE_HEIGHT = 150; >- private static final int INFO_HEIGHT = 100; >- >- private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; >- private final static int PLUGINS_ID = IDialogConstants.CLIENT_ID + 2; >+ /** >+ * Table height in dialog units (value 150). >+ */ >+ private static final int TABLE_HEIGHT = 150; >+ private static final int INFO_HEIGHT = 100; >+ private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; >+ private final static int PLUGINS_ID = IDialogConstants.CLIENT_ID + 2; > > private Table table; > private Label imageLabel; >@@ -96,18 +81,19 @@ > > private Map cachedImages = new HashMap(); > >- private String columnTitles[] = { IDEWorkbenchMessages.getString("AboutFeaturesDialog.provider"), //$NON-NLS-1$ >+ private String columnTitles[] = { >+ IDEWorkbenchMessages.getString("AboutFeaturesDialog.provider"), //$NON-NLS-1$ > IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureName"), //$NON-NLS-1$ > IDEWorkbenchMessages.getString("AboutFeaturesDialog.version"), //$NON-NLS-1$ > IDEWorkbenchMessages.getString("AboutFeaturesDialog.featureId"), //$NON-NLS-1$ > }; > >- private AboutInfo[] featureInfos; >- private AboutInfo primaryInfo; >+ private String productName; >+ private AboutBundleGroupData[] bundleGroupInfos; > > private int lastColumnChosen = 0; // initially sort by provider > private boolean reverseSort = false; // initially sort ascending >- private AboutInfo lastSelection = null; >+ private AboutBundleGroupData lastSelection = null; > private Button moreButton; > private Button pluginsButton; > >@@ -116,153 +102,158 @@ > /** > * Constructor for AboutFeaturesDialog > */ >- public AboutFeaturesDialog( >- Shell parentShell, >- AboutInfo primaryInfo, >- AboutInfo[] featureInfos) { >- super(parentShell); >- setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL); >- >- this.primaryInfo = primaryInfo; >- this.featureInfos = featureInfos; >- >- sortByProvider(); >- } >- >- /* (non-Javadoc) >- * Method declared on Dialog. >- */ >- protected void buttonPressed(int buttonId) { >- switch (buttonId) { >- case MORE_ID : >- { >- TableItem[] items = table.getSelection(); >- if (items.length > 0) { >- AboutInfo info = (AboutInfo) items[0].getData(); >- IFeature feature = getFeatureFor(info); >- IURLEntry entry = feature == null ? null : feature.getLicense(); >- if (feature == null || entry == null >- || !openBrowser(entry.getURL())) >- MessageDialog >- .openInformation( >- getShell(), >- IDEWorkbenchMessages >- .getString("AboutFeaturesDialog.noInfoTitle"), //$NON-NLS-1$ >- IDEWorkbenchMessages >- .getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ >- } >- return; >- } >- case PLUGINS_ID : >- { >- TableItem[] items = table.getSelection(); >- if (items.length > 0) { >- AboutInfo info = (AboutInfo) items[0].getData(); >- IFeature feature = getFeatureFor(info); >- IPluginDescriptor[] descriptors; >- if (feature == null) >- descriptors = new IPluginDescriptor[0]; >- else >- descriptors = getPluginsFor(feature); >- AboutPluginsDialog d = >- new AboutPluginsDialog( >- getShell(), >- primaryInfo, >- descriptors, >- IDEWorkbenchMessages.getString( >- "AboutFeaturesDialog.pluginInfoTitle"), //$NON-NLS-1$ >- IDEWorkbenchMessages.format( >- "AboutFeaturesDialog.pluginInfoMessage", //$NON-NLS-1$ >- new Object[] { info.getFeatureLabel()}), >- IHelpContextIds.ABOUT_FEATURES_PLUGINS_DIALOG); >- d.open(); >- } >- return; >- } >- } >- super.buttonPressed(buttonId); >- } >+ public AboutFeaturesDialog(Shell parentShell, String productName, >+ AboutBundleGroupData[] bundleGroupInfos) { >+ super(parentShell); >+ setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL); >+ >+ this.productName = productName; >+ this.bundleGroupInfos = bundleGroupInfos; >+ >+ AboutData.sortByProvider(reverseSort, bundleGroupInfos); >+ } >+ >+ /** >+ * The More Info button was pressed. Open a browser with the license for the >+ * selected item or an information dialog if there is no license, or the browser >+ * cannot be opened. >+ */ >+ private void handleMoreInfoPressed() { >+ TableItem[] items = table.getSelection(); >+ if (items.length <= 0) >+ return; >+ >+ AboutBundleGroupData info = (AboutBundleGroupData) items[0].getData(); >+ IFeature feature = getFeatureFor(info); >+ IURLEntry entry = feature == null ? null : feature.getLicense(); >+ if (feature == null || entry == null || !openBrowser(entry.getURL())) { >+ MessageDialog.openInformation(getShell(), IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.noInfoTitle"), //$NON-NLS-1$ >+ IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * The Plugins button was pressed. Open an about dialog on the plugins for >+ * the selected feature. >+ */ >+ private void handlePluginInfoPressed() { >+ TableItem[] items = table.getSelection(); >+ if (items.length <= 0) >+ return; >+ >+ AboutBundleGroupData info = (AboutBundleGroupData) items[0].getData(); >+ IBundleGroup bundleGroup = info.getBundleGroup(); >+ Bundle[] bundles = bundleGroup == null ? new Bundle[0] : bundleGroup >+ .getBundles(); >+ >+ AboutPluginsDialog d = new AboutPluginsDialog(getShell(), productName, >+ bundles, IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.pluginInfoTitle"), //$NON-NLS-1$ >+ IDEWorkbenchMessages.format( >+ "AboutFeaturesDialog.pluginInfoMessage", //$NON-NLS-1$ >+ new Object[] { bundleGroup.getIdentifier()}), >+ IHelpContextIds.ABOUT_FEATURES_PLUGINS_DIALOG); >+ d.open(); >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected void buttonPressed(int buttonId) { >+ switch (buttonId) { >+ case MORE_ID: >+ handleMoreInfoPressed(); >+ break; >+ case PLUGINS_ID: >+ handlePluginInfoPressed(); >+ break; >+ default: >+ super.buttonPressed(buttonId); >+ break; >+ } >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Window. >+ */ >+ protected void configureShell(Shell newShell) { >+ super.configureShell(newShell); >+ if (productName != null) >+ newShell.setText(IDEWorkbenchMessages.format( >+ "AboutFeaturesDialog.shellTitle", //$NON-NLS-1$ >+ new Object[] { productName })); >+ >+ WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_FEATURES_DIALOG); >+ } >+ >+ /** >+ * Add buttons to the dialog's button bar. >+ * >+ * Subclasses should override. >+ * >+ * @param parent >+ * the button bar composite >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ moreButton = createButton(parent, MORE_ID, IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.moreInfo"), false); //$NON-NLS-1$ >+ pluginsButton = createButton(parent, PLUGINS_ID, IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.pluginsInfo"), false); //$NON-NLS-1$ >+ >+ Label l = new Label(parent, SWT.NONE); >+ l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ GridLayout layout = (GridLayout) parent.getLayout(); >+ layout.numColumns++; >+ layout.makeColumnsEqualWidth = false; >+ >+ Button b = createButton(parent, IDialogConstants.OK_ID, >+ IDialogConstants.OK_LABEL, true); >+ b.setFocus(); >+ >+ TableItem[] items = table.getSelection(); >+ if (items.length > 0) >+ updateButtons((AboutBundleGroupData) items[0].getData()); >+ } >+ >+ /** >+ * Create the contents of the dialog (above the button bar). >+ * >+ * Subclasses should overide. >+ * >+ * @param the >+ * parent composite to contain the dialog area >+ * @return the dialog area control >+ */ >+ protected Control createDialogArea(Composite parent) { >+ setHandCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_HAND)); >+ setBusyCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT)); >+ getShell().addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ if (getHandCursor() != null) >+ getHandCursor().dispose(); >+ if (getBusyCursor() != null) >+ getBusyCursor().dispose(); >+ } >+ }); >+ >+ Composite outer = (Composite) super.createDialogArea(parent); >+ >+ createTable(outer); >+ createInfoArea(outer); >+ >+ GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL, >+ GridData.VERTICAL_ALIGN_FILL, true, true); >+ gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); >+ table.setLayoutData(gridData); > >- /* (non-Javadoc) >- * Method declared on Window. >- */ >- protected void configureShell(Shell newShell) { >- super.configureShell(newShell); >- String title = null; >- if (primaryInfo != null) { >- title = primaryInfo.getProductName(); >- } >- if (title != null) { >- newShell.setText(IDEWorkbenchMessages.format("AboutFeaturesDialog.shellTitle", //$NON-NLS-1$ >- new Object[] { title })); >- } >- WorkbenchHelp.setHelp(newShell, IHelpContextIds.ABOUT_FEATURES_DIALOG); >- } >- /** >- * Add buttons to the dialog's button bar. >- * >- * Subclasses should override. >- * >- * @param parent the button bar composite >- */ >- protected void createButtonsForButtonBar(Composite parent) { >- parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ return outer; >+ } > >- moreButton = createButton(parent, MORE_ID, IDEWorkbenchMessages.getString("AboutFeaturesDialog.moreInfo"), false); //$NON-NLS-1$ >- pluginsButton = createButton(parent, PLUGINS_ID, IDEWorkbenchMessages.getString("AboutFeaturesDialog.pluginsInfo"), false); //$NON-NLS-1$ >- >- Label l = new Label(parent, SWT.NONE); >- l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- GridLayout layout = (GridLayout) parent.getLayout(); >- layout.numColumns++; >- layout.makeColumnsEqualWidth = false; >- >- Button b = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); >- b.setFocus(); >- >- TableItem[] items = table.getSelection(); >- if (items.length > 0) >- updateButtons((AboutInfo) items[0].getData()); >- } >- >- /** >- * Create the contents of the dialog (above the button bar). >- * >- * Subclasses should overide. >- * >- * @param the parent composite to contain the dialog area >- * @return the dialog area control >- */ >- protected Control createDialogArea(Composite parent) { >- setHandCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_HAND)); >- setBusyCursor(new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT)); >- getShell().addDisposeListener(new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- if (getHandCursor() != null) >- getHandCursor().dispose(); >- if (getBusyCursor() != null) >- getBusyCursor().dispose(); >- } >- }); >- >- Composite outer = (Composite) super.createDialogArea(parent); >- >- createTable(outer); >- createColumns(); >- createInfoArea(outer); >- >- GridData gridData = >- new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); >- gridData.grabExcessVerticalSpace = true; >- gridData.grabExcessHorizontalSpace = true; >- >- // suggest a height for the table >- gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); >- table.setLayoutData(gridData); >- >- return outer; >- } >- /** >+ /** > * Create the info area containing the image and text > */ > protected void createInfoArea(Composite parent) { >@@ -303,7 +294,7 @@ > > TableItem[] items = table.getSelection(); > if (items.length > 0) >- updateInfoArea((AboutInfo) items[0].getData()); >+ updateInfoArea((AboutBundleGroupData) items[0].getData()); > } > > /** >@@ -312,475 +303,279 @@ > * @param the parent composite to contain the dialog area > */ > protected void createTable(Composite parent) { >- table = >- new Table( >- parent, >- SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); >- table.setHeaderVisible(true); >- table.setLinesVisible(true); >- table.setFont(parent.getFont()); >- >- SelectionListener listener = new SelectionAdapter() { >+ table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE >+ | SWT.FULL_SELECTION | SWT.BORDER); >+ table.setHeaderVisible(true); >+ table.setLinesVisible(true); >+ table.setFont(parent.getFont()); >+ table.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { >- AboutInfo info = (AboutInfo) e.item.getData(); >+ AboutBundleGroupData info = (AboutBundleGroupData) e.item.getData(); > updateInfoArea(info); > updateButtons(info); > } >- }; >- table.addSelectionListener(listener); >- } >- /** >- * @see Window#close() >- */ >- public boolean close() { >- Collection values = cachedImages.values(); >- for (Iterator iter = values.iterator(); iter.hasNext();) { >- Image image = (Image) iter.next(); >- image.dispose(); >- } >- return super.close(); >- } >- /** >- * Returns a mapping from feature id to feature >- */ >- private Map getFeaturesMap() { >- if (featuresMap != null) >- return featuresMap; >- >- featuresMap = new HashMap(); >- >- IPluginRegistry reg = Platform.getPluginRegistry(); >- if (reg == null) { >- MessageDialog.openError(getShell(), IDEWorkbenchMessages.getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ >- IDEWorkbenchMessages.getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ >- return featuresMap; >- } >- >- final ILocalSite[] localSiteArray = new ILocalSite[1]; >- BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { >- public void run() { >- // this may take a few seconds >- try { >- localSiteArray[0] = SiteManager.getLocalSite(); >- } catch (CoreException e) { >- MessageDialog.openError(getShell(), IDEWorkbenchMessages.getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ >- IDEWorkbenchMessages.getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ >- } >- } > }); >- if (localSiteArray[0] == null) >- return featuresMap; >- >- IInstallConfiguration installConfiguration = localSiteArray[0].getCurrentConfiguration(); >- IConfiguredSite[] configuredSites = installConfiguration.getConfiguredSites(); >- >- for (int i = 0; i < configuredSites.length; i++) { >- IFeatureReference[] featureReferences = configuredSites[i].getConfiguredFeatures(); >- for (int j = 0; j < featureReferences.length; j++) { >- IFeature feature; >- try { >- feature = featureReferences[j].getFeature(new NullProgressMonitor()); >- } catch (CoreException e) { >- // just skip it >- break; >- } >- String key = feature.getVersionedIdentifier().toString(); >- featuresMap.put(key, feature); >- } >- } >- return featuresMap; >- } >- >- /** >- * Return the feature for the given info >- */ >- private IFeature getFeatureFor(AboutInfo info) { >- Map map = getFeaturesMap(); >- if (map == null) >- return null; >- String key = info.getFeatureId() + "_" + info.getVersionId(); //$NON-NLS-1$ >- return (IFeature) map.get(key); >- } >- >- /** >- * Return the plugins for the given feature >- */ >- private IPluginDescriptor[] getPluginsFor(IFeature feature) { >- IPluginRegistry reg = Platform.getPluginRegistry(); >- if (reg == null) >- return new IPluginDescriptor[0]; >- IPluginEntry[] pluginEntries = feature.getPluginEntries(); >- ArrayList plugins = new ArrayList(); >- for (int k = 0; k < pluginEntries.length; k++) { >- VersionedIdentifier id = pluginEntries[k].getVersionedIdentifier(); >- >- IPluginDescriptor desc = reg.getPluginDescriptor(id.getIdentifier(), id.getVersion()); >- if (desc != null) >- plugins.add(desc); >- } >- return (IPluginDescriptor[]) plugins.toArray(new IPluginDescriptor[plugins.size()]); >- } >- >- /** >- * Update the button enablement >- */ >- private void updateButtons(AboutInfo info) { >- if (info == null) { >- moreButton.setEnabled(false); >- pluginsButton.setEnabled(false); >- return; >- } >- boolean shouldEnable = true; // by default enable >- // Avoid creating the map just to determine enablement >- if (featuresMap != null) { >- IFeature feature = getFeatureFor(info); >- shouldEnable = feature != null && feature.getLicense() != null; >- } >- moreButton.setEnabled(shouldEnable); >- >- // Assume there is at least one plugin >- shouldEnable = true; // by default enable >- if (featuresMap != null) { >- IFeature feature = getFeatureFor(info); >- shouldEnable = feature != null; >- } >- pluginsButton.setEnabled(shouldEnable); >- } >- >- /** >- * Update the info area >- */ >- private void updateInfoArea(AboutInfo info) { >- if (info == null) { >- imageLabel.setImage(null); >- text.setText(""); //$NON-NLS-1$ >- return; >- } >- ImageDescriptor desc = info.getFeatureImage(); >- Image image = (Image) cachedImages.get(desc); >- if (image == null && desc != null) { >- image = desc.createImage(); >- cachedImages.put(desc, image); >- } >- imageLabel.setImage(image); >- String aboutText = info.getAboutText(); >- setItem(null); >- if (aboutText != null) { >- // get an about item >- setItem(scan(aboutText)); >- } >- if (getItem() == null) >- text.setText(IDEWorkbenchMessages.getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ >- else { >- text.setText(getItem().getText()); >- text.setCursor(null); >- setLinkRanges(text, getItem().getLinkRanges()); >- } >- } > >- /** >- * Select the initial selection >- * >- */ >- public void setInitialSelection(AboutInfo info) { >- lastSelection = info; >- } >+ int[] columnWidths = { >+ convertHorizontalDLUsToPixels(120), >+ convertHorizontalDLUsToPixels(120), >+ convertHorizontalDLUsToPixels(70), >+ convertHorizontalDLUsToPixels(130) >+ }; > >- /** >- * Populate the table with plugin info obtained from the registry. >- * >- * @param the parent composite to contain the dialog area >- */ >- protected void createColumns() { >- /* create table headers */ >- int[] columnWidths = >- { >- convertHorizontalDLUsToPixels(120), >- convertHorizontalDLUsToPixels(180), >- convertHorizontalDLUsToPixels(70), >- convertHorizontalDLUsToPixels(70)}; > for (int i = 0; i < columnTitles.length; i++) { >- TableColumn tableColumn = new TableColumn(table, SWT.NULL); >- tableColumn.setWidth(columnWidths[i]); >- tableColumn.setText(columnTitles[i]); >- final int columnIndex = i; >- tableColumn.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- sort(columnIndex); >- } >- }); >- >- } >+ TableColumn tableColumn = new TableColumn(table, SWT.NULL); >+ tableColumn.setWidth(columnWidths[i]); >+ tableColumn.setText(columnTitles[i]); >+ final int columnIndex = i; >+ tableColumn.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ sort(columnIndex); >+ } >+ }); >+ } >+ >+ // create a table row for each bundle group >+ String selId = lastSelection == null ? null : lastSelection.getId(); >+ int sel = 0; >+ for (int i = 0; i < bundleGroupInfos.length; i++) { >+ if (bundleGroupInfos[i].getId().equals(selId)) >+ sel = i; > >- int initialSelectionIndex = 0; >- /* fill each row of the table with feature info */ >- for (int i = 0; i < featureInfos.length; i++) { >- if (featureInfos[i] == lastSelection) >- initialSelectionIndex = i; >- String provider = featureInfos[i].getProviderName(); >- String featureName = featureInfos[i].getFeatureLabel(); >- String versionId = featureInfos[i].getVersionId(); >- String featureId = featureInfos[i].getFeatureId(); >- if (provider == null) >- provider = ""; //$NON-NLS-1$ >- if (featureName == null) >- featureName = ""; //$NON-NLS-1$ >- if (versionId == null) >- versionId = ""; //$NON-NLS-1$ >- if (featureId == null) >- featureId = ""; //$NON-NLS-1$ >- String[] row = { provider, featureName, versionId, featureId }; > TableItem item = new TableItem(table, SWT.NULL); >- item.setText(row); >- item.setData(featureInfos[i]); >- } >- >- // set initial selection >- if (featureInfos.length > 0) { >- table.setSelection(initialSelectionIndex); >+ item.setText(createRow(bundleGroupInfos[i])); >+ item.setData(bundleGroupInfos[i]); > } >- } > >- /** >- * Sort the rows of the table based on the selected column. >- * >- * @param column index of table column selected as sort criteria >- */ >- private void sort(int column) { >- // Choose new sort algorithm >- if (lastColumnChosen == column) { >- reverseSort = !reverseSort; >- } else { >- reverseSort = false; >- lastColumnChosen = column; >- } >- >- if (table.getItemCount() <= 1) >- return; >- >- // Remember the last selection >- int idx = table.getSelectionIndex(); >- if (idx != -1) >- lastSelection = featureInfos[idx]; >- >- switch (column) { >- case 0 : >- sortByProvider(); >- break; >- case 1 : >- sortByName(); >- break; >- case 2 : >- sortByVersion(); >- break; >- case 3 : >- sortByFeatureId(); >- break; >- } >- >- refreshTable(column); >- } >- >- /** >- * Refresh the rows of the table based on the selected column. >- * Maintain selection from before sort action request. >- * >- * @param items the old state table items >- */ >- private void refreshTable(int col) { >- TableItem[] items = table.getItems(); >- int idx = -1; // the new index of the selection >- // Create new order of table items >- for (int i = 0; i < items.length; i++) { >- String provider = featureInfos[i].getProviderName(); >- String featureName = featureInfos[i].getFeatureLabel(); >- String versionId = featureInfos[i].getVersionId(); >- String featureId = featureInfos[i].getFeatureId(); >- if (provider == null) >- provider = ""; //$NON-NLS-1$ >- if (featureName == null) >- featureName = ""; //$NON-NLS-1$ >- if (versionId == null) >- versionId = ""; //$NON-NLS-1$ >- if (featureId == null) >- featureId = ""; //$NON-NLS-1$ >- String[] row = { provider, featureName, versionId, featureId }; >- items[i].setText(row); >- items[i].setData(featureInfos[i]); >- } >- // Maintain the original selection >- if (lastSelection != null) { >- for (int k = 0; k < featureInfos.length; k++) { >- if (lastSelection == featureInfos[k]) >- idx = k; >- } >- table.setSelection(idx); >+ // if an item was specified during construction, it should be >+ // selected when the table is created >+ if (bundleGroupInfos.length > 0) { >+ table.setSelection(sel); > table.showSelection(); > } >- >- updateInfoArea(lastSelection); > } >- /** >- * Sort the rows of the table based on the plugin provider. >- * Secondary criteria is unique plugin id. >- */ >- private void sortByProvider() { >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort) { >- java.util.List infoList = Arrays.asList(featureInfos); >- Collections.reverse(infoList); >- for (int i = 0; i < featureInfos.length; i++) { >- featureInfos[i] = (AboutInfo) infoList.get(i); >- } >- } else { >- // Sort ascending >- Arrays.sort(featureInfos, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- AboutInfo i1, i2; >- String provider1, provider2, name1, name2; >- i1 = (AboutInfo) a; >- provider1 = i1.getProviderName(); >- name1 = i1.getFeatureLabel(); >- if (provider1 == null) >- provider1 = ""; //$NON-NLS-1$ >- if (name1 == null) >- name1 = ""; //$NON-NLS-1$ >- i2 = (AboutInfo) b; >- provider2 = i2.getProviderName(); >- name2 = i2.getFeatureLabel(); >- if (provider2 == null) >- provider2 = ""; //$NON-NLS-1$ >- if (name2 == null) >- name2 = ""; //$NON-NLS-1$ >- if (provider1.equals(provider2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(provider1, provider2); >- } >- }); >- } >- } >- /** >- * Sort the rows of the table based on unique plugin id. >- */ >- private void sortByName() { >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort) { >- java.util.List infoList = Arrays.asList(featureInfos); >- Collections.reverse(infoList); >- for (int i = 0; i < featureInfos.length; i++) { >- featureInfos[i] = (AboutInfo) infoList.get(i); >- } >- } else { >- // Sort ascending >- Arrays.sort(featureInfos, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- AboutInfo i1, i2; >- String name1, name2; >- i1 = (AboutInfo) a; >- name1 = i1.getFeatureLabel(); >- i2 = (AboutInfo) b; >- name2 = i2.getFeatureLabel(); >- if (name1 == null) >- name1 = ""; //$NON-NLS-1$ >- if (name2 == null) >- name2 = ""; //$NON-NLS-1$ >- return coll.compare(name1, name2); >- } >- }); >- } > >- } >- /** >- * Sort the rows of the table based on the plugin version. >- * Secondary criteria is unique plugin id. >- */ >- private void sortByVersion() { >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort) { >- java.util.List infoList = Arrays.asList(featureInfos); >- Collections.reverse(infoList); >- for (int i = 0; i < featureInfos.length; i++) { >- featureInfos[i] = (AboutInfo) infoList.get(i); >- } >- } else { >- // Sort ascending >- Arrays.sort(featureInfos, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- AboutInfo i1, i2; >- String version1, version2, name1, name2; >- i1 = (AboutInfo) a; >- version1 = i1.getVersionId(); >- name1 = i1.getFeatureLabel(); >- if (version1 == null) >- version1 = ""; //$NON-NLS-1$ >- if (name1 == null) >- name1 = ""; //$NON-NLS-1$ >- i2 = (AboutInfo) b; >- version2 = i2.getVersionId(); >- name2 = i2.getFeatureLabel(); >- if (version2 == null) >- version2 = ""; //$NON-NLS-1$ >- if (name2 == null) >- name2 = ""; //$NON-NLS-1$ >- if (version1.equals(version2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(version1, version2); >- } >- }); >- } >- } > /** >- * Sort the rows of the table based on the feature Id. >- * Secondary criteria is unique plugin id. >- */ >- private void sortByFeatureId() { >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort) { >- java.util.List infoList = Arrays.asList(featureInfos); >- Collections.reverse(infoList); >- for (int i = 0; i < featureInfos.length; i++) { >- featureInfos[i] = (AboutInfo) infoList.get(i); >- } >- } else { >- // Sort ascending >- Arrays.sort(featureInfos, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- AboutInfo i1, i2; >- String featureId1, featureId2, name1, name2; >- i1 = (AboutInfo) a; >- featureId1 = i1.getFeatureId(); >- name1 = i1.getFeatureLabel(); >- if (featureId1 == null) >- featureId1 = ""; //$NON-NLS-1$ >- if (name1 == null) >- name1 = ""; //$NON-NLS-1$ >- i2 = (AboutInfo) b; >- featureId2 = i2.getFeatureId(); >- name2 = i2.getFeatureLabel(); >- if (featureId2 == null) >- featureId2 = ""; //$NON-NLS-1$ >- if (name2 == null) >- name2 = ""; //$NON-NLS-1$ >- if (featureId1.equals(featureId2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(featureId1, featureId2); >- } >- }); >- } >- } >-} >\ No newline at end of file >+ * @see Window#close() >+ */ >+ public boolean close() { >+ boolean ret = super.close(); >+ >+ Iterator iter = cachedImages.values().iterator(); >+ while (iter.hasNext()) { >+ Image image = (Image) iter.next(); >+ image.dispose(); >+ } >+ >+ return ret; >+ } >+ >+ /** >+ * Returns a mapping from feature id to feature. >+ */ >+ private Map getFeaturesMap() { >+ if (featuresMap != null) return featuresMap; >+ >+ featuresMap = new HashMap(); >+ >+ final ILocalSite[] localSiteArray = new ILocalSite[1]; >+ BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { >+ public void run() { >+ // this may take a few seconds >+ try { >+ localSiteArray[0] = SiteManager.getLocalSite(); >+ } catch (CoreException e) { >+ MessageDialog >+ .openError( >+ getShell(), >+ IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.errorTitle"), //$NON-NLS-1$ >+ IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.unableToObtainFeatureInfo")); //$NON-NLS-1$ >+ } >+ } >+ }); >+ if (localSiteArray[0] == null) >+ return featuresMap; >+ >+ IInstallConfiguration installConfiguration = localSiteArray[0] >+ .getCurrentConfiguration(); >+ IConfiguredSite[] configuredSites = installConfiguration >+ .getConfiguredSites(); >+ >+ for (int i = 0; i < configuredSites.length; i++) { >+ IFeatureReference[] featureReferences = configuredSites[i] >+ .getConfiguredFeatures(); >+ >+ for (int j = 0; j < featureReferences.length; j++) { >+ try { >+ IFeature feature = featureReferences[j] >+ .getFeature(new NullProgressMonitor()); >+ >+ String key = feature.getVersionedIdentifier().toString(); >+ featuresMap.put(key, feature); >+ } catch (CoreException e) { >+ // do nothing >+ } >+ } >+ } >+ >+ return featuresMap; >+ } >+ >+ /** >+ * Return the feature for the given bundle group. >+ */ >+ private IFeature getFeatureFor(AboutBundleGroupData info) { >+ Map map = getFeaturesMap(); >+ if (map == null) >+ return null; >+ >+ String key = info.getId() + "_" + info.getVersion(); //$NON-NLS-1$ >+ return (IFeature) map.get(key); >+ } >+ >+ /** >+ * Update the button enablement >+ */ >+ private void updateButtons(AboutBundleGroupData info) { >+ if (info == null) { >+ moreButton.setEnabled(false); >+ pluginsButton.setEnabled(false); >+ return; >+ } >+ >+ // Creating the feature map is too much just to determine enablement, so if >+ // it doesn't already exist, just enable the buttons. If this was the wrong >+ // choice, then when the button is actually pressed an dialog will be opened. >+ if(featuresMap == null) { >+ moreButton.setEnabled(true); >+ pluginsButton.setEnabled(true); >+ return; >+ } >+ >+ IFeature feature = getFeatureFor(info); >+ moreButton.setEnabled(feature != null && feature.getLicense() != null); >+ pluginsButton.setEnabled(feature != null); >+ } >+ >+ /** >+ * Update the info area >+ */ >+ private void updateInfoArea(AboutBundleGroupData info) { >+ if (info == null) { >+ imageLabel.setImage(null); >+ text.setText(""); //$NON-NLS-1$ >+ return; >+ } >+ >+ ImageDescriptor desc = info.getFeatureImage(); >+ Image image = (Image) cachedImages.get(desc); >+ if (image == null && desc != null) { >+ image = desc.createImage(); >+ cachedImages.put(desc, image); >+ } >+ imageLabel.setImage(image); >+ >+ String aboutText = info.getAboutText(); >+ setItem(null); >+ if (aboutText != null) >+ setItem(scan(aboutText)); >+ >+ if (getItem() == null) >+ text.setText(IDEWorkbenchMessages >+ .getString("AboutFeaturesDialog.noInformation")); //$NON-NLS-1$ >+ else { >+ text.setText(getItem().getText()); >+ text.setCursor(null); >+ setLinkRanges(text, getItem().getLinkRanges()); >+ } >+ } >+ >+ /** >+ * Select the initial selection >+ */ >+ public void setInitialSelection(AboutBundleGroupData info) { >+ lastSelection = info; >+ } >+ >+ /** >+ * Sort the rows of the table based on the selected column. >+ * >+ * @param column >+ * index of table column selected as sort criteria >+ */ >+ private void sort(int column) { >+ if (lastColumnChosen == column) >+ reverseSort = !reverseSort; >+ else { >+ reverseSort = false; >+ lastColumnChosen = column; >+ } >+ >+ if (table.getItemCount() <= 1) >+ return; >+ >+ // Remember the last selection >+ int sel = table.getSelectionIndex(); >+ if (sel != -1) >+ lastSelection = bundleGroupInfos[sel]; >+ >+ switch (column) { >+ case 0: >+ AboutData.sortByProvider(reverseSort, bundleGroupInfos); >+ break; >+ case 1: >+ AboutData.sortByName(reverseSort, bundleGroupInfos); >+ break; >+ case 2: >+ AboutData.sortByVersion(reverseSort, bundleGroupInfos); >+ break; >+ case 3: >+ AboutData.sortById(reverseSort, bundleGroupInfos); >+ break; >+ } >+ >+ refreshTable(column); >+ } >+ >+ /** >+ * Refresh the rows of the table based on the selected column. Maintain >+ * selection from before sort action request. >+ */ >+ private void refreshTable(int col) { >+ TableItem[] items = table.getItems(); >+ >+ // create new order of table items >+ for (int i = 0; i < items.length; i++) { >+ items[i].setText(createRow(bundleGroupInfos[i])); >+ items[i].setData(bundleGroupInfos[i]); >+ } >+ >+ // Maintain the original selection >+ int sel = -1; >+ if (lastSelection != null) { >+ String oldId = lastSelection.getId(); >+ for (int k = 0; k < bundleGroupInfos.length; k++) >+ if (oldId.equalsIgnoreCase(bundleGroupInfos[k].getId())) >+ sel = k; >+ >+ table.setSelection(sel); >+ table.showSelection(); >+ } >+ >+ updateInfoArea(lastSelection); >+ } >+ >+ /** >+ * Return an array of strings containing the argument's information in the >+ * proper order for this table's columns. >+ * >+ * @param info >+ * the source information for the new row, must not be null >+ */ >+ private static String[] createRow(AboutBundleGroupData info) { >+ return new String[] { info.getProviderName(), info.getName(), >+ info.getVersion(), info.getId()}; >+ } >+} >Index: src/org/eclipse/ui/internal/ide/dialogs/AboutPluginsDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/AboutPluginsDialog.java,v >retrieving revision 1.6 >diff -u -r1.6 AboutPluginsDialog.java >--- src/org/eclipse/ui/internal/ide/dialogs/AboutPluginsDialog.java 15 Mar 2004 19:11:35 -0000 1.6 >+++ src/org/eclipse/ui/internal/ide/dialogs/AboutPluginsDialog.java 5 Apr 2004 16:12:50 -0000 >@@ -1,34 +1,27 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials! > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/cpl-v10.html > * > * Contributors: >- * IBM Corporation - initial API and implementation >- * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog font should be >- * activated and used by other components. >+ * IBM Corporation - initial API and implementation >+ * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog >+ * font should be activated and used by other components. > ************************************************************************/ >- > package org.eclipse.ui.internal.ide.dialogs; > > import java.net.URL; >-import java.text.Collator; >-import java.util.Arrays; >-import java.util.Collections; >-import java.util.Comparator; >-import java.util.Locale; >+import java.util.ArrayList; > > import org.eclipse.core.runtime.IPluginDescriptor; >-import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Platform; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; >@@ -40,16 +33,19 @@ > import org.eclipse.swt.widgets.TableColumn; > import org.eclipse.swt.widgets.TableItem; > import org.eclipse.ui.help.WorkbenchHelp; >-import org.eclipse.ui.internal.AboutInfo; >+import org.eclipse.ui.internal.ide.AboutBundleData; >+import org.eclipse.ui.internal.ide.AboutData; > import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; > import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; > import org.eclipse.ui.internal.ide.IHelpContextIds; >+import org.eclipse.ui.internal.util.BundleUtility; >+import org.osgi.framework.Bundle; > > /** > * Displays information about the product plugins. > * > * @private >- * This class is internal to the workbench and must not be called outside the workbench >+ * this class is internal to the ide > */ > public class AboutPluginsDialog extends ProductInfoDialog { > >@@ -57,14 +53,12 @@ > * Table height in dialog units (value 200). > */ > private static final int TABLE_HEIGHT = 200; >- > private static final String PLUGININFO = "about.html"; //$NON-NLS-1$ >- > private final static int MORE_ID = IDialogConstants.CLIENT_ID + 1; > > private Table vendorInfo; > private Button moreInfo; >- >+ > private String title; > private String message; > private String helpContextId; >@@ -76,470 +70,327 @@ > IDEWorkbenchMessages.getString("AboutPluginsDialog.pluginId"), //$NON-NLS-1$ > }; > >- private IPluginDescriptor[] info; >+ private String productName; >+ private AboutBundleData[] bundleInfos; > >- private AboutInfo primaryInfo; >- > private int lastColumnChosen = 0; // initially sort by provider > private boolean reverseSort = false; // initially sort ascending >- private IPluginDescriptor lastSelection = null; >- >+ private AboutBundleData lastSelection = null; >+ > /** > * Constructor for AboutPluginsDialog > */ >- public AboutPluginsDialog(Shell parentShell, AboutInfo primaryInfo) { >+ public AboutPluginsDialog(Shell parentShell, String productName) { > this( > parentShell, >- primaryInfo, >- Platform.getPluginRegistry().getPluginDescriptors(), >+ productName, >+ getAllBundles(), > null, > null, > IHelpContextIds.ABOUT_PLUGINS_DIALOG); > } > > /** >- * Constructor for AboutPluginsDialog >- */ >- public AboutPluginsDialog(Shell parentShell, AboutInfo primaryInfo, IPluginDescriptor[] descriptors, String title, String msg, String helpContextId) { >+ * Constructor for AboutPluginsDialog >+ * >+ * @param productName >+ * must not be null >+ * @param bundles >+ * must not be null >+ */ >+ public AboutPluginsDialog(Shell parentShell, String productName, Bundle[] bundles, String title, String message, String helpContextId) { > super(parentShell); > setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL); >- info = descriptors; > this.title = title; >- message = msg; >+ this.message = message; > this.helpContextId = helpContextId; >- sortByProvider(); >- this.primaryInfo = primaryInfo; >- } >- >- /* (non-Javadoc) >- * Method declared on Dialog. >- */ >- protected void buttonPressed(int buttonId) { >- switch (buttonId) { >- case MORE_ID : { >- handleMoreInfoPressed(); >- return; >- } >- } >- super.buttonPressed(buttonId); >- } >- >- /* (non-Javadoc) >- * Method declared on Window. >- */ >- protected void configureShell(Shell newShell) { >- super.configureShell(newShell); >- if (title == null) { >- if (primaryInfo != null) { >- title = primaryInfo.getProductName(); >- } >- if (title != null) { >- title = IDEWorkbenchMessages.format( >- "AboutPluginsDialog.shellTitle", //$NON-NLS-1$ >- new Object[] {title}); >- } >- } >- if (title != null) >- newShell.setText(title); >- >- WorkbenchHelp.setHelp( >- newShell, >- helpContextId); >- } >- /** >- * Add buttons to the dialog's button bar. >- * >- * Subclasses should override. >- * >- * @param parent the button bar composite >- */ >- protected void createButtonsForButtonBar(Composite parent) { >- parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- >- moreInfo = createButton(parent, MORE_ID, IDEWorkbenchMessages.getString("AboutPluginsDialog.moreInfo"), false); //$NON-NLS-1$ >- >- // set initial enablement >- moreInfo.setEnabled(tableHasSelection() & selectionHasInfo()); >- >- Label l = new Label(parent, SWT.NONE); >- l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- GridLayout layout = (GridLayout)parent.getLayout(); >- layout.numColumns++; >- layout.makeColumnsEqualWidth = false; >- >- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); >- } >- >- >- /** >- * Create the contents of the dialog (above the button bar). >- * >- * Subclasses should overide. >- * >- * @param the parent composite to contain the dialog area >- * @return the dialog area control >- */ >- protected Control createDialogArea(Composite parent) { >- >- Composite outer = (Composite) super.createDialogArea(parent); >- >- if (message != null) { >- Label label = new Label(outer, SWT.NONE); >- label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- label.setFont(parent.getFont()); >- label.setText(message); >- } >- >- createTable(outer); >- createColumns(); >- >- GridData gridData = >- new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); >- gridData.grabExcessVerticalSpace = true; >- gridData.grabExcessHorizontalSpace = true; >- >- // suggest a height for the table >- gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); >- vendorInfo.setLayoutData(gridData); >- >- return outer; >- } >- /** >- * Create the table part of the dialog. >- * >- * @param the parent composite to contain the dialog area >- */ >- protected void createTable(Composite parent) { >- vendorInfo = >- new Table( >- parent, >- SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); >- vendorInfo.setHeaderVisible(true); >- vendorInfo.setLinesVisible(true); >- vendorInfo.setFont(parent.getFont()); >- >- SelectionListener listener = new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- setMoreButtonEnablement(e.item != null); >- } >- }; >- vendorInfo.addSelectionListener(listener); >- } >- /** >- * Populate the table with plugin info obtained from the registry. >- * >- * @param the parent composite to contain the dialog area >- */ >- protected void createColumns() { >- /* create table headers */ >- int[] columnWidths = >- { >- convertHorizontalDLUsToPixels(120), >- convertHorizontalDLUsToPixels(180), >- convertHorizontalDLUsToPixels(70), >- convertHorizontalDLUsToPixels(70)}; >- for (int i = 0; i < columnTitles.length; i++) { >- TableColumn tableColumn = new TableColumn(vendorInfo, SWT.NULL); >- tableColumn.setWidth(columnWidths[i]); >- tableColumn.setText(columnTitles[i]); >- final int columnIndex = i; >- tableColumn.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- sort(columnIndex); >- } >- }); >- >- } >- >- /* fill each row of the table with plugin registry info */ >- for (int i = 0; i < info.length; i++) { >- String provider = info[i].getProviderName(); >- String pluginName = info[i].getLabel(); >- String version = info[i].getVersionIdentifier().toString(); >- String pluginId = info[i].getUniqueIdentifier(); >- String[] row = { provider, pluginName, version, pluginId }; >- TableItem item = new TableItem(vendorInfo, SWT.NULL); >- item.setText(row); >- } >- } >- /** >- * Set enablement of moreInfo button based on whether or not >- * there is a selection in the table and if there is any additional >- * info to show for that plugin. >- * >- * @param isSelected whether there is a selection in the table >- */ >- protected void setMoreButtonEnablement(boolean isSelected) { >- moreInfo.setEnabled(isSelected && selectionHasInfo()); >- } >- >- /** >- * Check if the currently selected plugin has additional >- * information to show. >- * >- * @return true if the selected plugin has additional info available to display >- */ >- private boolean selectionHasInfo(){ >- TableItem[] items = vendorInfo.getSelection(); >- if (items.length == 0) >- return false; >- int i = vendorInfo.getSelectionIndex(); >- IPluginDescriptor desc = info[i]; >- URL infoURL = desc.find(new Path(PLUGININFO)); >- if (infoURL == null && IDEWorkbenchPlugin.DEBUG) { >- // only report ini problems if the -debug command line argument is used >- IDEWorkbenchPlugin.log("Problem reading plugin info for: " + desc.getLabel()); //$NON-NLS-1$ >- } >- return infoURL != null; >- } >+ this.productName = productName; > >- /** >- * Create the button to provide more info on the selected plugin. >- * >- * @return true if there is an item selected in the table, false otherwise >- */ >+ ArrayList list = new ArrayList(bundles.length); >+ for(int i = 0; i < bundles.length; ++i ) >+ list.add(new AboutBundleData(bundles[i])); >+ bundleInfos = (AboutBundleData[])list.toArray(new AboutBundleData[0]); >+ >+ AboutData.sortByProvider(reverseSort, bundleInfos); >+ } >+ >+ // TODO when bug 54574 is fixed, this should be changed to use bundle >+ // providers -> bundle groups -> bundles >+ private static Bundle[] getAllBundles() { >+ IPluginDescriptor[] descs = Platform.getPluginRegistry().getPluginDescriptors(); >+ Bundle[] bundles = new Bundle[descs.length]; >+ for(int i = 0; i < descs.length; ++i) >+ bundles[i] = Platform.getBundle(descs[i].getUniqueIdentifier()); >+ >+ return bundles; >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected void buttonPressed(int buttonId) { >+ switch (buttonId) { >+ case MORE_ID: >+ handleMoreInfoPressed(); >+ break; >+ default: >+ super.buttonPressed(buttonId); >+ break; >+ } >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Window. >+ */ >+ protected void configureShell(Shell newShell) { >+ super.configureShell(newShell); >+ if (title == null && productName != null) >+ title = IDEWorkbenchMessages.format( >+ "AboutPluginsDialog.shellTitle", //$NON-NLS-1$ >+ new Object[] { productName }); >+ >+ if (title != null) >+ newShell.setText(title); >+ >+ WorkbenchHelp.setHelp(newShell, helpContextId); >+ } >+ >+ /** >+ * Add buttons to the dialog's button bar. >+ * >+ * Subclasses should override. >+ * >+ * @param parent >+ * the button bar composite >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ moreInfo = createButton(parent, MORE_ID, IDEWorkbenchMessages >+ .getString("AboutPluginsDialog.moreInfo"), false); //$NON-NLS-1$ >+ moreInfo.setEnabled(tableHasSelection() && selectionHasInfo()); >+ >+ Label l = new Label(parent, SWT.NONE); >+ l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ GridLayout layout = (GridLayout) parent.getLayout(); >+ layout.numColumns++; >+ layout.makeColumnsEqualWidth = false; >+ >+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, >+ true); >+ } >+ >+ /** >+ * Create the contents of the dialog (above the button bar). >+ * >+ * Subclasses should overide. >+ * >+ * @param parent >+ * the parent composite to contain the dialog area >+ * @return the dialog area control >+ */ >+ protected Control createDialogArea(Composite parent) { >+ Composite outer = (Composite) super.createDialogArea(parent); >+ >+ if (message != null) { >+ Label label = new Label(outer, SWT.NONE); >+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ label.setFont(parent.getFont()); >+ label.setText(message); >+ } >+ >+ createTable(outer); >+ >+ return outer; >+ } >+ >+ /** >+ * Create the table part of the dialog. >+ * >+ * @param parent >+ * the parent composite to contain the dialog area >+ */ >+ protected void createTable(Composite parent) { >+ vendorInfo = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE >+ | SWT.FULL_SELECTION | SWT.BORDER); >+ vendorInfo.setHeaderVisible(true); >+ vendorInfo.setLinesVisible(true); >+ vendorInfo.setFont(parent.getFont()); >+ vendorInfo.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ // enable if there is an item selected and that >+ // item has additional info >+ moreInfo.setEnabled(e.item != null && selectionHasInfo()); >+ } >+ }); >+ >+ int[] columnWidths = { >+ convertHorizontalDLUsToPixels(120), >+ convertHorizontalDLUsToPixels(120), >+ convertHorizontalDLUsToPixels(70), >+ convertHorizontalDLUsToPixels(130) >+ }; >+ >+ // create table headers >+ for (int i = 0; i < columnTitles.length; i++) { >+ TableColumn column = new TableColumn(vendorInfo, SWT.NULL); >+ column.setWidth(columnWidths[i]); >+ column.setText(columnTitles[i]); >+ final int columnIndex = i; >+ column.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ sort(columnIndex); >+ } >+ }); >+ } >+ >+ // create a row for each member of the bundleInfo array >+ for (int i = 0; i < bundleInfos.length; ++i) { >+ TableItem item = new TableItem(vendorInfo, SWT.NULL); >+ item.setText(createRow(bundleInfos[i])); >+ item.setData(bundleInfos[i]); >+ } >+ >+ GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL, >+ GridData.VERTICAL_ALIGN_FILL, true, true); >+ gridData.heightHint = convertVerticalDLUsToPixels(TABLE_HEIGHT); >+ vendorInfo.setLayoutData(gridData); >+ } >+ >+ /** >+ * Check if the currently selected plugin has additional information to >+ * show. >+ * >+ * @return true if the selected plugin has additional info available to >+ * display >+ */ >+ private boolean selectionHasInfo() { >+ TableItem[] items = vendorInfo.getSelection(); >+ if (items.length <= 0) >+ return false; >+ >+ AboutBundleData bundleInfo = bundleInfos[vendorInfo.getSelectionIndex()]; >+ URL infoURL = BundleUtility.find(bundleInfo.getId(), PLUGININFO); >+ >+ // only report ini problems if the -debug command line argument is used >+ if (infoURL == null && IDEWorkbenchPlugin.DEBUG) >+ IDEWorkbenchPlugin.log("Problem reading plugin info for: " //$NON-NLS-1$ >+ + bundleInfo.getName()); >+ >+ return infoURL != null; >+ } >+ >+ /** >+ * Create the button to provide more info on the selected plugin. >+ * >+ * @return true if there is an item selected in the table, false otherwise >+ */ > private boolean tableHasSelection() { >- if (vendorInfo == null) >- return false; >- return (vendorInfo.getSelectionCount() > 0); >- >- } >+ return vendorInfo == null ? false : vendorInfo.getSelectionCount() > 0; >+ } > > /** >- * Respond to moreInfo button pressed. >- * >+ * The More Info button was pressed. Open a browser showing the license information >+ * for the selected bundle or an error dialog if the browser cannot be opened. > */ > protected void handleMoreInfoPressed() { >- TableItem[] items = vendorInfo.getSelection(); >- if (items.length == 0) >- return; >- int i = vendorInfo.getSelectionIndex(); >- IPluginDescriptor desc = info[i]; >- openMoreInfo(desc); >- } >- /** >- * Open html file containing additional info about the selected >- * plugin. >- * >- */ >- private void openMoreInfo(IPluginDescriptor desc) { >- if (desc != null && openBrowser(desc.find(new Path(PLUGININFO)))) >- return; >- MessageDialog.openError(getShell(), IDEWorkbenchMessages >- .getString("AboutPluginsDialog.errorTitle"), //$NON-NLS-1$ >- IDEWorkbenchMessages.format( >- "AboutPluginsDialog.unableToOpenFile", new Object[]{ //$NON-NLS-1$ >- PLUGININFO, desc.getUniqueIdentifier()})); >- } >- >- /** >- * Sort the rows of the table based on the selected column. >- * >- * @param column index of table column selected as sort criteria >- */ >- private void sort(int column) { >- // Choose new sort algorithm >- if (lastColumnChosen == column){ >- reverseSort = !reverseSort; >- } >- else{ >- reverseSort = false; >- lastColumnChosen = column; >- } >- >- if(vendorInfo.getItemCount() <= 1) return; >- >- // Remember the last selection >- int idx = vendorInfo.getSelectionIndex(); >- if (idx != -1) >- lastSelection = info[idx]; >- >- switch (column){ >- case 0: >- sortByProvider(); >- break; >- case 1: >- sortByName(); >- break; >- case 2: >- sortByVersion(); >- break; >- case 3: >- sortById(); >- break; >- } >- >- refreshTable(column); >- } >+ if(vendorInfo == null) >+ return; > >- /** >- * Refresh the rows of the table based on the selected column. >- * Maintain selection from before sort action request. >- * >- * @param items the old state table items >- */ >- private void refreshTable(int col){ >- TableItem[] items = vendorInfo.getItems(); >- int idx = -1; // the new index of the selection >- // Create new order of table items >- for(int i = 0; i < items.length; i++) { >- String provider = info[i].getProviderName(); >- String pluginName = info[i].getLabel(); >- String version = info[i].getVersionIdentifier().toString(); >- String pluginId = info[i].getUniqueIdentifier(); >- String [] row = { provider, pluginName, version, pluginId }; >- items[i].setText(row); >- } >- // Maintain the original selection >- if (lastSelection != null){ >- String oldId = lastSelection.getUniqueIdentifier(); >- for (int k = 0; k < info.length; k++){ >- if (oldId.equalsIgnoreCase(info[k].getUniqueIdentifier())) >- idx = k; >- } >- vendorInfo.setSelection(idx); >- vendorInfo.showSelection(); >- } >+ TableItem[] items = vendorInfo.getSelection(); >+ if (items.length <= 0) >+ return; > >- moreInfo.setEnabled(tableHasSelection() && selectionHasInfo()); >- } >- /** >- * Sort the rows of the table based on the plugin provider. >- * Secondary criteria is unique plugin id. >- */ >- private void sortByProvider(){ >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort){ >- java.util.List infoList = Arrays.asList(info); >- Collections.reverse(infoList); >- for (int i=0; i< info.length; i++){ >- info[i] = (IPluginDescriptor)infoList.get(i); >- } >- } >- else { >- // Sort ascending >- Arrays.sort(info, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- IPluginDescriptor d1, d2; >- String provider1, provider2, name1, name2; >- d1 = (IPluginDescriptor) a; >- provider1 = d1.getProviderName(); >- name1 = d1.getLabel(); >- d2 = (IPluginDescriptor) b; >- provider2 = d2.getProviderName(); >- name2 = d2.getLabel(); >- if (provider1.equals(provider2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(provider1, provider2); >- } >- }); >- } >- } >- /** >- * Sort the rows of the table based on unique plugin id. >- */ >- private void sortByName(){ >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort){ >- java.util.List infoList = Arrays.asList(info); >- Collections.reverse(infoList); >- for (int i=0; i< info.length; i++){ >- info[i] = (IPluginDescriptor)infoList.get(i); >- } >- } >- else { >- // Sort ascending >- Arrays.sort(info, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- IPluginDescriptor d1, d2; >- String name1, name2; >- d1 = (IPluginDescriptor) a; >- name1 = d1.getLabel(); >- d2 = (IPluginDescriptor) b; >- name2 = d2.getLabel(); >- return coll.compare(name1, name2); >- } >- }); >- } >- >- } >- /** >- * Sort the rows of the table based on the plugin version. >- * Secondary criteria is unique plugin id. >- */ >- private void sortByVersion(){ >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort){ >- java.util.List infoList = Arrays.asList(info); >- Collections.reverse(infoList); >- for (int i=0; i< info.length; i++){ >- info[i] = (IPluginDescriptor)infoList.get(i); >- } >- } >- else { >- // Sort ascending >- Arrays.sort(info, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- IPluginDescriptor d1, d2; >- String version1, version2, name1, name2; >- d1 = (IPluginDescriptor) a; >- version1 = d1.getVersionIdentifier().toString(); >- name1 = d1.getLabel(); >- d2 = (IPluginDescriptor) b; >- version2 = d2.getVersionIdentifier().toString(); >- name2 = d2.getLabel(); >- if (version1.equals(version2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(version1, version2); >- } >- }); >- } >- } >- /** >- * Sort the rows of the table based on the plugin id. >- * Secondary criteria is unique plugin id. >- */ >- private void sortById(){ >- /* If sorting in reverse, info array is already sorted forward by >- * key so the info array simply needs to be reversed. >- */ >- if (reverseSort){ >- java.util.List infoList = Arrays.asList(info); >- Collections.reverse(infoList); >- for (int i=0; i< info.length; i++){ >- info[i] = (IPluginDescriptor)infoList.get(i); >- } >- } >- else { >- // Sort ascending >- Arrays.sort(info, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- public int compare(Object a, Object b) { >- IPluginDescriptor d1, d2; >- String pluginId1, pluginId2, name1, name2; >- d1 = (IPluginDescriptor) a; >- pluginId1 = d1.getUniqueIdentifier(); >- name1 = d1.getLabel(); >- d2 = (IPluginDescriptor) b; >- pluginId2 = d2.getUniqueIdentifier(); >- name2 = d2.getLabel(); >- if (pluginId1.equals(pluginId2)) >- return coll.compare(name1, name2); >- else >- return coll.compare(pluginId1, pluginId2); >- } >- }); >- } >- } >-} >\ No newline at end of file >+ AboutBundleData bundleInfo = (AboutBundleData)items[0].getData(); >+ if (bundleInfo == null) >+ return; >+ >+ if (!openBrowser(BundleUtility.find(bundleInfo.getId(), PLUGININFO))) >+ MessageDialog >+ .openError(getShell(), IDEWorkbenchMessages >+ .getString("AboutPluginsDialog.errorTitle"), //$NON-NLS-1$ >+ IDEWorkbenchMessages.format( >+ "AboutPluginsDialog.unableToOpenFile", //$NON-NLS-1$ >+ new Object[] { PLUGININFO, >+ bundleInfo.getId()})); >+ } >+ >+ /** >+ * Sort the rows of the table based on the selected column. >+ * >+ * @param column >+ * index of table column selected as sort criteria >+ */ >+ private void sort(int column) { >+ if (lastColumnChosen == column) >+ reverseSort = !reverseSort; >+ else { >+ reverseSort = false; >+ lastColumnChosen = column; >+ } >+ >+ if (vendorInfo.getItemCount() <= 1) >+ return; >+ >+ int sel = vendorInfo.getSelectionIndex(); >+ if (sel != -1) >+ lastSelection = bundleInfos[sel]; >+ >+ switch (column) { >+ case 0: >+ AboutData.sortByProvider(reverseSort, bundleInfos); >+ break; >+ case 1: >+ AboutData.sortByName(reverseSort, bundleInfos); >+ break; >+ case 2: >+ AboutData.sortByVersion(reverseSort, bundleInfos); >+ break; >+ case 3: >+ AboutData.sortById(reverseSort, bundleInfos); >+ break; >+ } >+ >+ refreshTable(column); >+ } >+ >+ /** >+ * Refresh the rows of the table based on the selected column. Maintain >+ * selection from before sort action request. >+ */ >+ private void refreshTable(int col) { >+ TableItem[] items = vendorInfo.getItems(); >+ >+ // create new order of table items >+ for (int i = 0; i < items.length; i++) { >+ items[i].setText(createRow(bundleInfos[i])); >+ items[i].setData(bundleInfos[i]); >+ } >+ >+ // maintain the original selection >+ int sel = -1; >+ if (lastSelection != null) { >+ String oldId = lastSelection.getId(); >+ for (int k = 0; k < bundleInfos.length; k++) >+ if (oldId.equalsIgnoreCase(bundleInfos[k].getId())) >+ sel = k; >+ >+ vendorInfo.setSelection(sel); >+ vendorInfo.showSelection(); >+ } >+ >+ moreInfo.setEnabled(tableHasSelection() && selectionHasInfo()); >+ } >+ >+ /** >+ * Return an array of strings containing the argument's information in the >+ * proper order for this table's columns. >+ * >+ * @param info >+ * the source information for the new row, must not be null >+ */ >+ private static String[] createRow(AboutBundleData info) { >+ return new String[] { info.getProviderName(), info.getName(), >+ info.getVersion(), info.getId()}; >+ } >+} >Index: src/org/eclipse/ui/internal/ide/AboutBundleData.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/AboutBundleData.java >diff -N src/org/eclipse/ui/internal/ide/AboutBundleData.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/AboutBundleData.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,43 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.ide; >+ >+import org.eclipse.core.runtime.Platform; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.Constants; >+ >+ >+/** >+ * A small class to manage the about dialog information for a single bundle. >+ * @since 3.0 >+ */ >+public class AboutBundleData extends AboutData { >+ >+ public AboutBundleData(Bundle bundle) { >+ super(getResourceString(bundle, Constants.BUNDLE_VENDOR), >+ getResourceString(bundle, Constants.BUNDLE_NAME), >+ getResourceString(bundle, Constants.BUNDLE_VERSION), >+ bundle.getSymbolicName()); >+ } >+ >+ /** >+ * A function to translate the resource tags that may be embedded in a >+ * string associated with some bundle. >+ * >+ * @param headerName >+ * the used to retrieve the correct string >+ * @return the string or null if the string cannot be found >+ */ >+ private static String getResourceString(Bundle bundle, String headerName) { >+ String value = (String) bundle.getHeaders().get(headerName); >+ return value == null ? null : Platform.getResourceString(bundle, value); >+ } >+} >Index: src/org/eclipse/ui/internal/ide/AboutBundleGroupData.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/AboutBundleGroupData.java >diff -N src/org/eclipse/ui/internal/ide/AboutBundleGroupData.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/AboutBundleGroupData.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,102 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.ide; >+ >+import java.io.IOException; >+import java.io.InputStream; >+import java.net.URL; >+import java.util.zip.CRC32; >+import java.util.zip.CheckedInputStream; >+ >+import org.eclipse.core.runtime.IBundleGroup; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.ui.branding.IBundleGroupConstants; >+import org.eclipse.ui.branding.IProductConstants; >+ >+/** >+ * A small class to manage the information related to IBundleGroup's. >+ * @since 3.0 >+ */ >+public class AboutBundleGroupData extends AboutData { >+ private IBundleGroup bundleGroup; >+ >+ private URL featureImageUrl; >+ private Long featureImageCrc; >+ private ImageDescriptor featureImage; >+ >+ public AboutBundleGroupData(IBundleGroup bundleGroup) { >+ super(bundleGroup.getProviderName(), >+ bundleGroup.getName(), >+ bundleGroup.getVersion(), >+ bundleGroup.getIdentifier()); >+ this.bundleGroup = bundleGroup; >+ } >+ >+ public IBundleGroup getBundleGroup() { >+ return bundleGroup; >+ } >+ >+ public URL getFeatureImageUrl() { >+ if (featureImageUrl == null) >+ featureImageUrl = getURL(bundleGroup >+ .getProperty(IBundleGroupConstants.FEATURE_IMAGE)); >+ return featureImageUrl; >+ } >+ >+ public ImageDescriptor getFeatureImage() { >+ if(featureImage == null) >+ featureImage = getImage(getFeatureImageUrl()); >+ return featureImage; >+ } >+ >+ public Long getFeatureImageCrc() { >+ if(featureImageCrc != null) >+ return featureImageCrc; >+ >+ URL url = getFeatureImageUrl(); >+ if(url == null) >+ return null; >+ >+ // Get the image bytes >+ InputStream in = null; >+ try { >+ CRC32 checksum = new CRC32(); >+ in = new CheckedInputStream(url.openStream(), checksum); >+ >+ // the contents don't matter, the read just needs a place to go >+ byte[] sink = new byte[1024]; >+ while(true) >+ if(in.read(sink) <= 0) >+ break; >+ >+ featureImageCrc = new Long(checksum.getValue()); >+ return featureImageCrc; >+ >+ } catch (IOException e) { >+ return null; >+ } finally { >+ if (in != null) >+ try { >+ in.close(); >+ } catch (IOException e) { >+ // do nothing >+ } >+ } >+ } >+ >+ public String getAboutText() { >+ return bundleGroup.getProperty(IProductConstants.ABOUT_TEXT); >+ } >+ >+ public ImageDescriptor getAboutImage() { >+ return getImage(bundleGroup.getProperty(IProductConstants.ABOUT_IMAGE)); >+ } >+} >Index: src/org/eclipse/ui/internal/ide/AboutData.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/AboutData.java >diff -N src/org/eclipse/ui/internal/ide/AboutData.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/AboutData.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,220 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.ide; >+ >+import java.io.IOException; >+import java.net.URL; >+import java.text.Collator; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.Comparator; >+import java.util.List; >+import java.util.Locale; >+ >+import org.eclipse.jface.resource.ImageDescriptor; >+ >+ >+/** >+ * An abstract parent that describes data that can be displayed in a table in one of >+ * the about dialogs. >+ * @since 3.0 >+ */ >+public abstract class AboutData { >+ private String providerName; >+ private String name; >+ private String version; >+ private String id; >+ >+ protected AboutData(String providerName, String name, String version, String id) { >+ this.providerName = providerName == null ? "" : providerName; //$NON-NLS-1$ >+ this.name = name == null ? "" : name; //$NON-NLS-1$ >+ this.version = version == null ? "" : version; //$NON-NLS-1$ >+ this.id = id == null ? "" : id; //$NON-NLS-1$ >+ } >+ >+ public String getId() { >+ return id; >+ } >+ >+ public String getName() { >+ return name; >+ } >+ >+ public String getProviderName() { >+ return providerName; >+ } >+ >+ public String getVersion() { >+ return version; >+ } >+ >+ /** >+ * Modify the argument array to reverse the sort order. >+ * @param infos >+ */ >+ private static void reverse(AboutData[] infos) { >+ List infoList = Arrays.asList(infos); >+ Collections.reverse(infoList); >+ for (int i = 0; i < infos.length; ++i) >+ infos[i] = (AboutData) infoList.get(i); >+ } >+ >+ /** >+ * Modify the argument array to be sorted by provider. If the reverse >+ * boolean is true, the array is assumed to already be sorted and the >+ * direction of sort (ascending vs. descending) is reversed. Entries >+ * with the same name are sorted by name. >+ * >+ * @param reverse >+ * if true then the order of the argument is reversed without >+ * examining the value of the fields >+ * @param infos >+ * the data to be sorted >+ */ >+ public static void sortByProvider(boolean reverse, AboutData[] infos) { >+ if (reverse) { >+ reverse(infos); >+ return; >+ } >+ >+ Arrays.sort(infos, new Comparator() { >+ Collator collator = Collator.getInstance(Locale.getDefault()); >+ public int compare(Object a, Object b) { >+ AboutData info1 = (AboutData) a; >+ AboutData info2 = (AboutData) b; >+ >+ String provider1 = info1.getProviderName(); >+ String provider2 = info2.getProviderName(); >+ >+ if (!provider1.equals(provider2)) >+ return collator.compare(provider1, provider2); >+ >+ return collator.compare(info1.getName(), info2.getName()); >+ } >+ }); >+ } >+ >+ /** >+ * Modify the argument array to be sorted by name. If the reverse >+ * boolean is true, the array is assumed to already be sorted and the >+ * direction of sort (ascending vs. descending) is reversed. >+ * >+ * @param reverse >+ * if true then the order of the argument is reversed without >+ * examining the value of the fields >+ * @param infos >+ * the data to be sorted >+ */ >+ public static void sortByName(boolean reverse, AboutData[] infos) { >+ if (reverse) { >+ reverse(infos); >+ return; >+ } >+ >+ Arrays.sort(infos, new Comparator() { >+ Collator collator = Collator.getInstance(Locale.getDefault()); >+ public int compare(Object a, Object b) { >+ AboutData info1 = (AboutData) a; >+ AboutData info2 = (AboutData) b; >+ return collator.compare(info1.getName(), info2.getName()); >+ } >+ }); >+ } >+ >+ /** >+ * Modify the argument array to be sorted by version. If the reverse >+ * boolean is true, the array is assumed to already be sorted and the >+ * direction of sort (ascending vs. descending) is reversed. Entries >+ * with the same name are sorted by name. >+ * >+ * @param reverse >+ * if true then the order of the argument is reversed without >+ * examining the value of the fields >+ * @param infos >+ * the data to be sorted >+ */ >+ public static void sortByVersion(boolean reverse, AboutData[] infos) { >+ if (reverse) { >+ reverse(infos); >+ return; >+ } >+ >+ Arrays.sort(infos, new Comparator() { >+ Collator collator = Collator.getInstance(Locale.getDefault()); >+ public int compare(Object a, Object b) { >+ AboutData info1 = (AboutData) a; >+ AboutData info2 = (AboutData) b; >+ >+ String version1 = info1.getVersion(); >+ String version2 = info2.getVersion(); >+ >+ if (!version1.equals(version2)) >+ return collator.compare(version1, version2); >+ >+ return collator.compare(info1.getName(), info2.getName()); >+ } >+ }); >+ } >+ >+ /** >+ * Modify the argument array to be sorted by id. If the reverse >+ * boolean is true, the array is assumed to already be sorted and the >+ * direction of sort (ascending vs. descending) is reversed. Entries >+ * with the same name are sorted by name. >+ * >+ * @param reverse >+ * if true then the order of the argument is reversed without >+ * examining the value of the fields >+ * @param infos >+ * the data to be sorted >+ */ >+ public static void sortById(boolean reverse, AboutData[] infos) { >+ if (reverse) { >+ reverse(infos); >+ return; >+ } >+ >+ Arrays.sort(infos, new Comparator() { >+ Collator collator = Collator.getInstance(Locale.getDefault()); >+ public int compare(Object a, Object b) { >+ AboutData info1 = (AboutData) a; >+ AboutData info2 = (AboutData) b; >+ >+ String id1 = info1.getId(); >+ String id2 = info2.getId(); >+ >+ if (!id1.equals(id2)) >+ return collator.compare(id1, id2); >+ >+ return collator.compare(info1.getName(), info2.getName()); >+ } >+ }); >+ } >+ >+ protected static URL getURL(String value) { >+ try { >+ if (value != null) >+ return new URL(value); >+ } catch (IOException e) { >+ // do nothing >+ } >+ >+ return null; >+ } >+ >+ protected static ImageDescriptor getImage(URL url) { >+ return url == null ? null : ImageDescriptor.createFromURL(url); >+ } >+ >+ protected static ImageDescriptor getImage(String value) { >+ return getImage(getURL(value)); >+ } >+} >Index: src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesButtonManager.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesButtonManager.java >diff -N src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesButtonManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/dialogs/AboutFeaturesButtonManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,99 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.ide.dialogs; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.ui.internal.ide.AboutBundleGroupData; >+ >+/** >+ * Utility class used to associate BundleInfo's that have the same provider and >+ * image. The algorithm in <code>java.util.zip.CRC32</code> is used to determine >+ * image identity. >+ */ >+public class AboutFeaturesButtonManager { >+ private Map providerMap = new HashMap(); >+ >+ private static class Key { >+ public String providerName; >+ public Long crc; >+ >+ /** >+ * @param crc must not be null >+ */ >+ public Key(String providerName, Long crc) { >+ this.providerName = providerName; >+ this.crc = crc; >+ } >+ >+ public boolean equals(Object o) { >+ if (!(o instanceof Key)) >+ return false; >+ Key other = (Key) o; >+ if (!providerName.equals(other.providerName)) >+ return false; >+ return crc.equals(other.crc); >+ } >+ >+ public int hashCode() { >+ return providerName.hashCode(); >+ } >+ } >+ >+ /** >+ * @return true if a button should be added (i.e., the argument has an image >+ * and it does not already have a button) >+ */ >+ public boolean add(AboutBundleGroupData info) { >+ // no button for features without an image >+ Long crc = info.getFeatureImageCrc(); >+ if (crc == null) >+ return false; >+ >+ String providerName = info.getProviderName(); >+ Key key = new Key(providerName, crc); >+ >+ List infoList = (List) providerMap.get(key); >+ if (infoList != null) { >+ infoList.add(info); >+ return false; >+ } >+ >+ infoList = new ArrayList(); >+ infoList.add(info); >+ providerMap.put(key, infoList); >+ return true; >+ } >+ >+ /** >+ * Return an array of all bundle groups that share the argument's provider and >+ * image. Returns an empty array if there isn't any related information. >+ */ >+ public AboutBundleGroupData[] getRelatedInfos(AboutBundleGroupData info) { >+ // if there's no image, then there won't be a button >+ Long crc = info.getFeatureImageCrc(); >+ if (crc == null) return >+ new AboutBundleGroupData[0]; >+ >+ String providerName = info.getProviderName(); >+ Key key = new Key(providerName, crc); >+ >+ List infoList = (List) providerMap.get(key); >+ if (infoList == null) return >+ new AboutBundleGroupData[0]; >+ >+ return (AboutBundleGroupData[]) infoList >+ .toArray(new AboutBundleGroupData[0]); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 54548
: 9219 |
9296