-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from elvisisking/teiiddes-1467
Teiiddes 1467 Add method to MED assistant class to allow passing object to retrieve property descriptors
- Loading branch information
Showing
9 changed files
with
346 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 108 additions & 7 deletions
115
...src/org/teiid/designer/metamodels/function/extension/FunctionModelExtensionAssistant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,119 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.designer.metamodels.function.extension; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.teiid.core.util.CoreArgCheck; | ||
import org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant; | ||
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition; | ||
import org.teiid.designer.metamodels.function.ScalarFunction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class FunctionModelExtensionAssistant extends | ||
EmfModelObjectExtensionAssistant { | ||
public class FunctionModelExtensionAssistant extends EmfModelObjectExtensionAssistant { | ||
|
||
private static String getPropertyId(final String propName) { | ||
return ModelExtensionPropertyDefinition.Utils.getPropertyId(FunctionModelExtensionConstants.NAMESPACE_PROVIDER, propName); | ||
} | ||
|
||
private enum PropertyName { | ||
|
||
AGGREGATE(getPropertyId("aggregate")), //$NON-NLS-1$ | ||
ALLOWS_ORDER_BY(getPropertyId("allows-orderby")), //$NON-NLS-1$ | ||
ALLOWS_DISTINCT(getPropertyId("allows-distinct")), //$NON-NLS-1$ | ||
ANALYTIC(getPropertyId("analytic")), //$NON-NLS-1$ | ||
DECOMPOSABLE(getPropertyId("decomposable")), //$NON-NLS-1$ | ||
USES_DISTINCT_ROWS(getPropertyId("uses-distinct-rows")); //$NON-NLS-1$ | ||
|
||
public static boolean same(final PropertyName propName, | ||
final String value) { | ||
return propName.toString().equals(value); | ||
} | ||
|
||
private final String propName; | ||
|
||
private PropertyName(final String propName) { | ||
this.propName = propName; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see java.lang.Enum#toString() | ||
*/ | ||
@Override | ||
public String toString() { | ||
return this.propName; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant#getPropertyDefinition(java.lang.Object, java.lang.String) | ||
*/ | ||
@Override | ||
protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object modelObject, | ||
final String propId) throws Exception { | ||
CoreArgCheck.isInstanceOf(EObject.class, modelObject); | ||
|
||
// make sure there is a property definition first | ||
final ModelExtensionPropertyDefinition propDefn = super.getPropertyDefinition(modelObject, propId); | ||
|
||
if ((propDefn != null) && (modelObject instanceof ScalarFunction)) { | ||
if (PropertyName.same(PropertyName.ANALYTIC, propId) || PropertyName.same(PropertyName.ALLOWS_ORDER_BY, propId) | ||
|| PropertyName.same(PropertyName.USES_DISTINCT_ROWS, propId) | ||
|| PropertyName.same(PropertyName.ALLOWS_DISTINCT, propId) | ||
|| PropertyName.same(PropertyName.DECOMPOSABLE, propId)) { | ||
// aggregate must be true to have rest of the above properties | ||
final String isAggregate = getPropertyValue(modelObject, PropertyName.AGGREGATE.toString()); | ||
|
||
if (Boolean.parseBoolean(isAggregate)) { | ||
return propDefn; | ||
} | ||
|
||
// make sure model object does not have these extension properties for when aggregate is false | ||
removeProperty(modelObject, PropertyName.ANALYTIC.toString()); | ||
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString()); | ||
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString()); | ||
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString()); | ||
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString()); | ||
|
||
// EObject should not have the requested property definition | ||
return null; | ||
} | ||
|
||
return propDefn; | ||
} | ||
|
||
// property definition not found | ||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant#setPropertyValue(java.lang.Object, java.lang.String, java.lang.String) | ||
*/ | ||
@Override | ||
public void setPropertyValue(final Object modelObject, | ||
final String propId, | ||
final String newValue) throws Exception { | ||
super.setPropertyValue(modelObject, propId, newValue); | ||
|
||
// if setting aggregate to false remove these properties | ||
if (PropertyName.same(PropertyName.AGGREGATE, propId) && !Boolean.parseBoolean(newValue)) { | ||
removeProperty(modelObject, PropertyName.ANALYTIC.toString()); | ||
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString()); | ||
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString()); | ||
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString()); | ||
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.