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