use of org.cytoscape.task.NetworkViewLocationTaskFactory in project cytoscape-impl by cytoscape.
the class PopupMenuHelper method createNetworkViewMenu.
/**
* Creates a menu based on the NetworkView.
*
* @param action Acceptable values are "NEW" or "OPEN." Case does not matter.
*/
void createNetworkViewMenu(Point rawPt, Point xformPt, String action) {
Collection<NetworkViewTaskFactory> usableTFs = getPreferredActions(graphView.emptySpaceTFs, action);
Collection<NetworkViewLocationTaskFactory> usableTFs2 = getPreferredActions(graphView.networkViewLocationTfs, action);
Collection<CyNetworkViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyNetworkViewContextMenuFactory, action);
// remove TaskFactories that can't be executed from double-click menu
if (action.equalsIgnoreCase("OPEN")) {
Iterator<NetworkViewTaskFactory> i = usableTFs.iterator();
while (i.hasNext()) {
if (!i.next().isReady(graphView))
i.remove();
}
Iterator<NetworkViewLocationTaskFactory> i2 = usableTFs2.iterator();
while (i2.hasNext()) {
if (!i2.next().isReady(graphView, rawPt, xformPt))
i2.remove();
}
}
int menuItemCount = usableTFs.size() + usableTFs2.size() + usableCMFs.size();
int tfCount = usableTFs.size() + usableTFs2.size();
if (action.equalsIgnoreCase("OPEN") && menuItemCount == 1 && tfCount == 1) {
// Double click on open space and there is only one menu item, execute it
final DialogTaskManager taskManager = serviceRegistrar.getService(DialogTaskManager.class);
if (usableTFs.size() == 1) {
NetworkViewTaskFactory tf = usableTFs.iterator().next();
taskManager.execute(tf.createTaskIterator(graphView));
} else if (usableTFs2.size() == 1) {
NetworkViewLocationTaskFactory tf = usableTFs2.iterator().next();
taskManager.execute(tf.createTaskIterator(graphView, rawPt, xformPt));
}
} else {
final JPopupMenu menu = createMenu("Double Click Menu: empty");
final JMenuTracker tracker = new JMenuTracker(menu);
if (!action.equalsIgnoreCase("OPEN")) {
initializeNetworkTracker(tracker);
tracker.getGravityTracker(".").addMenuSeparator(-0.1);
tracker.getGravityTracker(".").addMenuSeparator(999.99);
}
for (NetworkViewTaskFactory nvtf : usableTFs) {
NamedTaskFactory provisioner = factoryProvisioner.createFor(nvtf, graphView);
addMenuItem(null, menu, provisioner, null, tracker, graphView.emptySpaceTFs.get(nvtf));
}
for (NetworkViewLocationTaskFactory nvltf : usableTFs2) {
NamedTaskFactory provisioner = factoryProvisioner.createFor(nvltf, graphView, rawPt, xformPt);
addMenuItem(null, menu, provisioner, null, tracker, graphView.networkViewLocationTfs.get(nvltf));
}
for (CyNetworkViewContextMenuFactory netVMF : usableCMFs) {
try {
CyMenuItem menuItem = netVMF.createMenuItem(graphView);
addCyMenuItem(graphView, menu, menuItem, tracker, graphView.cyNetworkViewContextMenuFactory.get(netVMF));
} catch (Throwable t) {
logger.error("Could not display context menu.", t);
}
}
// There are more than one menu item, let user make the selection
menu.show(invoker, (int) (rawPt.getX()), (int) (rawPt.getY()));
}
}
use of org.cytoscape.task.NetworkViewLocationTaskFactory in project cytoscape-impl by cytoscape.
the class CyActivator method start.
@Override
public void start(BundleContext bc) {
final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
{
// NetworkView (empty space) context menus
SIFInterpreterTaskFactory factory = new SIFInterpreterTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(ENABLE_FOR, "networkAndView");
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
props.setProperty(MENU_GRAVITY, "1.0");
props.setProperty(IN_MENU_BAR, "false");
props.setProperty(TITLE, "Edge (and possibly Nodes) using SIF...");
registerService(bc, factory, NetworkViewTaskFactory.class, props);
}
{
NetworkViewLocationTaskFactory factory = new AddNodeTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
props.setProperty(MENU_GRAVITY, "1.1");
props.setProperty(TITLE, "Node");
registerService(bc, factory, NetworkViewLocationTaskFactory.class, props);
}
// We need a place to hold the objects themselves
ClipboardManagerImpl clipboardManager = new ClipboardManagerImpl(serviceRegistrar);
{
// Copy node
NetworkViewTaskFactory factory = new CopyTaskFactory(clipboardManager);
Properties props = new Properties();
props.setProperty(ENABLE_FOR, "networkAndView");
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd c");
props.setProperty(TITLE, "Copy");
props.setProperty(MENU_GRAVITY, "0.0f");
registerService(bc, factory, NetworkViewTaskFactory.class, props);
}
{
// Cut node
NetworkViewTaskFactory factory = new CutTaskFactory(clipboardManager, serviceRegistrar);
Properties props = new Properties();
props.setProperty(ENABLE_FOR, "networkAndView");
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd x");
props.setProperty(MENU_GRAVITY, "0.1f");
props.setProperty(TITLE, "Cut");
registerService(bc, factory, NetworkViewTaskFactory.class, props);
}
{
// Paste node
NetworkViewLocationTaskFactory pasteTaskFactory = new PasteTaskFactory(clipboardManager, serviceRegistrar);
Properties props = new Properties();
props.setProperty(ENABLE_FOR, "networkAndView");
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
props.setProperty(TITLE, "Paste");
props.setProperty(MENU_GRAVITY, "0.2f");
props.setProperty(ACCELERATOR, "cmd v");
props.setProperty(IN_MENU_BAR, "true");
registerService(bc, pasteTaskFactory, NetworkViewLocationTaskFactory.class, props);
}
// At some point, add Paste Special. Paste special would allow paste node only, paste copy, etc.
// NodeView context menus
{
// Copy node
NodeViewTaskFactory factory = new CopyNodeTaskFactory(clipboardManager);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd c");
props.setProperty(MENU_GRAVITY, "0.0f");
props.setProperty(TITLE, "Copy");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
{
// Cut node
NodeViewTaskFactory factory = new CutNodeTaskFactory(clipboardManager, serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd x");
props.setProperty(MENU_GRAVITY, "0.1f");
props.setProperty(TITLE, "Cut");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
{
// Rename node
NodeViewTaskFactory factory = new RenameNodeTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
props.setProperty(INSERT_SEPARATOR_AFTER, "true");
props.setProperty(MENU_GRAVITY, "0.2f");
props.setProperty(TITLE, "Rename Node");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
{
NodeViewTaskFactory factory = new AddNestedNetworkTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
props.setProperty(MENU_GRAVITY, "0.1f");
props.setProperty(TITLE, "Add Nested Network");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
{
NodeViewTaskFactory factory = new DeleteNestedNetworkTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
props.setProperty(MENU_GRAVITY, "0.2f");
props.setProperty(TITLE, "Remove Nested Network");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
{
NodeViewTaskFactory factory = new GoToNestedNetworkTaskFactory(serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
props.setProperty(MENU_GRAVITY, "0.3f");
props.setProperty(TITLE, "Go to Nested Network");
registerService(bc, factory, NodeViewTaskFactory.class, props);
}
// EdgeView context menus
{
// Copy node
EdgeViewTaskFactory factory = new CopyEdgeTaskFactory(clipboardManager);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, EDGE_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd c");
props.setProperty(MENU_GRAVITY, "0.0f");
props.setProperty(TITLE, "Copy");
registerService(bc, factory, EdgeViewTaskFactory.class, props);
}
{
// Cut edge
EdgeViewTaskFactory factory = new CutEdgeTaskFactory(clipboardManager, serviceRegistrar);
Properties props = new Properties();
props.setProperty(PREFERRED_ACTION, "NEW");
props.setProperty(PREFERRED_MENU, EDGE_EDIT_MENU);
props.setProperty(ACCELERATOR, "cmd x");
props.setProperty(MENU_GRAVITY, "0.1f");
props.setProperty(TITLE, "Cut");
registerService(bc, factory, EdgeViewTaskFactory.class, props);
}
}
Aggregations