Skip to content

Commit

Permalink
TEIIDDES-1331 Host field of Teiid Server Properties dialog should val…
Browse files Browse the repository at this point in the history
…idate only when focus is shifted to another field

git-svn-id: http://anonsvn.jboss.org/repos/tdesigner/branches/7.4.x@2587 ceac5f5e-c25f-0410-8b95-ec8c2776e4a6
  • Loading branch information
jolee committed May 24, 2012
1 parent 1d3b4b3 commit 858e6e5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ serverPageSetAsDefaultLabel = Set as default Teiid instance on 'Finish'
serverPageSetAsDefaultToolTip = Auto-connect and set this new Teiid server instance as default on 'Finish'.\n\n\
All Preview Data, Deploy VDB and Execute VDB operations will be performed against the default Teiid Instance.
serverPageExistingServerUrl = Server with URL [{0}] already exists
serverPageUnknownHost = Server with hostname [{0}] cannot be contacted
serverPageAdminConnectionInfoLabel = Teiid Admin Connection Info
serverPageHostNameLabel = Host:
serverPageHostNameTooltip = Enter valid host name for Teiid Server connection URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

import static com.metamatrix.modeler.dqp.ui.DqpUiConstants.PLUGIN_ID;
import static com.metamatrix.modeler.dqp.ui.DqpUiConstants.UTIL;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand All @@ -17,7 +21,8 @@
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
Expand Down Expand Up @@ -246,14 +251,9 @@ private void constructHostPanel( Composite parent ) {
text.setToolTipText(UTIL.getString("serverPageHostNameTooltip")); //$NON-NLS-1$
text.setText(this.host);

text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
text.addFocusListener(new FocusAdapter() {
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleHostModified(((Text) e.widget).getText());
}
});
Expand Down Expand Up @@ -283,14 +283,9 @@ public void modifyText( ModifyEvent e ) {
txtCustomLabel.setEnabled(this.useCustomLabel);
txtCustomLabel.setText((this.customLabel == null) ? "" : this.customLabel); //$NON-NLS-1$

txtCustomLabel.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
txtCustomLabel.addFocusListener(new FocusAdapter() {
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleCustomLabelModified(((Text) e.widget).getText());
}
});
Expand Down Expand Up @@ -332,14 +327,9 @@ private void constructTeiidAdminConnectionPanel( Composite parent ) {
text.setText(this.adminPort);
}

text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
text.addFocusListener(new FocusAdapter() {
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleAdminPortModified(((Text) e.widget).getText());
}
});
Expand All @@ -365,16 +355,11 @@ public void modifyText( ModifyEvent e ) {
text.setText(this.adminUsername);
}

text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
@Override
public void modifyText( ModifyEvent e ) {
handleAdminUserModified(((Text) e.widget).getText());
}
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
handleAdminUserModified(((Text) e.widget).getText());
}
});

{
Expand All @@ -399,15 +384,9 @@ public void modifyText( ModifyEvent e ) {
text.setText(this.adminPassword);
}

// listener for when value changes
text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
text.addFocusListener(new FocusAdapter() {
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleAdminPasswordModified(((Text) e.widget).getText());
}
});
Expand Down Expand Up @@ -559,14 +538,14 @@ private void constructTeiidJdbcConnectionPanel( Composite parent ) {
text.setText(this.jdbcPort);
}

text.addModifyListener(new ModifyListener() {
text.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleJdbcPortModified(((Text) e.widget).getText());
}
});
Expand All @@ -591,14 +570,9 @@ public void modifyText( ModifyEvent e ) {
text.setText(this.jdbcUsername);
}

text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
@Override
public void modifyText( ModifyEvent e ) {
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
handleJdbcUserModified(((Text) e.widget).getText());
}
});
Expand Down Expand Up @@ -626,14 +600,9 @@ public void modifyText( ModifyEvent e ) {
}

