|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.decorators; |
| 12 |
|
| 13 |
import java.util.ArrayList; |
| 14 |
import java.util.Collection; |
| 15 |
|
| 16 |
import org.eclipse.core.runtime.OperationCanceledException; |
| 17 |
import org.eclipse.core.runtime.jobs.Job; |
| 18 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 19 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
| 20 |
import org.eclipse.jface.viewers.LabelProviderChangedEvent; |
| 21 |
import org.eclipse.osgi.util.NLS; |
| 22 |
import org.eclipse.swt.widgets.Display; |
| 23 |
import org.eclipse.ui.internal.WorkbenchMessages; |
| 24 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
| 25 |
import org.eclipse.ui.internal.decorators.DecoratorDefinition; |
| 26 |
import org.eclipse.ui.internal.decorators.DecoratorManager; |
| 27 |
import org.eclipse.ui.tests.navigator.AbstractNavigatorTest; |
| 28 |
import org.eclipse.ui.tests.statushandlers.StatusDialogUtil; |
| 29 |
|
| 30 |
/** |
| 31 |
* @version 1.0 |
| 32 |
*/ |
| 33 |
public class ExceptionDecoratorErrorHandlingTest extends AbstractNavigatorTest |
| 34 |
implements ILabelProviderListener { |
| 35 |
|
| 36 |
protected DecoratorDefinition definition; |
| 37 |
|
| 38 |
protected boolean updated = false; |
| 39 |
|
| 40 |
private Collection problemDecorators = new ArrayList(); |
| 41 |
|
| 42 |
private DecoratorDefinition light; |
| 43 |
|
| 44 |
/** |
| 45 |
* Constructor for DecoratorTestCase. |
| 46 |
* @param testName |
| 47 |
*/ |
| 48 |
public ExceptionDecoratorErrorHandlingTest(String testName) { |
| 49 |
super(testName); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Sets up the hierarchy. |
| 54 |
*/ |
| 55 |
protected void doSetUp() throws Exception { |
| 56 |
ErrorDialog.AUTOMATED_MODE = false; |
| 57 |
super.doSetUp(); |
| 58 |
createTestFile(); |
| 59 |
showNav(); |
| 60 |
|
| 61 |
WorkbenchPlugin.getDefault().getDecoratorManager().addListener(this); |
| 62 |
|
| 63 |
//reset the static fields so that the decorators will fail |
| 64 |
HeavyNullImageDecorator.fail = true; |
| 65 |
HeavyNullTextDecorator.fail = true; |
| 66 |
NullImageDecorator.fail = true; |
| 67 |
DecoratorDefinition[] definitions = WorkbenchPlugin.getDefault() |
| 68 |
.getDecoratorManager().getAllDecoratorDefinitions(); |
| 69 |
for (int i = 0; i < definitions.length; i++) { |
| 70 |
String id = definitions[i].getId(); |
| 71 |
if (id.equals("org.eclipse.ui.tests.heavyNullImageDecorator") |
| 72 |
|| id.equals("org.eclipse.ui.tests.heavyNullTextDecorator")) { |
| 73 |
definitions[i].setEnabled(true); |
| 74 |
problemDecorators.add(definitions[i]); |
| 75 |
} |
| 76 |
|
| 77 |
//Do not cache the light one - the disabling issues |
| 78 |
//still need to be worked out. |
| 79 |
if (id.equals("org.eclipse.ui.tests.lightNullImageDecorator")) { |
| 80 |
definitions[i].setEnabled(true); |
| 81 |
light = definitions[i]; |
| 82 |
} |
| 83 |
} |
| 84 |
} /* (non-Javadoc) |
| 85 |
* @see org.eclipse.ui.tests.navigator.LightweightDecoratorTestCase#doTearDown() |
| 86 |
*/ |
| 87 |
|
| 88 |
protected void doTearDown() throws Exception { |
| 89 |
super.doTearDown(); |
| 90 |
ErrorDialog.AUTOMATED_MODE = true; |
| 91 |
if(StatusDialogUtil.getStatusShell() == null){ |
| 92 |
StatusDialogUtil.getStatusShell().dispose(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/* (non-Javadoc) |
| 97 |
* @see org.eclipse.jface.viewers.ILabelProviderListener#labelProviderChanged(org.eclipse.jface.viewers.LabelProviderChangedEvent) |
| 98 |
*/ |
| 99 |
public void labelProviderChanged( |
| 100 |
LabelProviderChangedEvent event) { |
| 101 |
updated = true; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
public void testStatusHandlingDialog() { |
| 106 |
// Need to wait for decoration to end to allow for all |
| 107 |
// errors to occur |
| 108 |
try { |
| 109 |
Job.getJobManager().join(DecoratorManager.FAMILY_DECORATE, null); |
| 110 |
} catch (OperationCanceledException e) { |
| 111 |
} catch (InterruptedException e) { |
| 112 |
} |
| 113 |
int count1 = 50; |
| 114 |
while(StatusDialogUtil.getStatusShell() == null && count1-- != 0){ |
| 115 |
Display.getDefault().readAndDispatch(); |
| 116 |
Thread.yield(); |
| 117 |
} |
| 118 |
// be sure that dialog was displayed |
| 119 |
assertTrue(count1 > 0); |
| 120 |
|
| 121 |
int count2 = 50; |
| 122 |
while (StatusDialogUtil.getTable() == null && count2-- != 0) { |
| 123 |
Display.getDefault().readAndDispatch(); |
| 124 |
Thread.yield(); |
| 125 |
} |
| 126 |
// be sure that more than one status was reported |
| 127 |
assertTrue(count2 > 0); |
| 128 |
String message = StatusDialogUtil.getTable().getItem(0).getText(); |
| 129 |
String pattern = WorkbenchMessages.DecoratorError + " " |
| 130 |
+ NLS.bind(WorkbenchMessages.DecoratorWillBeDisabled, ".*"); |
| 131 |
assertTrue(message.matches(pattern)); |
| 132 |
// Turnoff the lightweight one so as not to clutter the methods. |
| 133 |
light.setEnabled(false); |
| 134 |
} |
| 135 |
} |