Programmatically click on menu item

31 views
Skip to first unread message

dpgil

unread,
Jul 21, 2016, 2:10:47 AM7/21/16
to cytoscape-app-dev
How can I programmatically "click" on a menu item in Cytoscape 3?

For example, I want to apply a yFiles layout algorithm. 
I understand this is closed source, so I want to grab the Layout menu item, click that, and then click yFiles -> Hierarchical.

How can I programmatically click these items?

Thanks,
Daniel

Alexander Pico

unread,
Jul 21, 2016, 1:10:35 PM7/21/16
to cytoscape-app-dev
Hi Daniel,

This is not supported by the Cytoscape API.  The yFiles code is closed to us, unfortunately, so we couldn't expose it's individual layouts and their parameters via the general Cytoscape Layout interface. And we don't the the UI directly exposed via the API either.

Good news: All of the other layouts, include app-specific layout, are available!  (see attached list)

 - Alex
Screen Shot 2016-07-21 at 10.09.16 AM.png

Matthias König

unread,
Jul 22, 2016, 3:40:27 AM7/22/16
to Alexander Pico, cytoscape-app-dev
But one should still be able to get and call the registered service, i.e. in this case the registered HierachicalLayout.
My understanding is if you install the ylayouts.jar which is part of the Cytoscape distribution in a local maven repository, and set the dependency to provided you should be able to get the layoutTaskFactory on runtime.
import yfiles.HierarchicLayout;
HierarchicLayout layoutTaskFactory = getService(bc, HierarchicLayout.class);
The name of the service you want is HierarchicLayout. You can see the registered service and structure of the task factory in the decompiled code below.
Not sure about legal aspects here. ylayouts is registering a service and you would consume it. This is part of the provided functionality of Cytoscape, so probably a grey area. I don't see much difference in clicking on a button or providing some own way to run the layout (as long as you don't provide batch capabilities via your app or export the functionality as a command/API, so others could use it in a batch fashion.


Decompiled CyActivator below.
package yfiles;

import java.util.Properties;
import org.cytoscape.service.util.AbstractCyActivator;
import org.cytoscape.task.NetworkViewTaskFactory;
import org.cytoscape.view.presentation.property.values.BendFactory;
import org.cytoscape.view.presentation.property.values.HandleFactory;
import org.osgi.framework.BundleContext;
import yfiles.CircularLayout;
import yfiles.HierarchicLayout;
import yfiles.MirrorX;
import yfiles.MirrorY;
import yfiles.OrganicLayout;
import yfiles.OrthogonalLayout;
import yfiles.RandomLayout;
import yfiles.Rotate90;
import yfiles.Rotate_90;
import yfiles.Scale2;
import yfiles.Scale_half;
import yfiles.TreeLayout;

