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 59782 Details for
Bug 175236
[StatusHandling] Move StatusDialog and StatusNotificationManager into WorkbenchErrorHandler
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]
Fix
175236.txt (text/plain), 59.91 KB, created by
Szymon Brandys
on 2007-02-26 08:36:43 EST
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Szymon Brandys
Created:
2007-02-26 08:36:43 EST
Size:
59.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/statushandlers/StatusDialog.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/statushandlers/StatusDialog.java >diff -N Eclipse UI/org/eclipse/ui/statushandlers/StatusDialog.java >--- Eclipse UI/org/eclipse/ui/statushandlers/StatusDialog.java 6 Feb 2007 17:49:49 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,560 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ui.statushandlers; >- >-import java.net.URL; >-import java.util.HashMap; >-import java.util.Iterator; >-import java.util.Map; >- >-import org.eclipse.core.runtime.jobs.Job; >-import org.eclipse.jface.action.IAction; >-import org.eclipse.jface.dialogs.ErrorDialog; >-import org.eclipse.jface.dialogs.IDialogConstants; >-import org.eclipse.jface.dialogs.MessageDialogWithToggle; >-import org.eclipse.jface.preference.IPreferenceStore; >-import org.eclipse.jface.resource.ImageDescriptor; >-import org.eclipse.jface.viewers.IContentProvider; >-import org.eclipse.jface.viewers.ILabelProviderListener; >-import org.eclipse.jface.viewers.ISelection; >-import org.eclipse.jface.viewers.ISelectionChangedListener; >-import org.eclipse.jface.viewers.IStructuredContentProvider; >-import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.jface.viewers.ITableLabelProvider; >-import org.eclipse.jface.viewers.SelectionChangedEvent; >-import org.eclipse.jface.viewers.StructuredSelection; >-import org.eclipse.jface.viewers.TableViewer; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerComparator; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.ui.internal.WorkbenchPlugin; >-import org.eclipse.ui.internal.progress.ProgressManager; >-import org.eclipse.ui.internal.progress.ProgressManagerUtil; >-import org.eclipse.ui.internal.progress.ProgressMessages; >-import org.eclipse.ui.progress.IProgressConstants; >-import org.eclipse.ui.statushandlers.StatusNotificationManager.StatusInfo; >- >-/** >- * A dialog for displaying >- * >- */ >-public class StatusDialog extends ErrorDialog { >- >- /* >- * Preference used to indicate whether the user should be prompted to >- * confirm the execution of the job's goto action >- */ >- private static final String PREF_SKIP_GOTO_ACTION_PROMPT = "pref_skip_goto_action_prompt"; //$NON-NLS-1$ >- >- /* >- * The id of the goto action button >- */ >- private static final int GOTO_ACTION_ID = IDialogConstants.CLIENT_ID + 1; >- >- private TableViewer statusListViewer; >- >- private StatusInfo selectedStatus; >- >- /** >- * Create a new instance of the receiver. >- * >- * @param parentShell >- * @param title >- * @param msg >- * @param statusInfo >- * @param displayMask >- */ >- public StatusDialog(Shell parentShell, String title, String msg, >- StatusInfo statusInfo, int displayMask) { >- super(parentShell, (title == null ? statusInfo.getStatus().getMessage() >- : title), msg, statusInfo.getStatus(), displayMask); >- setShellStyle(SWT.RESIZE | SWT.MIN | getShellStyle()); >- this.selectedStatus = statusInfo; >- setBlockOnOpen(false); >- } >- >- /** >- * Method which should be invoked when new errors become available for >- * display >- */ >- void refresh() { >- >- if (AUTOMATED_MODE) { >- return; >- } >- >- // Do not refresh if we are in the process of >- // opening or shutting down >- if (dialogArea == null || dialogArea.isDisposed()) { >- return; >- } >- >- if (isMultipleStatusDialog()) { >- if (statusListViewer == null) { >- // The job list doesn't exist so create it. >- setMessage(ProgressMessages.JobErrorDialog_MultipleErrorsMessage); >- getShell().setText( >- ProgressMessages.JobErrorDialog_MultipleErrorsTitle); >- createStatusListArea((Composite) dialogArea); >- showDetailsArea(); >- } >- refreshStatusList(); >- } >- updateEnablements(); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.dialogs.ErrorDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) >- */ >- protected void createButtonsForButtonBar(Composite parent) { >- IAction gotoAction = getGotoAction(); >- String text = null; >- if (gotoAction != null) { >- text = gotoAction.getText(); >- } >- if (text == null) { >- // Text is set to this initiallybut will be changed for active job >- text = ProgressMessages.JobErrorDialog_CustomJobText; >- } >- createButton(parent, GOTO_ACTION_ID, text, false); >- super.createButtonsForButtonBar(parent); >- } >- >- /* >- * Update the button enablements >- */ >- private void updateEnablements() { >- Button details = getButton(IDialogConstants.DETAILS_ID); >- if (details != null) { >- details.setEnabled(selectedStatus.getStatus().isMultiStatus() >- || isMultipleStatusDialog()); >- } >- Button gotoButton = getButton(GOTO_ACTION_ID); >- if (gotoButton != null) { >- IAction gotoAction = getGotoAction(); >- boolean hasValidGotoAction = gotoAction != null; >- String text = gotoButton.getText(); >- String newText = null; >- if (hasValidGotoAction) { >- newText = gotoAction.getText(); >- } >- if (newText == null) { >- hasValidGotoAction = false; >- newText = ProgressMessages.JobErrorDialog_CustomJobText; >- } >- if (!newText.equals(text)) { >- gotoButton.setText(newText); >- } >- gotoButton.setEnabled(hasValidGotoAction); >- gotoButton.setVisible(hasValidGotoAction); >- } >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int) >- */ >- protected void buttonPressed(int id) { >- if (id == GOTO_ACTION_ID) { >- IAction gotoAction = getGotoAction(); >- if (gotoAction != null) { >- if (!isMultipleStatusDialog() || isPromptToClose()) { >- okPressed(); // close the dialog >- gotoAction.run(); // run the goto action >- } >- } >- } >- super.buttonPressed(id); >- } >- >- /* >- * Prompt to inform the user that the dialog will close and the errors >- * cleared. >- */ >- private boolean isPromptToClose() { >- IPreferenceStore store = WorkbenchPlugin.getDefault() >- .getPreferenceStore(); >- if (!store.contains(PREF_SKIP_GOTO_ACTION_PROMPT) >- || !store.getString(PREF_SKIP_GOTO_ACTION_PROMPT).equals( >- MessageDialogWithToggle.ALWAYS)) { >- MessageDialogWithToggle dialog = MessageDialogWithToggle >- .openOkCancelConfirm( >- getShell(), >- ProgressMessages.JobErrorDialog_CloseDialogTitle, >- ProgressMessages.JobErrorDialog_CloseDialogMessage, >- ProgressMessages.JobErrorDialog_DoNotShowAgainMessage, >- false, store, PREF_SKIP_GOTO_ACTION_PROMPT); >- return dialog.getReturnCode() == OK; >- } >- return true; >- } >- >- private IAction getGotoAction() { >- >- Object extension = selectedStatus.getExtension(); >- Object property = null; >- >- if (extension != null && extension instanceof Job) { >- property = ((Job) extension) >- .getProperty(IProgressConstants.ACTION_PROPERTY); >- } >- >- if (property instanceof IAction) { >- return (IAction) property; >- } >- return null; >- } >- >- /** >- * This method sets the message in the message label. >- * >- * @param messageString - >- * the String for the message area >- */ >- private void setMessage(String messageString) { >- // must not set null text in a label >- message = messageString == null ? "" : messageString; //$NON-NLS-1$ >- if (messageLabel == null || messageLabel.isDisposed()) { >- return; >- } >- messageLabel.setText(message); >- } >- >- /** >- * Create an area that allow the user to select one of multiple jobs that >- * have reported errors >- * >- * @param parent - >- * the parent of the area >- */ >- private void createStatusListArea(Composite parent) { >- // Display a list of jobs that have reported errors >- statusListViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL >- | SWT.V_SCROLL | SWT.BORDER); >- statusListViewer.setComparator(getViewerComparator()); >- Control control = statusListViewer.getControl(); >- GridData data = new GridData(GridData.FILL_BOTH >- | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); >- data.heightHint = convertHeightInCharsToPixels(10); >- control.setLayoutData(data); >- initContentProvider(); >- initLabelProvider(); >- statusListViewer >- .addSelectionChangedListener(new ISelectionChangedListener() { >- public void selectionChanged(SelectionChangedEvent event) { >- handleSelectionChange(); >- } >- }); >- applyDialogFont(parent); >- } >- >- /* >- * Return whether there are multiple errors to be displayed >- */ >- private boolean isMultipleStatusDialog() { >- return getManager().getErrors().size() > 1; >- } >- >- /* >- * Get the notificationManager that this is being created for. >- */ >- private StatusNotificationManager getManager() { >- return StatusNotificationManager.getInstance(); >- } >- >- /** >- * Return the selected error info. >- * >- * @return ErrorInfo >- */ >- public StatusInfo getSelectedError() { >- return selectedStatus; >- } >- >- /** >- * Return a viewer sorter for looking at the jobs. >- * >- * @return ViewerSorter >- */ >- private ViewerComparator getViewerComparator() { >- return new ViewerComparator() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, >- * java.lang.Object, java.lang.Object) >- */ >- public int compare(Viewer testViewer, Object e1, Object e2) { >- return ((Comparable) e1).compareTo(e2); >- } >- }; >- } >- >- /** >- * Sets the content provider for the viewer. >- */ >- protected void initContentProvider() { >- IContentProvider provider = new IStructuredContentProvider() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IContentProvider#dispose() >- */ >- public void dispose() { >- // Nothing of interest here >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) >- */ >- public Object[] getElements(Object inputElement) { >- return getManager().getErrors().toArray(); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, >- * java.lang.Object, java.lang.Object) >- */ >- public void inputChanged(Viewer viewer, Object oldInput, >- Object newInput) { >- if (newInput != null) { >- refreshStatusList(); >- } >- } >- }; >- statusListViewer.setContentProvider(provider); >- statusListViewer.setInput(getManager()); >- statusListViewer.setSelection(new StructuredSelection(selectedStatus)); >- } >- >- /** >- * Refresh the contents of the viewer. >- */ >- void refreshStatusList() { >- if (statusListViewer != null >- && !statusListViewer.getControl().isDisposed()) { >- statusListViewer.refresh(); >- Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); >- getShell().setSize(newSize); >- } >- setStatus(selectedStatus.getStatus()); >- } >- >- private void initLabelProvider() { >- ITableLabelProvider provider = new ITableLabelProvider() { >- Map imageTable = new HashMap(); >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) >- */ >- public void addListener(ILabelProviderListener listener) { >- // Do nothing >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() >- */ >- public void dispose() { >- if (!imageTable.isEmpty()) { >- for (Iterator iter = imageTable.values().iterator(); iter >- .hasNext();) { >- Image image = (Image) iter.next(); >- image.dispose(); >- } >- } >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, >- * int) >- */ >- public Image getColumnImage(Object element, int columnIndex) { >- if (element != null) { >- Object extension = ((StatusInfo) element).getExtension(); >- if (extension != null && extension instanceof Job) { >- return getIcon((Job) extension); >- } >- } >- return null; >- } >- >- /* >- * Get the icon for the job. Code copied from NewProgressViewer >- */ >- private Image getIcon(Job job) { >- if (job != null) { >- >- Object property = job >- .getProperty(IProgressConstants.ICON_PROPERTY); >- >- // If we already have an image cached, return it >- Image im = (Image) imageTable.get(property); >- if (im != null) { >- return im; >- } >- >- // Create an image from the job's icon property or family >- Display display = getShell().getDisplay(); >- if (property instanceof ImageDescriptor) { >- im = ((ImageDescriptor) property).createImage(display); >- imageTable.put(property, im); // Cache for disposal >- } else if (property instanceof URL) { >- im = ImageDescriptor.createFromURL((URL) property) >- .createImage(display); >- imageTable.put(property, im); // Cache for disposal >- } else { >- im = ProgressManager.getInstance().getIconFor(job); >- // No need to cache since the progress manager will >- } >- return im; >- } >- return null; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, >- * int) >- */ >- public String getColumnText(Object element, int columnIndex) { >- return ((StatusInfo) element).getDisplayString(); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, >- * java.lang.String) >- */ >- public boolean isLabelProperty(Object element, String property) { >- return false; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) >- */ >- public void removeListener(ILabelProviderListener listener) { >- // Do nothing >- } >- }; >- statusListViewer.setLabelProvider(provider); >- } >- >- /** >- * Get the single selection. Return null if the selection is not just one >- * element. >- * >- * @return ErrorInfo or <code>null</code>. >- */ >- private StatusInfo getSingleSelection() { >- ISelection rawSelection = statusListViewer.getSelection(); >- if (rawSelection != null >- && rawSelection instanceof IStructuredSelection) { >- IStructuredSelection selection = (IStructuredSelection) rawSelection; >- if (selection.size() == 1) { >- return (StatusInfo) selection.getFirstElement(); >- } >- } >- return null; >- } >- >- public boolean close() { >- Rectangle shellPosition = getShell().getBounds(); >- boolean result = super.close(); >- ProgressManagerUtil.animateDown(shellPosition); >- return result; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.dialogs.Dialog#initializeBounds() >- */ >- protected void initializeBounds() { >- // We need to refesh here instead of in createContents >- // because the showDetailsArea requires that the content >- // composite be set >- refresh(); >- super.initializeBounds(); >- Rectangle shellPosition = getShell().getBounds(); >- ProgressManagerUtil.animateUp(shellPosition); >- } >- >- /** >- * The selection in the multiple job list has changed. Update widget >- * enablements and repopulate the list. >- */ >- void handleSelectionChange() { >- StatusInfo newSelection = getSingleSelection(); >- if (newSelection != null && newSelection != selectedStatus) { >- selectedStatus = newSelection; >- setStatus(selectedStatus.getStatus()); >- updateEnablements(); >- showDetailsArea(); >- } >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.dialogs.ErrorDialog#shouldShowDetailsButton() >- */ >- protected boolean shouldShowDetailsButton() { >- return true; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.dialogs.ErrorDialog#configureShell(org.eclipse.swt.widgets.Shell) >- */ >- protected void configureShell(Shell shell) { >- super.configureShell(shell); >- shell.addDisposeListener(new DisposeListener() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) >- */ >- public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { >- StatusNotificationManager.getInstance().dialogClosed(); >- } >- >- }); >- } >- >-} >Index: Eclipse UI/org/eclipse/ui/statushandlers/StatusNotificationManager.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/statushandlers/StatusNotificationManager.java >diff -N Eclipse UI/org/eclipse/ui/statushandlers/StatusNotificationManager.java >--- Eclipse UI/org/eclipse/ui/statushandlers/StatusNotificationManager.java 23 Feb 2007 13:26:00 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,415 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2004, 2006 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ui.statushandlers; >- >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.util.Collection; >-import java.util.Collections; >-import java.util.Date; >-import java.util.HashSet; >-import java.util.Iterator; >-import java.util.Set; >- >-import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Platform; >-import org.eclipse.core.runtime.Status; >-import org.eclipse.core.runtime.jobs.Job; >-import org.eclipse.jface.resource.ImageDescriptor; >-import org.eclipse.jface.resource.JFaceResources; >-import org.eclipse.osgi.util.NLS; >-import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.internal.Workbench; >-import org.eclipse.ui.internal.WorkbenchPlugin; >-import org.eclipse.ui.internal.progress.ProgressManagerUtil; >-import org.eclipse.ui.internal.progress.ProgressMessages; >-import org.eclipse.ui.progress.IProgressConstants; >-import org.eclipse.ui.progress.WorkbenchJob; >- >-import com.ibm.icu.text.DateFormat; >- >-/** >- * The StatusNotificationManager is the class that manages the display of status >- * information. >- */ >-public class StatusNotificationManager { >- >- private static final String ERROR_JOB = "errorstate.gif"; //$NON-NLS-1$ >- >- static final String ERROR_JOB_KEY = "ERROR_JOB"; //$NON-NLS-1$ >- >- private Collection errors = Collections.synchronizedSet(new HashSet()); >- >- private StatusDialog dialog; >- >- private static StatusNotificationManager sharedInstance; >- >- /** >- * Returns the shared instance. >- * >- * @return the shared instance >- */ >- public static StatusNotificationManager getInstance() { >- if (sharedInstance == null) { >- sharedInstance = new StatusNotificationManager(); >- } >- return sharedInstance; >- } >- >- /** >- * Create a new instance of the receiver. >- */ >- public StatusNotificationManager() { >- >- } >- >- /** >- * Set up any images the error management needs. >- * >- * @param iconsRoot >- * @throws MalformedURLException >- */ >- void setUpImages(URL iconsRoot) throws MalformedURLException { >- // TODO see ErrorNotificationManager - this method isn't currently used >- // In the ErrorNotificationManager it is invoked by ProgressManager >- JFaceResources.getImageRegistry().put(ERROR_JOB_KEY, >- ImageDescriptor.createFromURL(new URL(iconsRoot, ERROR_JOB))); >- } >- >- /** >- * Add a new error to the list for the supplied job. >- * >- * @param status >- */ >- void addError(IStatus status, Object extension) { >- StatusInfo errorInfo = new StatusInfo(status, extension); >- showError(errorInfo); >- } >- >- /** >- * Show the error in the error dialog. This is done from the UI thread to >- * ensure that no errors are dropped. >- * >- * @param statusInfo >- * the error to be displayed >- */ >- private void showError(final StatusInfo statusInfo) { >- >- if (!PlatformUI.isWorkbenchRunning()) { >- // we are shuttting down, so just log >- WorkbenchPlugin.log(statusInfo.getStatus()); >- return; >- } >- >- // We must open or update the error dialog in the UI thread to ensure >- // that errors are not dropped >- WorkbenchJob job = new WorkbenchJob( >- ProgressMessages.ErrorNotificationManager_OpenErrorDialogJob) { >- public IStatus runInUIThread(IProgressMonitor monitor) { >- >- // Add the error in the UI thread to ensure thread safety in the >- // dialog >- errors.add(statusInfo); >- if (dialog != null) { >- dialog.refresh(); >- } else if (Platform.isRunning()) { >- // Delay prompting if the job property is set >- Object noPromptProperty = null; >- Object extension = statusInfo.getExtension(); >- >- if (extension != null && extension instanceof Job) { >- noPromptProperty = ((Job) extension) >- .getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY); >- } >- >- boolean prompt = true; >- if (noPromptProperty instanceof Boolean) { >- prompt = !((Boolean) noPromptProperty).booleanValue(); >- } >- >- if (prompt) { >- return openErrorDialog(null /* use default title */, >- null /* use default message */, statusInfo); >- } >- } >- return Status.OK_STATUS; >- } >- }; >- job.setSystem(true); >- job.schedule(); >- } >- >- /** >- * Get the currently registered errors in the receiver. >- * >- * @return Collection of ErrorInfo >- */ >- Collection getErrors() { >- return errors; >- } >- >- /** >- * The job caleed jobName has just failed with status status. Open the error >- * dialog if possible - otherwise log the error. >- * >- * @param title >- * the title of the dialog or <code>null</code> >- * @param msg >- * the message for the dialog oe <code>null</code> >- * @param statusInfo >- * The info the dialog is being opened for. >- * @return IStatus >- */ >- private IStatus openErrorDialog(String title, String msg, >- final StatusInfo statusInfo) { >- IWorkbench workbench = PlatformUI.getWorkbench(); >- >- // Abort on shutdown >- if (workbench instanceof Workbench >- && ((Workbench) workbench).isClosing()) { >- return Status.CANCEL_STATUS; >- } >- dialog = new StatusDialog(ProgressManagerUtil.getDefaultParent(), >- title, msg, statusInfo, IStatus.OK | IStatus.INFO >- | IStatus.WARNING | IStatus.ERROR); >- >- dialog.open(); >- return Status.OK_STATUS; >- } >- >- /** >- * TODO unused !!! >- * >- * Remove all of the errors supplied from the list of errors. >- * >- * @param errorsToRemove >- * Collection of ErrorInfo >- */ >- void removeErrors(Collection errorsToRemove) { >- errors.removeAll(errorsToRemove); >- removeFromFinishedJobs(errorsToRemove); >- } >- >- /** >- * Remove all of the errors from the finished jobs >- * >- * @param errorsToRemove >- * The ErrorInfos that will be deleted. >- */ >- private void removeFromFinishedJobs(Collection errorsToRemove) { >- Iterator errorIterator = errorsToRemove.iterator(); >- Set errorStatuses = new HashSet(); >- while (errorIterator.hasNext()) { >- StatusInfo next = (StatusInfo) errorIterator.next(); >- errorStatuses.add(next.getStatus()); >- } >- >- // TODO those classes have default access modifier :/ >- // finished jobs are removed when the dialog is shown >- // also - job removal wasn't used in the old workencherrorhandler >- >- // JobTreeElement[] infos = FinishedJobs.getInstance().getJobInfos(); >- // for (int i = 0; i < infos.length; i++) { >- // if (infos[i].isJobInfo()) { >- // JobInfo info = (JobInfo) infos[i]; >- // if (errorStatuses.contains(info.getJob().getResult())) { >- // FinishedJobs.getInstance().remove(info); >- // } >- // } >- // } >- >- } >- >- /** >- * Clear all of the errors held onto by the receiver. >- */ >- private void clearAllErrors() { >- removeFromFinishedJobs(errors); >- errors.clear(); >- } >- >- /** >- * Display the error for the given job and any other errors that have been >- * accumulated. This method must be invoked from the UI thread. >- * >- * @param job >- * the job whose error should be displayed >- * @param title >- * The title for the dialog >- * @param msg >- * The message for the dialog. >- * @return <code>true</code> if the info for the job was found and the >- * error displayed and <code>false</code> otherwise. >- */ >- public boolean showErrorFor(Job job, String title, String msg) { >- if (dialog != null) { >- // The dialog is already open so the error is being displayed >- return true; >- } >- StatusInfo info = null; >- if (job == null) { >- info = getMostRecentJobError(); >- } else { >- info = getErrorInfo(job); >- } >- if (info != null) { >- openErrorDialog(title, msg, info); >- return true; >- } >- return false; >- } >- >- /* >- * Return the most recent error. >- */ >- private StatusInfo getMostRecentJobError() { >- StatusInfo mostRecentInfo = null; >- for (Iterator iter = errors.iterator(); iter.hasNext();) { >- StatusInfo info = (StatusInfo) iter.next(); >- if ((mostRecentInfo == null || info.getTimestamp() > mostRecentInfo >- .getTimestamp()) >- && info.getExtension() != null >- && info.getExtension() instanceof Job) { >- mostRecentInfo = info; >- } >- } >- return mostRecentInfo; >- } >- >- /* >- * Return the error info for the given job >- */ >- private StatusInfo getErrorInfo(Job job) { >- for (Iterator iter = errors.iterator(); iter.hasNext();) { >- StatusInfo info = (StatusInfo) iter.next(); >- if (info.getExtension() == job) { >- return info; >- } >- } >- return null; >- } >- >- /** >- * Return whether the manager has errors to report. >- * >- * @return whether the manager has errors to report >- */ >- public boolean hasErrors() { >- return !errors.isEmpty(); >- } >- >- /** >- * The error dialog has been closed. Clear the list of errors and the stored >- * dialog. >- */ >- public void dialogClosed() { >- dialog = null; >- clearAllErrors(); >- } >- >- /** >- * A wrapper class for statuses displayed in the dialog. >- * >- */ >- protected static class StatusInfo implements Comparable { >- >- private final IStatus status; >- >- private final long timestamp; >- >- private final Object extension; >- >- /** >- * Constructs a simple <code>StatusInfo</code>, without any >- * extensions. >- * >- * @param status >- * the root status for this status info >- */ >- public StatusInfo(IStatus status) { >- this(status, null); >- } >- >- /** >- * Constructs a <code>StatusInfo</code> with a extension (used to >- * retrieve extra properties). >- * >- * @param status >- * the root status for this status info >- * @param extension >- * the extension >- */ >- public StatusInfo(IStatus status, Object extension) { >- this.status = status; >- timestamp = System.currentTimeMillis(); >- this.extension = extension; >- } >- >- String getDisplayString() { >- String text = status.getMessage(); >- if (this.extension != null && this.extension instanceof Job) { >- text = ((Job) extension).getName(); >- } >- >- return NLS.bind(ProgressMessages.JobInfo_Error, (new Object[] { >- text, >- DateFormat.getDateTimeInstance(DateFormat.LONG, >- DateFormat.LONG).format(new Date(timestamp)) })); >- } >- >- /** >- * Time when this status info was created. >- * >- * @return the time >- */ >- public long getTimestamp() { >- return timestamp; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see java.lang.Comparable#compareTo(T) >- */ >- public int compareTo(Object arg0) { >- if (arg0 instanceof StatusInfo) { >- // Order ErrorInfo by time received >- long otherTimestamp = ((StatusInfo) arg0).timestamp; >- if (timestamp < otherTimestamp) { >- return -1; >- } else if (timestamp > otherTimestamp) { >- return 1; >- } else { >- return getDisplayString().compareTo( >- ((StatusInfo) arg0).getDisplayString()); >- } >- } >- return 0; >- } >- >- /** >- * @return Returns the status. >- */ >- public IStatus getStatus() { >- return status; >- } >- >- /** >- * @return Returns the extension. >- */ >- public Object getExtension() { >- return extension; >- } >- >- } >-} >Index: Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java,v >retrieving revision 1.3 >diff -u -r1.3 WorkbenchErrorHandler.java >--- Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java 5 Feb 2007 14:59:17 -0000 1.3 >+++ Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java 26 Feb 2007 13:32:43 -0000 >@@ -13,6 +13,7 @@ > > import org.eclipse.ui.application.WorkbenchAdvisor; > import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.internal.statushandlers.StatusNotificationManager; > > /** > * This is a default workbench error handler. The instance of this handler is >Index: Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusDialog.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusDialog.java >diff -N Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,560 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.statushandlers; >+ >+import java.net.URL; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.MessageDialogWithToggle; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.viewers.IContentProvider; >+import org.eclipse.jface.viewers.ILabelProviderListener; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.ITableLabelProvider; >+import org.eclipse.jface.viewers.SelectionChangedEvent; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.TableViewer; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerComparator; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.internal.progress.ProgressManager; >+import org.eclipse.ui.internal.progress.ProgressManagerUtil; >+import org.eclipse.ui.internal.progress.ProgressMessages; >+import org.eclipse.ui.internal.statushandlers.StatusNotificationManager.StatusInfo; >+import org.eclipse.ui.progress.IProgressConstants; >+ >+/** >+ * A dialog for displaying >+ * >+ */ >+public class StatusDialog extends ErrorDialog { >+ >+ /* >+ * Preference used to indicate whether the user should be prompted to >+ * confirm the execution of the job's goto action >+ */ >+ private static final String PREF_SKIP_GOTO_ACTION_PROMPT = "pref_skip_goto_action_prompt"; //$NON-NLS-1$ >+ >+ /* >+ * The id of the goto action button >+ */ >+ private static final int GOTO_ACTION_ID = IDialogConstants.CLIENT_ID + 1; >+ >+ private TableViewer statusListViewer; >+ >+ private StatusInfo selectedStatus; >+ >+ /** >+ * Create a new instance of the receiver. >+ * >+ * @param parentShell >+ * @param title >+ * @param msg >+ * @param statusInfo >+ * @param displayMask >+ */ >+ public StatusDialog(Shell parentShell, String title, String msg, >+ StatusInfo statusInfo, int displayMask) { >+ super(parentShell, (title == null ? statusInfo.getStatus().getMessage() >+ : title), msg, statusInfo.getStatus(), displayMask); >+ setShellStyle(SWT.RESIZE | SWT.MIN | getShellStyle()); >+ this.selectedStatus = statusInfo; >+ setBlockOnOpen(false); >+ } >+ >+ /** >+ * Method which should be invoked when new errors become available for >+ * display >+ */ >+ void refresh() { >+ >+ if (AUTOMATED_MODE) { >+ return; >+ } >+ >+ // Do not refresh if we are in the process of >+ // opening or shutting down >+ if (dialogArea == null || dialogArea.isDisposed()) { >+ return; >+ } >+ >+ if (isMultipleStatusDialog()) { >+ if (statusListViewer == null) { >+ // The job list doesn't exist so create it. >+ setMessage(ProgressMessages.JobErrorDialog_MultipleErrorsMessage); >+ getShell().setText( >+ ProgressMessages.JobErrorDialog_MultipleErrorsTitle); >+ createStatusListArea((Composite) dialogArea); >+ showDetailsArea(); >+ } >+ refreshStatusList(); >+ } >+ updateEnablements(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.ErrorDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ IAction gotoAction = getGotoAction(); >+ String text = null; >+ if (gotoAction != null) { >+ text = gotoAction.getText(); >+ } >+ if (text == null) { >+ // Text is set to this initiallybut will be changed for active job >+ text = ProgressMessages.JobErrorDialog_CustomJobText; >+ } >+ createButton(parent, GOTO_ACTION_ID, text, false); >+ super.createButtonsForButtonBar(parent); >+ } >+ >+ /* >+ * Update the button enablements >+ */ >+ private void updateEnablements() { >+ Button details = getButton(IDialogConstants.DETAILS_ID); >+ if (details != null) { >+ details.setEnabled(selectedStatus.getStatus().isMultiStatus() >+ || isMultipleStatusDialog()); >+ } >+ Button gotoButton = getButton(GOTO_ACTION_ID); >+ if (gotoButton != null) { >+ IAction gotoAction = getGotoAction(); >+ boolean hasValidGotoAction = gotoAction != null; >+ String text = gotoButton.getText(); >+ String newText = null; >+ if (hasValidGotoAction) { >+ newText = gotoAction.getText(); >+ } >+ if (newText == null) { >+ hasValidGotoAction = false; >+ newText = ProgressMessages.JobErrorDialog_CustomJobText; >+ } >+ if (!newText.equals(text)) { >+ gotoButton.setText(newText); >+ } >+ gotoButton.setEnabled(hasValidGotoAction); >+ gotoButton.setVisible(hasValidGotoAction); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int) >+ */ >+ protected void buttonPressed(int id) { >+ if (id == GOTO_ACTION_ID) { >+ IAction gotoAction = getGotoAction(); >+ if (gotoAction != null) { >+ if (!isMultipleStatusDialog() || isPromptToClose()) { >+ okPressed(); // close the dialog >+ gotoAction.run(); // run the goto action >+ } >+ } >+ } >+ super.buttonPressed(id); >+ } >+ >+ /* >+ * Prompt to inform the user that the dialog will close and the errors >+ * cleared. >+ */ >+ private boolean isPromptToClose() { >+ IPreferenceStore store = WorkbenchPlugin.getDefault() >+ .getPreferenceStore(); >+ if (!store.contains(PREF_SKIP_GOTO_ACTION_PROMPT) >+ || !store.getString(PREF_SKIP_GOTO_ACTION_PROMPT).equals( >+ MessageDialogWithToggle.ALWAYS)) { >+ MessageDialogWithToggle dialog = MessageDialogWithToggle >+ .openOkCancelConfirm( >+ getShell(), >+ ProgressMessages.JobErrorDialog_CloseDialogTitle, >+ ProgressMessages.JobErrorDialog_CloseDialogMessage, >+ ProgressMessages.JobErrorDialog_DoNotShowAgainMessage, >+ false, store, PREF_SKIP_GOTO_ACTION_PROMPT); >+ return dialog.getReturnCode() == OK; >+ } >+ return true; >+ } >+ >+ private IAction getGotoAction() { >+ >+ Object extension = selectedStatus.getExtension(); >+ Object property = null; >+ >+ if (extension != null && extension instanceof Job) { >+ property = ((Job) extension) >+ .getProperty(IProgressConstants.ACTION_PROPERTY); >+ } >+ >+ if (property instanceof IAction) { >+ return (IAction) property; >+ } >+ return null; >+ } >+ >+ /** >+ * This method sets the message in the message label. >+ * >+ * @param messageString - >+ * the String for the message area >+ */ >+ private void setMessage(String messageString) { >+ // must not set null text in a label >+ message = messageString == null ? "" : messageString; //$NON-NLS-1$ >+ if (messageLabel == null || messageLabel.isDisposed()) { >+ return; >+ } >+ messageLabel.setText(message); >+ } >+ >+ /** >+ * Create an area that allow the user to select one of multiple jobs that >+ * have reported errors >+ * >+ * @param parent - >+ * the parent of the area >+ */ >+ private void createStatusListArea(Composite parent) { >+ // Display a list of jobs that have reported errors >+ statusListViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL >+ | SWT.V_SCROLL | SWT.BORDER); >+ statusListViewer.setComparator(getViewerComparator()); >+ Control control = statusListViewer.getControl(); >+ GridData data = new GridData(GridData.FILL_BOTH >+ | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); >+ data.heightHint = convertHeightInCharsToPixels(10); >+ control.setLayoutData(data); >+ initContentProvider(); >+ initLabelProvider(); >+ statusListViewer >+ .addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ handleSelectionChange(); >+ } >+ }); >+ applyDialogFont(parent); >+ } >+ >+ /* >+ * Return whether there are multiple errors to be displayed >+ */ >+ private boolean isMultipleStatusDialog() { >+ return getManager().getErrors().size() > 1; >+ } >+ >+ /* >+ * Get the notificationManager that this is being created for. >+ */ >+ private StatusNotificationManager getManager() { >+ return StatusNotificationManager.getInstance(); >+ } >+ >+ /** >+ * Return the selected error info. >+ * >+ * @return ErrorInfo >+ */ >+ public StatusInfo getSelectedError() { >+ return selectedStatus; >+ } >+ >+ /** >+ * Return a viewer sorter for looking at the jobs. >+ * >+ * @return ViewerSorter >+ */ >+ private ViewerComparator getViewerComparator() { >+ return new ViewerComparator() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, >+ * java.lang.Object, java.lang.Object) >+ */ >+ public int compare(Viewer testViewer, Object e1, Object e2) { >+ return ((Comparable) e1).compareTo(e2); >+ } >+ }; >+ } >+ >+ /** >+ * Sets the content provider for the viewer. >+ */ >+ protected void initContentProvider() { >+ IContentProvider provider = new IStructuredContentProvider() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IContentProvider#dispose() >+ */ >+ public void dispose() { >+ // Nothing of interest here >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) >+ */ >+ public Object[] getElements(Object inputElement) { >+ return getManager().getErrors().toArray(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, >+ * java.lang.Object, java.lang.Object) >+ */ >+ public void inputChanged(Viewer viewer, Object oldInput, >+ Object newInput) { >+ if (newInput != null) { >+ refreshStatusList(); >+ } >+ } >+ }; >+ statusListViewer.setContentProvider(provider); >+ statusListViewer.setInput(getManager()); >+ statusListViewer.setSelection(new StructuredSelection(selectedStatus)); >+ } >+ >+ /** >+ * Refresh the contents of the viewer. >+ */ >+ void refreshStatusList() { >+ if (statusListViewer != null >+ && !statusListViewer.getControl().isDisposed()) { >+ statusListViewer.refresh(); >+ Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); >+ getShell().setSize(newSize); >+ } >+ setStatus(selectedStatus.getStatus()); >+ } >+ >+ private void initLabelProvider() { >+ ITableLabelProvider provider = new ITableLabelProvider() { >+ Map imageTable = new HashMap(); >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) >+ */ >+ public void addListener(ILabelProviderListener listener) { >+ // Do nothing >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() >+ */ >+ public void dispose() { >+ if (!imageTable.isEmpty()) { >+ for (Iterator iter = imageTable.values().iterator(); iter >+ .hasNext();) { >+ Image image = (Image) iter.next(); >+ image.dispose(); >+ } >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, >+ * int) >+ */ >+ public Image getColumnImage(Object element, int columnIndex) { >+ if (element != null) { >+ Object extension = ((StatusInfo) element).getExtension(); >+ if (extension != null && extension instanceof Job) { >+ return getIcon((Job) extension); >+ } >+ } >+ return null; >+ } >+ >+ /* >+ * Get the icon for the job. Code copied from NewProgressViewer >+ */ >+ private Image getIcon(Job job) { >+ if (job != null) { >+ >+ Object property = job >+ .getProperty(IProgressConstants.ICON_PROPERTY); >+ >+ // If we already have an image cached, return it >+ Image im = (Image) imageTable.get(property); >+ if (im != null) { >+ return im; >+ } >+ >+ // Create an image from the job's icon property or family >+ Display display = getShell().getDisplay(); >+ if (property instanceof ImageDescriptor) { >+ im = ((ImageDescriptor) property).createImage(display); >+ imageTable.put(property, im); // Cache for disposal >+ } else if (property instanceof URL) { >+ im = ImageDescriptor.createFromURL((URL) property) >+ .createImage(display); >+ imageTable.put(property, im); // Cache for disposal >+ } else { >+ im = ProgressManager.getInstance().getIconFor(job); >+ // No need to cache since the progress manager will >+ } >+ return im; >+ } >+ return null; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, >+ * int) >+ */ >+ public String getColumnText(Object element, int columnIndex) { >+ return ((StatusInfo) element).getDisplayString(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, >+ * java.lang.String) >+ */ >+ public boolean isLabelProperty(Object element, String property) { >+ return false; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) >+ */ >+ public void removeListener(ILabelProviderListener listener) { >+ // Do nothing >+ } >+ }; >+ statusListViewer.setLabelProvider(provider); >+ } >+ >+ /** >+ * Get the single selection. Return null if the selection is not just one >+ * element. >+ * >+ * @return ErrorInfo or <code>null</code>. >+ */ >+ private StatusInfo getSingleSelection() { >+ ISelection rawSelection = statusListViewer.getSelection(); >+ if (rawSelection != null >+ && rawSelection instanceof IStructuredSelection) { >+ IStructuredSelection selection = (IStructuredSelection) rawSelection; >+ if (selection.size() == 1) { >+ return (StatusInfo) selection.getFirstElement(); >+ } >+ } >+ return null; >+ } >+ >+ public boolean close() { >+ Rectangle shellPosition = getShell().getBounds(); >+ boolean result = super.close(); >+ ProgressManagerUtil.animateDown(shellPosition); >+ return result; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.Dialog#initializeBounds() >+ */ >+ protected void initializeBounds() { >+ // We need to refesh here instead of in createContents >+ // because the showDetailsArea requires that the content >+ // composite be set >+ refresh(); >+ super.initializeBounds(); >+ Rectangle shellPosition = getShell().getBounds(); >+ ProgressManagerUtil.animateUp(shellPosition); >+ } >+ >+ /** >+ * The selection in the multiple job list has changed. Update widget >+ * enablements and repopulate the list. >+ */ >+ void handleSelectionChange() { >+ StatusInfo newSelection = getSingleSelection(); >+ if (newSelection != null && newSelection != selectedStatus) { >+ selectedStatus = newSelection; >+ setStatus(selectedStatus.getStatus()); >+ updateEnablements(); >+ showDetailsArea(); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.ErrorDialog#shouldShowDetailsButton() >+ */ >+ protected boolean shouldShowDetailsButton() { >+ return true; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.ErrorDialog#configureShell(org.eclipse.swt.widgets.Shell) >+ */ >+ protected void configureShell(Shell shell) { >+ super.configureShell(shell); >+ shell.addDisposeListener(new DisposeListener() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) >+ */ >+ public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { >+ StatusNotificationManager.getInstance().dialogClosed(); >+ } >+ >+ }); >+ } >+ >+} >Index: Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusNotificationManager.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusNotificationManager.java >diff -N Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusNotificationManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/statushandlers/StatusNotificationManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,415 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.statushandlers; >+ >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.util.Collection; >+import java.util.Collections; >+import java.util.Date; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.internal.Workbench; >+import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.internal.progress.ProgressManagerUtil; >+import org.eclipse.ui.internal.progress.ProgressMessages; >+import org.eclipse.ui.progress.IProgressConstants; >+import org.eclipse.ui.progress.WorkbenchJob; >+ >+import com.ibm.icu.text.DateFormat; >+ >+/** >+ * The StatusNotificationManager is the class that manages the display of status >+ * information. >+ */ >+public class StatusNotificationManager { >+ >+ private static final String ERROR_JOB = "errorstate.gif"; //$NON-NLS-1$ >+ >+ static final String ERROR_JOB_KEY = "ERROR_JOB"; //$NON-NLS-1$ >+ >+ private Collection errors = Collections.synchronizedSet(new HashSet()); >+ >+ private StatusDialog dialog; >+ >+ private static StatusNotificationManager sharedInstance; >+ >+ /** >+ * Returns the shared instance. >+ * >+ * @return the shared instance >+ */ >+ public static StatusNotificationManager getInstance() { >+ if (sharedInstance == null) { >+ sharedInstance = new StatusNotificationManager(); >+ } >+ return sharedInstance; >+ } >+ >+ /** >+ * Create a new instance of the receiver. >+ */ >+ public StatusNotificationManager() { >+ >+ } >+ >+ /** >+ * Set up any images the error management needs. >+ * >+ * @param iconsRoot >+ * @throws MalformedURLException >+ */ >+ void setUpImages(URL iconsRoot) throws MalformedURLException { >+ // TODO see ErrorNotificationManager - this method isn't currently used >+ // In the ErrorNotificationManager it is invoked by ProgressManager >+ JFaceResources.getImageRegistry().put(ERROR_JOB_KEY, >+ ImageDescriptor.createFromURL(new URL(iconsRoot, ERROR_JOB))); >+ } >+ >+ /** >+ * Add a new error to the list for the supplied job. >+ * >+ * @param status >+ */ >+ public void addError(IStatus status, Object extension) { >+ StatusInfo errorInfo = new StatusInfo(status, extension); >+ showError(errorInfo); >+ } >+ >+ /** >+ * Show the error in the error dialog. This is done from the UI thread to >+ * ensure that no errors are dropped. >+ * >+ * @param statusInfo >+ * the error to be displayed >+ */ >+ private void showError(final StatusInfo statusInfo) { >+ >+ if (!PlatformUI.isWorkbenchRunning()) { >+ // we are shuttting down, so just log >+ WorkbenchPlugin.log(statusInfo.getStatus()); >+ return; >+ } >+ >+ // We must open or update the error dialog in the UI thread to ensure >+ // that errors are not dropped >+ WorkbenchJob job = new WorkbenchJob( >+ ProgressMessages.ErrorNotificationManager_OpenErrorDialogJob) { >+ public IStatus runInUIThread(IProgressMonitor monitor) { >+ >+ // Add the error in the UI thread to ensure thread safety in the >+ // dialog >+ errors.add(statusInfo); >+ if (dialog != null) { >+ dialog.refresh(); >+ } else if (Platform.isRunning()) { >+ // Delay prompting if the job property is set >+ Object noPromptProperty = null; >+ Object extension = statusInfo.getExtension(); >+ >+ if (extension != null && extension instanceof Job) { >+ noPromptProperty = ((Job) extension) >+ .getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY); >+ } >+ >+ boolean prompt = true; >+ if (noPromptProperty instanceof Boolean) { >+ prompt = !((Boolean) noPromptProperty).booleanValue(); >+ } >+ >+ if (prompt) { >+ return openErrorDialog(null /* use default title */, >+ null /* use default message */, statusInfo); >+ } >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ job.setSystem(true); >+ job.schedule(); >+ } >+ >+ /** >+ * Get the currently registered errors in the receiver. >+ * >+ * @return Collection of ErrorInfo >+ */ >+ Collection getErrors() { >+ return errors; >+ } >+ >+ /** >+ * The job caleed jobName has just failed with status status. Open the error >+ * dialog if possible - otherwise log the error. >+ * >+ * @param title >+ * the title of the dialog or <code>null</code> >+ * @param msg >+ * the message for the dialog oe <code>null</code> >+ * @param statusInfo >+ * The info the dialog is being opened for. >+ * @return IStatus >+ */ >+ private IStatus openErrorDialog(String title, String msg, >+ final StatusInfo statusInfo) { >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ >+ // Abort on shutdown >+ if (workbench instanceof Workbench >+ && ((Workbench) workbench).isClosing()) { >+ return Status.CANCEL_STATUS; >+ } >+ dialog = new StatusDialog(ProgressManagerUtil.getDefaultParent(), >+ title, msg, statusInfo, IStatus.OK | IStatus.INFO >+ | IStatus.WARNING | IStatus.ERROR); >+ >+ dialog.open(); >+ return Status.OK_STATUS; >+ } >+ >+ /** >+ * TODO unused !!! >+ * >+ * Remove all of the errors supplied from the list of errors. >+ * >+ * @param errorsToRemove >+ * Collection of ErrorInfo >+ */ >+ void removeErrors(Collection errorsToRemove) { >+ errors.removeAll(errorsToRemove); >+ removeFromFinishedJobs(errorsToRemove); >+ } >+ >+ /** >+ * Remove all of the errors from the finished jobs >+ * >+ * @param errorsToRemove >+ * The ErrorInfos that will be deleted. >+ */ >+ private void removeFromFinishedJobs(Collection errorsToRemove) { >+ Iterator errorIterator = errorsToRemove.iterator(); >+ Set errorStatuses = new HashSet(); >+ while (errorIterator.hasNext()) { >+ StatusInfo next = (StatusInfo) errorIterator.next(); >+ errorStatuses.add(next.getStatus()); >+ } >+ >+ // TODO those classes have default access modifier :/ >+ // finished jobs are removed when the dialog is shown >+ // also - job removal wasn't used in the old workencherrorhandler >+ >+ // JobTreeElement[] infos = FinishedJobs.getInstance().getJobInfos(); >+ // for (int i = 0; i < infos.length; i++) { >+ // if (infos[i].isJobInfo()) { >+ // JobInfo info = (JobInfo) infos[i]; >+ // if (errorStatuses.contains(info.getJob().getResult())) { >+ // FinishedJobs.getInstance().remove(info); >+ // } >+ // } >+ // } >+ >+ } >+ >+ /** >+ * Clear all of the errors held onto by the receiver. >+ */ >+ private void clearAllErrors() { >+ removeFromFinishedJobs(errors); >+ errors.clear(); >+ } >+ >+ /** >+ * Display the error for the given job and any other errors that have been >+ * accumulated. This method must be invoked from the UI thread. >+ * >+ * @param job >+ * the job whose error should be displayed >+ * @param title >+ * The title for the dialog >+ * @param msg >+ * The message for the dialog. >+ * @return <code>true</code> if the info for the job was found and the >+ * error displayed and <code>false</code> otherwise. >+ */ >+ public boolean showErrorFor(Job job, String title, String msg) { >+ if (dialog != null) { >+ // The dialog is already open so the error is being displayed >+ return true; >+ } >+ StatusInfo info = null; >+ if (job == null) { >+ info = getMostRecentJobError(); >+ } else { >+ info = getErrorInfo(job); >+ } >+ if (info != null) { >+ openErrorDialog(title, msg, info); >+ return true; >+ } >+ return false; >+ } >+ >+ /* >+ * Return the most recent error. >+ */ >+ private StatusInfo getMostRecentJobError() { >+ StatusInfo mostRecentInfo = null; >+ for (Iterator iter = errors.iterator(); iter.hasNext();) { >+ StatusInfo info = (StatusInfo) iter.next(); >+ if ((mostRecentInfo == null || info.getTimestamp() > mostRecentInfo >+ .getTimestamp()) >+ && info.getExtension() != null >+ && info.getExtension() instanceof Job) { >+ mostRecentInfo = info; >+ } >+ } >+ return mostRecentInfo; >+ } >+ >+ /* >+ * Return the error info for the given job >+ */ >+ private StatusInfo getErrorInfo(Job job) { >+ for (Iterator iter = errors.iterator(); iter.hasNext();) { >+ StatusInfo info = (StatusInfo) iter.next(); >+ if (info.getExtension() == job) { >+ return info; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * Return whether the manager has errors to report. >+ * >+ * @return whether the manager has errors to report >+ */ >+ public boolean hasErrors() { >+ return !errors.isEmpty(); >+ } >+ >+ /** >+ * The error dialog has been closed. Clear the list of errors and the stored >+ * dialog. >+ */ >+ public void dialogClosed() { >+ dialog = null; >+ clearAllErrors(); >+ } >+ >+ /** >+ * A wrapper class for statuses displayed in the dialog. >+ * >+ */ >+ protected static class StatusInfo implements Comparable { >+ >+ private final IStatus status; >+ >+ private final long timestamp; >+ >+ private final Object extension; >+ >+ /** >+ * Constructs a simple <code>StatusInfo</code>, without any >+ * extensions. >+ * >+ * @param status >+ * the root status for this status info >+ */ >+ public StatusInfo(IStatus status) { >+ this(status, null); >+ } >+ >+ /** >+ * Constructs a <code>StatusInfo</code> with a extension (used to >+ * retrieve extra properties). >+ * >+ * @param status >+ * the root status for this status info >+ * @param extension >+ * the extension >+ */ >+ public StatusInfo(IStatus status, Object extension) { >+ this.status = status; >+ timestamp = System.currentTimeMillis(); >+ this.extension = extension; >+ } >+ >+ String getDisplayString() { >+ String text = status.getMessage(); >+ if (this.extension != null && this.extension instanceof Job) { >+ text = ((Job) extension).getName(); >+ } >+ >+ return NLS.bind(ProgressMessages.JobInfo_Error, (new Object[] { >+ text, >+ DateFormat.getDateTimeInstance(DateFormat.LONG, >+ DateFormat.LONG).format(new Date(timestamp)) })); >+ } >+ >+ /** >+ * Time when this status info was created. >+ * >+ * @return the time >+ */ >+ public long getTimestamp() { >+ return timestamp; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see java.lang.Comparable#compareTo(T) >+ */ >+ public int compareTo(Object arg0) { >+ if (arg0 instanceof StatusInfo) { >+ // Order ErrorInfo by time received >+ long otherTimestamp = ((StatusInfo) arg0).timestamp; >+ if (timestamp < otherTimestamp) { >+ return -1; >+ } else if (timestamp > otherTimestamp) { >+ return 1; >+ } else { >+ return getDisplayString().compareTo( >+ ((StatusInfo) arg0).getDisplayString()); >+ } >+ } >+ return 0; >+ } >+ >+ /** >+ * @return Returns the status. >+ */ >+ public IStatus getStatus() { >+ return status; >+ } >+ >+ /** >+ * @return Returns the extension. >+ */ >+ public Object getExtension() { >+ return extension; >+ } >+ >+ } >+}
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 175236
: 59782