use of org.gephi.datalab.spi.edges.EdgesManipulator in project gephi by gephi.
the class DataLaboratoryHelper method getEdgesManipulators.
/**
* <p>Prepares an array with one new instance of every EdgesManipulator
* 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 EdgesManipulator implementations
*/
public EdgesManipulator[] getEdgesManipulators() {
ArrayList<EdgesManipulator> edgesManipulators = new ArrayList<>();
for (EdgesManipulatorBuilder em : Lookup.getDefault().lookupAll(EdgesManipulatorBuilder.class)) {
edgesManipulators.add(em.getEdgesManipulator());
}
sortManipulators(edgesManipulators);
return edgesManipulators.toArray(new EdgesManipulator[0]);
}
use of org.gephi.datalab.spi.edges.EdgesManipulator in project gephi by gephi.
the class EdgesPopupAdapter method createPopup.
@Override
protected JPopupMenu createPopup(Point p) {
final List<Edge> selectedElements = elementsDataTable.getElementsFromSelectedRows();
final Edge clickedElement = elementsDataTable.getElementFromRow(table.rowAtPoint(p));
JPopupMenu contextMenu = new JPopupMenu();
//First add edges manipulators items:
DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
Integer lastManipulatorType = null;
for (EdgesManipulator em : dlh.getEdgesManipulators()) {
em.setup(selectedElements.toArray(new Edge[0]), clickedElement);
if (lastManipulatorType == null) {
lastManipulatorType = em.getType();
}
if (lastManipulatorType != em.getType()) {
contextMenu.addSeparator();
}
lastManipulatorType = em.getType();
if (em.isAvailable()) {
contextMenu.add(PopupMenuUtils.createMenuItemFromEdgesManipulator(em, clickedElement, selectedElements.toArray(new Edge[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.edges.EdgesManipulator in project gephi by gephi.
the class PopupMenuUtils method createMenuItemFromEdgesManipulator.
public static JMenuItem createMenuItemFromEdgesManipulator(final EdgesManipulator item, final Edge clickedEdge, final Edge[] edges) {
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) {
((EdgesManipulator) subItem).setup(edges, clickedEdge);
if (lastItemType == null) {
lastItemType = subItem.getType();
}
if (lastItemType != subItem.getType()) {
subMenu.addSeparator();
}
lastItemType = subItem.getType();
if (subItem.isAvailable()) {
subMenu.add(createMenuItemFromEdgesManipulator((EdgesManipulator) subItem, clickedEdge, edges));
}
}
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