use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.
the class ManifestPanel method createPopupMenu.
private void createPopupMenu() {
myPopup = new JBPopupMenu();
JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
gotoItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
if (node != null) {
goToDeclaration(node.getUserObject());
}
});
myPopup.add(gotoItem);
myRemoveItem = new JBMenuItem("Remove");
myRemoveItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag", ManifestUtils.getMainManifest(myFacet)) {
@Override
protected void run() throws Throwable {
ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
}
}.execute();
});
myPopup.add(myRemoveItem);
MouseListener ml = new MouseAdapter() {
@Override
public void mousePressed(@NotNull MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
Node attribute = node.getUserObject();
if (attribute instanceof Attr) {
goToDeclaration(attribute);
}
}
}
}
private void handlePopup(@NotNull MouseEvent e) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath == null || e.getSource() == myDetails) {
// Use selection instead
treePath = myTree.getSelectionPath();
}
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
myRemoveItem.setEnabled(canRemove(node.getUserObject()));
myPopup.show(e.getComponent(), e.getX(), e.getY());
}
}
};
myTree.addMouseListener(ml);
myDetails.addMouseListener(ml);
}
use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.
the class DeviceDefinitionList method possiblyShowPopup.
private void possiblyShowPopup(MouseEvent e) {
if (!e.isPopupTrigger()) {
return;
}
Point p = e.getPoint();
int row = myTable.rowAtPoint(p);
int col = myTable.columnAtPoint(p);
if (row != -1 && col != -1) {
JBPopupMenu menu = new JBPopupMenu();
menu.add(createMenuItem(new CloneDeviceAction(this)));
menu.add(createMenuItem(new EditDeviceAction(this)));
menu.add(createMenuItem(new ExportDeviceAction(this)));
menu.add(createMenuItem(new DeleteDeviceAction(this)));
menu.show(myTable, p.x, p.y);
}
}
use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.
the class StateListPicker method createAlphaPopupMenu.
@NotNull
private JBPopupMenu createAlphaPopupMenu(@NotNull final ResourceHelper.StateListState state, @NotNull final StateComponent stateComponent) {
JBPopupMenu popupMenu = new JBPopupMenu();
final JMenuItem deleteAlpha = new JMenuItem("Delete alpha");
popupMenu.add(deleteAlpha);
deleteAlpha.setVisible(!StringUtil.isEmpty(state.getAlpha()));
final JMenuItem createAlpha = new JMenuItem("Create alpha");
popupMenu.add(createAlpha);
createAlpha.setVisible(StringUtil.isEmpty(state.getAlpha()));
deleteAlpha.addActionListener(e -> {
stateComponent.getAlphaComponent().setVisible(false);
stateComponent.setAlphaValue(null);
state.setAlpha(null);
updateIcon(stateComponent);
deleteAlpha.setVisible(false);
createAlpha.setVisible(true);
});
createAlpha.addActionListener(e -> {
AlphaActionListener listener = stateComponent.getAlphaActionListener();
if (listener == null) {
return;
}
listener.actionPerformed(new ActionEvent(stateComponent.getAlphaComponent(), ActionEvent.ACTION_PERFORMED, null));
if (!StringUtil.isEmpty(state.getAlpha())) {
stateComponent.getAlphaComponent().setVisible(true);
createAlpha.setVisible(false);
deleteAlpha.setVisible(true);
}
});
return popupMenu;
}
Aggregations