Skip to content
Snippets Groups Projects
Commit 979ee655 authored by Christoph Döbber's avatar Christoph Döbber
Browse files

reworking decomposition mechanism

parent 1bc85a12
No related branches found
No related tags found
No related merge requests found
Showing
with 230 additions and 18 deletions
......@@ -79,7 +79,7 @@ public class CutModelElementsAction extends ModelElementsActionBase {
public boolean canExecute() {
for (EObject o : selection) {
if (!IElementCompositorService.INSTANCE.canDecompose(
o.eContainer(), o, null)) {
o)) {
return false;
}
}
......
......@@ -136,4 +136,10 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier
return true;
}
/** Base implementation returns true by default */
public boolean canDisconnectSpecific(S source, T target,
EObject connection, IConnectionCompositionContext context) {
return true;
}
}
......@@ -47,7 +47,7 @@ public final class RemoveEditPolicy extends ComponentEditPolicy {
for (EditPart ep : (List<EditPart>) request.getEditParts()) {
EObject model = (EObject) ep.getModel();
boolean canDelete = IElementCompositorService.INSTANCE
.canDecompose(model.eContainer(), model, null);
.canDecompose(model);
if (canDelete) {
compound.add(new RemoveCommand(model));
} else {
......@@ -79,7 +79,7 @@ public final class RemoveEditPolicy extends ComponentEditPolicy {
@Override
public boolean canExecute() {
return IElementCompositorService.INSTANCE.canDecompose(
toRemove.eContainer(), toRemove, null);
toRemove);
}
}
}
......@@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.fortiss.tooling.kernel;bundle-version="0.0.1";visibility:=reexport
Bundle-ActivationPolicy: lazy
Export-Package: org.fortiss.tooling.base,
org.fortiss.tooling.base.decompose,
org.fortiss.tooling.base.model.base,
org.fortiss.tooling.base.model.base.impl,
org.fortiss.tooling.base.model.base.util,
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 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.base.decompose;
import java.util.HashSet;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.extension.IElementCompositor;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
/**
*
* @author doebber
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public abstract class HierarchicElementCompositorBase<HE extends IHierarchicElementContainer>
implements IElementCompositor<HE> {
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject contained) {
return iterateCanDecompose(contained, new CanDecomposeIterator());
}
/** recursive traversion of all model elements in subtree */
private boolean iterateCanDecompose(EObject contained,
CanDecomposeIterator cdi) {
if (!canDecomposeSpecific(contained)) {
return false;
}
if (contained instanceof IConnection) {
IConnection c = (IConnection) contained;
return IConnectionCompositorService.INSTANCE.canDecomposeSpecific(
c.getSource(), c.getTarget(), c, null);
}
if (contained instanceof IModelElement) {
IModelElement me = (IModelElement) contained;
for (IModelElementSpecification spec : me.getSpecificationsList()) {
if (cdi.contains(spec)) {
continue;
}
if (!iterateCanDecompose(spec, cdi)) {
return false;
}
cdi.add(spec);
}
// TODO CD: handle references
}
if (contained instanceof IHierarchicElement) {
IHierarchicElement he = (IHierarchicElement) contained;
for (IHierarchicElement subelement : he.getContainedElementsList()) {
if (cdi.contains(subelement)) {
continue;
}
if (!iterateCanDecompose(subelement, cdi)) {
return false;
}
cdi.add(subelement);
}
for (IConnection conn : he.getConnectionsList()) {
if (cdi.contains(conn)) {
continue;
}
if (!iterateCanDecompose(conn, cdi)) {
return false;
}
cdi.add(conn);
}
for (IConnector c : he.getConnectorsList()) {
if (cdi.contains(c)) {
continue;
}
if (!iterateCanDecompose(c, cdi)) {
return false;
}
cdi.add(c);
}
}
if (contained instanceof IConnector) {
IConnector connector = (IConnector) contained;
for (IConnection conn : connector.getIncomingList()) {
if (cdi.contains(conn)) {
continue;
}
if (!iterateCanDecompose(conn, cdi)) {
return false;
}
cdi.add(conn);
}
for (IConnection conn : connector.getOutgoingList()) {
if (cdi.contains(conn)) {
continue;
}
if (!iterateCanDecompose(conn, cdi)) {
return false;
}
cdi.add(conn);
}
}
return true;
}
/** Base implementation returns true by default. Subclasses may override. */
public boolean canDecomposeSpecific(
@SuppressWarnings("unused") EObject contained) {
return true;
}
/** Helper class to iterate over model elements in subtree to remove */
private class CanDecomposeIterator {
/** holds the model elements already visited */
private HashSet<EObject> set = new HashSet<EObject>();
/** add model element to traversed elements */
public void add(EObject element) {
set.add(element);
}
/**
* returns whether this model element has been inquired for
* decomposition ability before
*/
public boolean contains(EObject element) {
return set.contains(element);
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 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.base.decompose;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.extension.IConnectionCompositor;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
/**
*
* @author doebber
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public abstract class IConnectionCompositorBase<HE extends IHierarchicElement, S extends IHierarchicElement, T extends IHierarchicElement>
implements IConnectionCompositor<HE, S, T> {
/** {@inheritDoc} */
@Override
public boolean canDisconnect(S source, T target, EObject connection,
IConnectionCompositionContext context) {
if (connection instanceof IConnection) {
IConnection conn = (IConnection) connection;
for (IModelElementSpecification spec : conn.getSpecificationsList()) {
if (!IElementCompositorService.INSTANCE.canDecompose(spec)) {
return false;
}
}
}
return true;
}
}
......@@ -156,7 +156,7 @@ public class ActionService implements IActionService,
.canRedo(target));
boolean canDelete = IElementCompositorService.INSTANCE.canDecompose(
target.eContainer(), target, null);
target);
canDelete = canDelete
&& !IPersistencyService.INSTANCE.isTopLevelElement(target);
globalDeleteAction.setTarget(target);
......
......@@ -71,14 +71,12 @@ public interface IElementCompositor<C extends EObject> extends IEObjectAware<C>
* Returns whether the given contained element may be removed from the given
* container element.
*/
boolean canDecompose(C container, EObject contained,
IElementCompositionContext context);
boolean canDecompose(EObject contained);
/**
* Asks the compositor to remove the contained object from the container.
* This method returns a boolean, since user-interaction during compose
* might cancel the command.
*/
boolean decompose(C container, EObject contained,
IElementCompositionContext context);
boolean decompose(EObject contained);
}
......@@ -69,7 +69,7 @@ public class ConnectionCompositorService
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject source, EObject destination,
public boolean canDecomposeSpecific(EObject source, EObject destination,
EObject connection, IConnectionCompositionContext context) {
return findWorkingConnector(source, destination, connection, false,
context) != null;
......
......@@ -84,9 +84,9 @@ public final class ElementCompositorService extends
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject container, EObject contained,
IElementCompositionContext context) {
return findWorkingCompositor(container, contained, context, true) != null;
public boolean canDecompose(EObject contained) {
return findWorkingCompositor(contained.eContainer(), contained, null,
true) != null;
}
/** {@inheritDoc} */
......@@ -94,7 +94,7 @@ public final class ElementCompositorService extends
public boolean decompose(EObject container, EObject contained,
IElementCompositionContext context) {
return findWorkingCompositor(container, contained, context, true)
.decompose(container, contained, context);
.decompose(contained);
}
/**
......@@ -116,8 +116,7 @@ public final class ElementCompositorService extends
if (!decompose
&& compositor.canCompose(container, contained, context)) {
return compositor;
} else if (decompose
&& compositor.canDecompose(container, contained, context)) {
} else if (decompose && compositor.canDecompose(contained)) {
return compositor;
}
}
......
......@@ -75,7 +75,7 @@ public interface IConnectionCompositorService {
* Determines if there is a compositor that allows the decomposition of the
* connection between the source and target model element.
*/
boolean canDecompose(EObject source, EObject destination,
boolean canDecomposeSpecific(EObject source, EObject destination,
EObject connection, IConnectionCompositionContext context);
/**
......
......@@ -70,8 +70,7 @@ public interface IElementCompositorService {
* Determines if there is a compositor that allows the decomposition of the
* container and the contained {@link EObject}.
*/
boolean canDecompose(EObject container, EObject contained,
IElementCompositionContext context);
boolean canDecompose(EObject contained);
/**
* Decomposes the container and the element. Since this operation may be
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment