Skip to content

Commit

Permalink
TEIIDDES-2464 Teiid Connection Profile improvements
Browse files Browse the repository at this point in the history
 * Added server version text field with validaiton
 * Setting initial version to installed default version
 * Removed the auto-selection of the Driver which may have contained a
Preview VDB driver properties (preview vdb etc...)
 * Fixed minor layout issue with Teiid Server version preference combo
box
 * removed the 8.8 Teiid version enum value. Should not have been in
9.0.x
  • Loading branch information
blafond committed Apr 7, 2015
1 parent a04b2f6 commit 0aa486b
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.print.attribute.standard.Severity;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCConnectionProfileConstants;
import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants;
Expand All @@ -25,6 +29,7 @@
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
Expand All @@ -34,6 +39,7 @@
import org.teiid.datatools.connectivity.ConnectivityUtil;
import org.teiid.datatools.connectivity.TeiidJDBCConnection;
import org.teiid.datatools.connectivity.TeiidServerJDBCURL;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;

/**
* @since 8.0
Expand All @@ -42,6 +48,8 @@ public class TeiidDriverUIContributor implements IDriverUIContributor, Listener

protected String VDB_LBL_UI_ = Messages.getString("TeiidDriverUIContributor.VDB_LBL_UI_"); //$NON-NLS-1$

private static final String SERVER_VERSION_LBL_UI_ = Messages.getString("TeiidDriverUIContributor.SERVER_VERSION_LBL_UI_"); //$NON-NLS-1$

private static final String HOST_LBL_UI_ = Messages.getString("TeiidDriverUIContributor.HOST_LBL_UI_"); //$NON-NLS-1$

private static final String PORT_LBL_UI_ = Messages.getString("TeiidDriverUIContributor.PORT_LBL_UI_"); //$NON-NLS-1$
Expand Down Expand Up @@ -76,6 +84,10 @@ public class TeiidDriverUIContributor implements IDriverUIContributor, Listener

private static final String FALSE_SUMMARY_DATA_TEXT_ = Messages.getString("TeiidDriverUIContributor.summary.false"); //$NON-NLS-1$

private Label serverVersionLabel;

private Text serverVersionText;

private Label databaseLabel;

private Text databaseText;
Expand Down Expand Up @@ -107,6 +119,8 @@ public class TeiidDriverUIContributor implements IDriverUIContributor, Listener
private Label urlLabel;

private Text urlText;

private Text validationMessageText;

private DialogPage parentPage;

Expand All @@ -119,7 +133,7 @@ public class TeiidDriverUIContributor implements IDriverUIContributor, Listener
private Properties properties;

private boolean isReadOnly = false;

@Override
public Composite getContributedDriverUI( Composite parent,
boolean isReadOnly ) {
Expand All @@ -144,67 +158,80 @@ public Composite getContributedDriverUI( Composite parent,
generalTab.setText(ConnectivityUIPlugin.getDefault().getResourceString("CommonDriverUIContributor.generaltab")); //$NON-NLS-1$

Composite baseComposite = new Composite(tabComposite, SWT.NULL);
GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(baseComposite);
GridLayoutFactory.fillDefaults().numColumns(3).margins(5, 5).applyTo(baseComposite);
generalTab.setControl(baseComposite);


validationMessageText = new Text(baseComposite, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP );
validationMessageText.setBackground(parent.getBackground());
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.BEGINNING).
grab(true, false).hint(190, 20).applyTo(
validationMessageText);

serverVersionLabel = new Label(baseComposite, SWT.NONE);
serverVersionLabel.setText(SERVER_VERSION_LBL_UI_);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(serverVersionLabel);

serverVersionText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(serverVersionText);

databaseLabel = new Label(baseComposite, SWT.NONE);
databaseLabel.setText(VDB_LBL_UI_);
GridDataFactory.fillDefaults().span(2, 1).applyTo(databaseLabel);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(databaseLabel);

databaseText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(databaseText);

hostLabel = new Label(baseComposite, SWT.NONE);
hostLabel.setText(HOST_LBL_UI_);
GridDataFactory.fillDefaults().span(2, 1).applyTo(hostLabel);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(hostLabel);

hostText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(hostText);

portLabel = new Label(baseComposite, SWT.NONE);
portLabel.setText(PORT_LBL_UI_);
GridDataFactory.fillDefaults().span(2, 1).applyTo(portLabel);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(portLabel);

portText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(portText);

usernameLabel = new Label(baseComposite, SWT.NONE);
usernameLabel.setText(USERNAME_LBL_UI_);
GridDataFactory.fillDefaults().span(2, 1).applyTo(usernameLabel);

usernameText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
usernameLabel = new Label(baseComposite, SWT.NONE);
usernameLabel.setText(USERNAME_LBL_UI_);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(usernameLabel);
usernameText = new Text(baseComposite, SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(usernameText);

passwordLabel = new Label(baseComposite, SWT.NONE);
passwordLabel.setText(PASSWORD_LBL_UI_);
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(passwordLabel);
GridDataFactory.swtDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);

passwordText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD | additionalStyles);
GridDataFactory.fillDefaults().span(1, 1).grab(true, false).applyTo(passwordText);

savePasswordButton = new Button(baseComposite, SWT.CHECK);
savePasswordButton.setText(SAVE_PASSWORD_LBL_UI_);
GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).applyTo(savePasswordButton);

passwordText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(passwordText);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.END, SWT.BEGINNING).applyTo(savePasswordButton);

urlPropertiesLabel = new Label(baseComposite, SWT.NONE);
urlPropertiesLabel.setText(URL_PROPERTIES);
GridDataFactory.fillDefaults().span(2, 1).applyTo(usernameLabel);
GridDataFactory.fillDefaults().span(3, 1).applyTo(urlPropertiesLabel);

urlPropertiesText = new Text(baseComposite, SWT.SINGLE | SWT.BORDER | additionalStyles);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(urlPropertiesText);
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(urlPropertiesText);

urlLabel = new Label(baseComposite, SWT.NONE);
urlLabel.setText(CONNECTIONURL_LBL_UI_);
GridDataFactory.fillDefaults().applyTo(urlLabel);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(urlLabel);

protocolCheck = new Button(baseComposite, SWT.CHECK);
protocolCheck.setText(SSL_BTN_UI_);
protocolCheck.setSelection(false);
GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).applyTo(protocolCheck);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.BEGINNING).applyTo(protocolCheck);

urlText = new Text(baseComposite, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.BEGINNING).
grab(true, false).hint(190, 90).applyTo(urlText);
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.BEGINNING).
grab(true, false).hint(190, 50).applyTo(urlText);

// add optional properties tab
TabItem optionalPropsTab = new TabItem(tabComposite, SWT.None);
Expand All @@ -221,6 +248,20 @@ public Composite getContributedDriverUI( Composite parent,
}

public void setConnectionInformation() {
// validate version #
String newServerText = this.serverVersionText.getText().trim();
if( newServerText == null || newServerText.isEmpty() ) {
setMessage(IStatus.ERROR, Messages.getString("TeiidDriverUIContributor.serverVersionCannotBeEmpty")); //$NON-NLS-1$
} else {
TeiidServerVersionValidator validator = new TeiidServerVersionValidator(newServerText);
if( validator.getSeverity() == IStatus.OK ) {
setMessage(IStatus.OK, validator.getMessage());
} else {
setMessage(validator.getSeverity(), validator.getMessage());
}
}
properties.setProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.serverVersionText.getText().trim());

properties.setProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.databaseText.getText().trim());

properties.setProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID, this.usernameText.getText());
Expand Down Expand Up @@ -250,6 +291,25 @@ public void setConnectionInformation() {
optionalPropsComposite.setConnectionInformation();
this.contributorInformation.setProperties(properties);
}

private void setMessage( int severity, String message) {
switch(severity) {
case IStatus.OK: {
this.validationMessageText.setText("Click OK to save profile properties");
this.validationMessageText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
this.serverVersionLabel.setForeground(serverVersionLabel.getParent().getForeground());
} break;
case IStatus.WARNING: {
this.validationMessageText.setText(message);
this.validationMessageText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_YELLOW));
} break;
case IStatus.ERROR: {
this.validationMessageText.setText(message);
this.validationMessageText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
this.serverVersionLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
} break;
}
}

public void updateURL() {
String url = "jdbc:teiid:" + databaseText.getText().trim(); //$NON-NLS-1$
Expand All @@ -272,6 +332,8 @@ public void updateURL() {
}

private void removeListeners() {
serverVersionText.removeListener(SWT.Modify, this);
hostText.removeListener(SWT.Modify, this);
databaseText.removeListener(SWT.Modify, this);
hostText.removeListener(SWT.Modify, this);
portText.removeListener(SWT.Modify, this);
Expand All @@ -283,6 +345,7 @@ private void removeListeners() {
}

private void addListeners() {
serverVersionText.addListener(SWT.Modify, this);
databaseText.addListener(SWT.Modify, this);
hostText.addListener(SWT.Modify, this);
portText.addListener(SWT.Modify, this);
Expand Down Expand Up @@ -355,6 +418,18 @@ public void setDriverUIContributorInformation( IDriverUIContributorInformation c
@Override
public void loadProperties() {
removeListeners();

String version = this.properties.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID);

if (version != null) {
TeiidServerVersionValidator validator = new TeiidServerVersionValidator(version);
if( validator.containsWildcards()) {
version = TeiidServerVersion.deriveUltimateDefaultServerVersion().toString();
}
serverVersionText.setText(version);

}

TeiidServerJDBCURL url = new TeiidServerJDBCURL(
this.properties
.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID));
Expand Down Expand Up @@ -413,7 +488,8 @@ public void loadProperties() {
public List getSummaryData() {
List summaryData = new ArrayList();

summaryData.add(new String[] {DATABASE_SUMMARY_DATA_TEXT_, this.databaseText.getText().trim()});
summaryData.add(new String[] {SERVER_VERSION_LBL_UI_, this.serverVersionText.getText().trim()});
summaryData.add(new String[] {HOST_SUMMARY_DATA_TEXT_, this.hostText.getText().trim()});
summaryData.add(new String[] {HOST_SUMMARY_DATA_TEXT_, this.hostText.getText().trim()});
summaryData.add(new String[] {PORT_SUMMARY_DATA_TEXT_, this.portText.getText().trim()});

Expand All @@ -426,4 +502,73 @@ public List getSummaryData() {
summaryData.add(new String[] {URL_SUMMARY_DATA_TEXT_, this.urlText.getText().trim()});
return summaryData;
}

class TeiidServerVersionValidator {
String versionString;
int severity = IStatus.OK;
String message = Messages.getString("TeiidDriverUIContributor.serverVersionIsValid"); //$NON-NLS-1$

public TeiidServerVersionValidator(String versionString) {
super();
this.versionString = versionString;
validate();
}

private boolean containsWildcards() {
TeiidServerVersion version = null;
try {
version = new TeiidServerVersion(versionString);
} catch (IllegalArgumentException e) {
return false;
}

return version.hasWildCards();
}

private void validate() {
TeiidServerVersion version = null;
try {
version = new TeiidServerVersion(versionString);
} catch (IllegalArgumentException e) {
message = e.getMessage();
return;
}
// Test major, minor, micro versions

try {
Integer.parseInt(version.getMajor());
} catch (NumberFormatException e) {
severity = IStatus.ERROR;
message = Messages.getString("TeiidDriverUIContributor.majorVersionError.message") //$NON-NLS-1$
+ version.getMajor() + Messages.getString("TeiidDriverUIContributor.isNotAnInteger.message"); //$NON-NLS-1$
return;
}

try {
Integer.parseInt(version.getMinor());
} catch (NumberFormatException e) {
severity = IStatus.ERROR;
message = Messages.getString("TeiidDriverUIContributor.minorVersionError.message") //$NON-NLS-1$
+ version.getMinor() + Messages.getString("TeiidDriverUIContributor.isNotAnInteger.message"); //$NON-NLS-1$
return;
}

try {
Integer.parseInt(version.getMicro());
} catch (NumberFormatException e) {
severity = IStatus.ERROR;
message = Messages.getString("TeiidDriverUIContributor.microVersionError.message") //$NON-NLS-1$
+ version.getMicro() + Messages.getString("TeiidDriverUIContributor.isNotAnInteger.message"); //$NON-NLS-1$
return;
}
}

public int getSeverity() {
return severity;
}

public String getMessage() {
return message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ public void stateChanged(ChangeEvent e) {
};

driverCombo.addChangeListener(driverChangeListener);
if (driverCombo.getCombo().getItemCount() > 0) {
driverCombo.getCombo().select(0);
} else if (driverCombo.getErrorMessage() != null) {
if (driverCombo.getErrorMessage() != null) {
setMessage(driverCombo.getErrorMessage(), IMessageProvider.INFORMATION);//ErrorMessage(driverCombo.getErrorMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ TeiidDriverUIContributor.URL_PROPERTIES_ARG_LBL_UI_=URL Properties (in the form
TeiidDriverUIContributor.SSL_BTN_UI_=S&SL Connection
TeiidDriverUIContributor.SAVE_PASSWORD_LBL_UI_ =Sa&ve password
TeiidDriverUIContributor.CONNECTIONURL_LBL_UI_=Connection UR&L:
TeiidDriverUIContributor.SERVER_VERSION_LBL_UI_=Server V&ersion

TeiidDriverUIContributor.VALIDATE_DATABASE_REQ_UI_=Enter a database name.
TeiidDriverUIContributor.VALIDATE_HOST_REQ_UI_=Enter the host name for the Teiid Instance.
TeiidDriverUIContributor.VALIDATE_PORT_REQ_MSG_UI_=Enter the port number for the Teiid Instance.
TeiidDriverUIContributor.VALIDATE_USERID_REQ_MSG_UI_=Enter a user ID.
TeiidDriverUIContributor.serverVersionCannotBeEmpty=Server version cannot be empty
TeiidDriverUIContributor.serverVersionIsValid =Server version is valid
TeiidDriverUIContributor.majorVersionError.message = Teiid server major version value [
TeiidDriverUIContributor.minorVersionError.message = Teiid server minor version value [
TeiidDriverUIContributor.microVersionError.message = Teiid server micro version value [
TeiidDriverUIContributor.isNotAnInteger.message=] is not an integer


TeiidDriverUIContributor.summary.true = true
TeiidDriverUIContributor.summary.false = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,11 @@ public static enum Version {
* Teiid 8.7
*/
TEIID_8_7(VersionID.TEIID_8_7),

/**
* Teiid 8.8
*/
TEIID_8_8(VersionID.TEIID_8_7),

/**
* Default Teiid for this Designer
*/
TEIID_DEFAULT(VersionID.TEIID_8_8);
TEIID_DEFAULT(VersionID.TEIID_8_7);

private final ITeiidServerVersion version;

Expand Down

0 comments on commit 0aa486b

Please sign in to comment.