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 267409 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java (+1 lines)
Lines 466-471 Link Here
466
	public void handleStateChange(State state, Object oldValue) {
466
	public void handleStateChange(State state, Object oldValue) {
467
		if (state.getId().equals(RegistryToggleState.STATE_ID)) {
467
		if (state.getId().equals(RegistryToggleState.STATE_ID)) {
468
			checkedState = state;
468
			checkedState = state;
469
			refreshElements();
469
		} else if (state.getId().equals(RadioState.STATE_ID)) {
470
		} else if (state.getId().equals(RadioState.STATE_ID)) {
470
			radioState = state;
471
			radioState = state;
471
			refreshElements();
472
			refreshElements();
(-)Eclipse UI Tests/org/eclipse/ui/tests/commands/ToggleStateTest.java (+57 lines)
Lines 13-22 Link Here
13
13
14
import org.eclipse.core.commands.Command;
14
import org.eclipse.core.commands.Command;
15
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.Parameterization;
17
import org.eclipse.core.commands.ParameterizedCommand;
16
import org.eclipse.core.commands.State;
18
import org.eclipse.core.commands.State;
19
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.ui.commands.ICommandService;
20
import org.eclipse.ui.commands.ICommandService;
21
import org.eclipse.ui.commands.IElementReference;
18
import org.eclipse.ui.handlers.IHandlerService;
22
import org.eclipse.ui.handlers.IHandlerService;
19
import org.eclipse.ui.handlers.RegistryToggleState;
23
import org.eclipse.ui.handlers.RegistryToggleState;
24
import org.eclipse.ui.menus.UIElement;
25
import org.eclipse.ui.services.IServiceLocator;
20
import org.eclipse.ui.tests.harness.util.UITestCase;
26
import org.eclipse.ui.tests.harness.util.UITestCase;
21
27
22
/**
28
/**
Lines 71-76 Link Here
71
		}
77
		}
72
	}
78
	}
73
79
80
	static class MyUIElement extends UIElement{
81
82
		private boolean checked;
83
		protected MyUIElement(IServiceLocator serviceLocator){
84
			super(serviceLocator);
85
		}
86
87
		public void setDisabledIcon(ImageDescriptor desc) {}
88
		public void setHoverIcon(ImageDescriptor desc) {}
89
		public void setIcon(ImageDescriptor desc) {}
90
		public void setText(String text) {}
91
		public void setTooltip(String text) {}
92
93
		public void setChecked(boolean checked) {
94
			this.checked = checked;
95
		}
96
		
97
		public boolean isChecked() {
98
			return checked;
99
		}
100
101
	}
102
	
103
	public void testMultipleContributions() throws Exception{
104
		
105
		Command command1 = commandService.getCommand("org.eclipse.ui.tests.toggleStateCommand1");
106
		ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command1, new Parameterization[0]);
107
		
108
		MyUIElement element1 = new MyUIElement(fWorkbench);
109
		MyUIElement element2 = new MyUIElement(fWorkbench);
110
		
111
		IElementReference reference1 = commandService.registerElementForCommand(parameterizedCommand, element1);
112
		IElementReference reference2 = commandService.registerElementForCommand(parameterizedCommand, element2);
113
		
114
		try{
115
		
116
			commandService.refreshElements(command1.getId(), null);
117
			assertEquals(element1.isChecked(), element2.isChecked());
118
			
119
			Boolean oldValue = (Boolean) handlerService.executeCommand(command1.getId(), null);
120
			//value should have changed
121
			assertEquals(!oldValue.booleanValue(), element1.isChecked());
122
			//and changed in both places
123
			assertEquals(element1.isChecked(), element2.isChecked());
124
			
125
		}finally {
126
			commandService.unregisterElement(reference1);
127
			commandService.unregisterElement(reference2);
128
		}
129
		
130
	}
74
131
75
	private void assertState(Command command1, boolean expectedValue) {
132
	private void assertState(Command command1, boolean expectedValue) {
76
		State state = command1.getState(RegistryToggleState.STATE_ID);
133
		State state = command1.getState(RegistryToggleState.STATE_ID);

Return to bug 267409