From c58c28b9cc02438b78232f299eaa5397a9c92b7f Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 31 Jan 2020 11:02:25 -0500 Subject: [PATCH] Bug 559474: Format all TM.terminal code to CDT standard This is applying the per-project code formatting rules that would be applied on save in the JDT editor See also Bug 540373 Change-Id: Id04c972c3b3cb0a6ed1ab8581185359b7cf43f91 --- .../build.properties | 16 +- .../build.properties | 16 +- .../build.properties | 16 +- .../feature.properties | 2 +- .../build.properties | 16 +- .../feature.properties | 2 +- .../build.properties | 4 +- .../feature.properties | 2 +- .../build.properties | 4 +- .../feature.properties | 2 +- .../build.properties | 16 +- .../feature.properties | 2 +- .../build.properties | 16 +- .../feature.properties | 2 +- .../build.properties | 14 +- .../feature.properties | 2 +- .../build.properties | 14 +- .../feature.properties | 2 +- .../cdtserial/activator/Activator.java | 7 +- .../controls/SerialSettingsPage.java | 9 +- .../connector/local/activator/UIPlugin.java | 4 +- .../LocalWizardConfigurationPanel.java | 81 +- .../local/launcher/LocalLauncherDelegate.java | 141 ++- .../local/launcher/LocalLauncherHandler.java | 8 +- .../connector/process/ProcessConnector.java | 43 +- .../process/ProcessLauncherDelegate.java | 36 +- .../connector/process/ProcessMonitor.java | 125 +- .../connector/process/ProcessSettings.java | 28 +- .../process/ProcessSettingsPage.java | 15 +- .../connector/process/activator/UIPlugin.java | 4 +- .../process/help/IContextHelpIds.java | 1 - .../connector/remote/IRemoteSettings.java | 12 +- .../remote/IRemoteTerminalParser.java | 12 +- .../RemoteWizardConfigurationPanel.java | 16 +- .../connector/remote/internal/Activator.java | 20 +- .../remote/internal/ArgumentParser.java | 21 +- .../internal/RemoteConnectionManager.java | 18 +- .../remote/internal/RemoteConnector.java | 12 +- .../remote/internal/RemoteSettings.java | 8 +- .../remote/internal/RemoteSettingsPage.java | 6 +- .../launcher/RemoteLauncherDelegate.java | 5 +- .../remote/launcher/RemoteMementoHandler.java | 10 +- .../connector/remote/nls/Messages.java | 2 +- .../connector/ssh/activator/UIPlugin.java | 24 +- .../ssh/connector/ISshConstants.java | 5 +- .../connector/ssh/connector/ISshSettings.java | 30 +- .../connector/KeyboardInteractiveDialog.java | 303 ++--- .../ssh/connector/SshConnection.java | 197 +-- .../connector/ssh/connector/SshConnector.java | 52 +- .../connector/ssh/connector/SshMessages.java | 4 +- .../ssh/connector/SshMessages.properties | 4 +- .../connector/ssh/connector/SshSettings.java | 39 +- .../ssh/connector/SshSettingsPage.java | 61 +- .../ssh/connector/UserValidationDialog.java | 32 +- .../controls/SshWizardConfigurationPanel.java | 116 +- .../ssh/launcher/SshLauncherDelegate.java | 42 +- .../ssh/launcher/SshMementoHandler.java | 100 +- .../connector/telnet/activator/UIPlugin.java | 4 +- .../telnet/connector/ITelnetSettings.java | 6 + .../telnet/connector/NetworkPortMap.java | 22 +- .../telnet/connector/TelnetCodes.java | 104 +- .../telnet/connector/TelnetConnectWorker.java | 27 +- .../telnet/connector/TelnetConnection.java | 15 +- .../telnet/connector/TelnetConnector.java | 61 +- .../telnet/connector/TelnetMessages.java | 2 +- .../connector/TelnetMessages.properties | 2 +- .../telnet/connector/TelnetOption.java | 417 +++---- .../telnet/connector/TelnetProperties.java | 2 +- .../telnet/connector/TelnetSettings.java | 27 +- .../telnet/connector/TelnetSettingsPage.java | 63 +- .../TelnetWizardConfigurationPanel.java | 86 +- .../launcher/TelnetLauncherDelegate.java | 31 +- .../telnet/launcher/TelnetMementoHandler.java | 24 +- .../build.properties | 6 +- .../plugin.properties | 2 +- .../terminal/connector/TerminalConnector.java | 71 +- ...TerminalToRemoteInjectionOutputStream.java | 139 ++- .../control/CommandInputFieldWithHistory.java | 171 +-- .../terminal/control/ICommandInputField.java | 15 +- .../terminal/control/ITerminalListener2.java | 2 +- .../control/ITerminalMouseListener.java | 4 +- .../control/ITerminalViewControl.java | 100 +- .../control/TerminalViewControlFactory.java | 20 +- .../actions/AbstractTerminalAction.java | 35 +- .../control/actions/ActionMessages.java | 3 +- .../control/actions/ActionMessages.properties | 2 +- .../terminal/control/actions/ImageConsts.java | 2 +- .../actions/TerminalActionClearAll.java | 12 +- .../control/actions/TerminalActionCopy.java | 14 +- .../control/actions/TerminalActionCut.java | 14 +- .../control/actions/TerminalActionPaste.java | 19 +- .../actions/TerminalActionSelectAll.java | 6 +- .../control/impl/ITerminalControlForText.java | 22 +- .../control/impl/TerminalMessages.java | 28 +- .../control/impl/TerminalMessages.properties | 2 +- .../terminal/control/impl/TerminalPlugin.java | 23 +- .../emulator/EditActionAccelerators.java | 2 +- .../emulator/IVT100EmulatorBackend.java | 44 +- .../emulator/LoggingOutputStream.java | 26 +- .../emulator/VT100BackendTraceDecorator.java | 47 +- .../terminal/emulator/VT100Emulator.java | 148 +-- .../emulator/VT100EmulatorBackend.java | 203 ++-- .../emulator/VT100TerminalControl.java | 398 +++--- .../terminal/model/ISnapshotChanges.java | 8 +- .../terminal/model/SnapshotChanges.java | 225 ++-- .../model/SynchronizedTerminalTextData.java | 41 +- .../terminal/model/TerminalTextData.java | 92 +- .../model/TerminalTextDataFastScroll.java | 147 ++- .../model/TerminalTextDataSnapshot.java | 91 +- .../terminal/model/TerminalTextDataStore.java | 236 ++-- .../model/TerminalTextDataWindow.java | 148 ++- .../preferences/ITerminalConstants.java | 14 +- .../TerminalPreferenceInitializer.java | 2 +- .../preferences/TerminalPreferencePage.java | 19 +- .../provisional/api/AbstractSettingsPage.java | 21 +- .../provisional/api/ISettingsStore.java | 16 +- .../provisional/api/ITerminalConnector.java | 26 +- .../provisional/api/ITerminalControl.java | 12 +- .../terminal/provisional/api/Logger.java | 126 +- .../api/TerminalConnectorExtension.java | 30 +- .../provisional/api/TerminalState.java | 6 +- .../api/provider/TerminalConnectorImpl.java | 20 +- .../textcanvas/AbstractTextCanvasModel.java | 189 +-- .../terminal/textcanvas/GridCanvas.java | 134 +- .../terminal/textcanvas/ILinelRenderer.java | 6 + .../terminal/textcanvas/ITextCanvasModel.java | 6 + .../textcanvas/ITextCanvasModelListener.java | 2 + .../terminal/textcanvas/PipedInputStream.java | 112 +- .../textcanvas/PollingTextCanvasModel.java | 20 +- .../terminal/textcanvas/StyleMap.java | 152 +-- .../terminal/textcanvas/TextCanvas.java | 171 +-- .../terminal/textcanvas/TextLineRenderer.java | 123 +- .../terminal/textcanvas/VirtualCanvas.java | 227 ++-- .../tm/terminal/model/ITerminalTextData.java | 12 +- .../model/ITerminalTextDataReadOnly.java | 2 + .../model/ITerminalTextDataSnapshot.java | 6 + .../tm/terminal/model/LineSegment.java | 20 +- .../org/eclipse/tm/terminal/model/Style.java | 86 +- .../eclipse/tm/terminal/model/StyleColor.java | 27 +- .../model/TerminalTextDataFactory.java | 12 +- .../TerminalConnectorFactoryTest.java | 82 +- .../connector/TerminalConnectorTest.java | 82 +- ...inalToRemoteInjectionOutputStreamTest.java | 102 +- .../internal/terminal/emulator/AllTests.java | 2 +- .../emulator/VT100EmulatorBackendTest.java | 1076 +++++------------ .../model/AbstractITerminalTextDataTest.java | 704 +++++------ .../tm/internal/terminal/model/AllTests.java | 2 +- .../terminal/model/SnapshotChangesTest.java | 343 +++--- .../SynchronizedTerminalTextDataTest.java | 12 +- .../model/TerminalTextDataFastScrollTest.java | 12 +- ...rminalTextDataFastScrollTestMaxHeigth.java | 12 +- .../TerminalTextDataPerformanceTest.java | 233 ++-- .../model/TerminalTextDataSnapshotTest.java | 925 +++++++------- .../TerminalTextDataSnapshotWindowTest.java | 143 +-- .../model/TerminalTextDataStoreTest.java | 12 +- .../terminal/model/TerminalTextDataTest.java | 12 +- .../model/TerminalTextDataWindowTest.java | 384 +++--- .../model/TerminalTextTestHelper.java | 52 +- .../speedtest/SpeedTestConnection.java | 91 +- .../speedtest/SpeedTestConnector.java | 29 +- .../terminal/speedtest/SpeedTestSettings.java | 39 +- .../terminal/test/terminalcanvas/Main.java | 29 +- .../test/terminalcanvas/Snippet48.java | 151 +-- .../terminalcanvas/TerminalTextCanvas.java | 95 +- .../test/terminalcanvas/VirtualCanvas.java | 206 ++-- .../ui/AbstractLineOrientedDataSource.java | 23 +- .../internal/terminal/test/ui/DataReader.java | 61 +- .../terminal/test/ui/FastDataSource.java | 20 +- .../terminal/test/ui/FileDataSource.java | 30 +- .../terminal/test/ui/IDataSource.java | 12 +- .../tm/internal/terminal/test/ui/IStatus.java | 12 +- .../test/ui/LineCountingDataSource.java | 33 +- .../terminal/test/ui/RandomDataSource.java | 44 +- .../terminal/test/ui/TerminalTextUITest.java | 178 +-- .../terminal/test/ui/VT100DataSource.java | 35 +- .../PipedInputStreamPerformanceTest.java | 20 +- .../terminal/textcanvas/PipedStreamTest.java | 57 +- .../eclipse/tm/terminal/model/AllTests.java | 2 +- .../tm/terminal/model/StyleColorTest.java | 19 +- .../eclipse/tm/terminal/model/StyleTest.java | 110 +- .../terminal/test/AutomatedPluginTests.java | 2 +- ...minalContextPropertiesProviderFactory.java | 39 +- .../view/core/TerminalServiceFactory.java | 16 +- .../ITerminalsConnectorConstants.java | 3 +- .../view/core/internal/PropertyTester.java | 5 +- .../preferences/ScopedEclipsePreferences.java | 30 +- .../view/core/tracing/TraceHandler.java | 23 +- .../tm/terminal/view/core/utils/Env.java | 15 +- .../plugin.properties | 2 +- .../view/ui/actions/AbstractAction.java | 17 +- .../ui/actions/NewTerminalViewAction.java | 18 +- .../view/ui/actions/SelectEncodingAction.java | 17 +- .../view/ui/actions/TabScrollLockAction.java | 10 +- .../ui/actions/ToggleCommandFieldAction.java | 13 +- .../terminal/view/ui/activator/UIPlugin.java | 32 +- .../controls/ConfigurationPanelControl.java | 69 +- .../view/ui/controls/NoteCompositeHelper.java | 6 +- .../view/ui/help/IContextHelpIds.java | 1 - .../IConfigurationPanelContainer.java | 2 - .../view/ui/interfaces/ILauncherDelegate.java | 2 +- .../view/ui/interfaces/IMementoHandler.java | 28 +- .../view/ui/interfaces/IPreferenceKeys.java | 3 +- .../view/ui/interfaces/ImageConsts.java | 128 +- .../ui/internal/ExternalExecutablesState.java | 4 +- .../view/ui/internal/PropertyTester.java | 16 +- .../view/ui/internal/SettingsStore.java | 6 +- .../dialogs/EncodingSelectionDialog.java | 186 +-- .../dialogs/LaunchTerminalSettingsDialog.java | 103 +- .../AbstractTriggerCommandHandler.java | 7 +- .../DisconnectTerminalCommandHandler.java | 14 +- .../handler/LaunchTerminalCommandHandler.java | 45 +- .../ui/launcher/AbstractLauncherDelegate.java | 25 +- .../ui/launcher/LauncherDelegateManager.java | 77 +- .../ui/listeners/AbstractWindowListener.java | 65 +- .../ui/listeners/WorkbenchPartListener.java | 4 +- .../ui/listeners/WorkbenchWindowListener.java | 2 +- .../showin/DynamicContributionItems.java | 22 +- .../showin/ExternalExecutablesDialog.java | 420 ++++--- .../showin/ExternalExecutablesManager.java | 46 +- .../view/ui/manager/ConsoleManager.java | 126 +- .../tm/terminal/view/ui/nls/Messages.java | 11 +- .../terminal/view/ui/nls/Messages.properties | 4 +- .../ui/panels/AbstractConfigurationPanel.java | 48 +- .../AbstractExtendedConfigurationPanel.java | 80 +- .../view/ui/preferences/PreferencePage.java | 160 ++- .../preferences/PreferencesInitializer.java | 3 +- .../view/ui/services/TerminalService.java | 128 +- .../ui/streams/AbstractStreamsConnector.java | 256 ++-- .../view/ui/streams/InputStreamMonitor.java | 414 +++---- .../view/ui/streams/OutputStreamMonitor.java | 338 +++--- .../view/ui/streams/StreamsConnector.java | 5 +- .../ui/streams/StreamsLauncherDelegate.java | 25 +- .../view/ui/streams/StreamsSettings.java | 30 +- .../view/ui/tabs/TabCommandFieldHandler.java | 7 +- .../view/ui/tabs/TabDisposeListener.java | 15 +- .../view/ui/tabs/TabFolderManager.java | 161 ++- .../view/ui/tabs/TabFolderMenuHandler.java | 52 +- .../view/ui/tabs/TabFolderToolbarHandler.java | 42 +- .../view/ui/tabs/TabTerminalListener.java | 24 +- .../view/ui/view/OldTerminalsViewHandler.java | 15 +- .../terminal/view/ui/view/TerminalsView.java | 141 ++- .../ui/view/TerminalsViewMementoHandler.java | 80 +- .../view/showin/GitShowInContextHandler.java | 30 +- 243 files changed, 8230 insertions(+), 7835 deletions(-) diff --git a/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.feature/build.properties index 59d78e93926..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.sdk.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.sdk.feature/build.properties index 01228655964..9dbf021aaf0 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.sdk.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.cdtserial.sdk.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.local.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.local.feature/build.properties index 59d78e93926..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.local.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.local.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.local.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.local.feature/feature.properties index 9acef2d3f8a..6eeb795643a 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.local.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.local.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/build.properties index 59d78e93926..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/feature.properties index e3339ab9f3b..a7496356ac9 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.local.sdk.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/build.properties index 8e3ce5326b9..c3d7109be57 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/build.properties @@ -6,10 +6,10 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ############################################################################### bin.includes = feature.xml,\ feature.properties diff --git a/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/feature.properties index 2c8e307d916..92d67a71e3d 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.ssh.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/build.properties index 1b96b29abc4..70b8f53d16b 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/build.properties @@ -6,10 +6,10 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ############################################################################### bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/feature.properties index b650b956f92..97676b95e42 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.ssh.sdk.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/build.properties index 59d78e93926..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/feature.properties index a3b734b888f..d741ae24e81 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.telnet.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/build.properties index 59d78e93926..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: -# Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: +# Michael Scharf (Wind River) - initial API and implementation +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/feature.properties index 0c4787ac81c..d757d652160 100644 --- a/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.connector.telnet.sdk.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.control.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.control.feature/build.properties index bfccdf49079..865a10c6790 100644 --- a/terminal/features/org.eclipse.tm.terminal.control.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.control.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: # Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties diff --git a/terminal/features/org.eclipse.tm.terminal.control.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.control.feature/feature.properties index df9c50ce7f9..7a7e800d62c 100644 --- a/terminal/features/org.eclipse.tm.terminal.control.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.control.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/build.properties b/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/build.properties index 4e9a9c77c82..89538a20b32 100644 --- a/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/build.properties +++ b/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/build.properties @@ -1,13 +1,13 @@ ################################################################################ # Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# Contributors: +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# Contributors: # Michael Scharf (Wind River) - initial API and implementation -# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license +# Uwe Stieber (Wind River) - Bug 434937 - Releng: The Terminal Features have an incorrect license ################################################################################ bin.includes = feature.xml,\ feature.properties,\ diff --git a/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/feature.properties b/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/feature.properties index acbfce1de76..922a08ad6ab 100644 --- a/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/feature.properties +++ b/terminal/features/org.eclipse.tm.terminal.control.sdk.feature/feature.properties @@ -6,7 +6,7 @@ # https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 -# +# # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation ############################################################################### diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/activator/Activator.java b/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/activator/Activator.java index 84edbb2733a..fd41fbe57bf 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/activator/Activator.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/activator/Activator.java @@ -69,13 +69,13 @@ public class Activator extends AbstractUIPlugin { } @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } @@ -114,7 +114,8 @@ public class Activator extends AbstractUIPlugin { if (exception instanceof CoreException) { log(((CoreException) exception).getStatus()); } else { - log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), exception.getLocalizedMessage(), exception)); + log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), exception.getLocalizedMessage(), + exception)); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/controls/SerialSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/controls/SerialSettingsPage.java index 1f9f4f2e151..a96aa798a12 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/controls/SerialSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.cdtserial/src/org/eclipse/tm/terminal/connector/cdtserial/controls/SerialSettingsPage.java @@ -246,13 +246,10 @@ public class SerialSettingsPage extends AbstractSettingsPage { settings.setStopBits(StopBits.fromStringIndex(stopBitsCombo.getSelectionIndex())); dialogSettings.put(SerialSettings.PORT_NAME_ATTR, portCombo.getText()); - dialogSettings.put(SerialSettings.BAUD_RATE_ATTR, - BaudRate.getStrings()[baudRateCombo.getSelectionIndex()]); - dialogSettings.put(SerialSettings.BYTE_SIZE_ATTR, - ByteSize.getStrings()[byteSizeCombo.getSelectionIndex()]); + dialogSettings.put(SerialSettings.BAUD_RATE_ATTR, BaudRate.getStrings()[baudRateCombo.getSelectionIndex()]); + dialogSettings.put(SerialSettings.BYTE_SIZE_ATTR, ByteSize.getStrings()[byteSizeCombo.getSelectionIndex()]); dialogSettings.put(SerialSettings.PARITY_ATTR, Parity.getStrings()[parityCombo.getSelectionIndex()]); - dialogSettings.put(SerialSettings.STOP_BITS_ATTR, - StopBits.getStrings()[stopBitsCombo.getSelectionIndex()]); + dialogSettings.put(SerialSettings.STOP_BITS_ATTR, StopBits.getStrings()[stopBitsCombo.getSelectionIndex()]); } @Override diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/activator/UIPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/activator/UIPlugin.java index c725a5cdbcc..f115b5356bd 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/activator/UIPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/activator/UIPlugin.java @@ -81,7 +81,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -90,7 +90,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { plugin = null; scopedPreferences = null; traceHandler = null; diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/controls/LocalWizardConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/controls/LocalWizardConfigurationPanel.java index 28f0bcab2cb..32df2bf63fa 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/controls/LocalWizardConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/controls/LocalWizardConfigurationPanel.java @@ -44,18 +44,18 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration * * @param container The configuration panel container or null. */ - public LocalWizardConfigurationPanel(IConfigurationPanelContainer container) { - super(container); - } + public LocalWizardConfigurationPanel(IConfigurationPanelContainer container) { + super(container); + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) - */ + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) + */ @Override - public void setupPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new GridLayout()); - panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + public void setupPanel(Composite parent) { + Composite panel = new Composite(parent, SWT.NONE); + panel.setLayout(new GridLayout()); + panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // Create the encoding selection combo createEncodingUI(panel, false); @@ -66,13 +66,14 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration setEncoding("UTF-8"); //$NON-NLS-1$ } else { String encoding = WorkbenchEncoding.getWorkbenchDefaultEncoding(); - if (encoding != null && !"".equals(encoding)) setEncoding(encoding); //$NON-NLS-1$ + if (encoding != null && !"".equals(encoding)) //$NON-NLS-1$ + setEncoding(encoding); } // Fill the rest of the panel with a label to be able to // set a height and width hint for the dialog - Label label = new Label(panel, SWT.HORIZONTAL); - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + Label label = new Label(panel, SWT.HORIZONTAL); + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData.widthHint = 300; layoutData.heightHint = 80; label.setLayoutData(layoutData); @@ -82,36 +83,39 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration resource = getSelectionResource(); } - setControl(panel); - } + setControl(panel); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setupData(java.util.Map) */ @Override public void setupData(Map data) { - if (data == null) return; + if (data == null) + return; - String value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING); - if (value != null) setEncoding(value); - } + String value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING); + if (value != null) + setEncoding(value); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#extractData(java.util.Map) */ @Override public void extractData(Map data) { - // set the terminal connector id for local terminal - data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.local.LocalConnector"); //$NON-NLS-1$ + // set the terminal connector id for local terminal + data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, + "org.eclipse.tm.terminal.connector.local.LocalConnector"); //$NON-NLS-1$ - // Store the encoding + // Store the encoding data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding()); Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { // if we have a IResource selection use the location for working directory - if (resource instanceof org.eclipse.core.resources.IResource){ - String dir = ((org.eclipse.core.resources.IResource)resource).getProject().getLocation().toString(); + if (resource instanceof org.eclipse.core.resources.IResource) { + String dir = ((org.eclipse.core.resources.IResource) resource).getProject().getLocation().toString(); data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, dir); } } @@ -121,21 +125,21 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) */ @Override - protected void fillSettingsForHost(String host){ + protected void fillSettingsForHost(String host) { } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) */ @Override - protected void saveSettingsForHost(boolean add){ + protected void saveSettingsForHost(boolean add) { } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() */ @Override - public boolean isValid(){ + public boolean isValid() { return true; } @@ -143,16 +147,16 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) */ @Override - public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { + public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { // Save the encodings widget values doSaveEncodingsWidgetValues(settings, idPrefix); - } + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) */ @Override - public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) { + public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) { // Restore the encodings widget values doRestoreEncodingsWidgetValues(settings, idPrefix); } @@ -161,17 +165,17 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() */ @Override - protected String getHostFromSettings() { + protected String getHostFromSettings() { return null; - } + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isWithHostList() */ @Override - public boolean isWithHostList() { - return false; - } + public boolean isWithHostList() { + return false; + } /** * Returns the IResource from the current selection @@ -184,11 +188,12 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration if (selection instanceof IStructuredSelection && !selection.isEmpty()) { Object element = ((IStructuredSelection) selection).getFirstElement(); - if (element instanceof org.eclipse.core.resources.IResource){ - return ((org.eclipse.core.resources.IResource)element); + if (element instanceof org.eclipse.core.resources.IResource) { + return ((org.eclipse.core.resources.IResource) element); } if (element instanceof IAdaptable) { - return (org.eclipse.core.resources.IResource) ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class); + return (org.eclipse.core.resources.IResource) ((IAdaptable) element) + .getAdapter(org.eclipse.core.resources.IResource.class); } } return null; diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java index a7277d69dbf..c1f9291b28f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java @@ -104,7 +104,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { } else { encoding = WorkbenchEncoding.getWorkbenchDefaultEncoding(); } - if (encoding != null && !"".equals(encoding)) properties.put(ITerminalsConnectorConstants.PROP_ENCODING, encoding); //$NON-NLS-1$ + if (encoding != null && !"".equals(encoding)) //$NON-NLS-1$ + properties.put(ITerminalsConnectorConstants.PROP_ENCODING, encoding); } // For local terminals, force a new terminal tab each time it is launched, @@ -115,9 +116,11 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { // Initialize the local terminal working directory. // By default, start the local terminal in the users home directory - String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); + String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); String cwd = null; - if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$ + if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) + || "".equals(initialCwd.trim())) { //$NON-NLS-1$ cwd = System.getProperty("user.home"); //$NON-NLS-1$ } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd)) { String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$ @@ -126,16 +129,18 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { URI uri = URIUtil.fromString(eclipseHomeLocation); File f = URIUtil.toFile(uri); cwd = f.getAbsolutePath(); - } catch (URISyntaxException ex) { /* ignored on purpose */ } + } catch (URISyntaxException ex) { + /* ignored on purpose */ } } } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd)) { Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) { - cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); - } + if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) { + cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() + .toOSString(); + } } } else { try { @@ -161,28 +166,39 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { // If the current selection resolved to an folder, default the working directory // to that folder and update the terminal title ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); - if ((service != null && service.getSelection() != null) || properties.containsKey(ITerminalsConnectorConstants.PROP_SELECTION)) { - ISelection selection = (ISelection)properties.get(ITerminalsConnectorConstants.PROP_SELECTION); - if (selection == null) selection = service.getSelection(); + if ((service != null && service.getSelection() != null) + || properties.containsKey(ITerminalsConnectorConstants.PROP_SELECTION)) { + ISelection selection = (ISelection) properties.get(ITerminalsConnectorConstants.PROP_SELECTION); + if (selection == null) + selection = service.getSelection(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { String dir = null; - Iterator iter = ((IStructuredSelection)selection).iterator(); + Iterator iter = ((IStructuredSelection) selection).iterator(); while (iter.hasNext()) { Object element = iter.next(); Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { // If the element is not an IResource, try to adapt to IResource if (!(element instanceof org.eclipse.core.resources.IResource)) { - Object adapted = element instanceof IAdaptable ? ((IAdaptable)element).getAdapter(org.eclipse.core.resources.IResource.class) : null; - if (adapted == null) adapted = Platform.getAdapterManager().getAdapter(element, org.eclipse.core.resources.IResource.class); - if (adapted != null) element = adapted; + Object adapted = element instanceof IAdaptable + ? ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class) + : null; + if (adapted == null) + adapted = Platform.getAdapterManager().getAdapter(element, + org.eclipse.core.resources.IResource.class); + if (adapted != null) + element = adapted; } - if (element instanceof org.eclipse.core.resources.IResource && ((org.eclipse.core.resources.IResource)element).exists()) { - IPath location = ((org.eclipse.core.resources.IResource)element).getLocation(); - if (location == null) continue; - if (location.toFile().isFile()) location = location.removeLastSegments(1); + if (element instanceof org.eclipse.core.resources.IResource + && ((org.eclipse.core.resources.IResource) element).exists()) { + IPath location = ((org.eclipse.core.resources.IResource) element).getLocation(); + if (location == null) + continue; + if (location.toFile().isFile()) + location = location.removeLastSegments(1); if (location.toFile().isDirectory() && location.toFile().canRead()) { dir = location.toFile().getAbsolutePath(); break; @@ -190,7 +206,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { } if (element instanceof IPath || element instanceof File) { - File f = element instanceof IPath ? ((IPath)element).toFile() : (File)element; + File f = element instanceof IPath ? ((IPath) element).toFile() : (File) element; if (f.isDirectory() && f.canRead()) { dir = f.getAbsolutePath(); break; @@ -225,14 +241,16 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { private String getTerminalTitle(Map properties) { // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if (title != null) return title; + if (title != null) + return title; try { String hostname = InetAddress.getLocalHost().getHostName(); if (hostname != null && !"".equals(hostname.trim())) { //$NON-NLS-1$ return hostname; } - } catch (UnknownHostException e) { /* ignored on purpose */ } + } catch (UnknownHostException e) { + /* ignored on purpose */ } return "Local"; //$NON-NLS-1$ } @@ -245,7 +263,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { if (IMementoHandler.class.equals(adapter)) { return mementoHandler; } - return super.getAdapter(adapter); + return super.getAdapter(adapter); } /** @@ -264,7 +282,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { } } if (shell == null) { - shell = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + shell = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); if (shell == null || "".equals(shell)) { //$NON-NLS-1$ if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ shell = System.getenv("SHELL").trim(); //$NON-NLS-1$ @@ -280,13 +299,14 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) */ - @Override + @Override public ITerminalConnector createTerminalConnector(Map properties) { Assert.isNotNull(properties); // Check for the terminal connector id - String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.local.LocalConnector"; //$NON-NLS-1$ + String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + if (connectorId == null) + connectorId = "org.eclipse.tm.terminal.connector.local.LocalConnector"; //$NON-NLS-1$ // Extract the process properties using defaults String image; @@ -295,17 +315,19 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { File defaultShell = defaultShell(); image = defaultShell.isAbsolute() ? defaultShell.getAbsolutePath() : defaultShell.getPath(); } else { - image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH); + image = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH); } - String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); + String arguments = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); if (arguments == null && !Platform.OS_WIN32.equals(Platform.getOS())) { - arguments = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); + arguments = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); } // Determine if a PTY will be used - boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null && PTY.isSupported(PTY.Mode.TERMINAL)) - || properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ) instanceof PTY; + boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null + && PTY.isSupported(PTY.Mode.TERMINAL)) + || properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ) instanceof PTY; boolean localEcho = false; if (!properties.containsKey(ITerminalsConnectorConstants.PROP_LOCAL_ECHO) @@ -315,7 +337,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { localEcho = !isUsingPTY; } } else { - localEcho = ((Boolean)properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)).booleanValue(); + localEcho = ((Boolean) properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)).booleanValue(); } String lineSeparator = null; @@ -323,28 +345,32 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { || !(properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR) instanceof String)) { // No line separator will be set if a PTY is used if (!isUsingPTY) { - lineSeparator = Platform.OS_WIN32.equals(Platform.getOS()) ? ILineSeparatorConstants.LINE_SEPARATOR_CRLF : ILineSeparatorConstants.LINE_SEPARATOR_LF; + lineSeparator = Platform.OS_WIN32.equals(Platform.getOS()) ? ILineSeparatorConstants.LINE_SEPARATOR_CRLF + : ILineSeparatorConstants.LINE_SEPARATOR_LF; } } else { - lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); + lineSeparator = (String) properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); } - Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ); - PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ); - ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); - ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); - String workingDir = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR); + Process process = (Process) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ); + PTY pty = (PTY) properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ); + ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); + ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); + String workingDir = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR); String[] envp = null; - if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) && - properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null && - properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]){ - envp = (String[])properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT); + if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) + && properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null + && properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]) { + envp = (String[]) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT); } // Set the ECLIPSE_HOME and ECLIPSE_WORKSPACE environment variables List envpList = new ArrayList(); - if (envp != null) envpList.addAll(Arrays.asList(envp)); + if (envp != null) + envpList.addAll(Arrays.asList(envp)); // ECLIPSE_HOME String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$ @@ -353,21 +379,23 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { URI uri = URIUtil.fromString(eclipseHomeLocation); File f = URIUtil.toFile(uri); envpList.add("ECLIPSE_HOME=" + f.getAbsolutePath()); //$NON-NLS-1$ - } catch (URISyntaxException e) { /* ignored on purpose */ } + } catch (URISyntaxException e) { + /* ignored on purpose */ } } // ECLIPSE_WORKSPACE Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) { - envpList.add("ECLIPSE_WORKSPACE=" + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); //$NON-NLS-1$ - } + if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) { + envpList.add("ECLIPSE_WORKSPACE=" + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() //$NON-NLS-1$ + .getLocation().toOSString()); + } } - // Convert back into a string array - envp = envpList.toArray(new String[envpList.size()]); + // Convert back into a string array + envp = envpList.toArray(new String[envpList.size()]); Assert.isTrue(image != null || process != null); @@ -389,7 +417,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT)) { Object value = properties.get(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT); - processSettings.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean)value).booleanValue() : false); + processSettings + .setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean) value).booleanValue() : false); } // And save the settings to the store diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherHandler.java b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherHandler.java index d8701cb49b1..fa2a9c1d2b2 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherHandler.java @@ -46,10 +46,12 @@ public class LocalLauncherHandler extends AbstractHandler { if (!(selection instanceof IStructuredSelection)) { IEditorInput input = HandlerUtil.getActiveEditorInput(event); if (input instanceof IPathEditorInput) { - IPath path = ((IPathEditorInput)input).getPath(); + IPath path = ((IPathEditorInput) input).getPath(); if (path != null) { - if (path.toFile().isFile()) path = path.removeLastSegments(1); - if (path.toFile().isDirectory() && path.toFile().canRead()) selection = new StructuredSelection(path); + if (path.toFile().isFile()) + path = path.removeLastSegments(1); + if (path.toFile().isDirectory() && path.toFile().canRead()) + selection = new StructuredSelection(path); } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessConnector.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessConnector.java index a297da9cd9a..68469eba7e6 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessConnector.java @@ -113,7 +113,7 @@ public class ProcessConnector extends AbstractStreamsConnector { pty = new PTY(PTY.Mode.TERMINAL); // Initialize the terminal size - VT100Emulator text = ((VT100TerminalControl)control).getTerminalText(); + VT100Emulator text = ((VT100TerminalControl) control).getTerminalText(); text.fontChanged(); } catch (IOException e) { // PTY not supported @@ -129,13 +129,13 @@ public class ProcessConnector extends AbstractStreamsConnector { command.append(arguments.trim()); } - File workingDir =null; - if (settings.getWorkingDir()!=null){ + File workingDir = null; + if (settings.getWorkingDir() != null) { workingDir = new File(settings.getWorkingDir()); } String[] envp = null; - if (settings.getEnvironment()!=null){ + if (settings.getEnvironment() != null) { envp = settings.getEnvironment(); } @@ -165,7 +165,8 @@ public class ProcessConnector extends AbstractStreamsConnector { } // Execute the process - process = ProcessFactory.getFactory().exec(argv.toArray(new String[argv.size()]), envp, workingDir, pty); + process = ProcessFactory.getFactory().exec(argv.toArray(new String[argv.size()]), envp, workingDir, + pty); } else { // No PTY -> just execute via the standard Java Runtime implementation. process = Runtime.getRuntime().exec(command.toString(), envp, workingDir); @@ -177,11 +178,9 @@ public class ProcessConnector extends AbstractStreamsConnector { lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$ if ("\r".equals(lineSeparator)) { //$NON-NLS-1$ lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_CR; - } - else if ("\n".equals(lineSeparator)) { //$NON-NLS-1$ + } else if ("\n".equals(lineSeparator)) { //$NON-NLS-1$ lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_LF; - } - else { + } else { lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_CRLF; } } @@ -196,7 +195,8 @@ public class ProcessConnector extends AbstractStreamsConnector { control.setVT100LineWrapping(true); // connect the streams - connectStreams(control, process.getOutputStream(), process.getInputStream(), (pty == null ? process.getErrorStream() : null), settings.isLocalEcho(), lineSeparator); + connectStreams(control, process.getOutputStream(), process.getInputStream(), + (pty == null ? process.getErrorStream() : null), settings.isLocalEcho(), lineSeparator); // Set the terminal control state to CONNECTED control.setState(TerminalState.CONNECTED); @@ -209,7 +209,8 @@ public class ProcessConnector extends AbstractStreamsConnector { disconnect(); // Lookup the tab item CTabItem item = ConsoleManager.getInstance().findConsole(control); - if (item != null) item.dispose(); + if (item != null) + item.dispose(); // Get the error message from the exception String msg = e.getLocalizedMessage() != null ? e.getLocalizedMessage() : ""; //$NON-NLS-1$ Assert.isNotNull(msg); @@ -225,10 +226,10 @@ public class ProcessConnector extends AbstractStreamsConnector { private static String getTermVariable(String[] envp) { if (envp != null && !Platform.OS_WIN32.equals(Platform.getOS())) for (String var : envp) - if (var.startsWith("TERM=")) //$NON-NLS-1$ - return var.substring(5); - return "xterm"; //$NON-NLS-1$ - } + if (var.startsWith("TERM=")) //$NON-NLS-1$ + return var.substring(5); + return "xterm"; //$NON-NLS-1$ + } /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#isLocalEcho() @@ -252,7 +253,10 @@ public class ProcessConnector extends AbstractStreamsConnector { if (!isWindows) { // Destroy the process first, except on windows (Bug 465674) - if (process != null) { process.destroy(); process = null; } + if (process != null) { + process.destroy(); + process = null; + } } // Dispose the streams @@ -260,7 +264,10 @@ public class ProcessConnector extends AbstractStreamsConnector { if (isWindows) { // On Windows destroy the process after closing streams - if (process != null) { process.destroy(); process = null; } + if (process != null) { + process.destroy(); + process = null; + } } // Set the terminal control state to CLOSED. @@ -274,7 +281,7 @@ public class ProcessConnector extends AbstractStreamsConnector { */ @Override public void setDefaultSettings() { - settings.load(new NullSettingsStore()); + settings.load(new NullSettingsStore()); } /* (non-Javadoc) diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessLauncherDelegate.java index bc9e067f29d..493c9d50b3d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessLauncherDelegate.java @@ -72,26 +72,29 @@ public class ProcessLauncherDelegate extends AbstractLauncherDelegate { Assert.isNotNull(properties); // Check for the terminal connector id - String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.process.ProcessConnector"; //$NON-NLS-1$ + String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + if (connectorId == null) + connectorId = "org.eclipse.tm.terminal.connector.process.ProcessConnector"; //$NON-NLS-1$ // Extract the process properties - String image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH); - String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); - Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ); - PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ); + String image = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH); + String arguments = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); + Process process = (Process) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ); + PTY pty = (PTY) properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ); Object value = properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO); - boolean localEcho = value instanceof Boolean ? ((Boolean)value).booleanValue() : false; - String lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); - ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); - ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); - String workingDir = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR); + boolean localEcho = value instanceof Boolean ? ((Boolean) value).booleanValue() : false; + String lineSeparator = (String) properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); + ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); + ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); + String workingDir = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR); String[] envp = null; - if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) && - properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null && - properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]){ - envp = (String[])properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT); + if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) + && properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null + && properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]) { + envp = (String[]) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT); } Assert.isTrue(image != null || process != null); @@ -114,7 +117,8 @@ public class ProcessLauncherDelegate extends AbstractLauncherDelegate { if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT)) { value = properties.get(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT); - processSettings.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean)value).booleanValue() : false); + processSettings + .setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean) value).booleanValue() : false); } // And save the settings to the store diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessMonitor.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessMonitor.java index ad509ca1b50..ff61cb9f5f3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessMonitor.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessMonitor.java @@ -13,7 +13,6 @@ package org.eclipse.tm.terminal.connector.process; import org.eclipse.core.runtime.Assert; - /** * Process monitor implementation. */ @@ -27,82 +26,84 @@ public class ProcessMonitor { // Flag to mark the monitor disposed private boolean disposed; + /** + * Constructor. + * + * @param processConnector The parent process connector. Must not be null. + */ + public ProcessMonitor(ProcessConnector processConnector) { + super(); - /** - * Constructor. - * - * @param processConnector The parent process connector. Must not be null. - */ - public ProcessMonitor(ProcessConnector processConnector) { - super(); - - Assert.isNotNull(processConnector); + Assert.isNotNull(processConnector); this.processConnector = processConnector; // Query the monitored process for easier access this.process = processConnector.getProcess(); - } + } - /** - * Dispose the process monitor. - */ + /** + * Dispose the process monitor. + */ public void dispose() { - // Set the disposed status - disposed = true; - // Not initialized -> return immediately - if (thread == null) return; + // Set the disposed status + disposed = true; + // Not initialized -> return immediately + if (thread == null) + return; - // Copy the reference - final Thread oldThread = thread; - // Unlink the monitor from the thread - thread = null; - // And interrupt the writer thread - oldThread.interrupt(); - } + // Copy the reference + final Thread oldThread = thread; + // Unlink the monitor from the thread + thread = null; + // And interrupt the writer thread + oldThread.interrupt(); + } - /** - * Starts the terminal output stream monitor. - */ - public void startMonitoring() { - // If already initialized -> return immediately - if (thread != null) return; + /** + * Starts the terminal output stream monitor. + */ + public void startMonitoring() { + // If already initialized -> return immediately + if (thread != null) + return; - // Create a new runnable which is constantly reading from the stream - Runnable runnable = new Runnable() { - @Override + // Create a new runnable which is constantly reading from the stream + Runnable runnable = new Runnable() { + @Override public void run() { - monitorProcess(); - } - }; + monitorProcess(); + } + }; - // Create the monitor thread - thread = new Thread(runnable, "Terminal Process Monitor Thread"); //$NON-NLS-1$ + // Create the monitor thread + thread = new Thread(runnable, "Terminal Process Monitor Thread"); //$NON-NLS-1$ - // Configure the monitor thread - thread.setDaemon(true); + // Configure the monitor thread + thread.setDaemon(true); - // Start the processing - thread.start(); - } + // Start the processing + thread.start(); + } - /** - * Monitors the associated system process, waiting for it to terminate, - * and notifies the associated process monitor's. - */ + /** + * Monitors the associated system process, waiting for it to terminate, + * and notifies the associated process monitor's. + */ public void monitorProcess() { - // If already disposed -> return immediately - if (disposed) return; + // If already disposed -> return immediately + if (disposed) + return; - try { - // Wait for the monitored process to terminate - process.waitFor(); - } catch (InterruptedException ie) { - // clear interrupted state - Thread.interrupted(); - } finally { - // Dispose the parent process connector - if (!disposed) - processConnector.disconnect(); - } - } + try { + // Wait for the monitored process to terminate + process.waitFor(); + } catch (InterruptedException ie) { + // clear interrupted state + Thread.interrupted(); + } finally { + // Dispose the parent process connector + if (!disposed) + processConnector.disconnect(); + } + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettings.java index 4d74734df74..97a7084b7e0 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettings.java @@ -113,7 +113,8 @@ public class ProcessSettings { public void setPTY(PTY pty) { this.pty = pty; // If the PTY is set to "null", the local echo will be set to "true" - if (pty == null) setLocalEcho(true); + if (pty == null) + setLocalEcho(true); } /** @@ -265,15 +266,18 @@ public class ProcessSettings { image = store.get("Path", null);//$NON-NLS-1$ arguments = store.get("Arguments", null); //$NON-NLS-1$ localEcho = Boolean.parseBoolean(store.get("LocalEcho", Boolean.FALSE.toString())); //$NON-NLS-1$ - mergeWithNativeEnvironment = Boolean.parseBoolean(store.get("MergeWithNativeEnvironment", Boolean.FALSE.toString())); //$NON-NLS-1$ + mergeWithNativeEnvironment = Boolean + .parseBoolean(store.get("MergeWithNativeEnvironment", Boolean.FALSE.toString())); //$NON-NLS-1$ lineSeparator = store.get("LineSeparator", null); //$NON-NLS-1$ workingDir = store.get("WorkingDir", null); //$NON-NLS-1$ if (store instanceof SettingsStore) { - process = (Process)((SettingsStore)store).getSettings().get("Process"); //$NON-NLS-1$ - pty = (PTY)((SettingsStore)store).getSettings().get("PTY"); //$NON-NLS-1$ - stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdOutListeners"); //$NON-NLS-1$ - stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdErrListeners"); //$NON-NLS-1$ - environment = (String[])((SettingsStore)store).getSettings().get("Environment"); //$NON-NLS-1$ + process = (Process) ((SettingsStore) store).getSettings().get("Process"); //$NON-NLS-1$ + pty = (PTY) ((SettingsStore) store).getSettings().get("PTY"); //$NON-NLS-1$ + stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings() + .get("StdOutListeners"); //$NON-NLS-1$ + stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings() + .get("StdErrListeners"); //$NON-NLS-1$ + environment = (String[]) ((SettingsStore) store).getSettings().get("Environment"); //$NON-NLS-1$ } } @@ -291,11 +295,11 @@ public class ProcessSettings { store.put("LineSeparator", lineSeparator); //$NON-NLS-1$ store.put("WorkingDir", workingDir); //$NON-NLS-1$ if (store instanceof SettingsStore) { - ((SettingsStore)store).getSettings().put("Process", process); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("PTY", pty); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("Environment", environment); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("Process", process); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("PTY", pty); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("Environment", environment); //$NON-NLS-1$ } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettingsPage.java index 3b734e318b4..58f59e88682 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/ProcessSettingsPage.java @@ -69,7 +69,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage { // The entry fields shall be properly aligned Composite panel = new Composite(composite, SWT.NONE); GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; panel.setLayout(layout); panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -80,7 +81,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage { // Text field and browse button are aligned it their own panel Composite innerPanel = new Composite(panel, SWT.NONE); layout = new GridLayout(2, false); - layout.marginWidth = 0; layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; innerPanel.setLayout(layout); innerPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -127,7 +129,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage { */ protected void onBrowseButtonSelected(SelectionEvent e) { // Determine the shell - Shell shell = e != null ? e.widget.getDisplay().getActiveShell() : PlatformUI.getWorkbench().getDisplay().getActiveShell(); + Shell shell = e != null ? e.widget.getDisplay().getActiveShell() + : PlatformUI.getWorkbench().getDisplay().getActiveShell(); // create a standard file dialog FileDialog dialog = new FileDialog(shell, SWT.OPEN); @@ -141,7 +144,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage { IPath filePath = new Path(selectedFile); // If the selected file points to an directory, use the directory as is IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1); - String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null : filePath.lastSegment(); + String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null + : filePath.lastSegment(); if (!filterPath.isEmpty()) { dialog.setFilterPath(filterPath.toString()); @@ -152,7 +156,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage { } else { Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - dialog.setFilterPath(org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); + dialog.setFilterPath( + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/activator/UIPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/activator/UIPlugin.java index bf236afcf2e..6965fb78e45 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/activator/UIPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/activator/UIPlugin.java @@ -69,7 +69,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -78,7 +78,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/help/IContextHelpIds.java b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/help/IContextHelpIds.java index 2d042f346d7..7c6dcb752bf 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/help/IContextHelpIds.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.process/src/org/eclipse/tm/terminal/connector/process/help/IContextHelpIds.java @@ -13,7 +13,6 @@ package org.eclipse.tm.terminal.connector.process.help; import org.eclipse.tm.terminal.connector.process.activator.UIPlugin; - /** * Context help id definitions. */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteSettings.java index e0c4671e641..5e4d711372a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteSettings.java @@ -1,9 +1,9 @@ /******************************************************************************* * Copyright (c) 2015, 2018 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ *******************************************************************************/ package org.eclipse.tm.terminal.connector.remote; @@ -13,14 +13,14 @@ public interface IRemoteSettings { /** * Get the connection type ID for the connection (e.g. local, ssh, etc.) - * + * * @return connection type ID. */ String getConnectionTypeId(); /** * Get the connection name for the target system. - * + * * @return connection name */ String getConnectionName(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteTerminalParser.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteTerminalParser.java index dd8670059dc..3a91f1b5547 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteTerminalParser.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/IRemoteTerminalParser.java @@ -1,9 +1,9 @@ /******************************************************************************* * Copyright (c) 2015, 2018 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ *******************************************************************************/ package org.eclipse.tm.terminal.connector.remote; @@ -16,7 +16,7 @@ public interface IRemoteTerminalParser { /** * Initialize the remote shell. This method will be called after the connection has been initialized. Implementors can assume * that the connection is open when this is called. - * + * * @param connection * terminal shell connection * @return IRemoteProcess a remote process corresponding to the remote shell @@ -28,7 +28,7 @@ public interface IRemoteTerminalParser { /** * Parse the input stream. This method will be called with a buffer of characters read from the input stream. If the method * returns true, the characters will be displayed in the terminal view, otherwise they will be ignored. - * + * * @param buf * buffer containing characters from the terminal input stream * @return true if the characters should be displayed in the terminal diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/controls/RemoteWizardConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/controls/RemoteWizardConfigurationPanel.java index 5a8853f3d87..f0cb639f2fc 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/controls/RemoteWizardConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/controls/RemoteWizardConfigurationPanel.java @@ -50,7 +50,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) */ @Override @@ -88,7 +88,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setupData(java.util.Map) */ @Override @@ -117,7 +117,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#extractData(java.util.Map) */ @Override @@ -141,7 +141,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) */ @Override @@ -150,7 +150,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) */ @Override @@ -159,7 +159,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() */ @Override @@ -169,7 +169,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs. * IDialogSettings, java.lang.String) */ @@ -181,7 +181,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() */ @Override diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/Activator.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/Activator.java index 4ab951914e8..1d7e63dfecc 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/Activator.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/Activator.java @@ -1,9 +1,9 @@ /******************************************************************************* * Copyright (c) 2015, 2018 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ *******************************************************************************/ package org.eclipse.tm.terminal.connector.remote.internal; @@ -45,7 +45,7 @@ public class Activator extends Plugin { /** * Returns the shared instance - * + * * @return the shared instance */ public static Activator getDefault() { @@ -54,7 +54,7 @@ public class Activator extends Plugin { /** * Returns an image descriptor for the image file at the given plug-in relative path. - * + * * @param path * the path * @return the image descriptor @@ -65,7 +65,7 @@ public class Activator extends Plugin { /** * Create log entry from an IStatus - * + * * @param status * status to log */ @@ -75,7 +75,7 @@ public class Activator extends Plugin { /** * Create log entry from a string - * + * * @param msg * message to log */ @@ -85,7 +85,7 @@ public class Activator extends Plugin { /** * Create log entry from a Throwable - * + * * @param e * throwable to log */ @@ -97,7 +97,7 @@ public class Activator extends Plugin { /** * Generate a unique identifier - * + * * @return unique identifier string */ public static String getUniqueIdentifier() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/ArgumentParser.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/ArgumentParser.java index 59d647b9ef6..ca3e15e474e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/ArgumentParser.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/ArgumentParser.java @@ -6,7 +6,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -103,7 +103,8 @@ public class ArgumentParser { * string. Allows escaping. */ iterator.next(); // Skip quote - quoted_reader: while ((iterator.current() != CharacterIterator.DONE) && (iterator.current() != '"')) { + quoted_reader: while ((iterator.current() != CharacterIterator.DONE) + && (iterator.current() != '"')) { char innerChar = iterator.current(); switch (innerChar) { case '\\': @@ -177,7 +178,7 @@ public class ArgumentParser { /** * Convert all tokens in a full command line that can be executed in a * shell. - * + * * @param fullEscape * If every special character shall be escaped. If false, only * white spaces are escaped and the shell will interpret the @@ -254,7 +255,7 @@ public class ArgumentParser { /** * Returns a List of all entries of the command line. - * + * * @return The Array */ public String[] getTokenArray() { @@ -263,7 +264,7 @@ public class ArgumentParser { /** * Returns a List of all entries of the command line. - * + * * @return The List */ public List getTokenList() { @@ -273,7 +274,7 @@ public class ArgumentParser { /** * Returns the command of the command line, assuming that the first entry is * always the command. - * + * * @return The command or null if the command lines has no command nor * arguments. */ @@ -287,7 +288,7 @@ public class ArgumentParser { /** * Returns the command of the command line, assuming that the first entry is * always the command. - * + * * @return The command or null if the command lines has no command nor * arguments. * @param fullEscape @@ -305,7 +306,7 @@ public class ArgumentParser { /** * Returns a list of all arguments, assuming that the first entry is the * command name. - * + * * @return The Array or null if the command lines has no command nor * arguments. */ @@ -319,7 +320,7 @@ public class ArgumentParser { /** * Returns a list of all arguments, assuming that the first entry is the * command name. - * + * * @return The List or null if the command lines has no command nor * arguments. */ @@ -332,7 +333,7 @@ public class ArgumentParser { /** * Returns the total number of entries. - * + * * @return the total number of entries */ public int getSize() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java index 93279eadf3b..a05278cf799 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java @@ -64,7 +64,7 @@ public class RemoteConnectionManager extends Job { /* * (non-Javadoc) - * + * * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) */ @Override @@ -79,15 +79,15 @@ public class RemoteConnectionManager extends Job { remoteConnection = connType.getConnection(connector.getRemoteSettings().getConnectionName()); } if (remoteConnection == null) { - return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), - NLS.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName())); + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS + .bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName())); } if (!remoteConnection.isOpen()) { remoteConnection.open(monitor); if (!remoteConnection.isOpen()) { - return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), - NLS.bind(Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName())); + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS.bind( + Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName())); } } @@ -104,7 +104,8 @@ public class RemoteConnectionManager extends Job { String terminalShellCommand = prefs.get(IRemoteTerminalConstants.PREF_TERMINAL_SHELL_COMMAND, ""); //$NON-NLS-1$ if ("".equals(terminalShellCommand) //$NON-NLS-1$ && remoteConnection.hasService(IRemoteCommandShellService.class)) { - IRemoteCommandShellService cmdShellSvc = remoteConnection.getService(IRemoteCommandShellService.class); + IRemoteCommandShellService cmdShellSvc = remoteConnection + .getService(IRemoteCommandShellService.class); synchronized (this) { remoteProcess = cmdShellSvc.getCommandShell(IRemoteProcessBuilder.ALLOCATE_PTY); } @@ -117,7 +118,8 @@ public class RemoteConnectionManager extends Job { .getProcessBuilder(new ArgumentParser(terminalShellCommand).getTokenList()); remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY); } else { - return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), Messages.RemoteConnectionManager_2); + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), + Messages.RemoteConnectionManager_2); } } @@ -164,7 +166,7 @@ public class RemoteConnectionManager extends Job { /** * Read the data from the connection and display it in the terminal. - * + * * @param in * @throws IOException */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnector.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnector.java index 18b3ec59acc..5b79753f3c9 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnector.java @@ -38,7 +38,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /* * (non-Javadoc) - * + * * @see * org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#connect(org.eclipse.tm.internal.terminal. * provisional.api.ITerminalControl) @@ -53,7 +53,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /* * (non-Javadoc) - * + * * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#doDisconnect() */ @Override @@ -67,7 +67,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /* * (non-Javadoc) - * + * * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#getSettingsSummary() */ @Override @@ -77,7 +77,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /** * Return the Remote Settings. - * + * * @return the settings for a concrete connection. */ public IRemoteSettings getRemoteSettings() { @@ -86,7 +86,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /* * (non-Javadoc) - * + * * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#getTerminalToRemoteStream() */ @Override @@ -119,7 +119,7 @@ public class RemoteConnector extends TerminalConnectorImpl { /* * (non-Javadoc) - * + * * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#setTerminalSize(int, int) */ @Override diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettings.java index 37dae29bf91..1d880b1da0c 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettings.java @@ -1,9 +1,9 @@ /******************************************************************************* * Copyright (c) 2015, 2018 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ *******************************************************************************/ package org.eclipse.tm.terminal.connector.remote.internal; diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java index 8a5958027da..dbd3a5b48b3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java @@ -40,7 +40,8 @@ public class RemoteSettingsPage extends AbstractSettingsPage { if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) { if (fRemoteConnectionWidget.getConnection() != null) { if (fRemoteConnectionWidget.getConnection().getConnectionType() != null) { - fTerminalSettings.setConnectionTypeId(fRemoteConnectionWidget.getConnection().getConnectionType().getId()); + fTerminalSettings + .setConnectionTypeId(fRemoteConnectionWidget.getConnection().getConnectionType().getId()); } fTerminalSettings.setConnectionName(fRemoteConnectionWidget.getConnection().getName()); } @@ -50,7 +51,8 @@ public class RemoteSettingsPage extends AbstractSettingsPage { @Override public void loadSettings() { if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) { - fRemoteConnectionWidget.setConnection(fTerminalSettings.getConnectionTypeId(), fTerminalSettings.getConnectionName()); + fRemoteConnectionWidget.setConnection(fTerminalSettings.getConnectionTypeId(), + fTerminalSettings.getConnectionName()); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java index 32fb70edb39..32d77f4e0d7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java @@ -98,7 +98,8 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { private String getTerminalTitle(Map properties) { // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if (title != null) return title; + if (title != null) + return title; String connection = (String) properties.get(IRemoteSettings.CONNECTION_NAME); @@ -107,7 +108,7 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { String date = format.format(new Date(System.currentTimeMillis())); return NLS.bind(Messages.RemoteLauncherDelegate_terminalTitle, new String[] { connection, date }); } - + return Messages.RemoteLauncherDelegate_terminalTitle_default; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteMementoHandler.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteMementoHandler.java index 9b478cbc5c1..1fcd847e784 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteMementoHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteMementoHandler.java @@ -26,7 +26,7 @@ public class RemoteMementoHandler implements IMementoHandler { /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map) */ @Override @@ -37,14 +37,15 @@ public class RemoteMementoHandler implements IMementoHandler { // Do not write the terminal title to the memento -> needs to // be recreated at the time of restoration. memento.putString(IRemoteSettings.CONNECTION_NAME, (String) properties.get(IRemoteSettings.CONNECTION_NAME)); - memento.putString(IRemoteSettings.CONNECTION_TYPE_ID, (String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID)); + memento.putString(IRemoteSettings.CONNECTION_TYPE_ID, + (String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID)); memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); } /* * (non-Javadoc) - * + * * @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#restoreState(org.eclipse.ui.IMemento, java.util.Map) */ @Override @@ -55,6 +56,7 @@ public class RemoteMementoHandler implements IMementoHandler { // Restore the terminal properties from the memento properties.put(IRemoteSettings.CONNECTION_NAME, memento.getString(IRemoteSettings.CONNECTION_NAME)); properties.put(IRemoteSettings.CONNECTION_TYPE_ID, memento.getString(IRemoteSettings.CONNECTION_TYPE_ID)); - properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); + properties.put(ITerminalsConnectorConstants.PROP_ENCODING, + memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java index 5a209c22383..12862dc6601 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java @@ -23,7 +23,7 @@ public class Messages extends NLS { public static String RemoteTerminalPreferencePage_0; public static String TERMINAL_EXCEPTION; - + public static String RemoteLauncherDelegate_terminalTitle; public static String RemoteLauncherDelegate_terminalTitle_default; diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/activator/UIPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/activator/UIPlugin.java index 45b7e429d76..598f41ef17b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/activator/UIPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/activator/UIPlugin.java @@ -70,28 +70,28 @@ public class UIPlugin extends AbstractUIPlugin { return traceHandler; } - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- // - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- /* (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @SuppressWarnings("unchecked") - @Override - public void start(BundleContext context) throws Exception { + @Override + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null); - tracker.open(); + tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null); + tracker.open(); } /* (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { try { SshConnection.shutdown(); tracker.close(); @@ -106,13 +106,13 @@ public class UIPlugin extends AbstractUIPlugin { * @return An instance of IJSchService, or null if no * IJschService service is available. */ - public IJSchService getJSchService() { - return (IJSchService)tracker.getService(); - } + public IJSchService getJSchService() { + return (IJSchService) tracker.getService(); + } - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- // - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- /* (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry) diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshConstants.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshConstants.java index 2bcc30b4681..0d4bd371467 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshConstants.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshConstants.java @@ -10,17 +10,16 @@ * Contributors: * IBM Corporation - initial API and implementation * Martin Oberhuber (Wind River) - extracted from various team.cvs plugins - * Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API + * Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API *******************************************************************************/ package org.eclipse.tm.terminal.connector.ssh.connector; - /** * Defines the constants used by the terminal.ssh Plugin */ public interface ISshConstants { - // These are from cvs.ui.IHelpContextIds + // These are from cvs.ui.IHelpContextIds public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$ public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$ public static final String HELP_KEYBOARD_INTERACTIVE_DIALOG = CVSUIPREFIX + "keyboard_interactive_dialog_context"; //$NON-NLS-1$ diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshSettings.java index 939addb8116..65d2b0c69e4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/ISshSettings.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives @@ -18,26 +18,26 @@ public interface ISshSettings { public static int DEFAULT_SSH_PORT = 22; - /** + /** * Get the host name or IP address of remote system to connect. * @return host name or IP address of the remote system. - */ + */ String getHost(); /** * Get the login name for connecting to the remote system. * @return remote login name - */ + */ String getUser(); /** * Get the password for connecting to the remote system. * May be empty if connecting via SSH public key authentication * (with or without passphrase). - * @return password to use - */ + * @return password to use + */ String getPassword(); - + /** * Get the timeout (in seconds) after which the SSH connection is assumed dead. * @return timeout (in seconds) for the SSH connection. @@ -47,9 +47,9 @@ public interface ISshSettings { /** * Get the keepalive interval (in seconds). * After this time of inactivity, the SSH connector will send a message to the - * remote system in order to avoid timeouts on the remote. A maximum of 6 - * keepalive messages will be sent if enabled. When set to 0, the keepalive - * feature is disabled. + * remote system in order to avoid timeouts on the remote. A maximum of 6 + * keepalive messages will be sent if enabled. When set to 0, the keepalive + * feature is disabled. * @return interval (in seconds) for keepalive messages. */ int getKeepalive(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/KeyboardInteractiveDialog.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/KeyboardInteractiveDialog.java index 8e45799ff72..8cbff227e79 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/KeyboardInteractiveDialog.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/KeyboardInteractiveDialog.java @@ -33,161 +33,164 @@ import org.eclipse.ui.PlatformUI; * A dialog for keyboad-interactive authentication for the ssh2 connection. */ public class KeyboardInteractiveDialog extends TrayDialog { - // widgets - private Text[] texts; + // widgets + private Text[] texts; - protected String domain; - protected String destination; - protected String name; - protected String instruction; - protected String lang; - protected String[] prompt; - protected boolean[] echo; - private String message; - private String[] result; + protected String domain; + protected String destination; + protected String name; + protected String instruction; + protected String lang; + protected String[] prompt; + protected boolean[] echo; + private String message; + private String[] result; - /** - * Creates a nwe KeyboardInteractiveDialog. - * - * @param parentShell the parent shell - * @param connectionId an id for the connection - * @param destination the location - * @param name the name - * @param instruction the instruction - * @param prompt the titles for textfields - * @param echo '*' should be used or not - */ - public KeyboardInteractiveDialog(Shell parentShell, - String connectionId, - String destination, - String name, - String instruction, - String[] prompt, - boolean[] echo){ - super(parentShell); - this.domain=connectionId; - this.destination=destination; - this.name=name; - this.instruction=instruction; - this.prompt=prompt; - this.echo=echo; - this.message=NLS.bind(SshMessages.KeyboardInteractiveDialog_message, new String[] { destination+(name!=null && name.length()>0 ? ": "+name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ - } - /** - * @see Window#configureShell - */ - @Override -protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(message); - } - /** - * @see Window#create - */ - @Override -public void create() { - super.create(); - if(texts.length>0){ - texts[0].setFocus(); - } - } - /** - * @see Dialog#createDialogArea - */ - @Override -protected Control createDialogArea(Composite parent) { - Composite main=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); + /** + * Creates a nwe KeyboardInteractiveDialog. + * + * @param parentShell the parent shell + * @param connectionId an id for the connection + * @param destination the location + * @param name the name + * @param instruction the instruction + * @param prompt the titles for textfields + * @param echo '*' should be used or not + */ + public KeyboardInteractiveDialog(Shell parentShell, String connectionId, String destination, String name, + String instruction, String[] prompt, boolean[] echo) { + super(parentShell); + this.domain = connectionId; + this.destination = destination; + this.name = name; + this.instruction = instruction; + this.prompt = prompt; + this.echo = echo; + this.message = NLS.bind(SshMessages.KeyboardInteractiveDialog_message, + new String[] { destination + (name != null && name.length() > 0 ? ": " + name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ + } - // set F1 help - PlatformUI.getWorkbench().getHelpSystem().setHelp(main, ISshConstants.HELP_KEYBOARD_INTERACTIVE_DIALOG); + /** + * @see Window#configureShell + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(message); + } - if (message!=null) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - if(domain!=null){ - Label label = new Label(main, SWT.WRAP); - label.setText(NLS.bind(SshMessages.KeyboardInteractiveDialog_labelConnection, new String[] { domain })); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - label.setLayoutData(data); - } - if (instruction!=null && instruction.length()>0) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(instruction); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - createPasswordFields(main); - return main; - } - /** - * Creates the widgets that represent the entry area. - * - * @param parent the parent of the widgets - */ - @SuppressWarnings("unused") -protected void createPasswordFields(Composite parent) { - texts=new Text[prompt.length]; + /** + * @see Window#create + */ + @Override + public void create() { + super.create(); + if (texts.length > 0) { + texts[0].setFocus(); + } + } - for(int i=0; i - * The default implementation of this framework method sets - * this dialog's return code to Window.OK - * and closes the dialog. Subclasses may override. - *

- */ - @Override -protected void okPressed() { - result=new String[prompt.length]; - for(int i=0; i - * The default implementation of this framework method sets - * this dialog's return code to Window.CANCEL - * and closes the dialog. Subclasses may override. - *

- */ - @Override -protected void cancelPressed() { - result=null; - super.cancelPressed(); - } + if (message != null) { + Label messageLabel = new Label(main, SWT.WRAP); + messageLabel.setText(message); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + messageLabel.setLayoutData(data); + } + if (domain != null) { + Label label = new Label(main, SWT.WRAP); + label.setText(NLS.bind(SshMessages.KeyboardInteractiveDialog_labelConnection, new String[] { domain })); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + label.setLayoutData(data); + } + if (instruction != null && instruction.length() > 0) { + Label messageLabel = new Label(main, SWT.WRAP); + messageLabel.setText(instruction); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + messageLabel.setLayoutData(data); + } + createPasswordFields(main); + return main; + } + + /** + * Creates the widgets that represent the entry area. + * + * @param parent the parent of the widgets + */ + @SuppressWarnings("unused") + protected void createPasswordFields(Composite parent) { + texts = new Text[prompt.length]; + + for (int i = 0; i < prompt.length; i++) { + new Label(parent, SWT.NONE).setText(prompt[i]); + texts[i] = new Text(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + texts[i].setLayoutData(data); + + if (!echo[i]) { + texts[i].setEchoChar('*'); + } + new Label(parent, SWT.NONE); + } + + } + + /** + * Returns the entered values, or null + * if the user cancelled. + * + * @return the entered values + */ + public String[] getResult() { + return result; + } + + /** + * Notifies that the ok button of this dialog has been pressed. + *

+ * The default implementation of this framework method sets + * this dialog's return code to Window.OK + * and closes the dialog. Subclasses may override. + *

+ */ + @Override + protected void okPressed() { + result = new String[prompt.length]; + for (int i = 0; i < texts.length; i++) { + result[i] = texts[i].getText(); + } + super.okPressed(); + } + + /** + * Notifies that the cancel button of this dialog has been pressed. + *

+ * The default implementation of this framework method sets + * this dialog's return code to Window.CANCEL + * and closes the dialog. Subclasses may override. + *

+ */ + @Override + protected void cancelPressed() { + result = null; + super.cancelPressed(); + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnection.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnection.java index 954b76aa4ba..ee92426bfe1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnection.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnection.java @@ -54,8 +54,9 @@ public class SshConnection extends Thread { private final SshConnector fConn; private Session fSession; private boolean fDisconnectHasBeenCalled; - protected SshConnection(SshConnector conn,ITerminalControl control) { - super("SshConnection-"+fgNo++); //$NON-NLS-1$ + + protected SshConnection(SshConnector conn, ITerminalControl control) { + super("SshConnection-" + fgNo++); //$NON-NLS-1$ fControl = control; fConn = conn; fControl.setState(TerminalState.CONNECTING); @@ -72,19 +73,20 @@ public class SshConnection extends Thread { * the Jsch config (for instance, in order to switch off strict * host key checking or in order to add specific ciphers). */ - protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, IProgressMonitor monitor) throws JSchException { - IJSchService service = UIPlugin.getDefault().getJSchService(); - if (service == null) - return null; - Session session = service.createSession(hostname, port, username); - //session.setTimeout(getSshTimeoutInMillis()); - session.setTimeout(0); //never time out on the session - session.setServerAliveCountMax(6); //give up after 6 tries (remote will be dead after 30 min) - if (password != null) + protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, + IProgressMonitor monitor) throws JSchException { + IJSchService service = UIPlugin.getDefault().getJSchService(); + if (service == null) + return null; + Session session = service.createSession(hostname, port, username); + //session.setTimeout(getSshTimeoutInMillis()); + session.setTimeout(0); //never time out on the session + session.setServerAliveCountMax(6); //give up after 6 tries (remote will be dead after 30 min) + if (password != null) session.setPassword(password); - session.setUserInfo(wrapperUI); - return session; - } + session.setUserInfo(wrapperUI); + return session; + } public static void shutdown() { //TODO: Store all Jsch sessions in a pool and disconnect them on shutdown @@ -95,7 +97,7 @@ public class SshConnection extends Thread { //---------------------------------------------------------------------- @Override - public void run() { + public void run() { boolean connectSucceeded = false; String host = ""; //$NON-NLS-1$ int port = ISshSettings.DEFAULT_SSH_PORT; @@ -107,32 +109,31 @@ public class SshConnection extends Thread { String password = fConn.getSshSettings().getPassword(); port = fConn.getSshSettings().getPort(); - UserInfo ui=new MyUserInfo(null, user, password); + UserInfo ui = new MyUserInfo(null, user, password); - Session session = createSession(user, password, host, port, - ui, new NullProgressMonitor()); + Session session = createSession(user, password, host, port, ui, new NullProgressMonitor()); synchronized (this) { fSession = session; } - //java.util.Hashtable config=new java.util.Hashtable(); - //config.put("StrictHostKeyChecking", "no"); - //session.setConfig(config); - //ui.aboutToConnect(); - if (nKeepalive > 0) { - session.setServerAliveInterval(nKeepalive); //default is 5 minutes - } - // dont try to connect if disconnect has been requested already + //java.util.Hashtable config=new java.util.Hashtable(); + //config.put("StrictHostKeyChecking", "no"); + //session.setConfig(config); + //ui.aboutToConnect(); + if (nKeepalive > 0) { + session.setServerAliveInterval(nKeepalive); //default is 5 minutes + } + // dont try to connect if disconnect has been requested already synchronized (this) { if (fDisconnectHasBeenCalled) return; } - session.connect(nTimeout); // making connection with timeout. + session.connect(nTimeout); // making connection with timeout. // if we got disconnected, do not continue - if(!isSessionConnected()) + if (!isSessionConnected()) return; - ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$ + ChannelShell channel = (ChannelShell) session.openChannel("shell"); //$NON-NLS-1$ channel.setPtyType("xterm"); //$NON-NLS-1$ // TERM=xterm implies VT100 line wrapping mode fControl.setVT100LineWrapping(true); @@ -195,18 +196,19 @@ public class SshConnection extends Thread { void disconnect() { interrupt(); synchronized (this) { - fDisconnectHasBeenCalled=true; - if(fSession!=null) { + fDisconnectHasBeenCalled = true; + if (fSession != null) { try { fSession.disconnect(); } catch (Exception e) { // Ignore NPE due to bug in JSch if disconnecting // while not yet authenticated } - fSession=null; + fSession = null; } } } + /** * Read the data from the ssh connection and display it in the terminal. * @param in @@ -214,45 +216,47 @@ public class SshConnection extends Thread { */ private void readDataForever(InputStream in) throws IOException { // read the data - byte bytes[]=new byte[32*1024]; + byte bytes[] = new byte[32 * 1024]; int n; // read until the thread gets interrupted.... - while( (n=in.read(bytes))!=-1) { - fControl.getRemoteToTerminalOutputStream().write(bytes,0,n); + while ((n = in.read(bytes)) != -1) { + fControl.getRemoteToTerminalOutputStream().write(bytes, 0, n); } } protected static Display getStandardDisplay() { - Display display = Display.getCurrent(); - if( display==null ) { - display = Display.getDefault(); - } - return display; - } + Display display = Display.getCurrent(); + if (display == null) { + display = Display.getDefault(); + } + return display; + } - private class MyUserInfo implements UserInfo, UIKeyboardInteractive { - /* default */ final String fConnectionId; - /* default */ final String fUser; - private String fPassword; - private String fPassphrase; - private int fAttemptCount; + private class MyUserInfo implements UserInfo, UIKeyboardInteractive { + /* default */ final String fConnectionId; + /* default */ final String fUser; + private String fPassword; + private String fPassphrase; + private int fAttemptCount; public MyUserInfo(String connectionId, String user, String password) { fConnectionId = connectionId; fUser = user; fPassword = password; } + @Override - public String getPassword() { + public String getPassword() { return fPassword; } + @Override - public boolean promptYesNo(final String str) { + public boolean promptYesNo(final String str) { //need to switch to UI thread for prompting final boolean[] retval = new boolean[1]; Display.getDefault().syncExec(new Runnable() { @Override - public void run() { + public void run() { // [168197] Replace JFace MessagDialog by SWT MessageBox //retval[0] = MessageDialog.openQuestion(null, SshMessages.WARNING, str); if (isSessionConnected()) { @@ -267,11 +271,12 @@ public class SshConnection extends Thread { }); return retval[0]; } + private String promptSecret(final String message) { final String[] retval = new String[1]; getStandardDisplay().syncExec(new Runnable() { @Override - public void run() { + public void run() { if (isSessionConnected()) { UserValidationDialog uvd = new UserValidationDialog(null, fConnectionId, fUser, message); uvd.setUsernameMutable(false); @@ -287,29 +292,33 @@ public class SshConnection extends Thread { }); return retval[0]; } + @Override - public String getPassphrase() { + public String getPassphrase() { return fPassphrase; } + @Override - public boolean promptPassphrase(String message) { + public boolean promptPassphrase(String message) { fPassphrase = promptSecret(message); - return (fPassphrase!=null); + return (fPassphrase != null); } + @Override - public boolean promptPassword(final String message) { + public boolean promptPassword(final String message) { String _password = promptSecret(message); - if (_password!=null) { - fPassword=_password; - return true; - } + if (_password != null) { + fPassword = _password; + return true; + } return false; } + @Override - public void showMessage(final String message) { + public void showMessage(final String message) { Display.getDefault().syncExec(new Runnable() { @Override - public void run() { + public void run() { // [168197] Replace JFace MessagDialog by SWT MessageBox // MessageDialog.openInformation(null, SshMessages.INFO, message); if (isSessionConnected()) { @@ -321,50 +330,50 @@ public class SshConnection extends Thread { } }); } + @Override - public String[] promptKeyboardInteractive(final String destination, - final String name, final String instruction, - final String[] prompt, final boolean[] echo) - { - if (prompt.length == 0) { - // No need to prompt, just return an empty String array - return new String[0]; - } - try{ - if (fAttemptCount == 0 && fPassword != null && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ - // Return the provided password the first time but always prompt on subsequent tries - fAttemptCount++; - return new String[] { fPassword }; - } - final String[][] finResult = new String[1][]; - getStandardDisplay().syncExec(new Runnable() { - @Override - public void run() { - if (isSessionConnected()) { - KeyboardInteractiveDialog dialog = new KeyboardInteractiveDialog(null, fConnectionId, destination, name, instruction, prompt, echo); + public String[] promptKeyboardInteractive(final String destination, final String name, final String instruction, + final String[] prompt, final boolean[] echo) { + if (prompt.length == 0) { + // No need to prompt, just return an empty String array + return new String[0]; + } + try { + if (fAttemptCount == 0 && fPassword != null && prompt.length == 1 + && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ + // Return the provided password the first time but always prompt on subsequent tries + fAttemptCount++; + return new String[] { fPassword }; + } + final String[][] finResult = new String[1][]; + getStandardDisplay().syncExec(new Runnable() { + @Override + public void run() { + if (isSessionConnected()) { + KeyboardInteractiveDialog dialog = new KeyboardInteractiveDialog(null, fConnectionId, + destination, name, instruction, prompt, echo); dialog.open(); finResult[0] = dialog.getResult(); } else { finResult[0] = null; // indicate cancel to JSch } - } - }); - String[] result=finResult[0]; - if (result == null) - return null; // cancelled - if (result.length == 1 && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ - fPassword = result[0]; - } - fAttemptCount++; + } + }); + String[] result = finResult[0]; + if (result == null) + return null; // cancelled + if (result.length == 1 && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ + fPassword = result[0]; + } + fAttemptCount++; return result; - } - catch(OperationCanceledException e){ + } catch (OperationCanceledException e) { return null; } } - } + } - private void connectFailed(String terminalText, String msg) { + private void connectFailed(String terminalText, String msg) { Logger.log(terminalText); fControl.displayTextInTerminal(terminalText); // fControl.setMsg(msg); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnector.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnector.java index e940feafdb3..a402fdc8b70 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshConnector.java @@ -36,24 +36,29 @@ public class SshConnector extends TerminalConnectorImpl { private final SshSettings fSettings; private int fWidth; private int fHeight; + public SshConnector() { this(new SshSettings()); } + public SshConnector(SshSettings settings) { - fSettings=settings; + fSettings = settings; } + @Override - public void initialize() throws Exception { - fJsch=new JSch(); + public void initialize() throws Exception { + fJsch = new JSch(); } + @Override - public void connect(ITerminalControl control) { + public void connect(ITerminalControl control) { super.connect(control); - fConnection = new SshConnection(this,control); + fConnection = new SshConnection(this, control); fConnection.start(); } + @Override - synchronized public void doDisconnect() { + synchronized public void doDisconnect() { fConnection.disconnect(); if (getInputStream() != null) { try { @@ -71,28 +76,34 @@ public class SshConnector extends TerminalConnectorImpl { } } } + @Override - public void setTerminalSize(int newWidth, int newHeight) { - if(fChannel!=null && (newWidth!=fWidth || newHeight!=fHeight)) { + public void setTerminalSize(int newWidth, int newHeight) { + if (fChannel != null && (newWidth != fWidth || newHeight != fHeight)) { //avoid excessive communications due to change size requests by caching previous size - fChannel.setPtySize(newWidth, newHeight, 8*newWidth, 8*newHeight); - fWidth=newWidth; - fHeight=newHeight; + fChannel.setPtySize(newWidth, newHeight, 8 * newWidth, 8 * newHeight); + fWidth = newWidth; + fHeight = newHeight; } } + public InputStream getInputStream() { return fInputStream; } + @Override - public OutputStream getTerminalToRemoteStream() { + public OutputStream getTerminalToRemoteStream() { return fOutputStream; } + void setInputStream(InputStream inputStream) { fInputStream = inputStream; } + void setOutputStream(OutputStream outputStream) { fOutputStream = outputStream; } + /** * Return the SSH Settings. * @@ -102,31 +113,38 @@ public class SshConnector extends TerminalConnectorImpl { public ISshSettings getSshSettings() { return fSettings; } + @Override public void setDefaultSettings() { fSettings.load(new NullSettingsStore()); } + @Override - public String getSettingsSummary() { + public String getSettingsSummary() { return fSettings.getSummary(); } + @Override - public void load(ISettingsStore store) { + public void load(ISettingsStore store) { fSettings.load(store); } + @Override - public void save(ISettingsStore store) { + public void save(ISettingsStore store) { fSettings.save(store); } + protected JSch getJsch() { return fJsch; } + ChannelShell getChannel() { return fChannel; } + void setChannel(ChannelShell channel) { fChannel = channel; - fWidth=-1; - fHeight=-1; + fWidth = -1; + fHeight = -1; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.java index 74f0334e6e8..3e8bf0cc648 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.java @@ -59,7 +59,7 @@ public class SshMessages extends NLS { public static String java_net_SocketException; public static String java_net_NoRouteToHostException; - // + // public static String getMessageFor(Throwable throwable) { String message = getMessage(getMessageKey(throwable)); @@ -96,4 +96,4 @@ public class SshMessages extends NLS { // - } +} diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.properties b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.properties index 70588e272be..70d31247c9e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshMessages.properties @@ -8,7 +8,7 @@ # SPDX-License-Identifier: EPL-2.0 # # Contributors: -# Michael Scharf (Wind River) - initial API and implementation +# Michael Scharf (Wind River) - initial API and implementation # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives # Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting (Adopting code from org.eclipse.team.cvs.core) @@ -52,4 +52,4 @@ java_net_UnknownHostException=Cannot locate host: {0} java_net_ConnectException=Cannot connect to host: {0} java_net_SocketException=Socket Exception: {0} java_net_NoRouteToHostException={0} -# from org.eclipse.team.cvs.core +#
from org.eclipse.team.cvs.core diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettings.java index f39e8c6460f..ea8ad058fbd 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettings.java @@ -19,14 +19,15 @@ package org.eclipse.tm.terminal.connector.ssh.connector; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; public class SshSettings implements ISshSettings { - protected String fHost; - protected String fUser; - protected String fPassword; - protected String fPort; - protected String fTimeout; - protected String fKeepalive; + protected String fHost; + protected String fUser; + protected String fPassword; + protected String fPort; + protected String fTimeout; + protected String fKeepalive; + @Override - public String getHost() { + public String getHost() { return fHost; } @@ -35,16 +36,16 @@ public class SshSettings implements ISshSettings { } @Override - public String getSummary() { - String settings = getUser()+'@'+getHost(); - if(getPort()!=ISshSettings.DEFAULT_SSH_PORT) { + public String getSummary() { + String settings = getUser() + '@' + getHost(); + if (getPort() != ISshSettings.DEFAULT_SSH_PORT) { settings += ":" + getPort(); //$NON-NLS-1$ } return settings; } @Override - public void load(ISettingsStore store) { + public void load(ISettingsStore store) { fHost = store.get("Host", "");//$NON-NLS-1$ //$NON-NLS-2$ fUser = store.get("User", "");//$NON-NLS-1$ //$NON-NLS-2$ // ISettingsStore providers have to make sure that @@ -57,7 +58,7 @@ public class SshSettings implements ISshSettings { } @Override - public void save(ISettingsStore store) { + public void save(ISettingsStore store) { store.put("Host", fHost);//$NON-NLS-1$ store.put("User", fUser);//$NON-NLS-1$ store.put("Port", fPort);//$NON-NLS-1$ @@ -68,15 +69,15 @@ public class SshSettings implements ISshSettings { store.put("Keepalive", fKeepalive);//$NON-NLS-1$ } - @Override - public int getTimeout() { + public int getTimeout() { try { return Integer.parseInt(fTimeout); } catch (NumberFormatException numberFormatException) { return 10; } } + public String getTimeoutString() { return fTimeout; } @@ -86,13 +87,14 @@ public class SshSettings implements ISshSettings { } @Override - public int getKeepalive() { + public int getKeepalive() { try { return Integer.parseInt(fKeepalive); } catch (NumberFormatException numberFormatException) { return 300; } } + public String getKeepaliveString() { return fKeepalive; } @@ -102,15 +104,16 @@ public class SshSettings implements ISshSettings { } @Override - public String getUser() { + public String getUser() { return fUser; } public void setUser(String user) { fUser = user; } + @Override - public int getPort() { + public int getPort() { try { return Integer.parseInt(fPort); } catch (NumberFormatException numberFormatException) { @@ -127,7 +130,7 @@ public class SshSettings implements ISshSettings { } @Override - public String getPassword() { + public String getPassword() { return fPassword; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettingsPage.java index 02b9428e9a8..043ea44c959 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/SshSettingsPage.java @@ -37,10 +37,11 @@ public class SshSettingsPage extends AbstractSettingsPage { private Text fPassword; public SshSettingsPage(SshSettings settings) { - fTerminalSettings=settings; + fTerminalSettings = settings; } + @Override - public void saveSettings() { + public void saveSettings() { fTerminalSettings.setHost(fHostText.getText()); fTerminalSettings.setUser(fUser.getText()); fTerminalSettings.setPassword(fPassword.getText()); @@ -50,23 +51,25 @@ public class SshSettingsPage extends AbstractSettingsPage { } @Override - public void loadSettings() { - if(fTerminalSettings!=null) { - fHostText.setText(get(fTerminalSettings.getHost(),""));//$NON-NLS-1$ - fTimeout.setText(get(fTerminalSettings.getTimeoutString(),"0"));//$NON-NLS-1$ - fKeepalive.setText(get(fTerminalSettings.getKeepaliveString(),"300"));//$NON-NLS-1$ - fUser.setText(get(fTerminalSettings.getUser(),""));//$NON-NLS-1$ + public void loadSettings() { + if (fTerminalSettings != null) { + fHostText.setText(get(fTerminalSettings.getHost(), ""));//$NON-NLS-1$ + fTimeout.setText(get(fTerminalSettings.getTimeoutString(), "0"));//$NON-NLS-1$ + fKeepalive.setText(get(fTerminalSettings.getKeepaliveString(), "300"));//$NON-NLS-1$ + fUser.setText(get(fTerminalSettings.getUser(), ""));//$NON-NLS-1$ fPort.setText(get(fTerminalSettings.getPortString(), String.valueOf(ISshSettings.DEFAULT_SSH_PORT))); - fPassword.setText(get(fTerminalSettings.getPassword(),""));//$NON-NLS-1$ + fPassword.setText(get(fTerminalSettings.getPassword(), ""));//$NON-NLS-1$ } } + String get(String value, String def) { - if(value==null || value.length()==0) + if (value == null || value.length() == 0) return def; return value; } + @Override - public boolean validateSettings() { + public boolean validateSettings() { String message = null; int messageType = IMessageProvider.NONE; boolean valid = true; @@ -75,7 +78,10 @@ public class SshSettingsPage extends AbstractSettingsPage { String m = "Please enter a host IP or name."; //$NON-NLS-1$ int mt = IMessageProvider.INFORMATION; updateControlDecoration(fHostText, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -85,7 +91,10 @@ public class SshSettingsPage extends AbstractSettingsPage { String m = "Please enter a username."; //$NON-NLS-1$ int mt = IMessageProvider.INFORMATION; updateControlDecoration(fUser, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -97,7 +106,10 @@ public class SshSettingsPage extends AbstractSettingsPage { String m = "Invalid network port. Must be between 0 and 65535."; //$NON-NLS-1$ int mt = IMessageProvider.ERROR; updateControlDecoration(fPort, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -108,7 +120,10 @@ public class SshSettingsPage extends AbstractSettingsPage { String m = "Invalid timeout. Must be greater than 0."; //$NON-NLS-1$ int mt = IMessageProvider.ERROR; updateControlDecoration(fTimeout, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -119,7 +134,10 @@ public class SshSettingsPage extends AbstractSettingsPage { String m = "Invalid keep alive. Must be greater than 0."; //$NON-NLS-1$ int mt = IMessageProvider.ERROR; updateControlDecoration(fKeepalive, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -132,8 +150,9 @@ public class SshSettingsPage extends AbstractSettingsPage { setMessage(message, messageType); return valid; } + @Override - public void createControl(Composite parent) { + public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); @@ -144,13 +163,14 @@ public class SshSettingsPage extends AbstractSettingsPage { fHostText = createTextField(composite, SshMessages.HOST); fUser = createTextField(composite, SshMessages.USER); - fPassword = createTextField(composite, SshMessages.PASSWORD,SWT.PASSWORD); + fPassword = createTextField(composite, SshMessages.PASSWORD, SWT.PASSWORD); fTimeout = createTextField(composite, SshMessages.TIMEOUT); fKeepalive = createTextField(composite, SshMessages.KEEPALIVE); fKeepalive.setToolTipText(SshMessages.KEEPALIVE_Tooltip); fPort = createTextField(composite, SshMessages.PORT); loadSettings(); } + private Text createTextField(Composite composite, String labelTxt, int textOptions) { GridData gridData; // Add label @@ -159,17 +179,18 @@ public class SshSettingsPage extends AbstractSettingsPage { // Add control gridData = new GridData(GridData.FILL_HORIZONTAL); - final Text text= new Text(composite, SWT.BORDER | textOptions); + final Text text = new Text(composite, SWT.BORDER | textOptions); text.setLayoutData(gridData); text.addModifyListener(new ModifyListener() { @Override - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent e) { fireListeners(text); } }); createControlDecoration(text); return text; } + private Text createTextField(Composite composite, String labelTxt) { return createTextField(composite, labelTxt, 0); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/UserValidationDialog.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/UserValidationDialog.java index ba862db7d15..8047ac91579 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/UserValidationDialog.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/connector/UserValidationDialog.java @@ -62,26 +62,28 @@ public class UserValidationDialog extends TrayDialog { */ public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); + setShellStyle(getShellStyle() | SWT.RESIZE); this.defaultUsername = defaultName; this.domain = location; this.message = message; } + /** * @see Window#configureShell */ @Override - protected void configureShell(Shell newShell) { + protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(SshMessages.UserValidationDialog_required); // set F1 help - PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, ISshConstants.HELP_USER_VALIDATION_DIALOG); + PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, ISshConstants.HELP_USER_VALIDATION_DIALOG); } + /** * @see Window#create */ @Override - public void create() { + public void create() { super.create(); // add some default values usernameField.setText(defaultUsername); @@ -100,7 +102,7 @@ public class UserValidationDialog extends TrayDialog { * @see Dialog#createDialogArea */ @Override - protected Control createDialogArea(Composite parent) { + protected Control createDialogArea(Composite parent) { Composite top = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; @@ -142,7 +144,8 @@ public class UserValidationDialog extends TrayDialog { if (isUsernameMutable) { label.setText(NLS.bind(SshMessages.UserValidationDialog_labelUser, new String[] { domain })); } else { - label.setText(NLS.bind(SshMessages.UserValidationDialog_labelPassword, (new Object[]{defaultUsername, domain}))); + label.setText(NLS.bind(SshMessages.UserValidationDialog_labelPassword, + (new Object[] { defaultUsername, domain }))); } data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); data.horizontalSpan = 2; @@ -152,7 +155,7 @@ public class UserValidationDialog extends TrayDialog { createUsernameFields(main); createPasswordFields(main); - if(domain != null) { + if (domain != null) { allowCachingButton = new Button(main, SWT.CHECK); allowCachingButton.setText(SshMessages.UserValidationDialog_6); data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); @@ -160,7 +163,7 @@ public class UserValidationDialog extends TrayDialog { allowCachingButton.setLayoutData(data); allowCachingButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { allowCaching = allowCachingButton.getSelection(); } }); @@ -175,7 +178,8 @@ public class UserValidationDialog extends TrayDialog { warningComposite.setLayoutData(data); Label warningLabel = new Label(warningComposite, SWT.NONE); warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); - warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); + warningLabel.setLayoutData( + new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); Label warningText = new Label(warningComposite, SWT.WRAP); warningText.setText(SshMessages.UserValidationDialog_7); data = new GridData(GridData.FILL_HORIZONTAL); @@ -183,7 +187,7 @@ public class UserValidationDialog extends TrayDialog { warningText.setLayoutData(data); } - Dialog.applyDialogFont(parent); + Dialog.applyDialogFont(parent); return main; } @@ -202,6 +206,7 @@ public class UserValidationDialog extends TrayDialog { data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); passwordField.setLayoutData(data); } + /** * Creates the three widgets that represent the user name entry area. * @@ -255,12 +260,13 @@ public class UserValidationDialog extends TrayDialog { *

*/ @Override - protected void okPressed() { + protected void okPressed() { password = passwordField.getText(); username = usernameField.getText(); super.okPressed(); } + /** * Sets whether or not the username field should be mutable. * This method must be called before create(), otherwise it @@ -276,8 +282,8 @@ public class UserValidationDialog extends TrayDialog { * @see org.eclipse.jface.dialogs.Dialog#close() */ @Override - public boolean close() { - if(keyLockImage != null) { + public boolean close() { + if (keyLockImage != null) { keyLockImage.dispose(); } return super.close(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/controls/SshWizardConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/controls/SshWizardConfigurationPanel.java index 779b4c718d0..acda0b3d9f4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/controls/SshWizardConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/controls/SshWizardConfigurationPanel.java @@ -50,7 +50,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa private static final String SAVE_USER = "saveUser"; //$NON-NLS-1$ private static final String SAVE_PASSWORD = "savePassword"; //$NON-NLS-1$ - private SshSettings sshSettings; + private SshSettings sshSettings; private ISettingsPage sshSettingsPage; private Button userButton; private Button passwordButton; @@ -61,8 +61,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa * @param container The configuration panel container or null. */ public SshWizardConfigurationPanel(IConfigurationPanelContainer container) { - super(container); - } + super(container); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) @@ -75,7 +75,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa panel.setLayoutData(data); // Create the host selection combo - if (isWithoutSelection()) createHostsUI(panel, true); + if (isWithoutSelection()) + createHostsUI(panel, true); SshConnector conn = new SshConnector(); sshSettings = (SshSettings) conn.getSshSettings(); @@ -84,7 +85,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa sshSettingsPage = new SshSettingsPage(sshSettings); if (sshSettingsPage instanceof AbstractSettingsPage) { - ((AbstractSettingsPage)sshSettingsPage).setHasControlDecoration(true); + ((AbstractSettingsPage) sshSettingsPage).setHasControlDecoration(true); } sshSettingsPage.createControl(panel); @@ -92,7 +93,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa sshSettingsPage.addListener(new ISettingsPage.Listener() { @Override public void onSettingsPageChanged(Control control) { - if (getContainer() != null) getContainer().validate(); + if (getContainer() != null) + getContainer().validate(); } }); @@ -110,34 +112,42 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa */ @Override public void setupData(Map data) { - if (data == null || sshSettings == null || sshSettingsPage == null) return; + if (data == null || sshSettings == null || sshSettingsPage == null) + return; - String value = (String)data.get(ITerminalsConnectorConstants.PROP_IP_HOST); - if (value != null) sshSettings.setHost(value); + String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST); + if (value != null) + sshSettings.setHost(value); Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT); value = v != null ? v.toString() : null; - if (value != null) sshSettings.setPort(value); + if (value != null) + sshSettings.setPort(value); v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT); value = v != null ? v.toString() : null; - if (value != null) sshSettings.setTimeout(value); + if (value != null) + sshSettings.setTimeout(value); v = data.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE); value = v != null ? v.toString() : null; - if (value != null) sshSettings.setKeepalive(value); + if (value != null) + sshSettings.setKeepalive(value); - value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); - if (value != null) sshSettings.setPassword(value); + value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); + if (value != null) + sshSettings.setPassword(value); - value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_USER); - if (value != null) sshSettings.setUser(value); + value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_USER); + if (value != null) + sshSettings.setUser(value); - value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING); - if (value != null) setEncoding(value); + value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING); + if (value != null) + setEncoding(value); sshSettingsPage.loadSettings(); - } + } /** * Returns the default user name. @@ -151,7 +161,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element); if (provider != null) { Object user = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_USER); - if (user instanceof String) return ((String) user).trim(); + if (user instanceof String) + return ((String) user).trim(); } } @@ -163,20 +174,22 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa */ @Override public void extractData(Map data) { - if (data == null) return; + if (data == null) + return; - // set the terminal connector id for ssh - data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.ssh.SshConnector"); //$NON-NLS-1$ + // set the terminal connector id for ssh + data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, + "org.eclipse.tm.terminal.connector.ssh.SshConnector"); //$NON-NLS-1$ - sshSettingsPage.saveSettings(); - data.put(ITerminalsConnectorConstants.PROP_IP_HOST,sshSettings.getHost()); + sshSettingsPage.saveSettings(); + data.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost()); data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(sshSettings.getPort())); data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(sshSettings.getTimeout())); data.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.valueOf(sshSettings.getKeepalive())); data.put(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, sshSettings.getPassword()); data.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser()); data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding()); - } + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) @@ -185,8 +198,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa protected void fillSettingsForHost(String host) { boolean saveUser = true; boolean savePassword = false; - if (host != null && host.length() != 0){ - if (hostSettingsMap.containsKey(host)){ + if (host != null && host.length() != 0) { + if (hostSettingsMap.containsKey(host)) { Map hostSettings = hostSettingsMap.get(host); if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) { sshSettings.setHost(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST)); @@ -206,7 +219,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa if (hostSettings.get(SAVE_PASSWORD) != null) { savePassword = new Boolean(hostSettings.get(SAVE_PASSWORD)).booleanValue(); } - if (!savePassword){ + if (!savePassword) { sshSettings.setPassword(""); //$NON-NLS-1$ } else { String password = accessSecurePassword(sshSettings.getHost()); @@ -218,7 +231,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa String encoding = hostSettings.get(ITerminalsConnectorConstants.PROP_ENCODING); if (encoding == null || "null".equals(encoding)) { //$NON-NLS-1$ String defaultEncoding = getSelectionEncoding(); - encoding = defaultEncoding != null && !"".equals(defaultEncoding.trim()) ? defaultEncoding.trim() : "ISO-8859-1"; //$NON-NLS-1$ //$NON-NLS-2$ + encoding = defaultEncoding != null && !"".equals(defaultEncoding.trim()) ? defaultEncoding.trim() //$NON-NLS-1$ + : "ISO-8859-1"; //$NON-NLS-1$ } setEncoding(encoding); } else { @@ -238,10 +252,10 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa * @see org.eclipse.tm.terminal.view.ui.panels.AbstractExtendedConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) */ @Override - public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { - saveSettingsForHost(true); - super.doSaveWidgetValues(settings, idPrefix); - } + public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { + saveSettingsForHost(true); + super.doSaveWidgetValues(settings, idPrefix); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) @@ -252,20 +266,20 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa boolean savePassword = passwordButton.getSelection(); String host = getHostFromSettings(); if (host != null && host.length() != 0) { - if (hostSettingsMap.containsKey(host)){ + if (hostSettingsMap.containsKey(host)) { Map hostSettings = hostSettingsMap.get(host); hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost()); hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort())); hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout())); - hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive())); + hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, + Integer.toString(sshSettings.getKeepalive())); if (saveUser) { if (sshSettings.getUser() != null) { hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser()); } else { hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER); } - } - else { + } else { hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER); } @@ -280,18 +294,20 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa hostSettings.put(SAVE_USER, Boolean.toString(saveUser)); hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword)); - if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){ + if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0) { saveSecurePassword(host, sshSettings.getPassword()); } // maybe unchecked the password button - so try to remove a saved password - if any - if (!savePassword) removeSecurePassword(host); + if (!savePassword) + removeSecurePassword(host); } else if (add) { Map hostSettings = new HashMap(); hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost()); hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort())); hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout())); - hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive())); + hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, + Integer.toString(sshSettings.getKeepalive())); if (saveUser) { if (sshSettings.getUser() != null) { hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser()); @@ -302,7 +318,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword)); hostSettingsMap.put(host, hostSettings); - if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){ + if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0) { saveSecurePassword(host, sshSettings.getPassword()); } } @@ -328,8 +344,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa if (node != null) { try { node.put("password", password, true); //$NON-NLS-1$ - } - catch (StorageException ex) { /* ignored on purpose */ } + } catch (StorageException ex) { + /* ignored on purpose */ } } } } @@ -353,8 +369,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa String password = null; try { password = node.get("password", null); //$NON-NLS-1$ - } - catch (StorageException ex) { /* ignored on purpose */ } + } catch (StorageException ex) { + /* ignored on purpose */ } return password; } @@ -385,7 +401,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() */ @Override - public boolean isValid(){ + public boolean isValid() { return isEncodingValid() && sshSettingsPage.validateSettings(); } @@ -393,10 +409,10 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() */ @Override - protected String getHostFromSettings() { + protected String getHostFromSettings() { sshSettingsPage.saveSettings(); - return sshSettings.getHost(); - } + return sshSettings.getHost(); + } private void createSaveButtonsUI(final Composite parent, boolean separator) { Assert.isNotNull(parent); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java index 9de83a43739..6b43937b9c0 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java @@ -92,24 +92,26 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate { * * @return The terminal title string or null. */ - private String getTerminalTitle(Map properties) { + private String getTerminalTitle(Map properties) { // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if (title != null) return title; + if (title != null) + return title; //No title,try to calculate the title - String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); - String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER); + String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); + String user = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER); Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT); String port = value != null ? value.toString() : null; - if (host != null && user!= null) { + if (host != null && user != null) { DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String date = format.format(new Date(System.currentTimeMillis())); if (port != null && Integer.valueOf(port).intValue() != ISshSettings.DEFAULT_SSH_PORT) { - return NLS.bind(Messages.SshLauncherDelegate_terminalTitle_port, new String[]{user, host, port, date}); + return NLS.bind(Messages.SshLauncherDelegate_terminalTitle_port, + new String[] { user, host, port, date }); } - return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[]{user, host, date}); + return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[] { user, host, date }); } return Messages.SshLauncherDelegate_terminalTitle_default; @@ -118,40 +120,42 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate { /* (non-Javadoc) * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) */ - @Override + @Override public Object getAdapter(Class adapter) { if (IMementoHandler.class.equals(adapter)) { return mementoHandler; } - return super.getAdapter(adapter); + return super.getAdapter(adapter); } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) */ - @Override + @Override public ITerminalConnector createTerminalConnector(Map properties) { - Assert.isNotNull(properties); + Assert.isNotNull(properties); - // Check for the terminal connector id - String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.ssh.SshConnector"; //$NON-NLS-1$ + // Check for the terminal connector id + String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + if (connectorId == null) + connectorId = "org.eclipse.tm.terminal.connector.ssh.SshConnector"; //$NON-NLS-1$ // Extract the ssh properties - String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); + String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT); String port = value != null ? value.toString() : null; value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT); String timeout = value != null ? value.toString() : null; value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE); String keepAlive = value != null ? value.toString() : null; - String password = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); - String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER); + String password = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); + String user = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER); int portOffset = 0; if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) { - portOffset = ((Integer)properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue(); - if (portOffset < 0) portOffset = 0; + portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue(); + if (portOffset < 0) + portOffset = 0; } // The real port to connect to is port + portOffset diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshMementoHandler.java b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshMementoHandler.java index 76cf961d282..b7b5f4b65f1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshMementoHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshMementoHandler.java @@ -26,7 +26,6 @@ import org.eclipse.ui.IMemento; */ public class SshMementoHandler implements IMementoHandler { - /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map) */ @@ -37,15 +36,21 @@ public class SshMementoHandler implements IMementoHandler { // Do not write the terminal title to the memento -> needs to // be recreated at the time of restoration. - memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST)); + memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, + (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST)); Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT); - memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, value instanceof Integer ? ((Integer)value).intValue() : -1); + memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, + value instanceof Integer ? ((Integer) value).intValue() : -1); value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT); - memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, value instanceof Integer ? ((Integer)value).intValue() : -1); + memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, + value instanceof Integer ? ((Integer) value).intValue() : -1); value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE); - memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, value instanceof Integer ? ((Integer)value).intValue() : -1); - memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER, (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER)); - memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); + memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, + value instanceof Integer ? ((Integer) value).intValue() : -1); + memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER, + (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER)); + memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, + (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); // The password is stored within the Eclipse secure preferences -> no need to store it to the memento // @@ -55,22 +60,22 @@ public class SshMementoHandler implements IMementoHandler { String password = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); if (password != null) { try { - // Generate a temporary key. In practice, you would save this key. - // See also Encrypting with DES Using a Pass Phrase. - // SecretKey key = KeyGenerator.getInstance("DESede").generateKey(); + // Generate a temporary key. In practice, you would save this key. + // See also Encrypting with DES Using a Pass Phrase. + // SecretKey key = KeyGenerator.getInstance("DESede").generateKey(); SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); //$NON-NLS-1$ SecretKey key = factory.generateSecret(new DESKeySpec((ITerminalsConnectorConstants.PROP_SSH_PASSWORD + ".SshMementoHandler").getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ - Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$ - cipher.init(Cipher.ENCRYPT_MODE, key); + Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$ + cipher.init(Cipher.ENCRYPT_MODE, key); - String encrypedPwd = new String(Base64.encode(cipher.doFinal(password.getBytes("UTF-8")))); //$NON-NLS-1$ - memento.putString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, encrypedPwd); - } - catch (Exception e) { - if (Platform.inDebugMode()) e.printStackTrace(); - } + String encrypedPwd = new String(Base64.encode(cipher.doFinal(password.getBytes("UTF-8")))); //$NON-NLS-1$ + memento.putString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, encrypedPwd); + } + catch (Exception e) { + if (Platform.inDebugMode()) e.printStackTrace(); + } } */ } @@ -84,50 +89,57 @@ public class SshMementoHandler implements IMementoHandler { Assert.isNotNull(properties); // Restore the terminal properties from the memento - properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST)); - properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT)); - properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT)); - properties.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, memento.getInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE)); - properties.put(ITerminalsConnectorConstants.PROP_SSH_USER, memento.getString(ITerminalsConnectorConstants.PROP_SSH_USER)); - properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); + properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, + memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST)); + properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, + memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT)); + properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, + memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT)); + properties.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, + memento.getInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE)); + properties.put(ITerminalsConnectorConstants.PROP_SSH_USER, + memento.getString(ITerminalsConnectorConstants.PROP_SSH_USER)); + properties.put(ITerminalsConnectorConstants.PROP_ENCODING, + memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); // The password is stored within the Eclipse secure preferences -> restore it from there // To access the secure storage, we need the preference instance String password = null; ISecurePreferences preferences = SecurePreferencesFactory.getDefault(); - if (preferences != null && (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) { + if (preferences != null && (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) { // Construct the secure preferences node key - String nodeKey = "/Target Explorer SSH Password/" + (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); //$NON-NLS-1$ + String nodeKey = "/Target Explorer SSH Password/" //$NON-NLS-1$ + + (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); ISecurePreferences node = preferences.node(nodeKey); if (node != null) { try { password = node.get("password", null); //$NON-NLS-1$ - } - catch (StorageException ex) { /* ignored on purpose */ } + } catch (StorageException ex) { + /* ignored on purpose */ } } } // Example of restoring the password from an 3DES encrypted string. Do not remove! /* - String encrypedPwd = memento.getString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); - if (encrypedPwd != null) { - try { - SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); //$NON-NLS-1$ - SecretKey key = factory.generateSecret(new DESKeySpec((ITerminalsConnectorConstants.PROP_SSH_PASSWORD + ".SshMementoHandler").getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ + String encrypedPwd = memento.getString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD); + if (encrypedPwd != null) { + try { + SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); //$NON-NLS-1$ + SecretKey key = factory.generateSecret(new DESKeySpec((ITerminalsConnectorConstants.PROP_SSH_PASSWORD + ".SshMementoHandler").getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ - Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$ - cipher.init(Cipher.DECRYPT_MODE, key); + Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$ + cipher.init(Cipher.DECRYPT_MODE, key); - byte[] encBytes = Base64.decode(encrypedPwd.getBytes("UTF-8")); //$NON-NLS-1$ - byte[] decBytes = cipher.doFinal(encBytes); + byte[] encBytes = Base64.decode(encrypedPwd.getBytes("UTF-8")); //$NON-NLS-1$ + byte[] decBytes = cipher.doFinal(encBytes); - password = new String(decBytes); - } - catch (Exception e) { - if (Platform.inDebugMode()) e.printStackTrace(); - } - } - */ + password = new String(decBytes); + } + catch (Exception e) { + if (Platform.inDebugMode()) e.printStackTrace(); + } + } + */ properties.put(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, password); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/activator/UIPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/activator/UIPlugin.java index 0f7a167df9c..a3fc1a3afaa 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/activator/UIPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/activator/UIPlugin.java @@ -69,7 +69,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -78,7 +78,7 @@ public class UIPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/ITelnetSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/ITelnetSettings.java index 901f06ac34b..b59413ca745 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/ITelnetSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/ITelnetSettings.java @@ -30,13 +30,19 @@ public interface ITelnetSettings { static final String EOL_CRLF = "CR+LF"; //$NON-NLS-1$ String getHost(); + int getNetworkPort(); + int getTimeout(); + /** * @since 4.2 */ String getEndOfLine(); + String getSummary(); + void load(ISettingsStore store); + void save(ISettingsStore store); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/NetworkPortMap.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/NetworkPortMap.java index 87687c231de..f72c5f73fe4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/NetworkPortMap.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/NetworkPortMap.java @@ -22,17 +22,15 @@ import java.util.ArrayList; import java.util.List; public class NetworkPortMap { - public static final String PROP_NAMETGTCONS = "tgtcons"; //$NON-NLS-1$ - public static final String PROP_NAMETELNET = "telnet"; //$NON-NLS-1$ - public static final String PROP_VALUENET = "1233"; //$NON-NLS-1$ - public static final String PROP_VALUETGTCONS = "1232"; //$NON-NLS-1$ - public static final String PROP_VALUETELNET = "23"; //$NON-NLS-1$ + public static final String PROP_NAMETGTCONS = "tgtcons"; //$NON-NLS-1$ + public static final String PROP_NAMETELNET = "telnet"; //$NON-NLS-1$ + public static final String PROP_VALUENET = "1233"; //$NON-NLS-1$ + public static final String PROP_VALUETGTCONS = "1232"; //$NON-NLS-1$ + public static final String PROP_VALUETELNET = "23"; //$NON-NLS-1$ - String[][] fPortMap=new String[][] { + String[][] fPortMap = new String[][] { // portName, port - {PROP_NAMETGTCONS, PROP_VALUETGTCONS}, - {PROP_NAMETELNET, PROP_VALUETELNET} - }; + { PROP_NAMETGTCONS, PROP_VALUETGTCONS }, { PROP_NAMETELNET, PROP_VALUETELNET } }; public String getDefaultNetworkPort() { return PROP_VALUETELNET; @@ -40,7 +38,7 @@ public class NetworkPortMap { public String findPortName(String strPort) { for (int i = 0; i < fPortMap.length; i++) { - if(fPortMap[i][1].equals(strPort)) + if (fPortMap[i][1].equals(strPort)) return fPortMap[i][0]; } return null; @@ -48,14 +46,14 @@ public class NetworkPortMap { public String findPort(String strPortName) { for (int i = 0; i < fPortMap.length; i++) { - if(fPortMap[i][0].equals(strPortName)) + if (fPortMap[i][0].equals(strPortName)) return fPortMap[i][1]; } return null; } public List getNameTable() { - List names=new ArrayList(); + List names = new ArrayList(); for (int i = 0; i < fPortMap.length; i++) { names.add(fPortMap[i][0]); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetCodes.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetCodes.java index 1d60c75a080..21edea869da 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetCodes.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetCodes.java @@ -8,10 +8,10 @@ * SPDX-License-Identifier: EPL-2.0 * * Contributors: - * Fran Litterio (Wind River) - initial API and implementation - * Helmut Haigermoser (Wind River) - repackaged - * Ted Williams (Wind River) - repackaged into org.eclipse namespace - * Michael Scharf (Wind River) - split into core, view and connector plugins + * Fran Litterio (Wind River) - initial API and implementation + * Helmut Haigermoser (Wind River) - repackaged + * Ted Williams (Wind River) - repackaged into org.eclipse namespace + * Michael Scharf (Wind River) - split into core, view and connector plugins * Martin Oberhuber (Wind River) - fixed copyright headers and beautified *******************************************************************************/ package org.eclipse.tm.terminal.connector.telnet.connector; @@ -22,75 +22,73 @@ package org.eclipse.tm.terminal.connector.telnet.connector; * interface. The meanings of these constants are defined in the various TELNET RFCs * (RFC 854 to RFC 861, and others). */ -interface TelnetCodes -{ - /** Command code: Subnegotiation End. */ - static final byte TELNET_SE = (byte)240; +interface TelnetCodes { + /** Command code: Subnegotiation End. */ + static final byte TELNET_SE = (byte) 240; - /** Command code: No-op. */ - static final byte TELNET_NOP = (byte)241; + /** Command code: No-op. */ + static final byte TELNET_NOP = (byte) 241; - /** Command code: Data Mark. */ - static final byte TELNET_DM = (byte)242; + /** Command code: Data Mark. */ + static final byte TELNET_DM = (byte) 242; - /** Command code: Break. */ - static final byte TELNET_BREAK = (byte)243; + /** Command code: Break. */ + static final byte TELNET_BREAK = (byte) 243; - /** Command code: Interrupt Process. */ - static final byte TELNET_IP = (byte)244; + /** Command code: Interrupt Process. */ + static final byte TELNET_IP = (byte) 244; - /** Command code: Abort Output. */ - static final byte TELNET_AO = (byte)245; + /** Command code: Abort Output. */ + static final byte TELNET_AO = (byte) 245; - /** Command code: Are You There. */ - static final byte TELNET_AYT = (byte)246; + /** Command code: Are You There. */ + static final byte TELNET_AYT = (byte) 246; - /** Command code: Erase Character. */ - static final byte TELNET_EC = (byte)247; + /** Command code: Erase Character. */ + static final byte TELNET_EC = (byte) 247; - /** Command code: Erase Line. */ - static final byte TELNET_EL = (byte)248; + /** Command code: Erase Line. */ + static final byte TELNET_EL = (byte) 248; - /** Command code: Go Ahead. */ - static final byte TELNET_GA = (byte)249; + /** Command code: Go Ahead. */ + static final byte TELNET_GA = (byte) 249; - /** Command code: Subnegotiation Begin. */ - static final byte TELNET_SB = (byte)250; + /** Command code: Subnegotiation Begin. */ + static final byte TELNET_SB = (byte) 250; - /** Command code: Will. */ - static final byte TELNET_WILL = (byte)251; + /** Command code: Will. */ + static final byte TELNET_WILL = (byte) 251; - /** Command code: Won't. */ - static final byte TELNET_WONT = (byte)252; + /** Command code: Won't. */ + static final byte TELNET_WONT = (byte) 252; - /** Command code: Do. */ - static final byte TELNET_DO = (byte)253; + /** Command code: Do. */ + static final byte TELNET_DO = (byte) 253; - /** Command code: Don't. */ - static final byte TELNET_DONT = (byte)254; + /** Command code: Don't. */ + static final byte TELNET_DONT = (byte) 254; - /** Command code: Interpret As Command. */ - static final byte TELNET_IAC = (byte)255; + /** Command code: Interpret As Command. */ + static final byte TELNET_IAC = (byte) 255; - /** Command code: IS. */ - static final byte TELNET_IS = 0; + /** Command code: IS. */ + static final byte TELNET_IS = 0; - /** Command code: SEND. */ - static final byte TELNET_SEND = 1; + /** Command code: SEND. */ + static final byte TELNET_SEND = 1; + /** Option code: Transmit Binary option. */ + static final byte TELNET_OPTION_TRANSMIT_BINARY = 0; - /** Option code: Transmit Binary option. */ - static final byte TELNET_OPTION_TRANSMIT_BINARY = 0; + /** Option code: Echo option. */ + static final byte TELNET_OPTION_ECHO = 1; - /** Option code: Echo option. */ - static final byte TELNET_OPTION_ECHO = 1; + /** Option code: Suppress Go Ahead option. */ + static final byte TELNET_OPTION_SUPPRESS_GA = 3; - /** Option code: Suppress Go Ahead option. */ - static final byte TELNET_OPTION_SUPPRESS_GA = 3; + /** Option code: Terminal Type */ + static final byte TELNET_OPTION_TERMINAL_TYPE = 24; - /** Option code: Terminal Type */ - static final byte TELNET_OPTION_TERMINAL_TYPE = 24; - - /** Option code: Negotitate About Window Size (NAWS) */ - static final byte TELNET_OPTION_NAWS = 31; + /** Option code: Negotitate About Window Size (NAWS) */ + static final byte TELNET_OPTION_NAWS = 31; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnectWorker.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnectWorker.java index 330e31c1de1..d2ab614884a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnectWorker.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnectWorker.java @@ -32,13 +32,15 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; class TelnetConnectWorker extends Thread { private final ITerminalControl fControl; private final TelnetConnector fConn; - protected TelnetConnectWorker(TelnetConnector conn,ITerminalControl control) { + + protected TelnetConnectWorker(TelnetConnector conn, ITerminalControl control) { fControl = control; fConn = conn; fControl.setState(TerminalState.CONNECTING); } + @Override - public void run() { + public void run() { // Retry the connect with after a little pause in case the // remote telnet server isn't ready. ConnectExceptions might // happen if the telnet server process did not initialized itself. @@ -48,14 +50,18 @@ class TelnetConnectWorker extends Thread { while (remaining >= 0) { // Pause before we re-try if the remaining tries are less than the initial value - if (remaining < 10) try { Thread.sleep(500); } catch (InterruptedException e) { /* ignored on purpose */ } + if (remaining < 10) + try { + Thread.sleep(500); + } catch (InterruptedException e) { + /* ignored on purpose */ } try { int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000; String strHost = fConn.getTelnetSettings().getHost(); int nPort = fConn.getTelnetSettings().getNetworkPort(); InetSocketAddress address = new InetSocketAddress(strHost, nPort); - Socket socket=new Socket(); + Socket socket = new Socket(); socket.connect(address, nTimeout); @@ -74,7 +80,7 @@ class TelnetConnectWorker extends Thread { fConn.setSocket(socket); - TelnetConnection connection=new TelnetConnection(fConn, socket); + TelnetConnection connection = new TelnetConnection(fConn, socket); socket.setKeepAlive(true); fConn.setTelnetConnection(connection); connection.start(); @@ -85,21 +91,22 @@ class TelnetConnectWorker extends Thread { // the DNS will fix itself remaining = 0; //Construct error message and signal failed - String txt="Unknown host: " + ex.getMessage(); //$NON-NLS-1$ - connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + String txt = "Unknown host: " + ex.getMessage(); //$NON-NLS-1$ + connectFailed(txt, "Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (SocketTimeoutException socketTimeoutException) { // Time out occurred. No re-try in this case either. Time out can // be increased by the user. Multiplying the timeout with the remaining // counter is not desired. remaining = 0; // Construct error message and signal failed - connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$ + connectFailed(socketTimeoutException.getMessage(), + "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$ } catch (ConnectException connectException) { // In case of a ConnectException, do a re-try. The server could have been // simply not ready yet and the worker would give up to early. If the terminal // control is already closed (disconnected), don't print "Connection refused" errors if (remaining == 0 && TerminalState.CLOSED != fControl.getState()) { - connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$ + connectFailed(connectException.getMessage(), "Connection refused!"); //$NON-NLS-1$ } } catch (Exception exception) { // Any other exception on connect. No re-try in this case either @@ -107,7 +114,7 @@ class TelnetConnectWorker extends Thread { // Log the exception Logger.logException(exception); // And signal failed - connectFailed(exception.getMessage(),""); //$NON-NLS-1$ + connectFailed(exception.getMessage(), ""); //$NON-NLS-1$ } finally { remaining--; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnection.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnection.java index 67c1e1a2b2c..63a1afd9a8b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnection.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnection.java @@ -297,7 +297,7 @@ public class TelnetConnection extends Thread implements TelnetCodes { * display. */ @Override - public void run() { + public void run() { Logger.log("Entered"); //$NON-NLS-1$ try { @@ -335,7 +335,8 @@ public class TelnetConnection extends Thread implements TelnetCodes { // A "socket closed" exception is normal here. It's caused by the // user clicking the disconnect button on the Terminal view toolbar. - if (message != null && !message.equalsIgnoreCase("Socket closed") && !message.equalsIgnoreCase("Connection reset")) //$NON-NLS-1$ //$NON-NLS-2$ + if (message != null && !message.equalsIgnoreCase("Socket closed") //$NON-NLS-1$ + && !message.equalsIgnoreCase("Connection reset")) //$NON-NLS-1$ { Logger.logException(ex); } @@ -345,8 +346,14 @@ public class TelnetConnection extends Thread implements TelnetCodes { } finally { // Tell the ITerminalControl object that the connection is closed. terminalControl.setState(TerminalState.CLOSED); - try { inputStream.close(); } catch(IOException ioe) { /*ignore*/ } - try { outputStream.close(); } catch(IOException ioe) { /*ignore*/ } + try { + inputStream.close(); + } catch (IOException ioe) { + /*ignore*/ } + try { + outputStream.close(); + } catch (IOException ioe) { + /*ignore*/ } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnector.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnector.java index 5ac0865364b..13c994db808 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetConnector.java @@ -73,21 +73,24 @@ public class TelnetConnector extends TerminalConnectorImpl { public TelnetConnector() { this(new TelnetSettings()); } + public TelnetConnector(TelnetSettings settings) { - fSettings=settings; + fSettings = settings; } + @Override - public void connect(ITerminalControl control) { + public void connect(ITerminalControl control) { super.connect(control); - fWidth=-1; - fHeight=-1; + fWidth = -1; + fHeight = -1; // TERM=xterm implies VT100 line wrapping mode control.setVT100LineWrapping(true); - TelnetConnectWorker worker = new TelnetConnectWorker(this,control); + TelnetConnectWorker worker = new TelnetConnectWorker(this, control); worker.start(); } + @Override - public void doDisconnect() { + public void doDisconnect() { if (getSocket() != null) { try { getSocket().close(); @@ -113,31 +116,37 @@ public class TelnetConnector extends TerminalConnectorImpl { } cleanSocket(); } + @Override - public boolean isLocalEcho() { - if(fTelnetConnection==null) + public boolean isLocalEcho() { + if (fTelnetConnection == null) return false; return fTelnetConnection.localEcho(); } + @Override - public void setTerminalSize(int newWidth, int newHeight) { - if(fTelnetConnection!=null && (newWidth!=fWidth || newHeight!=fHeight)) { + public void setTerminalSize(int newWidth, int newHeight) { + if (fTelnetConnection != null && (newWidth != fWidth || newHeight != fHeight)) { //avoid excessive communications due to change size requests by caching previous size fTelnetConnection.setTerminalSize(newWidth, newHeight); - fWidth=newWidth; - fHeight=newHeight; + fWidth = newWidth; + fHeight = newHeight; } } + public InputStream getInputStream() { return fInputStream; } + @Override - public OutputStream getTerminalToRemoteStream() { + public OutputStream getTerminalToRemoteStream() { return fOutputStream; } + private void setInputStream(InputStream inputStream) { fInputStream = inputStream; } + private void setOutputStream(OutputStream outputStream) { if (outputStream == null) { fOutputStream = null; @@ -146,6 +155,7 @@ public class TelnetConnector extends TerminalConnectorImpl { // translate CR to telnet end-of-line sequence - RFC 854 fOutputStream = new TelnetOutputStream(outputStream, fSettings.getEndOfLine()); } + Socket getSocket() { return fSocket; } @@ -154,13 +164,13 @@ public class TelnetConnector extends TerminalConnectorImpl { * sets the socket to null */ void cleanSocket() { - fSocket=null; + fSocket = null; setInputStream(null); setOutputStream(null); } void setSocket(Socket socket) throws IOException { - if(socket==null) { + if (socket == null) { cleanSocket(); } else { fSocket = socket; @@ -169,35 +179,44 @@ public class TelnetConnector extends TerminalConnectorImpl { } } + public void setTelnetConnection(TelnetConnection connection) { - fTelnetConnection=connection; + fTelnetConnection = connection; } + public void displayTextInTerminal(String text) { fControl.displayTextInTerminal(text); } - public OutputStream getRemoteToTerminalOutputStream () { + + public OutputStream getRemoteToTerminalOutputStream() { return fControl.getRemoteToTerminalOutputStream(); } + public void setState(TerminalState state) { fControl.setState(state); } + public ITelnetSettings getTelnetSettings() { return fSettings; } + @Override public void setDefaultSettings() { - fSettings.load(new NullSettingsStore()); + fSettings.load(new NullSettingsStore()); } + @Override - public String getSettingsSummary() { + public String getSettingsSummary() { return fSettings.getSummary(); } + @Override - public void load(ISettingsStore store) { + public void load(ISettingsStore store) { fSettings.load(store); } + @Override - public void save(ISettingsStore store) { + public void save(ISettingsStore store) { fSettings.save(store); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.java index ed3ed05dfa4..b05c6f03e4e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.java @@ -28,4 +28,4 @@ public class TelnetMessages extends NLS { */ public static String END_OF_LINE; - } +} diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.properties b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.properties index 77acc43ec40..561ee4237dc 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetMessages.properties @@ -13,7 +13,7 @@ # Helmut Haigermoser and Ted Williams. # # Contributors: -# Michael Scharf (Wind River) - split into core, view and connector plugins +# Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified ############################################################################### PORT = Port diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetOption.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetOption.java index e97c9a1baa6..3889188dc38 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetOption.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetOption.java @@ -43,207 +43,204 @@ import org.eclipse.tm.internal.terminal.provisional.api.Logger; * * @author Fran Litterio (francis.litterio@windriver.com) */ -class TelnetOption implements TelnetCodes -{ - /** - * This array of Strings maps an integer TELNET option code value to the symbolic - * name of the option. Array elements of the form "?" represent unassigned option - * values. - */ - protected static final String[] optionNames = - { - "BINARY", // 0 //$NON-NLS-1$ - "ECHO", // 1 //$NON-NLS-1$ - "RECONNECTION", // 2 //$NON-NLS-1$ - "SUPPRESS GO AHEAD", // 3 //$NON-NLS-1$ - "MSG SIZE NEGOTIATION", // 4 //$NON-NLS-1$ - "STATUS", // 5 //$NON-NLS-1$ - "TIMING MARK", // 6 //$NON-NLS-1$ - "REMOTE CTRL TRANS+ECHO", // 7 //$NON-NLS-1$ - "OUTPUT LINE WIDTH", // 8 //$NON-NLS-1$ - "OUTPUT PAGE SIZE", // 9 //$NON-NLS-1$ - "OUTPUT CR DISPOSITION", // 10 //$NON-NLS-1$ - "OUTPUT HORIZ TABSTOPS", // 11 //$NON-NLS-1$ - "OUTPUT HORIZ TAB DISPOSITION", // 12 //$NON-NLS-1$ - "OUTPUT FORMFEED DISPOSITION", // 13 //$NON-NLS-1$ - "OUTPUT VERTICAL TABSTOPS", // 14 //$NON-NLS-1$ - "OUTPUT VT DISPOSITION", // 15 //$NON-NLS-1$ - "OUTPUT LF DISPOSITION", // 16 //$NON-NLS-1$ - "EXTENDED ASCII", // 17 //$NON-NLS-1$ - "LOGOUT", // 18 //$NON-NLS-1$ - "BYTE MACRO", // 19 //$NON-NLS-1$ - "DATA ENTRY TERMINAL", // 20 //$NON-NLS-1$ - "SUPDUP", // 21 //$NON-NLS-1$ - "SUPDUP OUTPUT", // 22 //$NON-NLS-1$ - "SEND LOCATION", // 23 //$NON-NLS-1$ - "TERMINAL TYPE", // 24 //$NON-NLS-1$ - "END OF RECORD", // 25 //$NON-NLS-1$ - "TACACS USER IDENTIFICATION", // 26 //$NON-NLS-1$ - "OUTPUT MARKING", // 27 //$NON-NLS-1$ - "TERMINAL LOCATION NUMBER", // 28 //$NON-NLS-1$ - "3270 REGIME", // 29 //$NON-NLS-1$ - "X.3 PAD", // 30 //$NON-NLS-1$ - "NEGOTIATE ABOUT WINDOW SIZE", // 31 //$NON-NLS-1$ - "TERMINAL SPEED", // 32 //$NON-NLS-1$ - "REMOTE FLOW CONTROL", // 33 //$NON-NLS-1$ - "LINEMODE", // 34 //$NON-NLS-1$ - "X DISPLAY LOCATION", // 35 //$NON-NLS-1$ - "ENVIRONMENT OPTION", // 36 //$NON-NLS-1$ - "AUTHENTICATION OPTION", // 37 //$NON-NLS-1$ - "ENCRYPTION OPTION", // 38 //$NON-NLS-1$ - "NEW ENVIRONMENT OPTION", // 39 //$NON-NLS-1$ - "TN3270E", // 40 //$NON-NLS-1$ - "XAUTH", // 41 //$NON-NLS-1$ - "CHARSET", // 42 //$NON-NLS-1$ - "REMOTE SERIAL PORT", // 43 //$NON-NLS-1$ - "COM PORT CONTROL OPTION", // 44 //$NON-NLS-1$ - "SUPPRESS LOCAL ECHO", // 45 //$NON-NLS-1$ - "START TLS", // 46 //$NON-NLS-1$ - "KERMIT", // 47 //$NON-NLS-1$ - "SEND URL", // 48 //$NON-NLS-1$ - "FORWARD X", // 49 //$NON-NLS-1$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 50 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", // ... 137 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "TELOPT PRAGMA LOGON", // 138 //$NON-NLS-1$ - "TELOPT SSPI LOGON", // 139 //$NON-NLS-1$ - "TELOPT PRAGMA HEARTBEAT", // 140 //$NON-NLS-1$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 141 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "?", "?", "?", "?", // ... 254 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "EXTENDED OPTIONS LIST" // 255 //$NON-NLS-1$ - }; +class TelnetOption implements TelnetCodes { + /** + * This array of Strings maps an integer TELNET option code value to the symbolic + * name of the option. Array elements of the form "?" represent unassigned option + * values. + */ + protected static final String[] optionNames = { "BINARY", // 0 //$NON-NLS-1$ + "ECHO", // 1 //$NON-NLS-1$ + "RECONNECTION", // 2 //$NON-NLS-1$ + "SUPPRESS GO AHEAD", // 3 //$NON-NLS-1$ + "MSG SIZE NEGOTIATION", // 4 //$NON-NLS-1$ + "STATUS", // 5 //$NON-NLS-1$ + "TIMING MARK", // 6 //$NON-NLS-1$ + "REMOTE CTRL TRANS+ECHO", // 7 //$NON-NLS-1$ + "OUTPUT LINE WIDTH", // 8 //$NON-NLS-1$ + "OUTPUT PAGE SIZE", // 9 //$NON-NLS-1$ + "OUTPUT CR DISPOSITION", // 10 //$NON-NLS-1$ + "OUTPUT HORIZ TABSTOPS", // 11 //$NON-NLS-1$ + "OUTPUT HORIZ TAB DISPOSITION", // 12 //$NON-NLS-1$ + "OUTPUT FORMFEED DISPOSITION", // 13 //$NON-NLS-1$ + "OUTPUT VERTICAL TABSTOPS", // 14 //$NON-NLS-1$ + "OUTPUT VT DISPOSITION", // 15 //$NON-NLS-1$ + "OUTPUT LF DISPOSITION", // 16 //$NON-NLS-1$ + "EXTENDED ASCII", // 17 //$NON-NLS-1$ + "LOGOUT", // 18 //$NON-NLS-1$ + "BYTE MACRO", // 19 //$NON-NLS-1$ + "DATA ENTRY TERMINAL", // 20 //$NON-NLS-1$ + "SUPDUP", // 21 //$NON-NLS-1$ + "SUPDUP OUTPUT", // 22 //$NON-NLS-1$ + "SEND LOCATION", // 23 //$NON-NLS-1$ + "TERMINAL TYPE", // 24 //$NON-NLS-1$ + "END OF RECORD", // 25 //$NON-NLS-1$ + "TACACS USER IDENTIFICATION", // 26 //$NON-NLS-1$ + "OUTPUT MARKING", // 27 //$NON-NLS-1$ + "TERMINAL LOCATION NUMBER", // 28 //$NON-NLS-1$ + "3270 REGIME", // 29 //$NON-NLS-1$ + "X.3 PAD", // 30 //$NON-NLS-1$ + "NEGOTIATE ABOUT WINDOW SIZE", // 31 //$NON-NLS-1$ + "TERMINAL SPEED", // 32 //$NON-NLS-1$ + "REMOTE FLOW CONTROL", // 33 //$NON-NLS-1$ + "LINEMODE", // 34 //$NON-NLS-1$ + "X DISPLAY LOCATION", // 35 //$NON-NLS-1$ + "ENVIRONMENT OPTION", // 36 //$NON-NLS-1$ + "AUTHENTICATION OPTION", // 37 //$NON-NLS-1$ + "ENCRYPTION OPTION", // 38 //$NON-NLS-1$ + "NEW ENVIRONMENT OPTION", // 39 //$NON-NLS-1$ + "TN3270E", // 40 //$NON-NLS-1$ + "XAUTH", // 41 //$NON-NLS-1$ + "CHARSET", // 42 //$NON-NLS-1$ + "REMOTE SERIAL PORT", // 43 //$NON-NLS-1$ + "COM PORT CONTROL OPTION", // 44 //$NON-NLS-1$ + "SUPPRESS LOCAL ECHO", // 45 //$NON-NLS-1$ + "START TLS", // 46 //$NON-NLS-1$ + "KERMIT", // 47 //$NON-NLS-1$ + "SEND URL", // 48 //$NON-NLS-1$ + "FORWARD X", // 49 //$NON-NLS-1$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 50 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", // ... 137 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + "TELOPT PRAGMA LOGON", // 138 //$NON-NLS-1$ + "TELOPT SSPI LOGON", // 139 //$NON-NLS-1$ + "TELOPT PRAGMA HEARTBEAT", // 140 //$NON-NLS-1$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 141 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "?", "?", "?", "?", // ... 254 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + "EXTENDED OPTIONS LIST" // 255 //$NON-NLS-1$ + }; - /** - * Negotiation state: Negotiation not yet started for this option.

- * - * This constant and the others having similar names represent the states of a - * finite state automaton (FSA) that tracks the negotiation state of this option. - * The initial state is NEGOTIATION_NOT_STARTED. The state machine is as follows - * (with transitions labeled with letters in parentheses):

- * - *

-     *     NEGOTIATION_NOT_STARTED -----> {@link #NEGOTIATION_IN_PROGRESS}
-     *                         |    (A)      |        ^
-     *                      (C)|          (B)|        |(D)
-     *                         |             V        |
-     *                         +--------> {@link #NEGOTIATION_DONE}
-     * 

- * - * Once the FSA leaves state NEGOTIATION_NOT_STARTED, it never returns to that - * state. Transition A happens when the local endpoint sends an option command - * before receiving a command for the same option from the remote endpoint.

- * - * Transition B happens when the local endpoint receives a reply to an option - * command sent earlier by the local endpoint. Receipt of that reply terminates - * the negotiation.

- * - * Transition D happens after negotiation is done and "something changes" (see the - * RFCs for the definition of "something changes"). Either endpoint can - * re-negotiate an option after a previous negotiation, but only if some external - * influence (such as the user or the OS) causes it to do so. Re-negotiation must - * start more than {@link #NEGOTIATION_IGNORE_DURATION} milliseconds after the FSA - * enters state NEGOTIATION_DONE or it will be ignored. This is how this client - * prevents negotiation loops.

- * - * Transition C happens when the local endpoint receives an option command from the - * remote endpoint before sending a command for the same option. In that case, the - * local endpoint replies immediately with an option command and the negotiation - * terminates.

- * - * Some TELNET servers (e.g., the Solaris server), after sending WILL and receiving - * DONT, will reply with a superfluous WONT. Any such superfluous option command - * received from the remote endpoint while the option's FSA is in state - * {@link #NEGOTIATION_DONE} will be ignored by the local endpoint. - */ - protected static final int NEGOTIATION_NOT_STARTED = 0; + /** + * Negotiation state: Negotiation not yet started for this option.

+ * + * This constant and the others having similar names represent the states of a + * finite state automaton (FSA) that tracks the negotiation state of this option. + * The initial state is NEGOTIATION_NOT_STARTED. The state machine is as follows + * (with transitions labeled with letters in parentheses):

+ * + *

+	 *     NEGOTIATION_NOT_STARTED -----> {@link #NEGOTIATION_IN_PROGRESS}
+	 *                         |    (A)      |        ^
+	 *                      (C)|          (B)|        |(D)
+	 *                         |             V        |
+	 *                         +--------> {@link #NEGOTIATION_DONE}
+	 * 

+ * + * Once the FSA leaves state NEGOTIATION_NOT_STARTED, it never returns to that + * state. Transition A happens when the local endpoint sends an option command + * before receiving a command for the same option from the remote endpoint.

+ * + * Transition B happens when the local endpoint receives a reply to an option + * command sent earlier by the local endpoint. Receipt of that reply terminates + * the negotiation.

+ * + * Transition D happens after negotiation is done and "something changes" (see the + * RFCs for the definition of "something changes"). Either endpoint can + * re-negotiate an option after a previous negotiation, but only if some external + * influence (such as the user or the OS) causes it to do so. Re-negotiation must + * start more than {@link #NEGOTIATION_IGNORE_DURATION} milliseconds after the FSA + * enters state NEGOTIATION_DONE or it will be ignored. This is how this client + * prevents negotiation loops.

+ * + * Transition C happens when the local endpoint receives an option command from the + * remote endpoint before sending a command for the same option. In that case, the + * local endpoint replies immediately with an option command and the negotiation + * terminates.

+ * + * Some TELNET servers (e.g., the Solaris server), after sending WILL and receiving + * DONT, will reply with a superfluous WONT. Any such superfluous option command + * received from the remote endpoint while the option's FSA is in state + * {@link #NEGOTIATION_DONE} will be ignored by the local endpoint. + */ + protected static final int NEGOTIATION_NOT_STARTED = 0; - /** Negotiation state: Negotiation is in progress for this option. */ - protected static final int NEGOTIATION_IN_PROGRESS = 1; + /** Negotiation state: Negotiation is in progress for this option. */ + protected static final int NEGOTIATION_IN_PROGRESS = 1; - /** Negotiation state: Negotiation has terminated for this option. */ - protected static final int NEGOTIATION_DONE = 2; + /** Negotiation state: Negotiation has terminated for this option. */ + protected static final int NEGOTIATION_DONE = 2; - /** - * The number of milliseconds following the end of negotiation of this option - * before which the remote endpoint can re-negotiate the option. Any option - * command received from the remote endpoint before this time passes is ignored. - * This is used to prevent option negotiation loops. - * - * @see #ignoreNegotiation() - * @see #negotiationCompletionTime - */ - protected static final int NEGOTIATION_IGNORE_DURATION = 30000; + /** + * The number of milliseconds following the end of negotiation of this option + * before which the remote endpoint can re-negotiate the option. Any option + * command received from the remote endpoint before this time passes is ignored. + * This is used to prevent option negotiation loops. + * + * @see #ignoreNegotiation() + * @see #negotiationCompletionTime + */ + protected static final int NEGOTIATION_IGNORE_DURATION = 30000; - /** - * This field holds the current negotiation state for this option. - */ - protected int negotiationState = NEGOTIATION_NOT_STARTED; + /** + * This field holds the current negotiation state for this option. + */ + protected int negotiationState = NEGOTIATION_NOT_STARTED; - /** - * This field holds the time when negotiation of this option most recently - * terminated (i.e., entered state {@link #NEGOTIATION_DONE}). This is used to - * determine whether an option command received from the remote endpoint after - * negotiation has terminated for this option is to be ignored or interpreted as - * the start of a new negotiation. - * - * @see #NEGOTIATION_IGNORE_DURATION - */ - protected Date negotiationCompletionTime = new Date(0); + /** + * This field holds the time when negotiation of this option most recently + * terminated (i.e., entered state {@link #NEGOTIATION_DONE}). This is used to + * determine whether an option command received from the remote endpoint after + * negotiation has terminated for this option is to be ignored or interpreted as + * the start of a new negotiation. + * + * @see #NEGOTIATION_IGNORE_DURATION + */ + protected Date negotiationCompletionTime = new Date(0); - /** - * Holds the total number of negotiations that have completed for this option. - */ - protected int negotiationCount = 0; + /** + * Holds the total number of negotiations that have completed for this option. + */ + protected int negotiationCount = 0; - /** - * Holds the integer code representing the option. - */ - protected byte option = 0; + /** + * Holds the integer code representing the option. + */ + protected byte option = 0; - /** - * Holds the OutputStream object that allows data to be sent to the remote endpoint - * of the TELNET connection. - */ - protected OutputStream outputStream; + /** + * Holds the OutputStream object that allows data to be sent to the remote endpoint + * of the TELNET connection. + */ + protected OutputStream outputStream; - /** - * True if this option is for the local endpoint, false for the remote endpoint. - */ - protected boolean local = true; + /** + * True if this option is for the local endpoint, false for the remote endpoint. + */ + protected boolean local = true; - /** - * This field is true if the option is enabled, false if it is disabled. All - * options are initially disabled until they are negotiated to be enabled.

- */ - protected boolean enabled = false; + /** + * This field is true if the option is enabled, false if it is disabled. All + * options are initially disabled until they are negotiated to be enabled.

+ */ + protected boolean enabled = false; - /** - * This field is true if the client desires the option to be enabled, false if the - * client desires the option to be disabled. This field does not represent the - * remote's endpoints desire (as expressed via WILL and WONT commands) -- it - * represnet the local endpoint's desire.

- * - * @see #setDesired(boolean) - */ - protected boolean desired = false; + /** + * This field is true if the client desires the option to be enabled, false if the + * client desires the option to be disabled. This field does not represent the + * remote's endpoints desire (as expressed via WILL and WONT commands) -- it + * represnet the local endpoint's desire.

+ * + * @see #setDesired(boolean) + */ + protected boolean desired = false; - /** + /** * Constructor.

* * @param option The integer code of this option. @@ -251,8 +248,7 @@ class TelnetOption implements TelnetCodes * @param local Whether this option is for the local or remote endpoint. * @param outputStream A stream used to negotiate with the remote endpoint. */ - TelnetOption(byte option, boolean desired, boolean local, - OutputStream outputStream) { + TelnetOption(byte option, boolean desired, boolean local, OutputStream outputStream) { this.option = option; this.desired = desired; this.local = local; @@ -333,12 +329,10 @@ class TelnetOption implements TelnetCodes public void negotiate() { if (negotiationState == NEGOTIATION_NOT_STARTED && desired) { if (local) { - Logger - .log("Starting negotiation for local option " + optionName()); //$NON-NLS-1$ + Logger.log("Starting negotiation for local option " + optionName()); //$NON-NLS-1$ sendWill(); } else { - Logger - .log("Starting negotiation for remote option " + optionName()); //$NON-NLS-1$ + Logger.log("Starting negotiation for remote option " + optionName()); //$NON-NLS-1$ sendDo(); } @@ -352,8 +346,7 @@ class TelnetOption implements TelnetCodes */ public void handleWill() { if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) { - Logger - .log("Ignoring superfluous WILL command from remote endpoint."); //$NON-NLS-1$ + Logger.log("Ignoring superfluous WILL command from remote endpoint."); //$NON-NLS-1$ return; } @@ -403,8 +396,7 @@ class TelnetOption implements TelnetCodes */ public void handleWont() { if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) { - Logger - .log("Ignoring superfluous WONT command from remote endpoint."); //$NON-NLS-1$ + Logger.log("Ignoring superfluous WONT command from remote endpoint."); //$NON-NLS-1$ return; } @@ -481,8 +473,7 @@ class TelnetOption implements TelnetCodes */ public void handleDont() { if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) { - Logger - .log("Ignoring superfluous DONT command from remote endpoint."); //$NON-NLS-1$ + Logger.log("Ignoring superfluous DONT command from remote endpoint."); //$NON-NLS-1$ return; } @@ -520,9 +511,8 @@ class TelnetOption implements TelnetCodes case TELNET_OPTION_TERMINAL_TYPE: if (subnegotiationData[1] != TELNET_SEND) { // This should never happen! - Logger - .log("Invalid TERMINAL-TYPE subnegotiation command from remote endpoint: " + //$NON-NLS-1$ - (subnegotiationData[1] & 0xff)); + Logger.log("Invalid TERMINAL-TYPE subnegotiation command from remote endpoint: " + //$NON-NLS-1$ + (subnegotiationData[1] & 0xff)); break; } @@ -531,8 +521,7 @@ class TelnetOption implements TelnetCodes // // IAC SB TERMINAL-TYPE IS x t e r m IAC SE - byte[] terminalTypeData = { TELNET_IAC, TELNET_SB, - TELNET_OPTION_TERMINAL_TYPE, TELNET_IS, (byte) 'x', + byte[] terminalTypeData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_TERMINAL_TYPE, TELNET_IS, (byte) 'x', (byte) 't', (byte) 'e', (byte) 'r', (byte) 'm', TELNET_IAC, TELNET_SE }; try { @@ -545,8 +534,7 @@ class TelnetOption implements TelnetCodes default: // This should never happen! - Logger - .log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$ + Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$ break; } } @@ -567,8 +555,7 @@ class TelnetOption implements TelnetCodes // IAC SB NAWS // IAC SE - final byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0, - 0, 0, 0, TELNET_IAC, TELNET_SE }; + final byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0, 0, 0, 0, TELNET_IAC, TELNET_SE }; int width = ((Integer) subnegotiationData[0]).intValue(); int height = ((Integer) subnegotiationData[1]).intValue(); @@ -577,17 +564,16 @@ class TelnetOption implements TelnetCodes NAWSData[5] = (byte) ((height >>> 8) & 0xff); // High order byte of height. NAWSData[6] = (byte) (height & 0xff); // Low order byte of height. - Logger - .log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$ - ", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$ + Logger.log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$ + ", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$ // Send the NAWS data in a new thread. The current thread is the display // thread, and calls to write() can block, but blocking the display thread // is _bad_ (it hangs the GUI). - Thread t=new Thread() { + Thread t = new Thread() { @Override - public void run() { + public void run() { try { outputStream.write(NAWSData); } catch (IOException ex) { @@ -602,8 +588,7 @@ class TelnetOption implements TelnetCodes default: // This should never happen! - Logger - .log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$ + Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$ break; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetProperties.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetProperties.java index 0af9feaa8f6..c96d7455845 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetProperties.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetProperties.java @@ -13,7 +13,7 @@ * Helmut Haigermoser and Ted Williams. * * Contributors: - * Michael Scharf (Wind River) - extracted from TerminalProperties + * Michael Scharf (Wind River) - extracted from TerminalProperties * Martin Oberhuber (Wind River) - fixed copyright headers and beautified *******************************************************************************/ package org.eclipse.tm.terminal.connector.telnet.connector; diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettings.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettings.java index 40d8ca5f492..4ecf960ea5c 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettings.java @@ -24,13 +24,14 @@ import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; * @noreference This class is not intended to be referenced by clients. */ public class TelnetSettings implements ITelnetSettings { - protected String fHost; - protected String fNetworkPort; - protected String fTimeout; - protected String fEndOfLine = EOL_CRNUL; - private final TelnetProperties fProperties=new TelnetProperties(); + protected String fHost; + protected String fNetworkPort; + protected String fTimeout; + protected String fEndOfLine = EOL_CRNUL; + private final TelnetProperties fProperties = new TelnetProperties(); + @Override - public String getHost() { + public String getHost() { return fHost; } @@ -43,7 +44,7 @@ public class TelnetSettings implements ITelnetSettings { } @Override - public int getNetworkPort() { + public int getNetworkPort() { try { return Integer.parseInt(fNetworkPort); } catch (NumberFormatException numberFormatException) { @@ -56,20 +57,20 @@ public class TelnetSettings implements ITelnetSettings { } @Override - public String getSummary() { + public String getSummary() { return getHost() + ":" + getNetworkPortString(); //$NON-NLS-1$ } @Override - public void load(ISettingsStore store) { + public void load(ISettingsStore store) { fHost = store.get("Host", fProperties.getDefaultHost());//$NON-NLS-1$ fNetworkPort = store.get("NetworkPort", fProperties.getDefaultNetworkPort());//$NON-NLS-1$ - fTimeout = store.get("Timeout","10");//$NON-NLS-1$ //$NON-NLS-2$ + fTimeout = store.get("Timeout", "10");//$NON-NLS-1$ //$NON-NLS-2$ fEndOfLine = store.get("EndOfLine", EOL_CRNUL);//$NON-NLS-1$ } @Override - public void save(ISettingsStore store) { + public void save(ISettingsStore store) { store.put("Host", fHost);//$NON-NLS-1$ store.put("NetworkPort", fNetworkPort);//$NON-NLS-1$ store.put("Timeout", fTimeout);//$NON-NLS-1$ @@ -79,14 +80,16 @@ public class TelnetSettings implements ITelnetSettings { public TelnetProperties getProperties() { return fProperties; } + @Override - public int getTimeout() { + public int getTimeout() { try { return Integer.parseInt(fTimeout); } catch (NumberFormatException numberFormatException) { return 10; } } + public String getTimeoutString() { return fTimeout; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettingsPage.java index f40cfb76e9f..170f674d816 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/connector/TelnetSettingsPage.java @@ -48,10 +48,11 @@ public class TelnetSettingsPage extends AbstractSettingsPage { private final TelnetSettings fTerminalSettings; public TelnetSettingsPage(TelnetSettings settings) { - fTerminalSettings=settings; + fTerminalSettings = settings; } + @Override - public void saveSettings() { + public void saveSettings() { fTerminalSettings.setHost(fHostText.getText()); fTerminalSettings.setTimeout(fTimeout.getText()); fTerminalSettings.setNetworkPort(getNetworkPort()); @@ -59,31 +60,34 @@ public class TelnetSettingsPage extends AbstractSettingsPage { } @Override - public void loadSettings() { - if(fTerminalSettings!=null) { + public void loadSettings() { + if (fTerminalSettings != null) { setHost(fTerminalSettings.getHost()); setTimeout(fTerminalSettings.getTimeoutString()); setNetworkPort(fTerminalSettings.getNetworkPortString()); setEndOfLine(fTerminalSettings.getEndOfLine()); } } + private void setHost(String strHost) { - if(strHost==null) - strHost=""; //$NON-NLS-1$ + if (strHost == null) + strHost = ""; //$NON-NLS-1$ fHostText.setText(strHost); } + private void setTimeout(String timeout) { - if(timeout==null || timeout.length()==0) - timeout="5"; //$NON-NLS-1$ + if (timeout == null || timeout.length() == 0) + timeout = "5"; //$NON-NLS-1$ fTimeout.setText(timeout); } + private void setNetworkPort(String strNetworkPort) { - if (strNetworkPort!=null) { + if (strNetworkPort != null) { String strPortName = getNetworkPortMap().findPortName(strNetworkPort); - if(strPortName==null) { - strPortName=strNetworkPort; //fallback to verbatim port if not found + if (strPortName == null) { + strPortName = strNetworkPort; //fallback to verbatim port if not found } int nIndex = fNetworkPortCombo.indexOf(strPortName); @@ -94,23 +98,28 @@ public class TelnetSettingsPage extends AbstractSettingsPage { } } } + private String getNetworkPort() { String portText = fNetworkPortCombo.getText().trim(); String mappedPort = getNetworkPortMap().findPort(portText); - return mappedPort!=null ? mappedPort : portText; + return mappedPort != null ? mappedPort : portText; } + private NetworkPortMap getNetworkPortMap() { return fTerminalSettings.getProperties().getNetworkPortMap(); } + private void setEndOfLine(String eol) { int idx = fEndOfLineCombo.indexOf(eol); fEndOfLineCombo.select(idx >= 0 ? idx : 0); } + private String getEndOfLine() { return fEndOfLineCombo.getText(); } + @Override - public boolean validateSettings() { + public boolean validateSettings() { String message = null; int messageType = IMessageProvider.NONE; boolean valid = true; @@ -119,7 +128,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage { String m = "Please enter a host IP or name."; //$NON-NLS-1$ int mt = IMessageProvider.INFORMATION; updateControlDecoration(fHostText, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -132,7 +144,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage { String m = "Invalid network port. Must be between 0 and 65535."; //$NON-NLS-1$ int mt = IMessageProvider.ERROR; updateControlDecoration(fNetworkPortCombo, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -144,7 +159,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage { String m = "Invalid timeout. Must be greater than 0."; //$NON-NLS-1$ int mt = IMessageProvider.ERROR; updateControlDecoration(fTimeout, m, mt); - if (mt > messageType) { message = m; messageType = mt; } + if (mt > messageType) { + message = m; + messageType = mt; + } valid = false; } else { @@ -160,7 +178,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage { } @Override - public void createControl(Composite parent) { + public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); @@ -179,7 +197,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage { fHostText.setLayoutData(gridData); fHostText.addModifyListener(new ModifyListener() { @Override - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent e) { fireListeners(fHostText); } }); @@ -195,13 +213,13 @@ public class TelnetSettingsPage extends AbstractSettingsPage { fNetworkPortCombo.setLayoutData(gridData); fNetworkPortCombo.addModifyListener(new ModifyListener() { @Override - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent e) { fireListeners(fNetworkPortCombo); } }); fNetworkPortCombo.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { fireListeners(fNetworkPortCombo); } }); @@ -216,7 +234,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage { fTimeout.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fTimeout.addModifyListener(new ModifyListener() { @Override - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent e) { fireListeners(fTimeout); } }); @@ -228,7 +246,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage { fEndOfLineCombo.setLayoutData(gridData); fEndOfLineCombo.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { fireListeners(fEndOfLineCombo); } }); @@ -236,6 +254,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage { loadSettings(); } + private void loadCombo(Combo ctlCombo, List table) { for (Iterator iter = table.iterator(); iter.hasNext();) { String label = iter.next(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/controls/TelnetWizardConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/controls/TelnetWizardConfigurationPanel.java index 05ca464dbc6..4736cf44c4d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/controls/TelnetWizardConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/controls/TelnetWizardConfigurationPanel.java @@ -36,7 +36,7 @@ import org.eclipse.tm.terminal.view.ui.panels.AbstractExtendedConfigurationPanel */ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfigurationPanel { - public TelnetSettings telnetSettings; + public TelnetSettings telnetSettings; private ISettingsPage telnetSettingsPage; /** @@ -45,8 +45,8 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio * @param container The configuration panel container or null. */ public TelnetWizardConfigurationPanel(IConfigurationPanelContainer container) { - super(container); - } + super(container); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) @@ -59,7 +59,8 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio panel.setLayoutData(data); // Create the host selection combo - if (isWithoutSelection()) createHostsUI(panel, true); + if (isWithoutSelection()) + createHostsUI(panel, true); TelnetConnector conn = new TelnetConnector(); telnetSettings = (TelnetSettings) conn.getTelnetSettings(); @@ -69,7 +70,7 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio telnetSettingsPage = new TelnetSettingsPage(telnetSettings); if (telnetSettingsPage instanceof AbstractSettingsPage) { - ((AbstractSettingsPage)telnetSettingsPage).setHasControlDecoration(true); + ((AbstractSettingsPage) telnetSettingsPage).setHasControlDecoration(true); } telnetSettingsPage.createControl(panel); @@ -78,7 +79,8 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio @Override public void onSettingsPageChanged(Control control) { - if (getContainer() != null) getContainer().validate(); + if (getContainer() != null) + getContainer().validate(); } }); @@ -93,54 +95,62 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio */ @Override public void setupData(Map data) { - if (data == null || telnetSettings == null || telnetSettingsPage == null) return; + if (data == null || telnetSettings == null || telnetSettingsPage == null) + return; - String value = (String)data.get(ITerminalsConnectorConstants.PROP_IP_HOST); - if (value != null) telnetSettings.setHost(value); + String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST); + if (value != null) + telnetSettings.setHost(value); Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT); value = v != null ? v.toString() : null; - if (value != null) telnetSettings.setNetworkPort(value); + if (value != null) + telnetSettings.setNetworkPort(value); v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT); value = v != null ? v.toString() : null; - if (value != null) telnetSettings.setTimeout(value); + if (value != null) + telnetSettings.setTimeout(value); v = data.get(ITerminalsConnectorConstants.PROP_TELNET_EOL); value = v != null ? v.toString() : null; - if (value != null) telnetSettings.setEndOfLine(value); + if (value != null) + telnetSettings.setEndOfLine(value); - value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING); - if (value != null) setEncoding(value); + value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING); + if (value != null) + setEncoding(value); telnetSettingsPage.loadSettings(); - } + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#extractData(java.util.Map) */ @Override public void extractData(Map data) { - if (data == null) return; + if (data == null) + return; - // set the terminal connector id for ssh - data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"); //$NON-NLS-1$ + // set the terminal connector id for ssh + data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, + "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"); //$NON-NLS-1$ - telnetSettingsPage.saveSettings(); - data.put(ITerminalsConnectorConstants.PROP_IP_HOST,telnetSettings.getHost()); + telnetSettingsPage.saveSettings(); + data.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost()); data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(telnetSettings.getNetworkPort())); data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(telnetSettings.getTimeout())); data.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine()); data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding()); - } + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) */ @Override - protected void fillSettingsForHost(String host){ - if (host != null && host.length() != 0){ - if (hostSettingsMap.containsKey(host)){ + protected void fillSettingsForHost(String host) { + if (host != null && host.length() != 0) { + if (hostSettingsMap.containsKey(host)) { Map hostSettings = hostSettingsMap.get(host); if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) { telnetSettings.setHost(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST)); @@ -171,18 +181,20 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) */ @Override - protected void saveSettingsForHost(boolean add){ + protected void saveSettingsForHost(boolean add) { String host = getHostFromSettings(); - if(host != null && host.length() != 0) { + if (host != null && host.length() != 0) { Map hostSettings = hostSettingsMap.get(host); if (hostSettings == null && !add) { - hostSettings=new HashMap(); + hostSettings = new HashMap(); hostSettingsMap.put(host, hostSettings); } if (hostSettings != null) { hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost()); - hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(telnetSettings.getNetworkPort())); - hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(telnetSettings.getTimeout())); + hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, + Integer.toString(telnetSettings.getNetworkPort())); + hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, + Integer.toString(telnetSettings.getTimeout())); hostSettings.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine()); if (getEncoding() != null) { hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding()); @@ -195,7 +207,7 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() */ @Override - public boolean isValid(){ + public boolean isValid() { return isEncodingValid() && telnetSettingsPage.validateSettings(); } @@ -203,17 +215,17 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) */ @Override - public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { - saveSettingsForHost(true); - super.doSaveWidgetValues(settings, idPrefix); - } + public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { + saveSettingsForHost(true); + super.doSaveWidgetValues(settings, idPrefix); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() */ @Override - protected String getHostFromSettings() { + protected String getHostFromSettings() { telnetSettingsPage.saveSettings(); - return telnetSettings.getHost(); - } + return telnetSettings.getHost(); + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java index 98221f60b71..80d6a7512cd 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java @@ -91,18 +91,19 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate { * * @return The terminal title string or null. */ - private String getTerminalTitle(Map properties) { + private String getTerminalTitle(Map properties) { // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if (title != null) return title; + if (title != null) + return title; //No title,try to calculate the title - String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); + String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); if (host != null) { DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String date = format.format(new Date(System.currentTimeMillis())); - return NLS.bind(Messages.TelnetLauncherDelegate_terminalTitle, new String[]{host, date}); + return NLS.bind(Messages.TelnetLauncherDelegate_terminalTitle, new String[] { host, date }); } return Messages.TelnetLauncherDelegate_terminalTitle_default; @@ -116,32 +117,34 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate { if (IMementoHandler.class.equals(adapter)) { return mementoHandler; } - return super.getAdapter(adapter); + return super.getAdapter(adapter); } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) */ - @Override + @Override public ITerminalConnector createTerminalConnector(Map properties) { - Assert.isNotNull(properties); + Assert.isNotNull(properties); - // Check for the terminal connector id - String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"; //$NON-NLS-1$ + // Check for the terminal connector id + String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + if (connectorId == null) + connectorId = "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"; //$NON-NLS-1$ // Extract the telnet properties - String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); + String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT); String port = value != null ? value.toString() : null; value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT); String timeout = value != null ? value.toString() : null; - String endOfLine = (String)properties.get(ITerminalsConnectorConstants.PROP_TELNET_EOL); + String endOfLine = (String) properties.get(ITerminalsConnectorConstants.PROP_TELNET_EOL); int portOffset = 0; if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) { - portOffset = ((Integer)properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue(); - if (portOffset < 0) portOffset = 0; + portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue(); + if (portOffset < 0) + portOffset = 0; } // The real port to connect to is port + portOffset diff --git a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetMementoHandler.java b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetMementoHandler.java index ea8a4be6b65..bee62f3e874 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetMementoHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetMementoHandler.java @@ -33,12 +33,16 @@ public class TelnetMementoHandler implements IMementoHandler { // Do not write the terminal title to the memento -> needs to // be recreated at the time of restoration. - memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST)); + memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, + (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST)); Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT); - memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, value instanceof Integer ? ((Integer)value).intValue() : -1); + memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, + value instanceof Integer ? ((Integer) value).intValue() : -1); value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT); - memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, value instanceof Integer ? ((Integer)value).intValue() : -1); - memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); + memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, + value instanceof Integer ? ((Integer) value).intValue() : -1); + memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, + (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); } /* (non-Javadoc) @@ -50,9 +54,13 @@ public class TelnetMementoHandler implements IMementoHandler { Assert.isNotNull(properties); // Restore the terminal properties from the memento - properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST)); - properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT)); - properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT)); - properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); + properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, + memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST)); + properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, + memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT)); + properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, + memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT)); + properties.put(ITerminalsConnectorConstants.PROP_ENCODING, + memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/build.properties b/terminal/plugins/org.eclipse.tm.terminal.control/build.properties index 33c3ee02e8d..4e1b392a770 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/build.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.control/build.properties @@ -13,7 +13,7 @@ # Helmut Haigermoser and Ted Williams. # # Contributors: -# Michael Scharf (Wind River) - split into core, view and connector plugins +# Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Anna Dushistova (MontaVista) - added icons ############################################################################### @@ -31,9 +31,9 @@ bin.includes = .,\ css/,\ about.mappings,\ cdt_logo_icon32.png - + source.. = src/ output.. = bin/ src.includes = schema/,\ about.html - + diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/plugin.properties b/terminal/plugins/org.eclipse.tm.terminal.control/plugin.properties index daad8a7fc59..033ccc4ec69 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/plugin.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.control/plugin.properties @@ -13,7 +13,7 @@ # Helmut Haigermoser and Ted Williams. # # Contributors: -# Michael Scharf (Wind River) - split into core, view and connector plugins +# Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget ############################################################################### diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalConnector.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalConnector.java index dfa2f8faf91..99cb5472d72 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalConnector.java @@ -10,7 +10,7 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - [200541] Extract from TerminalConnectorExtension.TerminalConnectorProxy - * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl + * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl * Uwe Stieber (Wind River) - [282996] [terminal][api] Add "hidden" attribute to terminal connector extension point *******************************************************************************/ package org.eclipse.tm.internal.terminal.connector; @@ -65,6 +65,7 @@ public class TerminalConnector implements ITerminalConnector { */ TerminalConnectorImpl makeConnector() throws Exception; } + /** * The factory for creating impl instances. */ @@ -95,6 +96,7 @@ public class TerminalConnector implements ITerminalConnector { * This keeps the value until the connector is created. */ private ISettingsStore fStore; + /** * Constructor for the terminal connector. * @@ -104,119 +106,138 @@ public class TerminalConnector implements ITerminalConnector { * this ID. * @param name translatable name to display the connector in the UI. */ - public TerminalConnector(TerminalConnector.Factory terminalConnectorFactory, String id, String name, boolean hidden) { + public TerminalConnector(TerminalConnector.Factory terminalConnectorFactory, String id, String name, + boolean hidden) { fTerminalConnectorFactory = terminalConnectorFactory; fId = id; fName = name; fHidden = hidden; } + public String getInitializationErrorMessage() { getConnectorImpl(); - if(fException!=null) + if (fException != null) return fException.getLocalizedMessage(); return null; } + public String getId() { return fId; } + public String getName() { return fName; } + public boolean isHidden() { return fHidden; } + private TerminalConnectorImpl getConnectorImpl() { - if(!isInitialized()) { + if (!isInitialized()) { try { - fConnector=fTerminalConnectorFactory.makeConnector(); + fConnector = fTerminalConnectorFactory.makeConnector(); fConnector.initialize(); } catch (Exception e) { - fException=e; - fConnector=new TerminalConnectorImpl(){ + fException = e; + fConnector = new TerminalConnectorImpl() { public void connect(ITerminalControl control) { // super.connect(control); control.setState(TerminalState.CLOSED); control.setMsg(getInitializationErrorMessage()); } + public OutputStream getTerminalToRemoteStream() { return null; } + public String getSettingsSummary() { return null; - }}; + } + }; // that's the place where we log the exception Logger.logException(e); } - if(fConnector!=null && fStore!=null) + if (fConnector != null && fStore != null) fConnector.load(fStore); } return fConnector; } public boolean isInitialized() { - return fConnector!=null || fException!=null; + return fConnector != null || fException != null; } + public void connect(ITerminalControl control) { getConnectorImpl().connect(control); } + public void disconnect() { getConnectorImpl().disconnect(); } + public OutputStream getTerminalToRemoteStream() { return getConnectorImpl().getTerminalToRemoteStream(); } + public String getSettingsSummary() { - if(fConnector!=null) + if (fConnector != null) return getConnectorImpl().getSettingsSummary(); else return TerminalMessages.NotInitialized; } + public boolean isLocalEcho() { return getConnectorImpl().isLocalEcho(); } + public void load(ISettingsStore store) { - if(fConnector==null) { - fStore=store; + if (fConnector == null) { + fStore = store; } else { getConnectorImpl().load(store); } } + @Override public void setDefaultSettings() { getConnectorImpl().setDefaultSettings(); } + public void save(ISettingsStore store) { // no need to save the settings: it cannot have changed // because we are not initialized.... - if(fConnector!=null) + if (fConnector != null) getConnectorImpl().save(store); } + public void setTerminalSize(int newWidth, int newHeight) { // we assume that setTerminalSize is called also after // the terminal has been initialized. Else we would have to cache // the values.... - if(fConnector!=null) { + if (fConnector != null) { fConnector.setTerminalSize(newWidth, newHeight); } } + public Object getAdapter(Class adapter) { - TerminalConnectorImpl connector=null; - if(isInitialized()) - connector=getConnectorImpl(); + TerminalConnectorImpl connector = null; + if (isInitialized()) + connector = getConnectorImpl(); // if we cannot create the connector then we cannot adapt... - if(connector!=null) { + if (connector != null) { // maybe the connector is adaptable - if(connector instanceof IAdaptable) { - Object result =((IAdaptable)connector).getAdapter(adapter); + if (connector instanceof IAdaptable) { + Object result = ((IAdaptable) connector).getAdapter(adapter); // Not sure if the next block is needed.... - if(result==null) + if (result == null) //defer to the platform - result= Platform.getAdapterManager().getAdapter(connector, adapter); - if(result!=null) + result = Platform.getAdapterManager().getAdapter(connector, adapter); + if (result != null) return result; } // maybe the real adapter is what we need.... - if(adapter.isInstance(connector)) + if (adapter.isInstance(connector)) return connector; } // maybe we have to be adapted.... diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStream.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStream.java index 362306a4fb1..5dc1173c5bb 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStream.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStream.java @@ -29,19 +29,22 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream { */ static abstract public class Interceptor { protected OutputStream fOriginal; + /** * @param original the injection into the original stream begins * @throws IOException */ public void begin(OutputStream original) throws IOException { - fOriginal=original; + fOriginal = original; } + /** * @param b a byte was written to the {@link TerminalToRemoteInjectionOutputStream}. * @throws IOException */ public void write(int b) throws IOException { } + /** * @param b bytes written to the {@link TerminalToRemoteInjectionOutputStream}. * @param off the start offset in the data. @@ -50,122 +53,144 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream { */ public void write(byte[] b, int off, int len) throws IOException { } + /** * The injection into the normal stream ends. * @throws IOException */ public void close() throws IOException { } + public void flush() { } } + static public class BufferInterceptor extends Interceptor { - private final ByteArrayOutputStream fBuffer=new ByteArrayOutputStream(); - public void close() throws IOException { - fOriginal.write(fBuffer.toByteArray()); + private final ByteArrayOutputStream fBuffer = new ByteArrayOutputStream(); + + public void close() throws IOException { + fOriginal.write(fBuffer.toByteArray()); } + public void write(byte[] b, int off, int len) throws IOException { fBuffer.write(b, off, len); } + public void write(int b) throws IOException { fBuffer.write(b); } } + private class TerminalFilterOutputStream extends OutputStream { - final private Object fLock=TerminalToRemoteInjectionOutputStream.this; + final private Object fLock = TerminalToRemoteInjectionOutputStream.this; + public void close() throws IOException { - synchronized(fLock) { - if(fInjection==this) { + synchronized (fLock) { + if (fInjection == this) { flush(); ungrabOutput(); } } } + public void write(byte[] b, int off, int len) throws IOException { - synchronized(fLock) { + synchronized (fLock) { checkStream(); out.write(b, off, len); } } + public void write(byte[] b) throws IOException { - synchronized(fLock) { + synchronized (fLock) { checkStream(); out.write(b); } } + public void flush() throws IOException { - synchronized(fLock) { + synchronized (fLock) { checkStream(); out.flush(); } } + public void write(int b) throws IOException { - synchronized(fLock) { + synchronized (fLock) { checkStream(); out.write(b); } } + private void checkStream() throws IOException { - if(fInjection!=this) + if (fInjection != this) throw new IOException("Stream is closed"); //$NON-NLS-1$ } } - private Interceptor fInterceptor; - private TerminalFilterOutputStream fInjection; + + private Interceptor fInterceptor; + private TerminalFilterOutputStream fInjection; + public TerminalToRemoteInjectionOutputStream(OutputStream out) { super(out); } + synchronized protected void ungrabOutput() throws IOException { - if(fInterceptor!=null) { + if (fInterceptor != null) { fInterceptor.close(); - fInterceptor=null; - fInjection=null; + fInterceptor = null; + fInjection = null; } } - /** - * There can only be one injection stream active at a time. You must call close on the - * returned output stream to end the injection. - * @param interceptor This is used handle bytes sent while the injection stream is active. - * @return a output stream that can be used to write to the decorated stream. - * @throws IOException - */ - public synchronized OutputStream grabOutput(Interceptor interceptor) throws IOException { - if(fInjection!=null) { - throw new IOException("Buffer in use"); //$NON-NLS-1$ - } - fInterceptor=interceptor; - fInterceptor.begin(out); - fInjection=new TerminalFilterOutputStream(); - return fInjection; - } - /** See {@link #grabOutput(TerminalToRemoteInjectionOutputStream.Interceptor)}. - * @return injection output stream - * @throws IOException - */ - public synchronized OutputStream grabOutput() throws IOException { - return grabOutput(new BufferInterceptor()); - } - synchronized public void close() throws IOException { - if(fInjection!=null) { - fInjection.close(); - } - super.close(); + + /** + * There can only be one injection stream active at a time. You must call close on the + * returned output stream to end the injection. + * @param interceptor This is used handle bytes sent while the injection stream is active. + * @return a output stream that can be used to write to the decorated stream. + * @throws IOException + */ + public synchronized OutputStream grabOutput(Interceptor interceptor) throws IOException { + if (fInjection != null) { + throw new IOException("Buffer in use"); //$NON-NLS-1$ + } + fInterceptor = interceptor; + fInterceptor.begin(out); + fInjection = new TerminalFilterOutputStream(); + return fInjection; } + + /** See {@link #grabOutput(TerminalToRemoteInjectionOutputStream.Interceptor)}. + * @return injection output stream + * @throws IOException + */ + public synchronized OutputStream grabOutput() throws IOException { + return grabOutput(new BufferInterceptor()); + } + + synchronized public void close() throws IOException { + if (fInjection != null) { + fInjection.close(); + } + super.close(); + } + synchronized public void flush() throws IOException { - if(fInterceptor!=null) - fInterceptor.flush(); + if (fInterceptor != null) + fInterceptor.flush(); out.flush(); } - synchronized public void write(byte[] b, int off, int len) throws IOException { - if(fInterceptor!=null) - fInterceptor.write(b, off, len); - else - out.write(b, off, len); + + synchronized public void write(byte[] b, int off, int len) throws IOException { + if (fInterceptor != null) + fInterceptor.write(b, off, len); + else + out.write(b, off, len); } + synchronized public void write(int b) throws IOException { - if(fInterceptor!=null) - fInterceptor.write(b); - else - out.write(b); - } + if (fInterceptor != null) + fInterceptor.write(b); + else + out.write(b); + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/CommandInputFieldWithHistory.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/CommandInputFieldWithHistory.java index 0034ea648ba..92f3a89c549 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/CommandInputFieldWithHistory.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/CommandInputFieldWithHistory.java @@ -41,8 +41,6 @@ import org.eclipse.swt.widgets.Sash; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; - - /** * Manages the Command History for the command line input * of the terminal control. @@ -60,16 +58,16 @@ public class CommandInputFieldWithHistory implements ICommandInputField { private class FieldAssist implements IContentProposalProvider { public IContentProposal[] getProposals(String contents, int position) { - String prefix=contents.substring(0, position); - List result=new ArrayList(); + String prefix = contents.substring(0, position); + List result = new ArrayList(); // show an entry only once - Set seen=new HashSet(); + Set seen = new HashSet(); for (Iterator iterator = fHistory.iterator(); iterator.hasNext();) { String history = iterator.next(); - if(history.startsWith(prefix) && !seen.contains(history)) { + if (history.startsWith(prefix) && !seen.contains(history)) { // the content is the rest of the history item - String content=history.substring(prefix.length()); - result.add(new Proposal(content,history)); + String content = history.substring(prefix.length()); + result.add(new Proposal(content, history)); // don't add this proposal again seen.add(history); } @@ -78,14 +76,17 @@ public class CommandInputFieldWithHistory implements ICommandInputField { } } + private static class Proposal implements IContentProposal { private final String fContent; private final String fLabel; + Proposal(String content, String label) { - fContent= content; - fLabel= label; + fContent = content; + fLabel = label; } + public String getContent() { return fContent; } @@ -103,7 +104,7 @@ public class CommandInputFieldWithHistory implements ICommandInputField { } } - final List fHistory=new ArrayList(); + final List fHistory = new ArrayList(); /** * Keeps a modifiable history while in history editing mode */ @@ -111,7 +112,7 @@ public class CommandInputFieldWithHistory implements ICommandInputField { /** * The current position in the edit history */ - private int fEditHistoryPos=0; + private int fEditHistoryPos = 0; /** * The limit of the history. */ @@ -122,9 +123,11 @@ public class CommandInputFieldWithHistory implements ICommandInputField { private Text fInputField; private Sash fSash; private Composite fPanel; + public CommandInputFieldWithHistory(int maxHistorySize) { - fMaxSize=maxHistorySize; + fMaxSize = maxHistorySize; } + /** * Add a line to the history. * @param line The line to be added to the history. @@ -132,16 +135,17 @@ public class CommandInputFieldWithHistory implements ICommandInputField { protected void pushLine(String line) { endHistoryMode(); // anything to remember? - if(line==null || line.trim().length()==0) + if (line == null || line.trim().length() == 0) return; - fHistory.add(0,line); + fHistory.add(0, line); // ignore if the same as last - if(fHistory.size()>1 && line.equals(fHistory.get(1))) + if (fHistory.size() > 1 && line.equals(fHistory.get(1))) fHistory.remove(0); // limit the history size. - if(fHistory.size()>=fMaxSize) - fHistory.remove(fHistory.size()-1); + if (fHistory.size() >= fMaxSize) + fHistory.remove(fHistory.size() - 1); } + /** * Sets the history * @param history or null @@ -149,34 +153,36 @@ public class CommandInputFieldWithHistory implements ICommandInputField { public void setHistory(String history) { endHistoryMode(); fHistory.clear(); - if(history==null) + if (history == null) return; // add history entries separated by '\n' // fHistory.addAll(Arrays.asList(history.split("\n"))); //$NON-NLS-1$ // - StringTokenizer tok=new StringTokenizer(history,"\n"); //$NON-NLS-1$ - while(tok.hasMoreElements()) + StringTokenizer tok = new StringTokenizer(history, "\n"); //$NON-NLS-1$ + while (tok.hasMoreElements()) fHistory.add((String) tok.nextElement()); // } + /** * @return the current content of the history buffer and new line separated list */ public String getHistory() { - StringBuffer buff=new StringBuffer(); - boolean sep=false; + StringBuffer buff = new StringBuffer(); + boolean sep = false; for (Iterator iterator = fHistory.iterator(); iterator.hasNext();) { - String line=iterator.next(); - if(line.length()>0) { - if(sep) + String line = iterator.next(); + if (line.length() > 0) { + if (sep) buff.append("\n"); //$NON-NLS-1$ else - sep=true; + sep = true; buff.append(line); } } return buff.toString(); } + /** * @param currLine Line of text to be moved in history * @param count (+1 or -1) for forward and backward movement. -1 goes back @@ -184,22 +190,23 @@ public class CommandInputFieldWithHistory implements ICommandInputField { * if the limit is reached. */ public String move(String currLine, int count) { - if(!inHistoryMode()) { - fEditedHistory=new ArrayList(fHistory.size()+1); + if (!inHistoryMode()) { + fEditedHistory = new ArrayList(fHistory.size() + 1); fEditedHistory.add(currLine); fEditedHistory.addAll(fHistory); - fEditHistoryPos=0; + fEditHistoryPos = 0; } - fEditedHistory.set(fEditHistoryPos,currLine); - if(fEditHistoryPos+count>=fEditedHistory.size()) + fEditedHistory.set(fEditHistoryPos, currLine); + if (fEditHistoryPos + count >= fEditedHistory.size()) return null; - if(fEditHistoryPos+count<0) + if (fEditHistoryPos + count < 0) return null; - fEditHistoryPos+=count; + fEditHistoryPos += count; return (String) fEditedHistory.get(fEditHistoryPos); } + private boolean inHistoryMode() { - return fEditedHistory!=null; + return fEditedHistory != null; } /** @@ -207,41 +214,43 @@ public class CommandInputFieldWithHistory implements ICommandInputField { * @return the string to be shown in the command line */ protected String escape() { - if(!inHistoryMode()) + if (!inHistoryMode()) return null; - String line= (String) fEditedHistory.get(0); + String line = (String) fEditedHistory.get(0); endHistoryMode(); return line; } + /** * End history editing */ private void endHistoryMode() { - fEditedHistory=null; - fEditHistoryPos=0; + fEditedHistory = null; + fEditHistoryPos = 0; } - public void createControl(final Composite parent,final ITerminalViewControl terminal) { -// fSash = new Sash(parent,SWT.HORIZONTAL|SWT.SMOOTH); - fSash = new Sash(parent,SWT.HORIZONTAL); + + public void createControl(final Composite parent, final ITerminalViewControl terminal) { + // fSash = new Sash(parent,SWT.HORIZONTAL|SWT.SMOOTH); + fSash = new Sash(parent, SWT.HORIZONTAL); final GridData gd_sash = new GridData(SWT.FILL, SWT.CENTER, true, false); - gd_sash.heightHint=5; + gd_sash.heightHint = 5; fSash.setLayoutData(gd_sash); - fSash.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { + fSash.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { if (e.detail == SWT.DRAG) { // don't redraw during drag, it causes paint errors - bug 220971 return; } // no idea why this is needed GridData gdata = (GridData) fInputField.getLayoutData(); - Rectangle sashRect = fSash.getBounds (); - Rectangle containerRect = parent.getClientArea (); + Rectangle sashRect = fSash.getBounds(); + Rectangle containerRect = parent.getClientArea(); - int h=fInputField.getLineHeight(); + int h = fInputField.getLineHeight(); // make sure the input filed height is a multiple of the line height - gdata.heightHint = Math.max(((containerRect.height-e.y-sashRect.height)/h)*h,h); + gdata.heightHint = Math.max(((containerRect.height - e.y - sashRect.height) / h) * h, h); // do not show less then one line - e.y=Math.min(e.y,containerRect.height-h); + e.y = Math.min(e.y, containerRect.height - h); fInputField.setLayoutData(gdata); parent.layout(); // else the content assist icon will be replicated @@ -250,17 +259,20 @@ public class CommandInputFieldWithHistory implements ICommandInputField { }); fPanel = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); - layout.marginWidth = 0; layout.marginHeight = 0; layout.marginTop = 0; layout.marginBottom = 2; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.marginTop = 0; + layout.marginBottom = 2; fPanel.setLayout(layout); fPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - fInputField=new Text(fPanel, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL); - GridData data=new GridData(SWT.FILL, SWT.FILL, true, false); - boolean installDecoration=true; - if(installDecoration) { + fInputField = new Text(fPanel, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); + boolean installDecoration = true; + if (installDecoration) { // The ContentAssistCommandAdapter says: "The client is responsible for // ensuring that adequate space is reserved for the decoration." // TODO: what is the "adequate space"??? - data.horizontalIndent=6; + data.horizontalIndent = 6; } fInputField.setLayoutData(data); fInputField.setFont(terminal.getFont()); @@ -268,57 +280,56 @@ public class CommandInputFieldWithHistory implements ICommandInputField { // Else the ENTER key is sent *first* to the input field // and then to the field assist popup. // (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211659) - new ContentAssistCommandAdapter( - fInputField, - new TextContentAdapter(), - new FieldAssist(), - null, - null, + new ContentAssistCommandAdapter(fInputField, new TextContentAdapter(), new FieldAssist(), null, null, installDecoration); - fInputField.addKeyListener(new KeyListener(){ + fInputField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { // if the field assist has handled the key already then // ignore it (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211659) - if(!e.doit) + if (!e.doit) return; - if(e.character==SWT.CR || e.character==SWT.LF) { - e.doit=false; - String line=fInputField.getText(); - if(!terminal.pasteString(line+'\r')) + if (e.character == SWT.CR || e.character == SWT.LF) { + e.doit = false; + String line = fInputField.getText(); + if (!terminal.pasteString(line + '\r')) return; pushLine(line); setCommand("");//$NON-NLS-1$ - } else if(e.keyCode==SWT.ARROW_UP || e.keyCode==SWT.PAGE_UP) { - e.doit=false; - setCommand(move(fInputField.getText(),1)); - } else if(e.keyCode==SWT.ARROW_DOWN || e.keyCode==SWT.PAGE_DOWN) { - e.doit=false; - setCommand(move(fInputField.getText(),-1)); - } else if(e.keyCode==SWT.ESC) { - e.doit=false; + } else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.PAGE_UP) { + e.doit = false; + setCommand(move(fInputField.getText(), 1)); + } else if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.PAGE_DOWN) { + e.doit = false; + setCommand(move(fInputField.getText(), -1)); + } else if (e.keyCode == SWT.ESC) { + e.doit = false; setCommand(escape()); } } + private void setCommand(String line) { - if(line==null) + if (line == null) return; fInputField.setText(line); fInputField.setSelection(fInputField.getCharCount()); } + public void keyReleased(KeyEvent e) { } }); } + public void setFont(Font font) { fInputField.setFont(font); fInputField.getParent().layout(true); } + public void dispose() { fSash.dispose(); - fSash=null; + fSash = null; fPanel.dispose(); - fPanel=null; + fPanel = null; fInputField.dispose(); - fInputField=null; + fInputField = null; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ICommandInputField.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ICommandInputField.java index 2e31750195f..8e314acd78b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ICommandInputField.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ICommandInputField.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.control; @@ -23,8 +23,9 @@ public interface ICommandInputField { * @param terminal */ void createControl(Composite parent, ITerminalViewControl terminal); - + void dispose(); + /** * Sets the font of a control created with {@link #createControl(Composite, ITerminalViewControl)} * @param control diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalListener2.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalListener2.java index 1166a99c929..30f22f82ba0 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalListener2.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalListener2.java @@ -13,7 +13,7 @@ package org.eclipse.tm.internal.terminal.control; /** * Terminal listener allowing to listen to terminal selection changes. - * + * * @since 4.1 */ public interface ITerminalListener2 extends ITerminalListener { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java index 1e07fb20069..d926433c83b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java @@ -17,7 +17,7 @@ import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly; * Terminal specific version of {@link org.eclipse.swt.events.MouseListener} * @since 4.1 */ -public interface ITerminalMouseListener { +public interface ITerminalMouseListener { /** * Invoked when a double-click has happend inside the terminal control.
*
@@ -26,6 +26,7 @@ public interface ITerminalMouseListener { * @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values */ void mouseDoubleClick(ITerminalTextDataReadOnly terminalText, int line, int column, int button); + /** * Invoked when a mouse button is pushed down inside the terminal control.
*
@@ -34,6 +35,7 @@ public interface ITerminalMouseListener { * @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values */ void mouseDown(ITerminalTextDataReadOnly terminalText, int line, int column, int button); + /** * Invoked when a mouse button is released inside the terminal control.
*
diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java index 08706167229..ef309cafc19 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java @@ -50,13 +50,15 @@ public interface ITerminalViewControl { */ String getEncoding(); - boolean isEmpty(); - /** - * Sets the Terminal font - * @deprecated use {@link #setFont(String)} in order to support bold and italic variants of the given font - * @param font - */ + boolean isEmpty(); + + /** + * Sets the Terminal font + * @deprecated use {@link #setFont(String)} in order to support bold and italic variants of the given font + * @param font + */ void setFont(Font font); + /** * Sets the font for the Terminal, using a JFace symbolic font name, such * that bold and italic variants can be leveraged. @@ -64,51 +66,74 @@ public interface ITerminalViewControl { * @param fontName */ void setFont(String fontName); + void setInvertedColors(boolean invert); + Font getFont(); + /** * @return the text control */ Control getControl(); + /** * @return the root of all controls */ Control getRootControl(); - boolean isDisposed(); - void selectAll(); - void clearTerminal(); - void copy(); - void paste(); - String getSelection(); - TerminalState getState(); - Clipboard getClipboard(); - void disconnectTerminal(); - void disposeTerminal(); - String getSettingsSummary(); - ITerminalConnector[] getConnectors(); - void setFocus(); - ITerminalConnector getTerminalConnector(); - void setConnector(ITerminalConnector connector); - void connectTerminal(); - /** - * @param write a single character to terminal - */ - void sendKey(char arg0); + + boolean isDisposed(); + + void selectAll(); + + void clearTerminal(); + + void copy(); + + void paste(); + + String getSelection(); + + TerminalState getState(); + + Clipboard getClipboard(); + + void disconnectTerminal(); + + void disposeTerminal(); + + String getSettingsSummary(); + + ITerminalConnector[] getConnectors(); + + void setFocus(); + + ITerminalConnector getTerminalConnector(); + + void setConnector(ITerminalConnector connector); + + void connectTerminal(); + + /** + * @param write a single character to terminal + */ + void sendKey(char arg0); + /** * @param string write string to terminal */ public boolean pasteString(String string); - boolean isConnected(); + boolean isConnected(); - /** - * @param inputField null means no input field is shown - */ - void setCommandInputField(ICommandInputField inputField); - /** - * @return null or the current input field - */ - ICommandInputField getCommandInputField(); + /** + * @param inputField null means no input field is shown + */ + void setCommandInputField(ICommandInputField inputField); + + /** + * @return null or the current input field + */ + ICommandInputField getCommandInputField(); /** * @return the maximum number of lines to display @@ -121,13 +146,16 @@ public interface ITerminalViewControl { * in the terminal view. -1 means unlimited. */ public void setBufferLineLimit(int bufferLineLimit); + boolean isScrollLock(); + void setScrollLock(boolean on); - + /** * @since 4.1 */ void addMouseListener(ITerminalMouseListener listener); + /** * @since 4.1 */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/TerminalViewControlFactory.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/TerminalViewControlFactory.java index 42717a45731..b04fb597701 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/TerminalViewControlFactory.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/TerminalViewControlFactory.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget @@ -23,7 +23,8 @@ public class TerminalViewControlFactory { * @param wndParent The Window parent to embed the Terminal in. * @param connectors Provided connectors. */ - public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors) { + public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, + ITerminalConnector[] connectors) { return makeControl(target, wndParent, connectors, false); } @@ -32,12 +33,13 @@ public class TerminalViewControlFactory { * @param target Callback for notifying the owner of Terminal state changes. * @param wndParent The Window parent to embed the Terminal in. * @param connectors Provided connectors. - * @param useCommonPrefs If true, the Terminal widget will pick up settings + * @param useCommonPrefs If true, the Terminal widget will pick up settings * from the org.eclipse.tm.terminal.TerminalPreferencePage Preference page. * Otherwise, clients need to maintain settings themselves. * @since 3.2 */ - public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors, boolean useCommonPrefs) { + public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, + ITerminalConnector[] connectors, boolean useCommonPrefs) { return new VT100TerminalControl(target, wndParent, connectors, useCommonPrefs); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/AbstractTerminalAction.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/AbstractTerminalAction.java index 218044a07aa..9745792e7af 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/AbstractTerminalAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/AbstractTerminalAction.java @@ -32,13 +32,11 @@ public abstract class AbstractTerminalAction extends Action { this(null, strId, 0); } - public AbstractTerminalAction(ITerminalViewControl target, - String strId) { + public AbstractTerminalAction(ITerminalViewControl target, String strId) { this(target, strId, 0); } - public AbstractTerminalAction(ITerminalViewControl target, - String strId, int style) { + public AbstractTerminalAction(ITerminalViewControl target, String strId, int style) { super("", style); //$NON-NLS-1$ fTarget = target; @@ -48,27 +46,20 @@ public abstract class AbstractTerminalAction extends Action { abstract public void run(); - protected void setupAction(String strText, String strToolTip, - String strImage, String strEnabledImage, String strDisabledImage, - boolean bEnabled) { - setupAction(strText, strToolTip, strImage, strEnabledImage, - strDisabledImage, bEnabled, TerminalPlugin.getDefault() - .getImageRegistry()); + protected void setupAction(String strText, String strToolTip, String strImage, String strEnabledImage, + String strDisabledImage, boolean bEnabled) { + setupAction(strText, strToolTip, strImage, strEnabledImage, strDisabledImage, bEnabled, + TerminalPlugin.getDefault().getImageRegistry()); } - protected void setupAction(String strText, String strToolTip, - String strHoverImage, String strEnabledImage, - String strDisabledImage, boolean bEnabled, - ImageRegistry imageRegistry) { - setupAction(strText, strToolTip, imageRegistry - .getDescriptor(strHoverImage), imageRegistry - .getDescriptor(strEnabledImage), imageRegistry - .getDescriptor(strDisabledImage), bEnabled); + protected void setupAction(String strText, String strToolTip, String strHoverImage, String strEnabledImage, + String strDisabledImage, boolean bEnabled, ImageRegistry imageRegistry) { + setupAction(strText, strToolTip, imageRegistry.getDescriptor(strHoverImage), + imageRegistry.getDescriptor(strEnabledImage), imageRegistry.getDescriptor(strDisabledImage), bEnabled); } - protected void setupAction(String strText, String strToolTip, - ImageDescriptor hoverImage, ImageDescriptor enabledImage, - ImageDescriptor disabledImage, boolean bEnabled) { + protected void setupAction(String strText, String strToolTip, ImageDescriptor hoverImage, + ImageDescriptor enabledImage, ImageDescriptor disabledImage, boolean bEnabled) { setText(strText); setToolTipText(strToolTip); setEnabled(bEnabled); @@ -85,7 +76,7 @@ public abstract class AbstractTerminalAction extends Action { /** * Return the terminal instance on which the action should operate. - * + * * @return the terminal instance on which the action should operate. */ protected ITerminalViewControl getTarget() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.java index 80baa8a81fe..b613258f390 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.java @@ -23,8 +23,7 @@ import org.eclipse.osgi.util.NLS; public class ActionMessages extends NLS { static { - NLS.initializeMessages(ActionMessages.class.getName(), - ActionMessages.class); + NLS.initializeMessages(ActionMessages.class.getName(), ActionMessages.class); } public static String COPY; diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.properties b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.properties index ffc7d452c3a..e6302102f4d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ActionMessages.properties @@ -13,7 +13,7 @@ # Helmut Haigermoser and Ted Williams. # # Contributors: -# Michael Scharf (Wind River) - split into core, view and connector plugins +# Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Anna Dushistova (MontaVista) - [227537] moved actions from terminal.view to terminal plugin ############################################################################### diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ImageConsts.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ImageConsts.java index e44e7dfaa27..5d3852f41b7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ImageConsts.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/ImageConsts.java @@ -23,7 +23,7 @@ public interface ImageConsts { public final static String IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$ public final static String IMAGE_DIR_LOCALTOOL = IMAGE_DIR_ROOT + "clcl16/"; // basic colors - size 16x16 //$NON-NLS-1$ public final static String IMAGE_DIR_DLCL = IMAGE_DIR_ROOT + "dlcl16/"; // disabled - size 16x16 //$NON-NLS-1$ - public final static String IMAGE_DIR_ELCL = IMAGE_DIR_ROOT+ "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$ + public final static String IMAGE_DIR_ELCL = IMAGE_DIR_ROOT + "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$ public static final String IMAGE_CLCL_CLEAR_ALL = "ImageClclClearAll"; //$NON-NLS-1$ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionClearAll.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionClearAll.java index eb0e91ce181..928465e6728 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionClearAll.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionClearAll.java @@ -26,19 +26,15 @@ public class TerminalActionClearAll extends AbstractTerminalAction { public TerminalActionClearAll() { super(TerminalActionClearAll.class.getName()); - setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, - ImageConsts.IMAGE_CLCL_CLEAR_ALL, - ImageConsts.IMAGE_ELCL_CLEAR_ALL, - ImageConsts.IMAGE_DLCL_CLEAR_ALL, false); + setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, ImageConsts.IMAGE_CLCL_CLEAR_ALL, + ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DLCL_CLEAR_ALL, false); } public TerminalActionClearAll(ITerminalViewControl target) { super(target, TerminalActionClearAll.class.getName()); - setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, - ImageConsts.IMAGE_CLCL_CLEAR_ALL, - ImageConsts.IMAGE_ELCL_CLEAR_ALL, - ImageConsts.IMAGE_DLCL_CLEAR_ALL, false); + setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, ImageConsts.IMAGE_CLCL_CLEAR_ALL, + ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DLCL_CLEAR_ALL, false); } public void run() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCopy.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCopy.java index 375accd6c0b..55cc03a3b08 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCopy.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCopy.java @@ -29,20 +29,18 @@ public class TerminalActionCopy extends AbstractTerminalAction { super(TerminalActionCopy.class.getName()); setActionDefinitionId("org.eclipse.tm.terminal.copy"); //$NON-NLS-1$ ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.COPY, ActionMessages.COPY, si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true); + setupAction(ActionMessages.COPY, ActionMessages.COPY, si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), + si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), + si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true); } public TerminalActionCopy(ITerminalViewControl target) { super(target, TerminalActionCopy.class.getName()); setActionDefinitionId("org.eclipse.tm.terminal.copy"); //$NON-NLS-1$ ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.COPY, ActionMessages.COPY, si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si - .getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true); + setupAction(ActionMessages.COPY, ActionMessages.COPY, si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), + si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), + si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true); } public void run() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCut.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCut.java index d35479dd174..4b07afd75a1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCut.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionCut.java @@ -27,19 +27,17 @@ public class TerminalActionCut extends AbstractTerminalAction { public TerminalActionCut() { super(TerminalActionCut.class.getName()); ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.CUT, ActionMessages.CUT, si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true); + setupAction(ActionMessages.CUT, ActionMessages.CUT, si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), + si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), + si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true); } public TerminalActionCut(ITerminalViewControl target) { super(target, TerminalActionCut.class.getName()); ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.CUT, ActionMessages.CUT, si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si - .getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true); + setupAction(ActionMessages.CUT, ActionMessages.CUT, si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), + si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), + si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true); } public void run() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionPaste.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionPaste.java index af13acb3964..1fb92daa66b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionPaste.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionPaste.java @@ -33,22 +33,18 @@ public class TerminalActionPaste extends AbstractTerminalAction { super(TerminalActionPaste.class.getName()); setActionDefinitionId("org.eclipse.tm.terminal.paste"); //$NON-NLS-1$ ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.PASTE, ActionMessages.PASTE, - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), - false); + setupAction(ActionMessages.PASTE, ActionMessages.PASTE, si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), + si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), + si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), false); } public TerminalActionPaste(ITerminalViewControl target) { super(target, TerminalActionPaste.class.getName()); setActionDefinitionId("org.eclipse.tm.terminal.paste"); //$NON-NLS-1$ ISharedImages si = PlatformUI.getWorkbench().getSharedImages(); - setupAction(ActionMessages.PASTE, ActionMessages.PASTE, - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), - si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), - false); + setupAction(ActionMessages.PASTE, ActionMessages.PASTE, si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), + si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE), + si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), false); } public void run() { @@ -62,8 +58,7 @@ public class TerminalActionPaste extends AbstractTerminalAction { ITerminalViewControl target = getTarget(); boolean bEnabled = target != null && target.getClipboard() != null && !target.getClipboard().isDisposed(); if (bEnabled) { - String strText = (String) target.getClipboard().getContents( - TextTransfer.getInstance()); + String strText = (String) target.getClipboard().getContents(TextTransfer.getInstance()); bEnabled = ((strText != null) && (!strText.equals("")) && (target.getState() == TerminalState.CONNECTED));//$NON-NLS-1$ } setEnabled(bEnabled); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionSelectAll.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionSelectAll.java index b2f0057e3d3..f194c97de06 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionSelectAll.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/actions/TerminalActionSelectAll.java @@ -27,15 +27,13 @@ public class TerminalActionSelectAll extends AbstractTerminalAction { public TerminalActionSelectAll() { super(TerminalActionSelectAll.class.getName()); - setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, - (ImageDescriptor) null, null, null, false); + setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, (ImageDescriptor) null, null, null, false); } public TerminalActionSelectAll(ITerminalViewControl target) { super(target, TerminalActionSelectAll.class.getName()); - setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, - (ImageDescriptor) null, null, null, false); + setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, (ImageDescriptor) null, null, null, false); } public void run() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/ITerminalControlForText.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/ITerminalControlForText.java index 0bbd0096fbb..7fa736975e5 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/ITerminalControlForText.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/ITerminalControlForText.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Anton Leherbauer (Wind River) - [458398] Add support for normal/application cursor keys mode @@ -23,19 +23,21 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; * */ public interface ITerminalControlForText { - + TerminalState getState(); + void setState(TerminalState state); + void setTerminalTitle(String title); - + ITerminalConnector getTerminalConnector(); OutputStream getOutputStream(); - + /** * Enable/disable Application Cursor Keys mode (DECCKM) * @param enable */ void enableApplicationCursorKeys(boolean enable); - + } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.java index 56b3d1b3511..cf95067c05c 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget @@ -19,14 +19,14 @@ public class TerminalMessages extends NLS { NLS.initializeMessages(TerminalMessages.class.getName(), TerminalMessages.class); } - public static String TerminalError; - public static String SocketError; - public static String IOError; - public static String CannotConnectTo; - public static String NotInitialized; + public static String TerminalError; + public static String SocketError; + public static String IOError; + public static String CannotConnectTo; + public static String NotInitialized; - //Preference Page - public static String INVERT_COLORS; - public static String BUFFERLINES; + //Preference Page + public static String INVERT_COLORS; + public static String BUFFERLINES; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.properties b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.properties index 93ee9767472..34492a197cb 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalMessages.properties @@ -13,7 +13,7 @@ # Helmut Haigermoser and Ted Williams. # # Contributors: -# Michael Scharf (Wind River) - split into core, view and connector plugins +# Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget ############################################################################### diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalPlugin.java index c566aaf61c6..9f96e7b28c4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/impl/TerminalPlugin.java @@ -31,14 +31,15 @@ import org.osgi.framework.BundleContext; public class TerminalPlugin extends AbstractUIPlugin { private static TerminalPlugin plugin; - public static final String PLUGIN_ID = "org.eclipse.tm.terminal.control"; //$NON-NLS-1$ - public static final String HELP_VIEW = PLUGIN_ID + ".terminal_view"; //$NON-NLS-1$ + public static final String PLUGIN_ID = "org.eclipse.tm.terminal.control"; //$NON-NLS-1$ + public static final String HELP_VIEW = PLUGIN_ID + ".terminal_view"; //$NON-NLS-1$ /** * The constructor. */ public TerminalPlugin() { } + /** * Returns the shared instance. */ @@ -50,7 +51,7 @@ public class TerminalPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -59,7 +60,7 @@ public class TerminalPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } @@ -73,20 +74,24 @@ public class TerminalPlugin extends AbstractUIPlugin { } @Override - protected void initializeImageRegistry(ImageRegistry imageRegistry) { + protected void initializeImageRegistry(ImageRegistry imageRegistry) { try { // Local toolbars - putImageInRegistry(imageRegistry, ImageConsts.IMAGE_CLCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$ + putImageInRegistry(imageRegistry, ImageConsts.IMAGE_CLCL_CLEAR_ALL, + ImageConsts.IMAGE_DIR_LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$ // Enabled local toolbars - putImageInRegistry(imageRegistry, ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_ELCL + "clear_co.gif"); //$NON-NLS-1$ + putImageInRegistry(imageRegistry, ImageConsts.IMAGE_ELCL_CLEAR_ALL, + ImageConsts.IMAGE_DIR_ELCL + "clear_co.gif"); //$NON-NLS-1$ // Disabled local toolbars - putImageInRegistry(imageRegistry, ImageConsts.IMAGE_DLCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_DLCL + "clear_co.gif"); //$NON-NLS-1$ + putImageInRegistry(imageRegistry, ImageConsts.IMAGE_DLCL_CLEAR_ALL, + ImageConsts.IMAGE_DIR_DLCL + "clear_co.gif"); //$NON-NLS-1$ } catch (MalformedURLException malformedURLException) { malformedURLException.printStackTrace(); } } - protected void putImageInRegistry(ImageRegistry imageRegistry, String strKey, String relativePath) throws MalformedURLException { + protected void putImageInRegistry(ImageRegistry imageRegistry, String strKey, String relativePath) + throws MalformedURLException { URL url = TerminalPlugin.getDefault().getBundle().getEntry(relativePath); ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url); imageRegistry.put(strKey, imageDescriptor); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/EditActionAccelerators.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/EditActionAccelerators.java index 6f5f5f2966f..9f8b06f57ed 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/EditActionAccelerators.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/EditActionAccelerators.java @@ -33,7 +33,7 @@ class EditActionAccelerators { private void addAccelerator(String commandId) { TriggerSequence[] bindings = bindingsFor(commandId); - for (int i=0; i - * + * * There are never any ANSI control characters or escape sequences in the * text being displayed by this method (this includes newlines, carriage * returns, and tabs). @@ -134,7 +134,7 @@ public interface IVT100EmulatorBackend { * first column of the next line, as if a carriage return (CR) and a NL were * written. *

- * + * * UNIX terminals typically display a NL character as a CR followed by a NL * because the terminal device typically has the ONLCR attribute bit set * (see the termios(4) man page for details), which causes the terminal @@ -151,7 +151,7 @@ public interface IVT100EmulatorBackend { * This method returns the relative line number of the line containing the * cursor. The returned line number is relative to the topmost visible line, * which has relative line number 0. - * + * * @return The relative line number of the line containing the cursor. */ int getCursorLine(); @@ -181,7 +181,7 @@ public interface IVT100EmulatorBackend { * If enabled, writing to the rightmost column does not cause * an immediate wrap to the next line. Instead the line wrap occurs on the * next output character. - * + * * @param enable whether to enable or disable VT100 line wrapping mode */ void setVT100LineWrapping(boolean enable); @@ -193,14 +193,14 @@ public interface IVT100EmulatorBackend { /** * Enables/disables insert mode (IRM). - * + * * @param enable whether to enable insert mode */ void setInsertMode(boolean enable); /** * Set scrolling region. Negative values reset the scroll region. - * + * * @param top top line of scroll region * @param bottom bottom line of scroll region */ @@ -208,14 +208,14 @@ public interface IVT100EmulatorBackend { /** * Scroll text upwards. - * + * * @param lines number of lines to scroll */ void scrollUp(int lines); /** * Scroll text downwards. - * + * * @param lines number of lines to scroll */ void scrollDown(int lines); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/LoggingOutputStream.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/LoggingOutputStream.java index e291b9e5345..c365c87043b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/LoggingOutputStream.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/LoggingOutputStream.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -23,25 +23,25 @@ public class LoggingOutputStream extends FilterOutputStream { } public void write(byte[] b, int off, int len) throws IOException { - if(Logger.isLogEnabled()) + if (Logger.isLogEnabled()) Logger.log("Received " + len + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$ Logger.encode(new String(b, 0, len)) + "'"); //$NON-NLS-1$ - + // we cannot call super.write, because this would call our write // which logs character by character..... //super.write(b, off, len); if ((off | len | (b.length - (len + off)) | (off + len)) < 0) - throw new IndexOutOfBoundsException(); + throw new IndexOutOfBoundsException(); - for (int i = 0 ; i < len ; i++) { - super.write(b[off + i]); + for (int i = 0; i < len; i++) { + super.write(b[off + i]); } } public void write(int b) throws IOException { - if(Logger.isLogEnabled()) + if (Logger.isLogEnabled()) Logger.log("Received " + 1 + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$ - Logger.encode(new String(new byte[]{(byte)b}, 0, 1)) + "'"); //$NON-NLS-1$ + Logger.encode(new String(new byte[] { (byte) b }, 0, 1)) + "'"); //$NON-NLS-1$ super.write(b); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java index 92d357f80d2..0f5f4ad1dbf 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode @@ -20,13 +20,14 @@ import org.eclipse.tm.terminal.model.Style; public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { final IVT100EmulatorBackend fBackend; final PrintStream fWriter; + public VT100BackendTraceDecorator(IVT100EmulatorBackend backend, PrintStream out) { fBackend = backend; - fWriter=out; + fWriter = out; } public void appendString(String buffer) { - fWriter.println("appendString(\""+buffer+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("appendString(\"" + buffer + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.appendString(buffer); } @@ -36,12 +37,12 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { } public void deleteCharacters(int n) { - fWriter.println("deleteCharacters("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("deleteCharacters(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.deleteCharacters(n); } public void deleteLines(int n) { - fWriter.println("deleteLines("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("deleteLines(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.deleteLines(n); } @@ -100,12 +101,12 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { } public void insertCharacters(int charactersToInsert) { - fWriter.println("insertCharacters("+charactersToInsert+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("insertCharacters(" + charactersToInsert + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.insertCharacters(charactersToInsert); } public void insertLines(int n) { - fWriter.println("insertLines("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("insertLines(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.insertLines(n); } @@ -115,37 +116,37 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { } public void setCursor(int targetLine, int targetColumn) { - fWriter.println("setCursor("+targetLine+", "+targetColumn+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + fWriter.println("setCursor(" + targetLine + ", " + targetColumn + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fBackend.setCursor(targetLine, targetColumn); } public void setCursorColumn(int targetColumn) { - fWriter.println("setCursorColumn("+targetColumn+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setCursorColumn(" + targetColumn + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setCursorColumn(targetColumn); } public void setCursorLine(int targetLine) { - fWriter.println("setCursorLine("+targetLine+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setCursorLine(" + targetLine + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setCursorLine(targetLine); } public void setDefaultStyle(Style defaultStyle) { - fWriter.println("setDefaultStyle("+defaultStyle+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setDefaultStyle(" + defaultStyle + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setDefaultStyle(defaultStyle); } public void setDimensions(int lines, int cols) { - fWriter.println("setDimensions("+lines+","+cols+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + fWriter.println("setDimensions(" + lines + "," + cols + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fBackend.setDimensions(lines, cols); } public void setStyle(Style style) { - fWriter.println("setStyle("+style+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setStyle(" + style + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setStyle(style); } public void setVT100LineWrapping(boolean enable) { - fWriter.println("setVT100LineWrapping("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setVT100LineWrapping(" + enable + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setVT100LineWrapping(enable); } @@ -154,22 +155,22 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { } public void setInsertMode(boolean enable) { - fWriter.println("setInsertMode("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setInsertMode(" + enable + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setInsertMode(enable); } public void setScrollRegion(int top, int bottom) { - fWriter.println("setScrollRegion("+top+','+bottom+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("setScrollRegion(" + top + ',' + bottom + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.setScrollRegion(top, bottom); } public void scrollUp(int lines) { - fWriter.println("scrollUp("+lines+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("scrollUp(" + lines + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.scrollUp(lines); } public void scrollDown(int lines) { - fWriter.println("scrollDown("+lines+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fWriter.println("scrollDown(" + lines + ")"); //$NON-NLS-1$ //$NON-NLS-2$ fBackend.scrollDown(lines); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java index cc3b76424c9..92159e8702b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java @@ -84,7 +84,6 @@ public class VT100Emulator implements ControlListener { * character. Expecting a character set designation character. */ private static final int ANSISTATE_EXPECTING_CHARSET_DESIGNATION = 5; - /** * This field holds the current state of the Finite TerminalState Automaton (FSA) @@ -140,6 +139,7 @@ public class VT100Emulator implements ControlListener { Reader fReader; boolean fCrAfterNewLine; + /** * The constructor. */ @@ -154,13 +154,13 @@ public class VT100Emulator implements ControlListener { ansiParameters[i] = new StringBuffer(); } setInputStreamReader(reader); - if(TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND)) - text=new VT100BackendTraceDecorator(new VT100EmulatorBackend(data),System.out); + if (TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND)) + text = new VT100BackendTraceDecorator(new VT100EmulatorBackend(data), System.out); else - text=new VT100EmulatorBackend(data); + text = new VT100EmulatorBackend(data); -// text.setDimensions(24, 80); - Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$ + // text.setDimensions(24, 80); + Style style = Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$ text.setDefaultStyle(style); text.setStyle(style); } @@ -182,7 +182,7 @@ public class VT100Emulator implements ControlListener { fReader = reader; } - public void setDimensions(int lines,int cols) { + public void setDimensions(int lines, int cols) { text.setDimensions(lines, cols); ITerminalConnector telnetConnection = getConnector(); if (telnetConnection != null) { @@ -236,22 +236,23 @@ public class VT100Emulator implements ControlListener { if (text != null) adjustTerminalDimensions(); } -// /** -// * This method executes in the Display thread to process data received from -// * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and -// * other implementors of {@link ITerminalConnector}, like the -// * SerialPortHandler. -// *

-// * These connectors write text to the terminal's buffer through -// * {@link TerminalControl#writeToTerminal(String)} and then have -// * this run method executed in the display thread. This method -// * must not execute at the same time as methods -// * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}. -// *

-// * IMPORTANT: This method must be called in strict alternation with method -// * {@link #setNewText(StringBuffer)}. -// *

-// */ + + // /** + // * This method executes in the Display thread to process data received from + // * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and + // * other implementors of {@link ITerminalConnector}, like the + // * SerialPortHandler. + // *

+ // * These connectors write text to the terminal's buffer through + // * {@link TerminalControl#writeToTerminal(String)} and then have + // * this run method executed in the display thread. This method + // * must not execute at the same time as methods + // * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}. + // *

+ // * IMPORTANT: This method must be called in strict alternation with method + // * {@link #setNewText(StringBuffer)}. + // *

+ // */ public void processText() { try { // Find the width and height of the terminal, and resize it to display an @@ -275,6 +276,7 @@ public class VT100Emulator implements ControlListener { Logger.logException(ex); } } + /** * This method scans the newly received text, processing ANSI control * characters and escape sequences and displaying normal text. @@ -283,7 +285,6 @@ public class VT100Emulator implements ControlListener { private void processNewText() throws IOException { Logger.log("entered"); //$NON-NLS-1$ - // Scan the newly received text. while (hasNextChar()) { @@ -309,7 +310,7 @@ public class VT100Emulator implements ControlListener { case '\n': processNewline(); // Newline (Control-J) - if(fCrAfterNewLine) + if (fCrAfterNewLine) processCarriageReturn(); // Carriage Return (Control-M) break; @@ -382,8 +383,7 @@ public class VT100Emulator implements ControlListener { break; default: - Logger - .log("Unsupported escape sequence: escape '" + character + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + Logger.log("Unsupported escape sequence: escape '" + character + "'"); //$NON-NLS-1$ //$NON-NLS-2$ ansiState = ANSISTATE_INITIAL; break; } @@ -448,6 +448,7 @@ public class VT100Emulator implements ControlListener { } } } + private void resetTerminal() { text.eraseAll(); text.setCursor(0, 0); @@ -456,6 +457,7 @@ public class VT100Emulator implements ControlListener { text.setInsertMode(false); terminal.enableApplicationCursorKeys(false); } + /** * This method is called when we have parsed an OS Command escape sequence. * The only one we support is "\e]0;...\u0007", which sets the terminal @@ -463,8 +465,7 @@ public class VT100Emulator implements ControlListener { */ private void processAnsiOsCommand() { if (ansiOsCommand.charAt(0) != '0' || ansiOsCommand.charAt(1) != ';') { - Logger - .log("Ignoring unsupported ANSI OSC sequence: '" + ansiOsCommand + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + Logger.log("Ignoring unsupported ANSI OSC sequence: '" + ansiOsCommand + "'"); //$NON-NLS-1$ //$NON-NLS-2$ return; } terminal.setTerminalTitle(ansiOsCommand.substring(2)); @@ -514,7 +515,7 @@ public class VT100Emulator implements ControlListener { // Line Position Absolute [row] (default = [1,column]) (VPA). processAnsiCommand_d(); break; - + case 'E': // Move cursor to first column of Nth next line (default 1). processAnsiCommand_E(); @@ -559,7 +560,7 @@ public class VT100Emulator implements ControlListener { // Set Mode. processAnsiCommand_l(); break; - + case 'M': // Delete line(s). processAnsiCommand_M(); @@ -688,7 +689,7 @@ public class VT100Emulator implements ControlListener { // Line Position Absolute [row] (default = [1,column]) (VPA). text.setCursorLine(getAnsiParameter(0) - 1); } - + /** * This method moves the cursor to the first column of the Nth next line, * where N is specified by the ANSI parameter (default 1). @@ -838,15 +839,14 @@ public class VT100Emulator implements ControlListener { ansiParameters[0].append('0'); } - Style style=text.getStyle(); + Style style = text.getStyle(); // There are a non-zero number of ANSI parameters. Process each one in // order. int totalParameters = ansiParameters.length; int parameterIndex = 0; - while (parameterIndex < totalParameters - && ansiParameters[parameterIndex].length() > 0) { + while (parameterIndex < totalParameters && ansiParameters[parameterIndex].length() > 0) { int ansiParameter = getAnsiParameter(parameterIndex); switch (ansiParameter) { @@ -896,15 +896,15 @@ public class VT100Emulator implements ControlListener { break; case 31: - style = style.setForground("RED"); //$NON-NLS-1$ + style = style.setForground("RED"); //$NON-NLS-1$ break; case 32: - style = style.setForground("GREEN"); //$NON-NLS-1$ + style = style.setForground("GREEN"); //$NON-NLS-1$ break; case 33: - style = style.setForground("YELLOW"); //$NON-NLS-1$ + style = style.setForground("YELLOW"); //$NON-NLS-1$ break; case 34: @@ -912,7 +912,7 @@ public class VT100Emulator implements ControlListener { break; case 35: - style = style.setForground("MAGENTA"); //$NON-NLS-1$ + style = style.setForground("MAGENTA"); //$NON-NLS-1$ break; case 36: @@ -964,8 +964,7 @@ public class VT100Emulator implements ControlListener { break; default: - Logger - .log("Unsupported graphics rendition parameter: " + ansiParameter); //$NON-NLS-1$ + Logger.log("Unsupported graphics rendition parameter: " + ansiParameter); //$NON-NLS-1$ break; } @@ -1025,23 +1024,23 @@ public class VT100Emulator implements ControlListener { top = getAnsiParameter(0); bottom = getAnsiParameter(1); } - text.setScrollRegion(top-1, bottom-1); + text.setScrollRegion(top - 1, bottom - 1); } - + /** * Scroll up n lines (default = 1 line). */ private void processAnsiCommand_S() { text.scrollUp(getAnsiParameter(0)); } - + /** * Scroll down n lines (default = 1 line). */ private void processAnsiCommand_T() { text.scrollDown(getAnsiParameter(0)); } - + private void processDecPrivateCommand_h() { int param = getAnsiParameter(0); switch (param) { @@ -1080,7 +1079,7 @@ public class VT100Emulator implements ControlListener { break; } } - + /** * This method returns one of the numeric ANSI parameters received in the * most recent escape sequence. @@ -1128,6 +1127,7 @@ public class VT100Emulator implements ControlListener { ansiParameters[nextAnsiParameter].append(ch); } } + /** * This method processes a contiguous sequence of non-control characters. * This is a performance optimization, so that we don't have to insert or @@ -1137,15 +1137,14 @@ public class VT100Emulator implements ControlListener { * @throws IOException */ private void processNonControlCharacters(char character) throws IOException { - StringBuffer buffer=new StringBuffer(); + StringBuffer buffer = new StringBuffer(); buffer.append(character); // Identify a contiguous sequence of non-control characters, starting at // firstNonControlCharacterIndex in newText. - while(hasNextChar()) { - character=getNextChar(); - if(character == '\u0000' || character == '\b' || character == '\t' - || character == '\u0007' || character == '\n' - || character == '\r' || character == '\u001b') { + while (hasNextChar()) { + character = getNextChar(); + if (character == '\u0000' || character == '\b' || character == '\t' || character == '\u0007' + || character == '\n' || character == '\r' || character == '\u001b') { pushBackChar(character); break; } @@ -1173,7 +1172,6 @@ public class VT100Emulator implements ControlListener { text.appendString(buffer); } - /** * Process a BEL (Control-G) character. */ @@ -1251,8 +1249,8 @@ public class VT100Emulator implements ControlListener { // to make it display an integral number of lines of text. // TODO -// if(text.getColumns()!=80 && text.getLines()!=80) -// text.setDimensions(24, 80); + // if(text.getColumns()!=80 && text.getLines()!=80) + // text.setDimensions(24, 80); // If we are in a TELNET connection and we know the dimensions of the terminal, // we give the size information to the TELNET connection object so it can // communicate it to the TELNET server. If we are in a serial connection, @@ -1267,7 +1265,7 @@ public class VT100Emulator implements ControlListener { } private ITerminalConnector getConnector() { - if(terminal.getTerminalConnector()!=null) + if (terminal.getTerminalConnector() != null) return terminal.getTerminalConnector(); return null; } @@ -1291,7 +1289,7 @@ public class VT100Emulator implements ControlListener { * contain any text to move the cursor to any column in that line. */ private void moveCursor(int targetLine, int targetColumn) { - text.setCursor(targetLine,targetColumn); + text.setCursor(targetLine, targetColumn); } /** @@ -1330,42 +1328,43 @@ public class VT100Emulator implements ControlListener { private void moveCursorBackward(int columnsToMove) { moveCursor(relativeCursorLine(), getCursorColumn() - columnsToMove); } + /** * Resets the state of the terminal text (foreground color, background color, * font style and other internal state). It essentially makes it ready for new input. */ public void resetState() { - ansiState=ANSISTATE_INITIAL; + ansiState = ANSISTATE_INITIAL; text.setStyle(text.getDefaultStyle()); text.setScrollRegion(-1, -1); text.setInsertMode(false); } -// public OutputStream getOutputStream() { -// return fTerminalInputStream.getOutputStream(); -// } + // public OutputStream getOutputStream() { + // return fTerminalInputStream.getOutputStream(); + // } /** * Buffer for {@link #pushBackChar(char)}. */ - private int fNextChar=-1; + private int fNextChar = -1; private char getNextChar() throws IOException { - int c=-1; - if(fNextChar!=-1) { - c= fNextChar; - fNextChar=-1; + int c = -1; + if (fNextChar != -1) { + c = fNextChar; + fNextChar = -1; } else { c = fReader.read(); } // TODO: better end of file handling - if(c==-1) - c=0; - return (char)c; + if (c == -1) + c = 0; + return (char) c; } - private boolean hasNextChar() throws IOException { - if(fNextChar>=0) + private boolean hasNextChar() throws IOException { + if (fNextChar >= 0) return true; return fReader.ready(); } @@ -1378,20 +1377,25 @@ public class VT100Emulator implements ControlListener { */ void pushBackChar(char c) { //assert fNextChar!=-1: "Already a character waiting:"+fNextChar; //$NON-NLS-1$ - fNextChar=c; + fNextChar = c; } + private int getCursorColumn() { return text.getCursorColumn(); } + public boolean isCrAfterNewLine() { return fCrAfterNewLine; } + public void setCrAfterNewLine(boolean crAfterNewLine) { fCrAfterNewLine = crAfterNewLine; } + void setVT100LineWrapping(boolean enable) { text.setVT100LineWrapping(enable); } + boolean isVT100LineWrapping() { return text.isVT100LineWrapping(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java index 0332edacc01..22afb9ac7e8 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [206329] Changing terminal size right after connect does not scroll properly * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode @@ -26,22 +26,27 @@ import org.eclipse.tm.terminal.model.Style; public class VT100EmulatorBackend implements IVT100EmulatorBackend { private static class ScrollRegion { - static final ScrollRegion FULL_WINDOW = new ScrollRegion(0, Integer.MAX_VALUE-1); + static final ScrollRegion FULL_WINDOW = new ScrollRegion(0, Integer.MAX_VALUE - 1); private final int fTop; private final int fBottom; + ScrollRegion(int top, int bottom) { fTop = top; fBottom = bottom; } + boolean contains(int line) { return line >= fTop && line <= fBottom; } + int getTopLine() { return fTop; } + int getBottomLine() { return fBottom; } + int getHeight() { return fBottom - fTop + 1; } @@ -54,7 +59,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { * {@link #widthInColumns} - 1. We track the cursor column using this field * to avoid having to recompute it repeatly using StyledText method calls. *

- * + * * The StyledText widget that displays text has a vertical bar (called the * "caret") that appears _between_ character cells, but ANSI terminals have * the concept of a cursor that appears _in_ a character cell, so we need a @@ -63,13 +68,13 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { * class is that the cursor is logically in column N when the caret is * physically positioned immediately to the _left_ of column N. *

- * + * * When fCursorColumn is N, the next character output to the terminal appears * in column N. When a character is output to the rightmost column on a * given line (column widthInColumns - 1), the cursor moves to column 0 on * the next line after the character is drawn (this is the default line wrapping * mode). If VT100 line wrapping mode is enabled, the cursor does not move - * to the next line until the next character is printed (this is known as + * to the next line until the next character is printed (this is known as * the VT100 'eat_newline_glitch'). * If the cursor is in the bottommost line when line wrapping * occurs, the topmost visible line is scrolled off the top edge of the @@ -78,7 +83,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { */ private int fCursorColumn; private int fCursorLine; - /* true if last output occurred on rightmost column + /* true if last output occurred on rightmost column * and next output requires line wrap */ private boolean fWrapPending; private boolean fInsertMode; @@ -91,16 +96,16 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { private ScrollRegion fScrollRegion = ScrollRegion.FULL_WINDOW; public VT100EmulatorBackend(ITerminalTextData terminal) { - fTerminal=terminal; + fTerminal = terminal; } - + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#clearAll() */ public void clearAll() { synchronized (fTerminal) { // clear the history - int n=fTerminal.getHeight(); + int n = fTerminal.getHeight(); for (int line = 0; line < n; line++) { fTerminal.cleanLine(line); } @@ -109,34 +114,35 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { setCursor(0, 0); } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setDimensions(int, int) */ public void setDimensions(int lines, int cols) { synchronized (fTerminal) { - if(lines==fLines && cols==fColumns) + if (lines == fLines && cols == fColumns) return; // nothing to do // relative cursor line - int cl=getCursorLine(); - int cc=getCursorColumn(); - int height=fTerminal.getHeight(); + int cl = getCursorLine(); + int cc = getCursorColumn(); + int height = fTerminal.getHeight(); // absolute cursor line - int acl=cl+height-fLines; - int newLines=Math.max(lines,height); - if(lines=fCursorColumn+n; col--) { - char c=fTerminal.getChar(line, col-n); - Style style=fTerminal.getStyle(line, col-n); - fTerminal.setChar(line, col,c, style); + int line = toAbsoluteLine(fCursorLine); + int n = charactersToInsert; + for (int col = fColumns - 1; col >= fCursorColumn + n; col--) { + char c = fTerminal.getChar(line, col - n); + Style style = fTerminal.getStyle(line, col - n); + fTerminal.setChar(line, col, c, style); } - int last=Math.min(fCursorColumn+n, fColumns); - for (int col = fCursorColumn; col 0; - int line=toAbsoluteLine(fCursorLine); - int nLines=Math.min(fTerminal.getHeight()-line, fScrollRegion.getBottomLine()-fCursorLine+1); + assert n > 0; + int line = toAbsoluteLine(fCursorLine); + int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getBottomLine() - fCursorLine + 1); fTerminal.scroll(line, nLines, n); } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#deleteCharacters(int) */ public void deleteCharacters(int n) { synchronized (fTerminal) { - int line=toAbsoluteLine(fCursorLine); - for (int col = fCursorColumn+n; col < fColumns; col++) { - char c=fTerminal.getChar(line, col); - Style style=fTerminal.getStyle(line, col); - fTerminal.setChar(line, col-n,c, style); + int line = toAbsoluteLine(fCursorLine); + for (int col = fCursorColumn + n; col < fColumns; col++) { + char c = fTerminal.getChar(line, col); + Style style = fTerminal.getStyle(line, col); + fTerminal.setChar(line, col - n, c, style); } - int first=Math.max(fCursorColumn, fColumns-n); - for (int col = first; col 0; - int line=toAbsoluteLine(fCursorLine); - int nLines=Math.min(fTerminal.getHeight()-line, fScrollRegion.getBottomLine()-fCursorLine+1); + assert n > 0; + int line = toAbsoluteLine(fCursorLine); + int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getBottomLine() - fCursorLine + 1); fTerminal.scroll(line, nLines, -n); } } + private boolean isCusorInScrollingRegion() { return fScrollRegion.contains(fCursorLine); } @@ -304,39 +319,41 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { */ public Style getStyle() { synchronized (fTerminal) { - if(fStyle==null) + if (fStyle == null) return fDefaultStyle; return fStyle; } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setStyle(org.eclipse.tm.terminal.model.Style) */ public void setStyle(Style style) { synchronized (fTerminal) { - fStyle=style; + fStyle = style; } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#appendString(java.lang.String) */ public void appendString(String buffer) { synchronized (fTerminal) { - char[] chars=buffer.toCharArray(); + char[] chars = buffer.toCharArray(); if (fInsertMode) insertCharacters(chars.length); - int line=toAbsoluteLine(fCursorLine); - int i=0; + int line = toAbsoluteLine(fCursorLine); + int i = 0; while (i < chars.length) { - if(fWrapPending) { + if (fWrapPending) { line = doLineWrap(); } - int n=Math.min(fColumns-fCursorColumn,chars.length-i); + int n = Math.min(fColumns - fCursorColumn, chars.length - i); fTerminal.setChars(line, fCursorColumn, chars, i, n, fStyle); - int col=fCursorColumn+n; - i+=n; + int col = fCursorColumn + n; + i += n; // wrap needed? - if(col == fColumns) { + if (col == fColumns) { if (fVT100LineWrapping) { // deferred line wrapping (eat_newline_glitch) setCursorColumn(col - 1); @@ -353,10 +370,10 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { private int doLineWrap() { int line; - line=toAbsoluteLine(fCursorLine); + line = toAbsoluteLine(fCursorLine); fTerminal.setWrappedLine(line); doNewline(); - line=toAbsoluteLine(fCursorLine); + line = toAbsoluteLine(fCursorLine); setCursorColumn(0); return line; } @@ -367,15 +384,16 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { private void doNewline() { if (fCursorLine == fScrollRegion.getBottomLine()) scrollUp(1); - else if (fCursorLine+1>=fLines) { - int h=fTerminal.getHeight(); + else if (fCursorLine + 1 >= fLines) { + int h = fTerminal.getHeight(); fTerminal.addLine(); - if(h!=fTerminal.getHeight()) - setCursorLine(fCursorLine+1); + if (h != fTerminal.getHeight()) + setCursorLine(fCursorLine + 1); } else { - setCursorLine(fCursorLine+1); + setCursorLine(fCursorLine + 1); } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#processNewline() */ @@ -384,6 +402,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { doNewline(); } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#getCursorLine() */ @@ -392,6 +411,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { return fCursorLine; } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#getCursorColumn() */ @@ -400,6 +420,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { return fCursorColumn; } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setCursor(int, int) */ @@ -415,11 +436,11 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { */ public void setCursorColumn(int targetColumn) { synchronized (fTerminal) { - if(targetColumn<0) - targetColumn=0; - else if(targetColumn>=fColumns) - targetColumn=fColumns-1; - fCursorColumn=targetColumn; + if (targetColumn < 0) + targetColumn = 0; + else if (targetColumn >= fColumns) + targetColumn = fColumns - 1; + fCursorColumn = targetColumn; fWrapPending = false; // We make the assumption that nobody is changing the // terminal cursor except this class! @@ -433,11 +454,11 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { */ public void setCursorLine(int targetLine) { synchronized (fTerminal) { - if(targetLine<0) - targetLine=0; - else if(targetLine>=fLines) - targetLine=fLines-1; - fCursorLine=targetLine; + if (targetLine < 0) + targetLine = 0; + else if (targetLine >= fLines) + targetLine = fLines - 1; + fCursorLine = targetLine; // We make the assumption that nobody is changing the // terminal cursor except this class! // This assumption gives a huge performance improvement @@ -470,32 +491,32 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { public boolean isVT100LineWrapping() { return fVT100LineWrapping; } - + public void setInsertMode(boolean enable) { fInsertMode = enable; } public void setScrollRegion(int top, int bottom) { if (top < 0 || bottom < 0) - fScrollRegion = ScrollRegion.FULL_WINDOW; + fScrollRegion = ScrollRegion.FULL_WINDOW; else if (top < bottom) fScrollRegion = new ScrollRegion(top, bottom); } public void scrollUp(int n) { - assert n>0; + assert n > 0; synchronized (fTerminal) { int line = toAbsoluteLine(fScrollRegion.getTopLine()); - int nLines = Math.min(fTerminal.getHeight()-line, fScrollRegion.getHeight()); + int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getHeight()); fTerminal.scroll(line, nLines, -n); } } public void scrollDown(int n) { - assert n>0; + assert n > 0; synchronized (fTerminal) { int line = toAbsoluteLine(fScrollRegion.getTopLine()); - int nLines = Math.min(fTerminal.getHeight()-line, fScrollRegion.getHeight()); + int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getHeight()); fTerminal.scroll(line, nLines, n); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 9f07dc37036..cd325c25874 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -125,30 +125,29 @@ import org.eclipse.ui.keys.IBindingService; * * @author Chris Thew */ -public class VT100TerminalControl implements ITerminalControlForText, ITerminalControl, ITerminalViewControl -{ - protected final static String[] LINE_DELIMITERS = { "\n" }; //$NON-NLS-1$ +public class VT100TerminalControl implements ITerminalControlForText, ITerminalControl, ITerminalViewControl { + protected final static String[] LINE_DELIMITERS = { "\n" }; //$NON-NLS-1$ - /** - * This field holds a reference to a TerminalText object that performs all ANSI - * text processing on data received from the remote host and controls how text is - * displayed using the view's StyledText widget. - */ - private final VT100Emulator fTerminalText; - private Display fDisplay; - private TextCanvas fCtlText; - private Composite fWndParent; - private Clipboard fClipboard; - private KeyListener fKeyHandler; - private final ITerminalListener fTerminalListener; - private String fMsg = ""; //$NON-NLS-1$ - private TerminalMouseTrackListener fFocusListener; - private ITerminalConnector fConnector; - private final ITerminalConnector[] fConnectors; + /** + * This field holds a reference to a TerminalText object that performs all ANSI + * text processing on data received from the remote host and controls how text is + * displayed using the view's StyledText widget. + */ + private final VT100Emulator fTerminalText; + private Display fDisplay; + private TextCanvas fCtlText; + private Composite fWndParent; + private Clipboard fClipboard; + private KeyListener fKeyHandler; + private final ITerminalListener fTerminalListener; + private String fMsg = ""; //$NON-NLS-1$ + private TerminalMouseTrackListener fFocusListener; + private ITerminalConnector fConnector; + private final ITerminalConnector[] fConnectors; private final boolean fUseCommonPrefs; - private boolean connectOnEnterIfClosed = true; + private boolean connectOnEnterIfClosed = true; - PipedInputStream fInputStream; + PipedInputStream fInputStream; private static final String defaultEncoding = Charset.defaultCharset().name(); private String fEncoding = defaultEncoding; private InputStreamReader fInputStreamReader; @@ -166,10 +165,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC /** * Listens to changes in the preferences */ - private final IPropertyChangeListener fPreferenceListener=new IPropertyChangeListener() { + private final IPropertyChangeListener fPreferenceListener = new IPropertyChangeListener() { @Override - public void propertyChange(PropertyChangeEvent event) { - if(event.getProperty().equals(ITerminalConstants.PREF_BUFFERLINES) + public void propertyChange(PropertyChangeEvent event) { + if (event.getProperty().equals(ITerminalConstants.PREF_BUFFERLINES) || event.getProperty().equals(ITerminalConstants.PREF_INVERT_COLORS)) { updatePreferences(); } @@ -177,7 +176,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC }; private final IPropertyChangeListener fFontListener = new IPropertyChangeListener() { @Override - public void propertyChange(PropertyChangeEvent event) { + public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(ITerminalConstants.FONT_DEFINITION)) { onTerminalFontChanged(); } @@ -205,13 +204,14 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * Otherwise, clients need to maintain settings themselves. * @since 3.2 */ - public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors, boolean useCommonPrefs) { - fConnectors=connectors; + public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors, + boolean useCommonPrefs) { + fConnectors = connectors; fUseCommonPrefs = useCommonPrefs; - fTerminalListener=target; - fTerminalModel=TerminalTextDataFactory.makeTerminalTextData(); + fTerminalListener = target; + fTerminalModel = TerminalTextDataFactory.makeTerminalTextData(); fTerminalModel.setMaxHeight(1000); - fInputStream=new PipedInputStream(8*1024); + fInputStream = new PipedInputStream(8 * 1024); fTerminalText = new VT100Emulator(fTerminalModel, this, null); try { // Use Default Encoding as start, until setEncoding() is called @@ -229,7 +229,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public void setEncoding(String encoding) throws UnsupportedEncodingException { + public void setEncoding(String encoding) throws UnsupportedEncodingException { if (encoding == null) { // TODO better use a standard remote-to-local encoding? encoding = "ISO-8859-1"; //$NON-NLS-1$ @@ -243,12 +243,12 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public String getEncoding() { + public String getEncoding() { return fEncoding; } @Override - public ITerminalConnector[] getConnectors() { + public ITerminalConnector[] getConnectors() { return fConnectors; } @@ -256,7 +256,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#copy() */ @Override - public void copy() { + public void copy() { copy(DND.CLIPBOARD); } @@ -273,17 +273,17 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#paste() */ @Override - public void paste() { + public void paste() { paste(DND.CLIPBOARD); -// TODO paste in another thread.... to avoid blocking -// new Thread() { -// public void run() { -// for (int i = 0; i < strText.length(); i++) { -// sendChar(strText.charAt(i), false); -// } -// -// } -// }.start(); + // TODO paste in another thread.... to avoid blocking + // new Thread() { + // public void run() { + // for (int i = 0; i < strText.length(); i++) { + // sendChar(strText.charAt(i), false); + // } + // + // } + // }.start(); } private void paste(int clipboardType) { @@ -296,8 +296,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @param strText the text to paste */ @Override - public boolean pasteString(String strText) { - if(!isConnected()) + public boolean pasteString(String strText) { + if (!isConnected()) return false; if (strText == null) return false; @@ -316,10 +316,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#selectAll() */ @Override - public void selectAll() { + public void selectAll() { getCtlText().selectAll(); if (fTerminalListener instanceof ITerminalListener2) { - ((ITerminalListener2)fTerminalListener).setTerminalSelectionChanged(); + ((ITerminalListener2) fTerminalListener).setTerminalSelectionChanged(); } } @@ -327,7 +327,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#sendKey(char) */ @Override - public void sendKey(char character) { + public void sendKey(char character) { Event event; KeyEvent keyEvent; @@ -346,12 +346,12 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#clearTerminal() */ @Override - public void clearTerminal() { + public void clearTerminal() { // The TerminalText object does all text manipulation. getTerminalText().clearTerminal(); getCtlText().clearSelection(); if (fTerminalListener instanceof ITerminalListener2) { - ((ITerminalListener2)fTerminalListener).setTerminalSelectionChanged(); + ((ITerminalListener2) fTerminalListener).setTerminalSelectionChanged(); } } @@ -359,7 +359,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#getClipboard() */ @Override - public Clipboard getClipboard() { + public Clipboard getClipboard() { return fClipboard; } @@ -367,10 +367,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @return non null selection */ @Override - public String getSelection() { - String txt= fCtlText.getSelectionText(); - if(txt==null) - txt=""; //$NON-NLS-1$ + public String getSelection() { + String txt = fCtlText.getSelectionText(); + if (txt == null) + txt = ""; //$NON-NLS-1$ return txt; } @@ -378,7 +378,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#setFocus() */ @Override - public void setFocus() { + public void setFocus() { getCtlText().setFocus(); } @@ -386,7 +386,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#isEmpty() */ @Override - public boolean isEmpty() { + public boolean isEmpty() { return getCtlText().isEmpty(); } @@ -394,7 +394,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#isDisposed() */ @Override - public boolean isDisposed() { + public boolean isDisposed() { return getCtlText().isDisposed(); } @@ -402,17 +402,17 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#isConnected() */ @Override - public boolean isConnected() { - return fState==TerminalState.CONNECTED; + public boolean isConnected() { + return fState == TerminalState.CONNECTED; } /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#disposeTerminal() */ @Override - public void disposeTerminal() { + public void disposeTerminal() { Logger.log("entered."); //$NON-NLS-1$ - if(fUseCommonPrefs) { + if (fUseCommonPrefs) { TerminalPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPreferenceListener); JFaceResources.getFontRegistry().removeListener(fFontListener); } @@ -422,16 +422,14 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public void connectTerminal() { + public void connectTerminal() { Logger.log("entered."); //$NON-NLS-1$ - if(getTerminalConnector()==null) + if (getTerminalConnector() == null) return; fTerminalText.resetState(); fApplicationCursorKeys = false; - if(fConnector.getInitializationErrorMessage()!=null) { - showErrorMessage(NLS.bind( - TerminalMessages.CannotConnectTo, - fConnector.getName(), + if (fConnector.getInitializationErrorMessage() != null) { + showErrorMessage(NLS.bind(TerminalMessages.CannotConnectTo, fConnector.getName(), fConnector.getInitializationErrorMessage())); // we cannot connect because the connector was not initialized return; @@ -443,39 +441,42 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public ITerminalConnector getTerminalConnector() { + public ITerminalConnector getTerminalConnector() { return fConnector; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#disconnectTerminal() */ @Override - public void disconnectTerminal() { + public void disconnectTerminal() { Logger.log("entered."); //$NON-NLS-1$ //Disconnect the remote side first - if (getState()!=TerminalState.CLOSED) { - if(getTerminalConnector()!=null) { + if (getState() != TerminalState.CLOSED) { + if (getTerminalConnector() != null) { getTerminalConnector().disconnect(); } } - //Ensure that a new Job can be started; then clean up old Job. - Job job; - synchronized(this) { - job = fJob; - fJob = null; - } - if (job!=null) { - job.cancel(); - // Join job to avoid leaving job running after workbench shutdown (333613). - // Interrupt to be fast enough; cannot close fInputStream since it is re-used (bug 348700). - Thread t = job.getThread(); - if(t!=null) t.interrupt(); - try { - job.join(); - } catch (InterruptedException e) {} - } + //Ensure that a new Job can be started; then clean up old Job. + Job job; + synchronized (this) { + job = fJob; + fJob = null; + } + if (job != null) { + job.cancel(); + // Join job to avoid leaving job running after workbench shutdown (333613). + // Interrupt to be fast enough; cannot close fInputStream since it is re-used (bug 348700). + Thread t = job.getThread(); + if (t != null) + t.interrupt(); + try { + job.join(); + } catch (InterruptedException e) { + } + } fPollingTextCanvasModel.stopPolling(); } @@ -486,7 +487,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC do { if (!fDisplay.readAndDispatch()) fDisplay.sleep(); - } while (getState()==TerminalState.CONNECTING); + } while (getState() == TerminalState.CONNECTING); if (getCtlText().isDisposed()) { disconnectTerminal(); @@ -506,23 +507,23 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } private synchronized void startReaderJob() { - if(fJob==null) { - fJob=new Job("Terminal data reader") { //$NON-NLS-1$ + if (fJob == null) { + fJob = new Job("Terminal data reader") { //$NON-NLS-1$ @Override - protected IStatus run(IProgressMonitor monitor) { - IStatus status=Status.OK_STATUS; + protected IStatus run(IProgressMonitor monitor) { + IStatus status = Status.OK_STATUS; try { - while(true) { - while(fInputStream.available()==0 && !monitor.isCanceled()) { + while (true) { + while (fInputStream.available() == 0 && !monitor.isCanceled()) { try { fInputStream.waitForAvailable(500); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } - if(monitor.isCanceled()) { + if (monitor.isCanceled()) { //Do not disconnect terminal here because another reader job may already be running - status=Status.CANCEL_STATUS; + status = Status.CANCEL_STATUS; break; } try { @@ -530,7 +531,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC fTerminalText.processText(); } catch (Exception e) { disconnectTerminal(); - status=new Status(IStatus.ERROR,TerminalPlugin.PLUGIN_ID,e.getLocalizedMessage(),e); + status = new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, e.getLocalizedMessage(), + e); break; } } @@ -538,8 +540,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC // clean the job: start a new one when the connection gets restarted // Bug 208145: make sure we do not clean an other job that's already started (since it would become a Zombie) synchronized (VT100TerminalControl.this) { - if (fJob==this) { - fJob=null; + if (fJob == this) { + fJob = null; } } } @@ -576,8 +578,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } catch (SocketException socketException) { displayTextInTerminal(socketException.getMessage()); - String strMsg = TerminalMessages.SocketError - + "!\n" + socketException.getMessage(); //$NON-NLS-1$ + String strMsg = TerminalMessages.SocketError + "!\n" + socketException.getMessage(); //$NON-NLS-1$ showErrorMessage(strMsg); Logger.logException(socketException); @@ -593,7 +594,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public Shell getShell() { + public Shell getShell() { return getCtlText().getShell(); } @@ -601,7 +602,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC try { int byteToSend = chKey; OutputStream os = getOutputStream(); - if (os==null) { + if (os == null) { // Bug 207785: NPE when trying to send char while no longer connected Logger.log("NOT sending '" + byteToSend + "' because no longer connected"); //$NON-NLS-1$ //$NON-NLS-2$ } else { @@ -619,7 +620,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC byte[] bytesToSend = String.valueOf(chKey).getBytes(fEncoding); StringBuilder b = new StringBuilder("sending ESC"); //$NON-NLS-1$ for (int i = 0; i < bytesToSend.length; i++) { - if (i != 0) b.append(" +"); //$NON-NLS-1$ + if (i != 0) + b.append(" +"); //$NON-NLS-1$ b.append(" '" + bytesToSend[i] + "'"); //$NON-NLS-1$ //$NON-NLS-2$ } Logger.log(b.toString()); @@ -629,7 +631,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC byte[] bytesToSend = String.valueOf(chKey).getBytes(fEncoding); StringBuilder b = new StringBuilder("sending"); //$NON-NLS-1$ for (int i = 0; i < bytesToSend.length; i++) { - if (i != 0) b.append(" +"); //$NON-NLS-1$ + if (i != 0) + b.append(" +"); //$NON-NLS-1$ b.append(" '" + bytesToSend[i] + "'"); //$NON-NLS-1$ //$NON-NLS-2$ } Logger.log(b.toString()); @@ -642,8 +645,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC displayTextInTerminal(socketException.getMessage()); - String strMsg = TerminalMessages.SocketError - + "!\n" + socketException.getMessage(); //$NON-NLS-1$ + String strMsg = TerminalMessages.SocketError + "!\n" + socketException.getMessage(); //$NON-NLS-1$ showErrorMessage(strMsg); Logger.logException(socketException); @@ -667,7 +669,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#setupTerminal(org.eclipse.swt.widgets.Composite) */ @Override - public void setupTerminal(Composite parent) { + public void setupTerminal(Composite parent) { Assert.isNotNull(parent); boolean wasDisposed = true; TerminalState oldState = fState; @@ -703,8 +705,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.control.ITerminalViewControl#updatePreferences() */ private void updatePreferences() { - int bufferLineLimit = Platform.getPreferencesService().getInt(TerminalPlugin.PLUGIN_ID, ITerminalConstants.PREF_BUFFERLINES, 0, null); - boolean invert = Platform.getPreferencesService().getBoolean(TerminalPlugin.PLUGIN_ID, ITerminalConstants.PREF_INVERT_COLORS, false, null); + int bufferLineLimit = Platform.getPreferencesService().getInt(TerminalPlugin.PLUGIN_ID, + ITerminalConstants.PREF_BUFFERLINES, 0, null); + boolean invert = Platform.getPreferencesService().getBoolean(TerminalPlugin.PLUGIN_ID, + ITerminalConstants.PREF_INVERT_COLORS, false, null); setBufferLineLimit(bufferLineLimit); setInvertedColors(invert); } @@ -719,10 +723,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.control.ITerminalViewControl#setFont(java.lang.String) */ @Override - public void setFont(String fontName) { - Font font=JFaceResources.getFont(fontName); + public void setFont(String fontName) { + Font font = JFaceResources.getFont(fontName); getCtlText().setFont(font); - if(fCommandInputField!=null) { + if (fCommandInputField != null) { fCommandInputField.setFont(font); } // Tell the TerminalControl singleton that the font has changed. @@ -734,10 +738,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.control.ITerminalViewControl#setFont(org.eclipse.swt.graphics.Font) */ @Override - @Deprecated + @Deprecated public void setFont(Font font) { getCtlText().setFont(font); - if(fCommandInputField!=null) { + if (fCommandInputField != null) { fCommandInputField.setFont(font); } @@ -745,40 +749,47 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC fCtlText.onFontChange(); getTerminalText().fontChanged(); } + @Override - public Font getFont() { + public Font getFont() { return getCtlText().getFont(); } + @Override - public Control getControl() { + public Control getControl() { return fCtlText; } + @Override - public Control getRootControl() { + public Control getRootControl() { return fWndParent; } + protected void setupControls(Composite parent) { - fWndParent=new Composite(parent,SWT.NONE); - GridLayout layout=new GridLayout(); - layout.marginWidth=0; layout.marginHeight=0; layout.verticalSpacing=0; + fWndParent = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; fWndParent.setLayout(layout); - ITerminalTextDataSnapshot snapshot=fTerminalModel.makeSnapshot(); + ITerminalTextDataSnapshot snapshot = fTerminalModel.makeSnapshot(); // TODO how to get the initial size correctly! snapshot.updateSnapshot(false); - fPollingTextCanvasModel=new PollingTextCanvasModel(snapshot); - fCtlText=new TextCanvas(fWndParent,fPollingTextCanvasModel,SWT.NONE,new TextLineRenderer(fCtlText,fPollingTextCanvasModel)); + fPollingTextCanvasModel = new PollingTextCanvasModel(snapshot); + fCtlText = new TextCanvas(fWndParent, fPollingTextCanvasModel, SWT.NONE, + new TextLineRenderer(fCtlText, fPollingTextCanvasModel)); fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); fCtlText.addResizeHandler(new TextCanvas.ResizeListener() { @Override - public void sizeChanged(int lines, int columns) { + public void sizeChanged(int lines, int columns) { fTerminalText.setDimensions(lines, columns); } }); fCtlText.addMouseListener(new MouseAdapter() { @Override - public void mouseUp(MouseEvent e) { + public void mouseUp(MouseEvent e) { // update selection used by middle mouse button paste if (e.button == 1 && getSelection().length() > 0) { copy(DND.SELECTION_CLIPBOARD); @@ -818,9 +829,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#displayTextInTerminal(java.lang.String) */ @Override - public void displayTextInTerminal(String text) { - writeToTerminal("\r\n"+text+"\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + public void displayTextInTerminal(String text) { + writeToTerminal("\r\n" + text + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ } + private void writeToTerminal(String text) { try { getRemoteToTerminalOutputStream().write(text.getBytes(fEncoding)); @@ -834,20 +846,21 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public OutputStream getRemoteToTerminalOutputStream() { - if(Logger.isLogEnabled()) { + public OutputStream getRemoteToTerminalOutputStream() { + if (Logger.isLogEnabled()) { return new LoggingOutputStream(fInputStream.getOutputStream()); } else { return fInputStream.getOutputStream(); } } + protected boolean isLogCharEnabled() { return TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_CHAR); } @Override - public OutputStream getOutputStream() { - if(getTerminalConnector()!=null) + public OutputStream getOutputStream() { + if (getTerminalConnector() != null) return getTerminalConnector().getTerminalToRemoteStream(); return null; } @@ -856,7 +869,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#setMsg(java.lang.String) */ @Override - public void setMsg(String msg) { + public void setMsg(String msg) { fMsg = msg; } @@ -877,6 +890,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC public VT100Emulator getTerminalText() { return fTerminalText; } + protected class TerminalMouseTrackListener implements MouseTrackListener { private IContextActivation terminalContextActivation = null; private IContextActivation editContextActivation = null; @@ -898,7 +912,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC if (getState() == TerminalState.CONNECTED) captureKeyEvents(true); - IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class); + IContextService contextService = (IContextService) PlatformUI.getWorkbench() + .getAdapter(IContextService.class); editContextActivation = contextService.activateContext("org.eclipse.tm.terminal.EditContext"); //$NON-NLS-1$ } @@ -910,14 +925,17 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC // Restore the command context to its previous value. - IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class); + IContextService contextService = (IContextService) PlatformUI.getWorkbench() + .getAdapter(IContextService.class); contextService.deactivateContext(editContextActivation); } @SuppressWarnings("cast") protected void captureKeyEvents(boolean capture) { - IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); - IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class); + IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench() + .getAdapter(IBindingService.class); + IContextService contextService = (IContextService) PlatformUI.getWorkbench() + .getAdapter(IContextService.class); boolean enableKeyFilter = !capture; if (bindingService.isKeyFilterEnabled() != enableKeyFilter) @@ -941,9 +959,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC protected class TerminalKeyHandler extends KeyAdapter { @Override - public void keyPressed(KeyEvent event) { + public void keyPressed(KeyEvent event) { //TODO next 2 lines are probably obsolete now - if (getState()==TerminalState.CONNECTING) + if (getState() == TerminalState.CONNECTING) return; //TODO we should no longer handle copy & paste specially. @@ -981,7 +999,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC boolean altKeyPressed = (event.stateMask & SWT.ALT) != 0 && !ctrlKeyPressed; //if (!isConnected()) { - if (fState==TerminalState.CLOSED) { + if (fState == TerminalState.CLOSED) { // Pressing ENTER while not connected causes us to connect. if (character == '\r' && isConnectOnEnterIfClosed()) { connectTerminal(); @@ -1203,12 +1221,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC // // o The character is the DELETE character. - if (getTerminalConnector() == null - || getTerminalConnector().isLocalEcho() == false || altKeyPressed - || (character >= '\u0001' && character < '\t') - || (character > '\t' && character < '\r') - || (character > '\r' && character <= '\u001f') - || character == '\u007f') { + if (getTerminalConnector() == null || getTerminalConnector().isLocalEcho() == false || altKeyPressed + || (character >= '\u0001' && character < '\t') || (character > '\t' && character < '\r') + || (character > '\r' && character <= '\u001f') || character == '\u007f') { // No local echoing. return; } @@ -1232,13 +1247,15 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC */ @SuppressWarnings("cast") private void processKeyBinding(KeyEvent event, int accelerator) { - IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); + IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench() + .getAdapter(IBindingService.class); KeyStroke keyStroke = SWTKeySupport.convertAcceleratorToKeyStroke(accelerator); Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyStroke)); if (binding != null) { ParameterizedCommand cmd = binding.getParameterizedCommand(); if (cmd != null) { - IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class); + IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench() + .getAdapter(IHandlerService.class); Event cmdEvent = new Event(); cmdEvent.type = SWT.KeyDown; cmdEvent.display = event.display; @@ -1252,9 +1269,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC Field f1 = event.getClass().getField("keyLocation"); //$NON-NLS-1$ Field f2 = cmdEvent.getClass().getField("keyLocation"); //$NON-NLS-1$ f2.set(cmdEvent, f1.get(event)); - } catch(NoSuchFieldException nsfe) { + } catch (NoSuchFieldException nsfe) { /* ignore, this is Eclipse 3.5 or earlier */ - } catch(Throwable t) { + } catch (Throwable t) { t.printStackTrace(); } cmdEvent.stateMask = event.stateMask; @@ -1262,8 +1279,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC try { handlerService.executeCommand(cmd, cmdEvent); } catch (ExecutionException e) { - TerminalPlugin.getDefault().getLog().log( - new Status(IStatus.ERROR,TerminalPlugin.PLUGIN_ID,e.getLocalizedMessage(),e)); + TerminalPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, e.getLocalizedMessage(), e)); } catch (Exception e) { // ignore other exceptions from cmd execution } @@ -1274,26 +1291,24 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } @Override - public void setTerminalTitle(String title) { + public void setTerminalTitle(String title) { fTerminalListener.setTerminalTitle(title); } - @Override - public TerminalState getState() { + public TerminalState getState() { return fState; } - @Override - public void setState(TerminalState state) { - fState=state; + public void setState(TerminalState state) { + fState = state; fTerminalListener.setState(state); // enable the (blinking) cursor if the terminal is connected runAsyncInDisplayThread(new Runnable() { @Override - public void run() { - if(fCtlText!=null && !fCtlText.isDisposed()) { + public void run() { + if (fCtlText != null && !fCtlText.isDisposed()) { if (isConnected()) { fCtlText.setCursorEnabled(true); } else { @@ -1305,73 +1320,76 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } }); } + /** * @param runnable run in display thread */ private void runAsyncInDisplayThread(Runnable runnable) { - if(Display.findDisplay(Thread.currentThread())!=null) + if (Display.findDisplay(Thread.currentThread()) != null) runnable.run(); - else if(PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getDisplay() != null && !PlatformUI.getWorkbench().getDisplay().isDisposed()) + else if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getDisplay() != null + && !PlatformUI.getWorkbench().getDisplay().isDisposed()) PlatformUI.getWorkbench().getDisplay().asyncExec(runnable); // else should not happen and we ignore it... } @Override - public String getSettingsSummary() { - if(getTerminalConnector()!=null) + public String getSettingsSummary() { + if (getTerminalConnector() != null) return getTerminalConnector().getSettingsSummary(); return ""; //$NON-NLS-1$ } @Override - public void setConnector(ITerminalConnector connector) { - fConnector=connector; + public void setConnector(ITerminalConnector connector) { + fConnector = connector; } + @Override - public ICommandInputField getCommandInputField() { + public ICommandInputField getCommandInputField() { return fCommandInputField; } @Override - public void setCommandInputField(ICommandInputField inputField) { - if(fCommandInputField!=null) + public void setCommandInputField(ICommandInputField inputField) { + if (fCommandInputField != null) fCommandInputField.dispose(); - fCommandInputField=inputField; - if(fCommandInputField!=null) + fCommandInputField = inputField; + if (fCommandInputField != null) fCommandInputField.createControl(fWndParent, this); - if(fWndParent.isVisible()) + if (fWndParent.isVisible()) fWndParent.layout(true); } @Override - public int getBufferLineLimit() { + public int getBufferLineLimit() { return fTerminalModel.getMaxHeight(); } @Override - public void setBufferLineLimit(int bufferLineLimit) { - if(bufferLineLimit<=0) + public void setBufferLineLimit(int bufferLineLimit) { + if (bufferLineLimit <= 0) return; synchronized (fTerminalModel) { - if(fTerminalModel.getHeight()>bufferLineLimit) + if (fTerminalModel.getHeight() > bufferLineLimit) fTerminalModel.setDimensions(bufferLineLimit, fTerminalModel.getWidth()); fTerminalModel.setMaxHeight(bufferLineLimit); } } @Override - public boolean isScrollLock() { + public boolean isScrollLock() { return fCtlText.isScrollLock(); } @Override - public void setScrollLock(boolean on) { + public void setScrollLock(boolean on) { fCtlText.setScrollLock(on); } @Override - public void setInvertedColors(boolean invert) { + public void setInvertedColors(boolean invert) { fCtlText.setInvertedColors(invert); } @@ -1379,7 +1397,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#setConnectOnEnterIfClosed(boolean) */ @Override - public final void setConnectOnEnterIfClosed(boolean on) { + public final void setConnectOnEnterIfClosed(boolean on) { connectOnEnterIfClosed = on; } @@ -1387,33 +1405,33 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC * @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#isConnectOnEnterIfClosed() */ @Override - public final boolean isConnectOnEnterIfClosed() { + public final boolean isConnectOnEnterIfClosed() { return connectOnEnterIfClosed; } @Override - public void setVT100LineWrapping(boolean enable) { + public void setVT100LineWrapping(boolean enable) { getTerminalText().setVT100LineWrapping(enable); } @Override - public boolean isVT100LineWrapping() { + public boolean isVT100LineWrapping() { return getTerminalText().isVT100LineWrapping(); } @Override - public void enableApplicationCursorKeys(boolean enable) { + public void enableApplicationCursorKeys(boolean enable) { fApplicationCursorKeys = enable; } - + @Override public void addMouseListener(ITerminalMouseListener listener) { - getCtlText().addTerminalMouseListener(listener); + getCtlText().addTerminalMouseListener(listener); } - + @Override public void removeMouseListener(ITerminalMouseListener listener) { - getCtlText().removeTerminalMouseListener(listener); + getCtlText().removeTerminalMouseListener(listener); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/ISnapshotChanges.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/ISnapshotChanges.java index b7c71eb9efa..9f51f2150ac 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/ISnapshotChanges.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/ISnapshotChanges.java @@ -48,7 +48,7 @@ public interface ISnapshotChanges { /** * Mark all lines changed - * @param height if no window is set this is the number of + * @param height if no window is set this is the number of * lines that are marked as changed */ void setAllChanged(int height); @@ -66,19 +66,21 @@ public interface ISnapshotChanges { boolean hasLineChanged(int line); void markDimensionsChanged(); + boolean hasDimensionsChanged(); + void markCursorChanged(); /** * @return true if the terminal data has changed */ boolean hasTerminalChanged(); + /** * mark the terminal as changed */ void setTerminalChanged(); - void copyChangedLines(ITerminalTextData dest, ITerminalTextData source); /** @@ -86,7 +88,9 @@ public interface ISnapshotChanges { * @param size number of lines to follow */ void setInterestWindow(int startLine, int size); + int getInterestWindowStartLine(); + int getInterestWindowSize(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/SnapshotChanges.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/SnapshotChanges.java index 0c62f59f091..a4975cfac66 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/SnapshotChanges.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/SnapshotChanges.java @@ -14,7 +14,6 @@ package org.eclipse.tm.internal.terminal.model; import org.eclipse.tm.terminal.model.ITerminalTextData; - /** * Collects the changes of the {@link ITerminalTextData} * @@ -45,26 +44,28 @@ public class SnapshotChanges implements ISnapshotChanges { * not changed don't have to be copied) */ private boolean[] fChangedLines; - + private int fInterestWindowSize; private int fInterestWindowStartLine; private boolean fDimensionsChanged; private boolean fTerminalHasChanged; private boolean fCursorHasChanged; - + public SnapshotChanges(int nLines) { setChangedLinesLength(nLines); - fFirstChangedLine=Integer.MAX_VALUE; - fLastChangedLine=-1; + fFirstChangedLine = Integer.MAX_VALUE; + fLastChangedLine = -1; } + public SnapshotChanges(int windowStart, int windowSize) { - setChangedLinesLength(windowStart+windowSize); - fFirstChangedLine=Integer.MAX_VALUE; - fLastChangedLine=-1; - fInterestWindowStartLine=windowStart; - fInterestWindowSize=windowSize; + setChangedLinesLength(windowStart + windowSize); + fFirstChangedLine = Integer.MAX_VALUE; + fLastChangedLine = -1; + fInterestWindowStartLine = windowStart; + fInterestWindowSize = windowSize; } + /** * This is used in asserts to throw an {@link RuntimeException}. * This is useful for tests. @@ -73,6 +74,7 @@ public class SnapshotChanges implements ISnapshotChanges { private boolean throwRuntimeException() { throw new RuntimeException(); } + /** * @param line * @param size @@ -82,12 +84,13 @@ public class SnapshotChanges implements ISnapshotChanges { * It used to be package protected, and it is public only for Unit Tests. */ public boolean isInInterestWindow(int line, int size) { - if(fInterestWindowSize<=0) + if (fInterestWindowSize <= 0) return true; - if(line+size<=fInterestWindowStartLine || line>=fInterestWindowStartLine+fInterestWindowSize) + if (line + size <= fInterestWindowStartLine || line >= fInterestWindowStartLine + fInterestWindowSize) return false; return true; } + /** * @param line * @return true if the line is within the interest window @@ -96,12 +99,13 @@ public class SnapshotChanges implements ISnapshotChanges { * It used to be package protected, and it is public only for Unit Tests. */ public boolean isInInterestWindow(int line) { - if(fInterestWindowSize<=0) + if (fInterestWindowSize <= 0) return true; - if(line=fInterestWindowStartLine+fInterestWindowSize) + if (line < fInterestWindowStartLine || line >= fInterestWindowStartLine + fInterestWindowSize) return false; return true; } + /** * @param line * @return the line within the window @@ -110,17 +114,18 @@ public class SnapshotChanges implements ISnapshotChanges { * It used to be package protected, and it is public only for Unit Tests. */ public int fitLineToWindow(int line) { - if(fInterestWindowSize<=0) + if (fInterestWindowSize <= 0) return line; - if(linebefore {@link #fitLineToWindow(int)} has been called! * @param size - * @return the adjusted size. + * @return the adjusted size. * @nooverride This method is not intended to be re-implemented or extended by clients. * @noreference This method is not intended to be referenced by clients. * It used to be package protected, and it is public only for Unit Tests. @@ -129,99 +134,110 @@ public class SnapshotChanges implements ISnapshotChanges { * move the window correctly! */ public int fitSizeToWindow(int line, int size) { - if(fInterestWindowSize<=0) + if (fInterestWindowSize <= 0) return size; - if(linefInterestWindowStartLine+fInterestWindowSize) - size=fInterestWindowStartLine+fInterestWindowSize-line; + if (line + size > fInterestWindowStartLine + fInterestWindowSize) + size = fInterestWindowStartLine + fInterestWindowSize - line; return size; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#markLineChanged(int) */ public void markLineChanged(int line) { - if(!isInInterestWindow(line)) + if (!isInInterestWindow(line)) return; - line=fitLineToWindow(line); - if(linefLastChangedLine) - fLastChangedLine=line; - // in case the terminal got resized we expand + line = fitLineToWindow(line); + if (line < fFirstChangedLine) + fFirstChangedLine = line; + if (line > fLastChangedLine) + fLastChangedLine = line; + // in case the terminal got resized we expand // don't remember the changed line because // there is nothing to copy - if(line0 || fScrollWindowShift!=0 ||fDimensionsChanged || fCursorHasChanged) + if (fFirstChangedLine != Integer.MAX_VALUE || fLastChangedLine > 0 || fScrollWindowShift != 0 + || fDimensionsChanged || fCursorHasChanged) return true; return false; } + public void markDimensionsChanged() { - fDimensionsChanged=true; + fDimensionsChanged = true; } + public boolean hasDimensionsChanged() { return fDimensionsChanged; } + public boolean hasTerminalChanged() { return fTerminalHasChanged; } + public void setTerminalChanged() { - fTerminalHasChanged=true; + fTerminalHasChanged = true; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#scroll(int, int, int) */ public void scroll(int startLine, int size, int shift) { - size=fitSizeToWindow(startLine, size); - startLine=fitLineToWindow(startLine); + size = fitSizeToWindow(startLine, size); + startLine = fitLineToWindow(startLine); // let's track only negative shifts - if(fScrollDontTrack) { + if (fScrollDontTrack) { // we are in a state where we cannot track scrolling // so let's simply mark the scrolled lines as changed markLinesChanged(startLine, size); - } else if(shift>=0) { + } else if (shift >= 0) { // we cannot handle positive scroll // forget about clever caching of scroll events doNotTrackScrollingAnymore(); @@ -229,12 +245,12 @@ public class SnapshotChanges implements ISnapshotChanges { markLinesChanged(startLine, size); } else { // we have already scrolled - if(fScrollWindowShift<0) { + if (fScrollWindowShift < 0) { // we have already scrolled - if(fScrollWindowStartLine==startLine && fScrollWindowSize==size) { + if (fScrollWindowStartLine == startLine && fScrollWindowSize == size) { // we are scrolling the same region again? - fScrollWindowShift+=shift; - scrollChangesLinesWithNegativeShift(startLine,size,shift); + fScrollWindowShift += shift; + scrollChangesLinesWithNegativeShift(startLine, size, shift); } else { // mark all lines in the old scroll region as changed doNotTrackScrollingAnymore(); @@ -243,28 +259,30 @@ public class SnapshotChanges implements ISnapshotChanges { } } else { // first scroll in this change -- we just notify it - fScrollWindowStartLine=startLine; - fScrollWindowSize=size; - fScrollWindowShift=shift; - scrollChangesLinesWithNegativeShift(startLine,size,shift); + fScrollWindowStartLine = startLine; + fScrollWindowSize = size; + fScrollWindowShift = shift; + scrollChangesLinesWithNegativeShift(startLine, size, shift); } } } + /** * Some incompatible scrolling occurred. We cannot do the * scroll optimization anymore... */ private void doNotTrackScrollingAnymore() { - if(fScrollWindowSize>0) { + if (fScrollWindowSize > 0) { // convert the current scrolling into changes markLinesChanged(fScrollWindowStartLine, fScrollWindowSize); - fScrollWindowStartLine=0; - fScrollWindowSize=0; - fScrollWindowShift=0; + fScrollWindowStartLine = 0; + fScrollWindowSize = 0; + fScrollWindowShift = 0; } // don't be clever on scrolling anymore - fScrollDontTrack=true; + fScrollDontTrack = true; } + /** * Scrolls the changed lines data * @@ -273,78 +291,85 @@ public class SnapshotChanges implements ISnapshotChanges { * @param shift must be negative! */ private void scrollChangesLinesWithNegativeShift(int line, int n, int shift) { - assert shift <0 || throwRuntimeException(); + assert shift < 0 || throwRuntimeException(); // scroll the region // don't run out of bounds! - int m=Math.min(line+n+shift,getChangedLineLength()+shift); + int m = Math.min(line + n + shift, getChangedLineLength() + shift); for (int i = line; i < m; i++) { - setChangedLine(i, hasLineChanged(i-shift)); + setChangedLine(i, hasLineChanged(i - shift)); // move the first changed line up. // We don't have to move the maximum down, // because with a shift scroll, the max is moved // my the next loop in this method - if(i0) { - int shift=oldStartLine-startLine; - if(shift==0) { - if(size>oldSize) { + int oldStartLine = fInterestWindowStartLine; + int oldSize = fInterestWindowSize; + fInterestWindowStartLine = startLine; + fInterestWindowSize = size; + if (oldSize > 0) { + int shift = oldStartLine - startLine; + if (shift == 0) { + if (size > oldSize) { // add lines to the end - markLinesChanged(oldStartLine+oldSize, size-oldSize); + markLinesChanged(oldStartLine + oldSize, size - oldSize); } // else no lines within the window have changed - - } else if(Math.abs(shift)0) + if (line > 0) buff.append("\n"); //$NON-NLS-1$ for (int column = 0; column < width; column++) { buff.append(term.getChar(line, column)); @@ -83,71 +84,86 @@ public class TerminalTextData implements ITerminalTextData { public TerminalTextData() { this(new TerminalTextDataFastScroll()); -// this(new TerminalTextDataStore()); + // this(new TerminalTextDataStore()); } + public TerminalTextData(ITerminalTextData data) { - fData=data; + fData = data; } + public int getWidth() { return fData.getWidth(); } + public int getHeight() { // no need for an extra variable return fData.getHeight(); } + public void setDimensions(int height, int width) { - int h=getHeight(); - int w=getWidth(); - if(w==width && h==height) + int h = getHeight(); + int w = getWidth(); + if (w == width && h == height) return; fData.setDimensions(height, width); sendDimensionsChanged(h, w, height, width); } + private void sendDimensionsChanged(int oldHeight, int oldWidth, int newHeight, int newWidth) { // determine what has changed - if(oldWidth==newWidth) { - if(oldHeight list=new ArrayList(); + List list = new ArrayList(); list.addAll(Arrays.asList(fSnapshots)); list.remove(snapshot); - fSnapshots=list.toArray(new TerminalTextDataSnapshot[list.size()]); + fSnapshots = list.toArray(new TerminalTextDataSnapshot[list.size()]); } public ITerminalTextDataSnapshot makeSnapshot() { // poor mans approach to modify the array - TerminalTextDataSnapshot snapshot=new TerminalTextDataSnapshot(this); + TerminalTextDataSnapshot snapshot = new TerminalTextDataSnapshot(this); snapshot.markDimensionsChanged(); - List list=new ArrayList(); + List list = new ArrayList(); list.addAll(Arrays.asList(fSnapshots)); list.add(snapshot); - fSnapshots=list.toArray(new TerminalTextDataSnapshot[list.size()]); + fSnapshots = list.toArray(new TerminalTextDataSnapshot[list.size()]); return snapshot; } + public void addLine() { - int oldHeight=getHeight(); + int oldHeight = getHeight(); fData.addLine(); // was is an append or a scroll? - int newHeight=getHeight(); - if(newHeight>oldHeight) { + int newHeight = getHeight(); + if (newHeight > oldHeight) { //the line was appended sendLinesChangedToSnapshot(oldHeight, 1); - int width=getWidth(); + int width = getWidth(); sendDimensionsChanged(oldHeight, width, newHeight, width); } else { @@ -225,44 +245,54 @@ public class TerminalTextData implements ITerminalTextData { public void copy(ITerminalTextData source) { fData.copy(source); - fCursorLine=source.getCursorLine(); - fCursorColumn=source.getCursorColumn(); + fCursorLine = source.getCursorLine(); + fCursorColumn = source.getCursorColumn(); } public void copyLine(ITerminalTextData source, int sourceLine, int destLine) { fData.copyLine(source, sourceLine, destLine); } + public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) { fData.copyRange(source, sourceStartLine, destStartLine, length); } + public char[] getChars(int line) { return fData.getChars(line); } + public Style[] getStyles(int line) { return fData.getStyles(line); } + public int getMaxHeight() { return fData.getMaxHeight(); } + public void setMaxHeight(int height) { fData.setMaxHeight(height); } + public void cleanLine(int line) { fData.cleanLine(line); sendLineChangedToSnapshots(line); } + public int getCursorColumn() { return fCursorColumn; } + public int getCursorLine() { return fCursorLine; } + public void setCursorColumn(int column) { - fCursorColumn=column; + fCursorColumn = column; sendCursorChanged(); } + public void setCursorLine(int line) { - fCursorLine=line; + fCursorLine = line; sendCursorChanged(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScroll.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScroll.java index e175cd7182c..14dbbaef115 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScroll.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScroll.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break *******************************************************************************/ @@ -23,27 +23,31 @@ import org.eclipse.tm.terminal.model.Style; * */ public class TerminalTextDataFastScroll implements ITerminalTextData { - + final ITerminalTextData fData; private int fHeight; private int fMaxHeight; /** - * The offset into the array. + * The offset into the array. */ int fOffset; - public TerminalTextDataFastScroll(ITerminalTextData data,int maxHeight) { - fMaxHeight=maxHeight; - fData=data; + + public TerminalTextDataFastScroll(ITerminalTextData data, int maxHeight) { + fMaxHeight = maxHeight; + fData = data; fData.setDimensions(maxHeight, fData.getWidth()); - if(maxHeight>2) + if (maxHeight > 2) assert shiftOffset(-2) || throwRuntimeException(); } + public TerminalTextDataFastScroll(int maxHeight) { - this(new TerminalTextDataStore(),maxHeight); + this(new TerminalTextDataStore(), maxHeight); } + public TerminalTextDataFastScroll() { - this(new TerminalTextDataStore(),1); + this(new TerminalTextDataStore(), 1); } + /** * This is used in asserts to throw an {@link RuntimeException}. * This is useful for tests. @@ -52,23 +56,26 @@ public class TerminalTextDataFastScroll implements ITerminalTextData { private boolean throwRuntimeException() { throw new RuntimeException(); } + /** - * + * * @param line * @return the actual line number in {@link #fData} */ int getPositionOfLine(int line) { - return (line+fOffset)%fMaxHeight; + return (line + fOffset) % fMaxHeight; } + /** * Moves offset by delta. This does not move the data! * @param delta */ void moveOffset(int delta) { - assert Math.abs(delta)=0 && destStartLine+length<=fHeight) || throwRuntimeException(); + assert (destStartLine >= 0 && destStartLine + length <= fHeight) || throwRuntimeException(); for (int i = 0; i < length; i++) { - fData.copyLine(source, i+sourceStartLine, getPositionOfLine(i+destStartLine)); + fData.copyLine(source, i + sourceStartLine, getPositionOfLine(i + destStartLine)); } } public char getChar(int line, int column) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.getChar(getPositionOfLine(line), column); } public char[] getChars(int line) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.getChars(getPositionOfLine(line)); } @@ -123,7 +132,7 @@ public class TerminalTextDataFastScroll implements ITerminalTextData { } public LineSegment[] getLineSegments(int line, int startCol, int numberOfCols) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.getLineSegments(getPositionOfLine(line), startCol, numberOfCols); } @@ -132,12 +141,12 @@ public class TerminalTextDataFastScroll implements ITerminalTextData { } public Style getStyle(int line, int column) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.getStyle(getPositionOfLine(line), column); } public Style[] getStyles(int line) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.getStyles(getPositionOfLine(line)); } @@ -148,111 +157,119 @@ public class TerminalTextDataFastScroll implements ITerminalTextData { public ITerminalTextDataSnapshot makeSnapshot() { return fData.makeSnapshot(); } + private void cleanLines(int line, int len) { - for (int i = line; i < line+len; i++) { + for (int i = line; i < line + len; i++) { fData.cleanLine(getPositionOfLine(i)); } } + public void scroll(int startLine, int size, int shift) { - assert (startLine>=0 && startLine+size<=fHeight) || throwRuntimeException(); - if(shift>=fMaxHeight || -shift>=fMaxHeight) { - cleanLines(startLine, fMaxHeight-startLine); + assert (startLine >= 0 && startLine + size <= fHeight) || throwRuntimeException(); + if (shift >= fMaxHeight || -shift >= fMaxHeight) { + cleanLines(startLine, fMaxHeight - startLine); return; } - if(size==fHeight) { + if (size == fHeight) { // This is the case this class is optimized for! moveOffset(-shift); - // we only have to clean the lines that appear by the move - if(shift<0) { - cleanLines(Math.max(startLine, startLine+size+shift),Math.min(-shift, getHeight()-startLine)); + // we only have to clean the lines that appear by the move + if (shift < 0) { + cleanLines(Math.max(startLine, startLine + size + shift), Math.min(-shift, getHeight() - startLine)); } else { - cleanLines(startLine, Math.min(shift, getHeight()-startLine)); + cleanLines(startLine, Math.min(shift, getHeight() - startLine)); } } else { // we have to copy the lines. - if(shift<0) { + if (shift < 0) { // move the region up // shift is negative!! - for (int i = startLine; i < startLine+size+shift; i++) { - fData.copyLine(fData, getPositionOfLine(i-shift), getPositionOfLine(i)); + for (int i = startLine; i < startLine + size + shift; i++) { + fData.copyLine(fData, getPositionOfLine(i - shift), getPositionOfLine(i)); } // then clean the opened lines - cleanLines(Math.max(0, startLine+size+shift),Math.min(-shift, getHeight()-startLine)); + cleanLines(Math.max(0, startLine + size + shift), Math.min(-shift, getHeight() - startLine)); } else { - for (int i = startLine+size-1; i >=startLine && i-shift>=0; i--) { - fData.copyLine(fData, getPositionOfLine(i-shift), getPositionOfLine(i)); + for (int i = startLine + size - 1; i >= startLine && i - shift >= 0; i--) { + fData.copyLine(fData, getPositionOfLine(i - shift), getPositionOfLine(i)); } - cleanLines(startLine, Math.min(shift, getHeight()-startLine)); + cleanLines(startLine, Math.min(shift, getHeight() - startLine)); } } } public void setChar(int line, int column, char c, Style style) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); fData.setChar(getPositionOfLine(line), column, c, style); } public void setChars(int line, int column, char[] chars, int start, int len, Style style) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); fData.setChars(getPositionOfLine(line), column, chars, start, len, style); } public void setChars(int line, int column, char[] chars, Style style) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); fData.setChars(getPositionOfLine(line), column, chars, style); } public void setDimensions(int height, int width) { - assert height>=0 || throwRuntimeException(); - assert width>=0 || throwRuntimeException(); - if(height > fMaxHeight) + assert height >= 0 || throwRuntimeException(); + assert width >= 0 || throwRuntimeException(); + if (height > fMaxHeight) setMaxHeight(height); - fHeight=height; - if(width!=fData.getWidth()) + fHeight = height; + if (width != fData.getWidth()) fData.setDimensions(fMaxHeight, width); } public void setMaxHeight(int maxHeight) { - assert maxHeight>=fHeight || throwRuntimeException(); + assert maxHeight >= fHeight || throwRuntimeException(); // move everything to offset0 - int start=getPositionOfLine(0); - if(start!=0) { + int start = getPositionOfLine(0); + if (start != 0) { // invent a more efficient algorithm.... - ITerminalTextData buffer=new TerminalTextDataStore(); + ITerminalTextData buffer = new TerminalTextDataStore(); // create a buffer with the expected height buffer.setDimensions(maxHeight, getWidth()); - int n=Math.min(fMaxHeight-start,maxHeight); + int n = Math.min(fMaxHeight - start, maxHeight); // copy the first part buffer.copyRange(fData, start, 0, n); // copy the second part - if(n=0 && line= 0 && line < fHeight) || throwRuntimeException(); return fData.isWrappedLine(getPositionOfLine(line)); } + public void setWrappedLine(int line) { - assert (line>=0 && line= 0 && line < fHeight) || throwRuntimeException(); fData.setWrappedLine(getPositionOfLine(line)); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshot.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshot.java index 1f64cc7cafb..6dad9798f93 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshot.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshot.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break *******************************************************************************/ @@ -21,7 +21,7 @@ import org.eclipse.tm.terminal.model.LineSegment; import org.eclipse.tm.terminal.model.Style; /** - * The public methods of this class have to be called from one thread! + * The public methods of this class have to be called from one thread! * * Threading considerations: * This class is not threadsafe! @@ -47,7 +47,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { // snapshot does not need internal synchronisation final TerminalTextDataWindow fSnapshot; // this variable is synchronized on fTerminal! - private SnapshotOutOfDateListener[] fListener=new SnapshotOutOfDateListener[0]; + private SnapshotOutOfDateListener[] fListener = new SnapshotOutOfDateListener[0]; // this variable is synchronized on fTerminal! private boolean fListenersNeedNotify; private int fInterestWindowSize; @@ -60,9 +60,10 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { fCurrentChanges.setTerminalChanged(); fFutureChanges = new SnapshotChanges(fTerminal.getHeight()); fFutureChanges.markLinesChanged(0, fTerminal.getHeight()); - fListenersNeedNotify=true; - fInterestWindowSize=-1; + fListenersNeedNotify = true; + fInterestWindowSize = -1; } + /** * This is used in asserts to throw an {@link RuntimeException}. * This is useful for tests. @@ -71,7 +72,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { private boolean throwRuntimeException() { throw new RuntimeException(); } - + public void detach() { fTerminal.removeSnapshot(this); } @@ -82,6 +83,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { return fFutureChanges.hasChanged(); } } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#snapshot() */ @@ -89,12 +91,12 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { // make sure terminal does not change while we make the snapshot synchronized (fTerminal) { // let's make the future changes current - fCurrentChanges=fFutureChanges; - fFutureChanges=new SnapshotChanges(fTerminal.getHeight()); + fCurrentChanges = fFutureChanges; + fFutureChanges = new SnapshotChanges(fTerminal.getHeight()); fFutureChanges.setInterestWindow(fInterestWindowStartLine, fInterestWindowSize); // and update the snapshot - if(fSnapshot.getHeight()!=fTerminal.getHeight()||fSnapshot.getWidth()!=fTerminal.getWidth()) { - if(fInterestWindowSize==-1) + if (fSnapshot.getHeight() != fTerminal.getHeight() || fSnapshot.getWidth() != fTerminal.getWidth()) { + if (fInterestWindowSize == -1) fSnapshot.setWindow(0, fTerminal.getHeight()); // if the dimensions have changed, we need a full copy fSnapshot.copy(fTerminal); @@ -102,17 +104,17 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { fCurrentChanges.setAllChanged(fTerminal.getHeight()); } else { // first we do the scroll on the copy - int start=fCurrentChanges.getScrollWindowStartLine(); - int lines=Math.min(fCurrentChanges.getScrollWindowSize(), fSnapshot.getHeight()-start); + int start = fCurrentChanges.getScrollWindowStartLine(); + int lines = Math.min(fCurrentChanges.getScrollWindowSize(), fSnapshot.getHeight() - start); fSnapshot.scroll(start, lines, fCurrentChanges.getScrollWindowShift()); // and then create the snapshot of the changed lines fCurrentChanges.copyChangedLines(fSnapshot, fTerminal); } - fListenersNeedNotify=true; + fListenersNeedNotify = true; fSnapshot.setCursorLine(fTerminal.getCursorLine()); fSnapshot.setCursorColumn(fTerminal.getCursorColumn()); } - if(!detectScrolling) { + if (!detectScrolling) { // let's pretend there was no scrolling and // convert the scrolling into line changes fCurrentChanges.convertScrollingIntoChanges(); @@ -138,12 +140,14 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { public int getWidth() { return fSnapshot.getWidth(); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getFirstChangedLine() */ public int getFirstChangedLine() { return fCurrentChanges.getFirstChangedLine(); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getLastChangedLine() */ @@ -154,9 +158,11 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { public boolean hasLineChanged(int line) { return fCurrentChanges.hasLineChanged(line); } + public boolean hasDimensionsChanged() { return fCurrentChanges.hasDimensionsChanged(); } + public boolean hasTerminalChanged() { return fCurrentChanges.hasTerminalChanged(); } @@ -167,19 +173,21 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { public int getScrollWindowStartLine() { return fCurrentChanges.getScrollWindowStartLine(); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getScrollChangeN() */ public int getScrollWindowSize() { return fCurrentChanges.getScrollWindowSize(); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getScrollChangeShift() */ public int getScrollWindowShift() { return fCurrentChanges.getScrollWindowShift(); } - + /** * Announces a change in line line * @param line @@ -190,22 +198,24 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { fFutureChanges.setTerminalChanged(); notifyListers(); } + /** * Announces a change of n lines beginning with line line * @param line * @param n */ - void markLinesChanged(int line,int n) { - fFutureChanges.markLinesChanged(line,n); + void markLinesChanged(int line, int n) { + fFutureChanges.markLinesChanged(line, n); fFutureChanges.setTerminalChanged(); notifyListers(); } - + void markDimensionsChanged() { fFutureChanges.markDimensionsChanged(); fFutureChanges.setTerminalChanged(); notifyListers(); } + void markCursorChanged() { fFutureChanges.markCursorChanged(); fFutureChanges.setTerminalChanged(); @@ -218,86 +228,87 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot { * @param shift */ void scroll(int startLine, int size, int shift) { - fFutureChanges.scroll(startLine,size,shift); + fFutureChanges.scroll(startLine, size, shift); fFutureChanges.setTerminalChanged(); notifyListers(); } + /** * Notifies listeners about the change */ private void notifyListers() { // this code has to be called from a block synchronized on fTerminal synchronized (fTerminal) { - if(fListenersNeedNotify) { + if (fListenersNeedNotify) { for (int i = 0; i < fListener.length; i++) { fListener[i].snapshotOutOfDate(this); } - fListenersNeedNotify=false; + fListenersNeedNotify = false; } } } + public ITerminalTextDataSnapshot makeSnapshot() { return fSnapshot.makeSnapshot(); } synchronized public void addListener(SnapshotOutOfDateListener listener) { - List list=new ArrayList(); + List list = new ArrayList(); list.addAll(Arrays.asList(fListener)); list.add(listener); - fListener=list.toArray(new SnapshotOutOfDateListener[list.size()]); + fListener = list.toArray(new SnapshotOutOfDateListener[list.size()]); } synchronized public void removeListener(SnapshotOutOfDateListener listener) { - List list=new ArrayList(); + List list = new ArrayList(); list.addAll(Arrays.asList(fListener)); list.remove(listener); - fListener=list.toArray(new SnapshotOutOfDateListener[list.size()]); + fListener = list.toArray(new SnapshotOutOfDateListener[list.size()]); } + public String toString() { return fSnapshot.toString(); } - public int getInterestWindowSize() { return fInterestWindowSize; } - public int getInterestWindowStartLine() { return fInterestWindowStartLine; } public void setInterestWindow(int startLine, int size) { - assert startLine>=0 || throwRuntimeException(); - assert size>=0 || throwRuntimeException(); - fInterestWindowStartLine=startLine; - fInterestWindowSize=size; + assert startLine >= 0 || throwRuntimeException(); + assert size >= 0 || throwRuntimeException(); + fInterestWindowStartLine = startLine; + fInterestWindowSize = size; fSnapshot.setWindow(startLine, size); fFutureChanges.setInterestWindow(startLine, size); notifyListers(); } - public char[] getChars(int line) { return fSnapshot.getChars(line); } - public Style[] getStyles(int line) { return fSnapshot.getStyles(line); } + public int getCursorColumn() { return fSnapshot.getCursorColumn(); } + public int getCursorLine() { return fSnapshot.getCursorLine(); } + public ITerminalTextData getTerminalTextData() { return fTerminal; } + public boolean isWrappedLine(int line) { return fSnapshot.isWrappedLine(line); } } - - diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStore.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStore.java index 280a28d7cdf..83a9ca0dd35 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStore.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStore.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break *******************************************************************************/ @@ -36,10 +36,11 @@ public class TerminalTextDataStore implements ITerminalTextData { final private BitSet fWrappedLines = new BitSet(); public TerminalTextDataStore() { - fChars=new char[0][]; - fStyle=new Style[0][]; - fWidth=0; + fChars = new char[0][]; + fStyle = new Style[0][]; + fWidth = 0; } + /** * This is used in asserts to throw an {@link RuntimeException}. * This is useful for tests. @@ -48,7 +49,6 @@ public class TerminalTextDataStore implements ITerminalTextData { private boolean throwRuntimeException() { throw new RuntimeException(); } - /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getWidth() @@ -56,47 +56,50 @@ public class TerminalTextDataStore implements ITerminalTextData { public int getWidth() { return fWidth; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getHeight() */ public int getHeight() { return fHeight; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#setDimensions(int, int) */ public void setDimensions(int height, int width) { - assert height>=0 || throwRuntimeException(); - assert width>=0 || throwRuntimeException(); + assert height >= 0 || throwRuntimeException(); + assert width >= 0 || throwRuntimeException(); // just extend the region - if(height>fChars.length) { - int h=4*height/3; - if(fMaxHeight>0 && h>fMaxHeight) - h=fMaxHeight; - fStyle=(Style[][]) resizeArray(fStyle, height); - fChars=(char[][]) resizeArray(fChars, height); + if (height > fChars.length) { + int h = 4 * height / 3; + if (fMaxHeight > 0 && h > fMaxHeight) + h = fMaxHeight; + fStyle = (Style[][]) resizeArray(fStyle, height); + fChars = (char[][]) resizeArray(fChars, height); } // clean the new lines - if(height>fHeight) { + if (height > fHeight) { for (int i = fHeight; i < height; i++) { cleanLine(i); } } // set dimensions after successful resize! - fWidth=width; - fHeight=height; + fWidth = width; + fHeight = height; } + /** * Reallocates an array with a new size, and copies the contents of the old * array to the new array. - * + * * @param origArray the old array, to be reallocated. * @param newSize the new array size. * @return A new array with the same contents (chopped off if needed or filled with 0 or null). */ private Object resizeArray(Object origArray, int newSize) { int oldSize = Array.getLength(origArray); - if(oldSize==newSize) + if (oldSize == newSize) return origArray; Class elementType = origArray.getClass().getComponentType(); Object newArray = Array.newInstance(elementType, newSize); @@ -106,145 +109,150 @@ public class TerminalTextDataStore implements ITerminalTextData { return newArray; } - /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getLineSegments(int, int, int) */ public LineSegment[] getLineSegments(int line, int column, int len) { // get the styles and chars for this line - Style[] styles=fStyle[line]; - char[] chars=fChars[line]; - int col=column; - int n=column+len; - - // expand the line if needed.... - if(styles==null) - styles=new Style[n]; - else if(styles.length segments=new ArrayList(); + Style style = styles[column]; + List segments = new ArrayList(); for (int i = column; i < n; i++) { - if(styles[i]!=style) { - segments.add(new LineSegment(col,new String(chars,col,i-col),style)); - style=styles[i]; - col=i; + if (styles[i] != style) { + segments.add(new LineSegment(col, new String(chars, col, i - col), style)); + style = styles[i]; + col = i; } } - if(col < n) { - segments.add(new LineSegment(col,new String(chars,col,n-col),style)); + if (col < n) { + segments.add(new LineSegment(col, new String(chars, col, n - col), style)); } return segments.toArray(new LineSegment[segments.size()]); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getChar(int, int) */ public char getChar(int line, int column) { - assert column=fChars[line].length) + assert column < fWidth || throwRuntimeException(); + if (fChars[line] == null || column >= fChars[line].length) return 0; return fChars[line][column]; } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getStyle(int, int) */ public Style getStyle(int line, int column) { - assert column=fStyle[line].length) + assert column < fWidth || throwRuntimeException(); + if (fStyle[line] == null || column >= fStyle[line].length) return null; return fStyle[line][column]; } - + void ensureLineLength(int iLine, int length) { - if(length>fWidth) + if (length > fWidth) throw new RuntimeException(); - if(fChars[iLine]==null) { - fChars[iLine]=new char[length]; - } else if(fChars[iLine].length=startLine && i-shift>=0; i--) { - fChars[i]=fChars[i-shift]; - fStyle[i]=fStyle[i-shift]; - fWrappedLines.set(i, fWrappedLines.get(i-shift)); + for (int i = startLine + size - 1; i >= startLine && i - shift >= 0; i--) { + fChars[i] = fChars[i - shift]; + fStyle[i] = fStyle[i - shift]; + fWrappedLines.set(i, fWrappedLines.get(i - shift)); } - cleanLines(startLine, Math.min(shift, getHeight()-startLine)); + cleanLines(startLine, Math.min(shift, getHeight() - startLine)); } } + /** * Replaces the lines with new empty data * @param line * @param len */ private void cleanLines(int line, int len) { - for (int i = line; i < line+len; i++) { + for (int i = line; i < line + len; i++) { cleanLine(i); } } - + /* * @return a text representation of the object. * Lines are separated by '\n'. No style information is returned. */ public String toString() { - StringBuffer buff=new StringBuffer(); + StringBuffer buff = new StringBuffer(); for (int line = 0; line < getHeight(); line++) { - if(line>0) + if (line > 0) buff.append("\n"); //$NON-NLS-1$ for (int column = 0; column < fWidth; column++) { buff.append(getChar(line, column)); @@ -253,65 +261,65 @@ public class TerminalTextDataStore implements ITerminalTextData { return buff.toString(); } - public ITerminalTextDataSnapshot makeSnapshot() { throw new UnsupportedOperationException(); } public void addLine() { - if(fMaxHeight>0 && getHeight() 0 && getHeight() < fMaxHeight) { + setDimensions(getHeight() + 1, getWidth()); } else { - scroll(0,getHeight(),-1); + scroll(0, getHeight(), -1); } } public void copy(ITerminalTextData source) { - fWidth=source.getWidth(); - int n=source.getHeight(); - if(getHeight()!=n) { - fChars=new char[n][]; - fStyle=new Style[n][]; + fWidth = source.getWidth(); + int n = source.getHeight(); + if (getHeight() != n) { + fChars = new char[n][]; + fStyle = new Style[n][]; } for (int i = 0; i < n; i++) { copyLine(source, i, i); } - fHeight=n; - fCursorLine=source.getCursorLine(); - fCursorColumn=source.getCursorColumn(); + fHeight = n; + fCursorLine = source.getCursorLine(); + fCursorColumn = source.getCursorColumn(); } - public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine,int length) { + + public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) { for (int i = 0; i < length; i++) { - copyLine(source, i+sourceStartLine, i+destStartLine); + copyLine(source, i + sourceStartLine, i + destStartLine); } } public void copyLine(ITerminalTextData source, int sourceLine, int destLine) { - fChars[destLine]=source.getChars(sourceLine); - fStyle[destLine]=source.getStyles(sourceLine); + fChars[destLine] = source.getChars(sourceLine); + fStyle[destLine] = source.getStyles(sourceLine); fWrappedLines.set(destLine, source.isWrappedLine(sourceLine)); } public char[] getChars(int line) { - if(fChars[line]==null) + if (fChars[line] == null) return null; return fChars[line].clone(); } public Style[] getStyles(int line) { - if(fStyle[line]==null) + if (fStyle[line] == null) return null; return fStyle[line].clone(); } public void setLine(int line, char[] chars, Style[] styles) { - fChars[line]=chars.clone(); - fStyle[line]=styles.clone(); + fChars[line] = chars.clone(); + fStyle[line] = styles.clone(); fWrappedLines.clear(line); } public void setMaxHeight(int height) { - fMaxHeight=height; + fMaxHeight = height; } public int getMaxHeight() { @@ -319,25 +327,31 @@ public class TerminalTextDataStore implements ITerminalTextData { } public void cleanLine(int line) { - fChars[line]=null; - fStyle[line]=null; + fChars[line] = null; + fStyle[line] = null; fWrappedLines.clear(line); } + public int getCursorColumn() { return fCursorColumn; } + public int getCursorLine() { return fCursorLine; } + public void setCursorColumn(int column) { - fCursorColumn=column; + fCursorColumn = column; } + public void setCursorLine(int line) { - fCursorLine=line; + fCursorLine = line; } + public boolean isWrappedLine(int line) { return fWrappedLines.get(line); } + public void setWrappedLine(int line) { fWrappedLines.set(line); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindow.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindow.java index 0e7eba4b4f2..57321df54f7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindow.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindow.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break *******************************************************************************/ @@ -17,8 +17,8 @@ import org.eclipse.tm.terminal.model.LineSegment; import org.eclipse.tm.terminal.model.Style; /** - * This class stores the data only within a window {@link #setWindow(int, int)} and - * {@link #getWindowStartLine()} and {@link #getWindowSize()}. Everything outside + * This class stores the data only within a window {@link #setWindow(int, int)} and + * {@link #getWindowStartLine()} and {@link #getWindowSize()}. Everything outside * the is char=='\000' and style=null. * */ @@ -28,12 +28,15 @@ public class TerminalTextDataWindow implements ITerminalTextData { int fWindowSize; int fHeight; int fMaxHeight; + public TerminalTextDataWindow(ITerminalTextData data) { - fData=data; + fData = data; } + public TerminalTextDataWindow() { this(new TerminalTextDataStore()); } + /** * This is used in asserts to throw an {@link RuntimeException}. * This is useful for tests. @@ -42,23 +45,25 @@ public class TerminalTextDataWindow implements ITerminalTextData { private boolean throwRuntimeException() { throw new RuntimeException(); } + /** * @param line * @return true if the line is within the window */ boolean isInWindow(int line) { - return line>=fWindowStartLine && line= fWindowStartLine && line < fWindowStartLine + fWindowSize; } + public char getChar(int line, int column) { - if(!isInWindow(line)) + if (!isInWindow(line)) return 0; - return fData.getChar(line-fWindowStartLine, column); + return fData.getChar(line - fWindowStartLine, column); } public char[] getChars(int line) { - if(!isInWindow(line)) + if (!isInWindow(line)) return null; - return fData.getChars(line-fWindowStartLine); + return fData.getChars(line - fWindowStartLine); } public int getHeight() { @@ -66,9 +71,9 @@ public class TerminalTextDataWindow implements ITerminalTextData { } public LineSegment[] getLineSegments(int line, int startCol, int numberOfCols) { - if(!isInWindow(line)) - return new LineSegment[]{new LineSegment(startCol,new String(new char[numberOfCols]),null)}; - return fData.getLineSegments(line-fWindowStartLine, startCol, numberOfCols); + if (!isInWindow(line)) + return new LineSegment[] { new LineSegment(startCol, new String(new char[numberOfCols]), null) }; + return fData.getLineSegments(line - fWindowStartLine, startCol, numberOfCols); } public int getMaxHeight() { @@ -76,15 +81,15 @@ public class TerminalTextDataWindow implements ITerminalTextData { } public Style getStyle(int line, int column) { - if(!isInWindow(line)) + if (!isInWindow(line)) return null; - return fData.getStyle(line-fWindowStartLine, column); + return fData.getStyle(line - fWindowStartLine, column); } public Style[] getStyles(int line) { - if(!isInWindow(line)) + if (!isInWindow(line)) return null; - return fData.getStyles(line-fWindowStartLine); + return fData.getStyles(line - fWindowStartLine); } public int getWidth() { @@ -94,114 +99,135 @@ public class TerminalTextDataWindow implements ITerminalTextData { public ITerminalTextDataSnapshot makeSnapshot() { throw new UnsupportedOperationException(); } + public void addLine() { - if(fMaxHeight>0 && getHeight() 0 && getHeight() < fMaxHeight) { + setDimensions(getHeight() + 1, getWidth()); } else { - scroll(0,getHeight(),-1); + scroll(0, getHeight(), -1); } } + public void copy(ITerminalTextData source) { // we inherit the dimensions of the source setDimensions(source.getHeight(), source.getWidth()); - int n=Math.min(fWindowSize, source.getHeight()-fWindowStartLine); - if(n>0) + int n = Math.min(fWindowSize, source.getHeight() - fWindowStartLine); + if (n > 0) fData.copyRange(source, fWindowStartLine, 0, n); } + public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) { - int n=length; - int dStart=destStartLine-fWindowStartLine; - int sStart=sourceStartLine; + int n = length; + int dStart = destStartLine - fWindowStartLine; + int sStart = sourceStartLine; // if start outside our range, cut the length to copy - if(dStart<0) { - n+=dStart; - sStart-=dStart; - dStart=0; + if (dStart < 0) { + n += dStart; + sStart -= dStart; + dStart = 0; } // do not exceed the window size - n=Math.min(n,fWindowSize); - if(n>0) + n = Math.min(n, fWindowSize); + if (n > 0) fData.copyRange(source, sStart, dStart, n); - + } + public void copyLine(ITerminalTextData source, int sourceLine, int destLine) { - if(isInWindow(destLine)) - fData.copyLine(source, sourceLine, destLine-fWindowStartLine); + if (isInWindow(destLine)) + fData.copyLine(source, sourceLine, destLine - fWindowStartLine); } + public void scroll(int startLine, int size, int shift) { - assert (startLine>=0 && startLine+size<=fHeight) || throwRuntimeException(); - int n=size; - int start=startLine-fWindowStartLine; + assert (startLine >= 0 && startLine + size <= fHeight) || throwRuntimeException(); + int n = size; + int start = startLine - fWindowStartLine; // if start outside our range, cut the length to copy - if(start<0) { - n+=start; - start=0; + if (start < 0) { + n += start; + start = 0; } - n=Math.min(n,fWindowSize-start); + n = Math.min(n, fWindowSize - start); // do not exceed the window size - if(n>0) + if (n > 0) fData.scroll(start, n, shift); } + public void setChar(int line, int column, char c, Style style) { - if(!isInWindow(line)) + if (!isInWindow(line)) return; - fData.setChar(line-fWindowStartLine, column, c, style); + fData.setChar(line - fWindowStartLine, column, c, style); } + public void setChars(int line, int column, char[] chars, int start, int len, Style style) { - if(!isInWindow(line)) + if (!isInWindow(line)) return; - fData.setChars(line-fWindowStartLine, column, chars, start, len, style); + fData.setChars(line - fWindowStartLine, column, chars, start, len, style); } + public void setChars(int line, int column, char[] chars, Style style) { - if(!isInWindow(line)) + if (!isInWindow(line)) return; - fData.setChars(line-fWindowStartLine, column, chars, style); + fData.setChars(line - fWindowStartLine, column, chars, style); } + public void setDimensions(int height, int width) { - assert height>=0 || throwRuntimeException(); + assert height >= 0 || throwRuntimeException(); fData.setDimensions(fWindowSize, width); - fHeight=height; + fHeight = height; } + public void setMaxHeight(int height) { - fMaxHeight=height; + fMaxHeight = height; } + public void setWindow(int startLine, int size) { - fWindowStartLine=startLine; - fWindowSize=size; + fWindowStartLine = startLine; + fWindowSize = size; fData.setDimensions(fWindowSize, getWidth()); } + public int getWindowStartLine() { return fWindowStartLine; } + public int getWindowSize() { return fWindowSize; } + public void setHeight(int height) { fHeight = height; } + public void cleanLine(int line) { - if(isInWindow(line)) - fData.cleanLine(line-fWindowStartLine); + if (isInWindow(line)) + fData.cleanLine(line - fWindowStartLine); } + public int getCursorColumn() { return fData.getCursorColumn(); } + public int getCursorLine() { return fData.getCursorLine(); } + public void setCursorColumn(int column) { fData.setCursorColumn(column); } + public void setCursorLine(int line) { fData.setCursorLine(line); } + public boolean isWrappedLine(int line) { - if(isInWindow(line)) + if (isInWindow(line)) return fData.isWrappedLine(line - fWindowStartLine); return false; } + public void setWrappedLine(int line) { - if(isInWindow(line)) + if (isInWindow(line)) fData.setWrappedLine(line - fWindowStartLine); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/ITerminalConstants.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/ITerminalConstants.java index b9980eec90b..0c44566fb77 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/ITerminalConstants.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/ITerminalConstants.java @@ -16,19 +16,19 @@ package org.eclipse.tm.internal.terminal.preferences; /** * Constants for Terminal Preferences. - * + * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface ITerminalConstants { - public static final String PREF_HAS_MIGRATED = "TerminalPref.migrated"; //$NON-NLS-1$ + public static final String PREF_HAS_MIGRATED = "TerminalPref.migrated"; //$NON-NLS-1$ - public static final String PREF_BUFFERLINES = "TerminalPrefBufferLines"; //$NON-NLS-1$ - public static final String PREF_INVERT_COLORS = "TerminalPrefInvertColors"; //$NON-NLS-1$ - public static final int DEFAULT_BUFFERLINES = 1000; - public static final boolean DEFAULT_INVERT_COLORS = false; + public static final String PREF_BUFFERLINES = "TerminalPrefBufferLines"; //$NON-NLS-1$ + public static final String PREF_INVERT_COLORS = "TerminalPrefInvertColors"; //$NON-NLS-1$ + public static final int DEFAULT_BUFFERLINES = 1000; + public static final boolean DEFAULT_INVERT_COLORS = false; - public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$ + public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$ } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferenceInitializer.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferenceInitializer.java index 431dd902d3b..8a028812fc3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferenceInitializer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferenceInitializer.java @@ -22,7 +22,7 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin; /** * Terminal Preference Initializer. - * + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. * @noreference This class is not intended to be referenced by clients. diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferencePage.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferencePage.java index 7bb452c5855..d9b51ff80ad 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferencePage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferencePage.java @@ -30,30 +30,33 @@ import org.eclipse.ui.IWorkbenchPreferencePage; /** * Terminal Preference Page. - * + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. * @noreference This class is not intended to be referenced by clients. */ -public class TerminalPreferencePage extends FieldEditorPreferencePage implements - IWorkbenchPreferencePage { - protected BooleanFieldEditor fInvertColors; +public class TerminalPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + protected BooleanFieldEditor fInvertColors; protected IntegerFieldEditor fEditorBufferSize; public TerminalPreferencePage() { super(GRID); } + protected void createFieldEditors() { setupPage(); } + public void init(IWorkbench workbench) { // do nothing } + protected void setupPage() { setupData(); setupEditors(); } + protected void setupData() { TerminalPlugin plugin; IPreferenceStore preferenceStore; @@ -62,12 +65,12 @@ public class TerminalPreferencePage extends FieldEditorPreferencePage implements preferenceStore = plugin.getPreferenceStore(); setPreferenceStore(preferenceStore); } + protected void setupEditors() { - fInvertColors = new BooleanFieldEditor( - ITerminalConstants.PREF_INVERT_COLORS, TerminalMessages.INVERT_COLORS, + fInvertColors = new BooleanFieldEditor(ITerminalConstants.PREF_INVERT_COLORS, TerminalMessages.INVERT_COLORS, + getFieldEditorParent()); + fEditorBufferSize = new IntegerFieldEditor(ITerminalConstants.PREF_BUFFERLINES, TerminalMessages.BUFFERLINES, getFieldEditorParent()); - fEditorBufferSize = new IntegerFieldEditor(ITerminalConstants.PREF_BUFFERLINES, - TerminalMessages.BUFFERLINES, getFieldEditorParent()); fEditorBufferSize.setValidRange(0, Integer.MAX_VALUE); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/AbstractSettingsPage.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/AbstractSettingsPage.java index 673716e8267..89b0d8ad095 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/AbstractSettingsPage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/AbstractSettingsPage.java @@ -40,16 +40,16 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#addListener(org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage.Listener) */ public void addListener(Listener listener) { - Assert.isNotNull(listener); - listeners.add(listener); + Assert.isNotNull(listener); + listeners.add(listener); } /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#removeListener(org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage.Listener) */ public void removeListener(Listener listener) { - Assert.isNotNull(listener); - listeners.remove(listener); + Assert.isNotNull(listener); + listeners.remove(listener); } /** @@ -61,8 +61,9 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro Object[] list = listeners.getListeners(); for (int i = 0; i < list.length; i++) { Object l = list[i]; - if (!(l instanceof Listener)) continue; - ((Listener)l).onSettingsPageChanged(control); + if (!(l instanceof Listener)) + continue; + ((Listener) l).onSettingsPageChanged(control); } } @@ -120,7 +121,8 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro */ protected final ControlDecoration createControlDecoration(Control control) { Assert.isNotNull(control); - if (!hasDecoration) return null; + if (!hasDecoration) + return null; ControlDecoration controlDecoration = new ControlDecoration(control, getControlDecorationPosition()); controlDecoration.setShowOnlyOnFocus(false); control.setData("controlDecoration", controlDecoration); //$NON-NLS-1$ @@ -149,7 +151,7 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro protected final void updateControlDecoration(Control control, String message, int messageType) { Assert.isNotNull(control); - ControlDecoration controlDecoration = (ControlDecoration)control.getData("controlDecoration"); //$NON-NLS-1$ + ControlDecoration controlDecoration = (ControlDecoration) control.getData("controlDecoration"); //$NON-NLS-1$ if (controlDecoration != null) { // The description is the same as the message controlDecoration.setDescriptionText(message); @@ -173,8 +175,7 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro if (message == null || messageType == IMessageProvider.NONE) { controlDecoration.hide(); - } - else { + } else { controlDecoration.show(); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ISettingsStore.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ISettingsStore.java index 7346453b4cc..71cfc58164b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ISettingsStore.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ISettingsStore.java @@ -1,19 +1,19 @@ /******************************************************************************* * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified *******************************************************************************/ package org.eclipse.tm.internal.terminal.provisional.api; /** - * A simple interface to a store to persist the state of a connection. - * + * A simple interface to a store to persist the state of a connection. + * * @author Michael Scharf *

* EXPERIMENTAL. This class or interface has been added as diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalConnector.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalConnector.java index 244fb9ab7fb..c4869ad22f1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalConnector.java @@ -104,20 +104,20 @@ public interface ITerminalConnector extends IAdaptable { */ boolean isLocalEcho(); - /** - * Notify the remote site that the size of the terminal has changed. - * @param newWidth - * @param newHeight - */ - void setTerminalSize(int newWidth, int newHeight); + /** + * Notify the remote site that the size of the terminal has changed. + * @param newWidth + * @param newHeight + */ + void setTerminalSize(int newWidth, int newHeight); - /** - * @return the terminal to remote stream (bytes written to this stream will - * be sent to the remote site). For the stream in the other direction (remote to - * terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()} + /** + * @return the terminal to remote stream (bytes written to this stream will + * be sent to the remote site). For the stream in the other direction (remote to + * terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()} * @since org.eclipse.tm.terminal 2.0 - */ - OutputStream getTerminalToRemoteStream(); + */ + OutputStream getTerminalToRemoteStream(); /** * Load the state of this connection. Is typically called before @@ -134,7 +134,7 @@ public interface ITerminalConnector extends IAdaptable { * @param store */ void save(ISettingsStore store); - + /** * Set or reset the settings store to the default values. */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java index ac133ffdb5c..226f03cdc36 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java @@ -131,30 +131,30 @@ public interface ITerminalControl { * the terminal connection if the user hits ENTER in a closed terminal. *

* Reconnect on ENTER if terminal is closed is enabled by default. - * + * * @param on True to enable the reconnect, false to disable it. */ void setConnectOnEnterIfClosed(boolean on); - + /** * Returns if or if not the terminal view control should try to reconnect * the terminal connection if the user hits ENTER in a closed terminal. - * + * * @return True the reconnect is enabled, false if disabled. */ boolean isConnectOnEnterIfClosed(); - + /** * Enables VT100 line wrapping mode (default is off). * This corresponds to the VT100 'eat_newline_glitch' terminal capability. * If enabled, writing to the rightmost column does not cause * an immediate wrap to the next line. Instead the line wrap occurs on the * next output character. - * + * * @param enable whether to enable or disable VT100 line wrapping mode */ void setVT100LineWrapping(boolean enable); - + /** * @return whether VT100 line wrapping mode is enabled */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java index 25f3c6649ac..1845104c0bb 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java @@ -44,18 +44,18 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin; *

*/ public final class Logger { - public static final String TRACE_DEBUG_LOG = "org.eclipse.tm.terminal.control/debug/log"; //$NON-NLS-1$ - public static final String TRACE_DEBUG_LOG_CHAR = "org.eclipse.tm.terminal.control/debug/log/char"; //$NON-NLS-1$ - public static final String TRACE_DEBUG_LOG_VT100BACKEND = "org.eclipse.tm.terminal.control/debug/log/VT100Backend"; //$NON-NLS-1$ + public static final String TRACE_DEBUG_LOG = "org.eclipse.tm.terminal.control/debug/log"; //$NON-NLS-1$ + public static final String TRACE_DEBUG_LOG_CHAR = "org.eclipse.tm.terminal.control/debug/log/char"; //$NON-NLS-1$ + public static final String TRACE_DEBUG_LOG_VT100BACKEND = "org.eclipse.tm.terminal.control/debug/log/VT100Backend"; //$NON-NLS-1$ - private static PrintStream logStream; + private static PrintStream logStream; static { // Any of the three known debugging options turns on the creation of the log file boolean createLogFile = TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG) - || TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_CHAR) - || TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_VT100BACKEND); - + || TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_CHAR) + || TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_VT100BACKEND); + // Log only if tracing is enabled if (createLogFile && TerminalPlugin.getDefault() != null) { IPath logFile = Platform.getStateLocation(TerminalPlugin.getDefault().getBundle()); @@ -80,48 +80,64 @@ public final class Logger { */ public static final String encode(String message) { boolean encoded = false; - StringBuffer buf = new StringBuffer(message.length()+32); - for (int i=0; i=' ' && c<'\u007f') { - buf.append(c); - } else if (c <= '\u00ff') { - buf.append('\\'); buf.append('x'); - buf.append(Integer.toHexString(c)); - encoded=true; - } else { - buf.append('\\'); buf.append('u'); - if (c<='\u0fff') { - buf.append('0'); - } - buf.append(Integer.toHexString(c)); - encoded=true; + StringBuffer buf = new StringBuffer(message.length() + 32); + for (int i = 0; i < message.length(); i++) { + char c = message.charAt(i); + switch (c) { + case '\\': + case '\'': + buf.append('\\'); + buf.append(c); + encoded = true; + break; + case '\r': + buf.append('\\'); + buf.append('r'); + encoded = true; + break; + case '\n': + buf.append('\\'); + buf.append('n'); + encoded = true; + break; + case '\t': + buf.append('\\'); + buf.append('t'); + encoded = true; + break; + case '\f': + buf.append('\\'); + buf.append('f'); + encoded = true; + break; + case '\b': + buf.append('\\'); + buf.append('b'); + encoded = true; + break; + default: + if (c <= '\u000f') { + buf.append('\\'); + buf.append('x'); + buf.append('0'); + buf.append(Integer.toHexString(c)); + encoded = true; + } else if (c >= ' ' && c < '\u007f') { + buf.append(c); + } else if (c <= '\u00ff') { + buf.append('\\'); + buf.append('x'); + buf.append(Integer.toHexString(c)); + encoded = true; + } else { + buf.append('\\'); + buf.append('u'); + if (c <= '\u0fff') { + buf.append('0'); } + buf.append(Integer.toHexString(c)); + encoded = true; + } } } if (encoded) { @@ -135,14 +151,14 @@ public final class Logger { * @return true if logging is enabled. */ public static final boolean isLogEnabled() { - return (logStream!=null); + return (logStream != null); } /** * Logs the specified message. Do not append a newline to parameter * message. This method does that for you. * - * @param message A String containing the message to log. + * @param message A String containing the message to log. */ public static final void log(String message) { if (logStream != null) { @@ -156,7 +172,7 @@ public final class Logger { String methodName = caller.getMethodName(); className = className.substring(className.lastIndexOf('.') + 1); - logStream.println(className + "." + methodName + ":" + lineNumber + ": " + message); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + logStream.println(className + "." + methodName + ":" + lineNumber + ": " + message); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ logStream.flush(); } } @@ -168,14 +184,15 @@ public final class Logger { public static final void logException(Exception ex) { // log in eclipse error log if (TerminalPlugin.getDefault() != null) { - TerminalPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex)); + TerminalPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex)); } else { ex.printStackTrace(); } // Additional Tracing for debug purposes: // Read my own stack to get the class name, method name, and line number // of where this method was called - if(logStream!=null) { + if (logStream != null) { StackTraceElement caller = new Throwable().getStackTrace()[1]; int lineNumber = caller.getLineNumber(); String className = caller.getClassName(); @@ -188,8 +205,7 @@ public final class Logger { tmpStream = logStream; } - tmpStream.println(className - + "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + tmpStream.println(className + "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ "Caught exception: " + ex); //$NON-NLS-1$ ex.printStackTrace(tmpStream); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalConnectorExtension.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalConnectorExtension.java index 6eea871b388..0379361cca0 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalConnectorExtension.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalConnectorExtension.java @@ -41,19 +41,20 @@ import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnect public class TerminalConnectorExtension { static private ITerminalConnector makeConnector(final IConfigurationElement config) { String id = config.getAttribute("id"); //$NON-NLS-1$ - if(id==null || id.length()==0) - id=config.getAttribute("class"); //$NON-NLS-1$ - String name= config.getAttribute("name"); //$NON-NLS-1$ - if(name==null || name.length()==0) { - name=id; + if (id == null || id.length() == 0) + id = config.getAttribute("class"); //$NON-NLS-1$ + String name = config.getAttribute("name"); //$NON-NLS-1$ + if (name == null || name.length() == 0) { + name = id; } String hidden = config.getAttribute("hidden"); //$NON-NLS-1$ boolean isHidden = hidden != null ? new Boolean(hidden).booleanValue() : false; - TerminalConnector.Factory factory=new TerminalConnector.Factory(){ + TerminalConnector.Factory factory = new TerminalConnector.Factory() { public TerminalConnectorImpl makeConnector() throws Exception { - return (TerminalConnectorImpl)config.createExecutableExtension("class"); //$NON-NLS-1$ - }}; - return new TerminalConnector(factory,id,name, isHidden); + return (TerminalConnectorImpl) config.createExecutableExtension("class"); //$NON-NLS-1$ + } + }; + return new TerminalConnector(factory, id, name, isHidden); } /** @@ -68,14 +69,16 @@ public class TerminalConnectorExtension { * @since org.eclipse.tm.terminal 2.0 */ public static ITerminalConnector makeTerminalConnector(String id) { - IConfigurationElement[] config = RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$ + IConfigurationElement[] config = RegistryFactory.getRegistry() + .getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$ for (int i = 0; i < config.length; i++) { - if(id.equals(config[i].getAttribute("id"))) { //$NON-NLS-1$ + if (id.equals(config[i].getAttribute("id"))) { //$NON-NLS-1$ return makeConnector(config[i]); } } return null; } + /** * Return a list of available terminal connectors (connection types). * @@ -89,8 +92,9 @@ public class TerminalConnectorExtension { * @since org.eclipse.tm.terminal 2.0 return value is ITerminalConnector[] */ public static ITerminalConnector[] makeTerminalConnectors() { - IConfigurationElement[] config = RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$ - List result=new ArrayList(); + IConfigurationElement[] config = RegistryFactory.getRegistry() + .getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$ + List result = new ArrayList(); for (int i = 0; i < config.length; i++) { result.add(makeConnector(config[i])); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalState.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalState.java index 9425cbf7eaf..621d5df86d3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalState.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/TerminalState.java @@ -30,17 +30,17 @@ public class TerminalState { /** * The terminal is not connected. */ - public final static TerminalState CLOSED=new TerminalState("CLOSED"); //$NON-NLS-1$ + public final static TerminalState CLOSED = new TerminalState("CLOSED"); //$NON-NLS-1$ /** * The terminal is about to connect. */ - public final static TerminalState CONNECTING=new TerminalState("CONNECTING..."); //$NON-NLS-1$ + public final static TerminalState CONNECTING = new TerminalState("CONNECTING..."); //$NON-NLS-1$ /** * The terminal is connected. */ - public final static TerminalState CONNECTED=new TerminalState("CONNECTED"); //$NON-NLS-1$ + public final static TerminalState CONNECTED = new TerminalState("CONNECTED"); //$NON-NLS-1$ private final String fState; diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/provider/TerminalConnectorImpl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/provider/TerminalConnectorImpl.java index 7b22cc3cdb7..79ecb9b92fd 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/provider/TerminalConnectorImpl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/provider/TerminalConnectorImpl.java @@ -9,7 +9,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation - * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl + * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl *******************************************************************************/ package org.eclipse.tm.internal.terminal.provisional.api.provider; @@ -29,7 +29,7 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; */ public abstract class TerminalConnectorImpl { - /** + /** * The TerminalControl associated with this connector. * Required for advertising state changes when needed. */ @@ -49,12 +49,12 @@ public abstract class TerminalConnectorImpl { /** * Connect using the current state of the settings. - * + * * This method is designed to be overridden by actual implementations, in * order to open the streams required for communicating with the remote * side. Extenders must call super.connect(control) as the * first thing they are doing. - * + * * @param control Used to inform the UI about state changes and messages * from the connection. */ @@ -81,11 +81,11 @@ public abstract class TerminalConnectorImpl { // Do nothing by default } - /** - * @return the terminal to remote stream (bytes written to this stream will - * be sent to the remote site). For the stream in the other direction (remote to - * terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()} - */ + /** + * @return the terminal to remote stream (bytes written to this stream will + * be sent to the remote site). For the stream in the other direction (remote to + * terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()} + */ abstract public OutputStream getTerminalToRemoteStream(); /** @@ -140,7 +140,7 @@ public abstract class TerminalConnectorImpl { // do nothing by default } - /** + /** * Notify the remote site that the size of the terminal has changed. * * Concrete connectors should override this if they have the possibility to diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java index c6035b38eb4..f3c67a96fb3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java @@ -32,13 +32,13 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { private final ITerminalTextDataSnapshot fSnapshot; private int fLines; - private int fSelectionStartLine=-1; + private int fSelectionStartLine = -1; private int fSeletionEndLine; private int fSelectionStartCoumn; private int fSelectionEndColumn; private ITerminalTextDataSnapshot fSelectionSnapshot; - private String fCurrentSelection=""; //$NON-NLS-1$ - private final Point fSelectionAnchor=new Point(0,0); + private String fCurrentSelection = ""; //$NON-NLS-1$ + private final Point fSelectionAnchor = new Point(0, 0); /** * do not update while update is running */ @@ -46,9 +46,10 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { private int fCols; public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) { - fSnapshot=snapshot; - fLines=fSnapshot.getHeight(); + fSnapshot = snapshot; + fLines = fSnapshot.getHeight(); } + public void addCellCanvasModelListener(ITextCanvasModelListener listener) { fListeners.add(listener); } @@ -63,13 +64,15 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { listener.rangeChanged(x, y, width, height); } } - protected void fireDimensionsChanged( int width,int height) { + + protected void fireDimensionsChanged(int width, int height) { for (Iterator iter = fListeners.iterator(); iter.hasNext();) { ITextCanvasModelListener listener = iter.next(); - listener.dimensionsChanged(width,height); + listener.dimensionsChanged(width, height); } } + protected void fireTerminalDataChanged() { for (Iterator iter = fListeners.iterator(); iter.hasNext();) { ITextCanvasModelListener listener = iter.next(); @@ -81,36 +84,39 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { public ITerminalTextDataReadOnly getTerminalText() { return fSnapshot; } + protected ITerminalTextDataSnapshot getSnapshot() { return fSnapshot; } + protected void updateSnapshot() { - if(!fInUpdate && fSnapshot.isOutOfDate()) { - fInUpdate=true; + if (!fInUpdate && fSnapshot.isOutOfDate()) { + fInUpdate = true; try { fSnapshot.updateSnapshot(false); - if(fSnapshot.hasTerminalChanged()) + if (fSnapshot.hasTerminalChanged()) fireTerminalDataChanged(); // TODO why does hasDimensionsChanged not work?????? // if(fSnapshot.hasDimensionsChanged()) // fireDimensionsChanged(); - if(fLines!=fSnapshot.getHeight() || fCols!=fSnapshot.getWidth()) { - fireDimensionsChanged(fSnapshot.getWidth(),fSnapshot.getHeight()); - fLines=fSnapshot.getHeight(); - fCols=fSnapshot.getWidth(); + if (fLines != fSnapshot.getHeight() || fCols != fSnapshot.getWidth()) { + fireDimensionsChanged(fSnapshot.getWidth(), fSnapshot.getHeight()); + fLines = fSnapshot.getHeight(); + fCols = fSnapshot.getWidth(); } - int y=fSnapshot.getFirstChangedLine(); + int y = fSnapshot.getFirstChangedLine(); // has any line changed? - if(y=getSnapshot().getHeight()) { - cursorLine=getSnapshot().getHeight()-1; - cursorColumn=getSnapshot().getWidth()-1; + if (cursorLine >= getSnapshot().getHeight()) { + cursorLine = getSnapshot().getHeight() - 1; + cursorColumn = getSnapshot().getWidth() - 1; } // has the cursor moved? - if(fCursorLine!=cursorLine || fCursorColumn!=cursorColumn) { + if (fCursorLine != cursorLine || fCursorColumn != cursorColumn) { // hide the old cursor! - fShowCursor=false; + fShowCursor = false; // clean the previous cursor // bug 206363: paint also the char to the left and right of the cursor - see also below - int col=fCursorColumn; - int width=2; - if(col>0) { + int col = fCursorColumn; + int width = 2; + if (col > 0) { col--; width++; } fireCellRangeChanged(col, fCursorLine, width, 1); // the cursor is shown when it moves! - fShowCursor=true; - fCursorTime=System.currentTimeMillis(); - fCursorLine=cursorLine; - fCursorColumn=cursorColumn; + fShowCursor = true; + fCursorTime = System.currentTimeMillis(); + fCursorLine = cursorLine; + fCursorColumn = cursorColumn; // and draw the new cursor fireCellRangeChanged(fCursorColumn, fCursorLine, 1, 1); } else { - long t=System.currentTimeMillis(); + long t = System.currentTimeMillis(); // TODO make the cursor blink time customisable - if(t-fCursorTime>500) { - fShowCursor=!fShowCursor; - fCursorTime=t; + if (t - fCursorTime > 500) { + fShowCursor = !fShowCursor; + fCursorTime = t; // on some windows machines, there is some left // over when updating the cursor . // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206363 - int col=fCursorColumn; - int width=2; - if(col>0) { + int col = fCursorColumn; + int width = 2; + if (col > 0) { col--; width++; } @@ -187,25 +193,29 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { } } } + public void setVisibleRectangle(int startLine, int startCol, int height, int width) { - fSnapshot.setInterestWindow(Math.max(0,startLine), Math.max(1,height)); + fSnapshot.setInterestWindow(Math.max(0, startLine), Math.max(1, height)); update(); } + protected void showCursor(boolean show) { - fShowCursor=true; + fShowCursor = true; } + public void setCursorEnabled(boolean visible) { - fCursorTime=System.currentTimeMillis(); - fShowCursor=visible; - fCursorIsEnabled=visible; + fCursorTime = System.currentTimeMillis(); + fShowCursor = visible; + fCursorIsEnabled = visible; fireCellRangeChanged(fCursorColumn, fCursorLine, 1, 1); } + public boolean isCursorEnabled() { return fCursorIsEnabled; } public Point getSelectionEnd() { - if(fSelectionStartLine<0) + if (fSelectionStartLine < 0) return null; else return new Point(fSelectionEndColumn, fSeletionEndLine); @@ -215,57 +225,60 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { if (fSelectionStartLine < 0) return null; else - return new Point(fSelectionStartCoumn,fSelectionStartLine); + return new Point(fSelectionStartCoumn, fSelectionStartLine); } + public Point getSelectionAnchor() { - if(fSelectionStartLine<0) + if (fSelectionStartLine < 0) return null; - return new Point(fSelectionAnchor.x,fSelectionAnchor.y); + return new Point(fSelectionAnchor.x, fSelectionAnchor.y); } + public void setSelectionAnchor(Point anchor) { - fSelectionAnchor.x=anchor.x; - fSelectionAnchor.y=anchor.y; + fSelectionAnchor.x = anchor.x; + fSelectionAnchor.y = anchor.y; } public void setSelection(int startLine, int endLine, int startColumn, int endColumn) { -// System.err.println(startLine+","+endLine+","+startColumn+","+endColumn); + // System.err.println(startLine+","+endLine+","+startColumn+","+endColumn); doSetSelection(startLine, endLine, startColumn, endColumn); - fCurrentSelection=extractSelectedText(); + fCurrentSelection = extractSelectedText(); } + private void doSetSelection(int startLine, int endLine, int startColumn, int endColumn) { - assert(startLine<0 || startLine<=endLine); - if(startLine>=0) { - if(fSelectionSnapshot==null) { - fSelectionSnapshot=fSnapshot.getTerminalTextData().makeSnapshot(); + assert (startLine < 0 || startLine <= endLine); + if (startLine >= 0) { + if (fSelectionSnapshot == null) { + fSelectionSnapshot = fSnapshot.getTerminalTextData().makeSnapshot(); fSelectionSnapshot.updateSnapshot(true); } - } else if(fSelectionSnapshot!=null) { + } else if (fSelectionSnapshot != null) { fSelectionSnapshot.detach(); - fSelectionSnapshot=null; + fSelectionSnapshot = null; } - int oldStart=fSelectionStartLine; - int oldEnd=fSeletionEndLine; + int oldStart = fSelectionStartLine; + int oldEnd = fSeletionEndLine; fSelectionStartLine = startLine; fSeletionEndLine = endLine; fSelectionStartCoumn = startColumn; fSelectionEndColumn = endColumn; - if(fSelectionSnapshot!=null) { + if (fSelectionSnapshot != null) { fSelectionSnapshot.setInterestWindow(0, fSelectionSnapshot.getHeight()); } int changedStart; int changedEnd; - if(oldStart<0) { - changedStart=fSelectionStartLine; - changedEnd=fSeletionEndLine; - } else if(fSelectionStartLine<0) { - changedStart=oldStart; - changedEnd=oldEnd; + if (oldStart < 0) { + changedStart = fSelectionStartLine; + changedEnd = fSeletionEndLine; + } else if (fSelectionStartLine < 0) { + changedStart = oldStart; + changedEnd = oldEnd; } else { - changedStart=Math.min(oldStart, fSelectionStartLine); - changedEnd=Math.max(oldEnd, fSeletionEndLine); + changedStart = Math.min(oldStart, fSelectionStartLine); + changedEnd = Math.max(oldEnd, fSeletionEndLine); } - if(changedStart>=0) { - fireCellRangeChanged(0, changedStart, fSnapshot.getWidth(), changedEnd-changedStart+1); + if (changedStart >= 0) { + fireCellRangeChanged(0, changedStart, fSnapshot.getWidth(), changedEnd - changedStart + 1); } } @@ -300,33 +313,35 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { * @return the currently selected text */ private String extractSelectedText() { - if(fSelectionStartLine<0 || fSelectionStartCoumn<0 || fSelectionSnapshot==null) + if (fSelectionStartLine < 0 || fSelectionStartCoumn < 0 || fSelectionSnapshot == null) return ""; //$NON-NLS-1$ - StringBuffer buffer=new StringBuffer(); + StringBuffer buffer = new StringBuffer(); for (int line = fSelectionStartLine; line <= fSeletionEndLine; line++) { String text; - char[] chars=fSelectionSnapshot.getChars(line); - if(chars!=null) { - text=new String(chars); - if(line==fSeletionEndLine && fSelectionEndColumn >= 0) - text=text.substring(0, Math.min(fSelectionEndColumn+1,text.length())); - if(line==fSelectionStartLine) - text=text.substring(Math.min(fSelectionStartCoumn,text.length())); - text=scrubLine(text); + char[] chars = fSelectionSnapshot.getChars(line); + if (chars != null) { + text = new String(chars); + if (line == fSeletionEndLine && fSelectionEndColumn >= 0) + text = text.substring(0, Math.min(fSelectionEndColumn + 1, text.length())); + if (line == fSelectionStartLine) + text = text.substring(Math.min(fSelectionStartCoumn, text.length())); + text = scrubLine(text); } else { - text=""; //$NON-NLS-1$ + text = ""; //$NON-NLS-1$ } buffer.append(text); - if(line < fSeletionEndLine && !fSelectionSnapshot.isWrappedLine(line)) + if (line < fSeletionEndLine && !fSelectionSnapshot.isWrappedLine(line)) buffer.append('\n'); } return buffer.toString(); } + private void updateSelection() { if (fSelectionSnapshot != null && fSelectionSnapshot.isOutOfDate()) { fSelectionSnapshot.updateSnapshot(true); // has the selection moved? - if (fSelectionSnapshot != null && fSelectionStartLine >= 0 && fSelectionSnapshot.getScrollWindowSize() > 0) { + if (fSelectionSnapshot != null && fSelectionStartLine >= 0 + && fSelectionSnapshot.getScrollWindowSize() > 0) { int start = fSelectionStartLine + fSelectionSnapshot.getScrollWindowShift(); int end = fSeletionEndLine + fSelectionSnapshot.getScrollWindowShift(); if (start < 0) @@ -338,7 +353,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { } // check if the content of the selection has changed. If the content has // changed, clear the selection - if (fCurrentSelection.length()>0 && fSelectionSnapshot != null + if (fCurrentSelection.length() > 0 && fSelectionSnapshot != null && fSelectionSnapshot.getFirstChangedLine() <= fSeletionEndLine && fSelectionSnapshot.getLastChangedLine() >= fSelectionStartLine) { // has the selected text changed? diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java index dc5d4c56993..5425354f5ea 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java @@ -1,17 +1,16 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [294468] Fix scroller and text line rendering *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; - import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; @@ -35,13 +34,13 @@ abstract public class GridCanvas extends VirtualCanvas { super(parent, style); addListener(SWT.MouseWheel, new Listener() { public void handleEvent(Event event) { - if(getVerticalBar().isVisible()) { - int delta=-fCellHeight; - if(event.count<0) - delta=-delta; + if (getVerticalBar().isVisible()) { + int delta = -fCellHeight; + if (event.count < 0) + delta = -delta; scrollYDelta(delta); } - event.doit=false; + event.doit = false; } }); @@ -51,36 +50,37 @@ abstract public class GridCanvas extends VirtualCanvas { * iterates over all cells in the clipping rectangle and paints them. */ protected void paint(GC gc) { - Rectangle clipping=gc.getClipping(); - if(clipping.width==0 || clipping.height==0) + Rectangle clipping = gc.getClipping(); + if (clipping.width == 0 || clipping.height == 0) return; - Rectangle clientArea= getScreenRectInVirtualSpace(); + Rectangle clientArea = getScreenRectInVirtualSpace(); // Beginning coordinates - int xOffset=clientArea.x; - int yOffset=clientArea.y; - int colFirst=virtualXToCell(xOffset+clipping.x); - if(colFirst>getCols()) - colFirst=getCols(); + int xOffset = clientArea.x; + int yOffset = clientArea.y; + int colFirst = virtualXToCell(xOffset + clipping.x); + if (colFirst > getCols()) + colFirst = getCols(); else if (colFirst < 0) { colFirst = 0; } - int rowFirst=virtualYToCell(yOffset+clipping.y); + int rowFirst = virtualYToCell(yOffset + clipping.y); // End coordinates - int colLast=virtualXToCell(xOffset+clipping.x+clipping.width+fCellWidth); - if(colLast>getCols()) - colLast=getCols(); - int rowLast=virtualYToCell(yOffset+clipping.y+clipping.height+fCellHeight); - if(rowLast>getRows()) - rowLast=getRows(); + int colLast = virtualXToCell(xOffset + clipping.x + clipping.width + fCellWidth); + if (colLast > getCols()) + colLast = getCols(); + int rowLast = virtualYToCell(yOffset + clipping.y + clipping.height + fCellHeight); + if (rowLast > getRows()) + rowLast = getRows(); // System.out.println(rowFirst+"->"+rowLast+" "+System.currentTimeMillis()); // draw the cells - for(int row=rowFirst;row<=rowLast;row++) { - int cx=colFirst*fCellWidth-xOffset; - int cy=row*fCellHeight-yOffset; - drawLine(gc,row,cx,cy,colFirst,colLast); + for (int row = rowFirst; row <= rowLast; row++) { + int cx = colFirst * fCellWidth - xOffset; + int cy = row * fCellHeight - yOffset; + drawLine(gc, row, cx, cy, colFirst, colLast); } - paintUnoccupiedSpace(gc,clipping); + paintUnoccupiedSpace(gc, clipping); } + /** * @param gc * @param row the line to draw @@ -92,6 +92,7 @@ abstract public class GridCanvas extends VirtualCanvas { abstract void drawLine(GC gc, int row, int x, int y, int colFirst, int colLast); abstract protected int getRows(); + abstract protected int getCols(); protected void setCellWidth(int cellWidth) { @@ -113,65 +114,66 @@ abstract public class GridCanvas extends VirtualCanvas { } int virtualXToCell(int x) { - return x/fCellWidth; + return x / fCellWidth; } int virtualYToCell(int y) { - return y/fCellHeight; + return y / fCellHeight; } protected Point screenPointToCell(int x, int y) { - x=screenXtoVirtual(x)/fCellWidth; - y=screenYtoVirtual(y)/fCellHeight; - return new Point(x,y); + x = screenXtoVirtual(x) / fCellWidth; + y = screenYtoVirtual(y) / fCellHeight; + return new Point(x, y); } Point screenPointToCell(Point point) { - return screenPointToCell(point.x,point.y); + return screenPointToCell(point.x, point.y); } protected Point cellToOriginOnScreen(int x, int y) { - x=virtualXtoScreen(fCellWidth*x); - y=virtualYtoScreen(fCellHeight*y); - return new Point(x,y); + x = virtualXtoScreen(fCellWidth * x); + y = virtualYtoScreen(fCellHeight * y); + return new Point(x, y); } Point cellToOriginOnScreen(Point cell) { - return cellToOriginOnScreen(cell.x,cell.y); + return cellToOriginOnScreen(cell.x, cell.y); } Rectangle getCellScreenRect(Point cell) { - return getCellScreenRect(cell.x,cell.y); + return getCellScreenRect(cell.x, cell.y); } Rectangle getCellScreenRect(int x, int y) { - x=fCellWidth*virtualXtoScreen(x); - y=fCellHeight*virtualYtoScreen(y); - return new Rectangle(x,y,fCellWidth,fCellHeight); + x = fCellWidth * virtualXtoScreen(x); + y = fCellHeight * virtualYtoScreen(y); + return new Rectangle(x, y, fCellWidth, fCellHeight); } protected Rectangle getCellVirtualRect(Point cell) { - return getCellVirtualRect(cell.x,cell.y); + return getCellVirtualRect(cell.x, cell.y); } Rectangle getCellVirtualRect(int x, int y) { - x=fCellWidth*x; - y=fCellHeight*y; - return new Rectangle(x,y,fCellWidth,fCellHeight); + x = fCellWidth * x; + y = fCellHeight * y; + return new Rectangle(x, y, fCellWidth, fCellHeight); } + protected void viewRectangleChanged(int x, int y, int width, int height) { - int cellX=virtualXToCell(x); - int cellY=virtualYToCell(y); + int cellX = virtualXToCell(x); + int cellY = virtualYToCell(y); // End coordinates - int xE=virtualXToCell(x+width); -// if(xE>getCols()) -// xE=getCols(); - int yE=virtualYToCell(y+height); -// if(yE>getRows()) -// yE=getRows(); - visibleCellRectangleChanged(cellX,cellY,xE-cellX,yE-cellY); + int xE = virtualXToCell(x + width); + // if(xE>getCols()) + // xE=getCols(); + int yE = virtualYToCell(y + height); + // if(yE>getRows()) + // yE=getRows(); + visibleCellRectangleChanged(cellX, cellY, xE - cellX, yE - cellY); } - + /** * Called when the viewed part has changed. * Override when you need this information.... @@ -183,7 +185,7 @@ abstract public class GridCanvas extends VirtualCanvas { */ protected void visibleCellRectangleChanged(int x, int y, int width, int height) { } - + protected void setVirtualExtend(int width, int height) { int cellHeight = getCellHeight(); if (cellHeight > 0) { @@ -191,7 +193,7 @@ abstract public class GridCanvas extends VirtualCanvas { } super.setVirtualExtend(width, height); } - + protected void setVirtualOrigin(int x, int y) { int cellHeight = getCellHeight(); if (cellHeight > 0) { @@ -204,9 +206,9 @@ abstract public class GridCanvas extends VirtualCanvas { } super.setVirtualOrigin(x, y); } - + protected void scrollY(ScrollBar vBar) { - int vSelection = vBar.getSelection (); + int vSelection = vBar.getSelection(); Rectangle bounds = getVirtualBounds(); int y = -vSelection; int cellHeight = getCellHeight(); @@ -219,8 +221,8 @@ abstract public class GridCanvas extends VirtualCanvas { } } int deltaY = y - bounds.y; - if(deltaY!=0) { - scrollSmart(0,deltaY); + if (deltaY != 0) { + scrollSmart(0, deltaY); setVirtualOrigin(bounds.x, bounds.y += deltaY); } if (-bounds.y + getRows() * getCellHeight() >= bounds.height) { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java index 9666fd9a910..efd8744bf8b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java @@ -22,18 +22,24 @@ import org.eclipse.swt.graphics.GC; */ public interface ILinelRenderer { int getCellWidth(); + int getCellHeight(); + void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast); + /** * Update for a font change from the global JFace Registry. */ void onFontChange(); + /** * Set a new font * @param fontName Jface name of the new font * @since 3.2 */ void updateFont(String fontName); + void setInvertedColors(boolean invert); + Color getDefaultBackgroundColor(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModel.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModel.java index 0fbba76959c..82362757726 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModel.java @@ -17,9 +17,11 @@ import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly; public interface ITextCanvasModel { void addCellCanvasModelListener(ITextCanvasModelListener listener); + void removeCellCanvasModelListener(ITextCanvasModelListener listener); ITerminalTextDataReadOnly getTerminalText(); + /** * This is is * @param startLine @@ -33,6 +35,7 @@ public interface ITextCanvasModel { * @return true when the cursor is shown (used for blinking cursors) */ boolean isCursorOn(); + /** * Show/Hide the cursor. * @param visible @@ -48,6 +51,7 @@ public interface ITextCanvasModel { * @return the line of the cursor */ int getCursorLine(); + /** * @return the column of the cursor */ @@ -58,6 +62,7 @@ public interface ITextCanvasModel { * {@link Point#x} is the column and {@link Point#y} is the line. */ Point getSelectionStart(); + /** * @return the end of the selection or null if nothing is selected * {@link Point#x} is the column and {@link Point#y} is the line. @@ -67,6 +72,7 @@ public interface ITextCanvasModel { Point getSelectionAnchor(); void setSelectionAnchor(Point anchor); + /** * Sets the selection. A negative startLine clears the selection. * @param startLine diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModelListener.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModelListener.java index bc942890baa..4d6251844ca 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModelListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ITextCanvasModelListener.java @@ -16,7 +16,9 @@ package org.eclipse.tm.internal.terminal.textcanvas; */ public interface ITextCanvasModelListener { void rangeChanged(int col, int line, int width, int height); + void dimensionsChanged(int cols, int rows); + /** * Called when any text change happened. Used to scroll to the * end of text in auto scroll mode. This does not get fired diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java index 4c00d995454..e1acd51a222 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java @@ -7,7 +7,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation - * Douglas Lea (Addison Wesley) - [cq:1552] BoundedBufferWithStateTracking adapted to BoundedByteBuffer + * Douglas Lea (Addison Wesley) - [cq:1552] BoundedBufferWithStateTracking adapted to BoundedByteBuffer * Martin Oberhuber (Wind River) - the waitForAvailable method * Martin Oberhuber (Wind River) - [208166] Avoid unnecessary arraycopy in BoundedByteBuffer * Pawel Piech (Wind River) - [333613] "Job found still running" after shutdown @@ -21,7 +21,7 @@ import java.io.OutputStream; /** * The main purpose of this class is to start a runnable in the - * display thread when data is available and to pretend no data + * display thread when data is available and to pretend no data * is available after a given amount of time the runnable is running. * */ @@ -34,27 +34,27 @@ public class PipedInputStream extends InputStream { * A blocking byte queue. */ private final BoundedByteBuffer fQueue; - + /** * A byte bounded buffer used to synchronize the input and the output stream. *

- * Adapted from BoundedBufferWithStateTracking + * Adapted from BoundedBufferWithStateTracking * http://gee.cs.oswego.edu/dl/cpj/allcode.java * http://gee.cs.oswego.edu/dl/cpj/ *

* BoundedBufferWithStateTracking is part of the examples for the book * Concurrent Programming in Java: Design Principles and Patterns by - * Doug Lea (ISBN 0-201-31009-0). Second edition published by - * Addison-Wesley, November 1999. The code is + * Doug Lea (ISBN 0-201-31009-0). Second edition published by + * Addison-Wesley, November 1999. The code is * Copyright(c) Douglas Lea 1996, 1999 and released to the public domain - * and may be used for any purposes whatsoever. + * and may be used for any purposes whatsoever. *

* For some reasons a solution based on * PipedOutputStream/PipedIntputStream * does work *very* slowly: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4404700 *

- * + * */ private class BoundedByteBuffer { protected final byte[] fBuffer; // the elements @@ -62,19 +62,22 @@ public class PipedInputStream extends InputStream { protected int fTakePos = 0; protected int fUsedSlots = 0; // the count private boolean fClosed; + public BoundedByteBuffer(int capacity) throws IllegalArgumentException { // make sure we don't deadlock on too small capacity if (capacity <= 0) throw new IllegalArgumentException(); fBuffer = new byte[capacity]; } + /** * @return the bytes available for {@link #read()} * Must be called with a lock on this! */ public int available() { - return fUsedSlots; + return fUsedSlots; } + /** * Writes a single byte to the buffer. Blocks if the buffer is full. * @param b byte to write to the buffer @@ -93,11 +96,13 @@ public class PipedInputStream extends InputStream { if (fUsedSlots++ == 0) // signal if was empty notifyAll(); } + public int getFreeSlots() { return fBuffer.length - fUsedSlots; } + public void write(byte[] b, int off, int len) throws InterruptedException { - assert len<=getFreeSlots(); + assert len <= getFreeSlots(); while (fUsedSlots == fBuffer.length) // wait until not full wait(); @@ -111,6 +116,7 @@ public class PipedInputStream extends InputStream { if (wasEmpty) // signal if was empty notifyAll(); } + /** * Read a single byte. Blocks until a byte is available. * @return a byte from the buffer @@ -120,7 +126,7 @@ public class PipedInputStream extends InputStream { */ public int read() throws InterruptedException { while (fUsedSlots == 0) { - if(fClosed) + if (fClosed) return -1; // wait until not empty wait(); @@ -132,10 +138,11 @@ public class PipedInputStream extends InputStream { notifyAll(); return b; } + public int read(byte[] cbuf, int off, int len) throws InterruptedException { - assert len<=available(); + assert len <= available(); while (fUsedSlots == 0) { - if(fClosed) + if (fClosed) return 0; // wait until not empty wait(); @@ -147,45 +154,47 @@ public class PipedInputStream extends InputStream { fTakePos = (fTakePos + len) % fBuffer.length; boolean wasFull = fUsedSlots == fBuffer.length; fUsedSlots -= len; - if(wasFull) + if (wasFull) notifyAll(); - + return len; } + public void close() { - fClosed=true; + fClosed = true; notifyAll(); } + public boolean isClosed() { return fClosed; } } /** - * An output stream that calls {@link PipedInputStream#textAvailable} + * An output stream that calls {@link PipedInputStream#textAvailable} * every time data is written to the stream. The data is written to * {@link PipedInputStream#fQueue}. - * + * */ class PipedOutputStream extends OutputStream { public void write(byte[] b, int off, int len) throws IOException { try { synchronized (fQueue) { - if(fQueue.isClosed()) + if (fQueue.isClosed()) throw new IOException("Stream is closed!"); //$NON-NLS-1$ - int written=0; - while(writtenPipedInputStream is the same as closing the output stream. - * The stream will allow reading data that's still in the pipe after which it will - * throw an IOException. - */ + + /** + * Closing a PipedInputStream is the same as closing the output stream. + * The stream will allow reading data that's still in the pipe after which it will + * throw an IOException. + */ public void close() throws IOException { - synchronized(fQueue) { - fQueue.close(); - } + synchronized (fQueue) { + fQueue.close(); + } } public int read(byte[] cbuf, int off, int len) throws IOException { - int n=0; - if(len==0) + int n = 0; + if (len == 0) return 0; // read as much as we can using a single synchronized statement try { - synchronized (fQueue) { + synchronized (fQueue) { // if nothing available, block and read one byte if (fQueue.available() == 0) { // block now until at least one byte is available @@ -302,7 +318,7 @@ public class PipedInputStream extends InputStream { fQueue.read(cbuf, off + n, nn); n += nn; } - + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PollingTextCanvasModel.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PollingTextCanvasModel.java index 4d0a6581cc3..8f84676089d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PollingTextCanvasModel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/PollingTextCanvasModel.java @@ -1,15 +1,16 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [420928] Terminal widget leaks memory *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; + import org.eclipse.swt.widgets.Display; import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot; @@ -22,23 +23,26 @@ public class PollingTextCanvasModel extends AbstractTextCanvasModel { int fPollInterval = -1; /** - * + * */ public PollingTextCanvasModel(ITerminalTextDataSnapshot snapshot) { super(snapshot); startPolling(); } + public void setUpdateInterval(int t) { fPollInterval = t; } + public void stopPolling() { // timerExec only dispatches if the delay is >=0 fPollInterval = -1; } + public void startPolling() { if (fPollInterval < 0) { fPollInterval = DEFAULT_POLL_INTERVAL; - Display.getDefault().timerExec(fPollInterval, new Runnable(){ + Display.getDefault().timerExec(fPollInterval, new Runnable() { public void run() { update(); Display.getDefault().timerExec(fPollInterval, this); diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java index 5d4e91a7a0f..e6e91d5c05e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java @@ -45,29 +45,32 @@ public class StyleMap { private static final String BLUE = "blue"; //$NON-NLS-1$ private static final String GREEN = "green"; //$NON-NLS-1$ private static final String RED = "red"; //$NON-NLS-1$ - + private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$ - String fFontName=ITerminalConstants.FONT_DEFINITION; - Map fColorMapForeground=new HashMap(); - Map fColorMapBackground=new HashMap(); - Map fColorMapIntense=new HashMap(); + String fFontName = ITerminalConstants.FONT_DEFINITION; + Map fColorMapForeground = new HashMap(); + Map fColorMapBackground = new HashMap(); + Map fColorMapIntense = new HashMap(); private Point fCharSize; private final Style fDefaultStyle; private boolean fInvertColors; private boolean fProportional; - private final int[] fOffsets=new int[256]; + private final int[] fOffsets = new int[256]; + StyleMap() { initColors(); - fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE)); + fDefaultStyle = Style.getStyle(StyleColor.getStyleColor(BLACK), StyleColor.getStyleColor(WHITE)); updateFont(); } + private void initColors() { initForegroundColors(); initBackgroundColors(); initIntenseColors(); } + private void initForegroundColors() { - if(fInvertColors) { + if (fInvertColors) { setColor(fColorMapForeground, WHITE, 0, 0, 0); setColor(fColorMapForeground, WHITE_FOREGROUND, 50, 50, 50); setColor(fColorMapForeground, BLACK, 229, 229, 229); @@ -86,7 +89,7 @@ public class StyleMap { } private void initBackgroundColors() { - if(fInvertColors) { + if (fInvertColors) { setColor(fColorMapBackground, WHITE, 0, 0, 0); setColor(fColorMapBackground, WHITE_FOREGROUND, 50, 50, 50); // only used when colors are inverse setColor(fColorMapBackground, BLACK, 255, 255, 255); @@ -105,7 +108,7 @@ public class StyleMap { } private void initIntenseColors() { - if(fInvertColors) { + if (fInvertColors) { setColor(fColorMapIntense, WHITE, 127, 127, 127); setColor(fColorMapIntense, WHITE_FOREGROUND, 0, 0, 0); // only used when colors are inverse setColor(fColorMapIntense, BLACK, 255, 255, 255); @@ -122,13 +125,13 @@ public class StyleMap { setColor(fColorMapIntense, MAGENTA, 255, 0, 255); setColor(fColorMapIntense, GRAY, 255, 255, 255); } - + private void setColor(Map colorMap, String name, int r, int g, int b) { - String colorName=PREFIX+r+"-"+g+"-"+b; //$NON-NLS-1$//$NON-NLS-2$ - Color color=JFaceResources.getColorRegistry().get(colorName); - if(color==null) { - JFaceResources.getColorRegistry().put(colorName, new RGB(r,g,b)); - color=JFaceResources.getColorRegistry().get(colorName); + String colorName = PREFIX + r + "-" + g + "-" + b; //$NON-NLS-1$//$NON-NLS-2$ + Color color = JFaceResources.getColorRegistry().get(colorName); + if (color == null) { + JFaceResources.getColorRegistry().put(colorName, new RGB(r, g, b)); + color = JFaceResources.getColorRegistry().get(colorName); } colorMap.put(StyleColor.getStyleColor(name), color); colorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color); @@ -138,66 +141,74 @@ public class StyleMap { style = defaultIfNull(style); Map map = style.isBold() ? fColorMapIntense : fColorMapForeground; //Map map = fColorMapForeground; - if(style.isReverse()) - return getColor(map ,style.getBackground()); + if (style.isReverse()) + return getColor(map, style.getBackground()); else - return getColor(map ,style.getForground()); + return getColor(map, style.getForground()); } + public Color getBackgroundColor(Style style) { style = defaultIfNull(style); - if(style.isReverse()) - return getColor(fColorMapBackground,style.getForground()); + if (style.isReverse()) + return getColor(fColorMapBackground, style.getForground()); else - return getColor(fColorMapBackground,style.getBackground()); + return getColor(fColorMapBackground, style.getBackground()); } - Color getColor(Map map,StyleColor color) { - Color c=map.get(color); - if(c==null) { - c=Display.getCurrent().getSystemColor(SWT.COLOR_GRAY); + + Color getColor(Map map, StyleColor color) { + Color c = map.get(color); + if (c == null) { + c = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY); } return c; } + private Style defaultIfNull(Style style) { - if(style==null) - style=fDefaultStyle; + if (style == null) + style = fDefaultStyle; return style; } + public void setInvertedColors(boolean invert) { - if(invert==fInvertColors) + if (invert == fInvertColors) return; - fInvertColors=invert; + fInvertColors = invert; initColors(); } -// static Font getBoldFont(Font font) { -// FontData fontDatas[] = font.getFontData(); -// FontData data = fontDatas[0]; -// return new Font(Display.getCurrent(), data.getName(), data.getHeight(), data.getStyle()|SWT.BOLD); -// } + // static Font getBoldFont(Font font) { + // FontData fontDatas[] = font.getFontData(); + // FontData data = fontDatas[0]; + // return new Font(Display.getCurrent(), data.getName(), data.getHeight(), data.getStyle()|SWT.BOLD); + // } public Font getFont(Style style) { style = defaultIfNull(style); - if(style.isBold()) { - return JFaceResources.getFontRegistry().getBold(fFontName); - } else if(style.isUnderline()) { - return JFaceResources.getFontRegistry().getItalic(fFontName); + if (style.isBold()) { + return JFaceResources.getFontRegistry().getBold(fFontName); + } else if (style.isUnderline()) { + return JFaceResources.getFontRegistry().getItalic(fFontName); } - return JFaceResources.getFontRegistry().get(fFontName); + return JFaceResources.getFontRegistry().get(fFontName); } public Font getFont() { - return JFaceResources.getFontRegistry().get(fFontName); + return JFaceResources.getFontRegistry().get(fFontName); } + public int getFontWidth() { return fCharSize.x; } + public int getFontHeight() { return fCharSize.y; } + public void updateFont() { updateFont(ITerminalConstants.FONT_DEFINITION); } + /** * Update the StyleMap for a new font name. * The font name must be a valid name in the Jface font registry. @@ -205,8 +216,8 @@ public class StyleMap { * @since 3.2 */ public void updateFont(String fontName) { - Display display=Display.getCurrent(); - GC gc = new GC (display); + Display display = Display.getCurrent(); + GC gc = new GC(display); if (JFaceResources.getFontRegistry().hasValueFor(fontName)) { fFontName = fontName; } else { @@ -214,55 +225,56 @@ public class StyleMap { fFontName = "org.eclipse.jface.textfont"; //$NON-NLS-1$ } gc.setFont(getFont()); - fCharSize = gc.textExtent ("W"); //$NON-NLS-1$ - fProportional=false; - + fCharSize = gc.textExtent("W"); //$NON-NLS-1$ + fProportional = false; + for (char c = ' '; c <= '~'; c++) { // consider only the first 128 chars for deciding if a font // is proportional. Collect char width as a side-effect. - if(measureChar(gc, c, true)) - fProportional=true; + if (measureChar(gc, c, true)) + fProportional = true; } - if(fProportional) { + if (fProportional) { // Widest char minus the padding on the left and right: // Looks much better for small fonts - fCharSize.x-=2; + fCharSize.x -= 2; // Collect width of the upper characters (for offset calculation) - for (char c = '~'+1; c < fOffsets.length; c++) { - measureChar(gc, c,false); + for (char c = '~' + 1; c < fOffsets.length; c++) { + measureChar(gc, c, false); } // Calculate offsets based on each character's width and the bounding box for (int i = ' '; i < fOffsets.length; i++) { - fOffsets[i]=(fCharSize.x-fOffsets[i])/2; + fOffsets[i] = (fCharSize.x - fOffsets[i]) / 2; } } else { // Non-Proportional: Reset all offsets (eg after font change) for (int i = 0; i < fOffsets.length; i++) { - fOffsets[i]=0; + fOffsets[i] = 0; } String t = "The quick brown Fox jumps over the Lazy Dog."; //$NON-NLS-1$ - Point ext=gc.textExtent(t); - if(ext.x != fCharSize.x * t.length()) { + Point ext = gc.textExtent(t); + if (ext.x != fCharSize.x * t.length()) { //Bug 475422: On OSX with Retina display and due to scaling, //a text many be shorter than the sum of its bounding boxes. - //Because even with fixed width font, bounding box size + //Because even with fixed width font, bounding box size //may not be an integer but a fraction eg 6.75 pixels. // //Painting in proportional mode ensures that each character //is painted individually into its proper bounding box, rather //than using an optimization where Strings would be drawn as //a whole. This fixes the "fractional bounding box" problem. - fProportional=true; + fProportional = true; } //measure font in boldface, too, and if wider then treat like proportional gc.setFont(getFont(fDefaultStyle.setBold(true))); Point charSizeBold = gc.textExtent("W"); //$NON-NLS-1$ if (fCharSize.x != charSizeBold.x) { - fProportional=true; + fProportional = true; } } - gc.dispose (); + gc.dispose(); } + /** * @param gc * @param c @@ -270,28 +282,30 @@ public class StyleMap { * @return true if the the font is proportional */ private boolean measureChar(GC gc, char c, boolean updateMax) { - boolean proportional=false; - Point ext=gc.textExtent(String.valueOf(c)); - if(ext.x>0 && ext.y>0 && (fCharSize.x!=ext.x || fCharSize.y!=ext.y)) { - proportional=true; - if(updateMax) { - fCharSize.x=Math.max(fCharSize.x, ext.x); - fCharSize.y=Math.max(fCharSize.y, ext.y); + boolean proportional = false; + Point ext = gc.textExtent(String.valueOf(c)); + if (ext.x > 0 && ext.y > 0 && (fCharSize.x != ext.x || fCharSize.y != ext.y)) { + proportional = true; + if (updateMax) { + fCharSize.x = Math.max(fCharSize.x, ext.x); + fCharSize.y = Math.max(fCharSize.y, ext.y); } } - fOffsets[c]=ext.x; + fOffsets[c] = ext.x; return proportional; } + public boolean isFontProportional() { return fProportional; } + /** * Return the offset in pixels required to center a given character * @param c the character to measure * @return the offset in x direction to center this character */ public int getCharOffset(char c) { - if(c>=fOffsets.length) + if (c >= fOffsets.length) return 0; return fOffsets[c]; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java index 2161798bf26..2f866c8c4f7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java @@ -23,7 +23,6 @@ *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; - import java.util.ArrayList; import java.util.List; @@ -64,10 +63,10 @@ public class TextCanvas extends GridCanvas { // than that minimum size, the backing store size remains at the minSize, // and a scrollbar is shown instead. In reality, this has the following // issues or effects today: - // (a) Bug 281328: For very early data coming in before the widget is - // realized, the minSize determines into what initial grid that is + // (a) Bug 281328: For very early data coming in before the widget is + // realized, the minSize determines into what initial grid that is // rendered. See also @link{#addResizeHandler(ResizeListener)}. - // (b) Bug 294468: Since we have redraw and size computation problems + // (b) Bug 294468: Since we have redraw and size computation problems // with horizontal scrollers, for now the minColumns must be small // enough to avoid a horizontal scroller appearing in most cases. // (b) Bug 294327: since we have problems with the vertical scroller @@ -80,35 +79,40 @@ public class TextCanvas extends GridCanvas { // - dumb terminals which expect 80x24 render garbled on small viewport. // If bug 294468 were resolved, an 80 wide minSize would be preferrable // since it allows switching the terminal viewport small/large as needed, - // without destroying the backing store. For a complete solution, + // without destroying the backing store. For a complete solution, // Bug 196462 tracks the request for a user-defined fixed-widow-size-mode. - private int fMinColumns=80; - private int fMinLines=4; + private int fMinColumns = 80; + private int fMinLines = 4; private boolean fCursorEnabled; private boolean fResizing; - + /** * Create a new CellCanvas with the given SWT style bits. * (SWT.H_SCROLL and SWT.V_SCROLL are automatically added). */ - public TextCanvas(Composite parent, ITextCanvasModel model, int style,ILinelRenderer cellRenderer) { + public TextCanvas(Composite parent, ITextCanvasModel model, int style, ILinelRenderer cellRenderer) { super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL); - fCellRenderer=cellRenderer; + fCellRenderer = cellRenderer; setCellWidth(fCellRenderer.getCellWidth()); setCellHeight(fCellRenderer.getCellHeight()); - fCellCanvasModel=model; - fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener(){ + fCellCanvasModel = model; + fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener() { public void rangeChanged(int col, int line, int width, int height) { - if(isDisposed()) return; - repaintRange(col,line,width,height); + if (isDisposed()) + return; + repaintRange(col, line, width, height); } + public void dimensionsChanged(int cols, int rows) { - if(isDisposed()) return; + if (isDisposed()) + return; calculateGrid(); } + public void terminalDataChanged() { - if(isDisposed()) return; - + if (isDisposed()) + return; + // scroll to end (unless scroll lock is active) if (!fResizing) { calculateGrid(); @@ -117,15 +121,17 @@ public class TextCanvas extends GridCanvas { } }); // let the cursor blink if the text canvas gets the focus... - addFocusListener(new FocusListener(){ + addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { fCellCanvasModel.setCursorEnabled(fCursorEnabled); } + public void focusLost(FocusEvent e) { fCellCanvasModel.setCursorEnabled(false); - }}); + } + }); fMouseListeners = new ArrayList(); - addMouseListener(new MouseListener(){ + addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent e) { if (fMouseListeners.size() > 0) { Point pt = screenPointToCell(e.x, e.y); @@ -136,18 +142,19 @@ public class TextCanvas extends GridCanvas { } } } + public void mouseDown(MouseEvent e) { - if(e.button==1) { // left button - fDraggingStart=screenPointToCell(e.x, e.y); - fHasSelection=false; - if((e.stateMask&SWT.SHIFT)!=0) { - Point anchor=fCellCanvasModel.getSelectionAnchor(); - if(anchor!=null) - fDraggingStart=anchor; + if (e.button == 1) { // left button + fDraggingStart = screenPointToCell(e.x, e.y); + fHasSelection = false; + if ((e.stateMask & SWT.SHIFT) != 0) { + Point anchor = fCellCanvasModel.getSelectionAnchor(); + if (anchor != null) + fDraggingStart = anchor; } else { fCellCanvasModel.setSelectionAnchor(fDraggingStart); } - fDraggingEnd=null; + fDraggingEnd = null; } if (fMouseListeners.size() > 0) { Point pt = screenPointToCell(e.x, e.y); @@ -158,14 +165,15 @@ public class TextCanvas extends GridCanvas { } } } + public void mouseUp(MouseEvent e) { - if(e.button==1) { // left button + if (e.button == 1) { // left button updateHasSelection(e); - if(fHasSelection) + if (fHasSelection) setSelection(screenPointToCell(e.x, e.y)); else - fCellCanvasModel.setSelection(-1,-1,-1,-1); - fDraggingStart=null; + fCellCanvasModel.setSelection(-1, -1, -1, -1); + fDraggingStart = null; } if (fMouseListeners.size() > 0) { Point pt = screenPointToCell(e.x, e.y); @@ -197,15 +205,15 @@ public class TextCanvas extends GridCanvas { * @param e */ private void updateHasSelection(MouseEvent e) { - if(fDraggingStart!=null) { - Point p=screenPointToCell(e.x, e.y); - if(fDraggingStart.x!=p.x||fDraggingStart.y!=p.y) - fHasSelection=true; + if (fDraggingStart != null) { + Point p = screenPointToCell(e.x, e.y); + if (fDraggingStart.x != p.x || fDraggingStart.y != p.y) + fHasSelection = true; } } void setSelection(Point p) { - if (fDraggingStart !=null && !p.equals(fDraggingEnd)) { + if (fDraggingStart != null && !p.equals(fDraggingEnd)) { fDraggingEnd = p; if (compare(p, fDraggingStart) < 0) { // bug 219589 - make sure selection start coordinates are non-negative @@ -234,6 +242,7 @@ public class TextCanvas extends GridCanvas { return -1; } } + public ILinelRenderer getCellRenderer() { return fCellRenderer; } @@ -255,30 +264,30 @@ public class TextCanvas extends GridCanvas { } protected void onResize(boolean init) { - if(fResizeListener!=null) { - Rectangle bonds=getClientArea(); + if (fResizeListener != null) { + Rectangle bonds = getClientArea(); int cellHeight = getCellHeight(); int cellWidth = getCellWidth(); - int lines=bonds.height/cellHeight; - int columns=bonds.width/cellWidth; + int lines = bonds.height / cellHeight; + int columns = bonds.width / cellWidth; // when the view is minimised, its size is set to 0 // we don't sent this to the terminal! - if((lines>0 && columns>0) || init) { - if(columns 0 && columns > 0) || init) { + if (columns < fMinColumns) { + if (!isHorizontalBarVisble()) { setHorizontalBarVisible(true); - bonds=getClientArea(); - lines=bonds.height/cellHeight; + bonds = getClientArea(); + lines = bonds.height / cellHeight; } - columns=fMinColumns; - } else if(columns>=fMinColumns && isHorizontalBarVisble()) { + columns = fMinColumns; + } else if (columns >= fMinColumns && isHorizontalBarVisble()) { setHorizontalBarVisible(false); - bonds=getClientArea(); - lines=bonds.height/cellHeight; - columns=bonds.width/cellWidth; + bonds = getClientArea(); + lines = bonds.height / cellHeight; + columns = bonds.width / cellWidth; } - if(lines 0) { y = 0; } - Rectangle v=getViewRectangle(); - if(v.y!=-y) { - setVirtualOrigin(v.x,y); + Rectangle v = getViewRectangle(); + if (v.y != -y) { + setVirtualOrigin(v.x, y); } // make sure the scroll area is correct: scrollY(getVerticalBar()); scrollX(getHorizontalBar()); } } + /** * * @return true if the cursor should be shown on output.... @@ -333,37 +344,46 @@ public class TextCanvas extends GridCanvas { public boolean isScrollLock() { return fScrollLock; } + /** * If set then if the size changes */ public void setScrollLock(boolean scrollLock) { - fScrollLock=scrollLock; + fScrollLock = scrollLock; } + protected void repaintRange(int col, int line, int width, int height) { - Point origin=cellToOriginOnScreen(col,line); - Rectangle r=new Rectangle(origin.x,origin.y,width*getCellWidth(),height*getCellHeight()); + Point origin = cellToOriginOnScreen(col, line); + Rectangle r = new Rectangle(origin.x, origin.y, width * getCellWidth(), height * getCellHeight()); repaint(r); } + protected void drawLine(GC gc, int line, int x, int y, int colFirst, int colLast) { - fCellRenderer.drawLine(fCellCanvasModel, gc,line,x,y,colFirst, colLast); + fCellRenderer.drawLine(fCellCanvasModel, gc, line, x, y, colFirst, colLast); } + protected Color getTerminalBackgroundColor() { return fCellRenderer.getDefaultBackgroundColor(); } + protected void visibleCellRectangleChanged(int x, int y, int width, int height) { - fCellCanvasModel.setVisibleRectangle(y,x,height,width); + fCellCanvasModel.setVisibleRectangle(y, x, height, width); update(); } + protected int getCols() { return fCellCanvasModel.getTerminalText().getWidth(); } + protected int getRows() { return fCellCanvasModel.getTerminalText().getHeight(); } + public String getSelectionText() { // TODO -- create a hasSelectionMethod! return fCellCanvasModel.getSelectedText(); } + public void copy() { String selectionText = getSelectionText(); if (selectionText != null && selectionText.length() > 0) { @@ -372,16 +392,18 @@ public class TextCanvas extends GridCanvas { clipboard.dispose(); } } + public void selectAll() { - fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0, fCellCanvasModel.getTerminalText().getWidth()); - fCellCanvasModel.setSelectionAnchor(new Point(0,0)); + fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0, + fCellCanvasModel.getTerminalText().getWidth()); + fCellCanvasModel.setSelectionAnchor(new Point(0, 0)); } /** * @since 4.1 */ public void clearSelection() { - fCellCanvasModel.setSelection(-1,-1,-1,-1); + fCellCanvasModel.setSelection(-1, -1, -1, -1); } /** @@ -403,6 +425,7 @@ public class TextCanvas extends GridCanvas { public boolean isEmpty() { return false; } + /** * Gets notified when the visible size of the terminal changes. * This should update the model! @@ -411,23 +434,24 @@ public class TextCanvas extends GridCanvas { public interface ResizeListener { void sizeChanged(int lines, int columns); } + /** * @param listener this listener gets notified, when the size of * the widget changed. It should change the dimensions of the underlying * terminaldata */ public void addResizeHandler(ResizeListener listener) { - if(fResizeListener!=null) + if (fResizeListener != null) throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$ - fResizeListener=listener; + fResizeListener = listener; // Bug 281328: [terminal] The very first few characters might be missing in // the terminal control if opened and connected programmatically // // In case the terminal had not been visible yet or is too small (less than one // line visible), the terminal should have a minimum size to avoid RuntimeExceptions. - Rectangle bonds=getClientArea(); - if (bonds.height=getTerminalText().getHeight() || colFirst>=getTerminalText().getWidth() || colFirst-colLast==0) { - fillBackground(gc, x, y, getCellWidth()*(colLast-colFirst), getCellHeight()); + if (line < 0 || line >= getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth() + || colFirst - colLast == 0) { + fillBackground(gc, x, y, getCellWidth() * (colLast - colFirst), getCellHeight()); } else { - colLast=Math.min(colLast, getTerminalText().getWidth()); - LineSegment[] segments=getTerminalText().getLineSegments(line, colFirst, colLast-colFirst); + colLast = Math.min(colLast, getTerminalText().getWidth()); + LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst); for (int i = 0; i < segments.length; i++) { - LineSegment segment=segments[i]; - Style style=segment.getStyle(); + LineSegment segment = segments[i]; + Style style = segment.getStyle(); setupGC(gc, style); - String text=segment.getText(); + String text = segment.getText(); drawText(gc, x, y, colFirst, segment.getColumn(), text); drawCursor(model, gc, line, x, y, colFirst); } - if(fModel.hasLineSelection(line)) { + if (fModel.hasLineSelection(line)) { gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)); gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION)); - Point start=model.getSelectionStart(); - Point end=model.getSelectionEnd(); - char[] chars=model.getTerminalText().getChars(line); - if(chars==null) + Point start = model.getSelectionStart(); + Point end = model.getSelectionEnd(); + char[] chars = model.getTerminalText().getChars(line); + if (chars == null) return; - int offset=0; - if(start.y==line) - offset=start.x; - offset=Math.max(offset, colFirst); + int offset = 0; + if (start.y == line) + offset = start.x; + offset = Math.max(offset, colFirst); int len; - if(end.y==line) - len=end.x-offset+1; + if (end.y == line) + len = end.x - offset + 1; else - len=chars.length-offset+1; - len=Math.min(len,chars.length-offset); - if(len>0) { - String text=new String(chars,offset,len); + len = chars.length - offset + 1; + len = Math.min(len, chars.length - offset); + if (len > 0) { + String text = new String(chars, offset, len); drawText(gc, x, y, colFirst, offset, text); } } @@ -88,9 +93,9 @@ public class TextLineRenderer implements ILinelRenderer { } private void fillBackground(GC gc, int x, int y, int width, int height) { - Color bg=gc.getBackground(); + Color bg = gc.getBackground(); gc.setBackground(getDefaultBackgroundColor()); - gc.fillRectangle (x,y,width,height); + gc.fillRectangle(x, y, width, height); gc.setBackground(bg); } @@ -99,70 +104,76 @@ public class TextLineRenderer implements ILinelRenderer { // null == default style return fStyleMap.getBackgroundColor(null); } - - private void drawCursor(ITextCanvasModel model, GC gc, int row, int x, int y, int colFirst) { - if(!model.isCursorOn()) - return; - int cursorLine=model.getCursorLine(); - if(row==cursorLine) { - int cursorColumn=model.getCursorColumn(); - if(cursorColumn0||marginHeight>0){ - Color bg=getBackground(); + int width = fVirtualBounds.width + fVirtualBounds.x; + int height = fVirtualBounds.height + fVirtualBounds.y; + int marginWidth = (clipping.x + clipping.width) - width; + int marginHeight = (clipping.y + clipping.height) - height; + if (marginWidth > 0 || marginHeight > 0) { + Color bg = getBackground(); gc.setBackground(getTerminalBackgroundColor()); if (marginWidth > 0) { - gc.fillRectangle (width, clipping.y, marginWidth, clipping.height); + gc.fillRectangle(width, clipping.y, marginWidth, clipping.height); } if (marginHeight > 0) { - gc.fillRectangle (clipping.x, height, clipping.width, marginHeight); + gc.fillRectangle(clipping.x, height, clipping.width, marginHeight); } gc.setBackground(bg); } } + /** * @private */ protected boolean inClipping(Rectangle clipping, Rectangle r) { // TODO check if this is OK in all cases (the <=!) - // - if(r.x+r.width<=clipping.x) + // + if (r.x + r.width <= clipping.x) return false; - if(clipping.x+clipping.width<=r.x) + if (clipping.x + clipping.width <= r.x) return false; - if(r.y+r.height<=clipping.y) + if (r.y + r.height <= clipping.y) return false; - if(clipping.y+clipping.height<=r.y) + if (clipping.y + clipping.height <= r.y) return false; - + return true; } + /** * @return the screen rect in virtual space (starting with (0,0)) * of the visible screen. (x,y>=0) */ protected Rectangle getScreenRectInVirtualSpace() { - Rectangle r= new Rectangle(fClientArea.x-fVirtualBounds.x,fClientArea.y-fVirtualBounds.y,fClientArea.width,fClientArea.height); + Rectangle r = new Rectangle(fClientArea.x - fVirtualBounds.x, fClientArea.y - fVirtualBounds.y, + fClientArea.width, fClientArea.height); return r; } + /** * @return the rect in virtual space (starting with (0,0)) * of the visible screen. (x,y>=0) */ protected Rectangle getRectInVirtualSpace(Rectangle r) { - return new Rectangle(r.x-fVirtualBounds.x,r.y-fVirtualBounds.y,r.width,r.height); + return new Rectangle(r.x - fVirtualBounds.x, r.y - fVirtualBounds.y, r.width, r.height); } - + /** * Sets the extent of the virtual display area * @param width width of the display area * @param height height of the display area */ protected void setVirtualExtend(int width, int height) { - fVirtualBounds.width=width; - fVirtualBounds.height=height; + fVirtualBounds.width = width; + fVirtualBounds.height = height; updateScrollbars(); updateViewRectangle(); } + /** * sets the scrolling origin. Also sets the scrollbars. * Does NOT redraw! @@ -227,54 +236,60 @@ public abstract class VirtualCanvas extends Canvas { */ protected void setVirtualOrigin(int x, int y) { if (fVirtualBounds.x != x || fVirtualBounds.y != y) { - fVirtualBounds.x=x; - fVirtualBounds.y=y; + fVirtualBounds.x = x; + fVirtualBounds.y = y; getHorizontalBar().setSelection(-x); getVerticalBar().setSelection(-y); updateViewRectangle(); } } + protected Rectangle getVirtualBounds() { return cloneRectangle(fVirtualBounds); } + /** * @param x * @return the virtual coordinate in screen space */ protected int virtualXtoScreen(int x) { - return x+fVirtualBounds.x; + return x + fVirtualBounds.x; } + protected int virtualYtoScreen(int y) { - return y+fVirtualBounds.y; + return y + fVirtualBounds.y; } + protected int screenXtoVirtual(int x) { - return x-fVirtualBounds.x; + return x - fVirtualBounds.x; } + protected int screenYtoVirtual(int y) { - return y-fVirtualBounds.y; + return y - fVirtualBounds.y; } + /** called when the viewed part is changing */ - private final Rectangle fViewRectangle=new Rectangle(0,0,0,0); + private final Rectangle fViewRectangle = new Rectangle(0, 0, 0, 0); + protected void updateViewRectangle() { - if( - fViewRectangle.x==-fVirtualBounds.x - && fViewRectangle.y==-fVirtualBounds.y - && fViewRectangle.width==fClientArea.width - && fViewRectangle.height==fClientArea.height - ) + if (fViewRectangle.x == -fVirtualBounds.x && fViewRectangle.y == -fVirtualBounds.y + && fViewRectangle.width == fClientArea.width && fViewRectangle.height == fClientArea.height) return; - fViewRectangle.x=-fVirtualBounds.x; - fViewRectangle.y=-fVirtualBounds.y; - fViewRectangle.width=fClientArea.width; - fViewRectangle.height=fClientArea.height; - viewRectangleChanged(fViewRectangle.x,fViewRectangle.y,fViewRectangle.width,fViewRectangle.height); + fViewRectangle.x = -fVirtualBounds.x; + fViewRectangle.y = -fVirtualBounds.y; + fViewRectangle.width = fClientArea.width; + fViewRectangle.height = fClientArea.height; + viewRectangleChanged(fViewRectangle.x, fViewRectangle.y, fViewRectangle.width, fViewRectangle.height); } + protected Rectangle getViewRectangle() { return cloneRectangle(fViewRectangle); } + private Rectangle cloneRectangle(Rectangle r) { - return new Rectangle(r.x,r.y,r.width,r.height); + return new Rectangle(r.x, r.y, r.width, r.height); } + /** * Called when the viewed part has changed. * Override when you need this information.... @@ -286,63 +301,69 @@ public abstract class VirtualCanvas extends Canvas { */ protected void viewRectangleChanged(int x, int y, int width, int height) { } + /** * @private */ private void updateScrollbars() { // don't get into infinite loops.... - if(!fInUpdateScrollbars) { - fInUpdateScrollbars=true; + if (!fInUpdateScrollbars) { + fInUpdateScrollbars = true; try { doUpdateScrollbar(); } finally { - fInUpdateScrollbars=false; + fInUpdateScrollbars = false; } } else { - if(!fInUpdateScrollbarsLogged) { - fInUpdateScrollbarsLogged=true; - TerminalPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, - TerminalPlugin.PLUGIN_ID, IStatus.OK, "Unexpected Recursion in terminal", //$NON-NLS-1$ - new RuntimeException())); + if (!fInUpdateScrollbarsLogged) { + fInUpdateScrollbarsLogged = true; + TerminalPlugin.getDefault().getLog() + .log(new Status(IStatus.WARNING, TerminalPlugin.PLUGIN_ID, IStatus.OK, + "Unexpected Recursion in terminal", //$NON-NLS-1$ + new RuntimeException())); } } } + private void doUpdateScrollbar() { - Rectangle clientArea= getClientArea(); - ScrollBar horizontal= getHorizontalBar(); + Rectangle clientArea = getClientArea(); + ScrollBar horizontal = getHorizontalBar(); // even if setVisible was called on the scrollbar, isVisible - // returns false if its parent is not visible. - if(!isVisible() || horizontal.isVisible()) { + // returns false if its parent is not visible. + if (!isVisible() || horizontal.isVisible()) { horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement()); - int max= fVirtualBounds.width; + int max = fVirtualBounds.width; horizontal.setMaximum(max); horizontal.setThumb(clientArea.width); } - ScrollBar vertical= getVerticalBar(); + ScrollBar vertical = getVerticalBar(); // even if setVisible was called on the scrollbar, isVisible - // returns false if its parent is not visible. - if(!isVisible() || vertical.isVisible()) { + // returns false if its parent is not visible. + if (!isVisible() || vertical.isVisible()) { vertical.setPageIncrement(clientArea.height - vertical.getIncrement()); - int max= fVirtualBounds.height; + int max = fVirtualBounds.height; vertical.setMaximum(max); vertical.setThumb(clientArea.height); } } + protected boolean isVertialBarVisible() { return getVerticalBar().isVisible(); } + protected void serVerticalBarVisible(boolean showVScrollBar) { - ScrollBar vertical= getVerticalBar(); + ScrollBar vertical = getVerticalBar(); vertical.setVisible(showVScrollBar); vertical.setSelection(0); } + protected boolean isHorizontalBarVisble() { return getHorizontalBar().isVisible(); } + protected void setHorizontalBarVisible(boolean showHScrollBar) { - ScrollBar horizontal= getHorizontalBar(); + ScrollBar horizontal = getHorizontalBar(); horizontal.setVisible(showHScrollBar); horizontal.setSelection(0); } } - diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextData.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextData.java index 83e5e9568e1..37a85731e45 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextData.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextData.java @@ -37,6 +37,7 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly { void setDimensions(int height, int width); void setMaxHeight(int height); + int getMaxHeight(); /** @@ -68,7 +69,6 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly { */ void setChars(int line, int column, char[] chars, int start, int len, Style style); - /** * Cleans the entire line. * @param line @@ -116,18 +116,21 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly { * will be scrolled. Else a line will be added. */ void addLine(); + /** * Copies the entire source into this and changes the size accordingly * @param source */ void copy(ITerminalTextData source); + /** * Copy a sourceLine from source to this at destLine. * @param source * @param sourceLine * @param destLine */ - void copyLine(ITerminalTextData source,int sourceLine, int destLine); + void copyLine(ITerminalTextData source, int sourceLine, int destLine); + /** * Copy length lines from source starting at sourceLine into this starting at * destLine. @@ -136,13 +139,14 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly { * @param destStartLine * @param length */ - void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine,int length); + void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length); void setCursorLine(int line); + void setCursorColumn(int column); /** - * Makes this line a wrapped line which logically continues on next line. + * Makes this line a wrapped line which logically continues on next line. * * @param line * @since 3.3 diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataReadOnly.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataReadOnly.java index 21a4870caaf..d935b409a71 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataReadOnly.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataReadOnly.java @@ -66,12 +66,14 @@ public interface ITerminalTextDataReadOnly { public ITerminalTextDataSnapshot makeSnapshot(); char[] getChars(int line); + Style[] getStyles(int line); /** * @return the line in which the cursor is at the moment */ int getCursorLine(); + /** * @return the column at which the cursor is at the moment */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataSnapshot.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataSnapshot.java index 47c7ee4cb57..24752f8fc32 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataSnapshot.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/ITerminalTextDataSnapshot.java @@ -108,7 +108,9 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly { */ void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot); } + void addListener(SnapshotOutOfDateListener listener); + void removeListener(SnapshotOutOfDateListener listener); /** @@ -116,6 +118,7 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly { * has been called no new snapshot data is collected. */ void detach(); + /** * @return true if the data has changed since the previous snapshot. */ @@ -129,7 +132,9 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly { * @param size number of lines to track. A size of -1 means track all. */ void setInterestWindow(int startLine, int size); + int getInterestWindowStartLine(); + int getInterestWindowSize(); /** @@ -195,6 +200,7 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly { * window of interest) */ boolean hasTerminalChanged(); + /** * If {@link #updateSnapshot(boolean)} was called with true, then this method * returns the top of the scroll region. diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/LineSegment.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/LineSegment.java index 7381d0e6439..15e4121de58 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/LineSegment.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/LineSegment.java @@ -1,35 +1,39 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; - public class LineSegment { private final String fText; private final int fCol; private final Style fStyle; + public LineSegment(int col, String text, Style style) { fCol = col; fText = text; fStyle = style; } + public Style getStyle() { return fStyle; } + public String getText() { return fText; } + public int getColumn() { return fCol; } + public String toString() { - return "LineSegment("+fCol+", \""+fText+"\","+fStyle+")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return "LineSegment(" + fCol + ", \"" + fText + "\"," + fStyle + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } \ No newline at end of file diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/Style.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/Style.java index fa7be137653..8c348918ec2 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/Style.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/Style.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; @@ -17,7 +17,7 @@ import java.util.Map; * @author scharf * Flyweight * Threadsafe. - * + * */ // TODO add an Object for user data, use weak map to keep track of styles with associated // user data @@ -28,8 +28,10 @@ public class Style { private final boolean fBlink; private final boolean fUnderline; private final boolean fReverse; - private final static Map fgStyles=new HashMap(); - private Style(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline, boolean reverse) { + private final static Map fgStyles = new HashMap(); + + private Style(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline, + boolean reverse) { fForground = forground; fBackground = background; fBold = bold; @@ -37,66 +39,86 @@ public class Style { fUnderline = underline; fReverse = reverse; } - public static Style getStyle(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline, boolean reverse) { - Style style = new Style(forground,background, bold, blink,underline,reverse); + + public static Style getStyle(StyleColor forground, StyleColor background, boolean bold, boolean blink, + boolean underline, boolean reverse) { + Style style = new Style(forground, background, bold, blink, underline, reverse); Style cached; synchronized (fgStyles) { - cached=fgStyles.get(style); - if(cached==null) { - cached=style; + cached = fgStyles.get(style); + if (cached == null) { + cached = style; fgStyles.put(cached, cached); } } return cached; } + public static Style getStyle(String forground, String background) { - return getStyle(StyleColor.getStyleColor(forground), StyleColor.getStyleColor(background),false,false,false,false); + return getStyle(StyleColor.getStyleColor(forground), StyleColor.getStyleColor(background), false, false, false, + false); } + public static Style getStyle(StyleColor forground, StyleColor background) { - return getStyle(forground, background,false,false,false,false); + return getStyle(forground, background, false, false, false, false); } + public Style setForground(StyleColor forground) { - return getStyle(forground,fBackground,fBold,fBlink,fUnderline,fReverse); + return getStyle(forground, fBackground, fBold, fBlink, fUnderline, fReverse); } + public Style setBackground(StyleColor background) { - return getStyle(fForground,background,fBold,fBlink,fUnderline,fReverse); + return getStyle(fForground, background, fBold, fBlink, fUnderline, fReverse); } + public Style setForground(String colorName) { - return getStyle(StyleColor.getStyleColor(colorName),fBackground,fBold,fBlink,fUnderline,fReverse); + return getStyle(StyleColor.getStyleColor(colorName), fBackground, fBold, fBlink, fUnderline, fReverse); } + public Style setBackground(String colorName) { - return getStyle(fForground,StyleColor.getStyleColor(colorName),fBold,fBlink,fUnderline,fReverse); + return getStyle(fForground, StyleColor.getStyleColor(colorName), fBold, fBlink, fUnderline, fReverse); } + public Style setBold(boolean bold) { - return getStyle(fForground,fBackground,bold,fBlink,fUnderline,fReverse); + return getStyle(fForground, fBackground, bold, fBlink, fUnderline, fReverse); } + public Style setBlink(boolean blink) { - return getStyle(fForground,fBackground,fBold,blink,fUnderline,fReverse); + return getStyle(fForground, fBackground, fBold, blink, fUnderline, fReverse); } + public Style setUnderline(boolean underline) { - return getStyle(fForground,fBackground,fBold,fBlink,underline,fReverse); + return getStyle(fForground, fBackground, fBold, fBlink, underline, fReverse); } + public Style setReverse(boolean reverse) { - return getStyle(fForground,fBackground,fBold,fBlink,fUnderline,reverse); + return getStyle(fForground, fBackground, fBold, fBlink, fUnderline, reverse); } + public StyleColor getBackground() { return fBackground; } + public boolean isBlink() { return fBlink; } + public boolean isBold() { return fBold; } + public StyleColor getForground() { return fForground; } + public boolean isReverse() { return fReverse; } + public boolean isUnderline() { return fUnderline; } + public int hashCode() { final int prime = 31; int result = 1; @@ -108,6 +130,7 @@ public class Style { result = prime * result + (fUnderline ? 1231 : 1237); return result; } + public boolean equals(Object obj) { if (this == obj) return true; @@ -131,24 +154,25 @@ public class Style { return false; return true; } + public String toString() { - StringBuffer result=new StringBuffer(); + StringBuffer result = new StringBuffer(); result.append("Style(foreground="); //$NON-NLS-1$ result.append(fForground); result.append(", background="); //$NON-NLS-1$ result.append(fBackground); - if(fBlink) + if (fBlink) result.append(", blink"); //$NON-NLS-1$ - if(fBold) + if (fBold) result.append(", bold"); //$NON-NLS-1$ - if(fBlink) + if (fBlink) result.append(", blink"); //$NON-NLS-1$ - if(fReverse) + if (fReverse) result.append(", reverse"); //$NON-NLS-1$ - if(fUnderline) + if (fUnderline) result.append(", underline"); //$NON-NLS-1$ result.append(")"); //$NON-NLS-1$ return result.toString(); } - + } \ No newline at end of file diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/StyleColor.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/StyleColor.java index 10e1ed55096..64c765f0b1d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/StyleColor.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/StyleColor.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; @@ -13,15 +13,15 @@ package org.eclipse.tm.terminal.model; import java.util.HashMap; import java.util.Map; -/** - * +/** + * * Flyweight * Threadsafe. */ public class StyleColor { - private final static Map fgStyleColors=new HashMap(); + private final static Map fgStyleColors = new HashMap(); final String fName; - + /** * @param name the name of the color. It is up to the UI to associate a * named color with a visual representation @@ -30,14 +30,15 @@ public class StyleColor { public static StyleColor getStyleColor(String name) { StyleColor result; synchronized (fgStyleColors) { - result=fgStyleColors.get(name); - if(result==null) { - result=new StyleColor(name); + result = fgStyleColors.get(name); + if (result == null) { + result = new StyleColor(name); fgStyleColors.put(name, result); } } return result; } + // nobody except the factory method is allowed to instantiate this class! private StyleColor(String name) { fName = name; diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/TerminalTextDataFactory.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/TerminalTextDataFactory.java index 2877c4d0631..25729aa3426 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/TerminalTextDataFactory.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/terminal/model/TerminalTextDataFactory.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java index 0edbe8b80b6..abba75c50b9 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java @@ -43,6 +43,7 @@ public class TerminalConnectorFactoryTest extends TestCase { } } + public static class TerminalControlMock implements ITerminalControl { public void setEncoding(String encoding) { @@ -78,11 +79,11 @@ public class TerminalConnectorFactoryTest extends TestCase { public void setupTerminal(Composite parent) { } - + public boolean isConnectOnEnterIfClosed() { return false; } - + public void setConnectOnEnterIfClosed(boolean on) { } @@ -93,6 +94,7 @@ public class TerminalConnectorFactoryTest extends TestCase { return false; } } + static class ConnectorMock extends TerminalConnectorImpl { public boolean fEcho; @@ -106,16 +108,19 @@ public class TerminalConnectorFactoryTest extends TestCase { public boolean isLocalEcho() { return fEcho; } + public void setTerminalSize(int newWidth, int newHeight) { - fWidth=newWidth; - fHeight=newHeight; + fWidth = newWidth; + fHeight = newHeight; } + public void connect(ITerminalControl control) { super.connect(control); fTerminalControl = control; } + public void doDisconnect() { - fDisconnect=true; + fDisconnect = true; } public OutputStream getTerminalToRemoteStream() { @@ -127,48 +132,50 @@ public class TerminalConnectorFactoryTest extends TestCase { } public void load(ISettingsStore store) { - fLoadStore=store; + fLoadStore = store; } public void save(ISettingsStore store) { - fSaveStore=store; + fSaveStore = store; } } + protected TerminalConnector makeTerminalConnector() { return makeTerminalConnector(new ConnectorMock()); } protected TerminalConnector makeTerminalConnector(final TerminalConnectorImpl mock) { - TerminalConnector c=new TerminalConnector(new TerminalConnector.Factory(){ + TerminalConnector c = new TerminalConnector(new TerminalConnector.Factory() { public TerminalConnectorImpl makeConnector() throws Exception { return mock; } - },"xID","xName", false); + }, "xID", "xName", false); return c; } public void testGetInitializationErrorMessage() { - TerminalConnector c=makeTerminalConnector(); + TerminalConnector c = makeTerminalConnector(); c.connect(new TerminalControlMock()); assertNull(c.getInitializationErrorMessage()); - c=makeTerminalConnector(new ConnectorMock(){ + c = makeTerminalConnector(new ConnectorMock() { public void initialize() throws Exception { throw new Exception("FAILED"); - }}); + } + }); c.connect(new TerminalControlMock()); - assertEquals("FAILED",c.getInitializationErrorMessage()); + assertEquals("FAILED", c.getInitializationErrorMessage()); } public void testGetIdAndName() { - TerminalConnector c=makeTerminalConnector(); + TerminalConnector c = makeTerminalConnector(); assertEquals("xID", c.getId()); assertEquals("xName", c.getName()); } public void testIsInitialized() { - TerminalConnector c=makeTerminalConnector(); + TerminalConnector c = makeTerminalConnector(); assertFalse(c.isInitialized()); c.getId(); assertFalse(c.isInitialized()); @@ -176,19 +183,20 @@ public class TerminalConnectorFactoryTest extends TestCase { assertFalse(c.isInitialized()); c.getSettingsSummary(); assertFalse(c.isInitialized()); - c.setTerminalSize(10,10); + c.setTerminalSize(10, 10); assertFalse(c.isInitialized()); c.load(null); assertFalse(c.isInitialized()); c.save(null); assertFalse(c.isInitialized()); - if (!Platform.isRunning()) return; + if (!Platform.isRunning()) + return; c.getAdapter(ConnectorMock.class); assertFalse(c.isInitialized()); } public void testConnect() { - TerminalConnector c=makeTerminalConnector(); + TerminalConnector c = makeTerminalConnector(); assertFalse(c.isInitialized()); c.connect(new TerminalControlMock()); assertTrue(c.isInitialized()); @@ -196,74 +204,76 @@ public class TerminalConnectorFactoryTest extends TestCase { } public void testDisconnect() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); - TerminalControlMock control=new TerminalControlMock(); + TerminalControlMock control = new TerminalControlMock(); c.connect(control); c.disconnect(); assertTrue(mock.fDisconnect); } public void testGetTerminalToRemoteStream() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); - TerminalControlMock control=new TerminalControlMock(); + TerminalControlMock control = new TerminalControlMock(); c.connect(control); - assertSame(mock.fTerminalControl,control); + assertSame(mock.fTerminalControl, control); } + public void testGetSettingsSummary() { - TerminalConnector c=makeTerminalConnector(); + TerminalConnector c = makeTerminalConnector(); assertEquals("Not Initialized", c.getSettingsSummary()); c.connect(new TerminalControlMock()); assertEquals("Summary", c.getSettingsSummary()); } public void testIsLocalEcho() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); assertFalse(c.isLocalEcho()); - mock.fEcho=true; + mock.fEcho = true; assertTrue(c.isLocalEcho()); } public void testLoad() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); - ISettingsStore s=new SettingsMock(); + ISettingsStore s = new SettingsMock(); c.load(s); // the load is called after the connect... assertNull(mock.fLoadStore); c.connect(new TerminalControlMock()); - assertSame(s,mock.fLoadStore); + assertSame(s, mock.fLoadStore); } public void testSave() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); - ISettingsStore s=new SettingsMock(); + ISettingsStore s = new SettingsMock(); c.save(s); assertNull(mock.fSaveStore); c.connect(new TerminalControlMock()); c.save(s); - assertSame(s,mock.fSaveStore); + assertSame(s, mock.fSaveStore); } public void testSetDefaultSettings() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); c.setDefaultSettings(); } public void testSetTerminalSize() { - ConnectorMock mock=new ConnectorMock(); + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); c.setTerminalSize(100, 200); } public void testGetAdapter() { - if (!Platform.isRunning()) return; - ConnectorMock mock=new ConnectorMock(); + if (!Platform.isRunning()) + return; + ConnectorMock mock = new ConnectorMock(); TerminalConnector c = makeTerminalConnector(mock); assertNull(c.getAdapter(ConnectorMock.class)); // the load is called after the connect... diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java index c44d936135a..8cf89c6b692 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java @@ -43,6 +43,7 @@ public class TerminalConnectorTest extends TestCase { } } + public static class TerminalControlMock implements ITerminalControl { public void setEncoding(String encoding) { @@ -78,11 +79,11 @@ public class TerminalConnectorTest extends TestCase { public void setupTerminal(Composite parent) { } - + public boolean isConnectOnEnterIfClosed() { return false; } - + public void setConnectOnEnterIfClosed(boolean on) { } @@ -93,6 +94,7 @@ public class TerminalConnectorTest extends TestCase { return false; } } + static class ConnectorMock extends TerminalConnectorImpl { public boolean fEcho; @@ -106,16 +108,19 @@ public class TerminalConnectorTest extends TestCase { public boolean isLocalEcho() { return fEcho; } + public void setTerminalSize(int newWidth, int newHeight) { - fWidth=newWidth; - fHeight=newHeight; + fWidth = newWidth; + fHeight = newHeight; } + public void connect(ITerminalControl control) { super.connect(control); fTerminalControl = control; } + public void doDisconnect() { - fDisconnect=true; + fDisconnect = true; } public OutputStream getTerminalToRemoteStream() { @@ -127,45 +132,50 @@ public class TerminalConnectorTest extends TestCase { } public void load(ISettingsStore store) { - fLoadStore=store; + fLoadStore = store; } public void save(ISettingsStore store) { - fSaveStore=store; + fSaveStore = store; } } + static class SimpleFactory implements Factory { final TerminalConnectorImpl fConnector; + public SimpleFactory(TerminalConnectorImpl connector) { fConnector = connector; } + public TerminalConnectorImpl makeConnector() throws Exception { // TODO Auto-generated method stub return fConnector; } } + public void testGetInitializationErrorMessage() { - TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false); + TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false); c.connect(new TerminalControlMock()); assertNull(c.getInitializationErrorMessage()); - c=new TerminalConnector(new SimpleFactory(new ConnectorMock(){ + c = new TerminalConnector(new SimpleFactory(new ConnectorMock() { public void initialize() throws Exception { throw new Exception("FAILED"); - }}),"xID","xName", false); + } + }), "xID", "xName", false); c.connect(new TerminalControlMock()); - assertEquals("FAILED",c.getInitializationErrorMessage()); + assertEquals("FAILED", c.getInitializationErrorMessage()); } public void testGetIdAndName() { - TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false); + TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false); assertEquals("xID", c.getId()); assertEquals("xName", c.getName()); } public void testConnect() { - TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false); + TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false); assertFalse(c.isInitialized()); c.connect(new TerminalControlMock()); assertTrue(c.isInitialized()); @@ -173,68 +183,68 @@ public class TerminalConnectorTest extends TestCase { } public void testDisconnect() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); - TerminalControlMock control=new TerminalControlMock(); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); + TerminalControlMock control = new TerminalControlMock(); c.connect(control); c.disconnect(); assertTrue(mock.fDisconnect); } public void testGetTerminalToRemoteStream() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); - TerminalControlMock control=new TerminalControlMock(); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); + TerminalControlMock control = new TerminalControlMock(); c.connect(control); - assertSame(mock.fTerminalControl,control); + assertSame(mock.fTerminalControl, control); } public void testGetSettingsSummary() { - TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false); + TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false); assertEquals("Not Initialized", c.getSettingsSummary()); c.connect(new TerminalControlMock()); assertEquals("Summary", c.getSettingsSummary()); } public void testIsLocalEcho() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); assertFalse(c.isLocalEcho()); - mock.fEcho=true; + mock.fEcho = true; assertTrue(c.isLocalEcho()); } public void testLoad() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); - ISettingsStore s=new SettingsMock(); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); + ISettingsStore s = new SettingsMock(); c.load(s); // the load is called after the connect... assertNull(mock.fLoadStore); c.connect(new TerminalControlMock()); - assertSame(s,mock.fLoadStore); + assertSame(s, mock.fLoadStore); } public void testSave() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); - ISettingsStore s=new SettingsMock(); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); + ISettingsStore s = new SettingsMock(); c.save(s); assertNull(mock.fSaveStore); c.connect(new TerminalControlMock()); c.save(s); - assertSame(s,mock.fSaveStore); + assertSame(s, mock.fSaveStore); } public void testSetDefaultSettings() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); c.setDefaultSettings(); } public void testSetTerminalSize() { - ConnectorMock mock=new ConnectorMock(); - TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false); + ConnectorMock mock = new ConnectorMock(); + TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false); c.setTerminalSize(100, 200); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStreamTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStreamTest.java index da374dee490..a2418f30da0 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStreamTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalToRemoteInjectionOutputStreamTest.java @@ -20,7 +20,8 @@ import java.io.UnsupportedEncodingException; import junit.framework.TestCase; public class TerminalToRemoteInjectionOutputStreamTest extends TestCase { - final static String ENCODING="UTF-8"; + final static String ENCODING = "UTF-8"; + /** * This class escapes strings coming on the original * terminal.. @@ -30,26 +31,30 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase { public void close() throws IOException { } + public void write(int b) throws IOException { fOriginal.write('['); fOriginal.write(b); fOriginal.write(']'); } + public void write(byte[] b, int off, int len) throws IOException { fOriginal.write('['); - fOriginal.write(b,off,len); + fOriginal.write(b, off, len); fOriginal.write(']'); } } + class NullInterceptor extends TerminalToRemoteInjectionOutputStream.Interceptor { } + public void testClose() throws UnsupportedEncodingException, IOException { - ByteArrayOutputStream bs=new ByteArrayOutputStream(); - TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs); s.write("begin:".getBytes(ENCODING)); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); - OutputStream os1=s.grabOutput(); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); + OutputStream os1 = s.grabOutput(); os1.write('x'); s.write('A'); os1.write('y'); @@ -57,7 +62,7 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase { os1.close(); s.write('-'); - OutputStream os=s.grabOutput(); + OutputStream os = s.grabOutput(); // make sure the closed output does not inject anything try { os1.write('k'); @@ -75,24 +80,24 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase { } s.write('b'); os.close(); - assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(), ENCODING)); } public void testFlush() { } public void testWriteInt() throws UnsupportedEncodingException, IOException { - ByteArrayOutputStream bs=new ByteArrayOutputStream(); - TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs); s.write("begin:".getBytes(ENCODING)); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); - OutputStream os=s.grabOutput(); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); + OutputStream os = s.grabOutput(); os.write('x'); s.write('A'); os.write('y'); s.write('B'); s.close(); - assertEquals("begin:xyAB", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:xyAB", new String(bs.toByteArray(), ENCODING)); } @@ -101,76 +106,79 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase { public void testWriteByteArrayIntInt() { } + public void testGrabOutput() throws UnsupportedEncodingException, IOException { - ByteArrayOutputStream bs=new ByteArrayOutputStream(); - TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs); s.write("begin:".getBytes(ENCODING)); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); - OutputStream os1=s.grabOutput(); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); + OutputStream os1 = s.grabOutput(); OutputStream os2; try { - os2=s.grabOutput(); + os2 = s.grabOutput(); fail("should fail until the foirst output is closed"); } catch (IOException e) { } os1.close(); - os2=s.grabOutput(); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); + os2 = s.grabOutput(); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); os2.write("Test".getBytes(ENCODING)); - assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING)); s.write(" west".getBytes(ENCODING)); - assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING)); os2.write(" the".getBytes(ENCODING)); - assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING)); os2.close(); - assertEquals("begin:Test the west", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the west", new String(bs.toByteArray(), ENCODING)); s.write('!'); - assertEquals("begin:Test the west!", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the west!", new String(bs.toByteArray(), ENCODING)); } + public void testGrabOutputWithCleverInterceptor() throws UnsupportedEncodingException, IOException { - ByteArrayOutputStream bs=new ByteArrayOutputStream(); - TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs); s.write("begin:".getBytes(ENCODING)); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); // the injector escapes the output coming from the main stream - OutputStream os=s.grabOutput(new CleverInterceptor()); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); + OutputStream os = s.grabOutput(new CleverInterceptor()); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); os.write("Test".getBytes(ENCODING)); - assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING)); s.write(" west".getBytes(ENCODING)); - assertEquals("begin:Test[ west]", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test[ west]", new String(bs.toByteArray(), ENCODING)); os.write(" the".getBytes(ENCODING)); - assertEquals("begin:Test[ west] the", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test[ west] the", new String(bs.toByteArray(), ENCODING)); s.write('x'); - assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING)); os.close(); - assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING)); s.write('!'); - assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(), ENCODING)); } + public void testGrabOutputWithNullInterceptor() throws UnsupportedEncodingException, IOException { - ByteArrayOutputStream bs=new ByteArrayOutputStream(); - TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs); s.write("begin:".getBytes(ENCODING)); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); // bytes written to the main stream are ignored while the injector // is active - OutputStream os=s.grabOutput(new NullInterceptor()); - assertEquals("begin:", new String(bs.toByteArray(),ENCODING)); + OutputStream os = s.grabOutput(new NullInterceptor()); + assertEquals("begin:", new String(bs.toByteArray(), ENCODING)); os.write("Test".getBytes(ENCODING)); - assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING)); s.write(" west".getBytes(ENCODING)); - assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING)); os.write(" the".getBytes(ENCODING)); - assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING)); s.write('x'); - assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING)); os.close(); - assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING)); s.write('!'); - assertEquals("begin:Test the!", new String(bs.toByteArray(),ENCODING)); + assertEquals("begin:Test the!", new String(bs.toByteArray(), ENCODING)); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/AllTests.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/AllTests.java index 11b6b283f3b..e1ec7baeff3 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/AllTests.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/AllTests.java @@ -17,7 +17,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * Terminal emulator test cases. + * Terminal emulator test cases. * Runs in emulator package to allow access to default visible items. */ public class AllTests extends TestCase { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java index e90adb7f22b..81f93c9c063 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java @@ -37,66 +37,56 @@ public class VT100EmulatorBackendTest extends TestCase { protected String toSimple(ITerminalTextData term) { return TerminalTextTestHelper.toSimple(term); } + protected String toMultiLineText(ITerminalTextDataReadOnly term) { return TerminalTextTestHelper.toMultiLineText(term); } protected void fill(ITerminalTextData term, String s) { - TerminalTextTestHelper.fill(term,s); + TerminalTextTestHelper.fill(term, s); } protected void fillSimple(ITerminalTextData term, String s) { TerminalTextTestHelper.fillSimple(term, s); } - /** * Used for multi line text * @param expected * @param actual */ - protected void assertEqualsTerm(String expected,String actual) { + protected void assertEqualsTerm(String expected, String actual) { assertEquals(expected.replace(' ', '.'), actual.replace('\000', '.')); } + /** * Used for simple text * @param expected * @param actual */ - protected void assertEqualsSimple(String expected,String actual) { - assertEquals(-1,actual.indexOf('\n')); + protected void assertEqualsSimple(String expected, String actual) { + assertEquals(-1, actual.indexOf('\n')); assertEquals(expected, actual); } + public void testClearAll() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - fill(term, "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"); + fill(term, "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"); vt100.clearAll(); - assertEqualsTerm( - " \n" + - " \n" + - " ",toMultiLineText(term)); + assertEqualsTerm(" \n" + " \n" + " ", toMultiLineText(term)); } + public void testSetDimensions() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - String s = "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"; + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + String s = "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"; fill(term, s); vt100.setDimensions(3, 4); - assertEquals(3,vt100.getLines()); - assertEquals(4,vt100.getColumns()); - assertEqualsTerm(s,toMultiLineText(term)); + assertEquals(3, vt100.getLines()); + assertEquals(4, vt100.getColumns()); + assertEqualsTerm(s, toMultiLineText(term)); vt100.setCursor(0, 2); vt100.setDimensions(2, 4); @@ -108,7 +98,7 @@ public class VT100EmulatorBackendTest extends TestCase { assertEquals(3, vt100.getCursorLine()); assertEquals(2, vt100.getCursorColumn()); - assertEqualsTerm(s,toMultiLineText(term)); + assertEqualsTerm(s, toMultiLineText(term)); vt100.setCursor(0, 3); vt100.setDimensions(5, 2); @@ -117,1131 +107,685 @@ public class VT100EmulatorBackendTest extends TestCase { } public void testToAbsoluteLine() { - ITerminalTextData term=makeITerminalTextData(); - VT100EmulatorBackend vt100=new VT100EmulatorBackend(term); + ITerminalTextData term = makeITerminalTextData(); + VT100EmulatorBackend vt100 = new VT100EmulatorBackend(term); vt100.setDimensions(2, 3); - assertEquals(vt100.toAbsoluteLine(0),0); + assertEquals(vt100.toAbsoluteLine(0), 0); // TODO - term=makeITerminalTextData(); - vt100=new VT100EmulatorBackend(term); + term = makeITerminalTextData(); + vt100 = new VT100EmulatorBackend(term); vt100.setDimensions(1, 10); - assertEquals(vt100.toAbsoluteLine(0),0); + assertEquals(vt100.toAbsoluteLine(0), 0); } public void testInsertCharacters() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - String s = - "aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "4567\n" + - "9012"; + String s = "aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "4567\n" + "9012"; fill(term, s); vt100.setCursor(0, 0); vt100.insertCharacters(1); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " 123\n" + - "4567\n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " 123\n" + "4567\n" + "9012", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.insertCharacters(1); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "4 56\n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "4 56\n" + "9012", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.insertCharacters(2); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "4 5\n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "4 5\n" + "9012", + toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 0); vt100.insertCharacters(10); - assertEqualsTerm(" ",toMultiLineText(term)); + assertEqualsTerm(" ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 0); vt100.insertCharacters(14); - assertEqualsTerm(" ",toMultiLineText(term)); + assertEqualsTerm(" ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.insertCharacters(14); - assertEqualsTerm("012 ",toMultiLineText(term)); + assertEqualsTerm("012 ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.insertCharacters(0); - assertEqualsTerm("0123456789",toMultiLineText(term)); + assertEqualsTerm("0123456789", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.insertCharacters(2); - assertEqualsTerm("012 34567",toMultiLineText(term)); + assertEqualsTerm("012 34567", toMultiLineText(term)); } public void testEraseToEndOfScreen() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - String s = - "aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "4567\n" + - "8901"; + String s = "aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "4567\n" + "8901"; fill(term, s); vt100.setCursor(0, 0); vt100.eraseToEndOfScreen(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " \n" + - " ",toMultiLineText(term)); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " \n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.eraseToEndOfScreen(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - " \n" + - " ",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + " \n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.eraseToEndOfScreen(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(1,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "4 \n" + - " ",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(1, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "4 \n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 4); - assertEquals(1,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(1, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); vt100.eraseToEndOfScreen(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "456.\n" + - " ",toMultiLineText(term)); - + assertEquals(1, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "456.\n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 5); vt100.eraseToEndOfScreen(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "456.\n" + - " ",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "456.\n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(2, 3); vt100.eraseToEndOfScreen(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "4567\n" + - "890 ",toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "4567\n" + "890 ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(2, 5); vt100.eraseToEndOfScreen(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "4567\n" + - "890.",toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "4567\n" + "890.", + toMultiLineText(term)); } public void testEraseToCursor() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - String s = - "aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "0123\n" + - "4567\n" + - "8901"; + String s = "aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "0123\n" + "4567\n" + "8901"; fill(term, s); vt100.setCursor(0, 0); vt100.eraseToCursor(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " 123\n" + - "4567\n" + - "8901",toMultiLineText(term)); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " 123\n" + "4567\n" + "8901", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.eraseToCursor(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " 567\n" + - "8901",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " 567\n" + "8901", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.eraseToCursor(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(1,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " 67\n" + - "8901",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(1, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " 67\n" + "8901", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 4); vt100.eraseToCursor(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " \n" + - "8901",toMultiLineText(term)); - + assertEquals(1, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " \n" + "8901", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 5); vt100.eraseToCursor(); - assertEquals(1,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " \n" + - "8901",toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " \n" + "8901", + toMultiLineText(term)); fill(term, s); vt100.setCursor(2, 3); vt100.eraseToCursor(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " \n" + - " ",toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " \n" + " ", + toMultiLineText(term)); fill(term, s); vt100.setCursor(2, 5); vt100.eraseToCursor(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - " \n" + - " \n" + - " ",toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + " \n" + " \n" + " ", + toMultiLineText(term)); } public void testEraseAll() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - fill(term, "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"); + fill(term, "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"); vt100.eraseAll(); - assertEqualsTerm("0000\n" + - "1111\n" + - "2222\n" + - " \n" + - " \n" + - " ",toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + " \n" + " \n" + " ", toMultiLineText(term)); } public void testEraseLine() { - String s = - "abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFGHI"; + String s = "abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFGHI"; - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(0, 3); vt100.eraseLine(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - " \n" + - "zABCD\n" + - "EFGHI", toMultiLineText(term)); - + assertEquals(0, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + " \n" + "zABCD\n" + "EFGHI", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(2, 3); vt100.eraseLine(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + " ", + toMultiLineText(term)); } public void testEraseLineToEnd() { - String s = - "abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFGHI"; + String s = "abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFGHI"; - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(0, 3); vt100.eraseLineToEnd(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvw \n" + - "zABCD\n" + - "EFGHI", toMultiLineText(term)); + assertEquals(0, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvw \n" + "zABCD\n" + "EFGHI", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(0, 0); vt100.eraseLineToEnd(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - " \n" + - "zABCD\n" + - "EFGHI", toMultiLineText(term)); - + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + " \n" + "zABCD\n" + "EFGHI", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(2, 3); vt100.eraseLineToEnd(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFG ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFG ", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(2, 4); vt100.eraseLineToEnd(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(4,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFGH ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(4, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFGH ", + toMultiLineText(term)); vt100.setCursor(2, 5); vt100.eraseLineToEnd(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(4,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFGH ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(4, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFGH ", + toMultiLineText(term)); } public void testEraseLineToCursor() { - String s = - "abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - "EFGHI"; + String s = "abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + "EFGHI"; - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(0, 3); vt100.eraseLineToCursor(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - " y\n" + - "zABCD\n" + - "EFGHI", toMultiLineText(term)); + assertEquals(0, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + " y\n" + "zABCD\n" + "EFGHI", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(0, 0); vt100.eraseLineToCursor(); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - " vwxy\n" + - "zABCD\n" + - "EFGHI", toMultiLineText(term)); - + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + " vwxy\n" + "zABCD\n" + "EFGHI", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(2, 3); vt100.eraseLineToCursor(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - " I", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + " I", + toMultiLineText(term)); vt100.setDimensions(3, 5); fill(term, s); vt100.setCursor(2, 4); vt100.eraseLineToCursor(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(4,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(4, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + " ", + toMultiLineText(term)); vt100.setCursor(2, 5); vt100.eraseLineToCursor(); - assertEquals(2,vt100.getCursorLine()); - assertEquals(4,vt100.getCursorColumn()); - assertEqualsTerm("abcde\n" + - "fghij\n" + - "klmno\n" + - "pqrst\n" + - "uvwxy\n" + - "zABCD\n" + - " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(4, vt100.getCursorColumn()); + assertEqualsTerm("abcde\n" + "fghij\n" + "klmno\n" + "pqrst\n" + "uvwxy\n" + "zABCD\n" + " ", + toMultiLineText(term)); } public void testInsertLines() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - String s = "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"; + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + String s = "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"; vt100.setDimensions(3, 4); fill(term, s); vt100.setCursor(0, 0); vt100.insertLines(1); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - " \n" + - "3333\n" + - "4444", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + " \n" + "3333\n" + "4444", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.insertLines(1); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - " \n" + - "4444", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + " \n" + "4444", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.insertLines(2); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + " \n" + " ", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 3); vt100.insertLines(2); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - " \n" + - " ", toMultiLineText(term)); - + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(1, 3); vt100.insertLines(2); - assertEqualsTerm( - "0000\n" + - " \n" + - " \n" + - "1111\n" + - "2222\n" + - "3333", toMultiLineText(term)); - + assertEqualsTerm("0000\n" + " \n" + " \n" + "1111\n" + "2222\n" + "3333", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(1, 3); vt100.insertLines(7); - assertEqualsTerm( - "0000\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + " \n" + " \n" + " \n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(0, 0); vt100.insertLines(7); - assertEqualsTerm( - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm(" \n" + " \n" + " \n" + " \n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(0, 0); vt100.insertLines(5); - assertEqualsTerm( - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "0000", toMultiLineText(term)); + assertEqualsTerm(" \n" + " \n" + " \n" + " \n" + " \n" + "0000", toMultiLineText(term)); } public void testDeleteCharacters() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); vt100.setDimensions(3, 4); - String s = - "aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "4567\n" + - "9012"; + String s = "aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "4567\n" + "9012"; fill(term, s); vt100.setCursor(0, 0); vt100.deleteCharacters(1); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "234 \n" + - "4567\n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "234 \n" + "4567\n" + "9012", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.deleteCharacters(1); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "467 \n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "467 \n" + "9012", + toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 1); vt100.deleteCharacters(2); - assertEqualsTerm("aaaa\n" + - "bbbb\n" + - "cccc\n" + - "dddd\n" + - "eeee\n" + - "ffff\n" + - "1234\n" + - "47 \n" + - "9012",toMultiLineText(term)); + assertEqualsTerm("aaaa\n" + "bbbb\n" + "cccc\n" + "dddd\n" + "eeee\n" + "ffff\n" + "1234\n" + "47 \n" + "9012", + toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 0); vt100.deleteCharacters(10); - assertEqualsTerm(" ",toMultiLineText(term)); + assertEqualsTerm(" ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 0); vt100.deleteCharacters(14); - assertEqualsTerm(" ",toMultiLineText(term)); + assertEqualsTerm(" ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.deleteCharacters(0); - assertEqualsTerm("0123456789",toMultiLineText(term)); + assertEqualsTerm("0123456789", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.deleteCharacters(2); - assertEqualsTerm("01256789 ",toMultiLineText(term)); + assertEqualsTerm("01256789 ", toMultiLineText(term)); vt100.setDimensions(1, 10); fill(term, "0123456789"); vt100.setCursor(0, 3); vt100.deleteCharacters(14); - assertEqualsTerm("012 ",toMultiLineText(term)); + assertEqualsTerm("012 ", toMultiLineText(term)); } public void testDeleteLines() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - String s = "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"; + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + String s = "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"; vt100.setDimensions(3, 4); fill(term, s); vt100.setCursor(0, 0); vt100.deleteLines(1); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "4444\n" + - "5555\n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "4444\n" + "5555\n" + " ", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.deleteLines(1); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "5555\n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + "5555\n" + " ", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 0); vt100.deleteLines(2); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + " \n" + " ", toMultiLineText(term)); fill(term, s); vt100.setCursor(1, 3); vt100.deleteLines(2); - assertEqualsTerm( - "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - " \n" + - " ", toMultiLineText(term)); - + assertEqualsTerm("0000\n" + "1111\n" + "2222\n" + "3333\n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(1, 3); vt100.deleteLines(2); - assertEqualsTerm( - "0000\n" + - "3333\n" + - "4444\n" + - "5555\n" + - " \n" + - " ", toMultiLineText(term)); - + assertEqualsTerm("0000\n" + "3333\n" + "4444\n" + "5555\n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(1, 3); vt100.deleteLines(7); - assertEqualsTerm( - "0000\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm("0000\n" + " \n" + " \n" + " \n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(0, 0); vt100.deleteLines(7); - assertEqualsTerm( - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm(" \n" + " \n" + " \n" + " \n" + " \n" + " ", toMultiLineText(term)); vt100.setDimensions(6, 4); fill(term, s); vt100.setCursor(0, 0); vt100.deleteLines(5); - assertEqualsTerm( - "5555\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm("5555\n" + " \n" + " \n" + " \n" + " \n" + " ", toMultiLineText(term)); } public void testGetDefaultStyle() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - Style style=Style.getStyle("white", "black"); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + Style style = Style.getStyle("white", "black"); vt100.setDefaultStyle(style); assertSame(style, vt100.getDefaultStyle()); - Style style2=style.setBold(true); + Style style2 = style.setBold(true); vt100.setDefaultStyle(style2); assertSame(style2, vt100.getDefaultStyle()); } public void testGetStyle() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - Style style=Style.getStyle("white", "black"); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + Style style = Style.getStyle("white", "black"); vt100.setStyle(style); assertSame(style, vt100.getStyle()); - Style style2=style.setBold(true); + Style style2 = style.setBold(true); vt100.setStyle(style2); assertSame(style2, vt100.getStyle()); } public void testAppendString() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(6); vt100.setDimensions(3, 4); vt100.setCursor(0, 0); - assertEqualsTerm( - " \n" + - " \n" + - " ", toMultiLineText(term)); + assertEqualsTerm(" \n" + " \n" + " ", toMultiLineText(term)); vt100.appendString("012"); - assertEqualsTerm( - "012 \n" + - " \n" + - " ", toMultiLineText(term)); - assertEquals(0,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEqualsTerm("012 \n" + " \n" + " ", toMultiLineText(term)); + assertEquals(0, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); vt100.appendString("3"); - assertEqualsTerm( - "0123\n" + - " \n" + - " ", toMultiLineText(term)); - assertEquals(1,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEqualsTerm("0123\n" + " \n" + " ", toMultiLineText(term)); + assertEquals(1, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.appendString("567890"); - assertEqualsTerm( - "0123\n" + - "5678\n" + - "90 ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); - + assertEqualsTerm("0123\n" + "5678\n" + "90 ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.appendString("a"); - assertEqualsTerm( - "0123\n" + - "5678\n" + - "90a ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEqualsTerm("0123\n" + "5678\n" + "90a ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); vt100.appendString("b"); - assertEqualsTerm( - "0123\n" + - "5678\n" + - "90ab\n" + - " ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEqualsTerm("0123\n" + "5678\n" + "90ab\n" + " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.appendString("cd"); - assertEqualsTerm( - "0123\n" + - "5678\n" + - "90ab\n" + - "cd ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEqualsTerm("0123\n" + "5678\n" + "90ab\n" + "cd ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.appendString("efgh"); - assertEqualsTerm( - "0123\n" + - "5678\n" + - "90ab\n" + - "cdef\n" + - "gh ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEqualsTerm("0123\n" + "5678\n" + "90ab\n" + "cdef\n" + "gh ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.appendString("ijklmnopqrstuvwx"); - assertEqualsTerm( - "cdef\n" + - "ghij\n" + - "klmn\n" + - "opqr\n" + - "stuv\n" + - "wx ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEqualsTerm("cdef\n" + "ghij\n" + "klmn\n" + "opqr\n" + "stuv\n" + "wx ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.setCursor(1, 1); vt100.appendString("123"); - assertEqualsTerm( - "cdef\n" + - "ghij\n" + - "klmn\n" + - "opqr\n" + - "s123\n" + - "wx ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEqualsTerm("cdef\n" + "ghij\n" + "klmn\n" + "opqr\n" + "s123\n" + "wx ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(1, 1); vt100.appendString("ABCDEFGHIJKL"); - assertEqualsTerm( - "klmn\n" + - "opqr\n" + - "sABC\n" + - "DEFG\n" + - "HIJK\n" + - "L ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(1,vt100.getCursorColumn()); + assertEqualsTerm("klmn\n" + "opqr\n" + "sABC\n" + "DEFG\n" + "HIJK\n" + "L ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(1, vt100.getCursorColumn()); } public void testProcessNewline() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); - String s = "0000\n" + - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555"; + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); + String s = "0000\n" + "1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555"; term.setMaxHeight(6); vt100.setDimensions(3, 4); vt100.setCursor(0, 0); - fill(term,s); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + fill(term, s); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.processNewline(); assertEqualsTerm(s, toMultiLineText(term)); - assertEquals(1,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(1, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursorColumn(3); vt100.processNewline(); assertEqualsTerm(s, toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); vt100.processNewline(); - assertEqualsTerm( - "1111\n" + - "2222\n" + - "3333\n" + - "4444\n" + - "5555\n" + - " ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); - + assertEqualsTerm("1111\n" + "2222\n" + "3333\n" + "4444\n" + "5555\n" + " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); vt100.processNewline(); - assertEqualsTerm( - "2222\n" + - "3333\n" + - "4444\n" + - "5555\n" + - " \n" + - " ", toMultiLineText(term)); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEqualsTerm("2222\n" + "3333\n" + "4444\n" + "5555\n" + " \n" + " ", toMultiLineText(term)); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); } public void testSetCursorLine() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(6); vt100.setDimensions(3, 4); // the cursor still at the beginning.... - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(0, 2); vt100.setCursorLine(1); - assertEquals(1,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEquals(1, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.setCursor(0, -2); vt100.setCursorLine(-1); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(0, 10); vt100.setCursorLine(10); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); } + public void testSetCursorAndSetDimensions() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(3, 4); // the cursor still at the beginning.... - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setDimensions(6, 4); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(2, 3); vt100.setDimensions(8, 4); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); } public void testSetCursorColumn() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(6); vt100.setDimensions(3, 4); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(1, 0); vt100.setCursorColumn(2); - assertEquals(1,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEquals(1, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.setCursor(-1, -2); vt100.setCursorColumn(-2); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(10, 0); vt100.setCursorColumn(10); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); } public void testSetCursor() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(6); vt100.setDimensions(3, 4); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(0, 0); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(1, 2); - assertEquals(1,vt100.getCursorLine()); - assertEquals(2,vt100.getCursorColumn()); + assertEquals(1, vt100.getCursorLine()); + assertEquals(2, vt100.getCursorColumn()); vt100.setCursor(-1, -2); - assertEquals(0,vt100.getCursorLine()); - assertEquals(0,vt100.getCursorColumn()); + assertEquals(0, vt100.getCursorLine()); + assertEquals(0, vt100.getCursorColumn()); vt100.setCursor(10, 10); - assertEquals(2,vt100.getCursorLine()); - assertEquals(3,vt100.getCursorColumn()); + assertEquals(2, vt100.getCursorLine()); + assertEquals(3, vt100.getCursorColumn()); } public void testVT100LineWrappingOn() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(6, 4); vt100.setVT100LineWrapping(true); @@ -1255,8 +799,8 @@ public class VT100EmulatorBackendTest extends TestCase { } public void testVT100LineWrappingOff() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(6, 4); vt100.setVT100LineWrapping(false); @@ -1270,8 +814,8 @@ public class VT100EmulatorBackendTest extends TestCase { } public void testWrappedLines() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(6, 4); vt100.setVT100LineWrapping(true); @@ -1290,8 +834,8 @@ public class VT100EmulatorBackendTest extends TestCase { } public void testInsertMode() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(4, 6); // replace mode @@ -1311,8 +855,8 @@ public class VT100EmulatorBackendTest extends TestCase { } public void testScrollRegion() { - ITerminalTextData term=makeITerminalTextData(); - IVT100EmulatorBackend vt100=makeBakend(term); + ITerminalTextData term = makeITerminalTextData(); + IVT100EmulatorBackend vt100 = makeBakend(term); term.setMaxHeight(10); vt100.setDimensions(8, 6); vt100.appendString("123"); @@ -1331,7 +875,7 @@ public class VT100EmulatorBackendTest extends TestCase { vt100.setCursorColumn(0); vt100.processNewline(); vt100.appendString("ghi"); - + // test scroll within region vt100.setCursorLine(1); vt100.setScrollRegion(1, 4); @@ -1367,7 +911,7 @@ public class VT100EmulatorBackendTest extends TestCase { assertEquals("abc", new String(term.getChars(3))); assertEquals("def", new String(term.getChars(4))); assertEquals("ghi", new String(term.getChars(5))); - + // test scroll by newline vt100.setScrollRegion(1, 4); vt100.setCursorLine(4); diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/AbstractITerminalTextDataTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/AbstractITerminalTextDataTest.java index 6d2cc23d09b..a26689a7c0f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/AbstractITerminalTextDataTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/AbstractITerminalTextDataTest.java @@ -1,15 +1,16 @@ /******************************************************************************* * Copyright (c) 2007-2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; + import junit.framework.TestCase; import org.eclipse.tm.terminal.model.ITerminalTextData; @@ -25,50 +26,53 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { try { assert false; throw new Error("No Assertions! Run this code with assertions enabled! (vmargs: -ea)"); - } catch(AssertionError e) { + } catch (AssertionError e) { // OK, assertions are enabled! } super.setUp(); } + protected String toSimple(ITerminalTextData term) { return TerminalTextTestHelper.toSimple(term); } + protected String toMultiLineText(ITerminalTextDataReadOnly term) { return TerminalTextTestHelper.toMultiLineText(term); } - + protected void fill(ITerminalTextData term, String s) { - TerminalTextTestHelper.fill(term,s); + TerminalTextTestHelper.fill(term, s); } protected void fill(ITerminalTextData term, int i, int j, String s) { - TerminalTextTestHelper.fill(term,i,j,s); + TerminalTextTestHelper.fill(term, i, j, s); } protected void fillSimple(ITerminalTextData term, String s) { TerminalTextTestHelper.fillSimple(term, s); } - /** * Used for multi line text * @param expected * @param actual */ - protected void assertEqualsTerm(String expected,String actual) { + protected void assertEqualsTerm(String expected, String actual) { assertEquals(expected, actual); } + /** * Used for simple text * @param expected * @param actual */ - protected void assertEqualsSimple(String expected,String actual) { - assertEquals(-1,actual.indexOf('\n')); + protected void assertEqualsSimple(String expected, String actual) { + assertEquals(-1, actual.indexOf('\n')); assertEquals(expected, actual); } + public void testGetWidth() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); assertEquals(0, term.getWidth()); term.setDimensions(term.getHeight(), 10); assertEquals(10, term.getWidth()); @@ -77,117 +81,57 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { } public void testAddLine() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); fill(term, s); term.setMaxHeight(5); term.addLine(); - assertEqualsTerm( - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000", toMultiLineText(term)); } + public void testCleanLine() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); fill(term, s); term.cleanLine(0); - assertEqualsTerm( - "\000\000\000\n" + - "222\n" + - "333\n" + - "444\n" + - "555", toMultiLineText(term)); - + assertEqualsTerm("\000\000\000\n" + "222\n" + "333\n" + "444\n" + "555", toMultiLineText(term)); + fill(term, s); term.cleanLine(4); - assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("111\n" + "222\n" + "333\n" + "444\n" + "\000\000\000", toMultiLineText(term)); } public void testMaxSize() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); term.setMaxHeight(8); fill(term, s); assertEquals(5, term.getHeight()); assertEquals(8, term.getMaxHeight()); term.addLine(); assertEquals(6, term.getHeight()); - assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000", toMultiLineText(term)); term.addLine(); assertEquals(7, term.getHeight()); - assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000", + toMultiLineText(term)); term.addLine(); assertEquals(8, term.getHeight()); assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + "111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000\n" + "\000\000\000", + toMultiLineText(term)); term.addLine(); assertEquals(8, term.getHeight()); - assertEqualsTerm( - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000\n" + "\000\000\000\n" + + "\000\000\000", toMultiLineText(term)); term.addLine(); assertEquals(8, term.getHeight()); - assertEqualsTerm( - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000\n" + "\000\000\000\n" + + "\000\000\000\n" + "\000\000\000", toMultiLineText(term)); } + public void testGetHeight() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); assertEquals(0, term.getHeight()); term.setDimensions(10, term.getWidth()); assertEquals(10, term.getHeight()); @@ -196,7 +140,7 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { } public void testSetDimensions() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); assertEquals(0, term.getHeight()); term.setDimensions(10, 5); assertEquals(5, term.getWidth()); @@ -214,50 +158,33 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { assertEquals(0, term.getWidth()); assertEquals(0, term.getHeight()); } + public void testResize() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(3, 5); - String s="12345\n" + - "abcde\n" + - "ABCDE"; - fill(term,0,0,s); + String s = "12345\n" + "abcde\n" + "ABCDE"; + fill(term, 0, 0, s); assertEqualsTerm(s, toMultiLineText(term)); term.setDimensions(3, 4); - assertEqualsTerm( - "1234\n" + - "abcd\n" + - "ABCD", toMultiLineText(term)); + assertEqualsTerm("1234\n" + "abcd\n" + "ABCD", toMultiLineText(term)); // the columns should be restored term.setDimensions(3, 5); - assertEqualsTerm( - "12345\n" + - "abcde\n" + - "ABCDE", toMultiLineText(term)); + assertEqualsTerm("12345\n" + "abcde\n" + "ABCDE", toMultiLineText(term)); term.setDimensions(3, 6); - assertEqualsTerm( - "12345\000\n" + - "abcde\000\n" + - "ABCDE\000", toMultiLineText(term)); + assertEqualsTerm("12345\000\n" + "abcde\000\n" + "ABCDE\000", toMultiLineText(term)); term.setChar(0, 5, 'x', null); term.setChar(1, 5, 'y', null); term.setChar(2, 5, 'z', null); - assertEqualsTerm( - "12345x\n" + - "abcdey\n" + - "ABCDEz", toMultiLineText(term)); + assertEqualsTerm("12345x\n" + "abcdey\n" + "ABCDEz", toMultiLineText(term)); term.setDimensions(2, 4); - assertEqualsTerm( - "1234\n" + - "abcd", toMultiLineText(term)); + assertEqualsTerm("1234\n" + "abcd", toMultiLineText(term)); } public void testResizeFailure() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(3, 5); - String s="12345\n" + - "abcde\n" + - "ABCDE"; - fill(term,0,0,s); + String s = "12345\n" + "abcde\n" + "ABCDE"; + fill(term, 0, 0, s); assertEqualsTerm(s, toMultiLineText(term)); try { term.setDimensions(-3, 4); @@ -265,541 +192,496 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { } catch (RuntimeException e) { // OK } -// assertEquals(5, term.getWidth()); -// assertEquals(3, term.getHeight()); -// assertEquals(s, toSimpleText(term)); + // assertEquals(5, term.getWidth()); + // assertEquals(3, term.getHeight()); + // assertEquals(s, toSimpleText(term)); } - + public void testGetLineSegments() { - Style s1=getDefaultStyle(); - Style s2=s1.setBold(true); - Style s3=s1.setUnderline(true); - ITerminalTextData term=makeITerminalTextData(); + Style s1 = getDefaultStyle(); + Style s2 = s1.setBold(true); + Style s3 = s1.setUnderline(true); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(8, 8); LineSegment[] segments; - - term.setChars(0, 0,"0123".toCharArray(), s1); - term.setChars(0, 4,"abcd".toCharArray(), null); - segments=term.getLineSegments(0, 0, term.getWidth()); + + term.setChars(0, 0, "0123".toCharArray(), s1); + term.setChars(0, 4, "abcd".toCharArray(), null); + segments = term.getLineSegments(0, 0, term.getWidth()); assertEquals(2, segments.length); assertSegment(0, "0123", s1, segments[0]); assertSegment(4, "abcd", null, segments[1]); - - - segments=term.getLineSegments(0, 4, term.getWidth()-4); + + segments = term.getLineSegments(0, 4, term.getWidth() - 4); assertEquals(1, segments.length); assertSegment(4, "abcd", null, segments[0]); - - segments=term.getLineSegments(0, 3, 2); + + segments = term.getLineSegments(0, 3, 2); assertEquals(2, segments.length); assertSegment(3, "3", s1, segments[0]); assertSegment(4, "a", null, segments[1]); - - segments=term.getLineSegments(0, 7, 1); + + segments = term.getLineSegments(0, 7, 1); assertEquals(1, segments.length); assertSegment(7, "d", null, segments[0]); - - segments=term.getLineSegments(0, 0, 1); + + segments = term.getLineSegments(0, 0, 1); assertEquals(1, segments.length); assertSegment(0, "0", s1, segments[0]); - + // line 1 - term.setChars(1, 0,"x".toCharArray(), s1); - term.setChars(1, 1,"y".toCharArray(), s2); - term.setChars(1, 2,"z".toCharArray(), s3); - - segments=term.getLineSegments(1, 0, term.getWidth()); + term.setChars(1, 0, "x".toCharArray(), s1); + term.setChars(1, 1, "y".toCharArray(), s2); + term.setChars(1, 2, "z".toCharArray(), s3); + + segments = term.getLineSegments(1, 0, term.getWidth()); assertEquals(4, segments.length); assertSegment(0, "x", s1, segments[0]); assertSegment(1, "y", s2, segments[1]); assertSegment(2, "z", s3, segments[2]); assertSegment(3, "\000\000\000\000\000", null, segments[3]); - + // line 2 - term.setChars(2, 4,"klm".toCharArray(), s1); - segments=term.getLineSegments(2, 0, term.getWidth()); + term.setChars(2, 4, "klm".toCharArray(), s1); + segments = term.getLineSegments(2, 0, term.getWidth()); assertEquals(3, segments.length); assertSegment(0, "\000\000\000\000", null, segments[0]); assertSegment(4, "klm", s1, segments[1]); assertSegment(7, "\000", null, segments[2]); - + // line 3 - segments=term.getLineSegments(3, 0, term.getWidth()); + segments = term.getLineSegments(3, 0, term.getWidth()); assertEquals(1, segments.length); assertSegment(0, "\000\000\000\000\000\000\000\000", null, segments[0]); - + } + public void testGetLineSegmentsNull() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(8, 8); - LineSegment[] segments=term.getLineSegments(0, 0, term.getWidth()); + LineSegment[] segments = term.getLineSegments(0, 0, term.getWidth()); assertEquals(1, segments.length); } + public void testGetLineSegmentsOutOfBounds() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(1, 8); - term.setChars(0,0,"xx".toCharArray(),null); - LineSegment[] segments=term.getLineSegments(0, 5, 2); + term.setChars(0, 0, "xx".toCharArray(), null); + LineSegment[] segments = term.getLineSegments(0, 5, 2); assertEquals(1, segments.length); - - + } - void assertSegment(int col,String text, Style style,LineSegment segment) { + + void assertSegment(int col, String text, Style style, LineSegment segment) { assertEquals(col, segment.getColumn()); assertEqualsTerm(text, segment.getText()); assertEquals(style, segment.getStyle()); - + } + public void testGetChar() { - String s="12345\n" + - "abcde\n" + - "ABCDE"; - ITerminalTextData term=makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE"; + ITerminalTextData term = makeITerminalTextData(); fill(term, s); - assertEquals('1', term.getChar(0,0)); - assertEquals('2', term.getChar(0,1)); - assertEquals('3', term.getChar(0,2)); - assertEquals('4', term.getChar(0,3)); - assertEquals('5', term.getChar(0,4)); - assertEquals('a', term.getChar(1,0)); - assertEquals('b', term.getChar(1,1)); - assertEquals('c', term.getChar(1,2)); - assertEquals('d', term.getChar(1,3)); - assertEquals('e', term.getChar(1,4)); - assertEquals('A', term.getChar(2,0)); - assertEquals('B', term.getChar(2,1)); - assertEquals('C', term.getChar(2,2)); - assertEquals('D', term.getChar(2,3)); - assertEquals('E', term.getChar(2,4)); + assertEquals('1', term.getChar(0, 0)); + assertEquals('2', term.getChar(0, 1)); + assertEquals('3', term.getChar(0, 2)); + assertEquals('4', term.getChar(0, 3)); + assertEquals('5', term.getChar(0, 4)); + assertEquals('a', term.getChar(1, 0)); + assertEquals('b', term.getChar(1, 1)); + assertEquals('c', term.getChar(1, 2)); + assertEquals('d', term.getChar(1, 3)); + assertEquals('e', term.getChar(1, 4)); + assertEquals('A', term.getChar(2, 0)); + assertEquals('B', term.getChar(2, 1)); + assertEquals('C', term.getChar(2, 2)); + assertEquals('D', term.getChar(2, 3)); + assertEquals('E', term.getChar(2, 4)); try { - term.getChar(0,-1); + term.getChar(0, -1); fail(); } catch (RuntimeException e) { } try { - term.getChar(-1,-1); + term.getChar(-1, -1); fail(); } catch (RuntimeException e) { } try { - term.getChar(-1,0); + term.getChar(-1, 0); fail(); } catch (RuntimeException e) { } try { - term.getChar(0,5); + term.getChar(0, 5); fail(); } catch (RuntimeException e) { } try { - term.getChar(3,5); + term.getChar(3, 5); fail(); } catch (RuntimeException e) { } try { - term.getChar(3,0); + term.getChar(3, 0); fail(); } catch (RuntimeException e) { } } public void testGetStyle() { - ITerminalTextData term=makeITerminalTextData(); - Style style=getDefaultStyle(); + ITerminalTextData term = makeITerminalTextData(); + Style style = getDefaultStyle(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor(""+c))); + char c = (char) ('a' + column + line); + term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor("" + c))); } } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - assertSame(style.setForground(StyleColor.getStyleColor(""+c)), term.getStyle(line, column)); + char c = (char) ('a' + column + line); + assertSame(style.setForground(StyleColor.getStyleColor("" + c)), term.getStyle(line, column)); } } - + } protected Style getDefaultStyle() { - return Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + return Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, + false); } public void testSetChar() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - term.setChar(line, column, (char)('a'+column+line), null); + term.setChar(line, column, (char) ('a' + column + line), null); } } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - assertEquals(c, term.getChar(line,column)); + char c = (char) ('a' + column + line); + assertEquals(c, term.getChar(line, column)); } } - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "def\n" - + "efg\n" - + "fgh", toMultiLineText(term)); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "def\n" + "efg\n" + "fgh", toMultiLineText(term)); } + public void testSetChars() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { - char[] chars=new char[term.getWidth()]; + char[] chars = new char[term.getWidth()]; for (int column = 0; column < term.getWidth(); column++) { - chars[column]=(char)('a'+column+line); + chars[column] = (char) ('a' + column + line); } term.setChars(line, 0, chars, null); } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - assertEquals(c, term.getChar(line,column)); + char c = (char) ('a' + column + line); + assertEquals(c, term.getChar(line, column)); } } - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "def\n" - + "efg\n" - + "fgh", toMultiLineText(term)); - - term.setChars(3, 1, new char[]{'1','2'}, null); - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "d12\n" - + "efg\n" - + "fgh", toMultiLineText(term)); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "def\n" + "efg\n" + "fgh", toMultiLineText(term)); + + term.setChars(3, 1, new char[] { '1', '2' }, null); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "d12\n" + "efg\n" + "fgh", toMultiLineText(term)); try { // check if we cannot exceed the range - term.setChars(4, 1, new char[]{'1','2','3','4','5'}, null); + term.setChars(4, 1, new char[] { '1', '2', '3', '4', '5' }, null); fail(); - } catch (RuntimeException e) {} - + } catch (RuntimeException e) { + } + } + public void testSetCharsLen() { - ITerminalTextData term=makeITerminalTextData(); - String s= "ZYXWVU\n" - + "abcdef\n" - + "ABCDEF"; + ITerminalTextData term = makeITerminalTextData(); + String s = "ZYXWVU\n" + "abcdef\n" + "ABCDEF"; fill(term, s); - char[] chars=new char[]{'1','2','3','4','5','6','7','8'}; - term.setChars(1, 0, chars, 0, 6,null); - assertEqualsTerm( - "ZYXWVU\n" - + "123456\n" - + "ABCDEF", toMultiLineText(term)); + char[] chars = new char[] { '1', '2', '3', '4', '5', '6', '7', '8' }; + term.setChars(1, 0, chars, 0, 6, null); + assertEqualsTerm("ZYXWVU\n" + "123456\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 0, chars, 0, 5, null); - assertEqualsTerm("ZYXWVU\n" - + "12345f\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "12345f\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 0, chars, 1, 5, null); - assertEqualsTerm("ZYXWVU\n" - + "23456f\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "23456f\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 1, chars, 1, 4, null); - assertEqualsTerm("ZYXWVU\n" - + "a2345f\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "a2345f\n" + "ABCDEF", toMultiLineText(term)); - - fill(term, s); term.setChars(1, 2, chars, 3, 4, null); - assertEqualsTerm("ZYXWVU\n" - + "ab4567\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "ab4567\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); try { term.setChars(1, 0, chars, 7, 10, null); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } fill(term, s); try { term.setChars(1, -1, chars, 0, 2, null); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { term.setChars(-1, 1, chars, 0, 2, null); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { term.setChars(1, 10, chars, 0, 2, null); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { term.setChars(10, 1, chars, 0, 2, null); fail(); - } catch (RuntimeException e) {} -// assertEquals(s, toSimpleText(term)); + } catch (RuntimeException e) { + } + // assertEquals(s, toSimpleText(term)); } + public void testSetCopyInto() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(3, 5); - String s="12345\n" + - "abcde\n" + - "ABCDE"; - fill(term,0,0,s); - ITerminalTextData termCopy=makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE"; + fill(term, 0, 0, s); + ITerminalTextData termCopy = makeITerminalTextData(); termCopy.copy(term); assertEqualsTerm(s, toMultiLineText(termCopy)); assertEqualsTerm(s, toMultiLineText(term)); - + termCopy.setChar(1, 1, 'X', null); assertEqualsTerm(s, toMultiLineText(term)); term.setDimensions(2, 4); assertEquals(5, termCopy.getWidth()); assertEquals(3, termCopy.getHeight()); - - assertEqualsTerm("12345\n" + - "aXcde\n" + - "ABCDE", toMultiLineText(termCopy)); + + assertEqualsTerm("12345\n" + "aXcde\n" + "ABCDE", toMultiLineText(termCopy)); assertEquals(4, term.getWidth()); assertEquals(2, term.getHeight()); } + public void testSetCopyLines() { - ITerminalTextData term=makeITerminalTextData(); - String s="012345"; + ITerminalTextData term = makeITerminalTextData(); + String s = "012345"; fillSimple(term, s); - ITerminalTextData termCopy=makeITerminalTextData(); - String sCopy="abcde"; + ITerminalTextData termCopy = makeITerminalTextData(); + String sCopy = "abcde"; fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,0); + termCopy.copyRange(term, 0, 0, 0); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple(sCopy, toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,5); + termCopy.copyRange(term, 0, 0, 5); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("01234", toSimple(termCopy)); - + fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,2); + termCopy.copyRange(term, 0, 0, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("01cde", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,1,2); + termCopy.copyRange(term, 0, 1, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a01de", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,1,1,2); + termCopy.copyRange(term, 1, 1, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a12de", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,1,1,4); + termCopy.copyRange(term, 1, 1, 4); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a1234", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,2,1,4); + termCopy.copyRange(term, 2, 1, 4); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a2345", toSimple(termCopy)); try { fillSimple(termCopy, sCopy); - termCopy.copyRange(term,1,1,5); + termCopy.copyRange(term, 1, 1, 5); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,6); + termCopy.copyRange(term, 0, 0, 6); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { fillSimple(termCopy, sCopy); - termCopy.copyRange(term,7,0,1); + termCopy.copyRange(term, 7, 0, 1); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } try { fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,7,1); + termCopy.copyRange(term, 0, 7, 1); fail(); - } catch (RuntimeException e) {} + } catch (RuntimeException e) { + } } + public void testCopyLine() { - ITerminalTextData term=makeITerminalTextData(); - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; + ITerminalTextData term = makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; fill(term, s); - ITerminalTextData dest=makeITerminalTextData(); - String sCopy= - "aaa\n" + - "bbb\n" + - "ccc\n" + - "ddd\n" + - "eee"; + ITerminalTextData dest = makeITerminalTextData(); + String sCopy = "aaa\n" + "bbb\n" + "ccc\n" + "ddd\n" + "eee"; fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{true,true,false,false,true}); + copySelective(dest, term, 0, 0, new boolean[] { true, true, false, false, true }); assertEqualsTerm(s, toMultiLineText(term)); - assertEqualsTerm( - "111\n" + - "222\n" + - "ccc\n" + - "ddd\n" + - "555", toMultiLineText(dest)); + assertEqualsTerm("111\n" + "222\n" + "ccc\n" + "ddd\n" + "555", toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{true,true,true,true,true}); + copySelective(dest, term, 0, 0, new boolean[] { true, true, true, true, true }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(s, toMultiLineText(dest)); - + fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{false,false,false,false,false}); + copySelective(dest, term, 0, 0, new boolean[] { false, false, false, false, false }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(sCopy, toMultiLineText(dest)); } - protected void copySelective(ITerminalTextData dest, ITerminalTextData source, int sourceStartLine, int destStartLine, boolean[] linesToCopy) { + + protected void copySelective(ITerminalTextData dest, ITerminalTextData source, int sourceStartLine, + int destStartLine, boolean[] linesToCopy) { for (int i = 0; i < linesToCopy.length; i++) { - if(linesToCopy[i]) { - dest.copyLine(source, i+sourceStartLine, i+destStartLine); + if (linesToCopy[i]) { + dest.copyLine(source, i + sourceStartLine, i + destStartLine); } } } public void testCopyLineWithOffset() { - ITerminalTextData term=makeITerminalTextData(); - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; + ITerminalTextData term = makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; fill(term, s); - ITerminalTextData dest=makeITerminalTextData(); - String sCopy= - "aaa\n" + - "bbb\n" + - "ccc\n" + - "ddd\n" + - "eee"; + ITerminalTextData dest = makeITerminalTextData(); + String sCopy = "aaa\n" + "bbb\n" + "ccc\n" + "ddd\n" + "eee"; fill(dest, sCopy); - copySelective(dest,term,1,0,new boolean []{true,false,false,true}); + copySelective(dest, term, 1, 0, new boolean[] { true, false, false, true }); assertEqualsTerm(s, toMultiLineText(term)); - assertEqualsTerm( - "222\n" + - "bbb\n" + - "ccc\n" + - "555\n" + - "eee", toMultiLineText(dest)); + assertEqualsTerm("222\n" + "bbb\n" + "ccc\n" + "555\n" + "eee", toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,2,0,new boolean []{true,true}); + copySelective(dest, term, 2, 0, new boolean[] { true, true }); assertEqualsTerm(s, toMultiLineText(term)); - assertEqualsTerm( - "333\n" + - "444\n" + - "ccc\n" + - "ddd\n" + - "eee", toMultiLineText(dest)); + assertEqualsTerm("333\n" + "444\n" + "ccc\n" + "ddd\n" + "eee", toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{true,true,true,true,true}); + copySelective(dest, term, 0, 0, new boolean[] { true, true, true, true, true }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(s, toMultiLineText(dest)); - + fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{false,false,false,false,false}); + copySelective(dest, term, 0, 0, new boolean[] { false, false, false, false, false }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(sCopy, toMultiLineText(dest)); } + public void testScrollNoop() { - scrollTest(0,0,0, "012345","012345"); - scrollTest(0,1,0, "012345","012345"); - scrollTest(0,6,0, "012345","012345"); + scrollTest(0, 0, 0, "012345", "012345"); + scrollTest(0, 1, 0, "012345", "012345"); + scrollTest(0, 6, 0, "012345", "012345"); } + public void testScrollAll() { - scrollTest(0,6,1, "012345"," 01234"); - scrollTest(0,6,-1, "012345","12345 "); - scrollTest(0,6,2, "012345"," 0123"); - scrollTest(0,6,-2, "012345","2345 "); + scrollTest(0, 6, 1, "012345", " 01234"); + scrollTest(0, 6, -1, "012345", "12345 "); + scrollTest(0, 6, 2, "012345", " 0123"); + scrollTest(0, 6, -2, "012345", "2345 "); } + public void testScrollNegative() { - scrollTest(0,2,-1,"012345","1 2345"); - scrollTest(0,1,-1,"012345"," 12345"); - scrollTest(0,6,-1,"012345","12345 "); - scrollTest(0,6,-6,"012345"," "); - scrollTest(0,6,-7,"012345"," "); - scrollTest(0,6,-8,"012345"," "); - scrollTest(0,6,-2,"012345","2345 "); - scrollTest(1,1,-1,"012345","0 2345"); - scrollTest(1,1,-1,"012345","0 2345"); - scrollTest(1,2,-1,"012345","02 345"); - scrollTest(5,1,-1,"012345","01234 "); - scrollTest(5,1,-1,"012345","01234 "); + scrollTest(0, 2, -1, "012345", "1 2345"); + scrollTest(0, 1, -1, "012345", " 12345"); + scrollTest(0, 6, -1, "012345", "12345 "); + scrollTest(0, 6, -6, "012345", " "); + scrollTest(0, 6, -7, "012345", " "); + scrollTest(0, 6, -8, "012345", " "); + scrollTest(0, 6, -2, "012345", "2345 "); + scrollTest(1, 1, -1, "012345", "0 2345"); + scrollTest(1, 1, -1, "012345", "0 2345"); + scrollTest(1, 2, -1, "012345", "02 345"); + scrollTest(5, 1, -1, "012345", "01234 "); + scrollTest(5, 1, -1, "012345", "01234 "); } + public void testScrollNegative2() { - scrollTest(0,2,-1," 23 "," 23 "); - scrollTest(0,1,-1," 23 "," 23 "); - scrollTest(0,6,-1," 23 "," 23 "); - scrollTest(0,6,-6," 23 "," "); - scrollTest(0,6,-7," 23 "," "); - scrollTest(0,6,-8," 23 "," "); - scrollTest(0,6,-2," 23 ","23 "); - scrollTest(1,1,-1," 23 "," 23 "); - scrollTest(1,2,-1," 23 "," 2 3 "); - scrollTest(5,1,-1," 23 "," 23 "); - scrollTest(5,1,-1," 23 "," 23 "); + scrollTest(0, 2, -1, " 23 ", " 23 "); + scrollTest(0, 1, -1, " 23 ", " 23 "); + scrollTest(0, 6, -1, " 23 ", " 23 "); + scrollTest(0, 6, -6, " 23 ", " "); + scrollTest(0, 6, -7, " 23 ", " "); + scrollTest(0, 6, -8, " 23 ", " "); + scrollTest(0, 6, -2, " 23 ", "23 "); + scrollTest(1, 1, -1, " 23 ", " 23 "); + scrollTest(1, 2, -1, " 23 ", " 2 3 "); + scrollTest(5, 1, -1, " 23 ", " 23 "); + scrollTest(5, 1, -1, " 23 ", " 23 "); } + public void testScrollNegative3() { - scrollTest(1,5,-7,"012345","0 "); + scrollTest(1, 5, -7, "012345", "0 "); } + public void testScrollPositive2() { - scrollTest(2,8,20, "0123456789", "01 "); + scrollTest(2, 8, 20, "0123456789", "01 "); } + public void testScrollPositive() { - scrollTest(0,2,1, "012345", " 02345"); - scrollTest(0,2,2, "012345", " 2345"); - scrollTest(2,4,2, "012345", "01 23"); - scrollTest(2,4,2, "0123456", "01 236"); - scrollTest(0,7,6, "0123456", " 0"); - scrollTest(0,7,8, "0123456", " "); - scrollTest(0,7,9, "0123456", " "); - scrollTest(2,4,2, "0123456", "01 236"); - scrollTest(2,5,3, "0123456789", "01 23789"); - scrollTest(2,7,3, "0123456789", "01 23459"); - scrollTest(2,8,3, "0123456789", "01 23456"); - scrollTest(2,8,5, "0123456789", "01 234"); - scrollTest(2,8,9, "0123456789", "01 "); - scrollTest(0,10,9,"0123456789", " 0"); - scrollTest(0,6,6, "012345", " "); + scrollTest(0, 2, 1, "012345", " 02345"); + scrollTest(0, 2, 2, "012345", " 2345"); + scrollTest(2, 4, 2, "012345", "01 23"); + scrollTest(2, 4, 2, "0123456", "01 236"); + scrollTest(0, 7, 6, "0123456", " 0"); + scrollTest(0, 7, 8, "0123456", " "); + scrollTest(0, 7, 9, "0123456", " "); + scrollTest(2, 4, 2, "0123456", "01 236"); + scrollTest(2, 5, 3, "0123456789", "01 23789"); + scrollTest(2, 7, 3, "0123456789", "01 23459"); + scrollTest(2, 8, 3, "0123456789", "01 23456"); + scrollTest(2, 8, 5, "0123456789", "01 234"); + scrollTest(2, 8, 9, "0123456789", "01 "); + scrollTest(0, 10, 9, "0123456789", " 0"); + scrollTest(0, 6, 6, "012345", " "); } + public void testScrollFail() { try { - scrollTest(5,2,-1,"012345","012345"); + scrollTest(5, 2, -1, "012345", "012345"); fail(); } catch (RuntimeException e) { } try { - scrollTest(0,7,1,"012345"," "); + scrollTest(0, 7, 1, "012345", " "); fail(); } catch (RuntimeException e) { } } + /** * Makes a simple shift test * @param line scroll start @@ -808,17 +690,17 @@ abstract public class AbstractITerminalTextDataTest extends TestCase { * @param start the original data * @param result the expected result */ - void scrollTest(int line,int n, int shift, String start,String result) { - ITerminalTextData term=makeITerminalTextData(); - fillSimple(term,start); + void scrollTest(int line, int n, int shift, String start, String result) { + ITerminalTextData term = makeITerminalTextData(); + fillSimple(term, start); term.scroll(line, n, shift); assertEqualsSimple(result, toSimple(term)); } - + public void testWrappedLines() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(4, 4); - for (int i=0; i=windowStart && i= windowStart && i < windowStart + windowSize; assertEquals(e, changes.hasLineChanged(i)); } - + } + public void testMarkLinesChanged() { - SnapshotChanges changes=new SnapshotChanges(2,3); + SnapshotChanges changes = new SnapshotChanges(2, 3); assertFalse(changes.hasChanged()); assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine()); assertEquals(-1, changes.getLastChangedLine()); @@ -227,92 +233,91 @@ public class SnapshotChangesTest extends TestCase { assertEquals(2, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00100000000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(1, 3); assertTrue(changes.hasChanged()); assertEquals(2, changes.getFirstChangedLine()); assertEquals(3, changes.getLastChangedLine()); assertChangedLines(changes, "00110000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(1, 4); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(1, 4); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(2, 4); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(3, 4); assertEquals(3, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00011000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(3, 1); assertEquals(3, changes.getFirstChangedLine()); assertEquals(3, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00010000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(4, 1); assertEquals(4, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00001000000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.markLinesChanged(5, 1); assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine()); assertEquals(-1, changes.getLastChangedLine()); assertFalse(changes.hasChanged()); assertChangedLines(changes, "00000000000"); } + public void testMarkLinesChangedNoWindow() { - SnapshotChanges changes=new SnapshotChanges(10); + SnapshotChanges changes = new SnapshotChanges(10); assertFalse(changes.hasChanged()); assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine()); assertEquals(-1, changes.getLastChangedLine()); - + changes.markLinesChanged(0, 1); assertTrue(changes.hasChanged()); assertEquals(0, changes.getFirstChangedLine()); assertEquals(0, changes.getLastChangedLine()); assertChangedLines(changes, "1000000000"); - - changes=new SnapshotChanges(10); + + changes = new SnapshotChanges(10); changes.markLinesChanged(0, 5); assertTrue(changes.hasChanged()); assertEquals(0, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertChangedLines(changes, "1111100000"); - changes=new SnapshotChanges(3); + changes = new SnapshotChanges(3); changes.markLinesChanged(1, 6); assertTrue(changes.hasChanged()); assertEquals(1, changes.getFirstChangedLine()); assertEquals(6, changes.getLastChangedLine()); assertChangedLines(changes, "011"); - - changes=new SnapshotChanges(10); + changes = new SnapshotChanges(10); changes.markLinesChanged(5, 6); assertTrue(changes.hasChanged()); assertEquals(5, changes.getFirstChangedLine()); @@ -322,61 +327,62 @@ public class SnapshotChangesTest extends TestCase { } public void testHasChanged() { - SnapshotChanges changes=new SnapshotChanges(0); + SnapshotChanges changes = new SnapshotChanges(0); assertFalse(changes.hasChanged()); - changes=new SnapshotChanges(1); + changes = new SnapshotChanges(1); assertFalse(changes.hasChanged()); - changes=new SnapshotChanges(1,9); + changes = new SnapshotChanges(1, 9); assertFalse(changes.hasChanged()); } public void testSetAllChanged() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.setAllChanged(10); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.setAllChanged(3); assertEquals(2, changes.getFirstChangedLine()); assertEquals(2, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.setAllChanged(4); assertEquals(2, changes.getFirstChangedLine()); assertEquals(3, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.setAllChanged(5); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.setAllChanged(6); assertEquals(2, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "00111000000"); } + public void testSetAllChangedNoWindow() { SnapshotChanges changes; - changes=new SnapshotChanges(5); + changes = new SnapshotChanges(5); changes.setAllChanged(10); assertEquals(0, changes.getFirstChangedLine()); assertEquals(9, changes.getLastChangedLine()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "1111111111"); - changes=new SnapshotChanges(5); + changes = new SnapshotChanges(5); changes.setAllChanged(3); assertEquals(0, changes.getFirstChangedLine()); assertEquals(2, changes.getLastChangedLine()); @@ -387,7 +393,7 @@ public class SnapshotChangesTest extends TestCase { public void testConvertScrollingIntoChanges() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.scroll(0, 4, -1); assertTrue(changes.hasChanged()); assertChangedLines(changes, "000100"); @@ -402,7 +408,7 @@ public class SnapshotChangesTest extends TestCase { public void testConvertScrollingIntoChangesNoWindow() { SnapshotChanges changes; - changes=new SnapshotChanges(7); + changes = new SnapshotChanges(7); changes.scroll(0, 4, -1); assertTrue(changes.hasChanged()); assertChangedLines(changes, "000100"); @@ -414,9 +420,10 @@ public class SnapshotChangesTest extends TestCase { assertEquals(0, changes.getScrollWindowShift()); assertChangedLines(changes, "111100"); } + public void testScrollNoWindow() { SnapshotChanges changes; - changes=new SnapshotChanges(7); + changes = new SnapshotChanges(7); changes.scroll(0, 3, -2); assertEquals(1, changes.getFirstChangedLine()); assertEquals(2, changes.getLastChangedLine()); @@ -426,7 +433,7 @@ public class SnapshotChangesTest extends TestCase { assertTrue(changes.hasChanged()); assertChangedLines(changes, "0110000"); - changes=new SnapshotChanges(7); + changes = new SnapshotChanges(7); changes.scroll(0, 3, -1); changes.scroll(0, 3, -1); assertEquals(1, changes.getFirstChangedLine()); @@ -436,8 +443,8 @@ public class SnapshotChangesTest extends TestCase { assertEquals(-2, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0110000"); - - changes=new SnapshotChanges(7); + + changes = new SnapshotChanges(7); changes.scroll(0, 7, -1); changes.scroll(0, 7, -1); assertEquals(5, changes.getFirstChangedLine()); @@ -447,9 +454,9 @@ public class SnapshotChangesTest extends TestCase { assertEquals(-2, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0000011"); - + // positive scrolls cannot be optimized at the moment - changes=new SnapshotChanges(7); + changes = new SnapshotChanges(7); changes.scroll(0, 7, 1); changes.scroll(0, 7, 1); assertEquals(0, changes.getFirstChangedLine()); @@ -461,9 +468,10 @@ public class SnapshotChangesTest extends TestCase { assertChangedLines(changes, "1111111"); } + public void testScroll() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.scroll(0, 7, -1); assertEquals(4, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); @@ -473,7 +481,7 @@ public class SnapshotChangesTest extends TestCase { assertTrue(changes.hasChanged()); assertChangedLines(changes, "0000100000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.scroll(0, 7, -2); assertEquals(3, changes.getFirstChangedLine()); assertEquals(4, changes.getLastChangedLine()); @@ -483,9 +491,10 @@ public class SnapshotChangesTest extends TestCase { assertTrue(changes.hasChanged()); assertChangedLines(changes, "0001100000"); } + public void testScrollNergative() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.scroll(0, 7, -1); changes.scroll(0, 7, -1); assertEquals(3, changes.getFirstChangedLine()); @@ -495,11 +504,12 @@ public class SnapshotChangesTest extends TestCase { assertEquals(-2, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0001100000"); - + } + public void testScrollPositive() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.scroll(0, 7, 1); changes.scroll(0, 7, 1); assertEquals(2, changes.getFirstChangedLine()); @@ -509,8 +519,8 @@ public class SnapshotChangesTest extends TestCase { assertEquals(0, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0011100000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.scroll(0, 3, 1); changes.scroll(0, 3, 1); assertEquals(2, changes.getFirstChangedLine()); @@ -520,8 +530,8 @@ public class SnapshotChangesTest extends TestCase { assertEquals(0, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0010000000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.scroll(0, 4, 1); changes.scroll(0, 4, 1); assertEquals(2, changes.getFirstChangedLine()); @@ -531,8 +541,8 @@ public class SnapshotChangesTest extends TestCase { assertEquals(0, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0011000000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.scroll(0, 5, 1); changes.scroll(0, 5, 1); assertEquals(2, changes.getFirstChangedLine()); @@ -542,8 +552,8 @@ public class SnapshotChangesTest extends TestCase { assertEquals(0, changes.getScrollWindowShift()); assertTrue(changes.hasChanged()); assertChangedLines(changes, "0011100000"); - - changes=new SnapshotChanges(2,3); + + changes = new SnapshotChanges(2, 3); changes.scroll(3, 5, 1); changes.scroll(3, 5, 1); assertEquals(3, changes.getFirstChangedLine()); @@ -557,125 +567,126 @@ public class SnapshotChangesTest extends TestCase { public void testCopyChangedLines() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLineChanged(3); - ITerminalTextData source=new TerminalTextDataStore(); + ITerminalTextData source = new TerminalTextDataStore(); TerminalTextTestHelper.fillSimple(source, "01234567890"); - ITerminalTextData dest=new TerminalTextDataStore(); + ITerminalTextData dest = new TerminalTextDataStore(); TerminalTextTestHelper.fillSimple(dest, "abcdefghijk"); - - changes.copyChangedLines(dest, source); - assertEquals("abc3efghijk",TerminalTextTestHelper.toSimple(dest)); - - changes=new SnapshotChanges(2,3); - changes.setAllChanged(7); - source=new TerminalTextDataStore(); - TerminalTextTestHelper.fillSimple(source, "01234567890"); - dest=new TerminalTextDataStore(); - TerminalTextTestHelper.fillSimple(dest, "abcdefghijk"); - - changes.copyChangedLines(dest, source); - assertEquals("ab234fghijk",TerminalTextTestHelper.toSimple(dest)); - changes=new SnapshotChanges(2,3); - changes.scroll(0,7,-1); - source=new TerminalTextDataStore(); + changes.copyChangedLines(dest, source); + assertEquals("abc3efghijk", TerminalTextTestHelper.toSimple(dest)); + + changes = new SnapshotChanges(2, 3); + changes.setAllChanged(7); + source = new TerminalTextDataStore(); TerminalTextTestHelper.fillSimple(source, "01234567890"); - dest=new TerminalTextDataStore(); + dest = new TerminalTextDataStore(); + TerminalTextTestHelper.fillSimple(dest, "abcdefghijk"); + + changes.copyChangedLines(dest, source); + assertEquals("ab234fghijk", TerminalTextTestHelper.toSimple(dest)); + + changes = new SnapshotChanges(2, 3); + changes.scroll(0, 7, -1); + source = new TerminalTextDataStore(); + TerminalTextTestHelper.fillSimple(source, "01234567890"); + dest = new TerminalTextDataStore(); TerminalTextTestHelper.fillSimple(dest, "abcdefghijk"); // only one line has changed! The other lines are scrolled! - assertChangedLines(changes,"00001000"); + assertChangedLines(changes, "00001000"); changes.copyChangedLines(dest, source); - assertEquals("abcd4fghijk",TerminalTextTestHelper.toSimple(dest)); + assertEquals("abcd4fghijk", TerminalTextTestHelper.toSimple(dest)); } + public void testCopyChangedLinesWithSmallSource() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLineChanged(3); - ITerminalTextData source=new TerminalTextDataStore(); + ITerminalTextData source = new TerminalTextDataStore(); source.setDimensions(2, 2); - TerminalTextDataWindow dest=new TerminalTextDataWindow(); + TerminalTextDataWindow dest = new TerminalTextDataWindow(); dest.setWindow(2, 2); changes.copyChangedLines(dest, source); } + public void testCopyChangedLinesWithSmallSource1() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); changes.markLineChanged(3); - ITerminalTextData source=new TerminalTextDataStore(); + ITerminalTextData source = new TerminalTextDataStore(); TerminalTextTestHelper.fillSimple(source, "01"); - ITerminalTextData dest=new TerminalTextDataStore(); + ITerminalTextData dest = new TerminalTextDataStore(); changes.copyChangedLines(dest, source); } public void testSetInterestWindowSize() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // move the window changes.setInterestWindow(3, 3); // only one line has changed! The other lines are scrolled! assertEquals(3, changes.getScrollWindowStartLine()); assertEquals(3, changes.getScrollWindowSize()); assertEquals(-1, changes.getScrollWindowShift()); - - assertChangedLines(changes,"0000010"); - changes.convertScrollingIntoChanges(); - assertChangedLines(changes,"0001110"); - changes=new SnapshotChanges(2,3); + assertChangedLines(changes, "0000010"); + changes.convertScrollingIntoChanges(); + assertChangedLines(changes, "0001110"); + + changes = new SnapshotChanges(2, 3); // move the window changes.setInterestWindow(3, 4); // only one line has changed! The other lines are scrolled! assertEquals(3, changes.getScrollWindowStartLine()); assertEquals(3, changes.getScrollWindowSize()); assertEquals(-1, changes.getScrollWindowShift()); - - assertChangedLines(changes,"0000011"); - changes.convertScrollingIntoChanges(); - assertChangedLines(changes,"0001111"); - - changes=new SnapshotChanges(2,3); + assertChangedLines(changes, "0000011"); + changes.convertScrollingIntoChanges(); + assertChangedLines(changes, "0001111"); + + changes = new SnapshotChanges(2, 3); // move the window changes.setInterestWindow(6, 3); // cannot scroll assertEquals(0, changes.getScrollWindowStartLine()); assertEquals(0, changes.getScrollWindowSize()); assertEquals(0, changes.getScrollWindowShift()); - assertChangedLines(changes,"000000111000"); + assertChangedLines(changes, "000000111000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // expand the window changes.setInterestWindow(2, 5); // cannot scroll assertEquals(0, changes.getScrollWindowStartLine()); assertEquals(0, changes.getScrollWindowSize()); assertEquals(0, changes.getScrollWindowShift()); - - assertChangedLines(changes,"0000011000"); + + assertChangedLines(changes, "0000011000"); } + public void testSetInterestWindowSize2() { SnapshotChanges changes; - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // move the window changes.setInterestWindow(1, 3); - assertChangedLines(changes,"0111000"); + assertChangedLines(changes, "0111000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // move the window changes.setInterestWindow(1, 4); - assertChangedLines(changes,"01111000"); + assertChangedLines(changes, "01111000"); - - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // expand the window changes.setInterestWindow(6, 3); - assertChangedLines(changes,"000000111000"); + assertChangedLines(changes, "000000111000"); - changes=new SnapshotChanges(2,3); + changes = new SnapshotChanges(2, 3); // expand the window changes.setInterestWindow(1, 2); - assertChangedLines(changes,"0110000"); + assertChangedLines(changes, "0110000"); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/SynchronizedTerminalTextDataTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/SynchronizedTerminalTextDataTest.java index e1ab3c90b3d..6086f4adc66 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/SynchronizedTerminalTextDataTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/SynchronizedTerminalTextDataTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTest.java index 2b4316ed52a..82b6185923a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTestMaxHeigth.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTestMaxHeigth.java index f89f9476f1c..1cb7ab81401 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTestMaxHeigth.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataFastScrollTestMaxHeigth.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataPerformanceTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataPerformanceTest.java index 71fc1eebb6b..7bb45b26bc2 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataPerformanceTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataPerformanceTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; @@ -18,204 +18,229 @@ import org.eclipse.tm.terminal.model.Style; import org.eclipse.tm.terminal.model.StyleColor; public class TerminalTextDataPerformanceTest extends TestCase { - long TIME=100; + long TIME = 100; + private void initPerformance(ITerminalTextData term) { - term.setDimensions(300,200); + term.setDimensions(300, 200); } + public void testPerformance0() { - ITerminalTextData term=new TerminalTextData(); - method0(term,"0 "); + ITerminalTextData term = new TerminalTextData(); + method0(term, "0 "); } + public void testPerformance0a() { - ITerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); - method0(term,"0a"); + ITerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); + method0(term, "0a"); snapshot.updateSnapshot(true); } + public void testPerformance0b() { - ITerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); - N=0; - snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener(){ + ITerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); + N = 0; + snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() { public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) { N++; - }}); - method0(term,"0b"); + } + }); + method0(term, "0b"); snapshot.updateSnapshot(true); } + private void method0(ITerminalTextData term, String label) { - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { - char c=s.charAt(i%s.length()); + char c = s.charAt(i % s.length()); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { term.setChar(line, column, c, style); n++; } } - if(System.currentTimeMillis()-t0>TIME) { - System.out.println(label+" "+(n*1000)/(System.currentTimeMillis()-t0)+" setChar()/sec "+ N); + if (System.currentTimeMillis() - t0 > TIME) { + System.out + .println(label + " " + (n * 1000) / (System.currentTimeMillis() - t0) + " setChar()/sec " + N); break; } } } + public void testPerformance1() { - ITerminalTextData term=new TerminalTextData(); + ITerminalTextData term = new TerminalTextData(); method1(term, "1 "); } + public void testPerformance1a() { - ITerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); method1(term, "1a"); snapshot.updateSnapshot(true); } + public void testPerformance1b() { - ITerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); - N=0; - snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener(){ + ITerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); + N = 0; + snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() { public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) { N++; - }}); + } + }); method1(term, "1b"); snapshot.updateSnapshot(true); } + private void method1(ITerminalTextData term, String label) { - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); - char[] chars=new char[term.getWidth()]; + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); + char[] chars = new char[term.getWidth()]; for (int i = 0; i < 10000000; i++) { for (int j = 0; j < chars.length; j++) { - chars[j]=s.charAt((i+j)%s.length()); + chars[j] = s.charAt((i + j) % s.length()); } for (int line = 0; line < term.getHeight(); line++) { term.setChars(line, 0, chars, style); - n+=chars.length; + n += chars.length; } - if(System.currentTimeMillis()-t0>TIME) { - System.out.println(label+" "+(n*1000)/(System.currentTimeMillis()-t0)+" setChars()/sec "+ N); + if (System.currentTimeMillis() - t0 > TIME) { + System.out + .println(label + " " + (n * 1000) / (System.currentTimeMillis() - t0) + " setChars()/sec " + N); break; } } } + public void testPerformance2() { - TerminalTextData term=new TerminalTextData(); - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + TerminalTextData term = new TerminalTextData(); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - TerminalTextData copy=new TerminalTextData(); + TerminalTextData copy = new TerminalTextData(); copy.copy(term); - - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); - char[] chars=new char[term.getWidth()]; + + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); + char[] chars = new char[term.getWidth()]; for (int i = 0; i < 10000000; i++) { for (int j = 0; j < chars.length; j++) { - chars[j]=s.charAt((i+j)%s.length()); + chars[j] = s.charAt((i + j) % s.length()); } for (int line = 0; line < term.getHeight(); line++) { - term.setChars(line, 0, chars, 0,1,style); + term.setChars(line, 0, chars, 0, 1, style); copy.copy(term); - n+=1; - if(System.currentTimeMillis()-t0>TIME) { - System.out.println((n*1000)/(System.currentTimeMillis()-t0)+" copy()/sec"); + n += 1; + if (System.currentTimeMillis() - t0 > TIME) { + System.out.println((n * 1000) / (System.currentTimeMillis() - t0) + " copy()/sec"); return; } } } } + public void testPerformance2a() { - TerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + TerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - TerminalTextData copy=new TerminalTextData(); + TerminalTextData copy = new TerminalTextData(); copy.copy(term); - - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); - char[] chars=new char[term.getWidth()]; + + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); + char[] chars = new char[term.getWidth()]; for (int i = 0; i < 10000000; i++) { for (int j = 0; j < chars.length; j++) { - chars[j]=s.charAt((i+j)%s.length()); + chars[j] = s.charAt((i + j) % s.length()); } for (int line = 0; line < term.getHeight(); line++) { - term.setChars(line, 0, chars, 0,1,style); + term.setChars(line, 0, chars, 0, 1, style); copy.copy(term); - n+=1; - if(System.currentTimeMillis()-t0>TIME) { - System.out.println((n*1000)/(System.currentTimeMillis()-t0)+" copy()/sec"); + n += 1; + if (System.currentTimeMillis() - t0 > TIME) { + System.out.println((n * 1000) / (System.currentTimeMillis() - t0) + " copy()/sec"); return; } } } snapshot.updateSnapshot(true); } - int N=0; + + int N = 0; + public void testPerformance2b() { - TerminalTextData term=new TerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); - N=0; - snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener(){ + TerminalTextData term = new TerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); + N = 0; + snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() { public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) { N++; - }}); - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + } + }); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - TerminalTextData copy=new TerminalTextData(); + TerminalTextData copy = new TerminalTextData(); copy.copy(term); - - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); - char[] chars=new char[term.getWidth()]; + + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); + char[] chars = new char[term.getWidth()]; for (int i = 0; i < 10000000; i++) { for (int j = 0; j < chars.length; j++) { - chars[j]=s.charAt((i+j)%s.length()); + chars[j] = s.charAt((i + j) % s.length()); } for (int line = 0; line < term.getHeight(); line++) { - term.setChars(line, 0, chars, 0,1,style); + term.setChars(line, 0, chars, 0, 1, style); copy.copy(term); - n+=1; - if(System.currentTimeMillis()-t0>TIME) { - System.out.println((n*1000)/(System.currentTimeMillis()-t0)+" copy()/sec "+n); + n += 1; + if (System.currentTimeMillis() - t0 > TIME) { + System.out.println((n * 1000) / (System.currentTimeMillis() - t0) + " copy()/sec " + n); return; } } } snapshot.updateSnapshot(true); } + public void testPerformance3() { - TerminalTextData term=new TerminalTextData(); - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + TerminalTextData term = new TerminalTextData(); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); initPerformance(term); - TerminalTextData copy=new TerminalTextData(); + TerminalTextData copy = new TerminalTextData(); copy.copy(term); - String s="This is a test string"; - long n=0; - long t0=System.currentTimeMillis(); - char[] chars=new char[term.getWidth()]; + String s = "This is a test string"; + long n = 0; + long t0 = System.currentTimeMillis(); + char[] chars = new char[term.getWidth()]; for (int i = 0; i < 10000000; i++) { - boolean[] linesToCopy=new boolean[term.getHeight()]; + boolean[] linesToCopy = new boolean[term.getHeight()]; for (int j = 0; j < chars.length; j++) { - chars[j]=s.charAt((i+j)%s.length()); + chars[j] = s.charAt((i + j) % s.length()); } for (int line = 0; line < term.getHeight(); line++) { - term.setChars(line, 0, chars, 0,1,style); - linesToCopy[line]=true; - copy.copyLine(term,0,0); - linesToCopy[line]=false; - n+=1; - if(System.currentTimeMillis()-t0>TIME) { - System.out.println((n*1000)/(System.currentTimeMillis()-t0)+" copy()/sec"); + term.setChars(line, 0, chars, 0, 1, style); + linesToCopy[line] = true; + copy.copyLine(term, 0, 0); + linesToCopy[line] = false; + n += 1; + if (System.currentTimeMillis() - t0 > TIME) { + System.out.println((n * 1000) / (System.currentTimeMillis() - t0) + " copy()/sec"); return; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotTest.java index 7f5b27de933..99d8116f633 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; @@ -27,24 +27,19 @@ public class TerminalTextDataSnapshotTest extends TestCase { return new TerminalTextData(); } - public void testTerminalTextDataSnapshot() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); assertEquals(toMultiLineText(term), toMultiLineText(snapshot)); - + // new snapshots are fully changed - assertEquals(0,snapshot.getFirstChangedLine()); - assertEquals(term.getHeight()-1,snapshot.getLastChangedLine()); + assertEquals(0, snapshot.getFirstChangedLine()); + assertEquals(term.getHeight() - 1, snapshot.getLastChangedLine()); for (int line = 0; line <= snapshot.getLastChangedLine(); line++) { assertTrue(snapshot.hasLineChanged(line)); } @@ -53,18 +48,14 @@ public class TerminalTextDataSnapshotTest extends TestCase { } public void testDetach() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - assertEquals(toMultiLineText(term),toMultiLineText(snapshot)); + assertEquals(toMultiLineText(term), toMultiLineText(snapshot)); snapshot.detach(); // after detach changes to the term has no effect term.setChar(0, 0, '?', null); @@ -72,42 +63,39 @@ public class TerminalTextDataSnapshotTest extends TestCase { term.setDimensions(2, 2); assertEquals(s, toMultiLineText(snapshot)); } + public void testIsOutOfDate() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + // make a change and expect it to be changed term.setChar(0, 0, '?', null); assertTrue(snapshot.isOutOfDate()); - + snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + // make a change and expect it to be changed - term.setChars(1, 1, new char[]{'?','!','.'},null); + term.setChars(1, 1, new char[] { '?', '!', '.' }, null); assertTrue(snapshot.isOutOfDate()); - + snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + // scroll term.scroll(1, 2, -1); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + // scroll term.scroll(1, 2, 1); assertTrue(snapshot.isOutOfDate()); @@ -121,131 +109,124 @@ public class TerminalTextDataSnapshotTest extends TestCase { snapshot.updateSnapshot(true); assertFalse(snapshot.isOutOfDate()); - + // scroll term.scroll(1, 2, 1); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(true); assertFalse(snapshot.isOutOfDate()); - + // setDimensions term.setDimensions(2, 2); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + // setDimensions term.setDimensions(20, 20); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); - + } + ITerminalTextDataSnapshot snapshot(String text, ITerminalTextData term) { - TerminalTextTestHelper.fill(term,text); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + TerminalTextTestHelper.fill(term, text); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); return snapshot; - + } + public void testUpdateSnapshot() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - String termString=toMultiLineText(term); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + String termString = toMultiLineText(term); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - assertEquals(termString,toMultiLineText(snapshot)); - + assertEquals(termString, toMultiLineText(snapshot)); + // make changes and assert that the snapshot has not changed // then update the snapshot and expect it to be the // same as the changed terminal - - // make a change + + // make a change term.setChar(0, 0, '?', null); - assertEquals(termString,toMultiLineText(snapshot)); - + assertEquals(termString, toMultiLineText(snapshot)); + snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - - // make a change - term.setChars(1, 1, new char[]{'?','!','.'},null); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + + // make a change + term.setChars(1, 1, new char[] { '?', '!', '.' }, null); + assertEquals(termString, toMultiLineText(snapshot)); + snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + // scroll term.scroll(1, 2, -1); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + // scroll term.scroll(1, 2, 1); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + // scroll term.scroll(1, 2, -1); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(true); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + // scroll term.scroll(1, 2, 1); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(true); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); - + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); + // set dimensions term.setDimensions(2, 2); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); // set dimensions term.setDimensions(20, 20); - assertEquals(termString,toMultiLineText(snapshot)); + assertEquals(termString, toMultiLineText(snapshot)); snapshot.updateSnapshot(false); - termString=toMultiLineText(term); - assertEquals(termString,toMultiLineText(snapshot)); + termString = toMultiLineText(term); + assertEquals(termString, toMultiLineText(snapshot)); } public void testMaxSize() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); term.setMaxHeight(8); TerminalTextTestHelper.fill(term, s); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); term.addLine(); @@ -275,321 +256,284 @@ public class TerminalTextDataSnapshotTest extends TestCase { } - public void testGetChar() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - ITerminalTextData termUnchanged=makeITerminalTextData(); - TerminalTextTestHelper.fill(termUnchanged,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + ITerminalTextData termUnchanged = makeITerminalTextData(); + TerminalTextTestHelper.fill(termUnchanged, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); for (int line = 0; line < snapshot.getHeight(); line++) { for (int column = 0; column < snapshot.getWidth(); column++) { - assertEquals(term.getChar(line, column),snapshot.getChar(line, column)); + assertEquals(term.getChar(line, column), snapshot.getChar(line, column)); } } - // make a change + // make a change term.setChar(0, 0, '?', null); // check against unchanged data for (int line = 0; line < snapshot.getHeight(); line++) { for (int column = 0; column < snapshot.getWidth(); column++) { - assertEquals(termUnchanged.getChar(line, column),snapshot.getChar(line, column)); + assertEquals(termUnchanged.getChar(line, column), snapshot.getChar(line, column)); } } // update and compare against the terminal snapshot.updateSnapshot(true); for (int line = 0; line < snapshot.getHeight(); line++) { for (int column = 0; column < snapshot.getWidth(); column++) { - assertEquals(term.getChar(line, column),snapshot.getChar(line, column)); + assertEquals(term.getChar(line, column), snapshot.getChar(line, column)); } } - + } public void testGetHeight() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - int expectedHeight=term.getHeight(); + int expectedHeight = term.getHeight(); assertEquals(expectedHeight, snapshot.getHeight()); - term.setDimensions(term.getHeight()-1, term.getWidth()); + term.setDimensions(term.getHeight() - 1, term.getWidth()); assertEquals(expectedHeight, snapshot.getHeight()); - + // snapshot.updateSnapshot(false); - expectedHeight=term.getHeight(); + expectedHeight = term.getHeight(); assertEquals(expectedHeight, snapshot.getHeight()); - term.setDimensions(term.getHeight()-1, term.getWidth()); + term.setDimensions(term.getHeight() - 1, term.getWidth()); assertEquals(expectedHeight, snapshot.getHeight()); } -// -// public void testGetLineSegments() { -// fail("Not yet implemented"); -// } -// + + // + // public void testGetLineSegments() { + // fail("Not yet implemented"); + // } + // public void testGetStyle() { - ITerminalTextData term=makeITerminalTextData(); - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + ITerminalTextData term = makeITerminalTextData(); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor(""+c))); + char c = (char) ('a' + column + line); + term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor("" + c))); } } - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - assertSame(style.setForground(StyleColor.getStyleColor(""+c)), snapshot.getStyle(line, column)); + char c = (char) ('a' + column + line); + assertSame(style.setForground(StyleColor.getStyleColor("" + c)), snapshot.getStyle(line, column)); } } - + } public void testGetWidth() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - int expectedWidth=term.getWidth(); + int expectedWidth = term.getWidth(); assertEquals(expectedWidth, snapshot.getWidth()); - term.setDimensions(term.getHeight(), term.getWidth()-1); + term.setDimensions(term.getHeight(), term.getWidth() - 1); assertEquals(expectedWidth, snapshot.getWidth()); - + // snapshot.updateSnapshot(false); - expectedWidth=term.getWidth(); + expectedWidth = term.getWidth(); assertEquals(expectedWidth, snapshot.getWidth()); - term.setDimensions(term.getHeight(), term.getWidth()-1); + term.setDimensions(term.getHeight(), term.getWidth() - 1); assertEquals(expectedWidth, snapshot.getWidth()); } public void testGetFirstChangedLine() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - ITerminalTextDataSnapshot snapshot=snapshot(s,term); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + ITerminalTextDataSnapshot snapshot = snapshot(s, term); - assertEquals(0, snapshot.getFirstChangedLine()); - + // if nothing has changed the first changed line i height snapshot.updateSnapshot(false); assertEquals(Integer.MAX_VALUE, snapshot.getFirstChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.setChar(0, 0, 'x', null); snapshot.updateSnapshot(false); assertEquals(0, snapshot.getFirstChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.setChar(3, 0, 'x', null); term.setChar(4, 0, 'x', null); snapshot.updateSnapshot(false); assertEquals(3, snapshot.getFirstChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.scroll(0, 1, -1); snapshot.updateSnapshot(false); assertEquals(0, snapshot.getFirstChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.scroll(2, 2, -1); snapshot.updateSnapshot(false); assertEquals(2, snapshot.getFirstChangedLine()); - + // when scrolling the end of the region 'has changed' - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); term.scroll(2, 2, -1); snapshot.updateSnapshot(true); assertEquals(3, snapshot.getFirstChangedLine()); - + // when scrolling the end of the region 'has changed' - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); term.scroll(2, 2, -1); term.setChar(1, 0, 'x', null); snapshot.updateSnapshot(true); assertEquals(1, snapshot.getFirstChangedLine()); - - } - public void testGetLastChangedLine() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - ITerminalTextDataSnapshot snapshot=snapshot(s,term); - + } + + public void testGetLastChangedLine() { + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + ITerminalTextDataSnapshot snapshot = snapshot(s, term); + assertEquals(4, snapshot.getLastChangedLine()); - + // if nothing has changed the first changed line i height snapshot.updateSnapshot(false); assertEquals(-1, snapshot.getLastChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.setChar(0, 0, 'x', null); snapshot.updateSnapshot(false); assertEquals(0, snapshot.getLastChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.cleanLine(1); snapshot.updateSnapshot(false); assertEquals(1, snapshot.getLastChangedLine()); - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); term.setChar(3, 0, 'x', null); term.setChar(4, 0, 'x', null); snapshot.updateSnapshot(false); assertEquals(4, snapshot.getLastChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.scroll(0, 1, -1); snapshot.updateSnapshot(false); assertEquals(0, snapshot.getLastChangedLine()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.scroll(2, 2, -1); snapshot.updateSnapshot(false); assertEquals(3, snapshot.getLastChangedLine()); - + // when scrolling the end of the region 'has changed' - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); term.scroll(2, 2, -1); snapshot.updateSnapshot(true); assertEquals(3, snapshot.getLastChangedLine()); - + // when scrolling the end of the region 'has changed' - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); term.scroll(2, 2, -1); term.setChar(1, 0, 'x', null); snapshot.updateSnapshot(true); assertEquals(3, snapshot.getLastChangedLine()); - + } + /** * @param snapshot * @param expected a string of 0 and 1 (1 means changed) */ void assertChangedLines(ITerminalTextDataSnapshot snapshot, String expected) { - assertEquals(expected.length(),snapshot.getHeight()); - StringBuffer buffer=new StringBuffer(); + assertEquals(expected.length(), snapshot.getHeight()); + StringBuffer buffer = new StringBuffer(); for (int line = 0; line < expected.length(); line++) { - if(snapshot.hasLineChanged(line)) + if (snapshot.hasLineChanged(line)) buffer.append('1'); else buffer.append('0'); } assertEquals(expected, buffer.toString()); } + public void testHasLineChangedScroll() { - ITerminalTextData term=makeITerminalTextData(); - String s="00\n" + - "11\n" + - "22\n" + - "33\n" + - "44\n" + - "55\n" + - "66\n" + - "77\n" + - "88\n" + - "99"; - ITerminalTextDataSnapshot snapshot=snapshot(s,term); - - term.scroll(2,3,-1); + ITerminalTextData term = makeITerminalTextData(); + String s = "00\n" + "11\n" + "22\n" + "33\n" + "44\n" + "55\n" + "66\n" + "77\n" + "88\n" + "99"; + ITerminalTextDataSnapshot snapshot = snapshot(s, term); + + term.scroll(2, 3, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0000100000"); - - snapshot=snapshot(s,term); - term.scroll(2,3,-2); + + snapshot = snapshot(s, term); + term.scroll(2, 3, -2); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0001100000"); - snapshot=snapshot(s,term); - term.scroll(2,4,-1); - term.scroll(2,4,-1); + snapshot = snapshot(s, term); + term.scroll(2, 4, -1); + term.scroll(2, 4, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0000110000"); - term.scroll(2,3,1); - snapshot.updateSnapshot(true); - assertChangedLines(snapshot, "0011100000"); - - snapshot=snapshot(s,term); - term.scroll(2,3,2); + term.scroll(2, 3, 1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0011100000"); - snapshot=snapshot(s,term); - term.scroll(2,4,1); - term.scroll(2,4,1); + snapshot = snapshot(s, term); + term.scroll(2, 3, 2); + snapshot.updateSnapshot(true); + assertChangedLines(snapshot, "0011100000"); + + snapshot = snapshot(s, term); + term.scroll(2, 4, 1); + term.scroll(2, 4, 1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0011110000"); - - snapshot=snapshot(s,term); - term.scroll(2,3,-1); - snapshot.updateSnapshot(false); - assertChangedLines(snapshot, "0011100000"); - - snapshot=snapshot(s,term); - term.scroll(2,3,-2); + snapshot = snapshot(s, term); + term.scroll(2, 3, -1); snapshot.updateSnapshot(false); assertChangedLines(snapshot, "0011100000"); - snapshot=snapshot(s,term); - term.scroll(2,4,-1); - term.scroll(2,4,-1); + snapshot = snapshot(s, term); + term.scroll(2, 3, -2); + snapshot.updateSnapshot(false); + assertChangedLines(snapshot, "0011100000"); + + snapshot = snapshot(s, term); + term.scroll(2, 4, -1); + term.scroll(2, 4, -1); snapshot.updateSnapshot(false); assertChangedLines(snapshot, "0011110000"); } + public void testMultiScrollWithDifferentSizes() { - ITerminalTextData term=makeITerminalTextData(); - String s="00\n" + - "11\n" + - "22\n" + - "33\n" + - "44\n" + - "55\n" + - "66\n" + - "77\n" + - "88\n" + - "99"; + ITerminalTextData term = makeITerminalTextData(); + String s = "00\n" + "11\n" + "22\n" + "33\n" + "44\n" + "55\n" + "66\n" + "77\n" + "88\n" + "99"; ITerminalTextDataSnapshot snapshot; - snapshot=snapshot(s,term); - term.scroll(2,6,-1); - term.scroll(2,5,-1); + snapshot = snapshot(s, term); + term.scroll(2, 6, -1); + term.scroll(2, 5, -1); snapshot.updateSnapshot(false); assertChangedLines(snapshot, "0011111100"); assertEquals(2, snapshot.getFirstChangedLine()); @@ -597,12 +541,12 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowShift()); - + // scrolls with different ranges cause no scroll // optimization - snapshot=snapshot(s,term); - term.scroll(2,6,-1); - term.scroll(2,5,-1); + snapshot = snapshot(s, term); + term.scroll(2, 6, -1); + term.scroll(2, 5, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0011111100"); assertEquals(2, snapshot.getFirstChangedLine()); @@ -611,80 +555,63 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowStartLine()); } + public void testHasLineChanged() { - ITerminalTextData term=makeITerminalTextData(); - String s="000000\n" + - "111111\n" + - "222222\n" + - "333333\n" + - "444444\n" + - "555555\n" + - "666666\n" + - "777777\n" + - "888888\n" + - "999999"; + ITerminalTextData term = makeITerminalTextData(); + String s = "000000\n" + "111111\n" + "222222\n" + "333333\n" + "444444\n" + "555555\n" + "666666\n" + "777777\n" + + "888888\n" + "999999"; ITerminalTextDataSnapshot snapshot; - - snapshot=snapshot(s,term); - term.scroll(2,3,-1); + + snapshot = snapshot(s, term); + term.scroll(2, 3, -1); term.setChar(7, 0, '.', null); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0000100100"); - - snapshot=snapshot(s,term); - term.scroll(2,3,-2); + + snapshot = snapshot(s, term); + term.scroll(2, 3, -2); term.setChar(9, 0, '.', null); - term.setChars(0, 0, new char[]{'.','!'}, null); + term.setChars(0, 0, new char[] { '.', '!' }, null); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1001100001"); - snapshot=snapshot(s,term); - term.scroll(2,4,-1); - term.scroll(2,4,-1); - term.setChars(2, 2, new char[]{'.','!','*'},1,1, null); + snapshot = snapshot(s, term); + term.scroll(2, 4, -1); + term.scroll(2, 4, -1); + term.setChars(2, 2, new char[] { '.', '!', '*' }, 1, 1, null); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0010110000"); - snapshot=snapshot(s,term); - term.scroll(2,7,-1); + snapshot = snapshot(s, term); + term.scroll(2, 7, -1); term.setChar(5, 2, '.', null); - term.scroll(2,7,-2); + term.scroll(2, 7, -2); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0001001110"); - - snapshot=snapshot(s,term); - term.scroll(2,7,-1); + snapshot = snapshot(s, term); + term.scroll(2, 7, -1); term.setChar(5, 2, '.', null); - term.scroll(2,7,-2); + term.scroll(2, 7, -2); snapshot.updateSnapshot(false); assertChangedLines(snapshot, "0011111110"); } public void testScroll() { - ITerminalTextData term=makeITerminalTextData(); - String s="00\n" + - "11\n" + - "22\n" + - "33\n" + - "44\n" + - "55\n" + - "66\n" + - "77\n" + - "88\n" + - "99"; - ITerminalTextDataSnapshot snapshot=snapshot(s,term); - - term.scroll(2,3,-1); + ITerminalTextData term = makeITerminalTextData(); + String s = "00\n" + "11\n" + "22\n" + "33\n" + "44\n" + "55\n" + "66\n" + "77\n" + "88\n" + "99"; + ITerminalTextDataSnapshot snapshot = snapshot(s, term); + + term.scroll(2, 3, -1); snapshot.updateSnapshot(true); assertEquals(2, snapshot.getScrollWindowStartLine()); assertEquals(3, snapshot.getScrollWindowSize()); assertEquals(-1, snapshot.getScrollWindowShift()); assertEquals(4, snapshot.getFirstChangedLine()); assertEquals(4, snapshot.getLastChangedLine()); - - term.scroll(2,3,-2); + + term.scroll(2, 3, -2); snapshot.updateSnapshot(true); assertEquals(2, snapshot.getScrollWindowStartLine()); assertEquals(3, snapshot.getScrollWindowSize()); @@ -692,8 +619,8 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(3, snapshot.getFirstChangedLine()); assertEquals(4, snapshot.getLastChangedLine()); - term.scroll(2,4,-1); - term.scroll(2,4,-1); + term.scroll(2, 4, -1); + term.scroll(2, 4, -1); snapshot.updateSnapshot(true); assertEquals(2, snapshot.getScrollWindowStartLine()); assertEquals(4, snapshot.getScrollWindowSize()); @@ -701,88 +628,78 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(4, snapshot.getFirstChangedLine()); assertEquals(5, snapshot.getLastChangedLine()); - - snapshot=snapshot(s,term); - term.scroll(2,3,-1); + snapshot = snapshot(s, term); + term.scroll(2, 3, -1); snapshot.updateSnapshot(false); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); assertEquals(2, snapshot.getFirstChangedLine()); assertEquals(4, snapshot.getLastChangedLine()); - + } + public void testDisjointScroll() { - ITerminalTextData term=makeITerminalTextData(); - String s="000000\n" + - "111111\n" + - "222222\n" + - "333333\n" + - "444444\n" + - "555555\n" + - "666666\n" + - "777777\n" + - "888888\n" + - "999999"; + ITerminalTextData term = makeITerminalTextData(); + String s = "000000\n" + "111111\n" + "222222\n" + "333333\n" + "444444\n" + "555555\n" + "666666\n" + "777777\n" + + "888888\n" + "999999"; ITerminalTextDataSnapshot snapshot; - - snapshot=snapshot(s,term); - term.scroll(0,2,-1); - term.scroll(4,2,-1); + + snapshot = snapshot(s, term); + term.scroll(0, 2, -1); + term.scroll(4, 2, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1100110000"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.scroll(0,3,-1); - term.scroll(2,2,-2); + snapshot = snapshot(s, term); + term.scroll(0, 3, -1); + term.scroll(2, 2, -2); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111000000"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.scroll(0,3,-1); - term.scroll(2,2,-2); - term.scroll(0,3,-1); + snapshot = snapshot(s, term); + term.scroll(0, 3, -1); + term.scroll(2, 2, -2); + term.scroll(0, 3, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111000000"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.scroll(0,3,-1); - term.scroll(2,2,-2); - term.scroll(0,3,-10); + snapshot = snapshot(s, term); + term.scroll(0, 3, -1); + term.scroll(2, 2, -2); + term.scroll(0, 3, -10); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111000000"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.scroll(1,3,-1); - term.scroll(1,3,1); + snapshot = snapshot(s, term); + term.scroll(1, 3, -1); + term.scroll(1, 3, 1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "0111000000"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); } + public void testResize() { - ITerminalTextData term=makeITerminalTextData(); - String s="000000\n" + - "111111\n" + - "222222\n" + - "333333"; + ITerminalTextData term = makeITerminalTextData(); + String s = "000000\n" + "111111\n" + "222222\n" + "333333"; ITerminalTextDataSnapshot snapshot; - - snapshot=snapshot(s,term); - term.setDimensions(term.getHeight(), term.getWidth()+1); + + snapshot = snapshot(s, term); + term.setDimensions(term.getHeight(), term.getWidth() + 1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111"); assertEquals(0, snapshot.getFirstChangedLine()); @@ -791,8 +708,8 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.setDimensions(term.getHeight()+1, term.getWidth()); + snapshot = snapshot(s, term); + term.setDimensions(term.getHeight() + 1, term.getWidth()); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "11111"); assertEquals(0, snapshot.getFirstChangedLine()); @@ -800,9 +717,9 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - - snapshot=snapshot(s,term); - term.setDimensions(term.getHeight()-1, term.getWidth()); + + snapshot = snapshot(s, term); + term.setDimensions(term.getHeight() - 1, term.getWidth()); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "111"); assertEquals(0, snapshot.getFirstChangedLine()); @@ -810,8 +727,8 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.setDimensions(0, 0); snapshot.updateSnapshot(true); assertChangedLines(snapshot, ""); @@ -820,24 +737,17 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - + } + public void testResizeAfterScroll() { - ITerminalTextData term=makeITerminalTextData(); - String s="000000\n" + - "111111\n" + - "222222\n" + - "333333\n" + - "444444\n" + - "555555\n" + - "666666\n" + - "777777\n" + - "888888\n" + - "999999"; + ITerminalTextData term = makeITerminalTextData(); + String s = "000000\n" + "111111\n" + "222222\n" + "333333\n" + "444444\n" + "555555\n" + "666666\n" + "777777\n" + + "888888\n" + "999999"; ITerminalTextDataSnapshot snapshot; - - snapshot=snapshot(s,term); - term.scroll(1,2,-1); + + snapshot = snapshot(s, term); + term.scroll(1, 2, -1); term.setDimensions(5, 4); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "11111"); @@ -845,94 +755,86 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); - term.scroll(1,2,-1); + snapshot = snapshot(s, term); + term.scroll(1, 2, -1); term.setDimensions(7, 2); - term.scroll(4,2,-1); + term.scroll(4, 2, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111111"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); - snapshot=snapshot(s,term); + snapshot = snapshot(s, term); - term.scroll(1,2,-1); - term.setDimensions(term.getHeight(),term.getWidth()+1); + term.scroll(1, 2, -1); + term.setDimensions(term.getHeight(), term.getWidth() + 1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "1111111111"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); } + public void testScrollAfterResize() { - ITerminalTextData term=makeITerminalTextData(); - String s="000000\n" + - "111111\n" + - "222222\n" + - "333333\n" + - "444444\n" + - "555555\n" + - "666666\n" + - "777777\n" + - "888888\n" + - "999999"; + ITerminalTextData term = makeITerminalTextData(); + String s = "000000\n" + "111111\n" + "222222\n" + "333333\n" + "444444\n" + "555555\n" + "666666\n" + "777777\n" + + "888888\n" + "999999"; ITerminalTextDataSnapshot snapshot; - - snapshot=snapshot(s,term); + + snapshot = snapshot(s, term); term.setDimensions(14, 6); - term.scroll(0,14,-1); + term.scroll(0, 14, -1); snapshot.updateSnapshot(true); assertChangedLines(snapshot, "11111111111111"); assertEquals(0, snapshot.getScrollWindowStartLine()); assertEquals(0, snapshot.getScrollWindowSize()); assertEquals(0, snapshot.getScrollWindowShift()); } + private final class SnapshotListener implements ITerminalTextDataSnapshot.SnapshotOutOfDateListener { int N; + public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) { N++; } + public void reset() { - N=0; + N = 0; } } public void testAddListener() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - SnapshotListener listener=new SnapshotListener(); + SnapshotListener listener = new SnapshotListener(); snapshot.addListener(listener); assertEquals(0, listener.N); - + // make a change and expect it to be changed term.setChar(0, 0, '?', null); assertEquals(1, listener.N); term.setChar(1, 1, '?', null); assertEquals(1, listener.N); - + snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); // make a change and expect it to be changed - term.setChars(1, 1, new char[]{'?','!','.'},null); + term.setChars(1, 1, new char[] { '?', '!', '.' }, null); assertEquals(1, listener.N); - term.setChars(2, 1, new char[]{'?','!','.'},null); + term.setChars(2, 1, new char[] { '?', '!', '.' }, null); assertEquals(1, listener.N); - + snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); - + // scroll term.scroll(1, 2, -1); assertEquals(1, listener.N); @@ -942,7 +844,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); - + // scroll term.scroll(1, 2, 1); assertEquals(1, listener.N); @@ -962,7 +864,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); - + // scroll term.scroll(1, 2, 1); assertEquals(1, listener.N); @@ -970,7 +872,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); - + // setDimensions term.setDimensions(2, 2); assertEquals(1, listener.N); @@ -978,7 +880,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { snapshot.updateSnapshot(false); assertEquals(1, listener.N); listener.reset(); - + // setDimensions term.setDimensions(20, 20); assertEquals(1, listener.N); @@ -988,25 +890,21 @@ public class TerminalTextDataSnapshotTest extends TestCase { } public void testRemoveListener() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - SnapshotListener listener1=new SnapshotListener(); - SnapshotListener listener2=new SnapshotListener(); - SnapshotListener listener3=new SnapshotListener(); + SnapshotListener listener1 = new SnapshotListener(); + SnapshotListener listener2 = new SnapshotListener(); + SnapshotListener listener3 = new SnapshotListener(); snapshot.addListener(listener1); snapshot.addListener(listener2); snapshot.addListener(listener3); assertEquals(0, listener1.N); - + // make a change and expect it to be changed term.setChar(0, 0, '?', null); assertEquals(1, listener1.N); @@ -1016,7 +914,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - + snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1026,16 +924,15 @@ public class TerminalTextDataSnapshotTest extends TestCase { listener3.reset(); // make a change and expect it to be changed - term.setChars(1, 1, new char[]{'?','!','.'},null); + term.setChars(1, 1, new char[] { '?', '!', '.' }, null); assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - term.setChars(2, 1, new char[]{'?','!','.'},null); + term.setChars(2, 1, new char[] { '?', '!', '.' }, null); assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1058,7 +955,6 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(0, listener2.N); assertEquals(1, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(0, listener2.N); @@ -1069,7 +965,6 @@ public class TerminalTextDataSnapshotTest extends TestCase { listener2.reset(); listener3.reset(); - snapshot.removeListener(listener3); // scroll term.scroll(1, 2, 1); @@ -1082,7 +977,6 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(1, listener2.N); assertEquals(0, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1095,7 +989,7 @@ public class TerminalTextDataSnapshotTest extends TestCase { // add listener multiple times snapshot.addListener(listener3); - + // scroll term.scroll(1, 2, -1); assertEquals(1, listener1.N); @@ -1107,7 +1001,6 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(1, listener2.N); assertEquals(2, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1119,14 +1012,12 @@ public class TerminalTextDataSnapshotTest extends TestCase { // remove the duplicate listener snapshot.removeListener(listener3); - // scroll term.scroll(1, 2, 1); assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1136,14 +1027,12 @@ public class TerminalTextDataSnapshotTest extends TestCase { listener2.reset(); listener3.reset(); - // setDimensions term.setDimensions(2, 2); assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - snapshot.updateSnapshot(false); assertEquals(1, listener1.N); assertEquals(1, listener2.N); @@ -1153,98 +1042,101 @@ public class TerminalTextDataSnapshotTest extends TestCase { listener2.reset(); listener3.reset(); - // setDimensions term.setDimensions(20, 20); assertEquals(1, listener1.N); assertEquals(1, listener2.N); assertEquals(1, listener3.N); - snapshot.updateSnapshot(false); assertFalse(snapshot.isOutOfDate()); } + public void testWindowOfInterest() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); snapshot.setInterestWindow(7, 4); snapshot.setInterestWindow(9, 4); snapshot.updateSnapshot(false); } + public void testWindowOfInterest2() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); snapshot.updateSnapshot(false); - term.scroll(7, 3,-1); + term.scroll(7, 3, -1); snapshot.setInterestWindow(9, 4); snapshot.updateSnapshot(false); } + public void testAddLine() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); term.setMaxHeight(20); snapshot.updateSnapshot(false); - assertEquals(10,term.getHeight()); - assertEquals(20,term.getMaxHeight()); + assertEquals(10, term.getHeight()); + assertEquals(20, term.getMaxHeight()); assertFalse(snapshot.isOutOfDate()); term.addLine(); assertTrue(snapshot.isOutOfDate()); - assertEquals(11,term.getHeight()); - assertEquals(10,snapshot.getHeight()); + assertEquals(11, term.getHeight()); + assertEquals(10, snapshot.getHeight()); snapshot.updateSnapshot(false); - assertEquals(11,term.getHeight()); - assertEquals(11,snapshot.getHeight()); - assertEquals(20,term.getMaxHeight()); - + assertEquals(11, term.getHeight()); + assertEquals(11, snapshot.getHeight()); + assertEquals(20, term.getMaxHeight()); + term.addLine(); term.addLine(); - assertEquals(11,snapshot.getHeight()); - assertEquals(13,term.getHeight()); + assertEquals(11, snapshot.getHeight()); + assertEquals(13, term.getHeight()); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertEquals(13,snapshot.getHeight()); - assertEquals(13,term.getHeight()); - assertEquals(20,term.getMaxHeight()); + assertEquals(13, snapshot.getHeight()); + assertEquals(13, term.getHeight()); + assertEquals(20, term.getMaxHeight()); } + public void testHasDimensionsChanged() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); term.setMaxHeight(20); snapshot.setInterestWindow(3, 4); snapshot.updateSnapshot(false); - assertEquals(10,term.getHeight()); - assertEquals(20,term.getMaxHeight()); + assertEquals(10, term.getHeight()); + assertEquals(20, term.getMaxHeight()); assertFalse(snapshot.isOutOfDate()); term.addLine(); assertTrue(snapshot.isOutOfDate()); - assertEquals(11,term.getHeight()); - assertEquals(10,snapshot.getHeight()); + assertEquals(11, term.getHeight()); + assertEquals(10, snapshot.getHeight()); snapshot.updateSnapshot(false); assertTrue(snapshot.hasDimensionsChanged()); - assertEquals(11,term.getHeight()); - assertEquals(11,snapshot.getHeight()); - assertEquals(20,term.getMaxHeight()); - + assertEquals(11, term.getHeight()); + assertEquals(11, snapshot.getHeight()); + assertEquals(20, term.getMaxHeight()); + term.addLine(); term.addLine(); - assertEquals(11,snapshot.getHeight()); - assertEquals(13,term.getHeight()); + assertEquals(11, snapshot.getHeight()); + assertEquals(13, term.getHeight()); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); assertTrue(snapshot.hasDimensionsChanged()); - assertEquals(13,snapshot.getHeight()); - assertEquals(13,term.getHeight()); - assertEquals(20,term.getMaxHeight()); + assertEquals(13, snapshot.getHeight()); + assertEquals(13, term.getHeight()); + assertEquals(20, term.getMaxHeight()); } + public void testCursor() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); term.setMaxHeight(20); snapshot.setInterestWindow(3, 4); snapshot.updateSnapshot(false); @@ -1259,10 +1151,11 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertEquals(3, snapshot.getCursorLine()); assertEquals(2, snapshot.getCursorColumn()); } + public void testCursor2() { - ITerminalTextData term=makeITerminalTextData(); - TerminalTextTestHelper.fillSimple(term,"0123456789"); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + TerminalTextTestHelper.fillSimple(term, "0123456789"); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); term.setMaxHeight(20); snapshot.setInterestWindow(3, 4); snapshot.updateSnapshot(false); @@ -1272,36 +1165,33 @@ public class TerminalTextDataSnapshotTest extends TestCase { term.setCursorColumn(1); assertTrue(snapshot.isOutOfDate()); } + public void testHasTerminalChanged() { - ITerminalTextData term=makeITerminalTextData(); - String s="12345\n" + - "abcde\n" + - "ABCDE\n" + - "vwxzy\n" + - "VWXYZ"; - TerminalTextTestHelper.fill(term,s); - - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE\n" + "vwxzy\n" + "VWXYZ"; + TerminalTextTestHelper.fill(term, s); + + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); assertTrue(snapshot.hasTerminalChanged()); snapshot.updateSnapshot(false); assertTrue(snapshot.hasTerminalChanged()); - + // make a change and expect it to be changed term.setChar(0, 0, '?', null); snapshot.updateSnapshot(false); assertTrue(snapshot.hasTerminalChanged()); - + // make a change and expect it to be changed - term.setChars(1, 1, new char[]{'?','!','.'},null); + term.setChars(1, 1, new char[] { '?', '!', '.' }, null); snapshot.updateSnapshot(false); assertTrue(snapshot.hasTerminalChanged()); - + // scroll term.scroll(1, 2, -1); snapshot.updateSnapshot(false); assertTrue(snapshot.hasTerminalChanged()); - + // scroll term.scroll(1, 2, 1); snapshot.updateSnapshot(false); @@ -1311,17 +1201,17 @@ public class TerminalTextDataSnapshotTest extends TestCase { term.scroll(1, 2, -1); snapshot.updateSnapshot(true); assertTrue(snapshot.hasTerminalChanged()); - + // scroll term.scroll(1, 2, 1); snapshot.updateSnapshot(true); assertTrue(snapshot.hasTerminalChanged()); - + // setDimensions term.setDimensions(2, 2); snapshot.updateSnapshot(false); assertTrue(snapshot.hasTerminalChanged()); - + // setDimensions term.setDimensions(20, 20); snapshot.updateSnapshot(false); @@ -1336,9 +1226,10 @@ public class TerminalTextDataSnapshotTest extends TestCase { assertFalse(snapshot.hasTerminalChanged()); } + public void testGetTerminalTextData() { - ITerminalTextData term=makeITerminalTextData(); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + ITerminalTextData term = makeITerminalTextData(); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); assertSame(term, snapshot.getTerminalTextData()); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotWindowTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotWindowTest.java index e788ec259a9..b8c980d4cba 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotWindowTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataSnapshotWindowTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; @@ -20,6 +20,7 @@ public class TerminalTextDataSnapshotWindowTest extends TestCase { String toMultiLineText(ITerminalTextDataReadOnly term) { return TerminalTextTestHelper.toMultiLineText(term); } + String toSimpleText(ITerminalTextDataReadOnly term) { return TerminalTextTestHelper.toSimple(term); } @@ -27,21 +28,23 @@ public class TerminalTextDataSnapshotWindowTest extends TestCase { protected ITerminalTextData makeITerminalTextData() { return new TerminalTextData(); } + ITerminalTextDataSnapshot snapshotSimple(String text, ITerminalTextData term) { - TerminalTextTestHelper.fillSimple(term,text); - ITerminalTextDataSnapshot snapshot=term.makeSnapshot(); + TerminalTextTestHelper.fillSimple(term, text); + ITerminalTextDataSnapshot snapshot = term.makeSnapshot(); return snapshot; - + } + /** * @param snapshot * @param expected a string of 0 and 1 (1 means changed) */ void assertChangedLines(ITerminalTextDataSnapshot snapshot, String expected) { - assertEquals(expected.length(),snapshot.getHeight()); - StringBuffer buffer=new StringBuffer(); + assertEquals(expected.length(), snapshot.getHeight()); + StringBuffer buffer = new StringBuffer(); for (int line = 0; line < expected.length(); line++) { - if(snapshot.hasLineChanged(line)) + if (snapshot.hasLineChanged(line)) buffer.append('1'); else buffer.append('0'); @@ -50,142 +53,144 @@ public class TerminalTextDataSnapshotWindowTest extends TestCase { } public void testSetInterestWindow() { - ITerminalTextData term=makeITerminalTextData(); - ITerminalTextDataSnapshot snapshot=snapshotSimple("0123456789",term); + ITerminalTextData term = makeITerminalTextData(); + ITerminalTextDataSnapshot snapshot = snapshotSimple("0123456789", term); assertEquals(0, snapshot.getInterestWindowStartLine()); assertEquals(-1, snapshot.getInterestWindowSize()); snapshot.setInterestWindow(2, 3); assertEquals(2, snapshot.getInterestWindowStartLine()); assertEquals(3, snapshot.getInterestWindowSize()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0011100000"); + assertChangedLines(snapshot, "0011100000"); } + public void testSetChar() { - ITerminalTextData term=makeITerminalTextData(); - ITerminalTextDataSnapshot snapshot=snapshotSimple("0123456789",term); + ITerminalTextData term = makeITerminalTextData(); + ITerminalTextDataSnapshot snapshot = snapshotSimple("0123456789", term); snapshot.setInterestWindow(2, 3); snapshot.updateSnapshot(false); assertEquals(" 234 ", toSimpleText(snapshot)); - + term.setChar(0, 0, 'x', null); assertFalse(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000000000"); - + assertChangedLines(snapshot, "0000000000"); + term.setChar(1, 0, 'x', null); assertFalse(snapshot.isOutOfDate()); - + term.setChar(2, 0, 'x', null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0010000000"); - + assertChangedLines(snapshot, "0010000000"); + term.setChar(3, 0, 'x', null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0001000000"); + assertChangedLines(snapshot, "0001000000"); term.setChar(4, 0, 'x', null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000100000"); + assertChangedLines(snapshot, "0000100000"); term.setChar(5, 0, 'x', null); assertFalse(snapshot.isOutOfDate()); - + term.setChar(6, 0, 'x', null); assertFalse(snapshot.isOutOfDate()); - + for (int i = 0; i < 9; i++) { - term.setChar(i, 0, (char)('a'+i), null); + term.setChar(i, 0, (char) ('a' + i), null); } assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0011100000"); + assertChangedLines(snapshot, "0011100000"); } public void testSetChars() { - ITerminalTextData term=makeITerminalTextData(); - ITerminalTextDataSnapshot snapshot=snapshotSimple("0123456789",term); + ITerminalTextData term = makeITerminalTextData(); + ITerminalTextDataSnapshot snapshot = snapshotSimple("0123456789", term); snapshot.setInterestWindow(2, 3); snapshot.updateSnapshot(false); assertEquals(" 234 ", toSimpleText(snapshot)); - + term.setChars(0, 0, "x".toCharArray(), null); assertFalse(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000000000"); - + assertChangedLines(snapshot, "0000000000"); + term.setChars(1, 0, "x".toCharArray(), null); assertFalse(snapshot.isOutOfDate()); - + term.setChars(2, 0, "x".toCharArray(), null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0010000000"); - + assertChangedLines(snapshot, "0010000000"); + term.setChars(3, 0, "x".toCharArray(), null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0001000000"); + assertChangedLines(snapshot, "0001000000"); term.setChars(4, 0, "x".toCharArray(), null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000100000"); + assertChangedLines(snapshot, "0000100000"); term.setChars(5, 0, "x".toCharArray(), null); assertFalse(snapshot.isOutOfDate()); - + term.setChars(6, 0, "x".toCharArray(), null); assertFalse(snapshot.isOutOfDate()); for (int i = 0; i < 9; i++) { - term.setChars(i, 0, (i+"").toCharArray(), null); + term.setChars(i, 0, (i + "").toCharArray(), null); } assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0011100000"); + assertChangedLines(snapshot, "0011100000"); } + public void testSetChars2() { - ITerminalTextData term=makeITerminalTextData(); - ITerminalTextDataSnapshot snapshot=snapshotSimple("0123456789",term); + ITerminalTextData term = makeITerminalTextData(); + ITerminalTextDataSnapshot snapshot = snapshotSimple("0123456789", term); snapshot.setInterestWindow(2, 3); snapshot.updateSnapshot(false); assertEquals(" 234 ", toSimpleText(snapshot)); - - term.setChars(0, 0, "abcdef".toCharArray(),2,1, null); - assertFalse(snapshot.isOutOfDate()); - snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000000000"); - - term.setChars(1, 0, "abcdef".toCharArray(),2 ,1, null); - assertFalse(snapshot.isOutOfDate()); - - term.setChars(2, 0, "abcdef".toCharArray(),2 ,1, null); - assertTrue(snapshot.isOutOfDate()); - snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0010000000"); - - term.setChars(3, 0, "abcdef".toCharArray(),2 ,1, null); - assertTrue(snapshot.isOutOfDate()); - snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0001000000"); - term.setChars(4, 0, "abcdef".toCharArray(),2 ,1, null); + term.setChars(0, 0, "abcdef".toCharArray(), 2, 1, null); + assertFalse(snapshot.isOutOfDate()); + snapshot.updateSnapshot(false); + assertChangedLines(snapshot, "0000000000"); + + term.setChars(1, 0, "abcdef".toCharArray(), 2, 1, null); + assertFalse(snapshot.isOutOfDate()); + + term.setChars(2, 0, "abcdef".toCharArray(), 2, 1, null); assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0000100000"); + assertChangedLines(snapshot, "0010000000"); - term.setChars(5, 0, "abcdef".toCharArray(),2 ,1, null); + term.setChars(3, 0, "abcdef".toCharArray(), 2, 1, null); + assertTrue(snapshot.isOutOfDate()); + snapshot.updateSnapshot(false); + assertChangedLines(snapshot, "0001000000"); + + term.setChars(4, 0, "abcdef".toCharArray(), 2, 1, null); + assertTrue(snapshot.isOutOfDate()); + snapshot.updateSnapshot(false); + assertChangedLines(snapshot, "0000100000"); + + term.setChars(5, 0, "abcdef".toCharArray(), 2, 1, null); assertFalse(snapshot.isOutOfDate()); - - term.setChars(6, 0, "abcdef".toCharArray(),2 ,1, null); + + term.setChars(6, 0, "abcdef".toCharArray(), 2, 1, null); assertFalse(snapshot.isOutOfDate()); for (int i = 0; i < 9; i++) { - term.setChars(i, 0, ("ab"+i+"def").toCharArray(),2 ,1, null); + term.setChars(i, 0, ("ab" + i + "def").toCharArray(), 2, 1, null); } assertTrue(snapshot.isOutOfDate()); snapshot.updateSnapshot(false); - assertChangedLines(snapshot,"0011100000"); + assertChangedLines(snapshot, "0011100000"); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStoreTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStoreTest.java index 997d961eced..d3ea6081471 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStoreTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataStoreTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataTest.java index 52f9283060a..9df1257e773 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindowTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindowTest.java index 23204cc2a5a..f2670ba907e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindowTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/model/TerminalTextDataWindowTest.java @@ -23,25 +23,29 @@ import org.eclipse.tm.terminal.model.StyleColor; public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest { int fOffset; int fSize; + public TerminalTextDataWindowTest() { - fOffset=2; - fSize=2; + fOffset = 2; + fSize = 2; } + protected ITerminalTextData makeITerminalTextData() { - TerminalTextDataWindow term=new TerminalTextDataWindow(); - term.setWindow(fOffset,fSize); + TerminalTextDataWindow term = new TerminalTextDataWindow(); + term.setWindow(fOffset, fSize); return term; } + /** * Used for multi line text * @param expected * @param actual */ - protected void assertEqualsTerm(String expected,String actual) { + protected void assertEqualsTerm(String expected, String actual) { assertEquals(stripMultiLine(expected), stripMultiLine(actual)); } + private String stripMultiLine(String s) { - StringBuffer b=new StringBuffer(); + StringBuffer b = new StringBuffer(); // String[] lines=s.split("\n"); // ArrayList l = new ArrayList(); @@ -63,426 +67,336 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest { } // for (int i = 0; i < lines.length; i++) { - if(i>0) + if (i > 0) b.append("\n"); //$NON-NLS-1$ - if(i>=fOffset && i= fOffset && i < fOffset + fSize) b.append(lines[i]); else b.append(new String(new char[lines[i].length()])); } return b.toString(); } + /** * Used for simple text * @param expected * @param actual */ - protected void assertEqualsSimple(String expected,String actual) { + protected void assertEqualsSimple(String expected, String actual) { assertEquals(stripSimple(expected), stripSimple(actual)); } + String stripSimple(String s) { - StringBuffer b=new StringBuffer(); + StringBuffer b = new StringBuffer(); for (int i = 0; i < s.length(); i++) { - if(i>=fOffset && i= fOffset && i < fOffset + fSize) b.append(s.charAt(i)); else b.append(' '); } return b.toString(); } + public void testAddLine() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); fill(term, s); term.addLine(); - assertEqualsTerm( - "222\n" + - "333\n" + - "444\n" + - "\0\0\0\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("222\n" + "333\n" + "444\n" + "\0\0\0\n" + "\000\000\000", toMultiLineText(term)); } public void testMaxSize() { - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; - ITerminalTextData term=makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; + ITerminalTextData term = makeITerminalTextData(); term.setMaxHeight(8); fill(term, s); assertEquals(5, term.getHeight()); assertEquals(8, term.getMaxHeight()); term.addLine(); assertEquals(6, term.getHeight()); - assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000", toMultiLineText(term)); term.addLine(); assertEquals(7, term.getHeight()); - assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000", + toMultiLineText(term)); term.addLine(); assertEquals(8, term.getHeight()); assertEqualsTerm( - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + "111\n" + "222\n" + "333\n" + "444\n" + "555\n" + "\000\000\000\n" + "\000\000\000\n" + "\000\000\000", + toMultiLineText(term)); term.addLine(); assertEquals(8, term.getHeight()); - assertEqualsTerm( - "222\n" + - "333\n" + - "444\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000\n" + - "\000\000\000", toMultiLineText(term)); + assertEqualsTerm("222\n" + "333\n" + "444\n" + "\000\000\000\n" + "\000\000\000\n" + "\000\000\000\n" + + "\000\000\000\n" + "\000\000\000", toMultiLineText(term)); } public void testGetLineSegments() { - Style s1=getDefaultStyle(); - Style s2=s1.setBold(true); - Style s3=s1.setUnderline(true); - ITerminalTextData term=makeITerminalTextData(); + Style s1 = getDefaultStyle(); + Style s2 = s1.setBold(true); + Style s3 = s1.setUnderline(true); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(8, 8); LineSegment[] segments; - term.setChars(2, 0,"0123".toCharArray(), s1); - term.setChars(2, 4,"abcd".toCharArray(), null); - segments=term.getLineSegments(2, 0, term.getWidth()); + term.setChars(2, 0, "0123".toCharArray(), s1); + term.setChars(2, 4, "abcd".toCharArray(), null); + segments = term.getLineSegments(2, 0, term.getWidth()); assertEquals(2, segments.length); assertSegment(0, "0123", s1, segments[0]); assertSegment(4, "abcd", null, segments[1]); - - segments=term.getLineSegments(2, 4, term.getWidth()-4); + segments = term.getLineSegments(2, 4, term.getWidth() - 4); assertEquals(1, segments.length); assertSegment(4, "abcd", null, segments[0]); - segments=term.getLineSegments(2, 3, 2); + segments = term.getLineSegments(2, 3, 2); assertEquals(2, segments.length); assertSegment(3, "3", s1, segments[0]); assertSegment(4, "a", null, segments[1]); - segments=term.getLineSegments(2, 7, 1); + segments = term.getLineSegments(2, 7, 1); assertEquals(1, segments.length); assertSegment(7, "d", null, segments[0]); - segments=term.getLineSegments(2, 0, 1); + segments = term.getLineSegments(2, 0, 1); assertEquals(1, segments.length); assertSegment(0, "0", s1, segments[0]); // line 1 - term.setChars(1, 0,"x".toCharArray(), s1); - term.setChars(1, 1,"y".toCharArray(), s2); - term.setChars(1, 2,"z".toCharArray(), s3); + term.setChars(1, 0, "x".toCharArray(), s1); + term.setChars(1, 1, "y".toCharArray(), s2); + term.setChars(1, 2, "z".toCharArray(), s3); - segments=term.getLineSegments(1, 0, term.getWidth()); + segments = term.getLineSegments(1, 0, term.getWidth()); assertEquals(1, segments.length); assertSegment(0, "\000\000\000\000\000\000\000\000", null, segments[0]); // line 3 - segments=term.getLineSegments(3, 0, term.getWidth()); + segments = term.getLineSegments(3, 0, term.getWidth()); assertEquals(1, segments.length); assertSegment(0, "\000\000\000\000\000\000\000\000", null, segments[0]); } + public void testGetChar() { - String s="12345\n" + - "abcde\n" + - "ABCDE"; - ITerminalTextData term=makeITerminalTextData(); + String s = "12345\n" + "abcde\n" + "ABCDE"; + ITerminalTextData term = makeITerminalTextData(); fill(term, s); - assertEquals('\000', term.getChar(0,0)); - assertEquals('\000', term.getChar(0,1)); - assertEquals('\000', term.getChar(0,2)); - assertEquals('\000', term.getChar(0,3)); - assertEquals('\000', term.getChar(0,4)); - assertEquals('\000', term.getChar(1,0)); - assertEquals('\000', term.getChar(1,1)); - assertEquals('\000', term.getChar(1,2)); - assertEquals('\000', term.getChar(1,3)); - assertEquals('\000', term.getChar(1,4)); - assertEquals('A', term.getChar(2,0)); - assertEquals('B', term.getChar(2,1)); - assertEquals('C', term.getChar(2,2)); - assertEquals('D', term.getChar(2,3)); - assertEquals('E', term.getChar(2,4)); + assertEquals('\000', term.getChar(0, 0)); + assertEquals('\000', term.getChar(0, 1)); + assertEquals('\000', term.getChar(0, 2)); + assertEquals('\000', term.getChar(0, 3)); + assertEquals('\000', term.getChar(0, 4)); + assertEquals('\000', term.getChar(1, 0)); + assertEquals('\000', term.getChar(1, 1)); + assertEquals('\000', term.getChar(1, 2)); + assertEquals('\000', term.getChar(1, 3)); + assertEquals('\000', term.getChar(1, 4)); + assertEquals('A', term.getChar(2, 0)); + assertEquals('B', term.getChar(2, 1)); + assertEquals('C', term.getChar(2, 2)); + assertEquals('D', term.getChar(2, 3)); + assertEquals('E', term.getChar(2, 4)); } + public void testGetStyle() { - ITerminalTextData term=makeITerminalTextData(); - Style style=getDefaultStyle(); + ITerminalTextData term = makeITerminalTextData(); + Style style = getDefaultStyle(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor(""+c))); + char c = (char) ('a' + column + line); + term.setChar(line, column, c, style.setForground(StyleColor.getStyleColor("" + c))); } } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=(char)('a'+column+line); - Style s=null; - if(line>=fOffset&&line= fOffset && line < fOffset + fSize) + s = style.setForground(StyleColor.getStyleColor("" + c)); assertSame(s, term.getStyle(line, column)); } } } + public void testSetChar() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - term.setChar(line, column, (char)('a'+column+line), null); + term.setChar(line, column, (char) ('a' + column + line), null); } } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=0; - if(line>=fOffset&&line= fOffset && line < fOffset + fSize) + c = (char) ('a' + column + line); + assertEquals(c, term.getChar(line, column)); } } - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "def\n" - + "efg\n" - + "fgh", toMultiLineText(term)); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "def\n" + "efg\n" + "fgh", toMultiLineText(term)); } public void testSetChars() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(6, 3); for (int line = 0; line < term.getHeight(); line++) { - char[] chars=new char[term.getWidth()]; + char[] chars = new char[term.getWidth()]; for (int column = 0; column < term.getWidth(); column++) { - chars[column]=(char)('a'+column+line); + chars[column] = (char) ('a' + column + line); } term.setChars(line, 0, chars, null); } for (int line = 0; line < term.getHeight(); line++) { for (int column = 0; column < term.getWidth(); column++) { - char c=0; - if(line>=fOffset&&line= fOffset && line < fOffset + fSize) + c = (char) ('a' + column + line); + assertEquals(c, term.getChar(line, column)); } } - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "def\n" - + "efg\n" - + "fgh", toMultiLineText(term)); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "def\n" + "efg\n" + "fgh", toMultiLineText(term)); - term.setChars(3, 1, new char[]{'1','2'}, null); - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "d12\n" - + "efg\n" - + "fgh", toMultiLineText(term)); + term.setChars(3, 1, new char[] { '1', '2' }, null); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "d12\n" + "efg\n" + "fgh", toMultiLineText(term)); // check if chars are correctly chopped - term.setChars(4, 1, new char[]{'1','2','3','4','5'}, null); - assertEqualsTerm( - "abc\n" - + "bcd\n" - + "cde\n" - + "d12\n" - + "e12\n" - + "fgh", toMultiLineText(term)); + term.setChars(4, 1, new char[] { '1', '2', '3', '4', '5' }, null); + assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "d12\n" + "e12\n" + "fgh", toMultiLineText(term)); } + public void testSetCharsLen() { - ITerminalTextData term=makeITerminalTextData(); - String s= "ZYXWVU\n" - + "abcdef\n" - + "ABCDEF"; + ITerminalTextData term = makeITerminalTextData(); + String s = "ZYXWVU\n" + "abcdef\n" + "ABCDEF"; fill(term, s); - char[] chars=new char[]{'1','2','3','4','5','6','7','8'}; - term.setChars(1, 0, chars, 0, 6,null); - assertEqualsTerm( - "ZYXWVU\n" - + "123456\n" - + "ABCDEF", toMultiLineText(term)); + char[] chars = new char[] { '1', '2', '3', '4', '5', '6', '7', '8' }; + term.setChars(1, 0, chars, 0, 6, null); + assertEqualsTerm("ZYXWVU\n" + "123456\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 0, chars, 0, 5, null); - assertEqualsTerm("ZYXWVU\n" - + "12345f\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "12345f\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 0, chars, 1, 5, null); - assertEqualsTerm("ZYXWVU\n" - + "23456f\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "23456f\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 1, chars, 1, 4, null); - assertEqualsTerm("ZYXWVU\n" - + "a2345f\n" - + "ABCDEF", toMultiLineText(term)); - - + assertEqualsTerm("ZYXWVU\n" + "a2345f\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); term.setChars(1, 2, chars, 3, 4, null); - assertEqualsTerm("ZYXWVU\n" - + "ab4567\n" - + "ABCDEF", toMultiLineText(term)); + assertEqualsTerm("ZYXWVU\n" + "ab4567\n" + "ABCDEF", toMultiLineText(term)); fill(term, s); } + public void testSetCopyLines() { - ITerminalTextData term=new TerminalTextDataStore(); - String s="012345"; + ITerminalTextData term = new TerminalTextDataStore(); + String s = "012345"; fillSimple(term, s); - ITerminalTextData termCopy=makeITerminalTextData(); - String sCopy="abcde"; + ITerminalTextData termCopy = makeITerminalTextData(); + String sCopy = "abcde"; fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,0); + termCopy.copyRange(term, 0, 0, 0); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple(sCopy, toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,5); + termCopy.copyRange(term, 0, 0, 5); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("01234", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,0,2); + termCopy.copyRange(term, 0, 0, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("01cde", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,0,1,2); + termCopy.copyRange(term, 0, 1, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a01de", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,1,1,2); + termCopy.copyRange(term, 1, 1, 2); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a12de", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,1,1,4); + termCopy.copyRange(term, 1, 1, 4); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a1234", toSimple(termCopy)); fillSimple(termCopy, sCopy); - termCopy.copyRange(term,2,1,4); + termCopy.copyRange(term, 2, 1, 4); assertEqualsSimple(s, toSimple(term)); assertEqualsSimple("a2345", toSimple(termCopy)); } + public void testScrollNegative() { - scrollTest(0,2,-1," 23 "," 23 "); - scrollTest(0,1,-1," 23 "," 23 "); - scrollTest(0,6,-1," 23 "," 3 "); - scrollTest(0,6,-6," 23 "," "); - scrollTest(0,6,-7," 23 "," "); - scrollTest(0,6,-8," 23 "," "); - scrollTest(0,6,-2," 23 "," "); - scrollTest(1,1,-1," 23 "," 23 "); - scrollTest(1,2,-1," 23 "," 3 "); - scrollTest(5,1,-1," 23 "," 23 "); - scrollTest(5,1,-1," 23 "," 23 "); + scrollTest(0, 2, -1, " 23 ", " 23 "); + scrollTest(0, 1, -1, " 23 ", " 23 "); + scrollTest(0, 6, -1, " 23 ", " 3 "); + scrollTest(0, 6, -6, " 23 ", " "); + scrollTest(0, 6, -7, " 23 ", " "); + scrollTest(0, 6, -8, " 23 ", " "); + scrollTest(0, 6, -2, " 23 ", " "); + scrollTest(1, 1, -1, " 23 ", " 23 "); + scrollTest(1, 2, -1, " 23 ", " 3 "); + scrollTest(5, 1, -1, " 23 ", " 23 "); + scrollTest(5, 1, -1, " 23 ", " 23 "); } + public void testScrollAll() { - scrollTest(0,6,1, " 2345"," 2 "); - scrollTest(0,6,-1, " 2345"," 3 "); - scrollTest(0,6,2, " 2345"," "); - scrollTest(0,6,-2, " 2345"," "); + scrollTest(0, 6, 1, " 2345", " 2 "); + scrollTest(0, 6, -1, " 2345", " 3 "); + scrollTest(0, 6, 2, " 2345", " "); + scrollTest(0, 6, -2, " 2345", " "); } + public void testCopyLineWithOffset() { - ITerminalTextData term=makeITerminalTextData(); - String s= - "111\n" + - "222\n" + - "333\n" + - "444\n" + - "555"; + ITerminalTextData term = makeITerminalTextData(); + String s = "111\n" + "222\n" + "333\n" + "444\n" + "555"; fill(term, s); - ITerminalTextData dest=makeITerminalTextData(); - String sCopy= - "aaa\n" + - "bbb\n" + - "ccc\n" + - "ddd\n" + - "eee"; + ITerminalTextData dest = makeITerminalTextData(); + String sCopy = "aaa\n" + "bbb\n" + "ccc\n" + "ddd\n" + "eee"; fill(dest, sCopy); - copySelective(dest,term,1,0,new boolean []{true,false,false,true}); + copySelective(dest, term, 1, 0, new boolean[] { true, false, false, true }); assertEqualsTerm(s, toMultiLineText(term)); - assertEqualsTerm( - "222\n" + - "bbb\n" + - "ccc\n" + - "\00\00\00\n" + - "eee", toMultiLineText(dest)); + assertEqualsTerm("222\n" + "bbb\n" + "ccc\n" + "\00\00\00\n" + "eee", toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,2,0,new boolean []{true,true}); + copySelective(dest, term, 2, 0, new boolean[] { true, true }); assertEqualsTerm(s, toMultiLineText(term)); - assertEqualsTerm( - "333\n" + - "444\n" + - "ccc\n" + - "ddd\n" + - "eee", toMultiLineText(dest)); + assertEqualsTerm("333\n" + "444\n" + "ccc\n" + "ddd\n" + "eee", toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{true,true,true,true,true}); + copySelective(dest, term, 0, 0, new boolean[] { true, true, true, true, true }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(s, toMultiLineText(dest)); fill(dest, sCopy); - copySelective(dest,term,0,0,new boolean []{false,false,false,false,false}); + copySelective(dest, term, 0, 0, new boolean[] { false, false, false, false, false }); assertEqualsTerm(s, toMultiLineText(term)); assertEqualsTerm(sCopy, toMultiLineText(dest)); } + public void testCopy() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(3, 1); - ITerminalTextData data=new TerminalTextData(); - fillSimple(data,"abcd"); + ITerminalTextData data = new TerminalTextData(); + fillSimple(data, "abcd"); term.copy(data); } public void testWrappedLines() { - ITerminalTextData term=makeITerminalTextData(); + ITerminalTextData term = makeITerminalTextData(); term.setDimensions(4, 4); - for (int i=0; i0) + if (line > 0) buff.append("\n"); //$NON-NLS-1$ for (int column = 0; column < width; column++) { buff.append(term.getChar(line, column)); @@ -34,6 +35,7 @@ public class TerminalTextTestHelper { } return buff.toString(); } + static public String toSimple(String str) { //return str.replaceAll("\000", " ").replaceAll("\n", ""); // @@ -54,54 +56,58 @@ public class TerminalTextTestHelper { return buf.toString(); // } + /** * @param term * @param s each character is one line */ static public void fillSimple(ITerminalTextData term, String s) { - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); term.setDimensions(s.length(), 1); for (int i = 0; i < s.length(); i++) { - char c=s.charAt(i); - term.setChar(i, 0, c, style.setForground(StyleColor.getStyleColor(""+c))); + char c = s.charAt(i); + term.setChar(i, 0, c, style.setForground(StyleColor.getStyleColor("" + c))); } } + /** * @param term * @param s lines separated by \n. The terminal will automatically * resized to fit the text. */ static public void fill(ITerminalTextData term, String s) { - int width=0; - int len=0; - int height=0; + int width = 0; + int len = 0; + int height = 0; for (int i = 0; i < s.length(); i++) { - char c=s.charAt(i); - if(c=='\n') { - width=Math.max(width,len); - len=0; + char c = s.charAt(i); + if (c == '\n') { + width = Math.max(width, len); + len = 0; } else { - if(len==0) + if (len == 0) height++; len++; } } - width=Math.max(width,len); + width = Math.max(width, len); term.setDimensions(height, width); - fill(term,0,0,s); + fill(term, 0, 0, s); } static public void fill(ITerminalTextData term, int column, int line, String s) { - int xx=column; - int yy=line; - Style style=Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, false, false); + int xx = column; + int yy = line; + Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false, + false, false); for (int i = 0; i < s.length(); i++) { - char c=s.charAt(i); - if(c=='\n') { + char c = s.charAt(i); + if (c == '\n') { yy++; - xx=column; + xx = column; } else { - term.setChar(yy, xx, c, style.setForground(StyleColor.getStyleColor(""+c))); + term.setChar(yy, xx, c, style.setForground(StyleColor.getStyleColor("" + c))); xx++; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnection.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnection.java index 39da95d6a21..4f05e92d5db 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnection.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnection.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.speedtest; @@ -26,79 +26,84 @@ public class SpeedTestConnection extends Thread { private final ITerminalControl fControl; private final InputStream fInputStream; private final SpeedTestSettings fSettings; - protected SpeedTestConnection(InputStream inputStream, SpeedTestSettings settings,ITerminalControl control) { - super("SpeedTestConnection-"+fgNo++); + + protected SpeedTestConnection(InputStream inputStream, SpeedTestSettings settings, ITerminalControl control) { + super("SpeedTestConnection-" + fgNo++); fControl = control; - fInputStream=inputStream; - fSettings=settings; + fInputStream = inputStream; + fSettings = settings; } + public void run() { fControl.setState(TerminalState.CONNECTED); try { - readDataForever(fInputStream,fControl.getRemoteToTerminalOutputStream()); + readDataForever(fInputStream, fControl.getRemoteToTerminalOutputStream()); } catch (IOException e) { - connectFailed(e.getMessage(),e.getMessage()); + connectFailed(e.getMessage(), e.getMessage()); } // when reading is done, we set the state to closed fControl.setState(TerminalState.CLOSED); } - private void connectFailed(String terminalText, String msg) { + + private void connectFailed(String terminalText, String msg) { Logger.log(terminalText); fControl.displayTextInTerminal(terminalText); fControl.setState(TerminalState.CLOSED); fControl.setMsg(msg); } + /** * Read the data from the input file and display it in the terminal. * @param in * @throws IOException */ private void readDataForever(InputStream in, OutputStream os) throws IOException { - long N=0; - long T=0; - long tDisplay=0; - int NCalls=0; - int bufferSize=fSettings.getBufferSize(); - int throttle=fSettings.getThrottle(); + long N = 0; + long T = 0; + long tDisplay = 0; + int NCalls = 0; + int bufferSize = fSettings.getBufferSize(); + int throttle = fSettings.getThrottle(); // read the data BufferedReader reader = new BufferedReader(new InputStreamReader(in)); // read until the thread gets interrupted.... - String info=""; - int n=0; - byte[] crnl="\r\n".getBytes("UTF-8"); - long t0=System.currentTimeMillis(); - String line=null; + String info = ""; + int n = 0; + byte[] crnl = "\r\n".getBytes("UTF-8"); + long t0 = System.currentTimeMillis(); + String line = null; do { - line=reader.readLine(); + line = reader.readLine(); // read some bytes - if(line!=null) { + if (line != null) { os.write(line.getBytes("UTF-8")); os.write(crnl); - n+=line.length(); + n += line.length(); } // process at least this number of characters to update the UI - if(line==null || n>bufferSize) { - if(throttle>0) + if (line == null || n > bufferSize) { + if (throttle > 0) sleep(throttle); // we assume we get ASCII UTF8 bytes - long t=System.currentTimeMillis(); - T+=t-t0; - N+=n; + long t = System.currentTimeMillis(); + T += t - t0; + N += n; NCalls++; - if(t-tDisplay>1000 && T>0) { - long rate=(1000*N)/T; - info=rate+" byte/s = "+rate*8+" baud "+"bytes/call="+N/NCalls; - info=rate+" byte/s with buffer size "+fSettings.getBufferSize(); + if (t - tDisplay > 1000 && T > 0) { + long rate = (1000 * N) / T; + info = rate + " byte/s = " + rate * 8 + " baud " + "bytes/call=" + N / NCalls; + info = rate + " byte/s with buffer size " + fSettings.getBufferSize(); setTitle(info); - tDisplay=System.currentTimeMillis(); + tDisplay = System.currentTimeMillis(); } - n=0; - t0=System.currentTimeMillis(); + n = 0; + t0 = System.currentTimeMillis(); } - } while(line!=null); + } while (line != null); } + private void sleep(int ms) { try { Thread.sleep(ms); @@ -106,11 +111,13 @@ public class SpeedTestConnection extends Thread { Thread.currentThread().interrupt(); } } + private void setTitle(final String title) { - Display.getDefault().asyncExec(new Runnable(){ + Display.getDefault().asyncExec(new Runnable() { public void run() { fControl.setTerminalTitle(title); - }}); + } + }); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnector.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnector.java index 59a8121c2bf..f673a350b73 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestConnector.java @@ -9,7 +9,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation - * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl + * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl *******************************************************************************/ package org.eclipse.tm.internal.terminal.speedtest; @@ -27,33 +27,35 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl; public class SpeedTestConnector extends TerminalConnectorImpl { - final SpeedTestSettings fSettings=new SpeedTestSettings(); + final SpeedTestSettings fSettings = new SpeedTestSettings(); InputStream fInputStream; OutputStream fOutputStream; SpeedTestConnection fConnection; + public SpeedTestConnector() { } + synchronized public void connect(ITerminalControl control) { super.connect(control); fControl.setState(TerminalState.CONNECTING); - String file=fSettings.getInputFile(); + String file = fSettings.getInputFile(); try { - fInputStream=new BufferedInputStream(new FileInputStream(file)); + fInputStream = new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { disconnect(); - fControl.setMsg(file+": "+e.getLocalizedMessage()); + fControl.setMsg(file + ": " + e.getLocalizedMessage()); return; } - fOutputStream=System.out; + fOutputStream = System.out; fControl.setTerminalTitle(fSettings.getInputFile()); - fConnection=new SpeedTestConnection(fInputStream,fSettings,fControl); + fConnection = new SpeedTestConnection(fInputStream, fSettings, fControl); fConnection.start(); } synchronized public void doDisconnect() { - if(fConnection!=null){ + if (fConnection != null) { fConnection.interrupt(); - fConnection=null; + fConnection = null; } if (fInputStream != null) { try { @@ -62,7 +64,7 @@ public class SpeedTestConnector extends TerminalConnectorImpl { Logger.logException(exception); } } - fInputStream=null; + fInputStream = null; if (fOutputStream != null) { try { fOutputStream.close(); @@ -70,8 +72,9 @@ public class SpeedTestConnector extends TerminalConnectorImpl { Logger.logException(exception); } } - fOutputStream=null; + fOutputStream = null; } + synchronized public InputStream getInputStream() { return fInputStream; } @@ -88,9 +91,9 @@ public class SpeedTestConnector extends TerminalConnectorImpl { public void setDefaultSettings() { fSettings.load(new NullSettingsStore()); } - + public void load(ISettingsStore store) { - fSettings.load(store); + fSettings.load(store); } public void save(ISettingsStore store) { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestSettings.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestSettings.java index 821fa04ba4c..8283cf4a927 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/speedtest/SpeedTestSettings.java @@ -1,61 +1,70 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.speedtest; - import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; public class SpeedTestSettings { - String fInputFile=""; - String fBufferSize=""; + String fInputFile = ""; + String fBufferSize = ""; String fThrottle; + String getInputFile() { return fInputFile; } + public String getBufferSizeString() { - return getBufferSize()+""; + return getBufferSize() + ""; } + public void setBufferSizeString(String bufferSize) { fBufferSize = bufferSize; } + public int getBufferSize() { try { return Integer.parseInt(fBufferSize); - } catch(RuntimeException e) { + } catch (RuntimeException e) { return 1024; } } + void setInputFile(String testFile) { fInputFile = testFile; } + public void load(ISettingsStore store) { - fInputFile=store.get("inputFile", ""); - fBufferSize=store.get("bufferSize", ""); - fThrottle=store.get("throttle", "0"); + fInputFile = store.get("inputFile", ""); + fBufferSize = store.get("bufferSize", ""); + fThrottle = store.get("throttle", "0"); } + public void save(ISettingsStore store) { store.put("inputFile", fInputFile); store.put("bufferSize", fBufferSize); store.put("throttle", fThrottle); } + public String getThrottleString() { return fThrottle; } + public int getThrottle() { try { return Integer.parseInt(fThrottle); - } catch(RuntimeException e) { + } catch (RuntimeException e) { return 0; } } + public void setThrottleString(String throttle) { fThrottle = throttle; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Main.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Main.java index 73cefecc023..fd1061db108 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Main.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Main.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.terminalcanvas; @@ -21,16 +21,17 @@ public class Main { * @param args */ public static void main(String[] args) { - Display display = new Display (); - Shell shell = new Shell (display); + Display display = new Display(); + Shell shell = new Shell(display); shell.setLayout(new FillLayout()); - new TerminalTextCanvas(shell,SWT.NONE); - shell.setSize (200, 150); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); + new TerminalTextCanvas(shell, SWT.NONE); + shell.setSize(200, 150); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); } - display.dispose (); + display.dispose(); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Snippet48.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Snippet48.java index f3a96c99ad3..a271d33fdc8 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Snippet48.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/Snippet48.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.terminalcanvas; - /* * Canvas example snippet: scroll an image (flicker free, no double buffering) * @@ -35,87 +34,89 @@ import org.eclipse.swt.widgets.Shell; public class Snippet48 { -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - Image originalImage = null; - FileDialog dialog = new FileDialog (shell, SWT.OPEN); - dialog.setText ("Open an image file or cancel"); - String string = dialog.open (); - if (string != null) { - originalImage = new Image (display, string); - } - final Image image = originalImage; - final Point origin = new Point (0, 0); - final Canvas canvas = new Canvas (shell, SWT.NO_BACKGROUND | - SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); - final ScrollBar hBar = canvas.getHorizontalBar (); - hBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int hSelection = hBar.getSelection (); - int destX = -hSelection - origin.x; - Rectangle rect = image.getBounds (); - canvas.scroll (destX, 0, 0, 0, rect.width, rect.height, false); - origin.x = -hSelection; + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Image originalImage = null; + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setText("Open an image file or cancel"); + String string = dialog.open(); + if (string != null) { + originalImage = new Image(display, string); } - }); - final ScrollBar vBar = canvas.getVerticalBar (); - vBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int vSelection = vBar.getSelection (); - int destY = -vSelection - origin.y; - Rectangle rect = image.getBounds (); - canvas.scroll (0, destY, 0, 0, rect.width, rect.height, false); - origin.y = -vSelection; - } - }); - canvas.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = image.getBounds (); - Rectangle client = canvas.getClientArea (); - hBar.setMaximum (rect.width); - vBar.setMaximum (rect.height); - hBar.setThumb (Math.min (rect.width, client.width)); - vBar.setThumb (Math.min (rect.height, client.height)); - int hPage = rect.width - client.width; - int vPage = rect.height - client.height; - int hSelection = hBar.getSelection (); - int vSelection = vBar.getSelection (); - if (hSelection >= hPage) { - if (hPage <= 0) hSelection = 0; + final Image image = originalImage; + final Point origin = new Point(0, 0); + final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); + final ScrollBar hBar = canvas.getHorizontalBar(); + hBar.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { + int hSelection = hBar.getSelection(); + int destX = -hSelection - origin.x; + Rectangle rect = image.getBounds(); + canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } - if (vSelection >= vPage) { - if (vPage <= 0) vSelection = 0; + }); + final ScrollBar vBar = canvas.getVerticalBar(); + vBar.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { + int vSelection = vBar.getSelection(); + int destY = -vSelection - origin.y; + Rectangle rect = image.getBounds(); + canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; } - canvas.redraw (); - } - }); - canvas.addListener (SWT.Paint, new Listener () { - public void handleEvent (Event e) { - GC gc = e.gc; - gc.drawImage (image, origin.x, origin.y); - Rectangle rect = image.getBounds (); - Rectangle client = canvas.getClientArea (); - int marginWidth = client.width - rect.width; - if (marginWidth > 0) { - gc.fillRectangle (rect.width, 0, marginWidth, client.height); + }); + canvas.addListener(SWT.Resize, new Listener() { + public void handleEvent(Event e) { + Rectangle rect = image.getBounds(); + Rectangle client = canvas.getClientArea(); + hBar.setMaximum(rect.width); + vBar.setMaximum(rect.height); + hBar.setThumb(Math.min(rect.width, client.width)); + vBar.setThumb(Math.min(rect.height, client.height)); + int hPage = rect.width - client.width; + int vPage = rect.height - client.height; + int hSelection = hBar.getSelection(); + int vSelection = vBar.getSelection(); + if (hSelection >= hPage) { + if (hPage <= 0) + hSelection = 0; + origin.x = -hSelection; + } + if (vSelection >= vPage) { + if (vPage <= 0) + vSelection = 0; + origin.y = -vSelection; + } + canvas.redraw(); } - int marginHeight = client.height - rect.height; - if (marginHeight > 0) { - gc.fillRectangle (0, rect.height, client.width, marginHeight); + }); + canvas.addListener(SWT.Paint, new Listener() { + public void handleEvent(Event e) { + GC gc = e.gc; + gc.drawImage(image, origin.x, origin.y); + Rectangle rect = image.getBounds(); + Rectangle client = canvas.getClientArea(); + int marginWidth = client.width - rect.width; + if (marginWidth > 0) { + gc.fillRectangle(rect.width, 0, marginWidth, client.height); + } + int marginHeight = client.height - rect.height; + if (marginHeight > 0) { + gc.fillRectangle(0, rect.height, client.width, marginHeight); + } } + }); + shell.setSize(200, 150); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); } - }); - shell.setSize (200, 150); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); + originalImage.dispose(); + display.dispose(); } - originalImage.dispose(); - display.dispose (); -} -} +} diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/TerminalTextCanvas.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/TerminalTextCanvas.java index 5027b2b3e80..02baabdfe49 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/TerminalTextCanvas.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/TerminalTextCanvas.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.terminalcanvas; @@ -24,79 +24,82 @@ import org.eclipse.swt.widgets.ScrollBar; public class TerminalTextCanvas extends Canvas { Image image; - Point origin = new Point (0, 0); + Point origin = new Point(0, 0); + public TerminalTextCanvas(Composite parent, int style) { - super(parent, SWT.NO_BACKGROUND | - SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL| style); + super(parent, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL | style); loadImage(parent); - final ScrollBar hBar = getHorizontalBar (); - hBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int hSelection = hBar.getSelection (); + final ScrollBar hBar = getHorizontalBar(); + hBar.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { + int hSelection = hBar.getSelection(); int destX = -hSelection - origin.x; - Rectangle rect = image.getBounds (); - scroll (destX, 0, 0, 0, rect.width, rect.height, false); + Rectangle rect = image.getBounds(); + scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); - final ScrollBar vBar = getVerticalBar (); - vBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int vSelection = vBar.getSelection (); + final ScrollBar vBar = getVerticalBar(); + vBar.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { + int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; - Rectangle rect = image.getBounds (); - scroll (0, destY, 0, 0, rect.width, rect.height, false); + Rectangle rect = image.getBounds(); + scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; } }); - addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = image.getBounds (); - Rectangle client = getClientArea (); - hBar.setMaximum (rect.width); - vBar.setMaximum (rect.height); - hBar.setThumb (Math.min (rect.width, client.width)); - vBar.setThumb (Math.min (rect.height, client.height)); + addListener(SWT.Resize, new Listener() { + public void handleEvent(Event e) { + Rectangle rect = image.getBounds(); + Rectangle client = getClientArea(); + hBar.setMaximum(rect.width); + vBar.setMaximum(rect.height); + hBar.setThumb(Math.min(rect.width, client.width)); + vBar.setThumb(Math.min(rect.height, client.height)); int hPage = rect.width - client.width; int vPage = rect.height - client.height; - int hSelection = hBar.getSelection (); - int vSelection = vBar.getSelection (); + int hSelection = hBar.getSelection(); + int vSelection = vBar.getSelection(); if (hSelection >= hPage) { - if (hPage <= 0) hSelection = 0; + if (hPage <= 0) + hSelection = 0; origin.x = -hSelection; } if (vSelection >= vPage) { - if (vPage <= 0) vSelection = 0; + if (vPage <= 0) + vSelection = 0; origin.y = -vSelection; } - redraw (); + redraw(); } }); - addListener (SWT.Paint, new Listener () { - public void handleEvent (Event e) { + addListener(SWT.Paint, new Listener() { + public void handleEvent(Event e) { GC gc = e.gc; - System.out.println(gc.getClipping()+" "+origin); - gc.drawImage (image, origin.x, origin.y); - Rectangle rect = image.getBounds (); - Rectangle client = getClientArea (); + System.out.println(gc.getClipping() + " " + origin); + gc.drawImage(image, origin.x, origin.y); + Rectangle rect = image.getBounds(); + Rectangle client = getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { - gc.fillRectangle (rect.width, 0, marginWidth, client.height); + gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { - gc.fillRectangle (0, rect.height, client.width, marginHeight); + gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); } + private void loadImage(Composite parent) { - FileDialog dialog = new FileDialog (parent.getShell(), SWT.OPEN); - dialog.setText ("Open an image file or cancel"); - String string = dialog.open (); + FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); + dialog.setText("Open an image file or cancel"); + String string = dialog.open(); if (string != null) { - image = new Image (getDisplay(), string); + image = new Image(getDisplay(), string); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/VirtualCanvas.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/VirtualCanvas.java index 461f544dfb9..4cda278e8bf 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/VirtualCanvas.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/terminalcanvas/VirtualCanvas.java @@ -1,16 +1,15 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.terminalcanvas; - import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; @@ -31,12 +30,13 @@ import org.eclipse.swt.widgets.ScrollBar; */ public abstract class VirtualCanvas extends Canvas { - private final Rectangle fVirtualBounds = new Rectangle(0,0,0,0); + private final Rectangle fVirtualBounds = new Rectangle(0, 0, 0, 0); private Rectangle fClientArea; - private GC fPaintGC=null; + private GC fPaintGC = null; + public VirtualCanvas(Composite parent, int style) { - super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE); - fPaintGC= new GC(this); + super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE); + fPaintGC = new GC(this); addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { paint(event.gc); @@ -44,13 +44,13 @@ public abstract class VirtualCanvas extends Canvas { }); addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { - fClientArea=getClientArea(); + fClientArea = getClientArea(); updateViewRectangle(); } }); getVerticalBar().addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { - scrollY((ScrollBar)e.widget); + scrollY((ScrollBar) e.widget); postScrollEventHandling(e); } @@ -58,32 +58,35 @@ public abstract class VirtualCanvas extends Canvas { }); getHorizontalBar().addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { - scrollX((ScrollBar)e.widget); + scrollX((ScrollBar) e.widget); postScrollEventHandling(e); } }); - addDisposeListener(new DisposeListener(){ + addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { - if(fPaintGC!=null){ + if (fPaintGC != null) { fPaintGC.dispose(); - fPaintGC=null; + fPaintGC = null; } } - + }); } + public void setAutoSelect(boolean on) { } + public boolean hasAutoSelect() { return false; } + public void doAutoSelect() { } - + /** HACK: run an event loop if the scrollbar is dragged...*/ private void postScrollEventHandling(Event e) { - if(true&&e.detail==SWT.DRAG) { + if (true && e.detail == SWT.DRAG) { // TODO check if this is always ok??? // used to process runnables while scrolling // This fixes the update problems when scrolling! @@ -92,74 +95,75 @@ public abstract class VirtualCanvas extends Canvas { // The alternative is to call redraw on the new visible area // redraw(expose.x, expose.y, expose.width, expose.height, true); - while (!getDisplay().isDisposed() && getDisplay().readAndDispatch()) { + while (!getDisplay().isDisposed() && getDisplay().readAndDispatch()) { // do nothing here... } } } - + protected void scrollX(ScrollBar hBar) { - int hSelection = hBar.getSelection (); + int hSelection = hBar.getSelection(); int destX = -hSelection - fVirtualBounds.x; fVirtualBounds.x = -hSelection; scrollSmart(destX, 0); updateViewRectangle(); } + protected void scrollXDelta(int delta) { - getHorizontalBar().setSelection(-fVirtualBounds.x+delta); + getHorizontalBar().setSelection(-fVirtualBounds.x + delta); scrollX(getHorizontalBar()); } protected void scrollY(ScrollBar vBar) { - int vSelection = vBar.getSelection (); + int vSelection = vBar.getSelection(); int destY = -vSelection - fVirtualBounds.y; fVirtualBounds.y = -vSelection; - scrollSmart(0,destY); + scrollSmart(0, destY); updateViewRectangle(); - + } + protected void scrollYDelta(int delta) { - getVerticalBar().setSelection(-fVirtualBounds.y+delta); + getVerticalBar().setSelection(-fVirtualBounds.y + delta); scrollY(getVerticalBar()); } - private void scrollSmart(int deltaX, int deltaY) { Rectangle rect = getBounds(); - scroll (deltaX, deltaY, 0, 0, rect.width, rect.height, false); + scroll(deltaX, deltaY, 0, 0, rect.width, rect.height, false); } protected void revealRect(Rectangle rect) { - Rectangle visibleRect=getScreenRectInVirtualSpace(); + Rectangle visibleRect = getScreenRectInVirtualSpace(); // scroll the X part - int deltaX=0; - if(rect.x0||marginHeight>0){ - Color bg=getBackground(); + int width = fVirtualBounds.width; + int height = fVirtualBounds.height; + int marginWidth = (clipping.x + clipping.width) - width; + int marginHeight = (clipping.y + clipping.height) - height; + if (marginWidth > 0 || marginHeight > 0) { + Color bg = getBackground(); gc.setBackground(getBackgroundCanvasColor()); if (marginWidth > 0) { - gc.fillRectangle (width, clipping.y, marginWidth, clipping.height); + gc.fillRectangle(width, clipping.y, marginWidth, clipping.height); } if (marginHeight > 0) { - gc.fillRectangle (clipping.x, height, clipping.width, marginHeight); + gc.fillRectangle(clipping.x, height, clipping.width, marginHeight); } gc.setBackground(bg); } } + /** * @private */ protected boolean inClipping(Rectangle clipping, Rectangle r) { // TODO check if this is OK in all cases (the <=!) - // - if(r.x+r.width<=clipping.x) + // + if (r.x + r.width <= clipping.x) return false; - if(clipping.x+clipping.width<=r.x) + if (clipping.x + clipping.width <= r.x) return false; - if(r.y+r.height<=clipping.y) + if (r.y + r.height <= clipping.y) return false; - if(clipping.y+clipping.height<=r.y) + if (clipping.y + clipping.height <= r.y) return false; - + return true; } + /** * @return the screen rect in virtual space (starting with (0,0)) * of the visible screen. (x,y>=0) */ protected Rectangle getScreenRectInVirtualSpace() { - return new Rectangle(fClientArea.x-fVirtualBounds.x,fClientArea.y-fVirtualBounds.y,fClientArea.width,fClientArea.height); + return new Rectangle(fClientArea.x - fVirtualBounds.x, fClientArea.y - fVirtualBounds.y, fClientArea.width, + fClientArea.height); } + /** * @return the rect in virtual space (starting with (0,0)) * of the visible screen. (x,y>=0) */ protected Rectangle getRectInVirtualSpace(Rectangle r) { - return new Rectangle(r.x-fVirtualBounds.x,r.y-fVirtualBounds.y,r.width,r.height); + return new Rectangle(r.x - fVirtualBounds.x, r.y - fVirtualBounds.y, r.width, r.height); } - + /** * Sets the extend of the virtual dieplay ares * @param width * @param height */ protected void setVirtualExtend(int width, int height) { - fVirtualBounds.width=width; - fVirtualBounds.height=height; + fVirtualBounds.width = width; + fVirtualBounds.height = height; updateScrollbars(); updateViewRectangle(); } + /** * sets the scrolling origin. Also sets the scrollbars. * Does NOT redraw! @@ -242,8 +253,8 @@ public abstract class VirtualCanvas extends Canvas { * @param y */ protected void setVirtualOrigin(int x, int y) { - fVirtualBounds.x=x; - fVirtualBounds.y=y; + fVirtualBounds.x = x; + fVirtualBounds.y = y; getHorizontalBar().setSelection(x); getVerticalBar().setSelection(y); updateViewRectangle(); @@ -254,36 +265,39 @@ public abstract class VirtualCanvas extends Canvas { * @return the virtual coordinate in scree space */ protected int virtualXtoScreen(int x) { - return x+fVirtualBounds.x; + return x + fVirtualBounds.x; } + protected int virtualYtoScreen(int y) { - return y+fVirtualBounds.y; + return y + fVirtualBounds.y; } + protected int screenXtoVirtual(int x) { - return x-fVirtualBounds.x; + return x - fVirtualBounds.x; } + protected int screenYtoVirtual(int y) { - return y-fVirtualBounds.y; + return y - fVirtualBounds.y; } + /** called when the viewed part is changing */ - private final Rectangle fViewRectangle=new Rectangle(0,0,0,0); + private final Rectangle fViewRectangle = new Rectangle(0, 0, 0, 0); + void updateViewRectangle() { - if( - fViewRectangle.x==-fVirtualBounds.x - && fViewRectangle.y==-fVirtualBounds.y - && fViewRectangle.width==fClientArea.width - && fViewRectangle.height==fClientArea.height - ) + if (fViewRectangle.x == -fVirtualBounds.x && fViewRectangle.y == -fVirtualBounds.y + && fViewRectangle.width == fClientArea.width && fViewRectangle.height == fClientArea.height) return; - fViewRectangle.x=-fVirtualBounds.x; - fViewRectangle.y=-fVirtualBounds.y; - fViewRectangle.width=fClientArea.width; - fViewRectangle.height=fClientArea.height; - viewRectangleChanged(fViewRectangle.x,fViewRectangle.y,fViewRectangle.width,fViewRectangle.height); + fViewRectangle.x = -fVirtualBounds.x; + fViewRectangle.y = -fVirtualBounds.y; + fViewRectangle.width = fClientArea.width; + fViewRectangle.height = fClientArea.height; + viewRectangleChanged(fViewRectangle.x, fViewRectangle.y, fViewRectangle.width, fViewRectangle.height); } + protected Rectangle getViewRectangle() { return fViewRectangle; } + /** * Called when the viewed part has changed. * Override when you need this information.... @@ -294,16 +308,17 @@ public abstract class VirtualCanvas extends Canvas { * @param height */ protected void viewRectangleChanged(int x, int y, int width, int height) { -// System.out.println(x+" "+y+" "+width+" "+height); + // System.out.println(x+" "+y+" "+width+" "+height); } + /** * @private */ private void updateScrollbars() { - Point size= getSize(); - Rectangle clientArea= getClientArea(); - - ScrollBar horizontal= getHorizontalBar(); + Point size = getSize(); + Rectangle clientArea = getClientArea(); + + ScrollBar horizontal = getHorizontalBar(); if (fVirtualBounds.width <= clientArea.width) { // TODO IMPORTANT in ScrollBar.setVisible comment out the line // that checks 'isvisible' and returns (at the beginning) @@ -311,23 +326,22 @@ public abstract class VirtualCanvas extends Canvas { horizontal.setSelection(0); } else { horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement()); - int max= fVirtualBounds.width + (size.x - clientArea.width); + int max = fVirtualBounds.width + (size.x - clientArea.width); horizontal.setMaximum(max); horizontal.setThumb(size.x > max ? max : size.x); horizontal.setVisible(true); } - - ScrollBar vertical= getVerticalBar(); + + ScrollBar vertical = getVerticalBar(); if (fVirtualBounds.height <= clientArea.height) { vertical.setVisible(false); vertical.setSelection(0); } else { vertical.setPageIncrement(clientArea.height - vertical.getIncrement()); - int max= fVirtualBounds.height + (size.y - clientArea.height); + int max = fVirtualBounds.height + (size.y - clientArea.height); vertical.setMaximum(max); vertical.setThumb(size.y > max ? max : size.y); vertical.setVisible(true); } } } - diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/AbstractLineOrientedDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/AbstractLineOrientedDataSource.java index 82311f06f36..78a688bbed4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/AbstractLineOrientedDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/AbstractLineOrientedDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -19,23 +19,24 @@ import org.eclipse.tm.terminal.model.Style; */ abstract class AbstractLineOrientedDataSource implements IDataSource { abstract public char[] dataSource(); + abstract public Style getStyle(); abstract public void next(); public int step(ITerminalTextData terminal) { next(); - char[] chars=dataSource(); - Style style= getStyle(); + char[] chars = dataSource(); + Style style = getStyle(); int len; // keep the synchronized block short! synchronized (terminal) { terminal.addLine(); - len=Math.min(terminal.getWidth(),chars.length); - int line=terminal.getHeight()-1; + len = Math.min(terminal.getWidth(), chars.length); + int line = terminal.getHeight() - 1; terminal.setChars(line, 0, chars, 0, len, style); terminal.setCursorLine(line); - terminal.setCursorColumn(len-1); + terminal.setCursorColumn(len - 1); } return len; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/DataReader.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/DataReader.java index 854509a1ecd..1c9327617d5 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/DataReader.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/DataReader.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -21,47 +21,53 @@ class DataReader implements Runnable { volatile int fThrottleTime; final IStatus fStatus; final String fName; + DataReader(String name, ITerminalTextData terminal, IDataSource dataSource, IStatus status) { - fStatus=status; - fName=name; - fTerminal=terminal; - fDataSource=dataSource; - fThread=new Thread(this,name); + fStatus = status; + fName = name; + fTerminal = terminal; + fDataSource = dataSource; + fThread = new Thread(this, name); fThread.setDaemon(true); fThread.start(); } + public void run() { - long t0=System.currentTimeMillis()-1; - long c=0; - int lines=0; - while(!Thread.interrupted()) { - while(!fStart || fStop) { + long t0 = System.currentTimeMillis() - 1; + long c = 0; + int lines = 0; + while (!Thread.interrupted()) { + while (!fStart || fStop) { sleep(1); } - if(fThrottleTime>0) + if (fThrottleTime > 0) sleep(fThrottleTime); // synchronize because we have to be sure the size does not change while // we add lines - int len=fDataSource.step(fTerminal); + int len = fDataSource.step(fTerminal); // keep the synchronized block short! - c+=len; + c += len; lines++; - if((fThrottleTime>0 || (lines%100==0))&&(System.currentTimeMillis()-t0)>1000) { - long t=System.currentTimeMillis()-t0; - final String s=(c*1000)/(t*1024)+"kb/s " + (lines*1000)/t+"lines/sec "+(c*1000*8)/t+" bits/s "; + if ((fThrottleTime > 0 || (lines % 100 == 0)) && (System.currentTimeMillis() - t0) > 1000) { + long t = System.currentTimeMillis() - t0; + final String s = (c * 1000) / (t * 1024) + "kb/s " + (lines * 1000) / t + "lines/sec " + + (c * 1000 * 8) / t + " bits/s "; fStatus.setStatus(s); - lines=0; - t0=System.currentTimeMillis(); - c=0; + lines = 0; + t0 = System.currentTimeMillis(); + c = 0; } } } + public int getThrottleTime() { return fThrottleTime; } + public void setThrottleTime(int throttleTime) { fThrottleTime = throttleTime; } + private void sleep(int ms) { try { Thread.sleep(ms); @@ -69,18 +75,23 @@ class DataReader implements Runnable { Thread.currentThread().interrupt(); } } + public boolean isStart() { return fStart; } + public void setStart(boolean start) { fStart = start; } + public String getName() { return fName; } + public boolean isStop() { return fStop; } + public void setStop(boolean stop) { fStop = stop; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FastDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FastDataSource.java index ce4ac180794..56a49c09bfc 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FastDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FastDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -13,16 +13,14 @@ package org.eclipse.tm.internal.terminal.test.ui; import org.eclipse.tm.terminal.model.Style; final class FastDataSource extends AbstractLineOrientedDataSource { - char lines[][]=new char[][]{ + char lines[][] = new char[][] { "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 ".toCharArray(), - "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ".toCharArray(), - }; - + "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ".toCharArray(), }; int pos; public char[] dataSource() { - return lines[pos%lines.length]; + return lines[pos % lines.length]; } public Style getStyle() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FileDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FileDataSource.java index 7680394e6a2..a64135cc218 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FileDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/FileDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -31,9 +31,9 @@ final class FileDataSource extends AbstractLineOrientedDataSource { Style style; - Style styleNormal=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("white")); + Style styleNormal = Style.getStyle(StyleColor.getStyleColor("black"), StyleColor.getStyleColor("white")); - Style styleBold=styleNormal.setBold(true); + Style styleBold = styleNormal.setBold(true); FileDataSource(String file) { fFile = file; @@ -49,20 +49,20 @@ final class FileDataSource extends AbstractLineOrientedDataSource { public void next() { try { - if(reader==null) + if (reader == null) reader = new BufferedReader(new FileReader(fFile)); - line=reader.readLine(); - if(line==null) { + line = reader.readLine(); + if (line == null) { reader.close(); - reader=null; + reader = null; // reopen the file next(); return; } - if(line.lastIndexOf('x')>0) - style=styleBold; + if (line.lastIndexOf('x') > 0) + style = styleBold; else - style=styleNormal; + style = styleNormal; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IDataSource.java index 44a2bf6400e..93f25146100 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IStatus.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IStatus.java index 351023697a6..02f8319878f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IStatus.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/IStatus.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/LineCountingDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/LineCountingDataSource.java index 8be77cb2c4f..e0931ff2340 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/LineCountingDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/LineCountingDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -14,27 +14,22 @@ import org.eclipse.tm.terminal.model.Style; import org.eclipse.tm.terminal.model.StyleColor; final class LineCountingDataSource extends AbstractLineOrientedDataSource { - Style styleNormal=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("red")); + Style styleNormal = Style.getStyle(StyleColor.getStyleColor("black"), StyleColor.getStyleColor("red")); - Style styles[]=new Style[] { - styleNormal, - styleNormal.setBold(true), - styleNormal.setForground("blue"), - styleNormal.setForground("yellow"), - styleNormal.setBold(true).setUnderline(true), - styleNormal.setReverse(true), - styleNormal.setReverse(true).setBold(true), - styleNormal.setReverse(true).setUnderline(true) - }; + Style styles[] = new Style[] { styleNormal, styleNormal.setBold(true), styleNormal.setForground("blue"), + styleNormal.setForground("yellow"), styleNormal.setBold(true).setUnderline(true), + styleNormal.setReverse(true), styleNormal.setReverse(true).setBold(true), + styleNormal.setReverse(true).setUnderline(true) }; int pos; public char[] dataSource() { - return (pos+" 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789").toCharArray(); + return (pos + " 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789") + .toCharArray(); } public Style getStyle() { - return styles[pos%styles.length]; + return styles[pos % styles.length]; } public void next() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/RandomDataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/RandomDataSource.java index 5e797f10808..308739ef2ab 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/RandomDataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/RandomDataSource.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -17,29 +17,23 @@ import org.eclipse.tm.terminal.model.Style; import org.eclipse.tm.terminal.model.StyleColor; public class RandomDataSource implements IDataSource { - Random fRandom=new Random(); - Style styleNormal=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("green")); - Style styles[]=new Style[] { - styleNormal, - styleNormal.setBold(true), - styleNormal.setForground("red"), - styleNormal.setForground("yellow"), - styleNormal.setBold(true).setUnderline(true), - styleNormal.setReverse(true), - styleNormal.setReverse(true).setBold(true), - styleNormal.setReverse(true).setUnderline(true) - }; + Random fRandom = new Random(); + Style styleNormal = Style.getStyle(StyleColor.getStyleColor("black"), StyleColor.getStyleColor("green")); + Style styles[] = new Style[] { styleNormal, styleNormal.setBold(true), styleNormal.setForground("red"), + styleNormal.setForground("yellow"), styleNormal.setBold(true).setUnderline(true), + styleNormal.setReverse(true), styleNormal.setReverse(true).setBold(true), + styleNormal.setReverse(true).setUnderline(true) }; public int step(ITerminalTextData terminal) { - int N=fRandom.nextInt(1000); - int h=terminal.getHeight(); - int w=terminal.getWidth(); + int N = fRandom.nextInt(1000); + int h = terminal.getHeight(); + int w = terminal.getWidth(); synchronized (terminal) { for (int i = 0; i < N; i++) { - int line=fRandom.nextInt(h); - int col=fRandom.nextInt(w); - char c=(char)('A'+fRandom.nextInt('z'-'A')); - Style style=styles[fRandom.nextInt(styles.length)]; + int line = fRandom.nextInt(h); + int col = fRandom.nextInt(w); + char c = (char) ('A' + fRandom.nextInt('z' - 'A')); + Style style = styles[fRandom.nextInt(styles.length)]; terminal.setChar(line, col, c, style); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/TerminalTextUITest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/TerminalTextUITest.java index 284d2c859d1..2949b6ebe49 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/TerminalTextUITest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/TerminalTextUITest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.test.ui; @@ -41,7 +41,7 @@ import org.eclipse.tm.terminal.model.TerminalTextDataFactory; /** * adjust columns when table gets resized.... - * + * */ public class TerminalTextUITest { static TextCanvas fgTextCanvas; @@ -51,40 +51,42 @@ public class TerminalTextUITest { static volatile int fHeight; static volatile int fWidth; static DataReader fDataReader; - static List fDataReaders=new ArrayList(); + static List fDataReaders = new ArrayList(); private static Text heightText; + static class Status implements IStatus { public void setStatus(final String s) { - if(!fStatusLabel.isDisposed()) - Display.getDefault().asyncExec(new Runnable(){ + if (!fStatusLabel.isDisposed()) + Display.getDefault().asyncExec(new Runnable() { public void run() { - if(!fStatusLabel.isDisposed()) + if (!fStatusLabel.isDisposed()) fStatusLabel.setText(s); - }}); + } + }); } - + } + public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); - Composite composite=new Composite(shell, SWT.NONE); + Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); RowLayout layout = new RowLayout(SWT.HORIZONTAL); layout.wrap = true; layout.fill = false; - fTerminalModel=TerminalTextDataFactory.makeTerminalTextData(); - fHeight=24; - fWidth=80; + fTerminalModel = TerminalTextDataFactory.makeTerminalTextData(); + fHeight = 24; + fWidth = 80; fTerminalModel.setDimensions(fHeight, fWidth); fTerminalModel.setMaxHeight(fHeight); - ITerminalTextDataSnapshot snapshot=fTerminalModel.makeSnapshot(); + ITerminalTextDataSnapshot snapshot = fTerminalModel.makeSnapshot(); // TODO how to get the initial size correctly! snapshot.updateSnapshot(false); - fgModel=new PollingTextCanvasModel(snapshot); - fgTextCanvas=new TextCanvas(shell,fgModel, SWT.NONE,new TextLineRenderer(fgTextCanvas,fgModel)); + fgModel = new PollingTextCanvasModel(snapshot); + fgTextCanvas = new TextCanvas(shell, fgModel, SWT.NONE, new TextLineRenderer(fgTextCanvas, fgModel)); fgTextCanvas.setLayoutData(new GridData(GridData.FILL_BOTH)); - composite.setLayout(layout); addAutorevealCursorButton(composite); @@ -92,29 +94,29 @@ public class TerminalTextUITest { addHeightInput(composite, maxHeightText); addWidthText(composite); Text throttleText = addThrottleText(composite); - - IStatus status=new Status(); - DataReader reader=new DataReader("Line Count",fTerminalModel,new LineCountingDataSource(),status); + + IStatus status = new Status(); + DataReader reader = new DataReader("Line Count", fTerminalModel, new LineCountingDataSource(), status); addDataReader(composite, reader); - reader=new DataReader("Fast",fTerminalModel,new FastDataSource(),status); + reader = new DataReader("Fast", fTerminalModel, new FastDataSource(), status); addDataReader(composite, reader); - reader=new DataReader("Random",fTerminalModel,new RandomDataSource(),status); + reader = new DataReader("Random", fTerminalModel, new RandomDataSource(), status); addDataReader(composite, reader); for (int i = 0; i < args.length; i++) { - File file=new File(args[i]); - reader=new DataReader(file.getName(),fTerminalModel,new VT100DataSource(args[i]),status); + File file = new File(args[i]); + reader = new DataReader(file.getName(), fTerminalModel, new VT100DataSource(args[i]), status); addDataReader(composite, reader); } addStopAllButton(composite, reader); - - fStatusLabel=new Label(shell,SWT.NONE); - fStatusLabel.setLayoutData(new GridData(250,15)); + + fStatusLabel = new Label(shell, SWT.NONE); + fStatusLabel.setLayoutData(new GridData(250, 15)); throttleText.setText("100"); setThrottleForAll(100); - if(args.length==0) + if (args.length == 0) addLabel(composite, "[Files can be added via commandline]"); - shell.setSize(600,300); + shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) @@ -122,126 +124,141 @@ public class TerminalTextUITest { } display.dispose(); } + private static Text addMaxHeightInput(Composite composite) { addLabel(composite, "maxHeight:"); - final Text maxHeightText=new Text(composite,SWT.BORDER); - setLayoutData(maxHeightText,30); - maxHeightText.addModifyListener(new ModifyListener(){ + final Text maxHeightText = new Text(composite, SWT.BORDER); + setLayoutData(maxHeightText, 30); + maxHeightText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { synchronized (fTerminalModel) { - int height=textToInt(maxHeightText); - if(height<1) + int height = textToInt(maxHeightText); + if (height < 1) return; - if(fTerminalModel.getHeight()>height) { - fTerminalModel.scroll(0, fTerminalModel.getHeight(), height-fTerminalModel.getHeight()); - fTerminalModel.setDimensions(height,fTerminalModel.getWidth()); - heightText.setText(height+""); + if (fTerminalModel.getHeight() > height) { + fTerminalModel.scroll(0, fTerminalModel.getHeight(), height - fTerminalModel.getHeight()); + fTerminalModel.setDimensions(height, fTerminalModel.getWidth()); + heightText.setText(height + ""); } fTerminalModel.setMaxHeight(height); } } }); - maxHeightText.setText(fHeight+""); + maxHeightText.setText(fHeight + ""); return maxHeightText; } + private static void addHeightInput(Composite composite, final Text maxHeightText) { - addLabel(composite,"heigth:"); - heightText=new Text(composite,SWT.BORDER); - setLayoutData(heightText,30); - heightText.addModifyListener(new ModifyListener(){ + addLabel(composite, "heigth:"); + heightText = new Text(composite, SWT.BORDER); + setLayoutData(heightText, 30); + heightText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { synchronized (fTerminalModel) { - int height=textToInt(heightText); - if(height<1) + int height = textToInt(heightText); + if (height < 1) return; - maxHeightText.setText(""+height); - fTerminalModel.setDimensions(height,fTerminalModel.getWidth()); + maxHeightText.setText("" + height); + fTerminalModel.setDimensions(height, fTerminalModel.getWidth()); fTerminalModel.setMaxHeight(height); } } }); - heightText.setText(fHeight+""); + heightText.setText(fHeight + ""); } + private static Text addWidthText(Composite composite) { - addLabel(composite,"width:"); - final Text widthText=new Text(composite,SWT.BORDER); - setLayoutData(widthText,30); - widthText.addModifyListener(new ModifyListener(){ + addLabel(composite, "width:"); + final Text widthText = new Text(composite, SWT.BORDER); + setLayoutData(widthText, 30); + widthText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { synchronized (fTerminalModel) { - int width=textToInt(widthText); - if(width>1) + int width = textToInt(widthText); + if (width > 1) fTerminalModel.setDimensions(fTerminalModel.getHeight(), width); } } }); - widthText.setText(fWidth+""); + widthText.setText(fWidth + ""); return widthText; } + private static Text addThrottleText(Composite composite) { - addLabel(composite,"throttle:"); - final Text throttleText=new Text(composite,SWT.BORDER); - setLayoutData(throttleText,30); - throttleText.addModifyListener(new ModifyListener(){ + addLabel(composite, "throttle:"); + final Text throttleText = new Text(composite, SWT.BORDER); + setLayoutData(throttleText, 30); + throttleText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { synchronized (fTerminalModel) { - int throttle=textToInt(throttleText); + int throttle = textToInt(throttleText); setThrottleForAll(throttle); } - }}); + } + }); return throttleText; } + private static void addStopAllButton(Composite composite, DataReader reader) { - final Button stopAllButton=new Button(composite,SWT.CHECK); + final Button stopAllButton = new Button(composite, SWT.CHECK); stopAllButton.setText("Stop ALL"); - stopAllButton.addSelectionListener(new SelectionAdapter(){ + stopAllButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - boolean stop=stopAllButton.getSelection(); + boolean stop = stopAllButton.getSelection(); for (Iterator iterator = fDataReaders.iterator(); iterator.hasNext();) { DataReader reader = (DataReader) iterator.next(); reader.setStop(stop); - }}}); + } + } + }); stopAllButton.setSelection(reader.isStart()); } + private static void addAutorevealCursorButton(Composite composite) { - final Button button=new Button(composite,SWT.CHECK); + final Button button = new Button(composite, SWT.CHECK); button.setText("ScrollLock"); - button.addSelectionListener(new SelectionAdapter(){ + button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - boolean scrollLock=button.getSelection(); + boolean scrollLock = button.getSelection(); fgTextCanvas.setScrollLock(scrollLock); } }); button.setSelection(fgTextCanvas.isScrollLock()); } - private static void addLabel(Composite composite,String message) { + + private static void addLabel(Composite composite, String message) { Label label; - label=new Label(composite, SWT.NONE); + label = new Label(composite, SWT.NONE); label.setText(message); } + private static void addDataReader(Composite composite, final DataReader reader) { fDataReaders.add(reader); - final Button button=new Button(composite,SWT.CHECK); + final Button button = new Button(composite, SWT.CHECK); button.setText(reader.getName()); - button.addSelectionListener(new SelectionAdapter(){ + button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { reader.setStart(button.getSelection()); - }}); + } + }); button.setSelection(reader.isStart()); - + } + static private void setThrottleForAll(int throttle) { for (Iterator iterator = fDataReaders.iterator(); iterator.hasNext();) { DataReader reader = (DataReader) iterator.next(); reader.setThrottleTime(throttle); } } - static void setLayoutData(Control c,int width) { - c.setLayoutData(new RowData(width,-1)); + + static void setLayoutData(Control c, int width) { + c.setLayoutData(new RowData(width, -1)); } + static int textToInt(Text text) { try { return Integer.valueOf(text.getText()).intValue(); @@ -250,4 +267,3 @@ public class TerminalTextUITest { } } } - diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/VT100DataSource.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/VT100DataSource.java index 589e9542f65..89bb0c4299f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/VT100DataSource.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/test/ui/VT100DataSource.java @@ -42,44 +42,50 @@ final class VT100DataSource implements IDataSource { private final String fFile; VT100DataSource(String file) { - fFile=file; + fFile = file; } + class InfiniteFileInputStream extends InputStream { public InfiniteFileInputStream() { try { - fInputStream=new FileInputStream(fFile); + fInputStream = new FileInputStream(fFile); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + public int available() throws IOException { return fAvailable; } + private InputStream fInputStream; + public int read() throws IOException { throw new IOException(); } + public int read(byte[] b, int off, int len) throws IOException { - while(fAvailable==0) { + while (fAvailable == 0) { try { Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } - len=fAvailable; - int n=fInputStream.read(b, off, len); - if(n<=0) { + len = fAvailable; + int n = fInputStream.read(b, off, len); + if (n <= 0) { fInputStream.close(); - fInputStream=new FileInputStream(fFile); - n=fInputStream.read(b, off, len); + fInputStream = new FileInputStream(fFile); + n = fInputStream.read(b, off, len); } - fAvailable-=n; + fAvailable -= n; return n; } } + void init(ITerminalTextData terminal) { final Reader reader; try { @@ -87,7 +93,7 @@ final class VT100DataSource implements IDataSource { } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } - fEmulator=new VT100Emulator(terminal,new ITerminalControlForText() { + fEmulator = new VT100Emulator(terminal, new ITerminalControlForText() { public void disconnectTerminal() { // TODO Auto-generated method stub @@ -116,16 +122,17 @@ final class VT100DataSource implements IDataSource { } }, reader); } + public int step(ITerminalTextData terminal) { - synchronized(terminal) { - if(fEmulator==null) { + synchronized (terminal) { + if (fEmulator == null) { init(terminal); -// fEmulator.setDimensions(48, 132); + // fEmulator.setDimensions(48, 132); fEmulator.setDimensions(24, 80); fEmulator.setCrAfterNewLine(true); } - fAvailable=80; + fAvailable = 80; fEmulator.processText(); } return 80; diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStreamPerformanceTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStreamPerformanceTest.java index 583059eae09..2b6a82d59ac 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStreamPerformanceTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStreamPerformanceTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; @@ -16,7 +16,7 @@ public class PipedInputStreamPerformanceTest { /** * @param args - * @throws InterruptedException + * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { runPerformanceTest(); @@ -24,9 +24,9 @@ public class PipedInputStreamPerformanceTest { } private static void runPerformanceTest() throws InterruptedException { - PipedInputStream in=new PipedInputStream(1024); - OutputStream out=in.getOutputStream(); - PipedStreamTest.runPipe("",in, out,100); + PipedInputStream in = new PipedInputStream(1024); + OutputStream out = in.getOutputStream(); + PipedStreamTest.runPipe("", in, out, 100); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedStreamTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedStreamTest.java index d937ae2be17..d1cdbedf36a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedStreamTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/textcanvas/PipedStreamTest.java @@ -16,7 +16,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; - class PipedStreamTest { static class ReadThread extends Thread implements Runnable { @@ -49,67 +48,81 @@ class PipedStreamTest { } } + static class FakeInputStream extends InputStream { int N; + FakeInputStream(int n) { - N=n; + N = n; } + public int read(byte[] b, int off, int len) throws IOException { - if(N==0) + if (N == 0) return -1; - int n=Math.min(len,N); - for (int i = off; i < off+n; i++) { - b[i]='x'; + int n = Math.min(len, N); + for (int i = off; i < off + n; i++) { + b[i] = 'x'; } - N-=n; + N -= n; return n; } + public int read() throws IOException { throw new UnsupportedOperationException(); } - /* + + /* * available has to be implemented! */ public int available() throws IOException { return N; } } + static class FakeOutputStream extends OutputStream { long N; + public void write(int b) throws IOException { throw new UnsupportedOperationException(); } + public void write(byte[] b, int off, int len) throws IOException { - N+=len; + N += len; } } + public static void main(String[] args) throws IOException, InterruptedException { - while(true) { + while (true) { runSunTest(); runMyTest(); } } + private static void runSunTest() throws IOException, InterruptedException { java.io.PipedInputStream in = new java.io.PipedInputStream(); OutputStream out = new java.io.PipedOutputStream(in); - runPipe("Sun ",in, out,10); + runPipe("Sun ", in, out, 10); } + private static void runMyTest() throws IOException, InterruptedException { - PipedInputStream in=new PipedInputStream(4*1024); - OutputStream out=in.getOutputStream(); - runPipe("My ",in, out,99); + PipedInputStream in = new PipedInputStream(4 * 1024); + OutputStream out = in.getOutputStream(); + runPipe("My ", in, out, 99); } - public static void runPipe(String what,InputStream writeIn, OutputStream readOut,int N) throws InterruptedException { - FakeInputStream in=new FakeInputStream(N*1000*1000); - FakeOutputStream out=new FakeOutputStream(); - ReadThread rt = new ReadThread("reader", in , readOut); + + public static void runPipe(String what, InputStream writeIn, OutputStream readOut, int N) + throws InterruptedException { + FakeInputStream in = new FakeInputStream(N * 1000 * 1000); + FakeOutputStream out = new FakeOutputStream(); + ReadThread rt = new ReadThread("reader", in, readOut); ReadThread wt = new ReadThread("writer", writeIn, out); - long t0=System.currentTimeMillis(); + long t0 = System.currentTimeMillis(); rt.start(); wt.start(); wt.join(); - long t=System.currentTimeMillis(); - long n=out.N; - System.out.println(what+n + " byte in " +(t-t0)+" ms -> "+(1000*n)/((t-t0+1)*1024)+" kb/sec"); + long t = System.currentTimeMillis(); + long n = out.N; + System.out.println( + what + n + " byte in " + (t - t0) + " ms -> " + (1000 * n) / ((t - t0 + 1) * 1024) + " kb/sec"); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/AllTests.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/AllTests.java index 35356ad0240..0b38892b92f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/AllTests.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/AllTests.java @@ -17,7 +17,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * Public Terminal Model test cases. + * Public Terminal Model test cases. * Runs in internal model package to allow access to default visible items. */ public class AllTests extends TestCase { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleColorTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleColorTest.java index 5c5784f4623..e2a48e04fdb 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleColorTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleColorTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; @@ -14,15 +14,14 @@ import junit.framework.TestCase; public class StyleColorTest extends TestCase { - public void testEqualsObject() { - assertEquals(StyleColor.getStyleColor("foo"),StyleColor.getStyleColor("foo")); + assertEquals(StyleColor.getStyleColor("foo"), StyleColor.getStyleColor("foo")); assertFalse(StyleColor.getStyleColor("foox").equals(StyleColor.getStyleColor("foo"))); } public void testSameObject() { - assertSame(StyleColor.getStyleColor("foo"),StyleColor.getStyleColor("foo")); - assertNotSame(StyleColor.getStyleColor("foox"),StyleColor.getStyleColor("foo")); + assertSame(StyleColor.getStyleColor("foo"), StyleColor.getStyleColor("foo")); + assertNotSame(StyleColor.getStyleColor("foox"), StyleColor.getStyleColor("foo")); } public void testToString() { diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleTest.java index b61de0c2c33..7e25628af66 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/model/StyleTest.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.terminal.model; @@ -13,99 +13,99 @@ package org.eclipse.tm.terminal.model; import junit.framework.TestCase; public class StyleTest extends TestCase { - final StyleColor c1=StyleColor.getStyleColor("c1"); - final StyleColor c2=StyleColor.getStyleColor("c2"); - final StyleColor c3=StyleColor.getStyleColor("c3"); + final StyleColor c1 = StyleColor.getStyleColor("c1"); + final StyleColor c2 = StyleColor.getStyleColor("c2"); + final StyleColor c3 = StyleColor.getStyleColor("c3"); public void testGetStyle() { - Style s1=Style.getStyle(c1, c2, true, false, true, false); - Style s2=Style.getStyle(c1, c2, true, false, true, false); - assertEquals(s1,s2); - assertSame(s1,s2); - s1=s1.setBlink(!s1.isBlink()); - assertNotSame(s1,s2); + Style s1 = Style.getStyle(c1, c2, true, false, true, false); + Style s2 = Style.getStyle(c1, c2, true, false, true, false); + assertEquals(s1, s2); + assertSame(s1, s2); + s1 = s1.setBlink(!s1.isBlink()); + assertNotSame(s1, s2); assertFalse(s1.equals(s2)); - s1=s1.setBlink(!s1.isBlink()); - assertSame(s1,s2); + s1 = s1.setBlink(!s1.isBlink()); + assertSame(s1, s2); } public void testSetForground() { - Style s1=Style.getStyle(c1, c2, true, false, true, false); - Style s2=s1; - s2=s1.setForground(c3); - assertNotSame(s1,s2); + Style s1 = Style.getStyle(c1, c2, true, false, true, false); + Style s2 = s1; + s2 = s1.setForground(c3); + assertNotSame(s1, s2); assertFalse(s1.equals(s2)); assertSame(s2.getForground(), c3); assertSame(s1.getForground(), c1); assertSame(s1.getBackground(), c2); assertSame(s2.getBackground(), c2); - s2=s2.setForground(c1); + s2 = s2.setForground(c1); assertSame(s1, s2); } public void testSetBackground() { - Style s1=Style.getStyle(c1, c2, true, false, true, false); - Style s2=s1; - s2=s1.setBackground(c3); - assertNotSame(s1,s2); + Style s1 = Style.getStyle(c1, c2, true, false, true, false); + Style s2 = s1; + s2 = s1.setBackground(c3); + assertNotSame(s1, s2); assertFalse(s1.equals(s2)); assertSame(s2.getForground(), c1); assertSame(s1.getForground(), c1); assertSame(s1.getBackground(), c2); assertSame(s2.getBackground(), c3); - s2=s2.setBackground(c2); + s2 = s2.setBackground(c2); assertSame(s1, s2); } public void testSetBold() { - Style s1=getDefaultStyle(); - Style s2=s1; - assertSame(s1,s2); + Style s1 = getDefaultStyle(); + Style s2 = s1; + assertSame(s1, s2); assertFalse(s2.isBold()); - s2=s2.setBold(true); - assertNotSame(s1,s2); + s2 = s2.setBold(true); + assertNotSame(s1, s2); assertTrue(s2.isBold()); - s2=s2.setBold(false); - assertSame(s1,s2); + s2 = s2.setBold(false); + assertSame(s1, s2); assertFalse(s2.isBold()); } public void testSetBlink() { - Style s1=getDefaultStyle(); - Style s2=s1; - assertSame(s1,s2); + Style s1 = getDefaultStyle(); + Style s2 = s1; + assertSame(s1, s2); assertFalse(s2.isBlink()); - s2=s2.setBlink(true); - assertNotSame(s1,s2); + s2 = s2.setBlink(true); + assertNotSame(s1, s2); assertTrue(s2.isBlink()); - s2=s2.setBlink(false); - assertSame(s1,s2); + s2 = s2.setBlink(false); + assertSame(s1, s2); assertFalse(s2.isBlink()); } public void testSetUnderline() { - Style s1=getDefaultStyle(); - Style s2=s1; - assertSame(s1,s2); + Style s1 = getDefaultStyle(); + Style s2 = s1; + assertSame(s1, s2); assertFalse(s2.isUnderline()); - s2=s2.setUnderline(true); - assertNotSame(s1,s2); + s2 = s2.setUnderline(true); + assertNotSame(s1, s2); assertTrue(s2.isUnderline()); - s2=s2.setUnderline(false); - assertSame(s1,s2); + s2 = s2.setUnderline(false); + assertSame(s1, s2); assertFalse(s2.isUnderline()); } public void testSetReverse() { - Style s1=getDefaultStyle(); - Style s2=s1; - assertSame(s1,s2); + Style s1 = getDefaultStyle(); + Style s2 = s1; + assertSame(s1, s2); assertFalse(s2.isReverse()); - s2=s2.setReverse(true); - assertNotSame(s1,s2); + s2 = s2.setReverse(true); + assertNotSame(s1, s2); assertTrue(s2.isReverse()); - s2=s2.setReverse(false); - assertSame(s1,s2); + s2 = s2.setReverse(false); + assertSame(s1, s2); assertFalse(s2.isReverse()); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/test/AutomatedPluginTests.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/test/AutomatedPluginTests.java index a2d7c7a2402..4e3f25d813e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/test/AutomatedPluginTests.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/terminal/test/AutomatedPluginTests.java @@ -29,7 +29,7 @@ public class AutomatedPluginTests extends TestCase { //These tests require Eclipse Platform to be up suite.addTestSuite(org.eclipse.tm.internal.terminal.connector.TerminalConnectorPluginTest.class); suite.addTestSuite(org.eclipse.tm.internal.terminal.connector.TerminalConnectorFactoryTest.class); - + //These tests must run as plain JUnit because they require access //to "package" protected methods //suite.addTest(AutomatedTests.suite()); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalContextPropertiesProviderFactory.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalContextPropertiesProviderFactory.java index 20414a4a846..524737f6c10 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalContextPropertiesProviderFactory.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalContextPropertiesProviderFactory.java @@ -63,7 +63,8 @@ public final class TerminalContextPropertiesProviderFactory { * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) */ @Override - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) + throws CoreException { Assert.isNotNull(config); this.configElement = config; @@ -71,17 +72,17 @@ public final class TerminalContextPropertiesProviderFactory { // Throws an exception if the attribute value is empty or null. clazz = config.getAttribute("class"); //$NON-NLS-1$ if (clazz == null || "".equals(clazz.trim())) { //$NON-NLS-1$ - throw new CoreException(new Status(IStatus.ERROR, - CoreBundleActivator.getUniqueIdentifier(), - NLS.bind(Messages.Extension_error_missingRequiredAttribute, "class", config.getContributor().getName()))); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + NLS.bind(Messages.Extension_error_missingRequiredAttribute, "class", //$NON-NLS-1$ + config.getContributor().getName()))); } // Read the "enablement" sub element of the extension IConfigurationElement[] children = configElement.getChildren("enablement"); //$NON-NLS-1$ if (children == null || children.length == 0) { - throw new CoreException(new Status(IStatus.ERROR, - CoreBundleActivator.getUniqueIdentifier(), - NLS.bind(Messages.Extension_error_missingRequiredAttribute, "enablement", config.getContributor().getName()))); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + NLS.bind(Messages.Extension_error_missingRequiredAttribute, "enablement", //$NON-NLS-1$ + config.getContributor().getName()))); } // Only one "enablement" element is expected expression = ExpressionConverter.getDefault().perform(children[0]); @@ -96,15 +97,16 @@ public final class TerminalContextPropertiesProviderFactory { // Create the service class instance via the configuration element Object provider = configElement.createExecutableExtension("class"); //$NON-NLS-1$ if (provider instanceof ITerminalContextPropertiesProvider) { - this.provider = (ITerminalContextPropertiesProvider)provider; - } - else { - IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Terminal context properties provider '" + provider.getClass().getName() + "' not of type ITerminalContextPropertiesProvider."); //$NON-NLS-1$ //$NON-NLS-2$ + this.provider = (ITerminalContextPropertiesProvider) provider; + } else { + IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + "Terminal context properties provider '" + provider.getClass().getName() //$NON-NLS-1$ + + "' not of type ITerminalContextPropertiesProvider."); //$NON-NLS-1$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); } - } - catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Cannot create terminal context properties provider '" + clazz + "'.", e); //$NON-NLS-1$ //$NON-NLS-2$ + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + "Cannot create terminal context properties provider '" + clazz + "'.", e); //$NON-NLS-1$ //$NON-NLS-2$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); } } @@ -138,7 +140,8 @@ public final class TerminalContextPropertiesProviderFactory { try { enabled = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE); } catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getLocalizedMessage(), e); + IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + e.getLocalizedMessage(), e); Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); } } @@ -156,7 +159,6 @@ public final class TerminalContextPropertiesProviderFactory { } } - /** * Creates a new terminal context properties provider proxy instance and initialize it. * @@ -180,7 +182,8 @@ public final class TerminalContextPropertiesProviderFactory { * Load the terminal context properties provider contributions. */ private static void loadContributions() { - IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.tm.terminal.view.core.contextPropertiesProviders"); //$NON-NLS-1$ + IExtensionPoint ep = Platform.getExtensionRegistry() + .getExtensionPoint("org.eclipse.tm.terminal.view.core.contextPropertiesProviders"); //$NON-NLS-1$ if (ep != null) { IExtension[] extensions = ep.getExtensions(); if (extensions != null) { @@ -216,7 +219,7 @@ public final class TerminalContextPropertiesProviderFactory { loadContributions(); contributionsLoaded = true; } - } + } for (Proxy proxy : contributions) { if (proxy.isEnabled(context)) { diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalServiceFactory.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalServiceFactory.java index bc26f8dc830..83e6ee59d14 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalServiceFactory.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/TerminalServiceFactory.java @@ -33,14 +33,14 @@ public final class TerminalServiceFactory { Bundle bundle = Platform.getBundle("org.eclipse.tm.terminal.view.ui"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { try { - Class clazz = bundle.loadClass("org.eclipse.tm.terminal.view.ui.services.TerminalService"); //$NON-NLS-1$ - instance = (ITerminalService) clazz.newInstance(); - } - catch (Exception e) { - if (Platform.inDebugMode()) { - Platform.getLog(bundle).log(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), Messages.TerminalServiceFactory_error_serviceImplLoadFailed, e)); - } - } + Class clazz = bundle.loadClass("org.eclipse.tm.terminal.view.ui.services.TerminalService"); //$NON-NLS-1$ + instance = (ITerminalService) clazz.newInstance(); + } catch (Exception e) { + if (Platform.inDebugMode()) { + Platform.getLog(bundle).log(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + Messages.TerminalServiceFactory_error_serviceImplLoadFailed, e)); + } + } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/interfaces/constants/ITerminalsConnectorConstants.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/interfaces/constants/ITerminalsConnectorConstants.java index 9c804202a35..ed14256fce1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/interfaces/constants/ITerminalsConnectorConstants.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/interfaces/constants/ITerminalsConnectorConstants.java @@ -14,7 +14,6 @@ package org.eclipse.tm.terminal.view.core.interfaces.constants; import org.eclipse.tm.terminal.view.core.interfaces.ITerminalServiceOutputStreamMonitorListener; - /** * Defines the terminals connector constants. * @@ -218,7 +217,7 @@ public interface ITerminalsConnectorConstants { /** * Property: Runtime process instance. - *

Typical for process terminals. + *

Typical for process terminals. *

* Property Type: {@link Process} */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/internal/PropertyTester.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/internal/PropertyTester.java index 402cd67a5ce..2294a57d074 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/internal/PropertyTester.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/internal/PropertyTester.java @@ -13,8 +13,6 @@ package org.eclipse.tm.terminal.view.core.internal; import org.eclipse.tm.terminal.view.core.TerminalContextPropertiesProviderFactory; - - /** * Property tester implementation. */ @@ -29,7 +27,8 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester // "hasContextPropertiesProvider": Checks if a context properties provider is available for the given receiver. if ("hasContextPropertiesProvider".equals(property)) { //$NON-NLS-1$ boolean hasProvider = TerminalContextPropertiesProviderFactory.getProvider(receiver) != null; - return expectedValue instanceof Boolean ? ((Boolean)expectedValue).equals(Boolean.valueOf(hasProvider)) : hasProvider; + return expectedValue instanceof Boolean ? ((Boolean) expectedValue).equals(Boolean.valueOf(hasProvider)) + : hasProvider; } return false; diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/preferences/ScopedEclipsePreferences.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/preferences/ScopedEclipsePreferences.java index 44654520423..8a604c3e4ad 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/preferences/ScopedEclipsePreferences.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/preferences/ScopedEclipsePreferences.java @@ -115,6 +115,7 @@ public class ScopedEclipsePreferences { public String[] getScopes() { return new String[] { InstanceScope.SCOPE }; } + /* (non-Javadoc) * @see org.eclipse.core.runtime.preferences.IPreferenceFilter#getMapping(java.lang.String) */ @@ -124,10 +125,10 @@ public class ScopedEclipsePreferences { } }; - Platform.getPreferencesService().exportPreferences(contextScopePrefs, new IPreferenceFilter[] { filter }, stream); + Platform.getPreferencesService().exportPreferences(contextScopePrefs, new IPreferenceFilter[] { filter }, + stream); stream.close(); - } - catch (Exception e) { + } catch (Exception e) { } } @@ -236,8 +237,7 @@ public class ScopedEclipsePreferences { if (value == null || value.equals(defValue)) { contextScopePrefs.remove(key); flushAndNotify(contextScopePrefs, key, instValue, defValue); - } - else if (!value.equals(instValue)) { + } else if (!value.equals(instValue)) { contextScopePrefs.put(key, value); flushAndNotify(contextScopePrefs, key, instValue, value); } @@ -258,8 +258,7 @@ public class ScopedEclipsePreferences { if (value == defValue) { contextScopePrefs.remove(key); flushAndNotify(contextScopePrefs, key, Boolean.toString(instValue), Boolean.toString(defValue)); - } - else if (value != instValue) { + } else if (value != instValue) { contextScopePrefs.putBoolean(key, value); flushAndNotify(contextScopePrefs, key, Boolean.toString(instValue), Boolean.toString(value)); } @@ -281,8 +280,7 @@ public class ScopedEclipsePreferences { if (value == defValue) { contextScopePrefs.remove(key); flushAndNotify(contextScopePrefs, key, Integer.toString(instValue), Integer.toString(defValue)); - } - else if (value != instValue) { + } else if (value != instValue) { contextScopePrefs.putInt(key, value); flushAndNotify(contextScopePrefs, key, Integer.toString(instValue), Integer.toString(value)); } @@ -304,8 +302,7 @@ public class ScopedEclipsePreferences { if (value == defValue) { contextScopePrefs.remove(key); flushAndNotify(contextScopePrefs, key, Long.toString(instValue), Long.toString(defValue)); - } - else if (value != instValue) { + } else if (value != instValue) { contextScopePrefs.putLong(key, value); flushAndNotify(contextScopePrefs, key, Long.toString(instValue), Long.toString(value)); } @@ -325,8 +322,7 @@ public class ScopedEclipsePreferences { if (value == null) { defaultPrefs.remove(key); flushAndNotify(defaultPrefs, key, defValue, null); - } - else if (!value.equals(defValue)) { + } else if (!value.equals(defValue)) { defaultPrefs.put(key, value); flushAndNotify(defaultPrefs, key, defValue, value); } @@ -392,7 +388,10 @@ public class ScopedEclipsePreferences { */ protected final void flushAndNotify(IEclipsePreferences node, String key, String oldValue, String newValue) { // Flush the preferences to the persistence store - try { node.flush(); } catch (BackingStoreException e) { /* Ignored on purpose */ } + try { + node.flush(); + } catch (BackingStoreException e) { + /* Ignored on purpose */ } // Notify the listeners firePreferenceEvent(node, key, oldValue, newValue); @@ -435,7 +434,8 @@ public class ScopedEclipsePreferences { Assert.isNotNull(key); // If no listener is registered, we are done here - if (listeners.isEmpty()) return; + if (listeners.isEmpty()) + return; // Get the list or currently registered listeners Object[] l = listeners.getListeners(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/tracing/TraceHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/tracing/TraceHandler.java index d14537533a5..98945b613c2 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/tracing/TraceHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/tracing/TraceHandler.java @@ -73,7 +73,8 @@ public class TraceHandler { if (mode != null && Integer.decode(mode).intValue() > 0) { return Integer.decode(mode).intValue(); } - } catch (NumberFormatException e) { /* ignored on purpose */ } + } catch (NumberFormatException e) { + /* ignored on purpose */ } return 0; } @@ -85,7 +86,8 @@ public class TraceHandler { * @return true if the slot is defined and enabled, false otherwise. */ protected boolean isSlotEnabled(String slotId) { - return fIdentifier != null ? Boolean.parseBoolean(Platform.getDebugOption(fIdentifier + "/" + slotId)) : false; //$NON-NLS-1$ + return fIdentifier != null ? Boolean.parseBoolean(Platform.getDebugOption(fIdentifier + "/" + slotId)) //$NON-NLS-1$ + : false; } /** @@ -97,9 +99,8 @@ public class TraceHandler { * @return true if the debug should be written, false otherwise. */ protected final boolean isEnabled(int debugMode, String slotId) { - return getDebugMode() < 0 || - (debugMode <= getDebugMode() && - (slotId == null || slotId.trim().length() == 0 || isSlotEnabled(slotId))); + return getDebugMode() < 0 || (debugMode <= getDebugMode() + && (slotId == null || slotId.trim().length() == 0 || isSlotEnabled(slotId))); } /** @@ -113,12 +114,15 @@ public class TraceHandler { * * @see IStatus */ - protected String getFormattedDebugMessage(String message, int debugMode, String slotId, int severity, Object clazz) { + protected String getFormattedDebugMessage(String message, int debugMode, String slotId, int severity, + Object clazz) { StringBuffer debug = new StringBuffer(); if (slotId != null || clazz != null) { if (clazz != null) { - String name = clazz instanceof Class ? ((Class)clazz).getSimpleName() : clazz.getClass().getSimpleName(); - debug.append(name.trim().length() > 0 ? name.trim() : clazz instanceof Class ? ((Class)clazz).getName() : clazz.getClass().getName()); + String name = clazz instanceof Class ? ((Class) clazz).getSimpleName() + : clazz.getClass().getSimpleName(); + debug.append(name.trim().length() > 0 ? name.trim() + : clazz instanceof Class ? ((Class) clazz).getName() : clazz.getClass().getName()); } if (slotId != null) { debug.append(" at "); //$NON-NLS-1$ @@ -152,8 +156,7 @@ public class TraceHandler { String formattedMessage = getFormattedDebugMessage(message, debugMode, slotId, severity, clazz); if (severity == IStatus.ERROR || severity == IStatus.WARNING) { System.err.println(formattedMessage); - } - else { + } else { System.out.println(formattedMessage); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/utils/Env.java b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/utils/Env.java index c44ed9b5e78..0aa8449beb6 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/utils/Env.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.core/src/org/eclipse/tm/terminal/view/core/utils/Env.java @@ -60,7 +60,8 @@ public class Env { // the cached environment Map env = new LinkedHashMap(nativeEnv); // Set the TERM environment variable if in terminal mode - if (terminal) env.put("TERM", "xterm"); //$NON-NLS-1$ //$NON-NLS-2$ + if (terminal) + env.put("TERM", "xterm"); //$NON-NLS-1$ //$NON-NLS-2$ // On Windows, the environment variable names are not case-sensitive. However, // we desire to preserve the original case. Build up a translation map between @@ -97,9 +98,10 @@ public class Env { } } // Get the variable value - String value = envpPart.substring(eqIdx+1); + String value = envpPart.substring(eqIdx + 1); // Don't overwrite the TERM variable if in terminal mode - if (terminal && "TERM".equals(name)) continue; //$NON-NLS-1$ + if (terminal && "TERM".equals(name)) //$NON-NLS-1$ + continue; // If a variable with the name does not exist, just append it if (!env.containsKey(name) && !"".equals(value)) { //$NON-NLS-1$ env.put(name, value); @@ -121,7 +123,8 @@ public class Env { // Convert into an array of strings List keys = new ArrayList(env.keySet()); // On Windows hosts, sort the environment keys - if (Platform.OS_WIN32.equals(Platform.getOS())) Collections.sort(keys); + if (Platform.OS_WIN32.equals(Platform.getOS())) + Collections.sort(keys); Iterator iter = keys.iterator(); List strings = new ArrayList(env.size()); StringBuilder buffer = null; @@ -165,7 +168,9 @@ public class Env { } else if (!Platform.getOS().equals(Constants.OS_UNKNOWN)) { nativeCommand = "env"; //$NON-NLS-1$ } - if (nativeCommand == null) { return; } + if (nativeCommand == null) { + return; + } Process process = Runtime.getRuntime().exec(nativeCommand); // read process directly on other platforms diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/plugin.properties b/terminal/plugins/org.eclipse.tm.terminal.view.ui/plugin.properties index 9241281d8b6..7bfa33a6474 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/plugin.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/plugin.properties @@ -67,7 +67,7 @@ activities.category.terminals.name=Terminal activities.category.terminals.description=Use the terminal to connect to remote hosts via telnet, ssh and others. activities.activity.terminals.views.name=Terminal Views -activities.activity.terminals.views.description=Terminal related views. +activities.activity.terminals.views.description=Terminal related views. # ----- Preference Pages ----- diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/AbstractAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/AbstractAction.java index 270c4c468af..f6446b53d13 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/AbstractAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/AbstractAction.java @@ -78,7 +78,7 @@ public abstract class AbstractAction extends AbstractTerminalAction { @Override public void run() { // Get the active tab item from the tab folder manager - TabFolderManager manager = (TabFolderManager)getParent().getAdapter(TabFolderManager.class); + TabFolderManager manager = (TabFolderManager) getParent().getAdapter(TabFolderManager.class); if (manager != null) { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); @@ -100,16 +100,18 @@ public abstract class AbstractAction extends AbstractTerminalAction { @SuppressWarnings("cast") protected void executeCommand(Object data) { // Get the command service from the workbench - ICommandService service = (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class); + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class); if (service != null && getCommandId() != null) { // Get the command final Command command = service.getCommand(getCommandId()); if (command != null && command.isDefined()) { - IHandlerService handlerSvc = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class); + IHandlerService handlerSvc = (IHandlerService) PlatformUI.getWorkbench() + .getService(IHandlerService.class); Assert.isNotNull(handlerSvc); // Construct a selection element - IStructuredSelection selection = data != null ? new StructuredSelection(data) : new StructuredSelection(); + IStructuredSelection selection = data != null ? new StructuredSelection(data) + : new StructuredSelection(); // Construct the application context EvaluationContext context = new EvaluationContext(handlerSvc.getCurrentState(), selection); // Apply the selection to the "activeMenuSelection" and "selection" variable too @@ -125,8 +127,9 @@ public abstract class AbstractAction extends AbstractTerminalAction { handlerSvc.executeCommandInContext(pCmd, null, context); } catch (Exception e) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.AbstractAction_error_commandExecutionFailed, getCommandId(), e.getLocalizedMessage()), - e); + NLS.bind(Messages.AbstractAction_error_commandExecutionFailed, getCommandId(), + e.getLocalizedMessage()), + e); UIPlugin.getDefault().getLog().log(status); } } @@ -155,7 +158,7 @@ public abstract class AbstractAction extends AbstractTerminalAction { // The action will be enabled if we can determine the VLM target object enabled = false; // Get the active tab item from the tab folder manager - TabFolderManager manager = (TabFolderManager)getParent().getAdapter(TabFolderManager.class); + TabFolderManager manager = (TabFolderManager) getParent().getAdapter(TabFolderManager.class); if (manager != null) { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/NewTerminalViewAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/NewTerminalViewAction.java index 583bfad7054..7194e3cff1e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/NewTerminalViewAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/NewTerminalViewAction.java @@ -44,9 +44,9 @@ public class NewTerminalViewAction extends AbstractTerminalAction { //this.view = view; setupAction(Messages.NewTerminalViewAction_menu, Messages.NewTerminalViewAction_tooltip, - UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Hover), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Enabled), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Disabled), true); + UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Hover), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Enabled), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_NewTerminalView_Disabled), true); setEnabled(true); } @@ -54,22 +54,24 @@ public class NewTerminalViewAction extends AbstractTerminalAction { * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#run() */ @SuppressWarnings("cast") - @Override + @Override public void run() { - ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); - Command command = service != null ? service.getCommand("org.eclipse.tm.terminal.view.ui.command.newview") : null; //$NON-NLS-1$ + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service != null ? service.getCommand("org.eclipse.tm.terminal.view.ui.command.newview") //$NON-NLS-1$ + : null; if (command != null && command.isDefined() && command.isEnabled()) { try { ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null); Assert.isNotNull(pCmd); - IHandlerService handlerSvc = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class); + IHandlerService handlerSvc = (IHandlerService) PlatformUI.getWorkbench() + .getService(IHandlerService.class); Assert.isNotNull(handlerSvc); handlerSvc.executeCommandInContext(pCmd, null, handlerSvc.getCurrentState()); } catch (Exception e) { // If the platform is in debug mode, we print the exception to the log view if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - Messages.AbstractTriggerCommandHandler_error_executionFailed, e); + Messages.AbstractTriggerCommandHandler_error_executionFailed, e); UIPlugin.getDefault().getLog().log(status); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/SelectEncodingAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/SelectEncodingAction.java index 9c416f4292b..d3e95225de4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/SelectEncodingAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/SelectEncodingAction.java @@ -42,12 +42,8 @@ public class SelectEncodingAction extends AbstractTerminalAction { Assert.isNotNull(tabFolderManager); this.tabFolderManager = tabFolderManager; - setupAction(Messages.SelectEncodingAction_menu, - Messages.SelectEncodingAction_tooltip, - (ImageDescriptor)null, - (ImageDescriptor)null, - (ImageDescriptor)null, - true); + setupAction(Messages.SelectEncodingAction_menu, Messages.SelectEncodingAction_tooltip, (ImageDescriptor) null, + (ImageDescriptor) null, (ImageDescriptor) null, true); } /* (non-Javadoc) @@ -56,7 +52,8 @@ public class SelectEncodingAction extends AbstractTerminalAction { @Override public void run() { ITerminalViewControl target = getTarget(); - if (target == null) return; + if (target == null) + return; EncodingSelectionDialog dialog = new EncodingSelectionDialog(null); dialog.setEncoding(target.getEncoding()); @@ -64,8 +61,9 @@ public class SelectEncodingAction extends AbstractTerminalAction { try { target.setEncoding(dialog.getEncoding()); tabFolderManager.updateStatusLine(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); } - catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } @@ -74,8 +72,7 @@ public class SelectEncodingAction extends AbstractTerminalAction { */ @Override public void updateAction(boolean aboutToShow) { - setEnabled(aboutToShow - && getTarget() != null && getTarget().getState() == TerminalState.CONNECTED); + setEnabled(aboutToShow && getTarget() != null && getTarget().getState() == TerminalState.CONNECTED); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/TabScrollLockAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/TabScrollLockAction.java index ada6f713b83..1f73877888f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/TabScrollLockAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/TabScrollLockAction.java @@ -30,12 +30,10 @@ public class TabScrollLockAction extends AbstractTerminalAction { public TabScrollLockAction() { super(null, TabScrollLockAction.class.getName(), IAction.AS_RADIO_BUTTON); - setupAction(Messages.TabScrollLockAction_text, - Messages.TabScrollLockAction_tooltip, - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Hover), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Enabled), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Disabled), - true); + setupAction(Messages.TabScrollLockAction_text, Messages.TabScrollLockAction_tooltip, + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Hover), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Enabled), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ScrollLock_Disabled), true); } /* (non-Javadoc) diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/ToggleCommandFieldAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/ToggleCommandFieldAction.java index a3a0073f4d7..92fafeeac5e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/ToggleCommandFieldAction.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/ToggleCommandFieldAction.java @@ -37,9 +37,9 @@ public class ToggleCommandFieldAction extends AbstractTerminalAction { this.view = view; setupAction(Messages.ToggleCommandFieldAction_menu, Messages.ToggleCommandFieldAction_toolTip, - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Hover), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Enabled), - UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Disabled), true); + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Hover), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Enabled), + UIPlugin.getImageDescriptor(ImageConsts.ACTION_ToggleCommandField_Disabled), true); TabCommandFieldHandler handler = getCommandFieldHandler(); setChecked(handler != null && handler.hasCommandInputField()); @@ -49,7 +49,7 @@ public class ToggleCommandFieldAction extends AbstractTerminalAction { * @see org.eclipse.jface.action.IAction#run() */ @Override - public void run() { + public void run() { TabCommandFieldHandler handler = getCommandFieldHandler(); if (handler != null) { handler.setCommandInputField(!handler.hasCommandInputField()); @@ -64,8 +64,7 @@ public class ToggleCommandFieldAction extends AbstractTerminalAction { public void updateAction(boolean aboutToShow) { TabCommandFieldHandler handler = getCommandFieldHandler(); ITerminalViewControl target = getTarget(); - setEnabled(aboutToShow && handler != null - && target != null && target.getState() == TerminalState.CONNECTED); + setEnabled(aboutToShow && handler != null && target != null && target.getState() == TerminalState.CONNECTED); setChecked(handler != null && handler.hasCommandInputField()); } @@ -78,7 +77,7 @@ public class ToggleCommandFieldAction extends AbstractTerminalAction { protected TabCommandFieldHandler getCommandFieldHandler() { TabCommandFieldHandler handler = null; // Get the active tab item from the tab folder manager - TabFolderManager manager = (TabFolderManager)view.getAdapter(TabFolderManager.class); + TabFolderManager manager = (TabFolderManager) view.getAdapter(TabFolderManager.class); if (manager != null) { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/activator/UIPlugin.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/activator/UIPlugin.java index 54128156f77..d399630248f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/activator/UIPlugin.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/activator/UIPlugin.java @@ -116,7 +116,8 @@ public class UIPlugin extends AbstractUIPlugin { @Override public boolean preShutdown(IWorkbench workbench, boolean forced) { - if (workbench != null && workbench.getActiveWorkbenchWindow() != null && workbench.getActiveWorkbenchWindow().getActivePage() != null) { + if (workbench != null && workbench.getActiveWorkbenchWindow() != null + && workbench.getActiveWorkbenchWindow().getActivePage() != null) { // Find all "Terminal" views IViewReference[] refs = workbench.getActiveWorkbenchWindow().getActivePage().getViewReferences(); for (IViewReference ref : refs) { @@ -135,16 +136,17 @@ public class UIPlugin extends AbstractUIPlugin { final List saveables = new ArrayList(); // Get the tab folder - CTabFolder tabFolder = (CTabFolder)((TerminalsView)part).getAdapter(CTabFolder.class); + CTabFolder tabFolder = (CTabFolder) ((TerminalsView) part).getAdapter(CTabFolder.class); if (tabFolder != null && !tabFolder.isDisposed()) { // Get the list of tab items CTabItem[] items = tabFolder.getItems(); // Loop the tab items and find the still connected ones for (CTabItem item : items) { // Ignore disposed items - if (item.isDisposed()) continue; + if (item.isDisposed()) + continue; // Get the terminal view control - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); if (terminal == null || terminal.getState() != TerminalState.CONNECTED) { continue; } @@ -154,8 +156,10 @@ public class UIPlugin extends AbstractUIPlugin { } // Push the determined saveable items to the memento handler - TerminalsViewMementoHandler mementoHandler = (TerminalsViewMementoHandler)((TerminalsView)part).getAdapter(TerminalsViewMementoHandler.class); - if (mementoHandler != null) mementoHandler.setSaveables(saveables); + TerminalsViewMementoHandler mementoHandler = (TerminalsViewMementoHandler) ((TerminalsView) part) + .getAdapter(TerminalsViewMementoHandler.class); + if (mementoHandler != null) + mementoHandler.setSaveables(saveables); } } } @@ -179,14 +183,15 @@ public class UIPlugin extends AbstractUIPlugin { void activateContexts() { if (Display.getCurrent() != null) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null && windowListener != null) windowListener.windowOpened(window); - } - else { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable(){ + if (window != null && windowListener != null) + windowListener.windowOpened(window); + } else { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { activateContexts(); - }}); + } + }); } } @@ -203,7 +208,10 @@ public class UIPlugin extends AbstractUIPlugin { plugin = null; scopedPreferences = null; traceHandler = null; - if (listener != null) { PlatformUI.getWorkbench().removeWorkbenchListener(listener); listener = null; } + if (listener != null) { + PlatformUI.getWorkbench().removeWorkbenchListener(listener); + listener = null; + } super.stop(context); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/ConfigurationPanelControl.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/ConfigurationPanelControl.java index d5941ccae69..ea5e12c5c21 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/ConfigurationPanelControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/ConfigurationPanelControl.java @@ -57,32 +57,32 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, * Constructor. * * @param container The configuration panel container or null. - */ - public EmptySettingsPanel(IConfigurationPanelContainer container) { - super(container); - } + */ + public EmptySettingsPanel(IConfigurationPanelContainer container) { + super(container); + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) - */ - @Override - public void setupPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new GridLayout()); - panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) + */ + @Override + public void setupPanel(Composite parent) { + Composite panel = new Composite(parent, SWT.NONE); + panel.setLayout(new GridLayout()); + panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - panel.setBackground(parent.getBackground()); + panel.setBackground(parent.getBackground()); - setControl(panel); - } + setControl(panel); + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() - */ - @Override - public boolean isValid() { - return false; - } + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() + */ + @Override + public boolean isValid() { + return false; + } } /** @@ -154,7 +154,8 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, if (isPanelIsGroup()) { panel = new Group(parent, SWT.NONE); - if (getGroupLabel() != null) ((Group)panel).setText(getGroupLabel()); + if (getGroupLabel() != null) + ((Group) panel).setText(getGroupLabel()); } else { panel = new Composite(parent, SWT.NONE); } @@ -216,7 +217,8 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, * @param panel The configuration panel instance or null. */ public void addConfigurationPanel(String key, IConfigurationPanel panel) { - if (key == null) return; + if (key == null) + return; if (panel != null) { configurationPanels.put(key, panel); } else { @@ -259,7 +261,8 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, } IConfigurationPanel configPanel = getActiveConfigurationPanel(); Map data = new HashMap(); - if (configPanel != null) configPanel.extractData(data); + if (configPanel != null) + configPanel.extractData(data); configPanel = getConfigurationPanel(key); Assert.isNotNull(configPanel); if (configPanel.getControl() != null) { @@ -267,10 +270,10 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, activeConfigurationPanelKey = key; panelLayout.topControl = configPanel.getControl(); panel.layout(); - if (!data.isEmpty()) configPanel.updateData(data); + if (!data.isEmpty()) + configPanel.updateData(data); configPanel.activate(); - } - else { + } else { activeConfigurationPanelKey = key; } } @@ -312,7 +315,7 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, section = settings.addNewSection(sectionName); } - return section; + return section; } /** @@ -349,7 +352,8 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, IConfigurationPanel configPanel = getConfigurationPanel(panelKey); if (configPanel != null && !isEmptyConfigurationPanel(configPanel)) { IDialogSettings configPanelSettings = settings.getSection(panelKey); - if (configPanelSettings == null) configPanelSettings = settings.addNewSection(panelKey); + if (configPanelSettings == null) + configPanelSettings = settings.addNewSection(panelKey); configPanel.doRestoreWidgetValues(configPanelSettings, idPrefix); } } @@ -388,7 +392,8 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, if (configPanel != null && !isEmptyConfigurationPanel(configPanel)) { String key = getActiveConfigurationPanelKey(); IDialogSettings configPanelSettings = settings.getSection(key); - if (configPanelSettings == null) configPanelSettings = settings.addNewSection(key); + if (configPanelSettings == null) + configPanelSettings = settings.addNewSection(key); configPanel.doSaveWidgetValues(configPanelSettings, idPrefix); } } @@ -416,7 +421,7 @@ public class ConfigurationPanelControl implements IConfigurationPanelContainer, * @param messageType The message type or IMessageProvider.NONE. */ @Override - public final void setMessage(String message, int messageType) { + public final void setMessage(String message, int messageType) { this.message = message; this.messageType = messageType; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/NoteCompositeHelper.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/NoteCompositeHelper.java index efaf2fcfa82..8c853014f5e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/NoteCompositeHelper.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/controls/NoteCompositeHelper.java @@ -91,7 +91,8 @@ public class NoteCompositeHelper { * * @return the composite for the note */ - public static Composite createNoteComposite(Font font, Composite composite, String title, String message, int minCharsPerLine) { + public static Composite createNoteComposite(Font font, Composite composite, String title, String message, + int minCharsPerLine) { final GC gc = new GC(composite); gc.setFont(font); @@ -142,7 +143,8 @@ public class NoteCompositeHelper { * needed */ layoutData = new GridData(GridData.FILL_HORIZONTAL); - layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), minCharsPerLine >= 20 ? minCharsPerLine : 65); + layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), + minCharsPerLine >= 20 ? minCharsPerLine : 65); messageLabel.setLayoutData(layoutData); gc.dispose(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/help/IContextHelpIds.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/help/IContextHelpIds.java index 4576584de18..0fb521ca456 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/help/IContextHelpIds.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/help/IContextHelpIds.java @@ -14,7 +14,6 @@ package org.eclipse.tm.terminal.view.ui.help; import org.eclipse.tm.terminal.view.ui.activator.UIPlugin; - /** * UI Context help id definitions. * diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IConfigurationPanelContainer.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IConfigurationPanelContainer.java index aa04b1246b1..c6f4e13319f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IConfigurationPanelContainer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IConfigurationPanelContainer.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.eclipse.tm.terminal.view.ui.interfaces; - - /** * A container to deal with configuration panels. * diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ILauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ILauncherDelegate.java index 7cd9990dd4d..f6d23cc366e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ILauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ILauncherDelegate.java @@ -95,5 +95,5 @@ public interface ILauncherDelegate extends IExecutableExtension, IAdaptable { * @param properties The terminal properties. Must not be null. * @return The terminal connector or null. */ - public ITerminalConnector createTerminalConnector(Map properties); + public ITerminalConnector createTerminalConnector(Map properties); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IMementoHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IMementoHandler.java index 79f15857579..c1f5e9bf26d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IMementoHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IMementoHandler.java @@ -20,19 +20,19 @@ import org.eclipse.ui.IMemento; */ public interface IMementoHandler { - /** - * Saves the terminal properties in the given memento. - * - * @param memento The memento. Must not be null. - * @param properties The map containing the terminal properties to save. Must not be null. - */ - public void saveState(IMemento memento, Map properties); + /** + * Saves the terminal properties in the given memento. + * + * @param memento The memento. Must not be null. + * @param properties The map containing the terminal properties to save. Must not be null. + */ + public void saveState(IMemento memento, Map properties); - /** - * Restore the terminal properties from the given memento. - * - * @param memento The memento. Must not be null. - * @param properties The map receiving the restored terminal properties. Must not be null. - */ - public void restoreState(IMemento memento, Map properties); + /** + * Restore the terminal properties from the given memento. + * + * @param memento The memento. Must not be null. + * @param properties The map receiving the restored terminal properties. Must not be null. + */ + public void restoreState(IMemento memento, Map properties); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IPreferenceKeys.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IPreferenceKeys.java index fa0245c9c7a..b37439f813f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IPreferenceKeys.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/IPreferenceKeys.java @@ -65,5 +65,6 @@ public interface IPreferenceKeys { * Preference key: Local terminal default shell command arguments on Unix hosts. * @since 4.1 */ - public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS = PREF_TERMINAL + ".localTerminalDefaultShellUnixArgs"; //$NON-NLS-1$ + public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS = PREF_TERMINAL + + ".localTerminalDefaultShellUnixArgs"; //$NON-NLS-1$ } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ImageConsts.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ImageConsts.java index 17d24111da2..352228af88b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ImageConsts.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/interfaces/ImageConsts.java @@ -23,82 +23,82 @@ public interface ImageConsts { * The root directory where to load the images from, relative to * the bundle directory. */ - public final static String IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$ + public final static String IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$ - /** - * The directory where to load colored local toolbar images from, - * relative to the image root directory. - */ - public final static String IMAGE_DIR_CLCL = "clcl16/"; //$NON-NLS-1$ + /** + * The directory where to load colored local toolbar images from, + * relative to the image root directory. + */ + public final static String IMAGE_DIR_CLCL = "clcl16/"; //$NON-NLS-1$ - /** - * The directory where to load disabled local toolbar images from, - * relative to the image root directory. - */ - public final static String IMAGE_DIR_DLCL = "dlcl16/"; //$NON-NLS-1$ + /** + * The directory where to load disabled local toolbar images from, + * relative to the image root directory. + */ + public final static String IMAGE_DIR_DLCL = "dlcl16/"; //$NON-NLS-1$ - /** - * The directory where to load enabled local toolbar images from, - * relative to the image root directory. - */ - public final static String IMAGE_DIR_ELCL = "elcl16/"; //$NON-NLS-1$ + /** + * The directory where to load enabled local toolbar images from, + * relative to the image root directory. + */ + public final static String IMAGE_DIR_ELCL = "elcl16/"; //$NON-NLS-1$ - /** - * The directory where to load view related images from, relative to - * the image root directory. - */ - public final static String IMAGE_DIR_EVIEW = "eview16/"; //$NON-NLS-1$ + /** + * The directory where to load view related images from, relative to + * the image root directory. + */ + public final static String IMAGE_DIR_EVIEW = "eview16/"; //$NON-NLS-1$ - /** - * The key to access the terminals console view image. - */ - public static final String VIEW_Terminals = "TerminalsView"; //$NON-NLS-1$ + /** + * The key to access the terminals console view image. + */ + public static final String VIEW_Terminals = "TerminalsView"; //$NON-NLS-1$ - /** - * The key to access the scroll lock action image (enabled). - */ - public static final String ACTION_ScrollLock_Enabled = "ScrollLockAction_enabled"; //$NON-NLS-1$ + /** + * The key to access the scroll lock action image (enabled). + */ + public static final String ACTION_ScrollLock_Enabled = "ScrollLockAction_enabled"; //$NON-NLS-1$ - /** - * The key to access the scroll lock action image (disabled). - */ - public static final String ACTION_ScrollLock_Disabled = "ScrollLockAction_disabled"; //$NON-NLS-1$ + /** + * The key to access the scroll lock action image (disabled). + */ + public static final String ACTION_ScrollLock_Disabled = "ScrollLockAction_disabled"; //$NON-NLS-1$ - /** - * The key to access the scroll lock action image (hover). - */ - public static final String ACTION_ScrollLock_Hover = "ScrollLockAction_hover"; //$NON-NLS-1$ + /** + * The key to access the scroll lock action image (hover). + */ + public static final String ACTION_ScrollLock_Hover = "ScrollLockAction_hover"; //$NON-NLS-1$ - /** - * The key to access the new terminal view action image (enabled). - * @since 4.1 - */ - public static final String ACTION_NewTerminalView_Enabled = "NewTerminalViewAction_enabled"; //$NON-NLS-1$ + /** + * The key to access the new terminal view action image (enabled). + * @since 4.1 + */ + public static final String ACTION_NewTerminalView_Enabled = "NewTerminalViewAction_enabled"; //$NON-NLS-1$ - /** - * The key to access the new terminal view action image (disabled). - * @since 4.1 - */ - public static final String ACTION_NewTerminalView_Disabled = "NewTerminalViewAction_disabled"; //$NON-NLS-1$ + /** + * The key to access the new terminal view action image (disabled). + * @since 4.1 + */ + public static final String ACTION_NewTerminalView_Disabled = "NewTerminalViewAction_disabled"; //$NON-NLS-1$ - /** - * The key to access the new terminal view action image (hover). - * @since 4.1 - */ - public static final String ACTION_NewTerminalView_Hover = "NewTerminalViewAction_hover"; //$NON-NLS-1$ + /** + * The key to access the new terminal view action image (hover). + * @since 4.1 + */ + public static final String ACTION_NewTerminalView_Hover = "NewTerminalViewAction_hover"; //$NON-NLS-1$ - /** - * The key to access the toggle command field action image (enabled). - */ - public static final String ACTION_ToggleCommandField_Enabled = "ToggleCommandField_enabled"; //$NON-NLS-1$ + /** + * The key to access the toggle command field action image (enabled). + */ + public static final String ACTION_ToggleCommandField_Enabled = "ToggleCommandField_enabled"; //$NON-NLS-1$ - /** - * The key to access the toggle command field action image (disabled). - */ - public static final String ACTION_ToggleCommandField_Disabled = "ToggleCommandField_disabled"; //$NON-NLS-1$ + /** + * The key to access the toggle command field action image (disabled). + */ + public static final String ACTION_ToggleCommandField_Disabled = "ToggleCommandField_disabled"; //$NON-NLS-1$ - /** - * The key to access the toggle command field action image (hover). - */ - public static final String ACTION_ToggleCommandField_Hover = "ToggleCommandField_hover"; //$NON-NLS-1$ + /** + * The key to access the toggle command field action image (hover). + */ + public static final String ACTION_ToggleCommandField_Hover = "ToggleCommandField_hover"; //$NON-NLS-1$ } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/ExternalExecutablesState.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/ExternalExecutablesState.java index d259cbc9c38..5c259d51cec 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/ExternalExecutablesState.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/ExternalExecutablesState.java @@ -44,11 +44,11 @@ public class ExternalExecutablesState extends AbstractSourceProvider { } public void enable() { - fireSourceChanged(ISources.WORKBENCH, CONFIGURED_STATE, "TRUE"); //$NON-NLS-1$ + fireSourceChanged(ISources.WORKBENCH, CONFIGURED_STATE, "TRUE"); //$NON-NLS-1$ } public void disable() { - fireSourceChanged(ISources.WORKBENCH, CONFIGURED_STATE, "FALSE"); //$NON-NLS-1$ + fireSourceChanged(ISources.WORKBENCH, CONFIGURED_STATE, "FALSE"); //$NON-NLS-1$ } @Override diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/PropertyTester.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/PropertyTester.java index 021a7cfd5d1..888a70d3f9a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/PropertyTester.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/PropertyTester.java @@ -20,7 +20,6 @@ import org.eclipse.tm.terminal.view.ui.interfaces.ITerminalsView; import org.eclipse.tm.terminal.view.ui.launcher.LauncherDelegateManager; import org.eclipse.tm.terminal.view.ui.tabs.TabFolderManager; - /** * Terminal property tester implementation. */ @@ -34,22 +33,25 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if ("hasApplicableLauncherDelegates".equals(property)) { //$NON-NLS-1$ - ISelection selection = receiver instanceof ISelection ? (ISelection)receiver : new StructuredSelection(receiver); - return expectedValue.equals(Boolean.valueOf(LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection).length > 0)); + ISelection selection = receiver instanceof ISelection ? (ISelection) receiver + : new StructuredSelection(receiver); + return expectedValue.equals(Boolean.valueOf( + LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection).length > 0)); } if ("canDisconnect".equals(property) && receiver instanceof ITerminalsView) { //$NON-NLS-1$ CTabItem tabItem = null; - TabFolderManager manager = (TabFolderManager) ((ITerminalsView)receiver).getAdapter(TabFolderManager.class); + TabFolderManager manager = (TabFolderManager) ((ITerminalsView) receiver) + .getAdapter(TabFolderManager.class); if (manager != null) { tabItem = manager.getActiveTabItem(); } if (tabItem != null && !tabItem.isDisposed() && tabItem.getData() instanceof ITerminalViewControl) { - ITerminalViewControl terminal = (ITerminalViewControl)tabItem.getData(); - TerminalState state = terminal.getState(); - return expectedValue.equals(Boolean.valueOf(state != TerminalState.CLOSED)); + ITerminalViewControl terminal = (ITerminalViewControl) tabItem.getData(); + TerminalState state = terminal.getState(); + return expectedValue.equals(Boolean.valueOf(state != TerminalState.CLOSED)); } return false; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/SettingsStore.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/SettingsStore.java index 719a24201a6..d2f99e5fe70 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/SettingsStore.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/SettingsStore.java @@ -64,7 +64,9 @@ public class SettingsStore implements ISettingsStore { @Override public final void put(String key, String value) { Assert.isNotNull(key); - if (value == null) settings.remove(key); - else settings.put(key, value); + if (value == null) + settings.remove(key); + else + settings.put(key, value); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/EncodingSelectionDialog.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/EncodingSelectionDialog.java index 72c4d8c414f..acc173f4e4e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/EncodingSelectionDialog.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/EncodingSelectionDialog.java @@ -48,79 +48,79 @@ public class EncodingSelectionDialog extends TrayDialog { * * @param container The configuration panel container or null. */ - public EncodingPanel(IConfigurationPanelContainer container) { - super(container); - } + public EncodingPanel(IConfigurationPanelContainer container) { + super(container); + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) - */ - @Override - public void setupPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new GridLayout()); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); - panel.setLayoutData(data); + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) + */ + @Override + public void setupPanel(Composite parent) { + Composite panel = new Composite(parent, SWT.NONE); + panel.setLayout(new GridLayout()); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + panel.setLayoutData(data); - // Create the encoding selection combo - createEncodingUI(panel, false); - if (EncodingSelectionDialog.this.encoding != null) { - setEncoding(EncodingSelectionDialog.this.encoding); - } + // Create the encoding selection combo + createEncodingUI(panel, false); + if (EncodingSelectionDialog.this.encoding != null) { + setEncoding(EncodingSelectionDialog.this.encoding); + } - setControl(panel); - } + setControl(panel); + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) */ - @Override - protected void saveSettingsForHost(boolean add) { - } + @Override + protected void saveSettingsForHost(boolean add) { + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) */ - @Override - protected void fillSettingsForHost(String host) { - } + @Override + protected void fillSettingsForHost(String host) { + } /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() */ - @Override - protected String getHostFromSettings() { - return null; - } + @Override + protected String getHostFromSettings() { + return null; + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getEncoding() - */ - @Override - public String getEncoding() { - return super.getEncoding(); - } + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getEncoding() + */ + @Override + public String getEncoding() { + return super.getEncoding(); + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setEncoding(java.lang.String) - */ - @Override - public void setEncoding(String encoding) { - super.setEncoding(encoding); - } + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setEncoding(java.lang.String) + */ + @Override + public void setEncoding(String encoding) { + super.setEncoding(encoding); + } } /** - * Constructor. - * + * Constructor. + * * @param shell The parent shell or null. - */ - public EncodingSelectionDialog(Shell shell) { - super(shell); + */ + public EncodingSelectionDialog(Shell shell) { + super(shell); this.contextHelpId = IContextHelpIds.ENCODING_SELECTION_DIALOG; setHelpAvailable(true); - } + } /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) @@ -135,11 +135,13 @@ public class EncodingSelectionDialog extends TrayDialog { Control control = super.createDialogArea(parent); // Setup the inner panel as scrollable composite if (control instanceof Composite) { - ScrolledComposite sc = new ScrolledComposite((Composite)control, SWT.V_SCROLL); + ScrolledComposite sc = new ScrolledComposite((Composite) control, SWT.V_SCROLL); GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; layout.marginWidth = 0; - layout.verticalSpacing = 0; layout.horizontalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + layout.horizontalSpacing = 0; sc.setLayout(layout); sc.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); @@ -168,22 +170,23 @@ public class EncodingSelectionDialog extends TrayDialog { * * @param parent The parent composite. Must not be null. */ - protected void createDialogAreaContent(Composite parent) { - Assert.isNotNull(parent); + protected void createDialogAreaContent(Composite parent) { + Assert.isNotNull(parent); - setDialogTitle(Messages.EncodingSelectionDialog_title); + setDialogTitle(Messages.EncodingSelectionDialog_title); - Composite panel = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; - panel.setLayout(layout); - panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); + Composite panel = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + panel.setLayout(layout); + panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); - encodingPanel = new EncodingPanel(null); - encodingPanel.setupPanel(panel); + encodingPanel = new EncodingPanel(null); + encodingPanel.setupPanel(panel); - applyDialogFont(panel); - } + applyDialogFont(panel); + } /** * Sets the title for this dialog. @@ -199,34 +202,35 @@ public class EncodingSelectionDialog extends TrayDialog { /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ - @Override - protected void okPressed() { - // Save the selected encoding - if (encodingPanel != null) encoding = encodingPanel.getEncoding(); - super.okPressed(); - } + @Override + protected void okPressed() { + // Save the selected encoding + if (encodingPanel != null) + encoding = encodingPanel.getEncoding(); + super.okPressed(); + } - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() - */ - @Override - protected void cancelPressed() { - // Reset the encoding - encoding = null; - super.cancelPressed(); - } + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() + */ + @Override + protected void cancelPressed() { + // Reset the encoding + encoding = null; + super.cancelPressed(); + } - /** - * Set the encoding to default to on creating the dialog. - */ - public final void setEncoding(String encoding) { - this.encoding = encoding; - } + /** + * Set the encoding to default to on creating the dialog. + */ + public final void setEncoding(String encoding) { + this.encoding = encoding; + } - /** - * Returns the selected encoding or null. - */ - public final String getEncoding() { - return encoding; - } + /** + * Returns the selected encoding or null. + */ + public final String getEncoding() { + return encoding; + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java index 945f6c37b59..e9b8a427da7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java @@ -122,9 +122,12 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { // Create the panel controls configPanel.setupPanel(getPanel()); // Restore widget values - IDialogSettings dialogSettings = LaunchTerminalSettingsDialog.this.settings.getDialogSettings(LaunchTerminalSettingsDialog.this.getDialogSettings()); - IDialogSettings configPanelSettings = dialogSettings != null ? dialogSettings.getSection(key) : null; - if (configPanelSettings != null) configPanel.doRestoreWidgetValues(configPanelSettings, null); + IDialogSettings dialogSettings = LaunchTerminalSettingsDialog.this.settings + .getDialogSettings(LaunchTerminalSettingsDialog.this.getDialogSettings()); + IDialogSettings configPanelSettings = dialogSettings != null ? dialogSettings.getSection(key) + : null; + if (configPanelSettings != null) + configPanel.doRestoreWidgetValues(configPanelSettings, null); } } @@ -197,7 +200,10 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { * Dispose the dialog resources. */ protected void dispose() { - if (settings != null) { settings.dispose(); settings = null; } + if (settings != null) { + settings.dispose(); + settings = null; + } dialogSettings = null; } @@ -235,11 +241,13 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { Control control = super.createDialogArea(parent); // Setup the inner panel as scrollable composite if (control instanceof Composite) { - ScrolledComposite sc = new ScrolledComposite((Composite)control, SWT.V_SCROLL); + ScrolledComposite sc = new ScrolledComposite((Composite) control, SWT.V_SCROLL); GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; layout.marginWidth = 0; - layout.verticalSpacing = 0; layout.horizontalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + layout.horizontalSpacing = 0; sc.setLayout(layout); sc.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); @@ -283,8 +291,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { Assert.isNotNull(parent); if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Creating dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Creating dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } setDialogTitle(Messages.LaunchTerminalSettingsDialog_title); @@ -293,7 +302,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { Composite panel = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; panel.setLayout(layout); panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); @@ -310,7 +320,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { IConfigurationPanel oldPanel = settings.getActiveConfigurationPanel(); // Extract the current settings in an special properties container Map data = new HashMap(); - if (oldPanel != null) oldPanel.extractData(data); + if (oldPanel != null) + oldPanel.extractData(data); // Clean out settings which are never passed between the panels data.remove(ITerminalsConnectorConstants.PROP_IP_PORT); data.remove(ITerminalsConnectorConstants.PROP_TIMEOUT); @@ -321,7 +332,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { // Get the new panel IConfigurationPanel newPanel = settings.getActiveConfigurationPanel(); // Re-setup the relevant data - if (newPanel != null) newPanel.setupData(data); + if (newPanel != null) + newPanel.setupData(data); // resize the dialog if needed to show the complete panel getShell().pack(); @@ -378,8 +390,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { applyDialogFont(panel); if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Created dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Created dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } } @@ -395,7 +408,7 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { UIPlugin.getTraceHandler().trace("Filling combo after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } Collections.sort(items); @@ -413,23 +426,27 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { ILauncherDelegate localLauncher = null; - if(selection==null || selection.isEmpty()){ + if (selection == null || selection.isEmpty()) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Getting launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Getting launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getLauncherDelegates(false); if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Got launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Got launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } for (ILauncherDelegate delegate : delegates) { - if (delegate.isHidden() || isFiltered(selection, delegate)) continue; + if (delegate.isHidden() || isFiltered(selection, delegate)) + continue; String label = delegate.getLabel(); - if (label == null || "".equals(label.trim()) || label2delegate.containsKey(label)) label = delegate.getId(); //$NON-NLS-1$ + if (label == null || "".equals(label.trim()) || label2delegate.containsKey(label)) //$NON-NLS-1$ + label = delegate.getId(); label2delegate.put(label, delegate); items.add(label); @@ -439,21 +456,26 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { } } else { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } - ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection); + ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance() + .getApplicableLauncherDelegates(selection); if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); + UIPlugin.getTraceHandler().trace( + "Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); } for (ILauncherDelegate delegate : delegates) { - if (delegate.isHidden() || isFiltered(selection, delegate)) continue; + if (delegate.isHidden() || isFiltered(selection, delegate)) + continue; String label = delegate.getLabel(); - if (label == null || "".equals(label.trim())) label = delegate.getId(); //$NON-NLS-1$ + if (label == null || "".equals(label.trim())) //$NON-NLS-1$ + label = delegate.getId(); label2delegate.put(label, delegate); items.add(label); @@ -476,14 +498,17 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { boolean translate = strTranslate != null ? Boolean.parseBoolean(strTranslate) : false; if (name != null && !"".equals(name) && path != null && !"".equals(path)) { //$NON-NLS-1$ //$NON-NLS-2$ - ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); + ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getSelectionService(); ISelection selection = service != null ? service.getSelection() : null; - if (selection != null && selection.isEmpty()) selection = null; + if (selection != null && selection.isEmpty()) + selection = null; Map properties = new HashMap(); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, path); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); - properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, Boolean.valueOf(translate)); + properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, + Boolean.valueOf(translate)); // store external executable and properties label2delegate.put(name, localLauncher); @@ -518,7 +543,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { public void validate() { IConfigurationPanel panel = this.settings.getActiveConfigurationPanel(); Button okButton = getButton(IDialogConstants.OK_ID); - if (okButton != null) okButton.setEnabled(panel.isValid()); + if (okButton != null) + okButton.setEnabled(panel.isValid()); } /** @@ -551,7 +577,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { IDialogSettings settings = getDialogSettings(); if (settings != null) { String terminalLabel = settings.get("terminalLabel"); //$NON-NLS-1$ - int index = terminalLabel != null && terminals != null ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) : -1; + int index = terminalLabel != null && terminals != null + ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) + : -1; if (index != -1) { terminals.select(index); this.settings.showConfigurationPanel(terminals.getText()); @@ -572,7 +600,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { if (!panel.isValid()) { MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK); mb.setText(Messages.LaunchTerminalSettingsDialog_error_title); - mb.setMessage(NLS.bind(Messages.LaunchTerminalSettingsDialog_error_invalidSettings, panel.getMessage() != null ? panel.getMessage() : Messages.LaunchTerminalSettingsDialog_error_unknownReason)); + mb.setMessage(NLS.bind(Messages.LaunchTerminalSettingsDialog_error_invalidSettings, + panel.getMessage() != null ? panel.getMessage() + : Messages.LaunchTerminalSettingsDialog_error_unknownReason)); mb.open(); return; } @@ -581,7 +611,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog { // Store the id of the selected delegate String terminalLabel = terminals != null ? terminals.getText() : singleDelegateLabel; String delegateId = terminalLabel != null ? label2delegate.get(terminalLabel).getId() : null; - if (delegateId != null) data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId); + if (delegateId != null) + data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId); // Store the selection data.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/AbstractTriggerCommandHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/AbstractTriggerCommandHandler.java index cbe783db89f..74d9ddead52 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/AbstractTriggerCommandHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/AbstractTriggerCommandHandler.java @@ -43,13 +43,14 @@ public abstract class AbstractTriggerCommandHandler extends AbstractHandler { protected void triggerCommand(String commandId, ISelection selection) { Assert.isNotNull(commandId); - ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = service != null ? service.getCommand(commandId) : null; if (command != null && command.isDefined() && command.isEnabled()) { try { ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null); Assert.isNotNull(pCmd); - IHandlerService handlerSvc = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class); + IHandlerService handlerSvc = (IHandlerService) PlatformUI.getWorkbench() + .getService(IHandlerService.class); Assert.isNotNull(handlerSvc); IEvaluationContext ctx = handlerSvc.getCurrentState(); if (selection != null) { @@ -61,7 +62,7 @@ public abstract class AbstractTriggerCommandHandler extends AbstractHandler { // If the platform is in debug mode, we print the exception to the log view if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - Messages.AbstractTriggerCommandHandler_error_executionFailed, e); + Messages.AbstractTriggerCommandHandler_error_executionFailed, e); UIPlugin.getDefault().getLog().log(status); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/DisconnectTerminalCommandHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/DisconnectTerminalCommandHandler.java index 30304d2baa7..457a5d05d63 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/DisconnectTerminalCommandHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/DisconnectTerminalCommandHandler.java @@ -31,28 +31,28 @@ public class DisconnectTerminalCommandHandler extends AbstractHandler { * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @SuppressWarnings("cast") - @Override + @Override public Object execute(ExecutionEvent event) throws ExecutionException { CTabItem item = null; ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { - Object element = ((IStructuredSelection)selection).getFirstElement(); - if (element instanceof CTabItem && ((CTabItem)element).getData() instanceof ITerminalViewControl) { - item = (CTabItem)element; + Object element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof CTabItem && ((CTabItem) element).getData() instanceof ITerminalViewControl) { + item = (CTabItem) element; } } if (item == null && HandlerUtil.getActivePart(event) instanceof ITerminalsView) { - ITerminalsView view = (ITerminalsView)HandlerUtil.getActivePart(event); - TabFolderManager mgr = (TabFolderManager)view.getAdapter(TabFolderManager.class); + ITerminalsView view = (ITerminalsView) HandlerUtil.getActivePart(event); + TabFolderManager mgr = (TabFolderManager) view.getAdapter(TabFolderManager.class); if (mgr != null && mgr.getActiveTabItem() != null) { item = mgr.getActiveTabItem(); } } if (item != null && item.getData() instanceof ITerminalViewControl) { - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); if (terminal != null && !terminal.isDisposed()) { terminal.disconnectTerminal(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java index 6679811c9ad..91930916de5 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java @@ -57,7 +57,7 @@ public class LaunchTerminalCommandHandler extends AbstractHandler { String date = format.format(new Date(start)); UIPlugin.getTraceHandler().trace("Started at " + date + " (" + start + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); } // Get the active shell @@ -67,65 +67,70 @@ public class LaunchTerminalCommandHandler extends AbstractHandler { if (commandId.equals("org.eclipse.tm.terminal.view.ui.command.launchToolbar")) { //$NON-NLS-1$ if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("(a) Attempt to open launch terminal settings dialog after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); + UIPlugin.getTraceHandler().trace("(a) Attempt to open launch terminal settings dialog after " //$NON-NLS-1$ + + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); } LaunchTerminalSettingsDialog dialog = new LaunchTerminalSettingsDialog(shell, start); - if(isValidSelection(selection)){ + if (isValidSelection(selection)) { dialog.setSelection(selection); } if (dialog.open() == Window.OK) { // Get the terminal settings from the dialog Map properties = dialog.getSettings(); if (properties != null) { - String delegateId = (String)properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); + String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); Assert.isNotNull(delegateId); - ILauncherDelegate delegate = LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false); + ILauncherDelegate delegate = LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, + false); Assert.isNotNull(delegateId); delegate.execute(properties, null); } } - } - else { + } else { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); + UIPlugin.getTraceHandler().trace( + "Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); } // Check if the dialog needs to be shown at all - ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection); + ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance() + .getApplicableLauncherDelegates(selection); if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); + UIPlugin.getTraceHandler().trace( + "Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); } if (delegates.length > 1 || (delegates.length == 1 && delegates[0].needsUserConfiguration())) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { - UIPlugin.getTraceHandler().trace("(b) Attempt to open launch terminal settings dialog after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ - ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); + UIPlugin.getTraceHandler().trace("(b) Attempt to open launch terminal settings dialog after " //$NON-NLS-1$ + + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ + ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this); } // Create the launch terminal settings dialog LaunchTerminalSettingsDialog dialog = new LaunchTerminalSettingsDialog(shell, start); - if(isValidSelection(selection)){ + if (isValidSelection(selection)) { dialog.setSelection(selection); } if (dialog.open() == Window.OK) { // Get the terminal settings from the dialog Map properties = dialog.getSettings(); if (properties != null) { - String delegateId = (String)properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); + String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); Assert.isNotNull(delegateId); - ILauncherDelegate delegate = LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false); + ILauncherDelegate delegate = LauncherDelegateManager.getInstance() + .getLauncherDelegate(delegateId, false); Assert.isNotNull(delegateId); delegate.execute(properties, null); } } - } - else if (delegates.length == 1) { + } else if (delegates.length == 1) { ILauncherDelegate delegate = delegates[0]; Map properties = new HashMap(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java index ac97ae5e80c..17365291f83 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java @@ -44,8 +44,10 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) */ @Override - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - if (config == null) return; + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) + throws CoreException { + if (config == null) + return; // Initialize the id field by reading the extension attribute. // Throws an exception if the id is empty or null. @@ -88,11 +90,8 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements Assert.isNotNull(attributeName); Assert.isNotNull(extensionId); - return new CoreException(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - 0, - NLS.bind(Messages.Extension_error_missingRequiredAttribute, attributeName, extensionId), - null)); + return new CoreException(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), 0, + NLS.bind(Messages.Extension_error_missingRequiredAttribute, attributeName, extensionId), null)); } /* (non-Javadoc) @@ -115,7 +114,7 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#getEnablement() */ @Override - public Expression getEnablement() { + public Expression getEnablement() { return expression; } @@ -124,7 +123,7 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements */ @Override public boolean isHidden() { - return hidden; + return hidden; } /* (non-Javadoc) @@ -133,9 +132,9 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements @Override public boolean equals(Object obj) { if (obj instanceof AbstractLauncherDelegate) { - return id.equals(((AbstractLauncherDelegate)obj).id); + return id.equals(((AbstractLauncherDelegate) obj).id); } - return super.equals(obj); + return super.equals(obj); } /* (non-Javadoc) @@ -143,7 +142,7 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements */ @Override public int hashCode() { - return id.hashCode(); + return id.hashCode(); } /** @@ -155,7 +154,7 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements * @since 4.1 */ protected String getDefaultTerminalTitle(Map properties) { - String title = (String)properties.get(ITerminalsConnectorConstants.PROP_TITLE); + String title = (String) properties.get(ITerminalsConnectorConstants.PROP_TITLE); return title != null ? title : null; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/LauncherDelegateManager.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/LauncherDelegateManager.java index 9f30fb98fe6..3bec3fc7450 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/LauncherDelegateManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/LauncherDelegateManager.java @@ -78,10 +78,9 @@ public class LauncherDelegateManager { // Extract the extension attributes id = element.getAttribute("id"); //$NON-NLS-1$ if (id == null || id.trim().length() == 0) { - throw new CoreException(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - 0, - NLS.bind(Messages.Extension_error_missingRequiredAttribute, "id", element.getContributor().getName()), //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), 0, + NLS.bind(Messages.Extension_error_missingRequiredAttribute, "id", //$NON-NLS-1$ + element.getContributor().getName()), null)); } @@ -113,7 +112,8 @@ public class LauncherDelegateManager { * @return The extension class instance or null if the instantiation fails. */ public ILauncherDelegate getInstance() { - if (instance == null) instance = newInstance(); + if (instance == null) + instance = newInstance(); return instance; } @@ -123,19 +123,21 @@ public class LauncherDelegateManager { * * @return A new extension class instance or null if the instantiation fails. */ - public ILauncherDelegate newInstance() { + public ILauncherDelegate newInstance() { IConfigurationElement element = getConfigurationElement(); Assert.isNotNull(element); // The "class" to load can be specified either as attribute or as child element if (element.getAttribute("class") != null || element.getChildren("class").length > 0) { //$NON-NLS-1$ //$NON-NLS-2$ try { - return (ILauncherDelegate)element.createExecutableExtension("class"); //$NON-NLS-1$ + return (ILauncherDelegate) element.createExecutableExtension("class"); //$NON-NLS-1$ } catch (Exception e) { // Possible exceptions: CoreException, ClassCastException. - Platform.getLog(UIPlugin.getDefault().getBundle()).log(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()), e)); + Platform.getLog(UIPlugin.getDefault().getBundle()) + .log(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + NLS.bind(Messages.Extension_error_invalidExtensionPoint, + element.getDeclaringExtension().getUniqueIdentifier()), + e)); } } return null; @@ -149,7 +151,7 @@ public class LauncherDelegateManager { // Proxies are equal if they have encapsulate an element // with the same unique id if (obj instanceof Proxy) { - return getId().equals(((Proxy)obj).getId()); + return getId().equals(((Proxy) obj).getId()); } return super.equals(obj); } @@ -183,11 +185,13 @@ public class LauncherDelegateManager { * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override - public int compare(IExtension o1, IExtension o2) { + public int compare(IExtension o1, IExtension o2) { // We ignore any comparisation with null and - if (o1 == null || o2 == null) return 0; + if (o1 == null || o2 == null) + return 0; // Check if it is the exact same element - if (o1 == o2) return 0; + if (o1 == o2) + return 0; // The extensions are compared by the unique id of the contributing plug-in first String contributor1 = o1.getContributor().getName(); @@ -300,7 +304,8 @@ public class LauncherDelegateManager { if (enablement != null) { if (selection != null) { // Set the default variable to selection. - IEvaluationContext currentState = ((IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class)).getCurrentState(); + IEvaluationContext currentState = ((IHandlerService) PlatformUI.getWorkbench() + .getService(IHandlerService.class)).getCurrentState(); EvaluationContext context = new EvaluationContext(currentState, selection); // Set the "selection" variable to the selection. context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection); @@ -310,7 +315,8 @@ public class LauncherDelegateManager { try { isApplicable = enablement.evaluate(context).equals(EvaluationResult.TRUE); } catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e); + IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + e.getLocalizedMessage(), e); UIPlugin.getDefault().getLog().log(status); } } else { @@ -321,7 +327,8 @@ public class LauncherDelegateManager { } // Add the page if applicable - if (isApplicable) applicable.add(delegate); + if (isApplicable) + applicable.add(delegate); } return applicable.toArray(new ILauncherDelegate[applicable.size()]); @@ -337,7 +344,10 @@ public class LauncherDelegateManager { protected Map getExtensions() { // Load and store the extensions thread-safe! synchronized (extensionsMap) { - if (!initialized) { loadExtensions(); initialized = true; } + if (!initialized) { + loadExtensions(); + initialized = true; + } } return extensionsMap; } @@ -379,7 +389,8 @@ public class LauncherDelegateManager { */ protected void loadExtensions() { // If already initialized, this method will do nothing. - if (initialized) return; + if (initialized) + return; IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint point = registry.getExtensionPoint("org.eclipse.tm.terminal.view.ui.launcherDelegates"); //$NON-NLS-1$ @@ -395,25 +406,25 @@ public class LauncherDelegateManager { // If no extension with this id had been registered before, register now. if (!extensionsMap.containsKey(candidate.getId())) { extensionsMap.put(candidate.getId(), candidate); - } - else { - throw new CoreException(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - 0, - NLS.bind(Messages.Extension_error_duplicateExtension, candidate.getId(), element.getContributor().getName()), - null)); + } else { + throw new CoreException( + new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), 0, + NLS.bind(Messages.Extension_error_duplicateExtension, + candidate.getId(), element.getContributor().getName()), + null)); } } else { - throw new CoreException(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - 0, - NLS.bind(Messages.Extension_error_missingRequiredAttribute, "id", element.getAttribute("label")), //$NON-NLS-1$ //$NON-NLS-2$ + throw new CoreException(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), 0, + NLS.bind(Messages.Extension_error_missingRequiredAttribute, "id", //$NON-NLS-1$ + element.getAttribute("label")), //$NON-NLS-1$ null)); } } catch (CoreException e) { - Platform.getLog(UIPlugin.getDefault().getBundle()).log(new Status(IStatus.ERROR, - UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()), e)); + Platform.getLog(UIPlugin.getDefault().getBundle()) + .log(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + NLS.bind(Messages.Extension_error_invalidExtensionPoint, + element.getDeclaringExtension().getUniqueIdentifier()), + e)); } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/AbstractWindowListener.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/AbstractWindowListener.java index df08324aba5..20eb1cb2d3d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/AbstractWindowListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/AbstractWindowListener.java @@ -32,36 +32,36 @@ public abstract class AbstractWindowListener implements IWindowListener { private boolean initialized = false; /** - * Constructor - */ - public AbstractWindowListener() { - // Create the part listener instance - partListener = createPartListener(); - // Create the perspective listener instance - perspectiveListener = createPerspectiveListener(); - } + * Constructor + */ + public AbstractWindowListener() { + // Create the part listener instance + partListener = createPartListener(); + // Create the perspective listener instance + perspectiveListener = createPerspectiveListener(); + } - /** - * Creates a new part listener instance. - *

- * Note: The default implementation returns null. - * - * @return The part listener instance or null. - */ - protected IPartListener2 createPartListener() { - return null; - } + /** + * Creates a new part listener instance. + *

+ * Note: The default implementation returns null. + * + * @return The part listener instance or null. + */ + protected IPartListener2 createPartListener() { + return null; + } - /** - * Creates a new perspective listener instance. - *

- * Note: The default implementation returns null. - * - * @return The perspective listener instance or null. - */ - protected IPerspectiveListener createPerspectiveListener() { - return null; - } + /** + * Creates a new perspective listener instance. + *

+ * Note: The default implementation returns null. + * + * @return The perspective listener instance or null. + */ + protected IPerspectiveListener createPerspectiveListener() { + return null; + } /* (non-Javadoc) * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) @@ -91,7 +91,8 @@ public abstract class AbstractWindowListener implements IWindowListener { window.getPartService().removePartListener(partListener); } - if (perspectiveListener != null) window.removePerspectiveListener(perspectiveListener); + if (perspectiveListener != null) + window.removePerspectiveListener(perspectiveListener); } } @@ -113,7 +114,8 @@ public abstract class AbstractWindowListener implements IWindowListener { IWorkbenchPage page = window.getActivePage(); if (page != null) { IWorkbenchPartReference partRef = page.getActivePartReference(); - if (partRef != null) partListener.partActivated(partRef); + if (partRef != null) + partListener.partActivated(partRef); } } @@ -122,7 +124,8 @@ public abstract class AbstractWindowListener implements IWindowListener { window.addPerspectiveListener(perspectiveListener); // Signal the active perspective to the perspective listener after registration if (window.getActivePage() != null) { - perspectiveListener.perspectiveActivated(window.getActivePage(), window.getActivePage().getPerspective()); + perspectiveListener.perspectiveActivated(window.getActivePage(), + window.getActivePage().getPerspective()); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchPartListener.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchPartListener.java index 972c13e02ed..e7b45903098 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchPartListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchPartListener.java @@ -73,7 +73,7 @@ public class WorkbenchPartListener implements IPartListener2 { if ("org.eclipse.tm.terminal.view.ui.TerminalsView".equals(partRef.getId())) { //$NON-NLS-1$ IWorkbenchPart part = partRef.getPart(false); if (part != null && part.getSite() != null) { - IContextService service = (IContextService)part.getSite().getService(IContextService.class); + IContextService service = (IContextService) part.getSite().getService(IContextService.class); if (service != null) { IContextActivation activation = service.activateContext(partRef.getId()); if (activation != null) { @@ -95,7 +95,7 @@ public class WorkbenchPartListener implements IPartListener2 { if ("org.eclipse.tm.terminal.view.ui.TerminalsView".equals(partRef.getId())) { //$NON-NLS-1$ IWorkbenchPart part = partRef.getPart(false); if (part != null && part.getSite() != null) { - IContextService service = (IContextService)part.getSite().getService(IContextService.class); + IContextService service = (IContextService) part.getSite().getService(IContextService.class); if (service != null) { IContextActivation activation = activations.remove(partRef); if (activation != null) { diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchWindowListener.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchWindowListener.java index 4334d6fc5f4..d9d953ea39e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchWindowListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/listeners/WorkbenchWindowListener.java @@ -24,6 +24,6 @@ public class WorkbenchWindowListener extends AbstractWindowListener { */ @Override protected IPartListener2 createPartListener() { - return new WorkbenchPartListener(); + return new WorkbenchPartListener(); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/DynamicContributionItems.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/DynamicContributionItems.java index 8a337fbe11d..dacfa4e4306 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/DynamicContributionItems.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/DynamicContributionItems.java @@ -51,7 +51,8 @@ public class DynamicContributionItems extends CompoundContributionItem implement this.serviceLocator = serviceLocator; // Get the local terminal launcher delegate - delegate = LauncherDelegateManager.getInstance().getLauncherDelegate("org.eclipse.tm.terminal.connector.local.launcher.local", false); //$NON-NLS-1$ + delegate = LauncherDelegateManager.getInstance() + .getLauncherDelegate("org.eclipse.tm.terminal.connector.local.launcher.local", false); //$NON-NLS-1$ } /* (non-Javadoc) @@ -79,7 +80,8 @@ public class DynamicContributionItems extends CompoundContributionItem implement ImageData id = icon != null ? ExternalExecutablesManager.loadImage(icon) : null; if (id != null) { ImageDescriptor desc = ImageDescriptor.createFromImageData(id); - if (desc != null) action.setImageDescriptor(desc); + if (desc != null) + action.setImageDescriptor(desc); } IContributionItem item = new ActionContributionItem(action); @@ -113,16 +115,20 @@ public class DynamicContributionItems extends CompoundContributionItem implement ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); ISelection selection = service != null ? service.getSelection() : null; - if (selection != null && selection.isEmpty()) selection = null; + if (selection != null && selection.isEmpty()) + selection = null; Map properties = new HashMap(); properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId()); - if (selection != null) properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); - properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, path); - if (args != null) properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); - properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, Boolean.valueOf(translate)); + if (selection != null) + properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); + properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, path); + if (args != null) + properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); + properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, + Boolean.valueOf(translate)); - delegate.execute(properties, null); + delegate.execute(properties, null); } }; diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesDialog.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesDialog.java index 61150391150..ef30e3a12db 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesDialog.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesDialog.java @@ -61,13 +61,13 @@ public class ExternalExecutablesDialog extends TrayDialog { private Map executableData; /** - * Constructor. - * + * Constructor. + * * @param shell The parent shell or null. - */ + */ public ExternalExecutablesDialog(Shell shell, boolean edit) { - super(shell); - this.edit = edit; + super(shell); + this.edit = edit; this.contextHelpId = IContextHelpIds.EXTERNAL_EXECUTABLES_DIALOG; setHelpAvailable(true); @@ -86,11 +86,13 @@ public class ExternalExecutablesDialog extends TrayDialog { Control control = super.createDialogArea(parent); // Setup the inner panel as scrollable composite if (control instanceof Composite) { - ScrolledComposite sc = new ScrolledComposite((Composite)control, SWT.V_SCROLL); + ScrolledComposite sc = new ScrolledComposite((Composite) control, SWT.V_SCROLL); GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; layout.marginWidth = 0; - layout.verticalSpacing = 0; layout.horizontalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + layout.horizontalSpacing = 0; sc.setLayout(layout); sc.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); @@ -119,203 +121,217 @@ public class ExternalExecutablesDialog extends TrayDialog { * * @param parent The parent composite. Must not be null. */ - protected void createDialogAreaContent(Composite parent) { - Assert.isNotNull(parent); + protected void createDialogAreaContent(Composite parent) { + Assert.isNotNull(parent); - setDialogTitle(edit ? Messages.ExternalExecutablesDialog_title_edit : Messages.ExternalExecutablesDialog_title_add); + setDialogTitle( + edit ? Messages.ExternalExecutablesDialog_title_edit : Messages.ExternalExecutablesDialog_title_add); - Composite panel = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; - panel.setLayout(layout); - GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, true); - layoutData.widthHint = convertWidthInCharsToPixels(50); - panel.setLayoutData(layoutData); + Composite panel = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + panel.setLayout(layout); + GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, true); + layoutData.widthHint = convertWidthInCharsToPixels(50); + panel.setLayoutData(layoutData); - Label label = new Label(panel, SWT.HORIZONTAL); - label.setText(Messages.ExternalExecutablesDialog_field_name); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - label.setLayoutData(layoutData); + Label label = new Label(panel, SWT.HORIZONTAL); + label.setText(Messages.ExternalExecutablesDialog_field_name); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + label.setLayoutData(layoutData); - name = new Text(panel, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - layoutData.widthHint = convertWidthInCharsToPixels(30); - name.setLayoutData(layoutData); - name.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - validate(); - } - }); - - label = new Label(panel, SWT.HORIZONTAL); - label.setText(Messages.ExternalExecutablesDialog_field_path); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - label.setLayoutData(layoutData); - - Composite panel2 = new Composite(panel, SWT.NONE); - layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; - panel2.setLayout(layout); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - panel2.setLayoutData(layoutData); - - path = new Text(panel2, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - layoutData.widthHint = convertWidthInCharsToPixels(30); - path.setLayoutData(layoutData); - path.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - validate(); - } - }); - - Button button = new Button(panel2, SWT.PUSH); - button.setText(Messages.ExternalExecutablesDialog_button_browse); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - layoutData.widthHint = convertWidthInCharsToPixels(10); - button.setLayoutData(layoutData); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); - - String selectedFile = path.getText(); - if (selectedFile != null && selectedFile.trim().length() > 0) { - IPath filePath = new Path(selectedFile); - // If the selected file points to an directory, use the directory as is - IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1); - while (filterPath != null && filterPath.segmentCount() > 1 && !filterPath.toFile().exists()) { - filterPath = filterPath.removeLastSegments(1); - } - String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null : filePath.lastSegment(); - - if (filterPath != null && !filterPath.isEmpty()) dialog.setFilterPath(filterPath.toString()); - if (filterFileName != null) dialog.setFileName(filterFileName); - } else { - String workspace = null; - Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); - } - - String filterPath = last_filter_path != null ? last_filter_path : workspace; - dialog.setFilterPath(filterPath); - } - - selectedFile = dialog.open(); - if (selectedFile != null) { - last_filter_path = dialog.getFilterPath(); - path.setText(selectedFile); - } - } + name = new Text(panel, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.widthHint = convertWidthInCharsToPixels(30); + name.setLayoutData(layoutData); + name.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + validate(); + } }); - label = new Label(panel, SWT.HORIZONTAL); - label.setText(Messages.ExternalExecutablesDialog_field_args); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - label.setLayoutData(layoutData); + label = new Label(panel, SWT.HORIZONTAL); + label.setText(Messages.ExternalExecutablesDialog_field_path); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + label.setLayoutData(layoutData); - args = new Text(panel, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - layoutData.widthHint = convertWidthInCharsToPixels(30); - args.setLayoutData(layoutData); - args.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - validate(); - } - }); + Composite panel2 = new Composite(panel, SWT.NONE); + layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + panel2.setLayout(layout); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + panel2.setLayoutData(layoutData); - label = new Label(panel, SWT.HORIZONTAL); - label.setText(Messages.ExternalExecutablesDialog_field_icon); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - label.setLayoutData(layoutData); - - panel2 = new Composite(panel, SWT.NONE); - layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; - panel2.setLayout(layout); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - panel2.setLayoutData(layoutData); - - icon = new Text(panel2, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); - layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); - layoutData.widthHint = convertWidthInCharsToPixels(30); - icon.setLayoutData(layoutData); - icon.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - validate(); - } - }); - - button = new Button(panel2, SWT.PUSH); - button.setText(Messages.ExternalExecutablesDialog_button_browse); - layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); - layoutData.widthHint = convertWidthInCharsToPixels(10); - button.setLayoutData(layoutData); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); - - String selectedFile = icon.getText(); - if (selectedFile != null && selectedFile.trim().length() > 0) { - IPath filePath = new Path(selectedFile); - // If the selected file points to an directory, use the directory as is - IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1); - while (filterPath != null && filterPath.segmentCount() > 1 && !filterPath.toFile().exists()) { - filterPath = filterPath.removeLastSegments(1); - } - String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null : filePath.lastSegment(); - - if (filterPath != null && !filterPath.isEmpty()) dialog.setFilterPath(filterPath.toString()); - if (filterFileName != null) dialog.setFileName(filterFileName); - } else { - String workspace = null; - Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); - } - - String filterPath = last_filter_icon != null ? last_filter_icon : workspace; - dialog.setFilterPath(filterPath); - } - - selectedFile = dialog.open(); - if (selectedFile != null) { - last_filter_icon = dialog.getFilterPath(); - icon.setText(selectedFile); - } - } + path = new Text(panel2, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.widthHint = convertWidthInCharsToPixels(30); + path.setLayoutData(layoutData); + path.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + validate(); + } }); - translate = new Button(panel, SWT.CHECK); - translate.setText(Messages.ExternalExecutablesDialog_field_translate); - layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - layoutData.horizontalSpan = 2; - translate.setLayoutData(layoutData); - translate.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - validate(); - } + Button button = new Button(panel2, SWT.PUSH); + button.setText(Messages.ExternalExecutablesDialog_button_browse); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + layoutData.widthHint = convertWidthInCharsToPixels(10); + button.setLayoutData(layoutData); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); + + String selectedFile = path.getText(); + if (selectedFile != null && selectedFile.trim().length() > 0) { + IPath filePath = new Path(selectedFile); + // If the selected file points to an directory, use the directory as is + IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1); + while (filterPath != null && filterPath.segmentCount() > 1 && !filterPath.toFile().exists()) { + filterPath = filterPath.removeLastSegments(1); + } + String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null + : filePath.lastSegment(); + + if (filterPath != null && !filterPath.isEmpty()) + dialog.setFilterPath(filterPath.toString()); + if (filterFileName != null) + dialog.setFileName(filterFileName); + } else { + String workspace = null; + Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { + workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() + .toOSString(); + } + + String filterPath = last_filter_path != null ? last_filter_path : workspace; + dialog.setFilterPath(filterPath); + } + + selectedFile = dialog.open(); + if (selectedFile != null) { + last_filter_path = dialog.getFilterPath(); + path.setText(selectedFile); + } + } }); - if (executableData != null) { - String value = executableData.get(IExternalExecutablesProperties.PROP_NAME); - name.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ - value = executableData.get(IExternalExecutablesProperties.PROP_PATH); - path.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ - value = executableData.get(IExternalExecutablesProperties.PROP_ARGS); - args.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ - value = executableData.get(IExternalExecutablesProperties.PROP_ICON); - icon.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ - value = executableData.get(IExternalExecutablesProperties.PROP_TRANSLATE); - translate.setSelection(value != null ? Boolean.parseBoolean(value) : false); - } + label = new Label(panel, SWT.HORIZONTAL); + label.setText(Messages.ExternalExecutablesDialog_field_args); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + label.setLayoutData(layoutData); + + args = new Text(panel, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.widthHint = convertWidthInCharsToPixels(30); + args.setLayoutData(layoutData); + args.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + validate(); + } + }); + + label = new Label(panel, SWT.HORIZONTAL); + label.setText(Messages.ExternalExecutablesDialog_field_icon); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + label.setLayoutData(layoutData); + + panel2 = new Composite(panel, SWT.NONE); + layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + panel2.setLayout(layout); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + panel2.setLayoutData(layoutData); + + icon = new Text(panel2, SWT.HORIZONTAL | SWT.SINGLE | SWT.BORDER); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.widthHint = convertWidthInCharsToPixels(30); + icon.setLayoutData(layoutData); + icon.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + validate(); + } + }); + + button = new Button(panel2, SWT.PUSH); + button.setText(Messages.ExternalExecutablesDialog_button_browse); + layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false); + layoutData.widthHint = convertWidthInCharsToPixels(10); + button.setLayoutData(layoutData); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); + + String selectedFile = icon.getText(); + if (selectedFile != null && selectedFile.trim().length() > 0) { + IPath filePath = new Path(selectedFile); + // If the selected file points to an directory, use the directory as is + IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1); + while (filterPath != null && filterPath.segmentCount() > 1 && !filterPath.toFile().exists()) { + filterPath = filterPath.removeLastSegments(1); + } + String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null + : filePath.lastSegment(); + + if (filterPath != null && !filterPath.isEmpty()) + dialog.setFilterPath(filterPath.toString()); + if (filterFileName != null) + dialog.setFileName(filterFileName); + } else { + String workspace = null; + Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { + workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() + .toOSString(); + } + + String filterPath = last_filter_icon != null ? last_filter_icon : workspace; + dialog.setFilterPath(filterPath); + } + + selectedFile = dialog.open(); + if (selectedFile != null) { + last_filter_icon = dialog.getFilterPath(); + icon.setText(selectedFile); + } + } + }); + + translate = new Button(panel, SWT.CHECK); + translate.setText(Messages.ExternalExecutablesDialog_field_translate); + layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + layoutData.horizontalSpan = 2; + translate.setLayoutData(layoutData); + translate.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + validate(); + } + }); + + if (executableData != null) { + String value = executableData.get(IExternalExecutablesProperties.PROP_NAME); + name.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ + value = executableData.get(IExternalExecutablesProperties.PROP_PATH); + path.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ + value = executableData.get(IExternalExecutablesProperties.PROP_ARGS); + args.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ + value = executableData.get(IExternalExecutablesProperties.PROP_ICON); + icon.setText(value != null && !"".equals(value.trim()) ? value : ""); //$NON-NLS-1$ //$NON-NLS-2$ + value = executableData.get(IExternalExecutablesProperties.PROP_TRANSLATE); + translate.setSelection(value != null ? Boolean.parseBoolean(value) : false); + } } /* (non-Javadoc) @@ -323,9 +339,9 @@ public class ExternalExecutablesDialog extends TrayDialog { */ @Override protected Control createButtonBar(Composite parent) { - Control control = super.createButtonBar(parent); - validate(); - return control; + Control control = super.createButtonBar(parent); + validate(); + return control; } /* (non-Javadoc) @@ -336,7 +352,7 @@ public class ExternalExecutablesDialog extends TrayDialog { if (IDialogConstants.OK_ID == id && !edit) { label = Messages.ExternalExecutablesDialog_button_add; } - return super.createButton(parent, id, label, defaultButton); + return super.createButton(parent, id, label, defaultButton); } /* (non-Javadoc) @@ -346,7 +362,8 @@ public class ExternalExecutablesDialog extends TrayDialog { protected void okPressed() { if (name != null && path != null) { // Extract the executable properties - if (executableData == null) executableData = new HashMap(); + if (executableData == null) + executableData = new HashMap(); String value = name.getText(); if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$ @@ -384,14 +401,14 @@ public class ExternalExecutablesDialog extends TrayDialog { } else { executableData = null; } - super.okPressed(); + super.okPressed(); } @Override protected void cancelPressed() { // If the user pressed cancel, the dialog needs to return null executableData = null; - super.cancelPressed(); + super.cancelPressed(); } /** @@ -446,7 +463,8 @@ public class ExternalExecutablesDialog extends TrayDialog { } Button okButton = getButton(IDialogConstants.OK_ID); - if (okButton != null) okButton.setEnabled(valid); + if (okButton != null) + okButton.setEnabled(valid); } /** diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesManager.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesManager.java index b973edb3215..fc16ee0cec7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/ExternalExecutablesManager.java @@ -59,20 +59,26 @@ public class ExternalExecutablesManager { try { Properties data = new Properties(); - r= new FileReader(f); + r = new FileReader(f); data.load(r); Map> c = new HashMap>(); for (String name : data.stringPropertyNames()) { - if (name == null || name.indexOf('.') == -1) continue; + if (name == null || name.indexOf('.') == -1) + continue; int ix = name.indexOf('.'); String n = name.substring(0, ix); String k = (ix + 1) < name.length() ? name.substring(ix + 1) : null; - if (n == null || k == null) continue; + if (n == null || k == null) + continue; Integer i = null; - try { i = Integer.decode(n); } catch (NumberFormatException e) { /* ignored on purpose */ } - if (i == null) continue; + try { + i = Integer.decode(n); + } catch (NumberFormatException e) { + /* ignored on purpose */ } + if (i == null) + continue; Map m = c.get(i); if (m == null) { @@ -88,14 +94,19 @@ public class ExternalExecutablesManager { Collections.sort(k); for (Integer i : k) { Map m = c.get(i); - if (m != null && !m.isEmpty()) l.add(m); + if (m != null && !m.isEmpty()) + l.add(m); } } catch (Exception e) { if (Platform.inDebugMode()) { e.printStackTrace(); } } finally { - if (r != null) try { r.close(); } catch (IOException e) { /* ignored on purpose */ } + if (r != null) + try { + r.close(); + } catch (IOException e) { + /* ignored on purpose */ } } } } @@ -155,7 +166,8 @@ public class ExternalExecutablesManager { m.put(IExternalExecutablesProperties.PROP_NAME, "Git Bash"); //$NON-NLS-1$ m.put(IExternalExecutablesProperties.PROP_PATH, gitPath); m.put(IExternalExecutablesProperties.PROP_ARGS, "--login -i"); //$NON-NLS-1$ - if (iconPath != null) m.put(IExternalExecutablesProperties.PROP_ICON, iconPath); + if (iconPath != null) + m.put(IExternalExecutablesProperties.PROP_ICON, iconPath); m.put(IExternalExecutablesProperties.PROP_TRANSLATE, Boolean.TRUE.toString()); l.add(m); @@ -197,18 +209,21 @@ public class ExternalExecutablesManager { * @param l The list of external executables or null. */ @SuppressWarnings("cast") - public static void save(List> l) { - ISourceProviderService sourceProviderService = (ISourceProviderService) PlatformUI.getWorkbench().getService(ISourceProviderService.class); - ExternalExecutablesState stateService = (ExternalExecutablesState) sourceProviderService.getSourceProvider(ExternalExecutablesState.CONFIGURED_STATE); + public static void save(List> l) { + ISourceProviderService sourceProviderService = (ISourceProviderService) PlatformUI.getWorkbench() + .getService(ISourceProviderService.class); + ExternalExecutablesState stateService = (ExternalExecutablesState) sourceProviderService + .getSourceProvider(ExternalExecutablesState.CONFIGURED_STATE); IPath stateLocation = UIPlugin.getDefault().getStateLocation(); if (stateLocation != null) { File f = stateLocation.append(".executables/data.properties").toFile(); //$NON-NLS-1$ if (f.isFile() && (l == null || l.isEmpty())) { @SuppressWarnings("unused") - boolean s = f.delete(); + boolean s = f.delete(); - if (stateService != null) stateService.disable(); + if (stateService != null) + stateService.disable(); } else { FileWriter w = null; @@ -230,7 +245,8 @@ public class ExternalExecutablesManager { w = new FileWriter(f); data.store(w, null); - if (stateService != null) stateService.enable(); + if (stateService != null) + stateService.enable(); } catch (Exception e) { if (Platform.inDebugMode()) { e.printStackTrace(); @@ -270,7 +286,7 @@ public class ExternalExecutablesManager { if (d.height == 16 && d.width == 16) { if (id == null || id.height != 16 && id.width != 16) { id = d; - } else if (d.depth < id.depth && d.depth >= 8){ + } else if (d.depth < id.depth && d.depth >= 8) { id = d; } } else { diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java index f81cb25dca0..08db70a38dc 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java @@ -69,18 +69,21 @@ public class ConsoleManager { @Override public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { // If the old references list is empty, just return - if (references.isEmpty()) return; + if (references.isEmpty()) + return; // Create a copy of the old view references list List oldReferences = new ArrayList(references); // Get the current list of view references List references = new ArrayList(Arrays.asList(page.getViewReferences())); for (IViewReference reference : oldReferences) { - if (references.contains(reference)) continue; + if (references.contains(reference)) + continue; // Previous visible terminals console view reference, make visible again try { page.showView(reference.getId(), reference.getSecondaryId(), IWorkbenchPage.VIEW_VISIBLE); - } catch (PartInitException e) { /* Failure on part instantiation is ignored */ } + } catch (PartInitException e) { + /* Failure on part instantiation is ignored */ } } } @@ -111,42 +114,42 @@ public class ConsoleManager { class ConsoleManagerPartListener implements IPartListener2 { @Override - public void partActivated(IWorkbenchPartReference partRef) { + public void partActivated(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part instanceof ITerminalsView) { - lastActiveViewId = ((ITerminalsView)part).getViewSite().getId(); - lastActiveSecondaryViewId = ((ITerminalsView)part).getViewSite().getSecondaryId(); + lastActiveViewId = ((ITerminalsView) part).getViewSite().getId(); + lastActiveSecondaryViewId = ((ITerminalsView) part).getViewSite().getSecondaryId(); //System.out.println("Terminals view activated: id = " + lastActiveViewId + ", secondary id = " + lastActiveSecondaryViewId); //$NON-NLS-1$ //$NON-NLS-2$ } - } + } @Override - public void partBroughtToTop(IWorkbenchPartReference partRef) { - } + public void partBroughtToTop(IWorkbenchPartReference partRef) { + } @Override - public void partClosed(IWorkbenchPartReference partRef) { - } + public void partClosed(IWorkbenchPartReference partRef) { + } @Override - public void partDeactivated(IWorkbenchPartReference partRef) { - } + public void partDeactivated(IWorkbenchPartReference partRef) { + } @Override - public void partOpened(IWorkbenchPartReference partRef) { - } + public void partOpened(IWorkbenchPartReference partRef) { + } @Override - public void partHidden(IWorkbenchPartReference partRef) { - } + public void partHidden(IWorkbenchPartReference partRef) { + } @Override - public void partVisible(IWorkbenchPartReference partRef) { - } + public void partVisible(IWorkbenchPartReference partRef) { + } @Override - public void partInputChanged(IWorkbenchPartReference partRef) { - } + public void partInputChanged(IWorkbenchPartReference partRef) { + } } /* @@ -172,7 +175,8 @@ public class ConsoleManager { perspectiveListener = new ConsoleManagerPerspectiveListener(); partListener = new ConsoleManagerPartListener(); - if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { + if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null + && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(perspectiveListener); IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService(); @@ -187,7 +191,8 @@ public class ConsoleManager { */ private final IWorkbenchPage getActiveWorkbenchPage() { // To lookup the console view, the workbench must be still running - if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { + if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null + && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); } return null; @@ -215,7 +220,7 @@ public class ConsoleManager { IViewPart part = getTerminalsViewWithSecondaryId(id != null ? id : IUIConstants.ID, secondaryId, true); // Check the interface if (part instanceof ITerminalsView) { - view = (ITerminalsView)part; + view = (ITerminalsView) part; } } @@ -236,9 +241,8 @@ public class ConsoleManager { for (IViewReference ref : getActiveWorkbenchPage().getViewReferences()) { if (ref.getId().equals(id)) { - if (ANY_SECONDARY_ID.equals(secondaryId) - || secondaryId == null && ref.getSecondaryId() == null - || secondaryId != null && secondaryId.equals(ref.getSecondaryId())) { + if (ANY_SECONDARY_ID.equals(secondaryId) || secondaryId == null && ref.getSecondaryId() == null + || secondaryId != null && secondaryId.equals(ref.getSecondaryId())) { return ref.getView(restore); } } @@ -259,7 +263,8 @@ public class ConsoleManager { IViewPart part = null; if (id.equals(lastActiveViewId)) { - if (secondaryId == null || ANY_SECONDARY_ID.equals(secondaryId) || secondaryId.equals(lastActiveSecondaryViewId)) { + if (secondaryId == null || ANY_SECONDARY_ID.equals(secondaryId) + || secondaryId.equals(lastActiveSecondaryViewId)) { part = getTerminalsViewWithSecondaryId(lastActiveViewId, lastActiveSecondaryViewId, false); } } @@ -296,8 +301,7 @@ public class ConsoleManager { if (scondaryIdInt > maxNumber) { maxNumber = scondaryIdInt; } - } - else { + } else { // add the one with secondaryId == null with 0 by default terminalViews.put(Integer.toString(0), ref); } @@ -337,12 +341,12 @@ public class ConsoleManager { try { // show the view IViewPart part = getActiveTerminalsView(id != null ? id : IUIConstants.ID, secondaryId); - if (part == null) part = page.showView(id != null ? id : IUIConstants.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); + if (part == null) + part = page.showView(id != null ? id : IUIConstants.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); // and force the view to the foreground page.bringToTop(part); return part; - } - catch (PartInitException e) { + } catch (PartInitException e) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e); UIPlugin.getDefault().getLog().log(status); } @@ -369,8 +373,10 @@ public class ConsoleManager { return newPart; } - if (activate) page.activate(activePart); - else page.bringToTop(activePart); + if (activate) + page.activate(activePart); + else + page.bringToTop(activePart); return activePart; } @@ -383,8 +389,8 @@ public class ConsoleManager { * @param id * @return the secondaryId argument is not null, or *, otherwise use the auto generated secondary id. */ - private String getSecondaryId(String secondaryId, String id){ - if(secondaryId==null || ANY_SECONDARY_ID.equals(secondaryId)){ + private String getSecondaryId(String secondaryId, String id) { + if (secondaryId == null || ANY_SECONDARY_ID.equals(secondaryId)) { return getNextTerminalSecondaryId(id != null ? id : IUIConstants.ID); } @@ -403,7 +409,8 @@ public class ConsoleManager { * @param data The custom terminal data node or null. * @param flags The flags controlling how the console is opened or null to use defaults. */ - public CTabItem openConsole(String id, String title, String encoding, ITerminalConnector connector, Object data, Map flags) { + public CTabItem openConsole(String id, String title, String encoding, ITerminalConnector connector, Object data, + Map flags) { return openConsole(id, ANY_SECONDARY_ID, title, encoding, connector, data, flags); } @@ -421,27 +428,33 @@ public class ConsoleManager { * @param flags The flags controlling how the console is opened or null to use defaults. */ @SuppressWarnings("cast") - public CTabItem openConsole(String id, String secondaryId, String title, String encoding, ITerminalConnector connector, Object data, Map flags) { + public CTabItem openConsole(String id, String secondaryId, String title, String encoding, + ITerminalConnector connector, Object data, Map flags) { Assert.isNotNull(title); Assert.isNotNull(connector); Assert.isNotNull(Display.findDisplay(Thread.currentThread())); // Get the flags handled by the openConsole method itself - boolean activate = flags != null && flags.containsKey("activate") ? flags.get("activate").booleanValue() : false; //$NON-NLS-1$ //$NON-NLS-2$ - boolean forceNew = flags != null && flags.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW) ? flags.get(ITerminalsConnectorConstants.PROP_FORCE_NEW).booleanValue() : false; + boolean activate = flags != null && flags.containsKey("activate") ? flags.get("activate").booleanValue() //$NON-NLS-1$//$NON-NLS-2$ + : false; + boolean forceNew = flags != null && flags.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW) + ? flags.get(ITerminalsConnectorConstants.PROP_FORCE_NEW).booleanValue() + : false; // Make the consoles view visible IViewPart part = bringToTop(id, secondaryId, activate); - if (!(part instanceof ITerminalsView)) return null; + if (!(part instanceof ITerminalsView)) + return null; // Cast to the correct type - ITerminalsView view = (ITerminalsView)part; + ITerminalsView view = (ITerminalsView) part; // Get the tab folder manager associated with the view TabFolderManager manager = (TabFolderManager) view.getAdapter(TabFolderManager.class); - if (manager == null) return null; + if (manager == null) + return null; // Lookup an existing console first - String secId = ((IViewSite)part.getSite()).getSecondaryId(); + String secId = ((IViewSite) part.getSite()).getSecondaryId(); CTabItem item = findConsole(id, secId, title, connector, data); // Switch to the tab folder page _before_ calling TabFolderManager#createItem(...). @@ -467,7 +480,8 @@ public class ConsoleManager { item = manager.createTabItem(title, encoding, connector, data, flags); } // If still null, something went wrong - if (item == null) return null; + if (item == null) + return null; // Make the item the active console manager.bringToTop(item); @@ -494,18 +508,21 @@ public class ConsoleManager { * @return The corresponding console tab item or null. */ @SuppressWarnings("cast") - public CTabItem findConsole(String id, String secondaryId, String title, ITerminalConnector connector, Object data) { + public CTabItem findConsole(String id, String secondaryId, String title, ITerminalConnector connector, + Object data) { Assert.isNotNull(title); Assert.isNotNull(connector); Assert.isNotNull(Display.findDisplay(Thread.currentThread())); // Get the console view ITerminalsView view = findConsoleView(id, secondaryId); - if (view == null) return null; + if (view == null) + return null; // Get the tab folder manager associated with the view TabFolderManager manager = (TabFolderManager) view.getAdapter(TabFolderManager.class); - if (manager == null) return null; + if (manager == null) + return null; return manager.findTabItem(title, connector, data); } @@ -530,7 +547,8 @@ public class ConsoleManager { IViewPart part = ref != null ? ref.getView(false) : null; if (part instanceof ITerminalsView) { CTabFolder tabFolder = (CTabFolder) part.getAdapter(CTabFolder.class); - if (tabFolder == null) continue; + if (tabFolder == null) + continue; CTabItem[] candidates = tabFolder.getItems(); for (CTabItem candidate : candidates) { Object data = candidate.getData(); @@ -540,7 +558,8 @@ public class ConsoleManager { } } } - if (item != null) break; + if (item != null) + break; } } @@ -560,7 +579,8 @@ public class ConsoleManager { * @return The corresponding console tab item or null. */ @SuppressWarnings("cast") - private CTabItem findConsoleForTerminalConnector(String id, String title, ITerminalConnector connector, Object data) { + private CTabItem findConsoleForTerminalConnector(String id, String title, ITerminalConnector connector, + Object data) { Assert.isNotNull(title); Assert.isNotNull(connector); @@ -629,7 +649,7 @@ public class ConsoleManager { CTabItem console = findConsoleForTerminalConnector(id, title, connector, data); // If found, disconnect the console if (console != null && !console.isDisposed()) { - ITerminalViewControl terminal = (ITerminalViewControl)console.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) console.getData(); if (terminal != null && !terminal.isDisposed()) { terminal.disconnectTerminal(); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java index c6b8889cf4c..f0f7dc2638e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java @@ -44,8 +44,9 @@ public class Messages extends NLS { if (key != null) { try { Field field = Messages.class.getDeclaredField(key); - return (String)field.get(null); - } catch (Exception e) { /* ignored on purpose */ } + return (String) field.get(null); + } catch (Exception e) { + /* ignored on purpose */ } } return null; @@ -100,10 +101,10 @@ public class Messages extends NLS { public static String LaunchTerminalSettingsDialog_combo_label; public static String LaunchTerminalSettingsDialog_group_label; - public static String TabScrollLockAction_text; - public static String TabScrollLockAction_tooltip; + public static String TabScrollLockAction_text; + public static String TabScrollLockAction_tooltip; - public static String LaunchTerminalSettingsDialog_error_title; + public static String LaunchTerminalSettingsDialog_error_title; public static String LaunchTerminalSettingsDialog_error_invalidSettings; public static String LaunchTerminalSettingsDialog_error_unknownReason; diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties index 45a8ea7bedf..1c3fa7bf79b 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties @@ -107,9 +107,9 @@ PreferencePage_workingDir_note_label=Note: PreferencePage_workingDir_note_text=The chosen initial working directory might be overwritten by the current selection of the active view. PreferencePage_workingDir_button_variables=&Variables... PreferencePage_workingDir_invalid=Selected initial working directory is not a directory or is not readable. -PreferencePage_command_label=Shell Command +PreferencePage_command_label=Shell Command PreferencePage_command_button_browse=&Browse... PreferencePage_command_invalid=Selected shell command is not a file or is not readable or executable. PreferencePage_command_note_label=Note: PreferencePage_command_note_text=Leave the shell command empty to fallback to the SHELL environment variable or if not set, to /bin/sh. -PreferencePage_command_arguments_label=Arguments: +PreferencePage_command_arguments_label=Arguments: diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractConfigurationPanel.java index 069fd3415c9..7fb05f2ac42 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractConfigurationPanel.java @@ -51,7 +51,7 @@ public abstract class AbstractConfigurationPanel implements IConfigurationPanel */ @Override public IConfigurationPanelContainer getContainer() { - return container; + return container; } /* (non-Javadoc) @@ -159,15 +159,15 @@ public abstract class AbstractConfigurationPanel implements IConfigurationPanel } /** - * @return Returns the enabled state. - */ - public boolean isEnabled() { - return enabled; - } + * @return Returns the enabled state. + */ + public boolean isEnabled() { + return enabled; + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#isValid() - */ + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#isValid() + */ @Override public boolean isValid() { setMessage(null, NONE); @@ -184,21 +184,21 @@ public abstract class AbstractConfigurationPanel implements IConfigurationPanel /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#extractData(java.util.Map) */ - @Override - public void extractData(Map data) { - } + @Override + public void extractData(Map data) { + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupData(java.util.Map) - */ - @Override - public void setupData(Map data) { - } + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupData(java.util.Map) + */ + @Override + public void setupData(Map data) { + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#updateData(java.util.Map) - */ - @Override - public void updateData(Map data) { - } + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#updateData(java.util.Map) + */ + @Override + public void updateData(Map data) { + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractExtendedConfigurationPanel.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractExtendedConfigurationPanel.java index e58140f5444..cbbd9243b55 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractExtendedConfigurationPanel.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/panels/AbstractExtendedConfigurationPanel.java @@ -116,7 +116,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element); if (provider != null) { Object encoding = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_ENCODING); - if (encoding instanceof String) return ((String) encoding).trim(); + if (encoding instanceof String) + return ((String) encoding).trim(); } } @@ -138,8 +139,7 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu if (hostString.length == 2) { HashMap attr = deSerialize(hostString[1]); hostSettingsMap.put(hostName, attr); - } - else { + } else { hostSettingsMap.put(hostName, new HashMap()); } } @@ -150,8 +150,7 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu if (host != null) { fillSettingsForHost(host); } - } - else { + } else { if (hostCombo != null) { fillHostCombo(); String lastHost = settings.get(LAST_HOST_TAG); @@ -159,12 +158,10 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu int index = hostCombo.indexOf(lastHost); if (index != -1) { hostCombo.select(index); - } - else { + } else { hostCombo.select(0); } - } - else { + } else { hostCombo.select(0); } fillSettingsForHost(hostCombo.getText()); @@ -190,7 +187,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu protected void doRestoreEncodingsWidgetValues(IDialogSettings settings, String idPrefix) { Assert.isNotNull(settings); - String encoding = settings.get(prefixDialogSettingsSlotId(ITerminalsConnectorConstants.PROP_ENCODING, idPrefix)); + String encoding = settings + .get(prefixDialogSettingsSlotId(ITerminalsConnectorConstants.PROP_ENCODING, idPrefix)); if (encoding != null && encoding.trim().length() > 0) { setEncoding(encoding); } @@ -208,7 +206,7 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu if (hostString.length() != 0) { String[] hostAttrs = hostString.split("\\:");//$NON-NLS-1$ - for (int j = 0; j < hostAttrs.length-1; j = j + 2) { + for (int j = 0; j < hostAttrs.length - 1; j = j + 2) { String key = hostAttrs[j]; String value = hostAttrs[j + 1]; attr.put(key, value); @@ -260,7 +258,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu if (isWithoutSelection()) { if (hostCombo != null) { String host = getHostFromSettings(); - if (host != null) settings.put(LAST_HOST_TAG, host); + if (host != null) + settings.put(LAST_HOST_TAG, host); } } @@ -335,16 +334,14 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu } if (hostList.size() <= 1) { hostCombo.setEnabled(false); - } - else { + } else { hostCombo.setEnabled(true); } if (deleteHostButton != null) { if (hostList.size() == 0) { deleteHostButton.setEnabled(false); - } - else { + } else { deleteHostButton.setEnabled(true); } } @@ -455,7 +452,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu Composite panel = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; panel.setLayout(layout); panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); @@ -469,25 +467,26 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu public void widgetSelected(SelectionEvent e) { if (Messages.AbstractConfigurationPanel_encoding_custom.equals(encodingCombo.getText())) { InputDialog dialog = new InputDialog(parent.getShell(), - Messages.AbstractConfigurationPanel_encoding_custom_title, - Messages.AbstractConfigurationPanel_encoding_custom_message, - null, - new IInputValidator() { - @Override - public String isValid(String newText) { - boolean valid = false; - try { - if (newText != null && !"".equals(newText)) { //$NON-NLS-1$ - valid = Charset.isSupported(newText); - } - } catch (IllegalCharsetNameException e) { /* ignored on purpose */ } + Messages.AbstractConfigurationPanel_encoding_custom_title, + Messages.AbstractConfigurationPanel_encoding_custom_message, null, new IInputValidator() { + @Override + public String isValid(String newText) { + boolean valid = false; + try { + if (newText != null && !"".equals(newText)) { //$NON-NLS-1$ + valid = Charset.isSupported(newText); + } + } catch (IllegalCharsetNameException e) { + /* ignored on purpose */ } - if (!valid) { - return newText != null && !"".equals(newText) ? Messages.AbstractConfigurationPanel_encoding_custom_error : ""; //$NON-NLS-1$ //$NON-NLS-2$ - } - return null; - } - }); + if (!valid) { + return newText != null && !"".equals(newText) //$NON-NLS-1$ + ? Messages.AbstractConfigurationPanel_encoding_custom_error + : ""; //$NON-NLS-1$ + } + return null; + } + }); if (dialog.open() == Window.OK) { String encoding = dialog.getValue(); encodingCombo.add(encoding, encodingCombo.getItemCount() - 1); @@ -496,7 +495,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu // Remember the last 5 custom encodings entered if (!encodingHistory.contains(encoding)) { - if (encodingHistory.size() == 5) encodingHistory.remove(4); + if (encodingHistory.size() == 5) + encodingHistory.remove(4); encodingHistory.add(encoding); } @@ -579,11 +579,12 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu * @return String */ @SuppressWarnings("deprecation") - private String getResourceEncoding() { + private String getResourceEncoding() { String preference = null; Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - preference = org.eclipse.core.resources.ResourcesPlugin.getPlugin().getPluginPreferences().getString(org.eclipse.core.resources.ResourcesPlugin.PREF_ENCODING); + preference = org.eclipse.core.resources.ResourcesPlugin.getPlugin().getPluginPreferences() + .getString(org.eclipse.core.resources.ResourcesPlugin.PREF_ENCODING); } return preference != null && preference.length() > 0 ? preference : null; @@ -599,7 +600,8 @@ public abstract class AbstractExtendedConfigurationPanel extends AbstractConfigu if (encodingCombo != null && !encodingCombo.isDisposed()) { int index = encodingCombo.indexOf("ISO-8859-1".equals(encoding) ? "Default (ISO-8859-1)" : encoding); //$NON-NLS-1$ //$NON-NLS-2$ - if (index != -1) encodingCombo.select(index); + if (index != -1) + encodingCombo.select(index); else { encodingCombo.add(encoding, encodingCombo.getItemCount() - 1); encodingCombo.select(encodingCombo.indexOf(encoding)); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencePage.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencePage.java index 08e56d9245d..29ce5f356ac 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencePage.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencePage.java @@ -144,7 +144,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ IPath p = new Path(text.trim()); valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute(); - if (!valid) message = Messages.PreferencePage_command_invalid; + if (!valid) + message = Messages.PreferencePage_command_invalid; } setValid(valid); @@ -159,7 +160,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage commandBrowseButton.setLayoutData(layoutData); commandBrowseButton.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); String text = command.getText(); @@ -182,14 +183,16 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage } }); - String cmd = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + String cmd = UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$ command.setText(new Path(cmd).toOSString()); } Composite argsPanel = new Composite(group, SWT.NONE); GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; layout.marginWidth = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; argsPanel.setLayout(layout); layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); layoutData.horizontalSpan = 2; @@ -201,12 +204,14 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER); arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - String args = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); + String args = UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); if (args != null && !"".equals(args)) { //$NON-NLS-1$ arguments.setText(args); } - NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, Messages.PreferencePage_command_note_text); + NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, + Messages.PreferencePage_command_note_text); } Group group = new Group(panel, SWT.NONE); @@ -217,9 +222,12 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage workingDir = new Combo(group, SWT.DROP_DOWN); Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, Messages.PreferencePage_workingDir_eclipsehome_label, Messages.PreferencePage_workingDir_eclipsews_label }); + workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, + Messages.PreferencePage_workingDir_eclipsehome_label, + Messages.PreferencePage_workingDir_eclipsews_label }); } else { - workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, Messages.PreferencePage_workingDir_eclipsehome_label }); + workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, + Messages.PreferencePage_workingDir_eclipsehome_label }); } workingDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); workingDir.select(0); @@ -231,9 +239,9 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage String text = workingDir.getText(); if (text != null && !"".equals(text.trim()) //$NON-NLS-1$ - && !Messages.PreferencePage_workingDir_userhome_label.equals(text) - && !Messages.PreferencePage_workingDir_eclipsehome_label.equals(text) - && !Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) { + && !Messages.PreferencePage_workingDir_userhome_label.equals(text) + && !Messages.PreferencePage_workingDir_eclipsehome_label.equals(text) + && !Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) { try { // Resolve possible dynamic variables IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager(); @@ -241,7 +249,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage IPath p = new Path(resolved); valid = p.toFile().canRead() && p.toFile().isDirectory(); - if (!valid) message = Messages.PreferencePage_workingDir_invalid; + if (!valid) + message = Messages.PreferencePage_workingDir_invalid; } catch (CoreException ex) { valid = false; message = ex.getLocalizedMessage(); @@ -267,7 +276,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage // HOME String home = System.getProperty("user.home"); //$NON-NLS-1$ - if (home != null && !"".equals(home)) uh = new Path(home); //$NON-NLS-1$ + if (home != null && !"".equals(home)) //$NON-NLS-1$ + uh = new Path(home); // ECLIPSE_HOME String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$ @@ -276,17 +286,19 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage URI uri = URIUtil.fromString(eclipseHomeLocation); File f = URIUtil.toFile(uri); eh = new Path(f.getAbsolutePath()); - } catch (URISyntaxException ex) { /* ignored on purpose */ } + } catch (URISyntaxException ex) { + /* ignored on purpose */ } } // ECLIPSE_WORKSPACE Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { - if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null - && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) { - ew = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation(); - } + if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null + && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() + .getLocation() != null) { + ew = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation(); + } } DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.OPEN); @@ -338,7 +350,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage variablesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - org.eclipse.debug.ui.StringVariableSelectionDialog dialog = new org.eclipse.debug.ui.StringVariableSelectionDialog(getShell()); + org.eclipse.debug.ui.StringVariableSelectionDialog dialog = new org.eclipse.debug.ui.StringVariableSelectionDialog( + getShell()); dialog.open(); String expression = dialog.getVariableExpression(); if (expression != null) { @@ -355,17 +368,21 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage } String initialCwd = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); - if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$ + if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) + || "".equals(initialCwd.trim())) { //$NON-NLS-1$ workingDir.select(0); - } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd) || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$ + } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd) + || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(1); - } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd) || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$ + } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd) + || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(2); } else { workingDir.setText(new Path(initialCwd).toOSString()); } - NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_workingDir_note_label, Messages.PreferencePage_workingDir_note_text); + NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_workingDir_note_label, + Messages.PreferencePage_workingDir_note_text); group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_executables_label); @@ -378,10 +395,10 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage table.setHeaderVisible(true); table.setLinesVisible(true); - TableColumn column = new TableColumn(table, SWT.LEFT); - column.setText(Messages.PreferencePage_executables_column_name_label); - column = new TableColumn(table, SWT.LEFT); - column.setText(Messages.PreferencePage_executables_column_path_label); + TableColumn column = new TableColumn(table, SWT.LEFT); + column.setText(Messages.PreferencePage_executables_column_name_label); + column = new TableColumn(table, SWT.LEFT); + column.setText(Messages.PreferencePage_executables_column_path_label); ColumnViewerToolTipSupport.enableFor(viewer); @@ -396,7 +413,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage Composite buttonsPanel = new Composite(group, SWT.NONE); GridLayout layout = new GridLayout(); - layout.marginHeight = 0; layout.marginWidth = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; buttonsPanel.setLayout(layout); buttonsPanel.setLayoutData(new GridData(SWT.LEAD, SWT.BEGINNING, false, false)); @@ -427,14 +445,15 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage editButton.setLayoutData(layoutData); editButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") - @Override + @Override public void widgetSelected(SelectionEvent e) { ISelection s = viewer.getSelection(); if (s instanceof IStructuredSelection && !s.isEmpty()) { - Object element = ((IStructuredSelection)s).getFirstElement(); + Object element = ((IStructuredSelection) s).getFirstElement(); if (element instanceof Map) { - final Map m = (Map)element; - ExternalExecutablesDialog dialog = new ExternalExecutablesDialog(PreferencePage.this.getShell(), true); + final Map m = (Map) element; + ExternalExecutablesDialog dialog = new ExternalExecutablesDialog(PreferencePage.this.getShell(), + true); dialog.setExecutableData(m); if (dialog.open() == Window.OK) { Map executableData = dialog.getExecutableData(); @@ -456,15 +475,15 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage removeButton.setLayoutData(layoutData); removeButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") - @Override + @Override public void widgetSelected(SelectionEvent e) { ISelection s = viewer.getSelection(); if (s instanceof IStructuredSelection && !s.isEmpty()) { - Iterator iterator = ((IStructuredSelection)s).iterator(); + Iterator iterator = ((IStructuredSelection) s).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof Map) { - Map m = (Map)element; + Map m = (Map) element; executables.remove(m); } viewer.refresh(); @@ -476,8 +495,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage viewer.setContentProvider(new IStructuredContentProvider() { @Override public Object[] getElements(Object inputElement) { - if (inputElement instanceof List && !((List)inputElement).isEmpty()) { - return ((List)inputElement).toArray(); + if (inputElement instanceof List && !((List) inputElement).isEmpty()) { + return ((List) inputElement).toArray(); } return NO_ELEMENTS; } @@ -496,27 +515,27 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage @Override public String getColumnText(Object element, int columnIndex) { if (element instanceof Map) { - Map m = (Map)element; + Map m = (Map) element; - switch (columnIndex) { - case 0: - return (String)m.get(IExternalExecutablesProperties.PROP_NAME); - case 1: - return (String)m.get(IExternalExecutablesProperties.PROP_PATH); - } + switch (columnIndex) { + case 0: + return (String) m.get(IExternalExecutablesProperties.PROP_NAME); + case 1: + return (String) m.get(IExternalExecutablesProperties.PROP_PATH); + } } return null; } @SuppressWarnings("unchecked") - @Override + @Override public Image getColumnImage(Object element, int columnIndex) { Image i = null; if (element instanceof Map) { switch (columnIndex) { case 0: - Map m = (Map)element; + Map m = (Map) element; String icon = (String) m.get(IExternalExecutablesProperties.PROP_ICON); if (icon != null) { i = images.get(icon); @@ -524,8 +543,10 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage ImageData id = ExternalExecutablesManager.loadImage(icon); if (id != null) { ImageDescriptor d = ImageDescriptor.createFromImageData(id); - if (d != null) i = d.createImage(); - if (i != null) images.put(icon, i); + if (d != null) + i = d.createImage(); + if (i != null) + images.put(icon, i); } } } @@ -557,7 +578,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage }); List> l = ExternalExecutablesManager.load(); - if (l != null) executables.addAll(l); + if (l != null) + executables.addAll(l); viewer.setInput(executables); @@ -585,7 +607,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage ISelection selection = viewer.getSelection(); boolean hasSelection = selection != null && !selection.isEmpty(); - int count = selection instanceof IStructuredSelection ? ((IStructuredSelection)selection).size() : 0; + int count = selection instanceof IStructuredSelection ? ((IStructuredSelection) selection).size() : 0; editButton.setEnabled(hasSelection && count == 1); removeButton.setEnabled(hasSelection && count > 0); @@ -606,12 +628,16 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage arguments.setText(""); //$NON-NLS-1$ } - String initialCwd = UIPlugin.getScopedPreferences().getDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); - if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$ + String initialCwd = UIPlugin.getScopedPreferences() + .getDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); + if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) + || "".equals(initialCwd.trim())) { //$NON-NLS-1$ workingDir.select(0); - } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd) || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$ + } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd) + || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(1); - } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd) || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$ + } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd) + || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(2); } else { workingDir.setText(new Path(initialCwd).toOSString()); @@ -619,10 +645,11 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage executables.clear(); List> l = ExternalExecutablesManager.load(); - if (l != null) executables.addAll(l); + if (l != null) + executables.addAll(l); viewer.refresh(); - super.performDefaults(); + super.performDefaults(); } /* (non-Javadoc) @@ -633,19 +660,23 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage if (!Platform.OS_WIN32.equals(Platform.getOS())) { String text = command.getText(); IPath p = new Path(text.trim()); - UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute() ? p.toOSString() : null); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, + p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute() ? p.toOSString() : null); text = arguments.getText(); - UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, !"".equals(text.trim()) ? text.trim() : null); //$NON-NLS-1$ + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, + !"".equals(text.trim()) ? text.trim() : null); //$NON-NLS-1$ } String text = workingDir.getText(); if (text == null || Messages.PreferencePage_workingDir_userhome_label.equals(text) || "".equals(text.trim())) { //$NON-NLS-1$ UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, null); } else if (Messages.PreferencePage_workingDir_eclipsehome_label.equals(text)) { - UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, + IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME); } else if (Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) { - UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, + IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS); } else { try { // Resolve possible dynamic variables @@ -653,7 +684,8 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage String resolved = vm.performStringSubstitution(text.trim()); IPath p = new Path(resolved); - UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, p.toFile().canRead() && p.toFile().isDirectory() ? text.trim() : null); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, + p.toFile().canRead() && p.toFile().isDirectory() ? text.trim() : null); } catch (CoreException e) { if (Platform.inDebugMode()) { UIPlugin.getDefault().getLog().log(e.getStatus()); @@ -663,7 +695,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage ExternalExecutablesManager.save(executables); - return super.performOk(); + return super.performOk(); } /* (non-Javadoc) @@ -675,6 +707,6 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage i.dispose(); } images.clear(); - super.dispose(); + super.dispose(); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencesInitializer.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencesInitializer.java index 3ebd30c698d..6b347314f90 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencesInitializer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/preferences/PreferencesInitializer.java @@ -37,7 +37,8 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer { prefs.putDefaultBoolean(IPreferenceKeys.PREF_REMOVE_TERMINATED_TERMINALS, true); - prefs.putDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME); + prefs.putDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, + IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME); prefs.putDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, null); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/services/TerminalService.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/services/TerminalService.java index fcb6aa1c914..43369a4e309 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/services/TerminalService.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/services/TerminalService.java @@ -69,7 +69,8 @@ public class TerminalService implements ITerminalService { * @param data The custom terminal data node or null. * @param done The callback to invoke if the operation finished or null. */ - public abstract void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, Done done); + public abstract void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, + Done done); /** * Returns if or if not to execute the runnable asynchronously. @@ -79,32 +80,34 @@ public class TerminalService implements ITerminalService { * * @return True to execute the runnable asynchronously, false otherwise. */ - public boolean isExecuteAsync() { return true; } + public boolean isExecuteAsync() { + return true; + } } /** - * Constructor - */ - public TerminalService() { - } + * Constructor + */ + public TerminalService() { + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#addTerminalTabListener(org.eclipse.tm.terminal.view.core.interfaces.ITerminalTabListener) - */ - @Override - public final void addTerminalTabListener(ITerminalTabListener listener) { + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#addTerminalTabListener(org.eclipse.tm.terminal.view.core.interfaces.ITerminalTabListener) + */ + @Override + public final void addTerminalTabListener(ITerminalTabListener listener) { Assert.isNotNull(listener); terminalTabListeners.add(listener); - } + } - /* (non-Javadoc) - * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#removeTerminalTabListener(org.eclipse.tm.terminal.view.core.interfaces.ITerminalTabListener) - */ - @Override - public final void removeTerminalTabListener(ITerminalTabListener listener) { + /* (non-Javadoc) + * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#removeTerminalTabListener(org.eclipse.tm.terminal.view.core.interfaces.ITerminalTabListener) + */ + @Override + public final void removeTerminalTabListener(ITerminalTabListener listener) { Assert.isNotNull(listener); terminalTabListeners.remove(listener); - } + } /** * Convenience method for notifying the registered terminal tab listeners. @@ -117,7 +120,8 @@ public class TerminalService implements ITerminalService { Assert.isNotNull(source); // If no listener is registered, we are done here - if (terminalTabListeners.isEmpty()) return; + if (terminalTabListeners.isEmpty()) + return; // Get the list or currently registered listeners // Loop the registered terminal tab listeners and invoke the proper method @@ -150,14 +154,15 @@ public class TerminalService implements ITerminalService { * @param runnable The terminal service runnable. Must not be null. * @param done The callback to invoke if the operation has been finished or null. */ - protected final void executeServiceOperation(final Map properties, final TerminalServiceRunnable runnable, final Done done) { + protected final void executeServiceOperation(final Map properties, + final TerminalServiceRunnable runnable, final Done done) { Assert.isNotNull(properties); Assert.isNotNull(runnable); // Extract the properties - String id = (String)properties.get(ITerminalsConnectorConstants.PROP_ID); - String secondaryId = (String)properties.get(ITerminalsConnectorConstants.PROP_SECONDARY_ID); - String title = (String)properties.get(ITerminalsConnectorConstants.PROP_TITLE); + String id = (String) properties.get(ITerminalsConnectorConstants.PROP_ID); + String secondaryId = (String) properties.get(ITerminalsConnectorConstants.PROP_SECONDARY_ID); + String title = (String) properties.get(ITerminalsConnectorConstants.PROP_TITLE); Object data = properties.get(ITerminalsConnectorConstants.PROP_DATA); // Normalize the terminals console view id @@ -171,7 +176,8 @@ public class TerminalService implements ITerminalService { // Properties contain invalid connector arguments if (done != null) { Exception e = new IllegalArgumentException(Messages.TerminalService_error_cannotCreateConnector); - done.done(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getLocalizedMessage(), e)); + done.done(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getLocalizedMessage(), + e)); } return; } @@ -185,20 +191,18 @@ public class TerminalService implements ITerminalService { // Execute the operation if (!runnable.isExecuteAsync()) { runnable.run(finId, finSecondaryId, finTitle, connector, finData, done); - } - else { - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { + } else { + try { + Display display = PlatformUI.getWorkbench().getDisplay(); + display.asyncExec(new Runnable() { @Override - public void run() { + public void run() { runnable.run(finId, finSecondaryId, finTitle, connector, finData, done); } }); - } - catch (Exception e) { - // if display is disposed, silently ignore. - } + } catch (Exception e) { + // if display is disposed, silently ignore. + } } } @@ -224,7 +228,8 @@ public class TerminalService implements ITerminalService { */ protected String normalizeTitle(String title, Object data) { // If the title is explicitly specified, return as is - if (title != null) return title; + if (title != null) + return title; // Return the default console title in all other cases return Messages.TerminalService_defaultTitle; @@ -243,7 +248,7 @@ public class TerminalService implements ITerminalService { ITerminalConnector connector = null; // Get the launcher delegate id from the properties - String delegateId = (String)properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); + String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); if (delegateId != null) { // Get the launcher delegate ILauncherDelegate delegate = LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false); @@ -260,7 +265,7 @@ public class TerminalService implements ITerminalService { * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#openConsole(java.util.Map, org.eclipse.tm.terminal.view.core.interfaces.ITerminalService.Done) */ @Override - public void openConsole(final Map properties, final Done done) { + public void openConsole(final Map properties, final Done done) { Assert.isNotNull(properties); final boolean restoringView = fRestoringView; @@ -268,7 +273,7 @@ public class TerminalService implements ITerminalService { @Override @SuppressWarnings("synthetic-access") public void run(final String id, final String secondaryId, final String title, - final ITerminalConnector connector, final Object data, final Done done) { + final ITerminalConnector connector, final Object data, final Done done) { if (restoringView) { doRun(id, secondaryId, title, connector, data, done); } else { @@ -278,45 +283,50 @@ public class TerminalService implements ITerminalService { fRestoringView = false; // After that schedule opening the requested console - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { + try { + Display display = PlatformUI.getWorkbench().getDisplay(); + display.asyncExec(new Runnable() { @Override public void run() { doRun(id, secondaryId, title, connector, data, done); } }); - } - catch (Exception e) { - // if display is disposed, silently ignore. - } + } catch (Exception e) { + // if display is disposed, silently ignore. + } } } - public void doRun(String id, String secondaryId, String title, ITerminalConnector connector, Object data, Done done) { + public void doRun(String id, String secondaryId, String title, ITerminalConnector connector, Object data, + Done done) { // Determine the terminal encoding - String encoding = (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING); + String encoding = (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING); // Create the flags to pass on to openConsole Map flags = new HashMap(); flags.put("activate", Boolean.TRUE); //$NON-NLS-1$ if (properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW) instanceof Boolean) { - flags.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, (Boolean)properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW)); + flags.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, + (Boolean) properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW)); } if (properties.get(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT) instanceof Boolean) { - flags.put(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT, (Boolean)properties.get(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT)); + flags.put(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT, + (Boolean) properties.get(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT)); } // Open the new console CTabItem item; if (secondaryId != null) - item = ConsoleManager.getInstance().openConsole(id, secondaryId, title, encoding, connector, data, flags); + item = ConsoleManager.getInstance().openConsole(id, secondaryId, title, encoding, connector, data, + flags); else item = ConsoleManager.getInstance().openConsole(id, title, encoding, connector, data, flags); // Associate the original terminal properties with the tab item. // This makes it easier to persist the connection data within the memento handler - if (item != null && !item.isDisposed()) item.setData("properties", properties); //$NON-NLS-1$ + if (item != null && !item.isDisposed()) + item.setData("properties", properties); //$NON-NLS-1$ // Invoke the callback - if (done != null) done.done(Status.OK_STATUS); + if (done != null) + done.done(Status.OK_STATUS); } }, done); } @@ -325,16 +335,18 @@ public class TerminalService implements ITerminalService { * @see org.eclipse.tm.terminal.view.core.interfaces.ITerminalService#closeConsole(java.util.Map, org.eclipse.tm.terminal.view.core.interfaces.ITerminalService.Done) */ @Override - public void closeConsole(final Map properties, final Done done) { + public void closeConsole(final Map properties, final Done done) { Assert.isNotNull(properties); executeServiceOperation(properties, new TerminalServiceRunnable() { @Override - public void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, Done done) { + public void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, + Done done) { // Close the console ConsoleManager.getInstance().closeConsole(id, title, connector, data); // Invoke the callback - if (done != null) done.done(Status.OK_STATUS); + if (done != null) + done.done(Status.OK_STATUS); } }, done); } @@ -348,11 +360,13 @@ public class TerminalService implements ITerminalService { executeServiceOperation(properties, new TerminalServiceRunnable() { @Override - public void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, Done done) { + public void run(String id, String secondaryId, String title, ITerminalConnector connector, Object data, + Done done) { // Close the console ConsoleManager.getInstance().terminateConsole(id, title, connector, data); // Invoke the callback - if (done != null) done.done(Status.OK_STATUS); + if (done != null) + done.done(Status.OK_STATUS); } }, done); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/AbstractStreamsConnector.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/AbstractStreamsConnector.java index 38cf5500dd1..a51b39e7665 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/AbstractStreamsConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/AbstractStreamsConnector.java @@ -25,148 +25,164 @@ import org.eclipse.ui.services.IDisposable; */ public abstract class AbstractStreamsConnector extends TerminalConnectorImpl { // Reference to the stdin monitor - private InputStreamMonitor stdInMonitor; - // Reference to the stdout monitor - private OutputStreamMonitor stdOutMonitor; - // Reference to the stderr monitor - private OutputStreamMonitor stdErrMonitor; + private InputStreamMonitor stdInMonitor; + // Reference to the stdout monitor + private OutputStreamMonitor stdOutMonitor; + // Reference to the stderr monitor + private OutputStreamMonitor stdErrMonitor; - // Reference to the list of stdout output listeners - private ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = null; - // Reference to the list of stderr output listeners - private ITerminalServiceOutputStreamMonitorListener[] stderrListeners = null; + // Reference to the list of stdout output listeners + private ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = null; + // Reference to the list of stderr output listeners + private ITerminalServiceOutputStreamMonitorListener[] stderrListeners = null; - /** - * Set the list of stdout listeners. - * - * @param listeners The list of stdout listeners or null. - */ - protected final void setStdoutListeners(ITerminalServiceOutputStreamMonitorListener[] listeners) { - this.stdoutListeners = listeners; - } + /** + * Set the list of stdout listeners. + * + * @param listeners The list of stdout listeners or null. + */ + protected final void setStdoutListeners(ITerminalServiceOutputStreamMonitorListener[] listeners) { + this.stdoutListeners = listeners; + } - /** - * Set the list of stderr listeners. - * - * @param listeners The list of stderr listeners or null. - */ - protected final void setStderrListeners(ITerminalServiceOutputStreamMonitorListener[] listeners) { - this.stderrListeners = listeners; - } + /** + * Set the list of stderr listeners. + * + * @param listeners The list of stderr listeners or null. + */ + protected final void setStderrListeners(ITerminalServiceOutputStreamMonitorListener[] listeners) { + this.stderrListeners = listeners; + } - /** - * Connect the given streams. The streams connector will wrap each stream - * with a corresponding terminal stream monitor. - * - * @param terminalControl The terminal control. Must not be null. - * @param stdin The stdin stream or null. - * @param stdout The stdout stream or null. - * @param stderr The stderr stream or null. + /** + * Connect the given streams. The streams connector will wrap each stream + * with a corresponding terminal stream monitor. + * + * @param terminalControl The terminal control. Must not be null. + * @param stdin The stdin stream or null. + * @param stdout The stdout stream or null. + * @param stderr The stderr stream or null. * @param localEcho Local echo on or off. * @param lineSeparator The line separator used by the stream. - */ - protected void connectStreams(ITerminalControl terminalControl, OutputStream stdin, InputStream stdout, InputStream stderr, boolean localEcho, String lineSeparator) { - Assert.isNotNull(terminalControl); + */ + protected void connectStreams(ITerminalControl terminalControl, OutputStream stdin, InputStream stdout, + InputStream stderr, boolean localEcho, String lineSeparator) { + Assert.isNotNull(terminalControl); - // Create the input stream monitor - if (stdin != null) { - stdInMonitor = createStdInMonitor(terminalControl, stdin, localEcho, lineSeparator); - // Register the connector if it implements IDisposable and stdout/stderr are not monitored - if (stdout == null && stderr == null && this instanceof IDisposable) stdInMonitor.addDisposable((IDisposable)this); - // Start the monitoring - stdInMonitor.startMonitoring(); - } + // Create the input stream monitor + if (stdin != null) { + stdInMonitor = createStdInMonitor(terminalControl, stdin, localEcho, lineSeparator); + // Register the connector if it implements IDisposable and stdout/stderr are not monitored + if (stdout == null && stderr == null && this instanceof IDisposable) + stdInMonitor.addDisposable((IDisposable) this); + // Start the monitoring + stdInMonitor.startMonitoring(); + } - // Create the output stream monitor - if (stdout != null) { - stdOutMonitor = createStdOutMonitor(terminalControl, stdout, lineSeparator); - // Register the connector if it implements IDisposable - if (this instanceof IDisposable) stdOutMonitor.addDisposable((IDisposable)this); - // Register the listeners - if (stdoutListeners != null) { - for (ITerminalServiceOutputStreamMonitorListener l : stdoutListeners) { - stdOutMonitor.addListener(l); - } - } - // Start the monitoring - stdOutMonitor.startMonitoring(); - } + // Create the output stream monitor + if (stdout != null) { + stdOutMonitor = createStdOutMonitor(terminalControl, stdout, lineSeparator); + // Register the connector if it implements IDisposable + if (this instanceof IDisposable) + stdOutMonitor.addDisposable((IDisposable) this); + // Register the listeners + if (stdoutListeners != null) { + for (ITerminalServiceOutputStreamMonitorListener l : stdoutListeners) { + stdOutMonitor.addListener(l); + } + } + // Start the monitoring + stdOutMonitor.startMonitoring(); + } - // Create the error stream monitor - if (stderr != null) { - stdErrMonitor = createStdErrMonitor(terminalControl, stderr, lineSeparator); - // Register the connector if it implements IDisposable and stdout is not monitored - if (stdout == null && this instanceof IDisposable) stdErrMonitor.addDisposable((IDisposable)this); - // Register the listeners - if (stderrListeners != null) { - for (ITerminalServiceOutputStreamMonitorListener l : stderrListeners) { - stdErrMonitor.addListener(l); - } - } - // Start the monitoring - stdErrMonitor.startMonitoring(); - } - } + // Create the error stream monitor + if (stderr != null) { + stdErrMonitor = createStdErrMonitor(terminalControl, stderr, lineSeparator); + // Register the connector if it implements IDisposable and stdout is not monitored + if (stdout == null && this instanceof IDisposable) + stdErrMonitor.addDisposable((IDisposable) this); + // Register the listeners + if (stderrListeners != null) { + for (ITerminalServiceOutputStreamMonitorListener l : stderrListeners) { + stdErrMonitor.addListener(l); + } + } + // Start the monitoring + stdErrMonitor.startMonitoring(); + } + } - /** - * Creates an stdin monitor for the given terminal control and stdin stream. - * Subclasses may override to create a specialized stream monitor. - * - * @param terminalControl The terminal control. Must not be null. - * @param stdin The stdin stream or null. + /** + * Creates an stdin monitor for the given terminal control and stdin stream. + * Subclasses may override to create a specialized stream monitor. + * + * @param terminalControl The terminal control. Must not be null. + * @param stdin The stdin stream or null. * @param localEcho Local echo on or off. * @param lineSeparator The line separator used by the stream. * - * @return input stream monitor - */ - protected InputStreamMonitor createStdInMonitor(ITerminalControl terminalControl, OutputStream stdin, boolean localEcho, String lineSeparator) { - return new InputStreamMonitor(terminalControl, stdin, localEcho, lineSeparator); - } + * @return input stream monitor + */ + protected InputStreamMonitor createStdInMonitor(ITerminalControl terminalControl, OutputStream stdin, + boolean localEcho, String lineSeparator) { + return new InputStreamMonitor(terminalControl, stdin, localEcho, lineSeparator); + } - /** - * Creates an stdout monitor for the given terminal control and stdout stream. - * Subclasses may override to create a specialized stream monitor. - * - * @param terminalControl The terminal control. Must not be null. - * @param stdout The stdout stream or null. + /** + * Creates an stdout monitor for the given terminal control and stdout stream. + * Subclasses may override to create a specialized stream monitor. + * + * @param terminalControl The terminal control. Must not be null. + * @param stdout The stdout stream or null. * @param lineSeparator The line separator used by the stream. * - * @return output stream monitor - */ - protected OutputStreamMonitor createStdOutMonitor(ITerminalControl terminalControl, InputStream stdout, String lineSeparator) { - return new OutputStreamMonitor(terminalControl, stdout, lineSeparator); - } + * @return output stream monitor + */ + protected OutputStreamMonitor createStdOutMonitor(ITerminalControl terminalControl, InputStream stdout, + String lineSeparator) { + return new OutputStreamMonitor(terminalControl, stdout, lineSeparator); + } - /** - * Creates an stderr monitor for the given terminal control and stderr stream. - * Subclasses may override to create a specialized stream monitor. - * - * @param terminalControl The terminal control. Must not be null. - * @param stderr The stderr stream or null. + /** + * Creates an stderr monitor for the given terminal control and stderr stream. + * Subclasses may override to create a specialized stream monitor. + * + * @param terminalControl The terminal control. Must not be null. + * @param stderr The stderr stream or null. * @param lineSeparator The line separator used by the stream. * - * @return output stream monitor - */ - protected OutputStreamMonitor createStdErrMonitor(ITerminalControl terminalControl, InputStream stderr, String lineSeparator) { - return new OutputStreamMonitor(terminalControl, stderr, lineSeparator); - } + * @return output stream monitor + */ + protected OutputStreamMonitor createStdErrMonitor(ITerminalControl terminalControl, InputStream stderr, + String lineSeparator) { + return new OutputStreamMonitor(terminalControl, stderr, lineSeparator); + } - /* (non-Javadoc) - * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#doDisconnect() - */ - @Override - protected void doDisconnect() { - // Dispose the streams - if (stdInMonitor != null) { stdInMonitor.dispose(); stdInMonitor = null; } - if (stdOutMonitor != null) { stdOutMonitor.dispose(); stdOutMonitor = null; } - if (stdErrMonitor != null) { stdErrMonitor.dispose(); stdErrMonitor = null; } + /* (non-Javadoc) + * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#doDisconnect() + */ + @Override + protected void doDisconnect() { + // Dispose the streams + if (stdInMonitor != null) { + stdInMonitor.dispose(); + stdInMonitor = null; + } + if (stdOutMonitor != null) { + stdOutMonitor.dispose(); + stdOutMonitor = null; + } + if (stdErrMonitor != null) { + stdErrMonitor.dispose(); + stdErrMonitor = null; + } - super.doDisconnect(); - } + super.doDisconnect(); + } - /* (non-Javadoc) - * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#getTerminalToRemoteStream() - */ + /* (non-Javadoc) + * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#getTerminalToRemoteStream() + */ @Override public OutputStream getTerminalToRemoteStream() { return stdInMonitor; diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/InputStreamMonitor.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/InputStreamMonitor.java index 5f6e804fdc4..7fabea68c1d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/InputStreamMonitor.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/InputStreamMonitor.java @@ -35,26 +35,26 @@ import org.eclipse.ui.services.IDisposable; * stream monitor is attached to the stdin stream of the monitored (remote) process. */ public class InputStreamMonitor extends OutputStream implements IDisposable { - // Reference to the parent terminal control + // Reference to the parent terminal control private final ITerminalControl terminalControl; // Reference to the monitored (output) stream - private final OutputStream stream; + private final OutputStream stream; - // Reference to the thread writing the stream - private volatile Thread thread; + // Reference to the thread writing the stream + private volatile Thread thread; - // Flag to mark the monitor disposed. When disposed, - // no further data is written from the monitored stream. - private volatile boolean disposed; + // Flag to mark the monitor disposed. When disposed, + // no further data is written from the monitored stream. + private volatile boolean disposed; - // A list of object to dispose if this monitor is disposed - private final List disposables = new ArrayList(); + // A list of object to dispose if this monitor is disposed + private final List disposables = new ArrayList(); - // Queue to buffer the data to write to the output stream - private final Queue queue = new LinkedList(); + // Queue to buffer the data to write to the output stream + private final Queue queue = new LinkedList(); - // ***** Line separator replacement logic ***** + // ***** Line separator replacement logic ***** private final static int TERMINAL_SENDS_CR = 0; private final static int TERMINAL_SENDS_CRLF = 1; @@ -77,29 +77,28 @@ public class InputStreamMonitor extends OutputStream implements IDisposable { // private final static int[][] CRLF_REPLACEMENT = { - {CHANGE_CR_TO_LF, INSERT_LF_AFTER_CR, NO_CHANGE}, - {REMOVE_CR, NO_CHANGE, REMOVE_LF} - }; + { CHANGE_CR_TO_LF, INSERT_LF_AFTER_CR, NO_CHANGE }, { REMOVE_CR, NO_CHANGE, REMOVE_LF } }; private int replacement; - /** - * Constructor. - * - * @param terminalControl The parent terminal control. Must not be null. - * @param stream The stream. Must not be null. + /** + * Constructor. + * + * @param terminalControl The parent terminal control. Must not be null. + * @param stream The stream. Must not be null. * @param localEcho Local echo on or off. * @param lineSeparator The line separator used by the stream. - */ - public InputStreamMonitor(ITerminalControl terminalControl, OutputStream stream, boolean localEcho, String lineSeparator) { - super(); + */ + public InputStreamMonitor(ITerminalControl terminalControl, OutputStream stream, boolean localEcho, + String lineSeparator) { + super(); - Assert.isNotNull(terminalControl); - this.terminalControl = terminalControl; - Assert.isNotNull(stream); - this.stream = stream; + Assert.isNotNull(terminalControl); + this.terminalControl = terminalControl; + Assert.isNotNull(stream); + this.stream = stream; - // Determine the line separator replacement setting + // Determine the line separator replacement setting int terminalSends = localEcho ? TERMINAL_SENDS_CRLF : TERMINAL_SENDS_CR; if (lineSeparator == null) { replacement = NO_CHANGE; @@ -107,17 +106,15 @@ public class InputStreamMonitor extends OutputStream implements IDisposable { int programExpects; if (lineSeparator.equals(ILineSeparatorConstants.LINE_SEPARATOR_LF)) { programExpects = PROGRAM_EXPECTS_LF; - } - else if (lineSeparator.equals(ILineSeparatorConstants.LINE_SEPARATOR_CR)) { + } else if (lineSeparator.equals(ILineSeparatorConstants.LINE_SEPARATOR_CR)) { programExpects = PROGRAM_EXPECTS_CR; - } - else { + } else { programExpects = PROGRAM_EXPECTS_CRLF; } replacement = CRLF_REPLACEMENT[terminalSends][programExpects]; } - } + } /** * Returns the associated terminal control. @@ -137,7 +134,8 @@ public class InputStreamMonitor extends OutputStream implements IDisposable { */ public final void addDisposable(IDisposable disposable) { Assert.isNotNull(disposable); - if (!disposed && !disposables.contains(disposable)) disposables.add(disposable); + if (!disposed && !disposables.contains(disposable)) + disposables.add(disposable); } /** @@ -156,213 +154,219 @@ public class InputStreamMonitor extends OutputStream implements IDisposable { @Override public void dispose() { // If already disposed --> return immediately - if (disposed) return; + if (disposed) + return; // Mark the monitor disposed - disposed = true; + disposed = true; - // Close the stream (ignore exceptions on close) - try { stream.close(); } catch (IOException e) { /* ignored on purpose */ } - // And interrupt the thread - close(); + // Close the stream (ignore exceptions on close) + try { + stream.close(); + } catch (IOException e) { + /* ignored on purpose */ } + // And interrupt the thread + close(); - // Dispose all registered disposable objects - for (IDisposable disposable : disposables) disposable.dispose(); - // Clear the list - disposables.clear(); + // Dispose all registered disposable objects + for (IDisposable disposable : disposables) + disposable.dispose(); + // Clear the list + disposables.clear(); } - /** - * Close the terminal input stream monitor. - */ - @Override + /** + * Close the terminal input stream monitor. + */ + @Override public void close() { - // Not initialized -> return immediately - if (thread == null) return; + // Not initialized -> return immediately + if (thread == null) + return; - // Copy the reference - final Thread oldThread = thread; - // Unlink the monitor from the thread - thread = null; - // And interrupt the writer thread - oldThread.interrupt(); - } + // Copy the reference + final Thread oldThread = thread; + // Unlink the monitor from the thread + thread = null; + // And interrupt the writer thread + oldThread.interrupt(); + } - /** - * Starts the terminal output stream monitor. - */ - public void startMonitoring() { - // If already initialized -> return immediately - if (thread != null) return; + /** + * Starts the terminal output stream monitor. + */ + public void startMonitoring() { + // If already initialized -> return immediately + if (thread != null) + return; - // Create a new runnable which is constantly reading from the stream - Runnable runnable = new Runnable() { - @Override + // Create a new runnable which is constantly reading from the stream + Runnable runnable = new Runnable() { + @Override public void run() { - writeStream(); - } - }; + writeStream(); + } + }; - // Create the writer thread - thread = new Thread(runnable, "Terminal Input Stream Monitor Thread"); //$NON-NLS-1$ + // Create the writer thread + thread = new Thread(runnable, "Terminal Input Stream Monitor Thread"); //$NON-NLS-1$ - // Configure the writer thread - thread.setDaemon(true); + // Configure the writer thread + thread.setDaemon(true); - // Start the processing - thread.start(); - } + // Start the processing + thread.start(); + } - - /** - * Reads from the queue and writes the read content to the stream. - */ - protected void writeStream() { - // Read from the queue and write to the stream until disposed - outer: while (thread != null && !disposed) { - byte[] data; + /** + * Reads from the queue and writes the read content to the stream. + */ + protected void writeStream() { + // Read from the queue and write to the stream until disposed + outer: while (thread != null && !disposed) { + byte[] data; // If the queue is empty, wait until notified - synchronized(queue) { - while (queue.isEmpty()) { - if (disposed) break outer; + synchronized (queue) { + while (queue.isEmpty()) { + if (disposed) + break outer; try { queue.wait(); } catch (InterruptedException e) { break outer; } - } - // Retrieves the queue head (is null if queue is empty (should never happen)) - data = queue.poll(); - } - if (data != null) { - try { - // Break up writes into max 1000 byte junks to avoid console input buffer overflows on Windows - int written = 0; - byte[] buf = new byte[1000]; - while (written < data.length) { - int len = Math.min(buf.length, data.length - written); - System.arraycopy(data, written, buf, 0, len); - // Write the data to the stream - stream.write(buf, 0, len); + } + // Retrieves the queue head (is null if queue is empty (should never happen)) + data = queue.poll(); + } + if (data != null) { + try { + // Break up writes into max 1000 byte junks to avoid console input buffer overflows on Windows + int written = 0; + byte[] buf = new byte[1000]; + while (written < data.length) { + int len = Math.min(buf.length, data.length - written); + System.arraycopy(data, written, buf, 0, len); + // Write the data to the stream + stream.write(buf, 0, len); written += len; - // Flush the stream immediately - stream.flush(); - // Wait a little between writes to allow input being processed - if (written < data.length) - Thread.sleep(100); - } - } catch (IOException e) { - // IOException received. If this is happening when already disposed -> ignore - if (!disposed) { - IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.InputStreamMonitor_error_writingToStream, e.getLocalizedMessage()), e); - UIPlugin.getDefault().getLog().log(status); - } - } - catch (InterruptedException e) { - break; - } - } - } + // Flush the stream immediately + stream.flush(); + // Wait a little between writes to allow input being processed + if (written < data.length) + Thread.sleep(100); + } + } catch (IOException e) { + // IOException received. If this is happening when already disposed -> ignore + if (!disposed) { + IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + NLS.bind(Messages.InputStreamMonitor_error_writingToStream, e.getLocalizedMessage()), + e); + UIPlugin.getDefault().getLog().log(status); + } + } catch (InterruptedException e) { + break; + } + } + } - // Dispose the stream - dispose(); - } + // Dispose the stream + dispose(); + } /* (non-Javadoc) * @see java.io.OutputStream#write(int) */ - @Override - public void write(int b) throws IOException { - synchronized(queue) { - queue.add(new byte[] { (byte)b }); - queue.notifyAll(); - } - } + @Override + public void write(int b) throws IOException { + synchronized (queue) { + queue.add(new byte[] { (byte) b }); + queue.notifyAll(); + } + } - /* (non-Javadoc) - * @see java.io.OutputStream#write(byte[], int, int) - */ - @Override - public void write(byte[] b, int off, int len) throws IOException { - // Write the whole block to the queue to avoid synchronization - // to happen for every byte. To do so, we have to avoid calling - // the super method. Therefore we have to do the same checking - // here as the base class does. + /* (non-Javadoc) + * @see java.io.OutputStream#write(byte[], int, int) + */ + @Override + public void write(byte[] b, int off, int len) throws IOException { + // Write the whole block to the queue to avoid synchronization + // to happen for every byte. To do so, we have to avoid calling + // the super method. Therefore we have to do the same checking + // here as the base class does. - // Null check. See the implementation in OutputStream. - if (b == null) throw new NullPointerException(); + // Null check. See the implementation in OutputStream. + if (b == null) + throw new NullPointerException(); - // Boundary check. See the implementation in OutputStream. - if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } - else if (len == 0) { - return; - } + // Boundary check. See the implementation in OutputStream. + if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } - // Make sure that the written block is not interlaced with other input. - synchronized(queue) { - // Preprocess the block to be written - byte[] processedBytes = onWriteContentToStream(b, off, len); - // If the returned array is not the original one, adjust offset and length - if (processedBytes != b) { - off = 0; len = processedBytes.length; b = processedBytes; - } + // Make sure that the written block is not interlaced with other input. + synchronized (queue) { + // Preprocess the block to be written + byte[] processedBytes = onWriteContentToStream(b, off, len); + // If the returned array is not the original one, adjust offset and length + if (processedBytes != b) { + off = 0; + len = processedBytes.length; + b = processedBytes; + } - // Get the content from the byte buffer specified by offset and length - byte[] bytes = new byte[len]; - int j = 0; - for (int i = 0 ; i < len ; i++) { - bytes[j++] = b[off + i]; - } + // Get the content from the byte buffer specified by offset and length + byte[] bytes = new byte[len]; + int j = 0; + for (int i = 0; i < len; i++) { + bytes[j++] = b[off + i]; + } - queue.add(bytes); - queue.notifyAll(); - } - } + queue.add(bytes); + queue.notifyAll(); + } + } - /** - * Allow for processing of data from byte stream from the terminal before - * it is written to the output stream. If the returned byte array is different - * than the one that was passed in with the bytes argument, then the - * length value will be adapted. - * - * @param bytes The byte stream. Must not be null. - * @param off The offset. - * @param len the length. - * - * @return The processed byte stream. - * - */ - protected byte[] onWriteContentToStream(byte[] bytes, int off, int len) { - Assert.isNotNull(bytes); + /** + * Allow for processing of data from byte stream from the terminal before + * it is written to the output stream. If the returned byte array is different + * than the one that was passed in with the bytes argument, then the + * length value will be adapted. + * + * @param bytes The byte stream. Must not be null. + * @param off The offset. + * @param len the length. + * + * @return The processed byte stream. + * + */ + protected byte[] onWriteContentToStream(byte[] bytes, int off, int len) { + Assert.isNotNull(bytes); - if (replacement != NO_CHANGE && len > 0) { - String origText = new String(bytes, off, len); - String text = null; - // - // TODO: check whether this is correct! new String(byte[], int, int) always uses the default - // encoding! + if (replacement != NO_CHANGE && len > 0) { + String origText = new String(bytes, off, len); + String text = null; + // + // TODO: check whether this is correct! new String(byte[], int, int) always uses the default + // encoding! - if (replacement == CHANGE_CR_TO_LF) { - text = origText.replace('\r', '\n'); - } - else if (replacement == INSERT_LF_AFTER_CR) { - text = origText.replaceAll("\r\n|\r", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ - } - else if (replacement == REMOVE_CR) { - text = origText.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_CR, ""); //$NON-NLS-1$ - } - else if (replacement == REMOVE_LF) { - text = origText.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_LF, ""); //$NON-NLS-1$ - } + if (replacement == CHANGE_CR_TO_LF) { + text = origText.replace('\r', '\n'); + } else if (replacement == INSERT_LF_AFTER_CR) { + text = origText.replaceAll("\r\n|\r", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + } else if (replacement == REMOVE_CR) { + text = origText.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_CR, ""); //$NON-NLS-1$ + } else if (replacement == REMOVE_LF) { + text = origText.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_LF, ""); //$NON-NLS-1$ + } - if (text != null && !origText.equals(text)) { - bytes = text.getBytes(); - } - } + if (text != null && !origText.equals(text)) { + bytes = text.getBytes(); + } + } - return bytes; - } + return bytes; + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/OutputStreamMonitor.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/OutputStreamMonitor.java index 92f7a6b0a8c..4b65ceadb35 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/OutputStreamMonitor.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/OutputStreamMonitor.java @@ -39,49 +39,49 @@ import org.eclipse.ui.services.IDisposable; */ public class OutputStreamMonitor implements IDisposable { // The default buffer size to use - private static final int BUFFER_SIZE = 8192; + private static final int BUFFER_SIZE = 8192; - // Reference to the parent terminal control - private final ITerminalControl terminalControl; + // Reference to the parent terminal control + private final ITerminalControl terminalControl; // Reference to the monitored (input) stream - private final InputStream stream; + private final InputStream stream; - // The line separator used by the monitored (input) stream - private final String lineSeparator; + // The line separator used by the monitored (input) stream + private final String lineSeparator; - // Reference to the thread reading the stream - private Thread thread; + // Reference to the thread reading the stream + private Thread thread; - // Flag to mark the monitor disposed. When disposed, - // no further data is read from the monitored stream. - private boolean disposed; + // Flag to mark the monitor disposed. When disposed, + // no further data is read from the monitored stream. + private boolean disposed; - // A list of object to dispose if this monitor is disposed - private final List disposables = new ArrayList(); + // A list of object to dispose if this monitor is disposed + private final List disposables = new ArrayList(); // The list of registered listener private final ListenerList listeners; - /** - * Constructor. - * - * @param terminalControl The parent terminal control. Must not be null. - * @param stream The stream. Must not be null. + /** + * Constructor. + * + * @param terminalControl The parent terminal control. Must not be null. + * @param stream The stream. Must not be null. * @param lineSeparator The line separator used by the stream. - */ + */ public OutputStreamMonitor(ITerminalControl terminalControl, InputStream stream, String lineSeparator) { - super(); + super(); - Assert.isNotNull(terminalControl); - this.terminalControl = terminalControl; - Assert.isNotNull(stream); - this.stream = new BufferedInputStream(stream, BUFFER_SIZE); + Assert.isNotNull(terminalControl); + this.terminalControl = terminalControl; + Assert.isNotNull(stream); + this.stream = new BufferedInputStream(stream, BUFFER_SIZE); - this.lineSeparator = lineSeparator; + this.lineSeparator = lineSeparator; - this.listeners = new ListenerList(); - } + this.listeners = new ListenerList(); + } /** * Register a streams data receiver listener. @@ -112,7 +112,8 @@ public class OutputStreamMonitor implements IDisposable { */ public final void addDisposable(IDisposable disposable) { Assert.isNotNull(disposable); - if (!disposed && !disposables.contains(disposable)) disposables.add(disposable); + if (!disposed && !disposables.contains(disposable)) + disposables.add(disposable); } /** @@ -128,144 +129,153 @@ public class OutputStreamMonitor implements IDisposable { /* (non-Javadoc) * @see org.eclipse.ui.services.IDisposable#dispose() */ - @Override + @Override public void dispose() { // If already disposed --> return immediately - if (disposed) return; + if (disposed) + return; // Mark the monitor disposed - disposed = true; + disposed = true; - // Close the stream (ignore exceptions on close) - try { stream.close(); } catch (IOException e) { /* ignored on purpose */ } + // Close the stream (ignore exceptions on close) + try { + stream.close(); + } catch (IOException e) { + /* ignored on purpose */ } - // Dispose all registered disposable objects - for (IDisposable disposable : disposables) disposable.dispose(); - // Clear the list - disposables.clear(); - } + // Dispose all registered disposable objects + for (IDisposable disposable : disposables) + disposable.dispose(); + // Clear the list + disposables.clear(); + } - /** - * Starts the terminal output stream monitor. - */ - protected void startMonitoring() { - // If already initialized -> return immediately - if (thread != null) return; + /** + * Starts the terminal output stream monitor. + */ + protected void startMonitoring() { + // If already initialized -> return immediately + if (thread != null) + return; - // Create a new runnable which is constantly reading from the stream - Runnable runnable = new Runnable() { - @Override + // Create a new runnable which is constantly reading from the stream + Runnable runnable = new Runnable() { + @Override public void run() { - readStream(); - } - }; + readStream(); + } + }; - // Create the reader thread - thread = new Thread(runnable, "Terminal Output Stream Monitor Thread"); //$NON-NLS-1$ + // Create the reader thread + thread = new Thread(runnable, "Terminal Output Stream Monitor Thread"); //$NON-NLS-1$ - // Configure the reader thread - thread.setDaemon(true); - thread.setPriority(Thread.MIN_PRIORITY); + // Configure the reader thread + thread.setDaemon(true); + thread.setPriority(Thread.MIN_PRIORITY); - // Start the processing - thread.start(); - } + // Start the processing + thread.start(); + } - /** - * Returns the terminal control that this stream monitor is associated with. - */ - protected ITerminalControl getTerminalControl() { - return terminalControl; - } + /** + * Returns the terminal control that this stream monitor is associated with. + */ + protected ITerminalControl getTerminalControl() { + return terminalControl; + } - /** - * Reads from the output stream and write the read content - * to the terminal control output stream. - */ - void readStream() { - // Creates the read buffer - byte[] readBuffer = new byte[BUFFER_SIZE]; + /** + * Reads from the output stream and write the read content + * to the terminal control output stream. + */ + void readStream() { + // Creates the read buffer + byte[] readBuffer = new byte[BUFFER_SIZE]; - // We need to maintain UI responsiveness but still stream the content - // to the terminal control fast. Put the thread to a short sleep each second. - long sleepMarker = System.currentTimeMillis(); + // We need to maintain UI responsiveness but still stream the content + // to the terminal control fast. Put the thread to a short sleep each second. + long sleepMarker = System.currentTimeMillis(); - // Read from the stream until EOS is reached or the - // monitor is marked disposed. - int read = 0; - while (read >= 0 && !disposed) { - try { + // Read from the stream until EOS is reached or the + // monitor is marked disposed. + int read = 0; + while (read >= 0 && !disposed) { + try { // Read from the stream read = stream.read(readBuffer); // If some data has been read, append to the terminal // control output stream if (read > 0) { // Allow for post processing the read content before appending - byte[] processedReadBuffer = onContentReadFromStream(readBuffer, read); - if (processedReadBuffer != readBuffer) { - read = processedReadBuffer.length; - } + byte[] processedReadBuffer = onContentReadFromStream(readBuffer, read); + if (processedReadBuffer != readBuffer) { + read = processedReadBuffer.length; + } terminalControl.getRemoteToTerminalOutputStream().write(processedReadBuffer, 0, read); } - } catch (IOException e) { - // IOException received. If this is happening when already disposed -> ignore + } catch (IOException e) { + // IOException received. If this is happening when already disposed -> ignore if (!disposed) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.OutputStreamMonitor_error_readingFromStream, e.getLocalizedMessage()), e); + NLS.bind(Messages.OutputStreamMonitor_error_readingFromStream, e.getLocalizedMessage()), e); UIPlugin.getDefault().getLog().log(status); } - break; - } catch (NullPointerException e) { + break; + } catch (NullPointerException e) { // killing the stream monitor while reading can cause an NPE // when reading from the stream if (!disposed && thread != null) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind(Messages.OutputStreamMonitor_error_readingFromStream, e.getLocalizedMessage()), e); + NLS.bind(Messages.OutputStreamMonitor_error_readingFromStream, e.getLocalizedMessage()), e); UIPlugin.getDefault().getLog().log(status); } break; - } + } - // See above -> Thread will go to sleep each second - if (System.currentTimeMillis() - sleepMarker > 1000) { - sleepMarker = System.currentTimeMillis(); - try { Thread.sleep(1); } catch (InterruptedException e) { /* ignored on purpose */ } - } - } + // See above -> Thread will go to sleep each second + if (System.currentTimeMillis() - sleepMarker > 1000) { + sleepMarker = System.currentTimeMillis(); + try { + Thread.sleep(1); + } catch (InterruptedException e) { + /* ignored on purpose */ } + } + } - // Dispose ourself - dispose(); - } + // Dispose ourself + dispose(); + } - /** - * Allow for processing of data from byte stream after it is read from - * client but before it is appended to the terminal. If the returned byte - * array is different than the one that was passed in with the byteBuffer - * argument, then the bytesRead value will be ignored and the full - * returned array will be written out. - * - * @param byteBuffer The byte stream. Must not be null. - * @param bytesRead The number of bytes that were read into the read buffer. - * @return The processed byte stream. - * - */ - protected byte[] onContentReadFromStream(byte[] byteBuffer, int bytesRead) { - Assert.isNotNull(byteBuffer); + /** + * Allow for processing of data from byte stream after it is read from + * client but before it is appended to the terminal. If the returned byte + * array is different than the one that was passed in with the byteBuffer + * argument, then the bytesRead value will be ignored and the full + * returned array will be written out. + * + * @param byteBuffer The byte stream. Must not be null. + * @param bytesRead The number of bytes that were read into the read buffer. + * @return The processed byte stream. + * + */ + protected byte[] onContentReadFromStream(byte[] byteBuffer, int bytesRead) { + Assert.isNotNull(byteBuffer); - // If tracing is enabled, print out the decimal byte values read - if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_OUTPUT_STREAM_MONITOR)) { - StringBuilder debug = new StringBuilder("byteBuffer [decimal, " + bytesRead + " bytes] : "); //$NON-NLS-1$ //$NON-NLS-2$ - for (int i = 0; i < bytesRead; i++) { - debug.append(Byte.valueOf(byteBuffer[i]).intValue()); - debug.append(' '); - } - System.out.println(debug.toString()); - } + // If tracing is enabled, print out the decimal byte values read + if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_OUTPUT_STREAM_MONITOR)) { + StringBuilder debug = new StringBuilder("byteBuffer [decimal, " + bytesRead + " bytes] : "); //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < bytesRead; i++) { + debug.append(Byte.valueOf(byteBuffer[i]).intValue()); + debug.append(' '); + } + System.out.println(debug.toString()); + } - // Remember if the text got changed. - boolean changed = false; + // Remember if the text got changed. + boolean changed = false; - // How can me make sure that we don't mess with the encoding here? + // How can me make sure that we don't mess with the encoding here? String text = new String(byteBuffer, 0, bytesRead); // Shift-In (14) and Shift-Out(15) confuses the terminal widget @@ -275,46 +285,48 @@ public class OutputStreamMonitor implements IDisposable { } // Check on the line separator setting - if (lineSeparator != null - && !ILineSeparatorConstants.LINE_SEPARATOR_CRLF.equals(lineSeparator)) { - String separator = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\n" : "\r"; //$NON-NLS-1$ //$NON-NLS-2$ - String separator2 = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\r" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + if (lineSeparator != null && !ILineSeparatorConstants.LINE_SEPARATOR_CRLF.equals(lineSeparator)) { + String separator = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\n" : "\r"; //$NON-NLS-1$ //$NON-NLS-2$ + String separator2 = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\r" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - if (text.indexOf(separator) != -1) { - String[] fragments = text.split(separator); - StringBuilder b = new StringBuilder(); - for (int i = 0; i < fragments.length; i++) { - String fragment = fragments[i]; - String nextFragment = i + 1 < fragments.length ? fragments[i + 1] : null; - b.append(fragment); - if (fragment.endsWith(separator2) || (nextFragment != null && nextFragment.startsWith(separator2))) { - // Both separators are found, just add the original separator - b.append(separator); - } else { - b.append("\n\r"); //$NON-NLS-1$ - } - } - if (!text.equals(b.toString())) { - text = b.toString(); - changed = true; - } - } - } + if (text.indexOf(separator) != -1) { + String[] fragments = text.split(separator); + StringBuilder b = new StringBuilder(); + for (int i = 0; i < fragments.length; i++) { + String fragment = fragments[i]; + String nextFragment = i + 1 < fragments.length ? fragments[i + 1] : null; + b.append(fragment); + if (fragment.endsWith(separator2) + || (nextFragment != null && nextFragment.startsWith(separator2))) { + // Both separators are found, just add the original separator + b.append(separator); + } else { + b.append("\n\r"); //$NON-NLS-1$ + } + } + if (!text.equals(b.toString())) { + text = b.toString(); + changed = true; + } + } + } - // If changed, get the new bytes array - if (changed) { - byteBuffer = text.getBytes(); - bytesRead = byteBuffer.length; - } + // If changed, get the new bytes array + if (changed) { + byteBuffer = text.getBytes(); + bytesRead = byteBuffer.length; + } - // If listeners are registered, invoke the listeners now. - if (listeners.size() > 0) { - for (Object candidate : listeners.getListeners()) { - if (!(candidate instanceof ITerminalServiceOutputStreamMonitorListener)) continue; - ((ITerminalServiceOutputStreamMonitorListener)candidate).onContentReadFromStream(byteBuffer, bytesRead); - } - } + // If listeners are registered, invoke the listeners now. + if (listeners.size() > 0) { + for (Object candidate : listeners.getListeners()) { + if (!(candidate instanceof ITerminalServiceOutputStreamMonitorListener)) + continue; + ((ITerminalServiceOutputStreamMonitorListener) candidate).onContentReadFromStream(byteBuffer, + bytesRead); + } + } - return byteBuffer; - } + return byteBuffer; + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsConnector.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsConnector.java index a62eb86a2c7..9384315e796 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsConnector.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsConnector.java @@ -57,7 +57,8 @@ public class StreamsConnector extends AbstractStreamsConnector implements IDispo setStderrListeners(settings.getStdErrListeners()); // connect the streams - connectStreams(control, settings.getStdinStream(), settings.getStdoutStream(), settings.getStderrStream(), settings.isLocalEcho(), settings.getLineSeparator()); + connectStreams(control, settings.getStdinStream(), settings.getStdoutStream(), settings.getStderrStream(), + settings.isLocalEcho(), settings.getLineSeparator()); // Set the terminal control state to CONNECTED control.setState(TerminalState.CONNECTED); @@ -103,7 +104,7 @@ public class StreamsConnector extends AbstractStreamsConnector implements IDispo @Override public void setDefaultSettings() { - settings.load(new NullSettingsStore()); + settings.load(new NullSettingsStore()); } /* (non-Javadoc) diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsLauncherDelegate.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsLauncherDelegate.java index 8c126f1bac0..d3e6120eb62 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsLauncherDelegate.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsLauncherDelegate.java @@ -67,23 +67,26 @@ public class StreamsLauncherDelegate extends AbstractLauncherDelegate { /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) */ - @Override + @Override public ITerminalConnector createTerminalConnector(Map properties) { Assert.isNotNull(properties); - // Check for the terminal connector id - String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.streams.StreamsConnector"; //$NON-NLS-1$ + // Check for the terminal connector id + String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + if (connectorId == null) + connectorId = "org.eclipse.tm.terminal.connector.streams.StreamsConnector"; //$NON-NLS-1$ // Extract the streams properties - OutputStream stdin = (OutputStream)properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDIN); - InputStream stdout = (InputStream)properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDOUT); - InputStream stderr = (InputStream)properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDERR); + OutputStream stdin = (OutputStream) properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDIN); + InputStream stdout = (InputStream) properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDOUT); + InputStream stderr = (InputStream) properties.get(ITerminalsConnectorConstants.PROP_STREAMS_STDERR); Object value = properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO); - boolean localEcho = value instanceof Boolean ? ((Boolean)value).booleanValue() : false; - String lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); - ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); - ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); + boolean localEcho = value instanceof Boolean ? ((Boolean) value).booleanValue() : false; + String lineSeparator = (String) properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); + ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); + ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties + .get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS); // Construct the terminal settings store ISettingsStore store = new SettingsStore(); diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsSettings.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsSettings.java index a7ca35fad50..09aecaa893a 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsSettings.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/streams/StreamsSettings.java @@ -33,10 +33,10 @@ public class StreamsSettings { private boolean localEcho = true; // The line separator setting private String lineSeparator = null; - // The list of stdout output listeners - private ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = null; - // The list of stderr output listeners - private ITerminalServiceOutputStreamMonitorListener[] stderrListeners = null; + // The list of stdout output listeners + private ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = null; + // The list of stderr output listeners + private ITerminalServiceOutputStreamMonitorListener[] stderrListeners = null; /** * Sets the stdin stream instance. @@ -175,11 +175,13 @@ public class StreamsSettings { localEcho = Boolean.parseBoolean(store.get("LocalEcho", Boolean.FALSE.toString())); //$NON-NLS-1$ lineSeparator = store.get("LineSeparator", null); //$NON-NLS-1$ if (store instanceof SettingsStore) { - stdin = (OutputStream)((SettingsStore)store).getSettings().get("stdin"); //$NON-NLS-1$ - stdout = (InputStream)((SettingsStore)store).getSettings().get("stdout"); //$NON-NLS-1$ - stderr = (InputStream)((SettingsStore)store).getSettings().get("stderr"); //$NON-NLS-1$ - stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdOutListeners"); //$NON-NLS-1$ - stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdErrListeners"); //$NON-NLS-1$ + stdin = (OutputStream) ((SettingsStore) store).getSettings().get("stdin"); //$NON-NLS-1$ + stdout = (InputStream) ((SettingsStore) store).getSettings().get("stdout"); //$NON-NLS-1$ + stderr = (InputStream) ((SettingsStore) store).getSettings().get("stderr"); //$NON-NLS-1$ + stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings() + .get("StdOutListeners"); //$NON-NLS-1$ + stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings() + .get("StdErrListeners"); //$NON-NLS-1$ } } @@ -193,11 +195,11 @@ public class StreamsSettings { store.put("LocalEcho", Boolean.toString(localEcho)); //$NON-NLS-1$ store.put("LineSeparator", lineSeparator); //$NON-NLS-1$ if (store instanceof SettingsStore) { - ((SettingsStore)store).getSettings().put("stdin", stdin); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("stdout", stdout); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("stderr", stderr); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$ - ((SettingsStore)store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("stdin", stdin); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("stdout", stdout); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("stderr", stderr); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$ + ((SettingsStore) store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$ } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabCommandFieldHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabCommandFieldHandler.java index 067586571e0..0a44222c8f8 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabCommandFieldHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabCommandFieldHandler.java @@ -66,7 +66,7 @@ public class TabCommandFieldHandler implements IDisposable, IAdaptable { if (CTabItem.class.equals(adapter)) { return item; } - return null; + return null; } /** @@ -97,8 +97,9 @@ public class TabCommandFieldHandler implements IDisposable, IAdaptable { // Apply to the terminal control Assert.isTrue(!item.isDisposed()); - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); - if (terminal != null) terminal.setCommandInputField(field); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); + if (terminal != null) + terminal.setCommandInputField(field); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabDisposeListener.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabDisposeListener.java index 3cc4186a5b1..cabdb9c71d7 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabDisposeListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabDisposeListener.java @@ -54,21 +54,23 @@ public class TabDisposeListener implements DisposeListener { // If a tab item gets disposed, we have to dispose the terminal as well if (e.getSource() instanceof CTabItem) { // Get the terminal control (if any) from the tab item - Object candidate = ((CTabItem)e.getSource()).getData(); + Object candidate = ((CTabItem) e.getSource()).getData(); if (candidate instanceof ITerminalViewControl) { - ITerminalViewControl terminal = (ITerminalViewControl)candidate; + ITerminalViewControl terminal = (ITerminalViewControl) candidate; // Keep the context menu from being disposed terminal.getControl().setMenu(null); terminal.disposeTerminal(); } // Dispose the command input field handler - parentTabFolderManager.disposeTabCommandFieldHandler((CTabItem)e.getSource()); + parentTabFolderManager.disposeTabCommandFieldHandler((CTabItem) e.getSource()); // Dispose the tab item control Control control = ((CTabItem) e.getSource()).getControl(); - if (control != null) control.dispose(); + if (control != null) + control.dispose(); // If all items got removed, we have to switch back to the empty page control - if (parentTabFolderManager.getTabFolder() != null && parentTabFolderManager.getTabFolder().getItemCount() == 0) { + if (parentTabFolderManager.getTabFolder() != null + && parentTabFolderManager.getTabFolder().getItemCount() == 0) { parentTabFolderManager.getParentView().switchToEmptyPageControl(); } // Fire selection changed event @@ -76,7 +78,8 @@ public class TabDisposeListener implements DisposeListener { // Fire the terminal console disposed event ITerminalService service = TerminalServiceFactory.getService(); if (service instanceof TerminalService) { - ((TerminalService)service).fireTerminalTabEvent(TerminalService.TAB_DISPOSED, e.getSource(), ((CTabItem)e.getSource()).getData("customData")); //$NON-NLS-1$ + ((TerminalService) service).fireTerminalTabEvent(TerminalService.TAB_DISPOSED, e.getSource(), + ((CTabItem) e.getSource()).getData("customData")); //$NON-NLS-1$ } } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderManager.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderManager.java index eaf36785aef..8e74303a6f1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderManager.java @@ -127,7 +127,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid @Override public void mouseDown(MouseEvent e) { // Left button down -> select mode starts - if (e.button == 1) selectMode = true; + if (e.button == 1) + selectMode = true; } /* (non-Javadoc) @@ -138,18 +139,17 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid if (e.button == 1 && selectMode) { selectMode = false; // Fire a selection changed event with the terminal controls selection - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { + try { + Display display = PlatformUI.getWorkbench().getDisplay(); + display.asyncExec(new Runnable() { @Override public void run() { fireSelectionChanged(new StructuredSelection(getTerminal().getSelection())); } }); - } - catch (Exception ex) { - // if display is disposed, silently ignore. - } + } catch (Exception ex) { + // if display is disposed, silently ignore. + } } } @@ -173,7 +173,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // Attach a selection listener to the tab folder selectionListener = doCreateTabFolderSelectionListener(this); - if (getTabFolder() != null) getTabFolder().addSelectionListener(selectionListener); + if (getTabFolder() != null) + getTabFolder().addSelectionListener(selectionListener); } /** @@ -202,7 +203,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid * @return The tab folder or null. */ @SuppressWarnings("cast") - protected final CTabFolder getTabFolder() { + protected final CTabFolder getTabFolder() { return (CTabFolder) getParentView().getAdapter(CTabFolder.class); } @@ -220,7 +221,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ public void dispose() { // Dispose the selection listener - if (getTabFolder() != null && !getTabFolder().isDisposed()) getTabFolder().removeSelectionListener(selectionListener); + if (getTabFolder() != null && !getTabFolder().isDisposed()) + getTabFolder().removeSelectionListener(selectionListener); // Dispose the tab command field handler for (TabCommandFieldHandler handler : commandFieldHandler.values()) { handler.dispose(); @@ -240,7 +242,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid * @return The created tab item or null if failed. */ @SuppressWarnings({ "unused", "cast" }) - public CTabItem createTabItem(String title, String encoding, ITerminalConnector connector, Object data, Map flags) { + public CTabItem createTabItem(String title, String encoding, ITerminalConnector connector, Object data, + Map flags) { Assert.isNotNull(title); Assert.isNotNull(connector); @@ -258,7 +261,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid item.setText(title); // Set the tab icon Image image = getTabItemImage(connector, data); - if (image != null) item.setImage(image); + if (image != null) + item.setImage(image); // Setup the tab item listeners setupTerminalTabListeners(item); @@ -273,11 +277,13 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid tabFolder.getParent().layout(true); // Create the terminal control - ITerminalViewControl terminal = TerminalViewControlFactory.makeControl(doCreateTerminalTabTerminalListener(this, item), composite, new ITerminalConnector[] { connector }, true); + ITerminalViewControl terminal = TerminalViewControlFactory.makeControl( + doCreateTerminalTabTerminalListener(this, item), composite, new ITerminalConnector[] { connector }, + true); if (terminal instanceof ITerminalControl) { Object value = flags != null ? flags.get(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT) : null; - boolean noReconnect = value instanceof Boolean ? ((Boolean)value).booleanValue() : false; - ((ITerminalControl)terminal).setConnectOnEnterIfClosed(!noReconnect); + boolean noReconnect = value instanceof Boolean ? ((Boolean) value).booleanValue() : false; + ((ITerminalControl) terminal).setConnectOnEnterIfClosed(!noReconnect); } // Add middle mouse button paste support @@ -285,11 +291,15 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // Add the "selection" listener to the terminal control new TerminalControlSelectionListener(terminal); // Configure the terminal encoding - try { terminal.setEncoding(encoding); } catch (UnsupportedEncodingException e) { /* ignored on purpose */ } + try { + terminal.setEncoding(encoding); + } catch (UnsupportedEncodingException e) { + /* ignored on purpose */ } // Associated the terminal with the tab item item.setData(terminal); // Associated the custom data node with the tab item (if any) - if (data != null) item.setData("customData", data); //$NON-NLS-1$ + if (data != null) + item.setData("customData", data); //$NON-NLS-1$ // Overwrite the text canvas help id String contextHelpId = getParentView().getContextHelpId(); @@ -298,9 +308,10 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid } // Set the context menu - TabFolderMenuHandler menuHandler = (TabFolderMenuHandler) getParentView().getAdapter(TabFolderMenuHandler.class); + TabFolderMenuHandler menuHandler = (TabFolderMenuHandler) getParentView() + .getAdapter(TabFolderMenuHandler.class); if (menuHandler != null) { - Menu menu = (Menu)menuHandler.getAdapter(Menu.class); + Menu menu = (Menu) menuHandler.getAdapter(Menu.class); if (menu != null) { // One weird occurrence of IllegalArgumentException: Widget has wrong parent. // Inspecting the code, this seem extremely unlikely. The terminal is created @@ -335,8 +346,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid } /** - * Used for DnD of terminal tab items between terminal views - *

+ * Used for DnD of terminal tab items between terminal views + *

* Create a new tab item in the "dropped" terminal view using the * information stored in the given item. * @@ -344,13 +355,13 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid * @return The new dropped tab item. */ @SuppressWarnings({ "unchecked", "cast" }) - public CTabItem cloneTabItemAfterDrop(CTabItem oldItem) { + public CTabItem cloneTabItemAfterDrop(CTabItem oldItem) { Assert.isNotNull(oldItem); - ITerminalViewControl terminal = (ITerminalViewControl)oldItem.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) oldItem.getData(); ITerminalConnector connector = terminal.getTerminalConnector(); Object data = oldItem.getData("customData"); //$NON-NLS-1$ - Map properties = (Map)oldItem.getData("properties"); //$NON-NLS-1$ + Map properties = (Map) oldItem.getData("properties"); //$NON-NLS-1$ String title = oldItem.getText(); // The result tab item @@ -367,7 +378,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid item.setText(title); // Set the tab icon Image image = getTabItemImage(connector, data); - if (image != null) item.setImage(image); + if (image != null) + item.setImage(image); // Setup the tab item listeners setupTerminalTabListeners(item); @@ -391,7 +403,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // change the "parent". Assert.isTrue(terminal instanceof ITerminalControl); - ((ITerminalControl)terminal).setupTerminal(composite); + ((ITerminalControl) terminal).setupTerminal(composite); // Add middle mouse button paste support addMiddleMouseButtonPasteSupport(terminal); @@ -399,9 +411,11 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid item.setData(terminal); // Associate the custom data node with the tab item (if any) - if (data != null) item.setData("customData", data); //$NON-NLS-1$ + if (data != null) + item.setData("customData", data); //$NON-NLS-1$ // Associate the properties with the tab item (if any) - if (properties != null) item.setData("properties", properties); //$NON-NLS-1$ + if (properties != null) + item.setData("properties", properties); //$NON-NLS-1$ // Overwrite the text canvas help id String contextHelpId = getParentView().getContextHelpId(); @@ -410,9 +424,10 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid } // Set the context menu - TabFolderMenuHandler menuHandler = (TabFolderMenuHandler) getParentView().getAdapter(TabFolderMenuHandler.class); + TabFolderMenuHandler menuHandler = (TabFolderMenuHandler) getParentView() + .getAdapter(TabFolderMenuHandler.class); if (menuHandler != null) { - Menu menu = (Menu)menuHandler.getAdapter(Menu.class); + Menu menu = (Menu) menuHandler.getAdapter(Menu.class); if (menu != null) { // One weird occurrence of IllegalArgumentException: Widget has wrong parent. // Inspecting the code, this seem extremely unlikely. The terminal is created @@ -437,7 +452,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // needed to get the focus and cursor Assert.isTrue(terminal instanceof ITerminalControl); - ((ITerminalControl)terminal).setState(oldState); + ((ITerminalControl) terminal).setState(oldState); // Fire selection changed event fireSelectionChanged(); @@ -447,15 +462,15 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid return item; } - protected void addMiddleMouseButtonPasteSupport(final ITerminalViewControl terminal) { - terminal.getControl().addMouseListener(new MouseAdapter(){ + terminal.getControl().addMouseListener(new MouseAdapter() { @Override - public void mouseDown(MouseEvent e) { + public void mouseDown(MouseEvent e) { // paste when the middle button is clicked if (e.button == 2) { Clipboard clipboard = terminal.getClipboard(); - if (clipboard.isDisposed()) return; + if (clipboard.isDisposed()) + return; int clipboardType = DND.SELECTION_CLIPBOARD; if (clipboard.getAvailableTypes(clipboardType).length == 0) // use normal clipboard if selection clipboard is not available @@ -466,7 +481,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid } } }); - } + } /** * Generate a unique title string based on the given proposal. @@ -490,7 +505,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid titles.add(item.getText()); } // Make the proposal unique be appending () against all known titles. - while (titles.contains(title)) title = proposal + " (" + ++index + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + while (titles.contains(title)) + title = proposal + " (" + ++index + ")"; //$NON-NLS-1$ //$NON-NLS-2$ return title; } @@ -565,12 +581,14 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // Get the tab folder CTabFolder tabFolder = getTabFolder(); - if (tabFolder == null) return null; + if (tabFolder == null) + return null; // Loop all existing tab items and try to find a matching title for (CTabItem item : tabFolder.getItems()) { // Disposed items cannot be matched - if (item.isDisposed()) continue; + if (item.isDisposed()) + continue; // Get the title from the current tab item String itemTitle = item.getText(); // The terminal console state might be signaled to the user via the @@ -578,7 +596,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid itemTitle = itemTitle.replaceFirst("^<.*>\\s*", ""); //$NON-NLS-1$ //$NON-NLS-2$ if (itemTitle.startsWith(title)) { // The title string matches -> double check with the terminal connector - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); ITerminalConnector connector2 = terminal.getTerminalConnector(); // If the connector id and name matches -> check on the settings if (connector.getId().equals(connector2.getId()) && connector.getName().equals(connector2.getName())) { @@ -589,7 +607,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid String summary = connector.getSettingsSummary(); String summary2 = connector2.getSettingsSummary(); // If we have matching settings -> we've found the matching item - if (summary.equals(summary2)) return item; + if (summary.equals(summary2)) + return item; } } } @@ -607,7 +626,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid // Get the tab folder CTabFolder tabFolder = getTabFolder(); - if (tabFolder == null) return; + if (tabFolder == null) + return; // Set the given tab item as selection to the tab folder tabFolder.setSelection(item); @@ -623,7 +643,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid public CTabItem getActiveTabItem() { // Get the tab folder CTabFolder tabFolder = getTabFolder(); - if (tabFolder == null) return null; + if (tabFolder == null) + return null; return tabFolder.getSelection(); } @@ -634,12 +655,14 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid public void removeTerminatedItems() { // Get the tab folder CTabFolder tabFolder = getTabFolder(); - if (tabFolder == null) return; + if (tabFolder == null) + return; // Loop the items and check for terminated status - for (CTabItem item: tabFolder.getItems()) { + for (CTabItem item : tabFolder.getItems()) { // Disposed items cannot be matched - if (item.isDisposed()) continue; + if (item.isDisposed()) + continue; // Check if the item is terminated if (isTerminatedTabItem(item)) { // item is terminated -> dispose @@ -657,7 +680,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ protected boolean isTerminatedTabItem(CTabItem item) { // Null items or disposed items cannot be matched - if (item == null || item.isDisposed()) return false; + if (item == null || item.isDisposed()) + return false; // First, match the item title. If it contains "", the item can be removed String itemTitle = item.getText(); @@ -666,7 +690,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid } // Second, check if the associated terminal control is closed // The title string matches -> double check with the terminal connector - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); if (terminal != null && terminal.getState() == TerminalState.CLOSED) { return true; } @@ -682,7 +706,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ public final TabCommandFieldHandler getTabCommandFieldHandler(CTabItem item) { // Null items or disposed items cannot be matched - if (item == null || item.isDisposed()) return null; + if (item == null || item.isDisposed()) + return null; TabCommandFieldHandler handler = commandFieldHandler.get(item); if (handler == null) { @@ -714,10 +739,12 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ protected void disposeTabCommandFieldHandler(CTabItem item) { // Null items or disposed items cannot be matched - if (item == null || item.isDisposed()) return; + if (item == null || item.isDisposed()) + return; TabCommandFieldHandler handler = commandFieldHandler.remove(item); - if (handler != null) handler.dispose(); + if (handler != null) + handler.dispose(); } /* (non-Javadoc) @@ -725,7 +752,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ @Override public void addSelectionChangedListener(ISelectionChangedListener listener) { - if (listener != null && !selectionChangedListeners.contains(listener)) selectionChangedListeners.add(listener); + if (listener != null && !selectionChangedListeners.contains(listener)) + selectionChangedListeners.add(listener); } /* (non-Javadoc) @@ -733,7 +761,8 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid */ @Override public void removeSelectionChangedListener(ISelectionChangedListener listener) { - if (listener != null) selectionChangedListeners.remove(listener); + if (listener != null) + selectionChangedListeners.remove(listener); } /* (non-Javadoc) @@ -752,10 +781,13 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid public void setSelection(ISelection selection) { if (selection instanceof IStructuredSelection && !selection.isEmpty()) { // The first selection element which is a CTabItem will become the active item - Iterator iterator = ((IStructuredSelection)selection).iterator(); + Iterator iterator = ((IStructuredSelection) selection).iterator(); while (iterator.hasNext()) { Object candidate = iterator.next(); - if (candidate instanceof CTabItem) { bringToTop((CTabItem)candidate); return; } + if (candidate instanceof CTabItem) { + bringToTop((CTabItem) candidate); + return; + } } } // fire a changed event in any case @@ -781,7 +813,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid updateStatusLine(); CTabItem item = getActiveTabItem(); if (item != null && !item.isDisposed()) { - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); if (terminal != null && !terminal.isDisposed()) { fireSelectionChanged(new StructuredSelection(terminal.getSelection())); } @@ -810,7 +842,7 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid CTabItem item = getActiveTabItem(); if (item != null && !item.isDisposed()) { - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); if (terminal != null && !terminal.isDisposed()) { StringBuilder buffer = new StringBuilder(); @@ -839,21 +871,24 @@ public class TabFolderManager extends PlatformObject implements ISelectionProvid * @return The string representation. */ @SuppressWarnings("unchecked") - protected String state2msg(CTabItem item, TerminalState state) { + protected String state2msg(CTabItem item, TerminalState state) { Assert.isNotNull(item); Assert.isNotNull(state); // Determine the terminal properties of the tab folder - Map properties = (Map)item.getData("properties"); //$NON-NLS-1$ + Map properties = (Map) item.getData("properties"); //$NON-NLS-1$ // Get he current terminal state as string String stateStr = state.toString(); // Lookup a matching text representation of the state String key = "TabFolderManager_state_" + stateStr.replaceAll("\\.", " ").trim().toLowerCase(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String stateMsg = null; - if (properties != null) stateMsg = properties.get(key) instanceof String ? (String) properties.get(key) : null; - if (stateMsg == null) stateMsg = Messages.getString(key); - if (stateMsg == null) stateMsg = stateStr; + if (properties != null) + stateMsg = properties.get(key) instanceof String ? (String) properties.get(key) : null; + if (stateMsg == null) + stateMsg = Messages.getString(key); + if (stateMsg == null) + stateMsg = stateStr; return stateMsg; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java index 39c4e465e0b..4736ed651b4 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java @@ -54,8 +54,7 @@ public class TabFolderMenuHandler extends PlatformObject { private final List contextMenuActions = new ArrayList(); // The list of invalid context menu contributions "startsWith" expressions - /* default */ static final String[] INVALID_CONTRIBUTIONS_STARTS_WITH = { - "org.eclipse.cdt", "org.eclipse.ui.edit" //$NON-NLS-1$ //$NON-NLS-2$ + /* default */ static final String[] INVALID_CONTRIBUTIONS_STARTS_WITH = { "org.eclipse.cdt", "org.eclipse.ui.edit" //$NON-NLS-1$ //$NON-NLS-2$ }; /** @@ -89,7 +88,8 @@ public class TabFolderMenuHandler extends PlatformObject { * @param manager The menu manager or null */ private void removeInvalidContributions(IMenuManager manager) { - if (manager == null) return; + if (manager == null) + return; IContributionItem[] items = manager.getItems(); for (IContributionItem item : items) { @@ -132,7 +132,7 @@ public class TabFolderMenuHandler extends PlatformObject { * @return The tab folder or null. */ @SuppressWarnings("cast") - protected final CTabFolder getTabFolder() { + protected final CTabFolder getTabFolder() { return (CTabFolder) getParentView().getAdapter(CTabFolder.class); } @@ -141,9 +141,15 @@ public class TabFolderMenuHandler extends PlatformObject { */ public void dispose() { // Dispose the context menu - if (contextMenu != null) { contextMenu.dispose(); contextMenu = null; } + if (contextMenu != null) { + contextMenu.dispose(); + contextMenu = null; + } // Dispose the context menu manager - if (contextMenuManager != null) { contextMenuManager.dispose(); contextMenuManager = null; } + if (contextMenuManager != null) { + contextMenuManager.dispose(); + contextMenuManager = null; + } // Clear all actions contextMenuActions.clear(); } @@ -189,7 +195,8 @@ public class TabFolderMenuHandler extends PlatformObject { doFillContextMenu(contextMenuManager); // Register to the view site to open the menu for contributions - getParentView().getSite().registerContextMenu(contextMenuManager, getParentView().getSite().getSelectionProvider()); + getParentView().getSite().registerContextMenu(contextMenuManager, + getParentView().getSite().getSelectionProvider()); // Create and associated the menu listener contextMenuManager.addMenuListener(new MenuListener()); @@ -209,7 +216,7 @@ public class TabFolderMenuHandler extends PlatformObject { * Create the context menu actions. */ @SuppressWarnings("cast") - protected void doCreateContextMenuActions() { + protected void doCreateContextMenuActions() { // Create and add the copy action add(new TerminalActionCopy() { /* (non-Javadoc) @@ -224,7 +231,7 @@ public class TabFolderMenuHandler extends PlatformObject { // Create and add the paste action add(new TerminalActionPaste() { @SuppressWarnings({ "unchecked" }) - @Override + @Override public void run() { // Determine if pasting to the active tab require backslash translation boolean needsTranslation = false; @@ -234,10 +241,12 @@ public class TabFolderMenuHandler extends PlatformObject { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); if (activeTabItem != null) { - Map properties = (Map)activeTabItem.getData("properties"); //$NON-NLS-1$ - if (properties != null && properties.containsKey(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE)) { - Object value = properties.get(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE); - needsTranslation = value instanceof Boolean ? ((Boolean)value).booleanValue() : false; + Map properties = (Map) activeTabItem.getData("properties"); //$NON-NLS-1$ + if (properties != null && properties + .containsKey(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE)) { + Object value = properties + .get(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE); + needsTranslation = value instanceof Boolean ? ((Boolean) value).booleanValue() : false; } } } @@ -256,8 +265,9 @@ public class TabFolderMenuHandler extends PlatformObject { } } - super.run(); + super.run(); } + /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#getTarget() */ @@ -282,10 +292,10 @@ public class TabFolderMenuHandler extends PlatformObject { */ @Override public void updateAction(boolean aboutToShow) { - super.updateAction(aboutToShow); - if (getTarget() != null && getTarget().getState() != TerminalState.CONNECTED) { - setEnabled(false); - } + super.updateAction(aboutToShow); + if (getTarget() != null && getTarget().getState() != TerminalState.CONNECTED) { + setEnabled(false); + } } }); @@ -301,7 +311,7 @@ public class TabFolderMenuHandler extends PlatformObject { }); // Create and add the select encoding action - add (new SelectEncodingAction((TabFolderManager) getParentView().getAdapter(TabFolderManager.class)) { + add(new SelectEncodingAction((TabFolderManager) getParentView().getAdapter(TabFolderManager.class)) { /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#getTarget() */ @@ -318,7 +328,7 @@ public class TabFolderMenuHandler extends PlatformObject { * @return The currently active terminal control or null. */ @SuppressWarnings("cast") - protected ITerminalViewControl getActiveTerminalViewControl() { + protected ITerminalViewControl getActiveTerminalViewControl() { ITerminalViewControl terminal = null; // Get the active tab item from the tab folder manager @@ -327,7 +337,7 @@ public class TabFolderMenuHandler extends PlatformObject { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); if (activeTabItem != null) { - terminal = (ITerminalViewControl)activeTabItem.getData(); + terminal = (ITerminalViewControl) activeTabItem.getData(); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderToolbarHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderToolbarHandler.java index 017a87c1122..eee419d35d1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderToolbarHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderToolbarHandler.java @@ -38,7 +38,6 @@ import org.eclipse.tm.terminal.view.ui.interfaces.ITerminalsView; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; - /** * Terminal tab folder toolbar handler. */ @@ -67,10 +66,9 @@ public class TabFolderToolbarHandler extends PlatformObject { // The VlmConsoleTabFolderManager is listening to the selection changes of the // TabFolder and fires selection changed events. if (enable && event.getSource() instanceof TabFolderManager) { - enable = event.getSelection() instanceof StructuredSelection - && !event.getSelection().isEmpty() - && (((StructuredSelection)event.getSelection()).getFirstElement() instanceof CTabItem - || ((StructuredSelection)event.getSelection()).getFirstElement() instanceof String); + enable = event.getSelection() instanceof StructuredSelection && !event.getSelection().isEmpty() + && (((StructuredSelection) event.getSelection()).getFirstElement() instanceof CTabItem + || ((StructuredSelection) event.getSelection()).getFirstElement() instanceof String); } updateToolbarItems(enable); @@ -103,7 +101,7 @@ public class TabFolderToolbarHandler extends PlatformObject { * @return The tab folder or null. */ @SuppressWarnings("cast") - protected final CTabFolder getTabFolder() { + protected final CTabFolder getTabFolder() { return (CTabFolder) getParentView().getAdapter(CTabFolder.class); } @@ -113,7 +111,7 @@ public class TabFolderToolbarHandler extends PlatformObject { * @return The currently active terminal control or null. */ @SuppressWarnings("cast") - public ITerminalViewControl getActiveTerminalViewControl() { + public ITerminalViewControl getActiveTerminalViewControl() { ITerminalViewControl terminal = null; // Get the active tab item from the tab folder manager @@ -122,7 +120,7 @@ public class TabFolderToolbarHandler extends PlatformObject { // If we have the active tab item, we can get the active terminal control CTabItem activeTabItem = manager.getActiveTabItem(); if (activeTabItem != null && !activeTabItem.isDisposed()) { - terminal = (ITerminalViewControl)activeTabItem.getData(); + terminal = (ITerminalViewControl) activeTabItem.getData(); } } @@ -135,7 +133,8 @@ public class TabFolderToolbarHandler extends PlatformObject { public void dispose() { // Dispose the selection changed listener if (selectionChangedListener != null) { - getParentView().getViewSite().getSelectionProvider().removeSelectionChangedListener(selectionChangedListener); + getParentView().getViewSite().getSelectionProvider() + .removeSelectionChangedListener(selectionChangedListener); selectionChangedListener = null; } @@ -232,7 +231,7 @@ public class TabFolderToolbarHandler extends PlatformObject { }); // Create and add the scroll lock action - add (new TabScrollLockAction() { + add(new TabScrollLockAction() { /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#getTarget() */ @@ -257,15 +256,15 @@ public class TabFolderToolbarHandler extends PlatformObject { */ @Override public void updateAction(boolean aboutToShow) { - super.updateAction(aboutToShow); - if (getTarget() != null && getTarget().getState() != TerminalState.CONNECTED) { - setEnabled(false); - } + super.updateAction(aboutToShow); + if (getTarget() != null && getTarget().getState() != TerminalState.CONNECTED) { + setEnabled(false); + } } }); // Create and add the toggle command input field action - add (new ToggleCommandFieldAction(getParentView()) { + add(new ToggleCommandFieldAction(getParentView()) { /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#getTarget() */ @@ -276,7 +275,7 @@ public class TabFolderToolbarHandler extends PlatformObject { }); // Create and add the new terminal view action - add (new NewTerminalViewAction(getParentView()) { + add(new NewTerminalViewAction(getParentView()) { /* (non-Javadoc) * @see org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction#getTarget() */ @@ -308,19 +307,19 @@ public class TabFolderToolbarHandler extends PlatformObject { for (AbstractTerminalAction action : toolbarActions) { // Add a separator before the clear all action or if the action is a separator if (action instanceof TabScrollLockAction - || (action instanceof AbstractAction && ((AbstractAction)action).isSeparator())) { + || (action instanceof AbstractAction && ((AbstractAction) action).isSeparator())) { manager.insertAfter("anchor", new Separator()); //$NON-NLS-1$ } // skip new terminal view action for now - if (action instanceof NewTerminalViewAction){ - newTerminalAction = (NewTerminalViewAction)action; + if (action instanceof NewTerminalViewAction) { + newTerminalAction = (NewTerminalViewAction) action; continue; } // Add the action itself manager.insertAfter("anchor", action); //$NON-NLS-1$ } // now add to the end - if (newTerminalAction != null){ + if (newTerminalAction != null) { manager.add(newTerminalAction); } } @@ -340,8 +339,7 @@ public class TabFolderToolbarHandler extends PlatformObject { // Workaround by forcing the action to get disabled with setEnabled. if (control == null && !(action instanceof NewTerminalViewAction)) { action.setEnabled(false); - } - else { + } else { action.updateAction(enabled); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabTerminalListener.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabTerminalListener.java index 3dd5cb784d0..688602ffb93 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabTerminalListener.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabTerminalListener.java @@ -60,7 +60,8 @@ public class TabTerminalListener implements ITerminalListener2 { } private void attachTo(CTabItem item) { - if (tabItem != null) tabItem.setData(TAB_TERMINAL_LISTENER, null); + if (tabItem != null) + tabItem.setData(TAB_TERMINAL_LISTENER, null); item.setData(TAB_TERMINAL_LISTENER, this); tabItem = item; } @@ -81,7 +82,8 @@ public class TabTerminalListener implements ITerminalListener2 { public void setState(final TerminalState state) { // The tab item must have been not yet disposed final CTabItem item = getTabItem(); - if (item == null || item.isDisposed()) return; + if (item == null || item.isDisposed()) + return; // Run asynchronously in the display thread item.getDisplay().asyncExec(new Runnable() { @@ -89,7 +91,8 @@ public class TabTerminalListener implements ITerminalListener2 { public void run() { // Update the tab item title String newTitle = getTerminalConsoleTabTitle(state); - if (newTitle != null) item.setText(newTitle); + if (newTitle != null) + item.setText(newTitle); // Turn off the command field (if necessary) TabCommandFieldHandler handler = tabFolderManager.getTabCommandFieldHandler(item); @@ -123,7 +126,8 @@ public class TabTerminalListener implements ITerminalListener2 { // The tab item must have been not yet disposed CTabItem item = getTabItem(); - if (item == null || item.isDisposed()) return null; + if (item == null || item.isDisposed()) + return null; // Get the current tab title String oldTitle = item.getText(); @@ -132,12 +136,12 @@ public class TabTerminalListener implements ITerminalListener2 { String newTitle = null; if (TerminalState.CLOSED.equals(state)) { - newTitle = NLS.bind(Messages.TabTerminalListener_consoleClosed, tabItemTitle, tabFolderManager.state2msg(item, state)); - } - else if (TerminalState.CONNECTING.equals(state)) { - newTitle = NLS.bind(Messages.TabTerminalListener_consoleConnecting, tabItemTitle, tabFolderManager.state2msg(item, state)); - } - else if (TerminalState.CONNECTED.equals(state)) { + newTitle = NLS.bind(Messages.TabTerminalListener_consoleClosed, tabItemTitle, + tabFolderManager.state2msg(item, state)); + } else if (TerminalState.CONNECTING.equals(state)) { + newTitle = NLS.bind(Messages.TabTerminalListener_consoleConnecting, tabItemTitle, + tabFolderManager.state2msg(item, state)); + } else if (TerminalState.CONNECTED.equals(state)) { newTitle = tabItemTitle; } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/OldTerminalsViewHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/OldTerminalsViewHandler.java index bc02c4ad931..f39c74357e1 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/OldTerminalsViewHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/OldTerminalsViewHandler.java @@ -50,7 +50,7 @@ public class OldTerminalsViewHandler extends ViewPart { protected void replaceWithTerminalsView() { if (fReplaced) return; - IViewSite site = getViewSite(); + IViewSite site = getViewSite(); final IWorkbenchPage page = site.getPage(); site.getShell().getDisplay().asyncExec(new Runnable() { @@ -63,8 +63,8 @@ public class OldTerminalsViewHandler extends ViewPart { // Show the new view try { page.showView(IUIConstants.ID, null, IWorkbenchPage.VIEW_CREATE); - } - catch (PartInitException e) { /* ignored on purpose */ } + } catch (PartInitException e) { + /* ignored on purpose */ } // Hide ourself in the current perspective page.hideView(OldTerminalsViewHandler.this); @@ -79,18 +79,23 @@ public class OldTerminalsViewHandler extends ViewPart { replaceWithTerminalsView(); } } + @Override public void partOpened(IWorkbenchPartReference partRef) { } + @Override public void partInputChanged(IWorkbenchPartReference partRef) { } + @Override public void partHidden(IWorkbenchPartReference partRef) { } + @Override public void partDeactivated(IWorkbenchPartReference partRef) { } + @Override public void partClosed(IWorkbenchPartReference partRef) { if (partRef.getPart(false) == OldTerminalsViewHandler.this) { @@ -102,9 +107,11 @@ public class OldTerminalsViewHandler extends ViewPart { replaceWithTerminalsView(); } } + @Override public void partBroughtToTop(IWorkbenchPartReference partRef) { } + @Override public void partActivated(IWorkbenchPartReference partRef) { } @@ -112,7 +119,7 @@ public class OldTerminalsViewHandler extends ViewPart { } } }); - } + } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#setFocus() diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsView.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsView.java index d66fd3cf036..526cd10e4ce 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsView.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsView.java @@ -218,15 +218,19 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa @Override public void handleEvent(Event event) { // Only handle events where a CTabFolder is the source - if (!(event.widget instanceof CTabFolder)) return; + if (!(event.widget instanceof CTabFolder)) + return; // TabFolderManager must be created - if (tabFolderManager == null) return; + if (tabFolderManager == null) + return; // only for own tab folders - if (event.widget != tabFolderControl) return; + if (event.widget != tabFolderControl) + return; // Skip drag if DnD is still ongoing (bug 443787) - if (tabFolderControl.getData(DND.DRAG_SOURCE_KEY) != null) return; + if (tabFolderControl.getData(DND.DRAG_SOURCE_KEY) != null) + return; final CTabFolder draggedFolder = (CTabFolder) event.widget; @@ -280,8 +284,7 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // only if the drop target is different then the drag source if (TerminalTransfer.getInstance().getTabFolderManager() == tabFolderManager) { event.detail = DND.DROP_NONE; - } - else { + } else { event.detail = DND.DROP_MOVE; } } @@ -314,7 +317,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // dispose tab item control final Control control = draggedItem.getControl(); draggedItem.setControl(null); - if (control != null) control.dispose(); + if (control != null) + control.dispose(); // need to remove the dispose listener first DisposeListener disposeListener = (DisposeListener) draggedItem.getData("disposeListener"); //$NON-NLS-1$ @@ -357,8 +361,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa */ @Override public void init(IViewSite site, IMemento memento) throws PartInitException { - super.init(site, memento); - restoreState(memento); + super.init(site, memento); + restoreState(memento); } /* (non-Javadoc) @@ -433,7 +437,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa protected void doConfigurePageBookControl(PageBook pagebook) { Assert.isNotNull(pagebook); - if (getContextHelpId() != null) PlatformUI.getWorkbench().getHelpSystem().setHelp(pagebook, getContextHelpId()); + if (getContextHelpId() != null) + PlatformUI.getWorkbench().getHelpSystem().setHelp(pagebook, getContextHelpId()); } /** @@ -493,16 +498,18 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // Set the tab gradient coloring from the global preferences if (useGradientTabBackgroundColor()) { - tabFolder.setSelectionBackground(new Color[] { - JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$ - JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END") //$NON-NLS-1$ - }, new int[] { 100 }, true); + tabFolder.setSelectionBackground( + new Color[] { JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$ + JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END") //$NON-NLS-1$ + }, new int[] { 100 }, true); } // Apply the tab folder selection foreground color - tabFolder.setSelectionForeground(JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$ + tabFolder.setSelectionForeground( + JFaceResources.getColorRegistry().get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$ // Set the tab style from the global preferences - tabFolder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); + tabFolder.setSimple( + PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); // Attach the mouse listener tabFolder.addMouseListener(new MouseAdapter() { @@ -511,7 +518,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa if (e.button == 2) { // middle mouse button click - close tab CTabItem item = tabFolder.getItem(new Point(e.x, e.y)); - if (item != null) item.dispose(); + if (item != null) + item.dispose(); } } }); @@ -585,7 +593,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa */ @Override public void setFocus() { - if (pageBookControl != null) pageBookControl.setFocus(); + if (pageBookControl != null) + pageBookControl.setFocus(); } /* (non-Javadoc) @@ -593,8 +602,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa */ @Override public void switchToEmptyPageControl() { - if (pageBookControl != null && !pageBookControl.isDisposed() - && emptyPageControl != null && !emptyPageControl.isDisposed()) { + if (pageBookControl != null && !pageBookControl.isDisposed() && emptyPageControl != null + && !emptyPageControl.isDisposed()) { pageBookControl.showPage(emptyPageControl); } } @@ -604,8 +613,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa */ @Override public void switchToTabFolderControl() { - if (pageBookControl != null && !pageBookControl.isDisposed() - && tabFolderControl != null && !tabFolderControl.isDisposed()) { + if (pageBookControl != null && !pageBookControl.isDisposed() && tabFolderControl != null + && !tabFolderControl.isDisposed()) { pageBookControl.showPage(tabFolderControl); } } @@ -614,7 +623,7 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class) */ @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override + @Override public Object getAdapter(Class adapter) { if (CTabFolder.class.isAssignableFrom(adapter)) { return tabFolderControl; @@ -641,8 +650,9 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa @Override public void saveState(IMemento memento) { super.saveState(memento); - if (memento == null) return; - mementoHandler.saveState(this, memento); + if (memento == null) + return; + mementoHandler.saveState(this, memento); } /** @@ -651,7 +661,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa * @param memento The memento or null. */ public void restoreState(IMemento memento) { - if (memento == null) return; + if (memento == null) + return; mementoHandler.restoreState(this, memento); } @@ -659,7 +670,7 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext) */ @SuppressWarnings("cast") - @Override + @Override public boolean show(ShowInContext context) { if (context != null) { // Get the selection from the context @@ -673,7 +684,8 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // org.eclipse.egit.ui.internal.history.HistoryPageInput if ("org.eclipse.egit.ui.internal.history.HistoryPageInput".equals(input.getClass().getName())) { //$NON-NLS-1$ Bundle bundle = Platform.getBundle("org.eclipse.egit.ui"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { selection = GitShowInContextHandler.getSelection(input); } } @@ -686,48 +698,65 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // Build a new structured selection with the adapted elements List elements = new ArrayList(); - Iterator iterator = ((IStructuredSelection)selection).iterator(); + Iterator iterator = ((IStructuredSelection) selection).iterator(); while (iterator.hasNext() && isValid) { Object element = iterator.next(); Object adapted = null; if (element instanceof File) { - if (!elements.contains(element)) elements.add(element); + if (!elements.contains(element)) + elements.add(element); continue; } - adapted = element instanceof IAdaptable ? ((IAdaptable)element).getAdapter(File.class) : null; - if (adapted == null) adapted = Platform.getAdapterManager().getAdapter(element, File.class); - if (adapted == null) adapted = Platform.getAdapterManager().loadAdapter(element, File.class.getName()); + adapted = element instanceof IAdaptable ? ((IAdaptable) element).getAdapter(File.class) : null; + if (adapted == null) + adapted = Platform.getAdapterManager().getAdapter(element, File.class); + if (adapted == null) + adapted = Platform.getAdapterManager().loadAdapter(element, File.class.getName()); if (adapted != null) { - if (!elements.contains(adapted)) elements.add(adapted); + if (!elements.contains(adapted)) + elements.add(adapted); continue; } if (element instanceof IPath) { - if (!elements.contains(element)) elements.add(element); + if (!elements.contains(element)) + elements.add(element); continue; } - adapted = element instanceof IAdaptable ? ((IAdaptable)element).getAdapter(IPath.class) : null; - if (adapted == null) adapted = Platform.getAdapterManager().getAdapter(element, IPath.class); - if (adapted == null) adapted = Platform.getAdapterManager().loadAdapter(element, IPath.class.getName()); + adapted = element instanceof IAdaptable ? ((IAdaptable) element).getAdapter(IPath.class) : null; + if (adapted == null) + adapted = Platform.getAdapterManager().getAdapter(element, IPath.class); + if (adapted == null) + adapted = Platform.getAdapterManager().loadAdapter(element, IPath.class.getName()); if (adapted != null) { - if (!elements.contains(adapted)) elements.add(adapted); + if (!elements.contains(adapted)) + elements.add(adapted); continue; } Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { if (element instanceof org.eclipse.core.resources.IResource) { - if (!elements.contains(element)) elements.add(element); + if (!elements.contains(element)) + elements.add(element); continue; } - adapted = element instanceof IAdaptable ? ((IAdaptable)element).getAdapter(org.eclipse.core.resources.IResource.class) : null; - if (adapted == null) adapted = Platform.getAdapterManager().getAdapter(element, org.eclipse.core.resources.IResource.class); - if (adapted == null) adapted = Platform.getAdapterManager().loadAdapter(element, org.eclipse.core.resources.IResource.class.getName()); + adapted = element instanceof IAdaptable + ? ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class) + : null; + if (adapted == null) + adapted = Platform.getAdapterManager().getAdapter(element, + org.eclipse.core.resources.IResource.class); + if (adapted == null) + adapted = Platform.getAdapterManager().loadAdapter(element, + org.eclipse.core.resources.IResource.class.getName()); } if (adapted != null) { - if (!elements.contains(adapted)) elements.add(adapted); + if (!elements.contains(adapted)) + elements.add(adapted); continue; } @@ -735,12 +764,14 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // "org.eclipse.egit.ui.internal.repository.tree...." if (element.getClass().getName().startsWith("org.eclipse.egit.ui.internal.repository.tree")) { //$NON-NLS-1$ bundle = Platform.getBundle("org.eclipse.egit.ui"); //$NON-NLS-1$ - if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { + if (bundle != null && bundle.getState() != Bundle.UNINSTALLED + && bundle.getState() != Bundle.STOPPING) { adapted = GitShowInContextHandler.getPath(element); } } if (adapted != null) { - if (!elements.contains(adapted)) elements.add(adapted); + if (!elements.contains(adapted)) + elements.add(adapted); continue; } @@ -749,14 +780,18 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // If the selection is valid, fire the command to open the local terminal if (isValid) { - selection = new StructuredSelection(elements); - ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); - Command command = service != null ? service.getCommand("org.eclipse.tm.terminal.connector.local.command.launch") : null; //$NON-NLS-1$ + selection = new StructuredSelection(elements); + ICommandService service = (ICommandService) PlatformUI.getWorkbench() + .getService(ICommandService.class); + Command command = service != null + ? service.getCommand("org.eclipse.tm.terminal.connector.local.command.launch") //$NON-NLS-1$ + : null; if (command != null && command.isDefined() && command.isEnabled()) { try { ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null); Assert.isNotNull(pCmd); - IHandlerService handlerSvc = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); + IHandlerService handlerSvc = (IHandlerService) PlatformUI.getWorkbench() + .getService(IHandlerService.class); Assert.isNotNull(handlerSvc); IEvaluationContext ctx = handlerSvc.getCurrentState(); ctx = new EvaluationContext(ctx, selection); @@ -766,7 +801,7 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa // If the platform is in debug mode, we print the exception to the log view if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - Messages.AbstractTriggerCommandHandler_error_executionFailed, e); + Messages.AbstractTriggerCommandHandler_error_executionFailed, e); UIPlugin.getDefault().getLog().log(status); } } @@ -775,6 +810,6 @@ public class TerminalsView extends ViewPart implements ITerminalsView, IShowInTa } } } - return false; + return false; } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsViewMementoHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsViewMementoHandler.java index 7fed672f369..4bf1edac28f 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsViewMementoHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/TerminalsViewMementoHandler.java @@ -52,7 +52,7 @@ public class TerminalsViewMementoHandler { * @param memento The memento. Must not be null. */ @SuppressWarnings("unchecked") - public void saveState(TerminalsView view, IMemento memento) { + public void saveState(TerminalsView view, IMemento memento) { Assert.isNotNull(view); Assert.isNotNull(memento); @@ -69,16 +69,22 @@ public class TerminalsViewMementoHandler { // item to the memento for (CTabItem item : saveables) { // Ignore disposed items - if (item.isDisposed()) continue; + if (item.isDisposed()) + continue; // Get the original terminal properties associated with the tab item - Map properties = (Map)item.getData("properties"); //$NON-NLS-1$ - if (properties == null) continue; + Map properties = (Map) item.getData("properties"); //$NON-NLS-1$ + if (properties == null) + continue; // Get the terminal launcher delegate - String delegateId = (String)properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); - ILauncherDelegate delegate = delegateId != null ? LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false) : null; - IMementoHandler mementoHandler = delegate != null ? (IMementoHandler)delegate.getAdapter(IMementoHandler.class) : null; + String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); + ILauncherDelegate delegate = delegateId != null + ? LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false) + : null; + IMementoHandler mementoHandler = delegate != null + ? (IMementoHandler) delegate.getAdapter(IMementoHandler.class) + : null; if (mementoHandler != null) { // Create terminal connection child memento IMemento connectionMemento = memento.createChild("connection"); //$NON-NLS-1$ @@ -86,19 +92,23 @@ public class TerminalsViewMementoHandler { // Store the common attributes connectionMemento.putString(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId); - String terminalConnectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); + String terminalConnectorId = (String) properties + .get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); if (terminalConnectorId != null) { - connectionMemento.putString(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, terminalConnectorId); + connectionMemento.putString(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, + terminalConnectorId); } if (properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW) instanceof Boolean) { - connectionMemento.putBoolean(ITerminalsConnectorConstants.PROP_FORCE_NEW, ((Boolean)properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW)).booleanValue()); + connectionMemento.putBoolean(ITerminalsConnectorConstants.PROP_FORCE_NEW, + ((Boolean) properties.get(ITerminalsConnectorConstants.PROP_FORCE_NEW)).booleanValue()); } // Store the current encoding - ITerminalViewControl terminal = (ITerminalViewControl)item.getData(); + ITerminalViewControl terminal = (ITerminalViewControl) item.getData(); String encoding = terminal != null ? terminal.getEncoding() : null; - if (encoding == null || "".equals(encoding)) encoding = (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING); //$NON-NLS-1$ + if (encoding == null || "".equals(encoding)) //$NON-NLS-1$ + encoding = (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING); if (encoding != null && !"".equals(encoding)) { //$NON-NLS-1$ connectionMemento.putString(ITerminalsConnectorConstants.PROP_ENCODING, encoding); } @@ -125,7 +135,8 @@ public class TerminalsViewMementoHandler { // Read view id and secondary id String id = memento.getString("id"); //$NON-NLS-1$ String secondaryId = memento.getString("secondaryId"); //$NON-NLS-1$ - if ("null".equals(secondaryId)) secondaryId = null; //$NON-NLS-1$ + if ("null".equals(secondaryId)) //$NON-NLS-1$ + secondaryId = null; // Get all the "connection" memento's. IMemento[] connections = memento.getChildren("connection"); //$NON-NLS-1$ @@ -138,30 +149,38 @@ public class TerminalsViewMementoHandler { properties.put(ITerminalsConnectorConstants.PROP_SECONDARY_ID, secondaryId); // Restore the common attributes - properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, connection.getString(ITerminalsConnectorConstants.PROP_DELEGATE_ID)); - properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, connection.getString(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID)); + properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, + connection.getString(ITerminalsConnectorConstants.PROP_DELEGATE_ID)); + properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, + connection.getString(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID)); if (connection.getBoolean(ITerminalsConnectorConstants.PROP_FORCE_NEW) != null) { - properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, connection.getBoolean(ITerminalsConnectorConstants.PROP_FORCE_NEW)); + properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, + connection.getBoolean(ITerminalsConnectorConstants.PROP_FORCE_NEW)); } // Restore the encoding if (connection.getString(ITerminalsConnectorConstants.PROP_ENCODING) != null) { - properties.put(ITerminalsConnectorConstants.PROP_ENCODING, connection.getString(ITerminalsConnectorConstants.PROP_ENCODING)); + properties.put(ITerminalsConnectorConstants.PROP_ENCODING, + connection.getString(ITerminalsConnectorConstants.PROP_ENCODING)); } - // Get the terminal launcher delegate - String delegateId = (String)properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); - ILauncherDelegate delegate = delegateId != null ? LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false) : null; - IMementoHandler mementoHandler = delegate != null ? (IMementoHandler)delegate.getAdapter(IMementoHandler.class) : null; - if (mementoHandler != null) { - // Pass on to the memento handler - mementoHandler.restoreState(connection, properties); - } + // Get the terminal launcher delegate + String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID); + ILauncherDelegate delegate = delegateId != null + ? LauncherDelegateManager.getInstance().getLauncherDelegate(delegateId, false) + : null; + IMementoHandler mementoHandler = delegate != null + ? (IMementoHandler) delegate.getAdapter(IMementoHandler.class) + : null; + if (mementoHandler != null) { + // Pass on to the memento handler + mementoHandler.restoreState(connection, properties); + } - // Restore the terminal connection - if (delegate != null && !properties.isEmpty()) { - delegate.execute(properties, null); - } + // Restore the terminal connection + if (delegate != null && !properties.isEmpty()) { + delegate.execute(properties, null); + } } } } @@ -173,7 +192,8 @@ public class TerminalsViewMementoHandler { */ /* default */ void asyncExec(Runnable runnable) { Assert.isNotNull(runnable); - if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getDisplay() != null && !PlatformUI.getWorkbench().getDisplay().isDisposed()) { + if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getDisplay() != null + && !PlatformUI.getWorkbench().getDisplay().isDisposed()) { PlatformUI.getWorkbench().getDisplay().asyncExec(runnable); } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/showin/GitShowInContextHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/showin/GitShowInContextHandler.java index 4c398b2a328..16caadc4f05 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/showin/GitShowInContextHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/view/showin/GitShowInContextHandler.java @@ -33,7 +33,7 @@ public class GitShowInContextHandler { * @param input The input element. Must not be null. * @return The selection or null. */ - public static ISelection getSelection(Object input) { + public static ISelection getSelection(Object input) { Assert.isNotNull(input); List elements = new ArrayList(); @@ -67,21 +67,21 @@ public class GitShowInContextHandler { return elements.isEmpty() ? null : new StructuredSelection(elements); } - /** - * Returns the path of the given element. - * - * @param element The element. Must not be null. - * @return The path or null. - */ - public static IPath getPath(Object element) { - Assert.isNotNull(element); + /** + * Returns the path of the given element. + * + * @param element The element. Must not be null. + * @return The path or null. + */ + public static IPath getPath(Object element) { + Assert.isNotNull(element); - IPath path = null; + IPath path = null; - if (element instanceof org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) { - path = ((org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)element).getPath(); - } + if (element instanceof org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) { + path = ((org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) element).getPath(); + } - return path; - } + return path; + } }