diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ElementCompositorBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ElementCompositorBase.java new file mode 100644 index 0000000000000000000000000000000000000000..e478e7657bff0735ed0324e1ad5199dd4d5f9230 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ElementCompositorBase.java @@ -0,0 +1,65 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2014 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.extension.base; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.fortiss.tooling.kernel.extension.IElementCompositor; +import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext; +import org.fortiss.tooling.kernel.extension.data.Prototype; + +/** + * Base implementation for supporting composition of {@link IElementCompositor}. + * + * This class is used for example in the variability plugin. + * + * @author moudy + */ +public abstract class ElementCompositorBase<C extends EObject> implements IElementCompositor<C> { + + /** {@inheritDoc} */ + @Override + public boolean canCompose(C container, EObject contained, IElementCompositionContext context) { + return isCorrectClass(contained); + } + + /** {@inheritDoc} */ + @Override + public boolean canComposePrototype(Prototype prototype) { + return isCorrectClass(prototype.getPrototype()); + } + + /** Returns true if the contained object is an instance of an acceptable class. */ + protected abstract boolean isCorrectClass(EObject contained); + + /** {@inheritDoc} */ + @Override + abstract public boolean compose(C container, EObject contained, + IElementCompositionContext context); + + /** {@inheritDoc} */ + @Override + public boolean canDecompose(EObject contained) { + return isCorrectClass(contained); + } + + /** {@inheritDoc} */ + @Override + public boolean decompose(EObject contained) { + EcoreUtil.delete(contained, true); + return true; + } +}