1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

[206917][terminal] Add validation for Terminal Settings

This commit is contained in:
Martin Oberhuber 2008-07-15 22:40:47 +00:00
parent af5bab0e12
commit 1c0e35b1ab
8 changed files with 79 additions and 19 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2003, 2008 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 v1.0
* which accompanies this distribution, and is available at
@ -11,8 +11,9 @@
* Helmut Haigermoser and Ted Williams.
*
* Contributors:
* Michael Scharf (Wind River) - extracted from TerminalSettingsDlg
* Michael Scharf (Wind River) - extracted from TerminalSettingsDlg
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
*******************************************************************************/
package org.eclipse.tm.internal.terminal.serial;
@ -91,11 +92,11 @@ public class SerialSettingsPage implements ISettingsPage {
nIndex = combo.indexOf(value);
} else {
return;
}
}
}
combo.select(nIndex);
}
private String getComboValue(Combo combo) {
int nIndex = combo.getSelectionIndex();
@ -106,9 +107,17 @@ public class SerialSettingsPage implements ISettingsPage {
}
return combo.getItem(nIndex);
}
public boolean validateSettings() {
try {
int p = Integer.parseInt(fTimeout.getText().trim());
if (p < 0) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
public void createControl(Composite parent) {

View file

@ -1,14 +1,15 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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
* Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
*******************************************************************************/
package org.eclipse.tm.internal.terminal.ssh;
@ -57,6 +58,28 @@ public class SshSettingsPage implements ISettingsPage {
return value;
}
public boolean validateSettings() {
if (fHostText.getText().trim().length() == 0) {
return false;
}
if (fUser.getText().trim().length() == 0) {
return false;
}
try {
int p = Integer.parseInt(fPort.getText().trim());
if (p <= 0 || p > 65535) {
return false;
}
p = Integer.parseInt(fTimeout.getText().trim());
if (p < 0) {
return false;
}
p = Integer.parseInt(fKeepalive.getText().trim());
if (p < 0) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
public void createControl(Composite parent) {
@ -84,7 +107,7 @@ public class SshSettingsPage implements ISettingsPage {
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
Text text= new Text(composite, SWT.BORDER | textOptions);
Text text= new Text(composite, SWT.BORDER | textOptions);
text.setLayoutData(gridData);
return text;
}

View file

@ -2,7 +2,7 @@
<feature
id="org.eclipse.tm.terminal.telnet"
label="%featureName"
version="2.0.0.qualifier"
version="2.0.1.qualifier"
provider-name="%providerName">
<description>

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.telnet;singleton:=true
Bundle-Version: 2.0.0.qualifier
Bundle-Version: 2.0.1.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2003, 2008 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 v1.0
* which accompanies this distribution, and is available at
@ -11,8 +11,9 @@
* Helmut Haigermoser and Ted Williams.
*
* Contributors:
* Michael Scharf (Wind River) - extracted from TerminalSettingsDlg
* Michael Scharf (Wind River) - extracted from TerminalSettingsDlg
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
*******************************************************************************/
package org.eclipse.tm.internal.terminal.telnet;
@ -55,13 +56,13 @@ public class TelnetSettingsPage implements ISettingsPage {
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$
fTimeout.setText(timeout);
}
private void setNetworkPort(String strNetworkPort) {
if (strNetworkPort!=null) {
@ -88,8 +89,24 @@ public class TelnetSettingsPage implements ISettingsPage {
}
public boolean validateSettings() {
if (fHostText.getText().trim().length() == 0) {
return false;
}
try {
int p = Integer.parseInt(getNetworkPort().trim());
if (p <= 0 || p > 65535) {
return false;
}
p = Integer.parseInt(fTimeout.getText().trim());
if (p < 0) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);

View file

@ -17,6 +17,7 @@
* Martin Oberhuber (Wind River) - [168186] Add Terminal User Docs
* Michael Scharf (Wind River) - [196454] Initial connection settings dialog should not be blank
* Michael Scharf (Wind River) - [240023] Get rid of the terminal's "Pin" button
* Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
*******************************************************************************/
package org.eclipse.tm.internal.terminal.view;
@ -148,8 +149,14 @@ class TerminalSettingsDlg extends Dialog {
}
protected void okPressed() {
if (!validateSettings())
if (!validateSettings()) {
String strTitle = ViewMessages.TERMINALSETTINGS;
MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(strTitle);
mb.setMessage(ViewMessages.INVALID_SETTINGS);
mb.open();
return;
}
if(fSelectedConnector>=0) {
getPage(fSelectedConnector).saveSettings();
}

View file

@ -14,6 +14,7 @@
* Michael Scharf (Wind River) - split into core, view and connector plugins
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Michael Scharf (Wind River) - [240023] Get rid of the terminal's "Pin" button
* Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
*******************************************************************************/
package org.eclipse.tm.internal.terminal.view;
@ -33,6 +34,7 @@ public class ViewMessages extends NLS {
public static String CONNECTIONTYPE;
public static String VIEW_TITLE;
public static String VIEW_SETTINGS;
public static String INVALID_SETTINGS;
public static String INVERT_COLORS;
public static String BUFFERLINES;

View file

@ -14,6 +14,7 @@
# Michael Scharf (Wind River) - split into core, view and connector plugins
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
# Michael Scharf (Wind River) - [240023] Get rid of the terminal's "Pin" button
# Martin Oberhuber (Wind River) - [206917] Add validation for Terminal Settings
###############################################################################
NO_CONNECTION_SELECTED = No Connection Selected
PROP_TITLE = Terminal
@ -25,6 +26,7 @@ NEW_TERMINAL_VIEW = New Terminal View
CONNECTIONTYPE = Connection Type
VIEW_TITLE = View Title:
VIEW_SETTINGS = View Settings:
INVALID_SETTINGS = The specified settings are invalid, please review or cancel.
INVERT_COLORS = Invert terminal colors
BUFFERLINES = Terminal buffer lines: