@@ -48,18 +48,26 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
4848 IWorkbenchWindow window = HandlerUtil .getActiveWorkbenchWindowChecked (event );
4949 ICommandService cs = window .getService (ICommandService .class );
5050
51- // Show the Search view
51+ // Check if search view is available
5252 Command showView = cs .getCommand (IWorkbenchCommandConstants .VIEWS_SHOW_VIEW );
53- HashMap <String , Object > parms = new HashMap <String , Object >();
54- parms .put (IWorkbenchCommandConstants .VIEWS_SHOW_VIEW_PARM_ID , "org.eclipse.search.ui.views.SearchView" );
53+ if (!showView .isDefined ()) {
54+ return null ; // Search view not available, exit gracefully
55+ }
56+
57+ // Show the Search view
58+ HashMap <String , Object > parms = new HashMap <>();
59+ parms .put (IWorkbenchCommandConstants .VIEWS_SHOW_VIEW_PARM_ID , "org.eclipse.search.ui.views.SearchView" ); //$NON-NLS-1$
5560 ParameterizedCommand showSearchView = ParameterizedCommand .generateCommand (showView , parms );
5661
5762 IHandlerService hs = window .getService (IHandlerService .class );
63+ Object triggerObj = event .getTrigger ();
64+ Event trigger = (triggerObj instanceof Event ) ? (Event ) triggerObj : new Event ();
65+
5866 try {
5967 // Execute the sequence: show search view -> navigate -> activate editor
60- hs .executeCommand (showSearchView , ( Event ) event . getTrigger () );
61- hs .executeCommand (searchCommand , ( Event ) event . getTrigger () );
62- hs .executeCommand (IWorkbenchCommandConstants .WINDOW_ACTIVATE_EDITOR , ( Event ) event . getTrigger () );
68+ hs .executeCommand (showSearchView , trigger );
69+ hs .executeCommand (searchCommand , trigger );
70+ hs .executeCommand (IWorkbenchCommandConstants .WINDOW_ACTIVATE_EDITOR , trigger );
6371 } catch (NotDefinedException | NotEnabledException | NotHandledException e ) {
6472 throw new ExecutionException (e .getMessage (), e );
6573 }
@@ -69,7 +77,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
6977
7078 @ Override
7179 public void setInitializationData (IConfigurationElement config , String propertyName , Object data ) throws CoreException {
72- if ("previous" .equals (data )) {
80+ if ("previous" .equals (data )) { //$NON-NLS-1$
7381 searchCommand = IWorkbenchCommandConstants .NAVIGATE_PREVIOUS ;
7482 }
7583 }
0 commit comments