use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.
the class DataLaboratoryHelper method getNodesManipulators.
/**
* <p>Prepares an array with one new instance of every NodesManipulator
* that has a builder registered and returns it.</p>
* <p>It also returns the manipulators ordered first by type and then by position.</p>
* @return Array of all NodesManipulator implementations
*/
public NodesManipulator[] getNodesManipulators() {
ArrayList<NodesManipulator> nodesManipulators = new ArrayList<>();
for (NodesManipulatorBuilder nm : Lookup.getDefault().lookupAll(NodesManipulatorBuilder.class)) {
nodesManipulators.add(nm.getNodesManipulator());
}
sortManipulators(nodesManipulators);
return nodesManipulators.toArray(new NodesManipulator[0]);
}
use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.
the class DataTableTopComponent method eventDispatched.
/**
* To react to Ctrl+F keys combination calling Search/Replace general action
* (and nodes/edges context menu mappings)
*
* @param event
*/
@Override
public void eventDispatched(AWTEvent event) {
KeyEvent evt = (KeyEvent) event;
if (evt.getID() == KeyEvent.KEY_RELEASED && (evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) {
DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
if (evt.getKeyCode() == KeyEvent.VK_F) {
//Call Search replace with 'F' without general actions key mappings support:
GeneralActionsManipulator gam = dlh.getGeneralActionsManipulatorByName("SearchReplace");
if (gam != null) {
dlh.executeManipulator(gam);
}
evt.consume();
} else {
//Nodes/edges mappings:
if (isShowingNodesTable()) {
final ContextMenuItemManipulator item = nodesActionMappings.get(evt.getKeyCode());
if (item != null) {
Node[] nodes = nodeTable.getElementsFromSelectedRows().toArray(new Node[0]);
if (nodes.length > 0) {
((NodesManipulator) item).setup(nodes, nodes[0]);
if (item.isAvailable() && item.canExecute()) {
DataLaboratoryHelper.getDefault().executeManipulator(item);
}
}
evt.consume();
}
} else if (isShowingEdgesTable()) {
final ContextMenuItemManipulator item = edgesActionMappings.get(evt.getKeyCode());
if (item != null) {
Edge[] edges = edgeTable.getElementsFromSelectedRows().toArray(new Edge[0]);
if (edges.length > 0) {
((EdgesManipulator) item).setup(edges, edges[0]);
if (item.isAvailable() && item.canExecute()) {
DataLaboratoryHelper.getDefault().executeManipulator(item);
}
}
evt.consume();
}
}
}
}
}
use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.
the class NodesPopupAdapter method createPopup.
@Override
protected JPopupMenu createPopup(Point p) {
final List<Node> selectedElements = elementsDataTable.getElementsFromSelectedRows();
final Node clickedElement = elementsDataTable.getElementFromRow(table.rowAtPoint(p));
JPopupMenu contextMenu = new JPopupMenu();
//First add edges manipulators items:
DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
Integer lastManipulatorType = null;
for (NodesManipulator em : dlh.getNodesManipulators()) {
em.setup(selectedElements.toArray(new Node[0]), clickedElement);
if (lastManipulatorType == null) {
lastManipulatorType = em.getType();
}
if (lastManipulatorType != em.getType()) {
contextMenu.addSeparator();
}
lastManipulatorType = em.getType();
if (em.isAvailable()) {
contextMenu.add(PopupMenuUtils.createMenuItemFromNodesManipulator(em, clickedElement, selectedElements.toArray(new Node[0])));
}
}
//Add AttributeValues manipulators submenu:
Column column = elementsDataTable.getColumnAtIndex(table.columnAtPoint(p));
if (column != null) {
contextMenu.add(PopupMenuUtils.createSubMenuFromRowColumn(clickedElement, column));
}
return contextMenu;
}
use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.
the class PopupMenuUtils method createMenuItemFromNodesManipulator.
public static JMenuItem createMenuItemFromNodesManipulator(final NodesManipulator item, final Node clickedNode, final Node[] nodes) {
ContextMenuItemManipulator[] subItems = item.getSubItems();
if (subItems != null && item.canExecute()) {
JMenu subMenu = new JMenu();
subMenu.setText(item.getName());
if (item.getDescription() != null && !item.getDescription().isEmpty()) {
subMenu.setToolTipText(item.getDescription());
}
subMenu.setIcon(item.getIcon());
Integer lastItemType = null;
for (ContextMenuItemManipulator subItem : subItems) {
((NodesManipulator) subItem).setup(nodes, clickedNode);
if (lastItemType == null) {
lastItemType = subItem.getType();
}
if (lastItemType != subItem.getType()) {
subMenu.addSeparator();
}
lastItemType = subItem.getType();
if (subItem.isAvailable()) {
subMenu.add(createMenuItemFromNodesManipulator((NodesManipulator) subItem, clickedNode, nodes));
}
}
if (item.getMnemonicKey() != null) {
//Mnemonic for opening a sub menu
subMenu.setMnemonic(item.getMnemonicKey());
}
return subMenu;
} else {
JMenuItem menuItem = new JMenuItem();
menuItem.setText(item.getName());
if (item.getDescription() != null && !item.getDescription().isEmpty()) {
menuItem.setToolTipText(item.getDescription());
}
menuItem.setIcon(item.getIcon());
if (item.canExecute()) {
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread() {
@Override
public void run() {
DataLaboratoryHelper.getDefault().executeManipulator(item);
}
}.start();
}
});
} else {
menuItem.setEnabled(false);
}
if (item.getMnemonicKey() != null) {
//Mnemonic for executing the action
menuItem.setMnemonic(item.getMnemonicKey());
//And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
}
return menuItem;
}
}
Aggregations