Skip to content

Commit

Permalink
TEIIDDES-2369 fixed persistance of Parameters (names, types and defau…
Browse files Browse the repository at this point in the history
…lt values).

 * changed default height of parameters table to show more than 1 parameter
  • Loading branch information
blafond committed Oct 15, 2014
1 parent a0e39f7 commit 08bbf8a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*
*/
public class Parameter {
private char COLON = ':';


public static final String PREFIX = "rest_param:"; //$NON-NLS-N$

private String name;
private String defaultValue;
Expand Down Expand Up @@ -41,6 +45,17 @@ public Parameter(String name, String defaultValue, Type type) {
this.defaultValue = defaultValue;
this.type = type;
}

/**
* @param name
* @param defaultValue
*/
public Parameter(String keyName, String propertyValue) {
super();
this.name = extractName(keyName);
this.defaultValue = extractDefaultValue(propertyValue);
this.type = extractType(propertyValue);
}

/**
* @return the name
Expand Down Expand Up @@ -83,5 +98,34 @@ public Type getType() {
public void setType(Type type) {
this.type = type;
}

public String getPropertyKey() {
return PREFIX + getName();
}

public String getPropertyValue() {
return getType().toString() + ':' + getDefaultValue();
}

private String extractName(String keyName) {
if( keyName.indexOf(COLON) > -1 ) {
return keyName.substring(keyName.indexOf(COLON)+1);
}
return keyName;
}

private Type extractType(String propertyValue) {
if( propertyValue.indexOf(COLON) > -1 ) {
return Type.fromValue(propertyValue.substring(0, propertyValue.indexOf(COLON)));
}
return Type.Query;
}

private String extractDefaultValue(String propertyValue) {
if( propertyValue.indexOf(COLON) > -1 ) {
return propertyValue.substring(propertyValue.indexOf(COLON)+1);
}
return propertyValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
Expand Down Expand Up @@ -49,6 +50,7 @@
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.core.designer.util.StringConstants;
import org.teiid.core.designer.util.StringUtilities;
import org.teiid.datatools.connectivity.model.Parameter;
import org.teiid.designer.core.translators.SimpleProperty;
import org.teiid.designer.datatools.ui.DatatoolsUiConstants;
import org.teiid.designer.datatools.ui.DatatoolsUiPlugin;
Expand Down Expand Up @@ -126,7 +128,7 @@ public Object[] getElements( Object inputElement ) {
ICredentialsCommon.SECURITY_TYPE_ID.equalsIgnoreCase(keyStr) ||
ICredentialsCommon.USERNAME_PROP_ID.equalsIgnoreCase(keyStr) ||
IWSProfileConstants.END_POINT_URI_PROP_ID.equalsIgnoreCase(keyStr) ||
IWSProfileConstants.PARAMETER_MAP.equalsIgnoreCase(keyStr) ||
keyStr.toLowerCase().startsWith(Parameter.PREFIX) ||
IWSProfileConstants.URI.equalsIgnoreCase(keyStr) ||
IWSProfileConstants.QUERY_STRING.equalsIgnoreCase(keyStr) ||
IWSProfileConstants.RESPONSE_TYPE_PROPERTY_KEY.equalsIgnoreCase(keyStr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
Expand Down Expand Up @@ -112,7 +113,7 @@ private void createPanel(Composite parent) {
panel.setLayoutData(gd);

this.propertiesViewer = new TableViewerBuilder(panel, (SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.BORDER));
GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(propertiesViewer.getTableComposite());
GridDataFactory.fillDefaults().grab(true, true).span(3, 1).hint(360, 160).applyTo(propertiesViewer.getTableComposite());

ColumnViewerToolTipSupport.enableFor(this.propertiesViewer.getTableViewer());
this.propertiesViewer.setContentProvider(new IStructuredContentProvider() {
Expand Down Expand Up @@ -194,7 +195,6 @@ public int compare( Viewer viewer,
column.setLabelProvider(new PropertyLabelProvider(2));
column.setEditingSupport(new PropertyNameEditingSupport(this.propertiesViewer.getTableViewer(), 2));


this.propertiesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
/**
* {@inheritDoc}
Expand Down Expand Up @@ -302,14 +302,18 @@ void handleAddProperty() {
}

if (this.wsProfileDetailsWizardPage!=null){
wsProfileDetailsWizardPage.getProfileProperties().put(IWSProfileConstants.PARAMETER_MAP, this.parameterMap);
for( Object key : this.parameterMap.keySet() ) {
Parameter para = (Parameter)this.parameterMap.get((String)key);
wsProfileDetailsWizardPage.getProfileProperties().put(para.getPropertyKey(), para.getPropertyValue());
}
wsProfileDetailsWizardPage.setParameterMap(this.parameterMap);
wsProfileDetailsWizardPage.getProfileProperties().put(IWSProfileConstants.PARAMETER_MAP, this.parameterMap);
wsProfileDetailsWizardPage.urlPreviewText.setText(wsProfileDetailsWizardPage.updateUrlPreview().toString());
}else{
propertyPage.getExtraProperties().put(IWSProfileConstants.PARAMETER_MAP, this.parameterMap);
for( Object key : this.parameterMap.keySet() ) {
Parameter para = (Parameter)this.parameterMap.get((String)key);
propertyPage.getExtraProperties().put(para.getPropertyKey(), para.getPropertyValue());
}
propertyPage.setParameterMap(this.parameterMap);
propertyPage.getExtraProperties().put(IWSProfileConstants.PARAMETER_MAP, this.parameterMap);
propertyPage.urlPreviewText.setText(propertyPage.updateUrlPreview().toString());
}
}
Expand Down Expand Up @@ -423,7 +427,7 @@ protected Object getValue(Object element) {
@Override
protected void setValue(Object element, Object value) {
if( element instanceof Parameter ) {
String key = ((Parameter)element).getName();
String key = ((Parameter)element).getPropertyKey();
if( columnID == 1 ) {
String oldType = ((Parameter)element).getType().toString();
String newType = (String)value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ui.wizards.ProfileDetailsPropertyPage;
import org.eclipse.datatools.help.ContextProviderDelegate;
Expand Down Expand Up @@ -257,7 +258,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
this.parametersTab = new TabItem(tabFolder, SWT.FILL);
this.parametersTab.setControl(parameterPanel);
this.parametersTab.setText(UTIL.getString("ParametersPanel_groupTitle")); //$NON-NLS-1$
this.parameterPanel = new ParameterPanel(this, parameterPanel, parameterMap, 6);
this.parameterPanel = new ParameterPanel(this, parameterPanel, parameterMap, 8);
this.urlPreviewText.setText(updateUrlPreview().toString());

Composite headerPropertiesPanel = WidgetFactory.createPanel(tabFolder);
Expand All @@ -273,15 +274,22 @@ public void widgetDefaultSelected(SelectionEvent e) {
* @return the extraProperties
*/
public Properties getExtraProperties() {
this.extraProperties.put(IWSProfileConstants.PARAMETER_MAP, this.getParameterMap());
for( String key : this.getParameterMap().keySet() ) {
Parameter para = this.getParameterMap().get(key);
this.extraProperties.put(para.getPropertyKey(), para.getPropertyValue());
}

return this.extraProperties;
}

/**
* @param extraProperties the extraProperties to set
*/
public void setExtraProperties(Properties extraProperties) {
this.extraProperties.put(IWSProfileConstants.PARAMETER_MAP, this.getParameterMap());
for( String key : this.getParameterMap().keySet() ) {
Parameter para = this.getParameterMap().get(key);
this.extraProperties.put(para.getPropertyKey(), para.getPropertyValue());
}
this.extraProperties = extraProperties;
}

Expand Down Expand Up @@ -331,10 +339,10 @@ private StringBuilder buildParameterString() {

for (String key : parameterMap.keySet()) {
Parameter value = parameterMap.get(key);
if (value.getType().equals(IWSProfileConstants.QUERY_STRING)) {
if (value.getType().equals(Parameter.Type.URI)) {
parameterString.append("/").append(value.getDefaultValue()); //$NON-NLS-1$
}
if (value.getType().equals(IWSProfileConstants.QUERY_STRING)) {
if (value.getType().equals(Parameter.Type.Query)) {
if (parameterString.length()==0 || !parameterString.toString().contains("?")){ //$NON-NLS-1$
parameterString.append("?"); //$NON-NLS-1$
}else{
Expand Down Expand Up @@ -442,11 +450,10 @@ protected void validate() {
private void initControls() {
IConnectionProfile profile = getConnectionProfile();
Properties props = profile.getBaseProperties();
if (props.get(IWSProfileConstants.PARAMETER_MAP) != null) {
if (props.get(IWSProfileConstants.PARAMETER_MAP) instanceof Map) {
this.parameterMap = ((Map)props.get(IWSProfileConstants.PARAMETER_MAP));
}
}

// Check properties and load any existing parameters into parametersMap
loadParameters(props);

if (null != props.get(ICredentialsCommon.USERNAME_PROP_ID)) {
usernameText.setText((String)props.get(ICredentialsCommon.USERNAME_PROP_ID));
}
Expand Down Expand Up @@ -480,6 +487,25 @@ private void initControls() {
}

}

/*
* Need to load the parameters map from general profile properties
*
* KEYS will look like: "rest_param:myParam"
* VALUES will look like: "Query:myDefaultValue"
* The Parameter class includes a constructor that will take these two values and extract the
* appropriate parameter name, type and default value values
*/
private void loadParameters(Properties props) {
for( Object key : props.keySet() ) {
String keyStr = (String)key;

if( keyStr.startsWith(Parameter.PREFIX)) {
Parameter newParam = new Parameter(keyStr, props.getProperty((String)key));
parameterMap.put(newParam.getName(), newParam);
}
}
}

/**
* {@inheritDoc}
Expand Down

0 comments on commit 08bbf8a

Please sign in to comment.