Skip to content

Commit

Permalink
TEIIDDES-2093, TEIIDDES-2005, TEIIDDES-2074
Browse files Browse the repository at this point in the history
* Added Import Properties editing in Teiid Connection Importer
* Refactored core Translator property classes to designer.core
* Added TranslatorUtils class to simplify getting property definitions from translator
* Added data source property defn description to data source property items for display
  • Loading branch information
blafond committed Apr 15, 2014
1 parent 579b22b commit 79ca477
Show file tree
Hide file tree
Showing 39 changed files with 1,636 additions and 396 deletions.
1 change: 1 addition & 0 deletions plugins/org.teiid.designer.core/META-INF/MANIFEST.MF
Expand Up @@ -41,6 +41,7 @@ Export-Package: org.teiid.designer.core,
org.teiid.designer.core.search.runtime,
org.teiid.designer.core.spi,
org.teiid.designer.core.transaction,
org.teiid.designer.core.translators,
org.teiid.designer.core.types,
org.teiid.designer.core.util,
org.teiid.designer.core.validation,
Expand Down
Expand Up @@ -972,4 +972,24 @@ VdbHelper.errorCountingFolderFiles=Error counting files in folder: {0}

ModelerCore.noDefaultServer=No default teiid instance defined

ModelProjectResourceValidator.duplicateFileNamesError=Multiple files with same name "{0}" exist in project. Same named files are not allowed in VDBs.
ModelProjectResourceValidator.duplicateFileNamesError=Multiple files with same name "{0}" exist in project. Same named files are not allowed in VDBs.

TranslatorPropertyDefinition.emptyPropertyName = The property name cannot be empty.
TranslatorPropertyDefinition.emptyPropertyValue = The property must have a value.
TranslatorPropertyDefinition.invalidPropertyName = The property name of "{0}" is invalid. Only valid java identifiers are allowed.
TranslatorPropertyDefinition.customPropertyDescription = This is a custom property. All custom property's must have a value. Custom properties can be deleted.

TranslatorOverride.emptyTranslatorName = A translator override must have a name.
TranslatorOverride.invalidTranslatorName = The translator name of "{0}" is invalid. Only letters, digits, and a dash are allowed.
TranslatorOverride.translatorNameMustStartWithLetter = The translator name must start with a letter.
TranslatorOverride.emptyTranslatorType = A translator override must have a type.
TranslatorOverride.invalidTranslatorType = The translator type of "{0}" is invalid. Only letters, digits, and a dash are allowed.
TranslatorOverride.translatorTypeMustStartWithLetter = The translator type must start with a letter.

invalidPropertyValueForType = The value "{0}" is not valid for a "{1}" property type.
invalidPropertyValue = The value "{0}" is not valid for property "{1}."
invalidPropertyEditorConstrainedValue = "{0}" is not a valid. Must be one of the following: {1}
invalidPropertyEditorValue = "{0}" is not a valid {1} value
invalidNullPropertyValue = The property "{0}" must have a value.
missingPropertyDefinition = No property definition found for property "{0}."
unknownPropertyType = Property "{0}" has an unknown type of "{1}."
@@ -0,0 +1,227 @@
package org.teiid.designer.core.translators;

import static org.teiid.designer.core.ModelerCore.Util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.teiid.core.designer.properties.PropertyDefinition;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.core.translators.TranslatorOverrideProperty;
import org.teiid.designer.core.translators.TranslatorPropertyDefinition;
import org.teiid.designer.core.util.StringUtilities;

