mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-01 02:38:21 +08:00
PL-7356 Cannot remove shortcut from Action programmatically
This commit is contained in:
parent
4bf6fd3c3a
commit
22847bce3d
@ -348,7 +348,7 @@ public abstract class DesktopAbstractTable<C extends JXTable, E extends Entity>
|
||||
|
||||
protected Action getEnterAction() {
|
||||
for (Action action : getActions()) {
|
||||
KeyCombination kc = action.getShortcut();
|
||||
KeyCombination kc = action.getShortcutCombination();
|
||||
if (kc != null) {
|
||||
if ((kc.getModifiers() == null || kc.getModifiers().length == 0)
|
||||
&& kc.getKey() == KeyCombination.Key.ENTER) {
|
||||
@ -1959,8 +1959,8 @@ public abstract class DesktopAbstractTable<C extends JXTable, E extends Entity>
|
||||
if (action.getIcon() != null) {
|
||||
menuItem.setIcon(App.getInstance().getResources().getIcon(action.getIcon()));
|
||||
}
|
||||
if (action.getShortcut() != null) {
|
||||
menuItem.setAccelerator(convertKeyCombination(action.getShortcut()));
|
||||
if (action.getShortcutCombination() != null) {
|
||||
menuItem.setAccelerator(convertKeyCombination(action.getShortcutCombination()));
|
||||
}
|
||||
menuItem.setEnabled(action.isEnabled());
|
||||
menuItem.addActionListener(
|
||||
|
@ -99,8 +99,8 @@ public class DesktopButton extends DesktopAbstractComponent<JButton> implements
|
||||
}
|
||||
|
||||
String description = action.getDescription();
|
||||
if (description == null && action.getShortcut() != null) {
|
||||
description = action.getShortcut().format();
|
||||
if (description == null && action.getShortcutCombination() != null) {
|
||||
description = action.getShortcutCombination().format();
|
||||
}
|
||||
if (description != null && getDescription() == null) {
|
||||
setDescription(description);
|
||||
|
@ -31,7 +31,6 @@ import static com.haulmont.cuba.gui.ComponentsHelper.findActionById;
|
||||
/**
|
||||
* Encapsulates {@link com.haulmont.cuba.gui.components.Component.ActionsHolder} functionality for desktop frames and
|
||||
* windows.
|
||||
*
|
||||
*/
|
||||
public class DesktopFrameActionsHolder {
|
||||
|
||||
@ -64,8 +63,8 @@ public class DesktopFrameActionsHolder {
|
||||
}
|
||||
}
|
||||
|
||||
if (action.getShortcut() != null) {
|
||||
KeyStroke keyStroke = DesktopComponentsHelper.convertKeyCombination(action.getShortcut());
|
||||
if (action.getShortcutCombination() != null) {
|
||||
KeyStroke keyStroke = DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination());
|
||||
InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
inputMap.put(keyStroke, action.getId());
|
||||
ActionMap actionMap = panel.getActionMap();
|
||||
@ -83,7 +82,7 @@ public class DesktopFrameActionsHolder {
|
||||
|
||||
public void removeAction(Action action) {
|
||||
if (actionList.remove(action)) {
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
ActionMap actionMap = panel.getActionMap();
|
||||
KeyStroke keyStroke = shortcutActions.get(action);
|
||||
|
@ -490,10 +490,10 @@ public class DesktopPickerField extends DesktopAbstractField<Picker>
|
||||
}
|
||||
});
|
||||
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED);
|
||||
|
||||
KeyStroke shortcutKeyStroke = DesktopComponentsHelper.convertKeyCombination(action.getShortcut());
|
||||
KeyStroke shortcutKeyStroke = DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination());
|
||||
inputMap.put(shortcutKeyStroke, action.getId());
|
||||
}
|
||||
|
||||
|
@ -533,8 +533,8 @@ public class DesktopTree<E extends Entity> extends DesktopAbstractActionsHolderC
|
||||
if (action.getIcon() != null) {
|
||||
menuItem.setIcon(App.getInstance().getResources().getIcon(action.getIcon()));
|
||||
}
|
||||
if (action.getShortcut() != null) {
|
||||
menuItem.setAccelerator(DesktopComponentsHelper.convertKeyCombination(action.getShortcut()));
|
||||
if (action.getShortcutCombination() != null) {
|
||||
menuItem.setAccelerator(DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination()));
|
||||
}
|
||||
menuItem.setEnabled(action.isEnabled());
|
||||
menuItem.addActionListener(e -> action.actionPerform(DesktopTree.this));
|
||||
|
@ -1901,12 +1901,12 @@ public class DesktopWindowManager extends WindowManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyCombination getShortcut() {
|
||||
public KeyCombination getShortcutCombination() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortcut(KeyCombination shortcut) {
|
||||
public void setShortcutCombination(KeyCombination shortcut) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,12 +111,12 @@ public abstract class AbstractAction implements Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyCombination getShortcut() {
|
||||
public KeyCombination getShortcutCombination() {
|
||||
return shortcut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortcut(KeyCombination shortcut) {
|
||||
public void setShortcutCombination(KeyCombination shortcut) {
|
||||
KeyCombination oldValue = this.shortcut;
|
||||
if (!Objects.equals(oldValue, shortcut)) {
|
||||
this.shortcut = shortcut;
|
||||
@ -127,9 +127,9 @@ public abstract class AbstractAction implements Action {
|
||||
@Override
|
||||
public void setShortcut(String shortcut) {
|
||||
if (shortcut != null) {
|
||||
setShortcut(KeyCombination.create(shortcut));
|
||||
setShortcutCombination(KeyCombination.create(shortcut));
|
||||
} else {
|
||||
setShortcut((KeyCombination) null);
|
||||
setShortcutCombination(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,8 @@ public interface Action {
|
||||
*
|
||||
* @return action's shortcut
|
||||
*/
|
||||
KeyCombination getShortcut();
|
||||
void setShortcut(KeyCombination shortcut);
|
||||
KeyCombination getShortcutCombination();
|
||||
void setShortcutCombination(KeyCombination shortcut);
|
||||
|
||||
/**
|
||||
* Set shortcut from string representation.
|
||||
|
@ -26,7 +26,6 @@ import java.util.Map;
|
||||
* Handles active shortcuts for actions holder (Table or Tree)
|
||||
*
|
||||
* @param <T> type of shortcut descriptor
|
||||
*
|
||||
*/
|
||||
public abstract class ShortcutsDelegate<T> {
|
||||
|
||||
@ -43,10 +42,10 @@ public abstract class ShortcutsDelegate<T> {
|
||||
}
|
||||
|
||||
public void addAction(@Nullable Action oldAction, Action newAction) {
|
||||
KeyCombination newShortcut = newAction.getShortcut();
|
||||
KeyCombination newShortcut = newAction.getShortcutCombination();
|
||||
if (newShortcut != null) {
|
||||
if (oldAction != null) {
|
||||
KeyCombination oldShortcut = oldAction.getShortcut();
|
||||
KeyCombination oldShortcut = oldAction.getShortcutCombination();
|
||||
if (newShortcut.equals(oldShortcut)) {
|
||||
removeShortcut(oldAction);
|
||||
} else if (oldShortcut != null) {
|
||||
@ -59,7 +58,7 @@ public abstract class ShortcutsDelegate<T> {
|
||||
addShortcut(newAction.getId(), newShortcut);
|
||||
} else {
|
||||
if (oldAction != null) {
|
||||
KeyCombination oldShortcut = oldAction.getShortcut();
|
||||
KeyCombination oldShortcut = oldAction.getShortcutCombination();
|
||||
if (oldShortcut != null) {
|
||||
removeShortcut(oldAction);
|
||||
// find and assign alternative
|
||||
@ -73,8 +72,8 @@ public abstract class ShortcutsDelegate<T> {
|
||||
if (action != null) {
|
||||
removeShortcut(action);
|
||||
// find and assign alternative
|
||||
if (action.getShortcut() != null) {
|
||||
addAlternativeShortcut(action.getShortcut());
|
||||
if (action.getShortcutCombination() != null) {
|
||||
addAlternativeShortcut(action.getShortcutCombination());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,12 +82,12 @@ public abstract class ShortcutsDelegate<T> {
|
||||
Action alternativeAction = null;
|
||||
for (Action action : getActions()) {
|
||||
// find last action with same shortcut
|
||||
if (kc.equals(action.getShortcut())) {
|
||||
if (kc.equals(action.getShortcutCombination())) {
|
||||
alternativeAction = action;
|
||||
}
|
||||
}
|
||||
if (alternativeAction != null) {
|
||||
addShortcut(alternativeAction.getId(), alternativeAction.getShortcut());
|
||||
addShortcut(alternativeAction.getId(), alternativeAction.getShortcutCombination());
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +106,7 @@ public abstract class ShortcutsDelegate<T> {
|
||||
}
|
||||
|
||||
for (Action oldAction : getActions()) {
|
||||
if (keyCombination.equals(oldAction.getShortcut())) {
|
||||
if (keyCombination.equals(oldAction.getShortcutCombination())) {
|
||||
removeShortcut(oldAction);
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class WebWindow implements Window, Component.Wrapper,
|
||||
actionsPermissions.apply(action);
|
||||
|
||||
// force update of actions on client side
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
component.markAsDirty();
|
||||
}
|
||||
}
|
||||
@ -257,7 +257,7 @@ public class WebWindow implements Window, Component.Wrapper,
|
||||
actionsPermissions.apply(action);
|
||||
|
||||
// force update of actions on client side
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
component.markAsDirty();
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ public abstract class ContextMenuButton extends WebButton {
|
||||
if (action != null) {
|
||||
String caption = action.getCaption();
|
||||
if (!StringUtils.isEmpty(caption)) {
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(caption);
|
||||
if (action.getShortcut() != null) {
|
||||
sb.append(" (").append(action.getShortcut().format()).append(")");
|
||||
if (action.getShortcutCombination() != null) {
|
||||
sb.append(" (").append(action.getShortcutCombination().format()).append(")");
|
||||
}
|
||||
caption = sb.toString();
|
||||
component.setCaption(caption);
|
||||
@ -60,11 +60,11 @@ public abstract class ContextMenuButton extends WebButton {
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(caption);
|
||||
if (action.getShortcut() != null) {
|
||||
sb.append(" (").append(action.getShortcut().format()).append(")");
|
||||
if (action.getShortcutCombination() != null) {
|
||||
sb.append(" (").append(action.getShortcutCombination().format()).append(")");
|
||||
}
|
||||
caption = sb.toString();
|
||||
}
|
||||
|
@ -690,7 +690,7 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
|
||||
|
||||
protected Action getEnterAction() {
|
||||
for (Action action : getActions()) {
|
||||
KeyCombination kc = action.getShortcut();
|
||||
KeyCombination kc = action.getShortcutCombination();
|
||||
if (kc != null) {
|
||||
if ((kc.getModifiers() == null || kc.getModifiers().length == 0)
|
||||
&& kc.getKey() == KeyCombination.Key.ENTER) {
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Action;
|
||||
|
||||
/**
|
||||
* {@link Action} adapter for web client.
|
||||
*
|
||||
*/
|
||||
class WebActionWrapper extends com.vaadin.event.Action {
|
||||
|
||||
private final Action action;
|
||||
|
||||
public WebActionWrapper(Action action) {
|
||||
super(""); // don't invoke action.getCaption() here as it may not be properly initialized at the moment
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(action.getCaption());
|
||||
if (action.getShortcut() != null) {
|
||||
sb.append(" (").append(action.getShortcut().format()).append(")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -98,8 +98,8 @@ public class WebButton extends WebAbstractComponent<CubaButton> implements Butto
|
||||
}
|
||||
|
||||
String description = action.getDescription();
|
||||
if (description == null && action.getShortcut() != null) {
|
||||
description = action.getShortcut().format();
|
||||
if (description == null && action.getShortcutCombination() != null) {
|
||||
description = action.getShortcutCombination().format();
|
||||
}
|
||||
if (description != null && component.getDescription() == null) {
|
||||
component.setDescription(description);
|
||||
|
@ -309,7 +309,7 @@ public class WebComponentsHelper {
|
||||
}
|
||||
|
||||
public static com.vaadin.event.ShortcutAction createShortcutAction(com.haulmont.cuba.gui.components.Action action) {
|
||||
KeyCombination keyCombination = action.getShortcut();
|
||||
KeyCombination keyCombination = action.getShortcutCombination();
|
||||
if (keyCombination != null) {
|
||||
return new com.vaadin.event.ShortcutAction(
|
||||
action.getCaption(),
|
||||
|
@ -32,7 +32,6 @@ import static com.haulmont.cuba.gui.ComponentsHelper.findActionById;
|
||||
/**
|
||||
* Encapsulates {@link com.haulmont.cuba.gui.components.Component.ActionsHolder} functionality for web frames and
|
||||
* windows.
|
||||
*
|
||||
*/
|
||||
public class WebFrameActionsHolder {
|
||||
|
||||
@ -57,7 +56,7 @@ public class WebFrameActionsHolder {
|
||||
}
|
||||
}
|
||||
|
||||
if (action.getShortcut() != null) {
|
||||
if (action.getShortcutCombination() != null) {
|
||||
actions.put(WebComponentsHelper.createShortcutAction(action), action);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class WebPickerFieldActionHandler implements Action.Handler {
|
||||
|
||||
updateOrderedShortcuts();
|
||||
|
||||
KeyCombination combination = action.getShortcut();
|
||||
KeyCombination combination = action.getShortcutCombination();
|
||||
if (combination != null) {
|
||||
int key = combination.getKey().getCode();
|
||||
int[] modifiers = KeyCombination.Modifier.codes(combination.getModifiers());
|
||||
|
@ -26,7 +26,6 @@ import com.haulmont.cuba.web.toolkit.ui.CubaPopupButton;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaPopupButtonLayout;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.BaseTheme;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -414,12 +413,12 @@ public class WebPopupButton extends WebAbstractComponent<CubaPopupButton>
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyCombination getShortcut() {
|
||||
public KeyCombination getShortcutCombination() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortcut(KeyCombination shortcut) {
|
||||
public void setShortcutCombination(KeyCombination shortcut) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user