public class CyActivator extends AbstractCyActivator {
public CyActivator() {
}

public void start(BundleContext var1) {
Properties var2 = new Properties();
var2.setProperty("inToolBar", "false");
var2.setProperty("inMenuBar", "true");
var2.setProperty("preferredMenu", "Layout.yFiles Layouts");
var2.setProperty("title", "Organic");
var2.setProperty("menuGravity", "1.0");
var2.setProperty("inContextMenu", "false");
this.registerService(var1, new OrganicLayout(), NetworkViewTaskFactory.class, var2);
Properties var3 = new Properties();
var3.setProperty("inToolBar", "false");
var3.setProperty("inMenuBar", "true");
var3.setProperty("preferredMenu", "Layout.yFiles Layouts");
var3.setProperty("title", "Circular");
var3.setProperty("menuGravity", "2.0");
var3.setProperty("inContextMenu", "false");
this.registerService(var1, new CircularLayout(), NetworkViewTaskFactory.class, var3);
BendFactory var4 = (BendFactory)this.getService(var1, BendFactory.class);
HandleFactory var5 = (HandleFactory)this.getService(var1, HandleFactory.class);
Properties var6 = new Properties();
var6.setProperty("inToolBar", "false");
var6.setProperty("inMenuBar", "true");
var6.setProperty("preferredMenu", "Layout.yFiles Layouts");
var6.setProperty("title", "Hierarchic");
var6.setProperty("menuGravity", "3.0");
var6.setProperty("inContextMenu", "false");
this.registerService(var1, new HierarchicLayout(var4, var5), NetworkViewTaskFactory.class, var6);
Properties var7 = new Properties();
var7.setProperty("inToolBar", "false");
var7.setProperty("inMenuBar", "true");
var7.setProperty("preferredMenu", "Layout.yFiles Layouts");
var7.setProperty("title", "Orthogonal");
var7.setProperty("menuGravity", "4.0");
var7.setProperty("inContextMenu", "false");
this.registerService(var1, new OrthogonalLayout(), NetworkViewTaskFactory.class, var7);
Properties var8 = new Properties();
var8.setProperty("inToolBar", "false");
var8.setProperty("inMenuBar", "true");
var8.setProperty("preferredMenu", "Layout.yFiles Layouts");
var8.setProperty("title", "Tree");
var8.setProperty("menuGravity", "5.0");
var8.setProperty("inContextMenu", "false");
this.registerService(var1, new TreeLayout(), NetworkViewTaskFactory.class, var8);
Properties var9 = new Properties();
var9.setProperty("inToolBar", "false");
var9.setProperty("inMenuBar", "true");
var9.setProperty("preferredMenu", "Layout.yFiles Layouts");
var9.setProperty("title", "Random");
var9.setProperty("menuGravity", "6.0");
var9.setProperty("inContextMenu", "false");
this.registerService(var1, new RandomLayout(), NetworkViewTaskFactory.class, var9);
Properties var10 = new Properties();
var10.setProperty("inToolBar", "false");
var10.setProperty("inMenuBar", "true");
var10.setProperty("preferredMenu", "Layout.yFiles Layouts");
var10.setProperty("title", "Rotate 90 Degrees");
var10.setProperty("menuGravity", "7.0");
var10.setProperty("inContextMenu", "false");
this.registerService(var1, new Rotate90(), NetworkViewTaskFactory.class, var10);
Properties var11 = new Properties();
var11.setProperty("inToolBar", "false");
var11.setProperty("inMenuBar", "true");
var11.setProperty("preferredMenu", "Layout.yFiles Layouts");
var11.setProperty("title", "Rotate -90 Degrees");
var11.setProperty("menuGravity", "8.0");
var11.setProperty("inContextMenu", "false");
this.registerService(var1, new Rotate_90(), NetworkViewTaskFactory.class, var11);
Properties var12 = new Properties();
var12.setProperty("inToolBar", "false");
var12.setProperty("inMenuBar", "true");
var12.setProperty("preferredMenu", "Layout.yFiles Layouts");
var12.setProperty("title", "Scale 2X");
var12.setProperty("menuGravity", "9.0");
var12.setProperty("inContextMenu", "false");
this.registerService(var1, new Scale2(), NetworkViewTaskFactory.class, var12);
Properties var13 = new Properties();
var13.setProperty("inToolBar", "false");
var13.setProperty("inMenuBar", "true");
var13.setProperty("preferredMenu", "Layout.yFiles Layouts");
var13.setProperty("title", "Scale 1/2X");
var13.setProperty("menuGravity", "10.0");
var13.setProperty("inContextMenu", "false");
this.registerService(var1, new Scale_half(), NetworkViewTaskFactory.class, var13);
Properties var14 = new Properties();
var14.setProperty("inToolBar", "false");
var14.setProperty("inMenuBar", "true");
var14.setProperty("preferredMenu", "Layout.yFiles Layouts");
var14.setProperty("title", "Mirror X-Axis");
var14.setProperty("menuGravity", "11.0");
var14.setProperty("inContextMenu", "false");
this.registerService(var1, new MirrorX(), NetworkViewTaskFactory.class, var14);
Properties var15 = new Properties();
var15.setProperty("inToolBar", "false");
var15.setProperty("inMenuBar", "true");
var15.setProperty("preferredMenu", "Layout.yFiles Layouts");
var15.setProperty("title", "Mirror Y-Axis");
var15.setProperty("menuGravity", "12.0");
var15.setProperty("inContextMenu", "false");
this.registerService(var1, new MirrorY(), NetworkViewTaskFactory.class, var15);
}
}
decompiled HiearchicLayout
package yfiles;

import org.cytoscape.task.AbstractNetworkViewTaskFactory;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.presentation.property.values.BendFactory;
import org.cytoscape.view.presentation.property.values.HandleFactory;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskIterator;
import yfiles.HierarchicLayout.HierarchicLayoutTask;

class HierarchicLayout extends AbstractNetworkViewTaskFactory {
private final BendFactory A;
private final HandleFactory B;

HierarchicLayout(BendFactory var1, HandleFactory var2) {
this.A = var1;
this.B = var2;
}

public TaskIterator createTaskIterator(CyNetworkView var1) {
return new TaskIterator(new Task[]{new HierarchicLayoutTask(this, var1)});
}
}


--
You received this message because you are subscribed to the Google Groups "cytoscape-app-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-app-...@googlegroups.com.
To post to this group, send email to cytoscap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cytoscape-app-dev/0da06075-61f1-481a-95be-e062c7b2bf79%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Matthias König
Junior Group Leader LiSym - Systems Medicine of the Liver
Humboldt-University Berlin, Institute for Theoretical Biology
  https://www.livermetabolism.com
koni...@googlemail.com

Tel: +49 30 20938450
Tel: +49 176 81168480

dpgil

unread,
Jul 25, 2016, 11:52:23 AM7/25/16
to cytoscape-app-dev, xande...@gmail.com
Thank you for your response!

dpgil

unread,
Jul 25, 2016, 11:52:45 AM7/25/16
to cytoscape-app-dev
Thanks, Alex!
Reply all
Reply to author
Forward
0 new messages