Search in sources :

Example 1 with IViewer

use of de.cau.cs.kieler.klighd.IViewer in project lingua-franca by lf-lang.

the class MemorizingExpandCollapseAction method execute.

// -----------------------------------------------------------------------------------------------------------------
@Override
public IAction.ActionResult execute(final IAction.ActionContext context) {
    ViewContext vc = context.getViewContext();
    IViewer v = vc.getViewer();
    KNode node = context.getKNode();
    NamedInstance<?> linkedInstance = NamedInstanceUtil.getLinkedInstance(node);
    // Find node that is properly linked
    while (node != null && linkedInstance == null) {
        node = node.getParent();
        linkedInstance = NamedInstanceUtil.getLinkedInstance(node);
    }
    if (node == null) {
        return IAction.ActionResult.createResult(false);
    } else {
        // toggle
        setExpansionState(node, linkedInstance, v, !v.isExpanded(node));
        return IAction.ActionResult.createResult(true);
    }
}
Also used : ViewContext(de.cau.cs.kieler.klighd.ViewContext) IViewer(de.cau.cs.kieler.klighd.IViewer) KNode(de.cau.cs.kieler.klighd.kgraph.KNode)

Example 2 with IViewer

use of de.cau.cs.kieler.klighd.IViewer in project lingua-franca by lf-lang.

the class ReactionPortAdjustment method modify.

@Override
public boolean modify(IStyleModifier.StyleModificationContext context) {
    try {
        KGraphElement node = context.getGraphElement();
        if (node instanceof KNode) {
            KNode knode = (KNode) node;
            // Find root node
            KNode parent = knode;
            while (parent.eContainer() != null) {
                parent = (KNode) parent.eContainer();
            }
            // Get viewer (this is a bit brittle because it fetches the viewer from some internal property)
            Map.Entry<IProperty<?>, Object> first = IterableExtensions.findFirst(parent.getAllProperties().entrySet(), it -> {
                return it.getKey().getId().equals("de.cau.cs.kieler.klighd.viewer") || it.getKey().getId().equals("klighd.layout.viewer");
            });
            Object viewer = first != null ? first.getValue() : null;
            ILayoutRecorder recorder = null;
            if (viewer instanceof IViewer) {
                recorder = ((IViewer) viewer).getViewContext().getLayoutRecorder();
            }
            if (!knode.getPorts().isEmpty()) {
                if (IterableExtensions.head(knode.getPorts()).getYpos() != 0 && !knode.getProperty(ReactionPortAdjustment.PROCESSED)) {
                    // important for incremental update animation
                    if (recorder != null) {
                        recorder.startRecording();
                    }
                    List<KPort> in = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
                        return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
                    }), it -> {
                        return it.getYpos();
                    }));
                    List<KPort> out = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
                        return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
                    }), it -> {
                        return it.getYpos();
                    }));
                    // Adjust
                    adjustPositions(IterableExtensions.indexed(in), in.size(), true);
                    adjustPositions(IterableExtensions.indexed(out), out.size(), false);
                    knode.setProperty(ReactionPortAdjustment.PROCESSED, true);
                    if (recorder != null) {
                        recorder.stopRecording(0);
                    }
                } else if (IterableExtensions.head(knode.getPorts()).getYpos() == 0) {
                    knode.setProperty(PROCESSED, false);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    // do not disturb rendering process
    }
    return false;
}
Also used : KGraphElement(de.cau.cs.kieler.klighd.kgraph.KGraphElement) KEdge(de.cau.cs.kieler.klighd.kgraph.KEdge) CoreOptions(org.eclipse.elk.core.options.CoreOptions) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KGraphElement(de.cau.cs.kieler.klighd.kgraph.KGraphElement) Property(org.eclipse.elk.graph.properties.Property) PortSide(org.eclipse.elk.core.options.PortSide) KPoint(de.cau.cs.kieler.klighd.kgraph.KPoint) KGraphFactory(de.cau.cs.kieler.klighd.kgraph.KGraphFactory) LinguaFrancaShapeExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions) Extension(org.eclipse.xtext.xbase.lib.Extension) IViewer(de.cau.cs.kieler.klighd.IViewer) List(java.util.List) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) IProperty(org.eclipse.elk.graph.properties.IProperty) Map(java.util.Map) IStyleModifier(de.cau.cs.kieler.klighd.IStyleModifier) Pair(org.eclipse.xtext.xbase.lib.Pair) ILayoutRecorder(de.cau.cs.kieler.klighd.internal.ILayoutRecorder) IViewer(de.cau.cs.kieler.klighd.IViewer) IProperty(org.eclipse.elk.graph.properties.IProperty) ILayoutRecorder(de.cau.cs.kieler.klighd.internal.ILayoutRecorder) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) Map(java.util.Map)

Aggregations

IViewer (de.cau.cs.kieler.klighd.IViewer)2 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)2 IStyleModifier (de.cau.cs.kieler.klighd.IStyleModifier)1 ViewContext (de.cau.cs.kieler.klighd.ViewContext)1 ILayoutRecorder (de.cau.cs.kieler.klighd.internal.ILayoutRecorder)1 KEdge (de.cau.cs.kieler.klighd.kgraph.KEdge)1 KGraphElement (de.cau.cs.kieler.klighd.kgraph.KGraphElement)1 KGraphFactory (de.cau.cs.kieler.klighd.kgraph.KGraphFactory)1 KPoint (de.cau.cs.kieler.klighd.kgraph.KPoint)1 KPort (de.cau.cs.kieler.klighd.kgraph.KPort)1 List (java.util.List)1 Map (java.util.Map)1 CoreOptions (org.eclipse.elk.core.options.CoreOptions)1 PortSide (org.eclipse.elk.core.options.PortSide)1 IProperty (org.eclipse.elk.graph.properties.IProperty)1 Property (org.eclipse.elk.graph.properties.Property)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 IterableExtensions (org.eclipse.xtext.xbase.lib.IterableExtensions)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1 LinguaFrancaShapeExtensions (org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions)1