|
Lines 15-23
Link Here
|
| 15 |
import org.eclipse.core.commands.Parameterization; |
15 |
import org.eclipse.core.commands.Parameterization; |
| 16 |
import org.eclipse.core.commands.ParameterizedCommand; |
16 |
import org.eclipse.core.commands.ParameterizedCommand; |
| 17 |
import org.eclipse.core.commands.State; |
17 |
import org.eclipse.core.commands.State; |
|
|
18 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 18 |
import org.eclipse.ui.commands.ICommandService; |
19 |
import org.eclipse.ui.commands.ICommandService; |
|
|
20 |
import org.eclipse.ui.commands.IElementReference; |
| 19 |
import org.eclipse.ui.handlers.IHandlerService; |
21 |
import org.eclipse.ui.handlers.IHandlerService; |
| 20 |
import org.eclipse.ui.handlers.RadioState; |
22 |
import org.eclipse.ui.handlers.RadioState; |
|
|
23 |
import org.eclipse.ui.menus.UIElement; |
| 24 |
import org.eclipse.ui.services.IServiceLocator; |
| 21 |
import org.eclipse.ui.tests.harness.util.UITestCase; |
25 |
import org.eclipse.ui.tests.harness.util.UITestCase; |
| 22 |
|
26 |
|
| 23 |
/** |
27 |
/** |
|
Lines 70-75
Link Here
|
| 70 |
handlerService.executeCommand(parameterizedCommand2, null); |
74 |
handlerService.executeCommand(parameterizedCommand2, null); |
| 71 |
assertState(command1, "value2"); |
75 |
assertState(command1, "value2"); |
| 72 |
} |
76 |
} |
|
|
77 |
|
| 78 |
|
| 79 |
static class MyUIElement extends UIElement{ |
| 80 |
|
| 81 |
private boolean checked; |
| 82 |
protected MyUIElement(IServiceLocator serviceLocator){ |
| 83 |
super(serviceLocator); |
| 84 |
} |
| 85 |
|
| 86 |
public void setDisabledIcon(ImageDescriptor desc) {} |
| 87 |
public void setHoverIcon(ImageDescriptor desc) {} |
| 88 |
public void setIcon(ImageDescriptor desc) {} |
| 89 |
public void setText(String text) {} |
| 90 |
public void setTooltip(String text) {} |
| 91 |
|
| 92 |
public void setChecked(boolean checked) { |
| 93 |
this.checked = checked; |
| 94 |
} |
| 95 |
|
| 96 |
public boolean isChecked() { |
| 97 |
return checked; |
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
MyUIElement element1a; |
| 103 |
MyUIElement element2a; |
| 104 |
MyUIElement element3a; |
| 105 |
|
| 106 |
MyUIElement element1b; |
| 107 |
MyUIElement element2b; |
| 108 |
MyUIElement element3b; |
| 109 |
|
| 110 |
public void testMultipleContributions() throws Exception{ |
| 111 |
|
| 112 |
Command command1 = commandService.getCommand("org.eclipse.ui.tests.radioStateCommand1"); |
| 113 |
|
| 114 |
// group 1 |
| 115 |
Parameterization radioParam1a = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value1"); |
| 116 |
ParameterizedCommand parameterizedCommand1a = new ParameterizedCommand(command1, new Parameterization[] { radioParam1a }); |
| 117 |
|
| 118 |
Parameterization radioParam2a = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value2"); |
| 119 |
ParameterizedCommand parameterizedCommand2a = new ParameterizedCommand(command1, new Parameterization[] { radioParam2a }); |
| 120 |
|
| 121 |
Parameterization radioParam3a = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value3"); |
| 122 |
ParameterizedCommand parameterizedCommand3a = new ParameterizedCommand(command1, new Parameterization[] { radioParam3a }); |
| 123 |
|
| 124 |
element1a = new MyUIElement(fWorkbench); |
| 125 |
element2a = new MyUIElement(fWorkbench); |
| 126 |
element3a = new MyUIElement(fWorkbench); |
| 127 |
|
| 128 |
IElementReference reference1a = commandService.registerElementForCommand(parameterizedCommand1a, element1a); |
| 129 |
IElementReference reference2a = commandService.registerElementForCommand(parameterizedCommand2a, element2a); |
| 130 |
IElementReference reference3a = commandService.registerElementForCommand(parameterizedCommand3a, element3a); |
| 131 |
|
| 132 |
// group 2 |
| 133 |
Parameterization radioParam1b = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value1"); |
| 134 |
ParameterizedCommand parameterizedCommand1b = new ParameterizedCommand(command1, new Parameterization[] { radioParam1b }); |
| 135 |
|
| 136 |
Parameterization radioParam2b = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value2"); |
| 137 |
ParameterizedCommand parameterizedCommand2b = new ParameterizedCommand(command1, new Parameterization[] { radioParam2b }); |
| 138 |
|
| 139 |
Parameterization radioParam3b = new Parameterization(command1.getParameter(RadioState.PARAMETER_ID), "value3"); |
| 140 |
ParameterizedCommand parameterizedCommand3b = new ParameterizedCommand(command1, new Parameterization[] { radioParam3b }); |
| 141 |
|
| 142 |
element1b = new MyUIElement(fWorkbench); |
| 143 |
element2b = new MyUIElement(fWorkbench); |
| 144 |
element3b = new MyUIElement(fWorkbench); |
| 145 |
|
| 146 |
IElementReference reference1b = commandService.registerElementForCommand(parameterizedCommand1b, element1b); |
| 147 |
IElementReference reference2b = commandService.registerElementForCommand(parameterizedCommand2b, element2b); |
| 148 |
IElementReference reference3b = commandService.registerElementForCommand(parameterizedCommand3b, element3b); |
| 149 |
|
| 150 |
try{ |
| 151 |
|
| 152 |
// first set the state to value1 |
| 153 |
handlerService.executeCommand(parameterizedCommand1a, null); |
| 154 |
commandService.refreshElements(command1.getId(), null); |
| 155 |
|
| 156 |
assertChecked(element1a); |
| 157 |
assertBothGroupsUpdated(); |
| 158 |
|
| 159 |
// then set the state to value2 |
| 160 |
handlerService.executeCommand(parameterizedCommand2a, null); |
| 161 |
|
| 162 |
// only value 2 is checked |
| 163 |
assertChecked(element2a); |
| 164 |
assertBothGroupsUpdated(); |
| 165 |
|
| 166 |
|
| 167 |
}finally { |
| 168 |
commandService.unregisterElement(reference1a); |
| 169 |
commandService.unregisterElement(reference2a); |
| 170 |
commandService.unregisterElement(reference3a); |
| 171 |
commandService.unregisterElement(reference1b); |
| 172 |
commandService.unregisterElement(reference2b); |
| 173 |
commandService.unregisterElement(reference3b); |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
private void assertChecked(MyUIElement checkedElement) { |
| 179 |
|
| 180 |
// only the element passed is checked and other two should be unchecked |
| 181 |
assertTrue(checkedElement == element1a? element1a.isChecked():!element1a.isChecked()); |
| 182 |
assertTrue(checkedElement == element2a? element2a.isChecked():!element2a.isChecked()); |
| 183 |
assertTrue(checkedElement == element3a? element3a.isChecked():!element3a.isChecked()); |
| 184 |
} |
| 185 |
|
| 186 |
private void assertBothGroupsUpdated() { |
| 187 |
assertEquals(element1a.isChecked(), element1b.isChecked()); |
| 188 |
assertEquals(element2a.isChecked(), element2b.isChecked()); |
| 189 |
assertEquals(element3a.isChecked(), element3b.isChecked()); |
| 190 |
} |
| 191 |
|
| 73 |
private void assertState(Command command, String expectedValue) { |
192 |
private void assertState(Command command, String expectedValue) { |
| 74 |
State state = command.getState(RadioState.STATE_ID); |
193 |
State state = command.getState(RadioState.STATE_ID); |
| 75 |
Object value = state.getValue(); |
194 |
Object value = state.getValue(); |