mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Terminal: Add control decorations for SSH and Telnet settings panel. Updated the corresponding validateSettings() implementations to use the control decorations and give a hint to the user what is missing or wrong.
This commit is contained in:
parent
3d1e94ee3c
commit
b13053defb
4 changed files with 174 additions and 13 deletions
|
@ -13,6 +13,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.ssh;
|
||||
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
|
@ -60,34 +62,66 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
return value;
|
||||
}
|
||||
public boolean validateSettings() {
|
||||
String message = null;
|
||||
int messageType = IMessageProvider.NONE;
|
||||
boolean valid = true;
|
||||
|
||||
if (fHostText.getText().trim().length() == 0) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
if (fUser.getText().trim().length() == 0) {
|
||||
return false;
|
||||
String m = "Please enter a username."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.INFORMATION;
|
||||
updateControlDecoration(fHostText, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
try {
|
||||
int p = Integer.parseInt(fPort.getText().trim());
|
||||
if (p <= 0 || p > 65535) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
p = Integer.parseInt(fTimeout.getText().trim());
|
||||
if (p < 0) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
p = Integer.parseInt(fKeepalive.getText().trim());
|
||||
if (p < 0) {
|
||||
return false;
|
||||
String m = "Invalid keep alive. Must be greater than 0."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fTimeout, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
valid = false;
|
||||
}
|
||||
return true;
|
||||
|
||||
setMessage(message, messageType);
|
||||
return valid;
|
||||
}
|
||||
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);
|
||||
gridData.horizontalIndent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
|
||||
|
||||
composite.setLayout(gridLayout);
|
||||
composite.setLayoutData(gridData);
|
||||
|
@ -116,6 +150,7 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
fireListeners(text);
|
||||
}
|
||||
});
|
||||
createControlDecoration(text);
|
||||
return text;
|
||||
}
|
||||
private Text createTextField(Composite composite, String labelTxt) {
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
|
@ -93,28 +95,53 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
}
|
||||
|
||||
public boolean validateSettings() {
|
||||
String message = null;
|
||||
int messageType = IMessageProvider.NONE;
|
||||
boolean valid = true;
|
||||
|
||||
if (fHostText.getText().trim().length() == 0) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
|
||||
try {
|
||||
int p = Integer.parseInt(getNetworkPort().trim());
|
||||
if (p <= 0 || p > 65535) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
|
||||
p = Integer.parseInt(fTimeout.getText().trim());
|
||||
if (p < 0) {
|
||||
return false;
|
||||
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; }
|
||||
|
||||
valid = false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
valid = false;
|
||||
}
|
||||
return true;
|
||||
|
||||
setMessage(message, messageType);
|
||||
return valid;
|
||||
}
|
||||
|
||||
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);
|
||||
gridData.horizontalIndent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
|
||||
|
||||
composite.setLayout(gridLayout);
|
||||
composite.setLayoutData(gridData);
|
||||
|
@ -132,6 +159,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
fireListeners(fHostText);
|
||||
}
|
||||
});
|
||||
createControlDecoration(fHostText);
|
||||
|
||||
// Add label
|
||||
ctlLabel = new Label(composite, SWT.RIGHT);
|
||||
|
@ -151,6 +179,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
fireListeners(fNetworkPortCombo);
|
||||
}
|
||||
});
|
||||
createControlDecoration(fNetworkPortCombo);
|
||||
|
||||
List table = getNetworkPortMap().getNameTable();
|
||||
Collections.sort(table);
|
||||
|
@ -164,6 +193,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
fireListeners(fTimeout);
|
||||
}
|
||||
});
|
||||
createControlDecoration(fTimeout);
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ package org.eclipse.tm.internal.terminal.provisional.api;
|
|||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.fieldassist.ControlDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +31,9 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
// Reference to the listener
|
||||
private final ListenerList listeners = new ListenerList();
|
||||
|
||||
// Flag to control the control decorations
|
||||
private boolean hasDecoration = false;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#addListener(org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage.Listener)
|
||||
*/
|
||||
|
@ -81,4 +88,94 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
this.message = message;
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if or if not the settings panel widgets will have control decorations
|
||||
* or not. The method has effect only if called before {@link #createControl(org.eclipse.swt.widgets.Composite)}.
|
||||
*
|
||||
* @param value <code>True</code> if the panel widgets have control decorations, <code>false</code> otherwise.
|
||||
*/
|
||||
public final void setHasControlDecoration(boolean value) {
|
||||
this.hasDecoration = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if or if not the settings panel widgets will have control
|
||||
* decorations or not.
|
||||
*
|
||||
* @return <code>True</code> if the panel widgets have control decorations, <code>false</code> otherwise.
|
||||
*/
|
||||
protected final boolean hasControlDecoration() {
|
||||
return hasDecoration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a {@link ControlDecoration} object associated with
|
||||
* the given control. The method is called after the control has been created.
|
||||
*
|
||||
* @param control The control. Must not be <code>null</code>.
|
||||
* @return The control decoration object instance.
|
||||
*/
|
||||
protected final ControlDecoration createControlDecoration(Control control) {
|
||||
Assert.isNotNull(control);
|
||||
if (!hasDecoration) return null;
|
||||
ControlDecoration controlDecoration = new ControlDecoration(control, getControlDecorationPosition());
|
||||
controlDecoration.setShowOnlyOnFocus(false);
|
||||
control.setData("controlDecoration", controlDecoration); //$NON-NLS-1$
|
||||
return controlDecoration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the control decoration position. The default is
|
||||
* {@link SWT#TOP} | {@link SWT#LEFT}.
|
||||
*
|
||||
* @return The control position.
|
||||
*/
|
||||
protected int getControlDecorationPosition() {
|
||||
return SWT.TOP | SWT.LEFT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the control decoration of the given control to represent the given message
|
||||
* and message type. If the message is <code>null</code> or the message type is
|
||||
* {@link IMessageProvider#NONE} no decoration will be shown.
|
||||
*
|
||||
* @param control The control. Must not be <code>null</code>.
|
||||
* @param message The message.
|
||||
* @param messageType The message type.
|
||||
*/
|
||||
protected final void updateControlDecoration(Control control, String message, int messageType) {
|
||||
Assert.isNotNull(control);
|
||||
|
||||
ControlDecoration controlDecoration = (ControlDecoration)control.getData("controlDecoration"); //$NON-NLS-1$
|
||||
if (controlDecoration != null) {
|
||||
// The description is the same as the message
|
||||
controlDecoration.setDescriptionText(message);
|
||||
|
||||
// The icon depends on the message type
|
||||
FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
|
||||
|
||||
// Determine the id of the decoration to show
|
||||
String decorationId = FieldDecorationRegistry.DEC_INFORMATION;
|
||||
if (messageType == IMessageProvider.ERROR) {
|
||||
decorationId = FieldDecorationRegistry.DEC_ERROR;
|
||||
} else if (messageType == IMessageProvider.WARNING) {
|
||||
decorationId = FieldDecorationRegistry.DEC_WARNING;
|
||||
}
|
||||
|
||||
// Get the field decoration
|
||||
FieldDecoration fieldDeco = registry.getFieldDecoration(decorationId);
|
||||
if (fieldDeco != null) {
|
||||
controlDecoration.setImage(fieldDeco.getImage());
|
||||
}
|
||||
|
||||
if (message == null || messageType == IMessageProvider.NONE) {
|
||||
controlDecoration.hide();
|
||||
}
|
||||
else {
|
||||
controlDecoration.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.swt.widgets.Control;
|
|||
/**
|
||||
* @author Michael Scharf
|
||||
*
|
||||
* TODO: Michael Scharf: provide a mechanism to set an error string
|
||||
* TODO: Michael Scharf: provide a long description of a wizard
|
||||
* TODO: Michael Scharf: allow multiple pages to be generated
|
||||
* <p>
|
||||
|
|
Loading…
Add table
Reference in a new issue