Skip to content

Commit

Permalink
TEIIDDES-1869 added override handleInfoChanged() methods to set exten…
Browse files Browse the repository at this point in the history
…sion properties when entered or changed.

Re-arranged setting of extension properties onto EObjects in RelationalModelFactory so it occurrs after EObject is added to resource
  • Loading branch information
blafond committed Oct 2, 2013
1 parent 68ce3e1 commit 84182b3
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 18 deletions.
Expand Up @@ -17,6 +17,7 @@
import org.teiid.designer.extension.ExtensionConstants;
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;
import org.teiid.designer.metamodels.core.ModelType;
import org.teiid.designer.metamodels.relational.ForeignKey;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.metamodels.relational.RelationalPackage;
import org.teiid.designer.metamodels.relational.Table;
Expand Down Expand Up @@ -126,6 +127,16 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo
// EObject should not have the native query property definition
return null;
}

// must be a procedure in a physical model to have these properties
if (PropertyName.same(PropertyName.ALLOW_JOIN, propId)) {
if ((modelObject instanceof ForeignKey) && isPhysical) {
return propDefn;
}

// EObject should not have these property definitions
return null;
}

// must be a procedure in a physical model to have these properties
if (PropertyName.same(PropertyName.NON_PREPARED, propId)) {
Expand Down
Expand Up @@ -58,5 +58,26 @@ interface PropertyIds {
String UDF_JAR_PATH = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "udfJarPath"); //$NON-NLS-1$

}

interface PropertyKeysNoPrefix {
String JAVA_CLASS = "java-class"; //$NON-NLS-1$
String JAVA_METHOD = "java-method"; //$NON-NLS-1$
String FUNCTION_CATEGORY = "function-category"; //$NON-NLS-1$
String UDF_JAR_PATH = "udfJarPath"; //$NON-NLS-1$
String VARARGS = "varargs"; //$NON-NLS-1$
String NULL_ON_NULL= "null-on-null"; //$NON-NLS-1$
String DETERMINISTIC= "deterministic"; //$NON-NLS-1$
String AGGREGATE= "aggregate"; //$NON-NLS-1$

String ALLOWS_ORDER_BY = "allows-orderby"; //$NON-NLS-1$
String ALLOWS_DISTINCT = "allows-distinct"; //$NON-NLS-1$
String ANALYTIC = "analytic"; //$NON-NLS-1$
String DECOMPOSABLE= "decomposable"; //$NON-NLS-1$
String NATIVE_QUERY = "native-query"; //$NON-NLS-1$
String NON_PREPARED = "non-prepared"; //$NON-NLS-1$
String USES_DISTINCT_ROWS = "uses-distinct-rows"; //$NON-NLS-1$
String ALLOW_JOIN = "allow-join"; //$NON-NLS-1$

}

}
Expand Up @@ -108,6 +108,8 @@ public class Messages extends NLS {
public static String javaMethodLabel;
public static String udfJarPathLabel;
public static String functionCategoryLabel;
public static String allowJoinLabel;
public static String allowJoinTooltip;

public static String validationOkCreateObject;
public static String selectColumnsTitle;
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class EditForeignKeyDialog extends TitleAreaDialog {
TableViewer theColumnDataViewer;
Combo uniqueKeyMultiCombo;
Combo foreignKeyMultiCombo;
Button allowJoinButton;

Set<RelationalColumn> selectedColumns = new HashSet<RelationalColumn>();

Expand Down Expand Up @@ -273,6 +275,25 @@ public void modifyText( final ModifyEvent event ) {
});
WidgetUtil.setComboItems(this.uniqueKeyMultiCombo, MULTIPLICITY_LIST, multipicityLP, true);

this.allowJoinButton = new Button(composite, SWT.CHECK);
this.allowJoinButton.setText(Messages.allowJoinLabel);
this.allowJoinButton.setToolTipText(Messages.allowJoinTooltip);
this.allowJoinButton.setSelection(editedFK.isAllowJoin());
this.allowJoinButton.addSelectionListener(new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
editedFK.setAllowJoin(allowJoinButton.getSelection());
validate();
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub

}
});

Group keysGroup = WidgetFactory.createGroup(dialogComposite, Messages.selectPrimaryKeyOrUniqueConstraint, SWT.NONE, 2, 2);
keysGroup.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
Expand Down
Expand Up @@ -108,6 +108,8 @@ javaClassLabel=Java Class
javaMethodLabel=Java Method
udfJarPathLabel=UDF Jar Path
functionCategoryLabel=Function Category
allowJoinLabel=Allow Join
allowJoinTooltip=Allow joining using this foreign key