public class TranslatorOverride {

private static final String PREFIX = I18nUtil.getPropertyPrefix(TranslatorOverride.class);

/**
* @param proposedName the proposed translator name
* @return an error message or <code>null</code> if name is valid
*/
public static String validateName( String proposedName ) {
// must have a name
if (StringUtilities.isEmpty(proposedName)) {
return Util.getString(PREFIX + "emptyTranslatorName"); //$NON-NLS-1$
}

// make sure only letters, digits, or dash
for (char c : proposedName.toCharArray()) {
if (!Character.isLetter(c) && !Character.isDigit(c)
&& (c != '-')) {
return Util.getString(PREFIX + "invalidTranslatorName", proposedName); //$NON-NLS-1$
}
}

// first char must be letter
if (!Character.isLetter(proposedName.charAt(0))) {
return Util.getString(PREFIX + "translatorNameMustStartWithLetter"); //$NON-NLS-1$
}

// valid name
return null;
}

/**
* @param proposedType the proposed translator type
* @return an error message or <code>null</code> if type is valid
*/
public static String validateType( String proposedType ) {
// must have a type
if (StringUtilities.isEmpty(proposedType)) {
return Util.getString(PREFIX + "emptyTranslatorType"); //$NON-NLS-1$
}

// make sure only letters, digits, or dash
for (char c : proposedType.toCharArray()) {
if (!Character.isLetterOrDigit(c) && c != '-') {
return Util.getString(PREFIX + "invalidTranslatorType", proposedType); //$NON-NLS-1$
}
}

// first char must be letter
if (!Character.isLetter(proposedType.charAt(0))) {
return Util.getString(PREFIX + "translatorTypeMustStartWithLetter"); //$NON-NLS-1$
}

// valid type
return null;
}


private final Map<String, TranslatorOverrideProperty> properties;

private final String type;

/**
* @param name the name of the overridden translator (may not be <code>null</code>)
* @param type the translator type being overridden (may not be <code>null</code>)
* @param vdb the VDB this override is contained in
* @param description the translator override description (may be <code>null</code> or empty)
*/
public TranslatorOverride( String type, Properties properties ) {
assert (type != null);

this.type = type;
this.properties = new HashMap<String, TranslatorOverrideProperty>();
}

/**
* @param newProperty the property being added (may not be <code>null</code>)
*/
public void addProperty( TranslatorOverrideProperty newProperty) {
assert (newProperty != null);

this.properties.put(newProperty.getDefinition().getId(), newProperty);

}

/**
* Obtains all the properties of the translator even those properties whose values have not been overridden.
*
* @return all translator properties (never <code>null</code>)
*/
public TranslatorOverrideProperty[] getProperties() {
TranslatorOverrideProperty[] props = new TranslatorOverrideProperty[this.properties.size()];
int i = 0;

for (TranslatorOverrideProperty property : this.properties.values()) {
props[i++] = property;
}

return props;
}

/**
* @return a list of all property names (never <code>null</code> but can be empty)
*/
public List<String> getPropertyNames() {
return Arrays.asList(this.properties.keySet().toArray(new String[this.properties.size()]));
}

/**
* @return the translator type being overridden (never <code>null</code>)
*/
public String getType() {
return this.type;
}

/**
* @param property the property being marked as a user-defined or custom property (may not be <code>null</code>)
*/
public void markAsUserDefined( TranslatorOverrideProperty property ) {
property.getDefinition().markAsUserDefined(property.getOverriddenValue());
}

/**
* Removes the property and fires a VDB property changed event
*
* @param propName the name of the property being removed (may not be <code>null</code> or empty)
* @return <code>true</code> if the property was removed
*/
public boolean removeProperty( String propName ) {
return removeProperty(propName, true);
}

/**
* @param propName the name of the property being removed (may not be <code>null</code> or empty)
* @param firePropertyEvent <code>true</code> if a VDB property changed event should be fired
* @return <code>true</code> if the property was removed
*/
public boolean removeProperty( String propName,
boolean firePropertyEvent ) {
assert (propName != null);
assert (this.properties.containsKey(propName));

this.properties.remove(propName);

return false;
}


/**
* Updates the overridden value and fires a VDB property changed event.
*
* @param propDefn the property definition whose overridden value is being changed (may not be <code>null</code>)
* @param newValue the new value (may be <code>null</code> or empty)
*/
public void setOverrideValue( TranslatorPropertyDefinition propDefn,
String newValue ) {
setOverrideValue(propDefn, newValue, true);
}

/**
* @param propDefn the property definition whose overridden value is being changed (may not be <code>null</code>)
* @param newValue the new value (may be <code>null</code> or empty)
* @param firePropertyEvent <code>true</code> if a VDB property changed event should be fired
*/
public void setOverrideValue( TranslatorPropertyDefinition propDefn,
String newValue,
boolean firePropertyEvent ) {
assert (propDefn != null);
assert (this.properties.containsKey(propDefn.getId()));

TranslatorOverrideProperty prop = this.properties.get(propDefn.getId());
String oldValue = prop.getOverriddenValue();

// don't set if nothing has changed
if (StringUtilities.equals(newValue, oldValue)) {
return;
}

prop.setValue(newValue);
}

/**
* Updates the property definition and fires a VDB property changed event.
*
* @param propertyName the property whose definition is being updated (may not be <code>null</code> or empty)
* @param newServerPropDefn the new definition (may not be <code>null</code>)
*/
public void updatePropertyDefinition( String propertyName,
PropertyDefinition newServerPropDefn ) {
updatePropertyDefinition(propertyName, newServerPropDefn, true);
}

/**
* @param propertyName the property whose definition is being updated (may not be <code>null</code> or empty)
* @param newServerPropDefn the new definition (may not be <code>null</code>)
* @param firePropertyEvent <code>true</code> if a VDB property changed event should be fired
*/
public void updatePropertyDefinition( String propertyName,
PropertyDefinition newServerPropDefn,
boolean firePropertyEvent ) {
assert (!StringUtilities.isEmpty(propertyName));
assert (newServerPropDefn != null);

TranslatorOverrideProperty prop = this.properties.get(propertyName);

if (prop != null) {
prop.setDefinition(newServerPropDefn);
}
}

}
Expand Up @@ -5,7 +5,7 @@
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.vdb;
package org.teiid.designer.core.translators;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down

0 comments on commit 79ca477

Please sign in to comment.