Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 242821
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java (-14 / +61 lines)
Lines 41-46 Link Here
41
import org.eclipse.jface.resource.ResourceManager;
41
import org.eclipse.jface.resource.ResourceManager;
42
import org.eclipse.jface.util.Policy;
42
import org.eclipse.jface.util.Policy;
43
import org.eclipse.jface.viewers.IContentProvider;
43
import org.eclipse.jface.viewers.IContentProvider;
44
import org.eclipse.jface.viewers.ILabelDecorator;
44
import org.eclipse.jface.viewers.ILabelProviderListener;
45
import org.eclipse.jface.viewers.ILabelProviderListener;
45
import org.eclipse.jface.viewers.ISelection;
46
import org.eclipse.jface.viewers.ISelection;
46
import org.eclipse.jface.viewers.ISelectionChangedListener;
47
import org.eclipse.jface.viewers.ISelectionChangedListener;
Lines 1095-1100 Link Here
1095
	 * Header area.
1096
	 * Header area.
1096
	 */
1097
	 */
1097
	private Composite titleArea;
1098
	private Composite titleArea;
1099
	
1100
	private ILabelDecorator messageDecorator;
1098
1101
1099
	/**
1102
	/**
1100
	 * Creates workbench status dialog.
1103
	 * Creates workbench status dialog.
Lines 1667-1680 Link Here
1667
		if (property instanceof String) {
1670
		if (property instanceof String) {
1668
			String header = (String) property;
1671
			String header = (String) property;
1669
			if (header.trim().length() > 0) {
1672
			if (header.trim().length() > 0) {
1670
				return header;
1673
				return decorate(header, statusAdapter);
1671
			}
1674
			}
1672
		}
1675
		}
1673
		// if there was message set in the status
1676
		// if there was message set in the status
1674
		IStatus status = statusAdapter.getStatus();
1677
		IStatus status = statusAdapter.getStatus();
1675
		if (status.getMessage() != null
1678
		if (status.getMessage() != null
1676
				&& status.getMessage().trim().length() > 0) {
1679
				&& status.getMessage().trim().length() > 0) {
1677
			return status.getMessage();
1680
			return decorate(status.getMessage(), statusAdapter);
1678
		}
1681
		}
1679
1682
1680
		// if status has children
1683
		// if status has children
Lines 1686-1694 Link Here
1686
		Throwable t = status.getException();
1689
		Throwable t = status.getException();
1687
		if (t != null) {
1690
		if (t != null) {
1688
			if (t.getMessage() != null && t.getMessage().trim().length() > 0) {
1691
			if (t.getMessage() != null && t.getMessage().trim().length() > 0) {
1689
				return t.getMessage();
1692
				return decorate(t.getMessage(), statusAdapter);
1690
			}
1693
			}
1691
			return t.getClass().getName();
1694
			return decorate(t.getClass().getName(), statusAdapter);
1692
		}
1695
		}
1693
		return WorkbenchMessages.WorkbenchStatusDialog_ProblemOccurred;
1696
		return WorkbenchMessages.WorkbenchStatusDialog_ProblemOccurred;
1694
	}
1697
	}
Lines 1719-1744 Link Here
1719
1722
1720
		// if there was message set in the status
1723
		// if there was message set in the status
1721
		IStatus status = statusAdapter.getStatus();
1724
		IStatus status = statusAdapter.getStatus();
1722
		if (status.getMessage() != null
1725
		String message = status.getMessage();
1723
				&& status.getMessage().trim().length() > 0
1726
		String decoratedMessage = message == null ? null : decorate(message,
1724
				&& !primary.equals(status.getMessage())) { // we have not
1727
				statusAdapter);
1725
			// displayed it yet
1728
		if (message != null && message.trim().length() > 0
1726
			return status.getMessage();
1729
				&& !primary.equals(decoratedMessage)) { 
1730
			/* we have not displayed it yet */
1731
			return decoratedMessage;
1727
		}
1732
		}
1728
		// if status has children
1733
		// if status has children
1729
		if (status.getChildren().length > 0
1734
		if (status.getChildren().length > 0
1730
				&& !primary.equals(status.getMessage())) {
1735
				&& !primary.equals(decoratedMessage)) {
1731
			return WorkbenchMessages.WorkbenchStatusDialog_StatusWithChildren;
1736
			return WorkbenchMessages.WorkbenchStatusDialog_StatusWithChildren;
1732
		}
1737
		}
1733
1738
1734
		// check the exception
1739
		// check the exception
1735
		Throwable t = status.getException();
1740
		Throwable t = status.getException();
