1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

The port inheritable entry field does not remember the inheritable text because the text could not be set as it was rejected by the numeric verifier (the inheritable text is not all numeric).

This commit is contained in:
Kushal Munir 2006-09-29 22:38:45 +00:00
parent 25c9a9ed52
commit d94dace5b6
4 changed files with 150 additions and 15 deletions

View file

@ -20,27 +20,55 @@ import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
/**
* A class that only allows keys representing numeric values to be entered.
* A class that only allows keys representing numeric values to be entered. It can be turned off if necessary.
*/
public class SystemNumericVerifyListener implements VerifyListener {
private boolean isOff;
/**
* Constructor. The verifier is on by default.
*/
public SystemNumericVerifyListener() {
isOff = false;
}
/**
* Verifies the event text if it is not turned off.
* @see org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse.swt.events.VerifyEvent)
*/
public void verifyText(VerifyEvent e) {
String text = e.text;
boolean doit = true;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (!Character.isDigit(c)) {
doit = false;
break;
if (!isOff) {
String text = e.text;
boolean doit = true;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (!Character.isDigit(c)) {
doit = false;
break;
}
}
e.doit = doit;
}
e.doit = doit;
}
/**
* Turns the verifier on or off.
* @param isOff <code>true</code> to turn the verifier off, <code>false</code> to turn it on.
*/
public void setOff(boolean isOff) {
this.isOff = isOff;
}
/**
* Returns whether the verifier is on or off.
* @return <code>true</code> if the verifier is off, <code>false</code> if it is on.
*/
public boolean isOff() {
return isOff;
}
}

View file

@ -0,0 +1,31 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation. 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.ui.widgets;
/**
* Any listener that wants to be notified of state changes to the inheritable
* entry field widget must implement this interface.
*/
public interface IInheritableEntryFieldStateChangeListener {
/**
* Called when the state of the inheritable field has changed. The new state of the field can be queried by calling
* <code>isLocal</code> on on the entry field.
* @param field the inheritable field which has changed state.
*/
public void stateChanged(InheritableEntryField field);
}

View file

@ -16,6 +16,10 @@
package org.eclipse.rse.ui.widgets;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
@ -57,6 +61,7 @@ public class InheritableEntryField extends Composite implements KeyListener {
private String localValue = "";
private boolean isLocal = true;
private boolean allowEditOfInherited = false;
private List listeners;
/**
* Constructor
@ -88,6 +93,10 @@ public class InheritableEntryField extends Composite implements KeyListener {
*/
public InheritableEntryField(Composite parent, int style, int buttonStyle, int textStyle, boolean showToggleButton) {
super(parent, style);
// must initialize list of listeners before anything else
listeners = new Vector();
prepareComposite(2);
if (showToggleButton) {
createToggleButton(this, buttonStyle);
@ -103,6 +112,11 @@ public class InheritableEntryField extends Composite implements KeyListener {
public void setLocal(boolean local) {
boolean wasLocal = isLocal;
isLocal = local;
if (isLocal != wasLocal) {
notifyStateChangeListeners();
}
if (isLocal) { // from inherit to local
if (allowEditOfInherited && !wasLocal) inheritValue = entryField.getText();
entryField.setEnabled(true);
@ -342,4 +356,35 @@ public class InheritableEntryField extends Composite implements KeyListener {
setLocal(true);
}
}
/**
* Adds a state change listener. If the listener was already added, it will not be added again.
* @param l the listener to add.
*/
public void addStateChangeListener(IInheritableEntryFieldStateChangeListener l) {
if (!listeners.contains(l)) {
listeners.add(l);
}
}
/**
* Removes a state change listener.
* @param l the listener to remove.
*/
public void removeStateChangeListener(IInheritableEntryFieldStateChangeListener l) {
listeners.remove(l);
}
/**
* Notifies all state change listeners.
*/
private void notifyStateChangeListeners() {
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
IInheritableEntryFieldStateChangeListener listener = (IInheritableEntryFieldStateChangeListener)(iter.next());
listener.stateChanged(this);
}
}
}

View file

@ -57,7 +57,37 @@ public class SystemPortPrompt
// validators
protected ISystemValidator portValidator;
// Inputs from caller
protected ISystemMessageLine msgLine;
protected ISystemMessageLine msgLine;
/**
* A listener for state changes to the port entry inheritable field.
*/
private class PortFieldStateChangeListener implements IInheritableEntryFieldStateChangeListener {
private SystemNumericVerifyListener verifyListener;
/**
* Constructor.
* @param verifyListener the verify listener for the port field.
*/
private PortFieldStateChangeListener(SystemNumericVerifyListener verifyListener) {
this.verifyListener = verifyListener;
}
/**
* Turns the verifier off if the state of the inheritable entry field is not local, turns it on otherwise.
* @see org.eclipse.rse.ui.widgets.IInheritableEntryFieldStateChangeListener#stateChanged(org.eclipse.rse.ui.widgets.InheritableEntryField)
*/
public void stateChanged(InheritableEntryField field) {
if (field.isLocal()) {
verifyListener.setOff(false);
}
else {
verifyListener.setOff(true);
}
}
}
/**
* Constructor when you want a new composite to hold the child controls
@ -258,8 +288,9 @@ public class SystemPortPrompt
}
});
textPort.getTextField().addVerifyListener(new SystemNumericVerifyListener());
//textPort.addSelectionListener(this); Removed for defect 44132
SystemNumericVerifyListener verifyListener = new SystemNumericVerifyListener();
textPort.getTextField().addVerifyListener(verifyListener);
textPort.addStateChangeListener(new PortFieldStateChangeListener(verifyListener));
}
}