Skip to content
Snippets Groups Projects
Commit 74a4199f authored by Simon Barner's avatar Simon Barner
Browse files

- Enable automatic layouter only for diagrams without rounded edges, which is...

- Enable automatic layouter only for diagrams without rounded edges, which is the case if none of the positions of the connected connectors is specified using an angle (i.e., in particular also if the model does not contain any connectors, or none of the connectors is connected to a connection).
- getContributedItems(): Use shortcut style when checking conditions, i.e. return dedicated value at as soon as possible, instead of using nested ifs
refs 2898
parent f969b059
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.layout.auto;
import static org.fortiss.tooling.base.layout.LayoutKeyConstants.CONNECTOR_ANGLE;
import static org.fortiss.tooling.base.utils.AngleUtils.getAngle;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.ArrayList;
......@@ -28,6 +30,8 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.resource.ImageDescriptor;
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.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.ToolingBaseUIActivator;
......@@ -41,7 +45,7 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 2EC00DB461A5106CEB42DF8819159504
* @ConQAT.Rating YELLOW Hash: 76FF1ADFC034DE69815575B04BA534F0
*/
public class AutoLayoutMenu implements IContextMenuContributor {
......@@ -76,26 +80,58 @@ public class AutoLayoutMenu implements IContextMenuContributor {
}
}
/**
* Predicate if the given {@link IHierarchicElement} contains an {@link IConnector} whose
* position is specified using an angle, and that is connected to at least one incoming or
* outgoing {@link IConnection}.
*/
private boolean hasConnectedConnectorWithAngle(IHierarchicElement element) {
for(IConnector connector : element.getConnectors()) {
if(getAngle((ILayoutedModelElement)connector, CONNECTOR_ANGLE) != null) {
return !connector.getIncoming().isEmpty() || !connector.getOutgoing().isEmpty();
}
}
return false;
}
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof IHierarchicElement) {
IHierarchicElement element = (IHierarchicElement)selection;
// Skip single top-level model element (e.g., AF3 component architecture)
if(element instanceof IProjectRootElement && element.getContainedElements().size() == 1) {
// There is exactly one child element
element = element.getContainedElements().get(0);
}
if(!pickInstanceOf(ILayoutedModelElement.class, element.getContainedElements())
.isEmpty()) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(
new LaunchAutoLayoutAction(element)));
return contributionItems;
if(!(selection instanceof IHierarchicElement)) {
return Collections.emptyList();
}
IHierarchicElement element = (IHierarchicElement)selection;
// Skip single top-level model element (e.g., AF3 component architecture)
if(element instanceof IProjectRootElement && element.getContainedElements().size() == 1) {
// There is exactly one child element
element = element.getContainedElements().get(0);
}
// Check if model is empty
if(pickInstanceOf(ILayoutedModelElement.class, element.getContainedElements()).isEmpty()) {
return Collections.emptyList();
}
// Enable automatic layouter only for diagrams without rounded edges, which is the case if
// none of the positions of the connected connectors is specified using an angle (i.e., in
// particular also if the model does not contain any connectors, or none of the connectors
// is connected to a connection).
if(hasConnectedConnectorWithAngle(element)) {
return Collections.emptyList();
}
for(IHierarchicElement childElement : element.getContainedElements()) {
if(hasConnectedConnectorWithAngle(childElement)) {
return Collections.emptyList();
}
}
return Collections.emptyList();
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(new LaunchAutoLayoutAction(element)));
return contributionItems;
}
/** {@inheritDoc} */
......
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