1736
		if (t != null) {
1741
		if (t != null) {
1737
			if (t.getMessage() != null && t.getMessage().trim().length() > 0
1742
			if (t.getMessage() != null) {
1738
					&& !primary.equals(t.getMessage())) {
1743
				String decoratedThrowable = decorate(t.getMessage(),
1739
				return t.getMessage();
1744
						statusAdapter);
1745
				if (t.getMessage().trim().length() > 0
1746
						&& !primary.equals(decoratedThrowable)) {
1747
					return decoratedThrowable;
1748
				}
1740
			}
1749
			}
1741
			String throwableName = t.getClass().getName();
1750
			String throwableName = decorate(t.getClass().getName(), statusAdapter);
1742
			if (!primary.equals(throwableName)) {
1751
			if (!primary.equals(throwableName)) {
1743
				return throwableName;
1752
				return throwableName;
1744
			}
1753
			}
Lines 2289-2292 Link Here
2289
			return null;
2298
			return null;
2290
		return this.dialog.getShell();
2299
		return this.dialog.getShell();
2291
	}
2300
	}
2301
2302
	/**
2303
	 * <p>
2304
	 * This methods sets up the decorator, which is used to modify displayed
2305
	 * strings extracted from StatusAdapter. The decorator should be used to
2306
	 * remove technical codes from the dialog, f.e. following message
2307
	 * "<i>ERR2008 Invalid password</i>" can be translated into
2308
	 * "<i>Invalid password</i>".
2309
	 * </p>
2310
	 * <p>
2311
	 * The decorator will be applied only to messages extracted from
2312
	 * StatusAdapter (predefined messages like
2313
	 * "This status has children statuses. See 'Details' for more information."
2314
	 * are not affected.
2315
	 * </p>
2316
	 * <p>
2317
	 * This method should not be used together with
2318
	 * {@link #setStatusListLabelProvider(ITableLabelProvider)}.
2319
	 * </p>
2320
	 * 
2321
	 * @param decorator
2322
	 *            - the decorator to be set. Only
2323
	 *            {@link ILabelDecorator#decorateText(String, Object)} method
2324
	 *            will be used. This method should return <code>null</code> if
2325
	 *            and only if the first argument is null. StatusAdapter is
2326
	 *            passed as second parameter.
2327
	 * @since 3.5
2328
	 */
2329
	public void setMessageDecorator(ILabelDecorator decorator){
2330
		this.messageDecorator = decorator;
2331
	}
2332
	
2333
	private String decorate(String string, StatusAdapter adapter) {
2334
		if(messageDecorator != null){
2335
			string = messageDecorator.decorateText(string, adapter);
2336
		}
2337
		return string;
2338
	}
2292
}
2339
}
(-)Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java (+47 lines)
Lines 21-26 Link Here
21
import org.eclipse.jface.dialogs.ErrorDialog;
21
import org.eclipse.jface.dialogs.ErrorDialog;
22
import org.eclipse.jface.dialogs.IDialogConstants;
22
import org.eclipse.jface.dialogs.IDialogConstants;
23
import org.eclipse.jface.util.Policy;
23
import org.eclipse.jface.util.Policy;
24
import org.eclipse.jface.viewers.ILabelDecorator;
24
import org.eclipse.jface.viewers.ILabelProviderListener;
25
import org.eclipse.jface.viewers.ILabelProviderListener;
25
import org.eclipse.jface.viewers.ITableLabelProvider;
26
import org.eclipse.jface.viewers.ITableLabelProvider;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.osgi.util.NLS;
Lines 249-254 Link Here
249
		assertTrue(((GridData) layoutData).exclude);
250
		assertTrue(((GridData) layoutData).exclude);
250
	}
251
	}
251
252
253
	public void testWithStatusAdapterAndLabelProvider1(){
254
		wsdm.setMessageDecorator(new ILabelDecorator(){
255
			
256
			public Image decorateImage(Image image, Object element) {
257
				// TODO Auto-generated method stub
258
				return null;
259
			}
260
			
261
			public String decorateText(String text, Object element) {
262
				// TODO Auto-generated method stub
263
				return text.replaceAll("[A-Z][A-Z][A-Z][0-9][0-9]", "");
264
			}
265
			
266
			public void addListener(ILabelProviderListener listener) {
267
				// TODO Auto-generated method stub
268
				
269
			}
270
			
271
			public void dispose() {
272
				// TODO Auto-generated method stub
273
				
274
			}
275
			
276
			public boolean isLabelProperty(Object element, String property) {
277
				// TODO Auto-generated method stub
278
				return false;
279
			}
280
			
281
			public void removeListener(ILabelProviderListener listener) {
282
				// TODO Auto-generated method stub
283
				
284
			}
285
			
286
		});
287
		wsdm.addStatusAdapter(createStatusAdapter("XYZ01" + MESSAGE_1), false);
288
		Label titleLabel = StatusDialogUtil.getTitleLabel();
289
		assertNotNull(titleLabel);
290
		assertEquals(MESSAGE_1, titleLabel.getText());
291
292
		Label secondaryLabel = StatusDialogUtil.getSingleStatusLabel();
293
		assertNotNull(secondaryLabel);
294
		assertEquals(WorkbenchMessages.WorkbenchStatusDialog_SeeDetails,
295
				secondaryLabel.getText());
296
	}
297
	
298
	
252
	/**
299
	/**
253
	 * Simple status with title. Check primary and secondary message. Verify
300
	 * Simple status with title. Check primary and secondary message. Verify
254
	 * closing.
301
	 * closing.

Return to bug 242821