24
24
import java .util .HashMap ;
25
25
import java .util .List ;
26
26
import java .util .Map ;
27
+ import java .util .Objects ;
28
+ import org .eclipse .core .commands .Command ;
27
29
import org .eclipse .core .commands .ExecutionException ;
30
+ import org .eclipse .core .commands .IHandler ;
28
31
import org .eclipse .core .commands .IStateListener ;
29
32
import org .eclipse .core .commands .ParameterizedCommand ;
30
33
import org .eclipse .core .commands .State ;
54
57
import org .eclipse .jface .bindings .TriggerSequence ;
55
58
import org .eclipse .jface .menus .IMenuStateIds ;
56
59
import org .eclipse .swt .SWT ;
60
+ import org .eclipse .swt .widgets .Display ;
57
61
import org .eclipse .swt .widgets .Event ;
58
62
import org .eclipse .swt .widgets .MenuItem ;
59
63
import org .eclipse .swt .widgets .ToolItem ;
@@ -120,11 +124,10 @@ public void setModel(MItem item) {
120
124
}
121
125
122
126
/**
123
- * This method seems to be necessary for calls via reflection when called
124
- * with MHandledItem parameter.
127
+ * This method seems to be necessary for calls via reflection when called with
128
+ * MHandledItem parameter.
125
129
*
126
- * @param item
127
- * The model item
130
+ * @param item The model item
128
131
*/
129
132
public void setModel (MHandledItem item ) {
130
133
setModel ((MItem ) item );
@@ -148,10 +151,8 @@ private void generateCommand() {
148
151
WorkbenchSWTActivator .trace (Policy .DEBUG_MENUS_FLAG , "command: " + parmCmd , null ); //$NON-NLS-1$
149
152
}
150
153
if (parmCmd == null ) {
151
- logger .error (
152
- "Unable to generate the parameterized " + "command with the id \" " + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
153
- + parameters
154
- + " parameter(s). Model details: " + getModel ());//$NON-NLS-1$
154
+ logger .error ("Unable to generate the parameterized " + "command with the id \" " + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
155
+ + parameters + " parameter(s). Model details: " + getModel ());//$NON-NLS-1$
155
156
return ;
156
157
}
157
158
@@ -169,6 +170,8 @@ private void generateCommand() {
169
170
} else if (radioState != null ) {
170
171
radioState .addListener (stateListener );
171
172
}
173
+
174
+ parmCmd .getCommand ().addCommandListener (event -> Display .getDefault ().asyncExec (() -> update ()));
172
175
}
173
176
}
174
177
@@ -264,8 +267,7 @@ protected void updateMenuItem() {
264
267
if (mnemonics != null && !mnemonics .isEmpty ()) {
265
268
int idx = text .indexOf (mnemonics );
266
269
if (idx != -1 ) {
267
- text = text .substring (0 , idx ) + '&'
268
- + text .substring (idx );
270
+ text = text .substring (0 , idx ) + '&' + text .substring (idx );
269
271
}
270
272
}
271
273
}
@@ -307,6 +309,7 @@ protected void updateToolItem() {
307
309
item .setToolTipText (tooltip );
308
310
item .setSelection (getModel ().isSelected ());
309
311
item .setEnabled (getModel ().isEnabled ());
312
+
310
313
}
311
314
312
315
private String getToolTipText (boolean attachKeybinding ) {
@@ -317,6 +320,8 @@ private String getToolTipText(boolean attachKeybinding) {
317
320
parmCmd = getModel ().getWbCommand ();
318
321
}
319
322
323
+ text = legacyActionLabelSupport (text , parmCmd );
324
+
320
325
if (parmCmd != null && text == null ) {
321
326
try {
322
327
text = parmCmd .getName ();
@@ -332,6 +337,12 @@ private String getToolTipText(boolean attachKeybinding) {
332
337
return text ;
333
338
}
334
339
340
+ private String legacyActionLabelSupport (String text , ParameterizedCommand command ) {
341
+
342
+ return java .util .Optional .of (command ).map (ParameterizedCommand ::getCommand ).map (Command ::getHandler )
343
+ .map (IHandler ::getHandlerLabel ).filter (Objects ::nonNull ).orElse (text );
344
+ }
345
+
335
346
@ Override
336
347
protected void handleWidgetDispose (Event event ) {
337
348
if (event .widget == widget ) {
@@ -389,7 +400,7 @@ public void dispose() {
389
400
390
401
@ Override
391
402
protected void handleHelpRequest () {
392
- if (helpService == null )
403
+ if (helpService == null )
393
404
return ;
394
405
String helpContextId = getModel ().getPersistedState ().get (EHelpService .HELP_CONTEXT_ID );
395
406
if (helpContextId != null ) {
0 commit comments