mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more control for action buttons
This commit is contained in:
+73
-85
@@ -264,51 +264,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
private JComponent createTableWithButtons() {
|
||||
final boolean isAnalyzeShown = ((ApplicationEx)ApplicationManager.getApplication()).isInternal();
|
||||
|
||||
final AnActionButton addButton = new AnActionButton(ProjectBundle.message("button.add"), null, IconUtil.getAddRowIcon()) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
initPopupActions();
|
||||
final JBPopup popup = JBPopupFactory.getInstance().createListPopup(
|
||||
new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
|
||||
@Override
|
||||
public Icon getIconFor(AddItemPopupAction<?> aValue) {
|
||||
return aValue.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
|
||||
return selectedValue.hasSubStep();
|
||||
}
|
||||
|
||||
public boolean isMnemonicsNavigationEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
|
||||
if (selectedValue.hasSubStep()) {
|
||||
return selectedValue.createSubStep();
|
||||
}
|
||||
return doFinalStep(new Runnable() {
|
||||
public void run() {
|
||||
selectedValue.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTextFor(AddItemPopupAction<?> value) {
|
||||
return "&" + value.getIndex() + " " + value.getTitle();
|
||||
}
|
||||
});
|
||||
final RelativePoint point = getPreferredPopupPoint();
|
||||
if (point == null) {
|
||||
popup.showInBestPositionFor(e.getDataContext());
|
||||
} else {
|
||||
popup.show(point);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final ClasspathPanelAction removeAction = new ClasspathPanelAction(this) {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -333,13 +288,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
};
|
||||
|
||||
final AnActionButton removeButton = new AnActionButton(ProjectBundle.message("button.remove"), null, IconUtil.getRemoveRowIcon()) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
removeAction.actionPerformed(null);
|
||||
}
|
||||
};
|
||||
|
||||
myEditButton = new AnActionButton(ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
@@ -363,19 +311,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
};
|
||||
|
||||
final AnActionButton upButton = new AnActionButton(ProjectBundle.message("module.classpath.button.move.up"), null, IconUtil.getMoveRowUpIcon()) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
moveSelectedRows(-1);
|
||||
}
|
||||
};
|
||||
|
||||
final AnActionButton downButton = new AnActionButton(ProjectBundle.message("module.classpath.button.move.down"), null, IconUtil.getMoveRowDownIcon()) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
moveSelectedRows(+1);
|
||||
}
|
||||
};
|
||||
|
||||
final AnActionButton analyzeButton = new AnActionButton(ProjectBundle.message("classpath.panel.analyze"), null, SystemInfo.isMac ? PlatformIcons.TABLE_ANALYZE : PlatformIcons.ANALYZE) {
|
||||
@Override
|
||||
@@ -384,6 +319,77 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
};
|
||||
|
||||
//addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
|
||||
//removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
|
||||
//upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
|
||||
//downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
|
||||
myEntryTable.setBorder(new LineBorder(UIUtil.getBorderColor()));
|
||||
|
||||
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
|
||||
decorator
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
initPopupActions();
|
||||
final JBPopup popup = JBPopupFactory.getInstance().createListPopup(
|
||||
new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
|
||||
@Override
|
||||
public Icon getIconFor(AddItemPopupAction<?> aValue) {
|
||||
return aValue.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
|
||||
return selectedValue.hasSubStep();
|
||||
}
|
||||
|
||||
public boolean isMnemonicsNavigationEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
|
||||
if (selectedValue.hasSubStep()) {
|
||||
return selectedValue.createSubStep();
|
||||
}
|
||||
return doFinalStep(new Runnable() {
|
||||
public void run() {
|
||||
selectedValue.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTextFor(AddItemPopupAction<?> value) {
|
||||
return "&" + value.getIndex() + " " + value.getTitle();
|
||||
}
|
||||
});
|
||||
popup.show(button.getPreferredPopupPoint());
|
||||
}
|
||||
})
|
||||
.setRemoveAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
removeAction.actionPerformed(null);
|
||||
}
|
||||
})
|
||||
.setUpAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
moveSelectedRows(-1);
|
||||
}
|
||||
})
|
||||
.setDownAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
moveSelectedRows(+1);
|
||||
}
|
||||
})
|
||||
.addExtraAction(myEditButton);
|
||||
if (isAnalyzeShown) {
|
||||
decorator.addExtraAction(analyzeButton);
|
||||
}
|
||||
final JPanel panel = decorator.createPanel();
|
||||
|
||||
myEntryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (e.getValueIsAdjusting()) {
|
||||
@@ -401,31 +407,13 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
removeButtonEnabled = false;
|
||||
}
|
||||
}
|
||||
upButton.setEnabled(minRow > 0 && minRow < myEntryTable.getRowCount());
|
||||
downButton.setEnabled(maxRow >= 0 && maxRow < myEntryTable.getRowCount() - 1);
|
||||
removeButton.setEnabled(removeButtonEnabled);
|
||||
ToolbarDecorator.findRemoveButton(panel).setEnabled(removeButtonEnabled);
|
||||
ClasspathTableItem<?> selectedItem = selectedRows.length == 1 ? myModel.getItemAt(selectedRows[0]) : null;
|
||||
myEditButton.setEnabled(selectedItem != null && selectedItem.isEditable());
|
||||
}
|
||||
});
|
||||
|
||||
addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
|
||||
removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
|
||||
upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
|
||||
downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
|
||||
myEntryTable.setBorder(new LineBorder(UIUtil.getBorderColor()));
|
||||
|
||||
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
|
||||
decorator
|
||||
.addExtraAction(addButton)
|
||||
.addExtraAction(removeButton)
|
||||
.addExtraAction(upButton)
|
||||
.addExtraAction(downButton)
|
||||
.addExtraAction(myEditButton);
|
||||
if (isAnalyzeShown) {
|
||||
decorator.addExtraAction(analyzeButton);
|
||||
}
|
||||
return decorator.createPanel();
|
||||
return panel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -175,13 +175,21 @@ class AddRemoveUpDownPanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final JComponent component = getContextComponent();
|
||||
if (myButton != Buttons.ADD && component != null) {
|
||||
if ((component instanceof JTable && ((JTable)component).getRowCount() == 0)
|
||||
|| (component instanceof JList && ((JList)component).getModel().getSize() == 0)) {
|
||||
final JComponent c = getContextComponent();
|
||||
if (c instanceof JTable || c instanceof JList) {
|
||||
final ListSelectionModel model = c instanceof JTable ? ((JTable)c).getSelectionModel()
|
||||
: ((JList)c).getSelectionModel();
|
||||
final int size = c instanceof JTable ? ((JTable)c).getRowCount()
|
||||
: ((JList)c).getModel().getSize();
|
||||
final int min = model.getMinSelectionIndex();
|
||||
final int max = model.getMaxSelectionIndex();
|
||||
|
||||
if ((myButton == Buttons.UP && min < 1)
|
||||
|| (myButton == Buttons.DOWN && max == size - 1)
|
||||
|| (myButton != Buttons.ADD && size == 0)) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
} else {
|
||||
e.getPresentation().setEnabled(true);
|
||||
e.getPresentation().setEnabled(isEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,4 +480,29 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static AnActionButton findAddButton(@NotNull JComponent container) {
|
||||
return findButton(container, AddRemoveUpDownPanel.Buttons.ADD);
|
||||
}
|
||||
|
||||
public static AnActionButton findRemoveButton(@NotNull JComponent container) {
|
||||
return findButton(container, AddRemoveUpDownPanel.Buttons.REMOVE);
|
||||
}
|
||||
|
||||
public static AnActionButton findUpButton(@NotNull JComponent container) {
|
||||
return findButton(container, AddRemoveUpDownPanel.Buttons.UP);
|
||||
}
|
||||
|
||||
public static AnActionButton findDownButton(@NotNull JComponent container) {
|
||||
return findButton(container, AddRemoveUpDownPanel.Buttons.DOWN);
|
||||
}
|
||||
|
||||
|
||||
private static AnActionButton findButton(JComponent comp, AddRemoveUpDownPanel.Buttons type) {
|
||||
final AddRemoveUpDownPanel panel = UIUtil.findComponentOfType(comp, AddRemoveUpDownPanel.class);
|
||||
if (panel != null) {
|
||||
return panel.getAnActionButton(type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user