validationOkCreateObject=Click OK to add new object to model
selectColumnsTitle=Select Columns
Expand Down
Expand Up @@ -37,13 +37,15 @@ public class RelationalForeignKey extends RelationalReference {
public static final String DEFAULT_PRIMARY_KEY_MULTIPLICITY = MULTIPLICITY.ONE;
public static final String DEFAULT_UNIQUE_KEY_NAME = null;
public static final String DEFAULT_UNIQUE_KEY_TABLE_NAME = null;
public static final boolean DEFAULT_ALLOW_JOIN = true;


private Collection<RelationalColumn> columns;
private String foreignKeyMultiplicity;
private String primaryKeyMultiplicity;
private String uniqueKeyName;
private String uniqueKeyTableName;
private boolean allowJoin = DEFAULT_ALLOW_JOIN;

/**
* RelationalForeignKey constructor
Expand Down Expand Up @@ -76,6 +78,7 @@ public RelationalForeignKey clone() {
clonedFK.setUniqueKeyName(getUniqueKeyName());
clonedFK.setUniqueKeyTableName(getUniqueKeyTableName());
clonedFK.setModelType(getModelType());
clonedFK.setAllowJoin(isAllowJoin());
for( RelationalColumn col : getColumns() ) {
clonedFK.addColumn(col);
}
Expand Down Expand Up @@ -124,7 +127,10 @@ public String getForeignKeyMultiplicity() {
* @param foreignKeyMultiplicity Sets foreignKeyMultiplicity to the specified value.
*/
public void setForeignKeyMultiplicity( String foreignKeyMultiplicity ) {
this.foreignKeyMultiplicity = foreignKeyMultiplicity;
if( foreignKeyMultiplicity == null || this.foreignKeyMultiplicity == null || !this.foreignKeyMultiplicity.equals(foreignKeyMultiplicity) ) {
this.foreignKeyMultiplicity = foreignKeyMultiplicity;
handleInfoChanged();
}
}
/**
* @return primaryKeyMultiplicity
Expand All @@ -136,7 +142,10 @@ public String getPrimaryKeyMultiplicity() {
* @param primaryKeyMultiplicity Sets primaryKeyMultiplicity to the specified value.
*/
public void setPrimaryKeyMultiplicity( String primaryKeyMultiplicity ) {
this.primaryKeyMultiplicity = primaryKeyMultiplicity;
if( primaryKeyMultiplicity == null || this.primaryKeyMultiplicity == null || !this.primaryKeyMultiplicity.equals(primaryKeyMultiplicity) ) {
this.primaryKeyMultiplicity = primaryKeyMultiplicity;
handleInfoChanged();
}
}
/**
* @return uniqueKeyName
Expand All @@ -148,7 +157,10 @@ public String getUniqueKeyName() {
* @param uniqueKeyName Sets uniqueKeyName to the specified value.
*/
public void setUniqueKeyName( String uniqueKeyName ) {
this.uniqueKeyName = uniqueKeyName;
if( uniqueKeyName == null || this.uniqueKeyName == null || !this.uniqueKeyName.equals(uniqueKeyName) ) {
this.uniqueKeyName = uniqueKeyName;
handleInfoChanged();
}
}

/**
Expand All @@ -162,7 +174,10 @@ public String getUniqueKeyTableName() {
* @param uniqueKeyTableName Sets uniqueKeyTableName to the specified value.
*/
public void setUniqueKeyTableName( String uniqueKeyTableName ) {
this.uniqueKeyTableName = uniqueKeyTableName;
if( uniqueKeyTableName == null || this.uniqueKeyTableName == null || !this.uniqueKeyTableName.equals(uniqueKeyTableName) ) {
this.uniqueKeyTableName = uniqueKeyTableName;
handleInfoChanged();
}
}

/**
Expand All @@ -175,6 +190,22 @@ public RelationalTable getTable() {

return null;
}

/**
* @return allowJoin
*/
public boolean isAllowJoin() {
return allowJoin;
}
/**
* @param allowJoin
*/
public void setAllowJoin( boolean allowJoin ) {
if( this.allowJoin != allowJoin ) {
this.allowJoin = allowJoin;
handleInfoChanged();
}
}

/**
* Set properties
Expand Down Expand Up @@ -207,6 +238,18 @@ public void setProperties(Properties props) {
}
}

@Override
public void handleInfoChanged() {
super.handleInfoChanged();

// Set extension properties here

if( !this.allowJoin ) {
getExtensionProperties().put(ALLOW_JOIN, Boolean.toString(this.isAllowJoin()) );
} else getExtensionProperties().remove(ALLOW_JOIN);

}

@Override
public void validate() {
// Walk through the properties for the table and set the status
Expand Down
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -31,8 +30,6 @@
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.core.workspace.ModelWorkspaceItem;
import org.teiid.designer.core.workspace.ModelWorkspaceManager;
import org.teiid.designer.extension.ExtensionPlugin;
import org.teiid.designer.extension.definition.ModelExtensionAssistant;
import org.teiid.designer.extension.definition.ModelExtensionDefinition;
Expand Down Expand Up @@ -261,7 +258,7 @@ public EObject buildObject( RelationalReference relationalRef, ModelResource mod
} break;
case TYPES.TABLE: {
newEObject = createBaseTable(relationalRef, modelResource);
modelResource.getEmfResource().getContents().add(newEObject);
//modelResource.getEmfResource().getContents().add(newEObject);
//applyTableExtensionProperties((RelationalTable)obj, (BaseTable)baseTable, false);

// In the case of the new object wizards, users can create Indexes while creating a table
Expand All @@ -270,15 +267,17 @@ public EObject buildObject( RelationalReference relationalRef, ModelResource mod
EObject newIndex = createIndex(index, modelResource);
modelResource.getEmfResource().getContents().add(newIndex);
}

} break;
case TYPES.VIEW: {
newEObject = createView(relationalRef, modelResource);
modelResource.getEmfResource().getContents().add(newEObject);

} break;
case TYPES.PROCEDURE: {
newEObject = createProcedure(relationalRef, modelResource);
modelResource.getEmfResource().getContents().add(newEObject);
//applyProcedureExtensionProperties((RelationalProcedure)obj,(Procedure) procedure);

} break;
case TYPES.INDEX: {
indexes.add((RelationalIndex)relationalRef);
Expand All @@ -303,7 +302,7 @@ public EObject buildObject( RelationalReference relationalRef, ModelResource mod
* @param modelResource the model resource
* @return the new object
*/
public EObject createBaseTable( final RelationalReference ref, ModelResource modelResource) {
public EObject createBaseTable( final RelationalReference ref, ModelResource modelResource) throws ModelWorkspaceException {
CoreArgCheck.isInstanceOf(RelationalTable.class, ref);

RelationalTable tableRef = (RelationalTable)ref;
Expand All @@ -316,6 +315,8 @@ public EObject createBaseTable( final RelationalReference ref, ModelResource mod
baseTable.setSystem(tableRef.isSystem());
baseTable.setCardinality(tableRef.getCardinality());

modelResource.getEmfResource().getContents().add(baseTable);

// Set Description
if( tableRef.getDescription() != null ) {
createAnnotation(baseTable, tableRef.getDescription(), modelResource);
Expand Down Expand Up @@ -357,7 +358,7 @@ public EObject createBaseTable( final RelationalReference ref, ModelResource mod
* @param modelResource the model resource
* @return the new object
*/
public EObject createView( final RelationalReference ref, ModelResource modelResource) {
public EObject createView( final RelationalReference ref, ModelResource modelResource) throws ModelWorkspaceException {
CoreArgCheck.isInstanceOf(RelationalView.class, ref);

RelationalView viewRef = (RelationalView)ref;
Expand All @@ -369,6 +370,8 @@ public EObject createView( final RelationalReference ref, ModelResource modelRes
view.setNameInSource(viewRef.getNameInSource());
view.setSystem(viewRef.isSystem());

modelResource.getEmfResource().getContents().add(view);

// Set Description
if( viewRef.getDescription() != null ) {
createAnnotation(view, viewRef.getDescription(), modelResource);
Expand Down Expand Up @@ -697,7 +700,7 @@ private BaseTable getTable(String tableName, ModelResource modelResource) {
* @param modelResource the model resource
* @return the object
*/
public EObject createProcedure( final RelationalReference ref, ModelResource modelResource) {
public EObject createProcedure( final RelationalReference ref, ModelResource modelResource) throws ModelWorkspaceException {
CoreArgCheck.isInstanceOf(RelationalProcedure.class, ref);

RelationalProcedure procedureRef = (RelationalProcedure)ref;
Expand All @@ -708,7 +711,7 @@ public EObject createProcedure( final RelationalReference ref, ModelResource mod
procedure.setFunction(procedureRef.isFunction());
procedure.setUpdateCount(getUpdateCount(procedureRef.getUpdateCount()));


modelResource.getEmfResource().getContents().add(procedure);

// Set Description
if( procedureRef.getDescription() != null ) {
Expand Down Expand Up @@ -910,7 +913,7 @@ public EObject createResultSet( RelationalReference ref, Procedure procedure, Mo
* @param modelResource the model resource
* @return the index object
*/
public EObject createIndex( RelationalReference ref, ModelResource modelResource) {
public EObject createIndex( RelationalReference ref, ModelResource modelResource) throws ModelWorkspaceException {
CoreArgCheck.isInstanceOf(RelationalIndex.class, ref);

RelationalIndex indexRef = (RelationalIndex)ref;
Expand All @@ -923,6 +926,8 @@ public EObject createIndex( RelationalReference ref, ModelResource modelResource
index.setNullable(indexRef.isNullable());
index.setUnique(indexRef.isUnique());

modelResource.getEmfResource().getContents().add(index);

// Set Description
if( indexRef.getDescription() != null ) {
createAnnotation(index, indexRef.getDescription(), modelResource);
Expand Down

0 comments on commit 84182b3

Please sign in to comment.