CleanUp: [NiConsole] Tweak nullable handling

Change-Id: Iee2d739736ed1a2da3ac193675d86eba1b5dbc81
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/ReconnectEngineHandler.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/ReconnectEngineHandler.java
index 4759919..7880fe5 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/ReconnectEngineHandler.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/ReconnectEngineHandler.java
@@ -104,6 +104,7 @@
 				add.put(IRemoteEngineController.LAUNCH_RECONNECT_ATTRIBUTE, reconnect);
 				final ILaunchConfiguration reconnectConfig= new OverlayLaunchConfiguration(originalConfig, add);
 				try {
+					@SuppressWarnings("unused")
 					final ILaunch reconnectLaunch= reconnectConfig.launch(
 							originalLaunch.getLaunchMode(), monitor, false );
 					
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/RelaunchToolHandler.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/RelaunchToolHandler.java
index 21753f5..5439c61 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/RelaunchToolHandler.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/internal/nico/ui/actions/RelaunchToolHandler.java
@@ -39,7 +39,6 @@
 import org.eclipse.ui.commands.IElementUpdater;
 import org.eclipse.ui.progress.IProgressConstants;
 
-import org.eclipse.statet.jcommons.lang.NonNull;
 import org.eclipse.statet.jcommons.lang.NonNullByDefault;
 import org.eclipse.statet.jcommons.lang.Nullable;
 import org.eclipse.statet.jcommons.ts.core.Tool;
@@ -79,7 +78,7 @@
 		
 		
 		@Override
-		public boolean belongsTo(final Object family) {
+		public boolean belongsTo(final @Nullable Object family) {
 			return (family == RelaunchJob.class);
 		}
 		
@@ -164,8 +163,7 @@
 		try {
 			tool.terminate();
 			
-			@NonNull Job[] jobs= Job.getJobManager().find(RelaunchJob.class);
-			for (final Job job : jobs) {
+			for (final Job job : Job.getJobManager().find(RelaunchJob.class)) {
 				if (((RelaunchJob)job).process == tool) {
 					return null;
 				}
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/NicoUITools.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/NicoUITools.java
index 14aaec3..1e9aebd 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/NicoUITools.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/NicoUITools.java
@@ -153,12 +153,13 @@
 	
 	/**
 	 * 
-	 * @param type an optional expected main type
-	 * @param tool the tool to check or <code>null</code>
+	 * @param type the expected main type (optional)
+	 * @param tool the tool to check or {@code null}
+	 * @return the tool
 	 * @throws CoreException if tool is missing or the wrong type
 	 */
-	public static void accessTool(final String type,
-			final @Nullable Tool tool) throws CoreException {
+	public static <T extends Tool> T accessTool(final @Nullable String type,
+			final @Nullable T tool) throws CoreException {
 		if (tool == null || (type != null && !type.equals(tool.getMainType()))) {
 			throw new CoreException(new Status(IStatus.ERROR, NicoUI.BUNDLE_ID, -1,
 					(type != null) ?
@@ -166,13 +167,14 @@
 							"No tool session is active in the current workbench window.", null)
 			);
 		}
+		return tool;
 	}
 	
 	/**
 	 * 
 	 * @param type the expected main type (optional)
 	 * @param type the id of the expected feature set (optional)
-	 * @param tool the tool to check or <code>null</code>
+	 * @param tool the tool to check or {@code null}
 	 * @return the controller of the tool
 	 */
 	public static boolean isToolReady(final String type, final @Nullable String featureSetID,
@@ -185,12 +187,12 @@
 	/**
 	 * 
 	 * @param type the expected main type (optional)
-	 * @param process the tool to check or <code>null</code>
+	 * @param tool the tool to check or {@code null}
 	 * @return the controller of the tool
 	 * @throws CoreException if tool is missing, wrong type or terminated
 	 */
 	public static <W extends ToolWorkspace> ToolController accessController(
-			final String type, final Tool tool) throws CoreException {
+			final @Nullable String type, final @Nullable Tool tool) throws CoreException {
 		return accessController(type, null, tool);
 	}
 	
@@ -198,13 +200,14 @@
 	 * 
 	 * @param type the expected main type (optional)
 	 * @param type the id of the expected feature set (optional)
-	 * @param process the tool to check or <code>null</code>
+	 * @param tool the tool to check or {@code null}
 	 * @return the controller of the tool
 	 * @throws CoreException if tool is missing, wrong type or terminated
 	 */
 	public static <W extends ToolWorkspace> ToolController accessController(
-			final String type, final @Nullable String featureSetId, final Tool tool) throws CoreException {
-		accessTool(type, tool);
+			final @Nullable String type, final @Nullable String featureSetId,
+			@Nullable Tool tool) throws CoreException {
+		tool= accessTool(type, tool);
 		if ((featureSetId != null && !tool.isProvidingFeatureSet(featureSetId))
 				|| !(tool instanceof ToolProcess) ) {
 			throw new CoreException(new Status(IStatus.ERROR, NicoUI.BUNDLE_ID, -1,
@@ -222,7 +225,7 @@
 	 * 
 	 * @param type the expected main type (optional)
 	 * @param type the id of the expected feature set (optional)
-	 * @param process the tool to check or <code>null</code>
+	 * @param process the tool to check or {@code null}
 	 * @return the controller of the tool
 	 * @throws CoreException if tool is missing, wrong type or terminated
 	 */
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/actions/AbstractToolScopeHandler.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/actions/AbstractToolScopeHandler.java
index 7c22d3a..3440ec5 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/actions/AbstractToolScopeHandler.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/actions/AbstractToolScopeHandler.java
@@ -56,8 +56,10 @@
 			toolProvider= (ToolProvider)scope;
 		}
 		else if (scope instanceof IWorkbenchWindow) {
-			toolProvider= NicoUI.getToolRegistry()
-					.getToolProvider(((IWorkbenchWindow)scope).getActivePage());
+			final var workbenchPage= ((IWorkbenchWindow)scope).getActivePage();
+			if (workbenchPage != null) {
+				toolProvider= NicoUI.getToolRegistry().getToolProvider(workbenchPage);
+			}
 		}
 		
 		if (toolProvider != null) {
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/ConsolePageEditor.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/ConsolePageEditor.java
index 3394c86..e6e71b8 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/ConsolePageEditor.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/ConsolePageEditor.java
@@ -66,6 +66,8 @@
 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
 
+import org.eclipse.statet.jcommons.lang.NonNull;
+import org.eclipse.statet.jcommons.lang.Nullable;
 import org.eclipse.statet.jcommons.status.Status;
 
 import org.eclipse.statet.ecommons.io.FileUtil;
@@ -414,7 +416,8 @@
 	
 	
 	private void updateSettings() {
-		this.submitHistoryTypesFilter= EPreferences.getInstancePrefs().getPreferenceValue(ConsolePreferences.HISTORYNAVIGATION_SUBMIT_TYPES_PREF);
+		this.submitHistoryTypesFilter= EPreferences.getInstancePrefs().getPreferenceValue(
+				ConsolePreferences.HISTORYNAVIGATION_SUBMIT_TYPES_PREF );
 	}
 	
 	
@@ -775,7 +778,7 @@
 			if (!oldText.equals(newText)) {
 				this.prompt.setText(newText);
 				if (oldText.length() != newText.length()) { // assuming monospace font
-					getComposite().layout(new Control[] { this.prompt });
+					getComposite().layout(new @NonNull Control[] { this.prompt });
 				}
 			}
 			onPromptUpdate(p);
@@ -1002,7 +1005,7 @@
 	
 	@Override
 	@SuppressWarnings("unchecked")
-	public <T> T getAdapter(final Class<T> adapterType) {
+	public <T> @Nullable T getAdapter(final Class<T> adapterType) {
 		if (adapterType == SourceEditor.class) {
 			return (T) this;
 		}
diff --git a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/NIConsolePage.java b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/NIConsolePage.java
index c7a2cfb..19b65b9 100644
--- a/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/NIConsolePage.java
+++ b/r/org.eclipse.statet.nico.ui/src/org/eclipse/statet/nico/ui/console/NIConsolePage.java
@@ -539,7 +539,7 @@
 						&& (e.stateMask == SWT.NONE || e.stateMask == SWT.SHIFT)
 						&& ((e.keyCode & SWT.KEYCODE_BIT) == 0) ) {
 					final StyledText textWidget= NIConsolePage.this.inputEditor.getViewer().getTextWidget();
-					if (!UIAccess.isOkToUse(textWidget)) {
+					if (textWidget == null || !UIAccess.isOkToUse(textWidget)) {
 						return;
 					}
 					final int cType= Character.getType(e.character);