// listener for when value changes
text.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
text.addFocusListener(new FocusAdapter() {
@Override
public void modifyText( ModifyEvent e ) {
public void focusLost(FocusEvent e) {
handleJdbcPasswordModified(((Text) e.widget).getText());
}
});
Expand Down Expand Up @@ -768,13 +737,25 @@ ServerManager getServerManager() {
void handleAutoConnect() {
this.autoConnect = this.btnAutoConnectOnFinish.getSelection();
}

/**
* @param oldValue
* @param newValue
* @return
*/
private boolean valueChanged(String oldValue, String newValue) {
return oldValue == null || ! oldValue.equals(newValue);
}

/**
* Handler for when the password control value is modified
*
* @param newPassword the new password value
*/
void handleAdminPasswordModified( String newPassword ) {
if (! valueChanged(this.adminPassword, newPassword)) {
return;
}
this.adminPassword = newPassword;
this.localAdminInfo.setPassword(newPassword);
updateState();
Expand All @@ -793,12 +774,19 @@ void handleAdminSavePasswordChanged( boolean savePassword ) {
* @param newPort the new host value
*/
void handleAdminPortModified( String newPort ) {
this.adminPort = newPort;
if (! valueChanged(this.adminPort, newPort)) {
return;
}

this.adminPort = newPort;
this.localAdminInfo.setPort(newPort);
updateState();
}

void handleCustomLabelModified( String newCustomLabel ) {
if (! valueChanged(this.customLabel, newCustomLabel)) {
return;
}
this.customLabel = newCustomLabel.trim();
updateState();
}
Expand All @@ -807,7 +795,11 @@ void handleCustomLabelModified( String newCustomLabel ) {
* @param newHost the new host value
*/
void handleHostModified( String newHost ) {
this.host = newHost;
if (! valueChanged(this.host, newHost)) {
return;
}

this.host = newHost;
updateState();
}

Expand All @@ -817,6 +809,9 @@ void handleHostModified( String newHost ) {
* @param newPassword the new password value
*/
void handleJdbcPasswordModified( String newPassword ) {
if (! valueChanged(this.jdbcPassword, newPassword)) {
return;
}
this.jdbcPassword = newPassword;
this.localJdbcInfo.setPassword(newPassword);
updateState();
Expand All @@ -835,7 +830,11 @@ void handleJdbcSavePasswordChanged( boolean savePassword ) {
* @param newPort the new host value
*/
void handleJdbcPortModified( String newPort ) {
this.jdbcPort = newPort;
if (! valueChanged(this.jdbcPort, newPort)) {
return;
}

this.jdbcPort = newPort;
this.localJdbcInfo.setPort(newPort);
updateState();
}
Expand Down Expand Up @@ -878,6 +877,9 @@ public void run() {
* @param newUser the new user value
*/
void handleAdminUserModified( String newUser ) {
if (! valueChanged(this.adminUsername, newUser)) {
return;
}
this.adminUsername = newUser;
this.localAdminInfo.setUsername(newUser);
updateState();
Expand All @@ -900,6 +902,9 @@ void handleAdminSSLChanged( boolean isSecure ) {
* @param newUser the new user value
*/
void handleJdbcUserModified( String newUser ) {
if (! valueChanged(this.jdbcUsername, newUser)) {
return;
}
this.jdbcUsername = newUser;
this.localJdbcInfo.setUsername(newUser);
updateState();
Expand Down Expand Up @@ -981,6 +986,17 @@ private void updateState() {
* Validates all inputs and sets the validation status.
*/
private void validate() {

// Validate that we have a known host
try {
InetAddress.getByName(this.host);
} catch (UnknownHostException ex) {
this.status = new Status(IStatus.ERROR,
DqpUiConstants.PLUGIN_ID,
UTIL.getString("serverPageUnknownHost", this.host)); //$NON-NLS-1$
return;
}

// validate admin connection info
this.status = this.localAdminInfo.validate();

Expand Down Expand Up @@ -1026,11 +1042,22 @@ private void validate() {
this.status = new Status(IStatus.ERROR, PLUGIN_ID, UTIL.getString("serverPageEmptyCustomLabelMsg")); //$NON-NLS-1$
}
}

/* (non-Javadoc)
* @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
*/
@Override
public boolean isPageComplete() {
return IStatus.OK == this.status.getSeverity();
}

/**
* Processing done after wizard 'Finish' button is clicked. Wizard was not canceled.
*/
void performFinish() {
if (! isPageComplete()) {
return;
}
// update dialog settings
getDialogSettings().put(AUTO_CONNECT_KEY, this.autoConnect);
// If editing, set local server info values to the original server info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ protected ServerManager getServerManager() {
*/
@Override
public boolean performFinish() {
if (! this.page.isPageComplete()) {
return false;
}
// first let page know that wizard finished and was not canceled
this.page.performFinish();

Expand Down

0 comments on commit 858e6e5

Please sign in to comment.