use of org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent in project zaproxy by zaproxy.
the class MainPopupMenu method setVisible.
/**
* {@inheritDoc}
* <p>
* Overridden to call the method {@code ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)} of child
* {@code ExtensionPopupMenuComponent}s when the pop up menu is hidden.
*
* @see ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)
*/
@Override
public void setVisible(boolean b) {
super.setVisible(b);
if (!b) {
ExtensionPopupMenuComponent selectedMenuComponent = null;
if (pathSelectedMenu != null) {
MenuElement selectedMenuElement = pathSelectedMenu[pathSelectedMenu.length - 1];
if (PopupMenuUtils.isExtensionPopupMenuComponent(selectedMenuElement)) {
selectedMenuComponent = (ExtensionPopupMenuComponent) selectedMenuElement;
}
pathSelectedMenu = null;
}
for (int i = 0; i < getComponentCount(); i++) {
Component component = getComponent(i);
if (PopupMenuUtils.isExtensionPopupMenuComponent(component)) {
((ExtensionPopupMenuComponent) component).dismissed(selectedMenuComponent);
}
}
}
}
use of org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent in project zaproxy by zaproxy.
the class ExtensionPopupMenu method processExtensionPopupChildren.
/**
* Returns {@code true} if at least one of the child {@code ExtensionPopupMenuComponent}s is enable, {@code false}
* otherwise.
* <p>
* The method {@code isEnableForComponent(Component)} or {@code isEnableForMessageContainer(MessageContainer)}, depending on
* actual implementation of the given {@code invokerWrapper}, is called on all child {@code ExtensionPopupMenuComponent}s.
* </p>
* <p>
* All the child menus that implement {@code ExtensionPopupMenuComponent} will have the methods
* {@code precedeWithSeparator()}, {@code succeedWithSeparator()}, {@code getMenuIndex()} and {@code isSafe()} honoured,
* with the following caveats:
* <ul>
* <li>{@code precedeWithSeparator()} - the separator will only be added if there's already a menu component in the menu and
* if it is not a separator;</li>
* <li>{@code succeedWithSeparator()} - the separator will be added always but removed if there's no item following it when
* the menu is ready to be shown;</li>
* <li>{@code getMenuIndex()} - the menu index will be honoured only if the method {@code isOrderChildren()} returns
* {@code true};</li>
* </ul>
* The separators will be dynamically added and removed as needed when the pop up menu is shown.
*
* @param invokerWrapper the wrapped invoker
* @return {@code true} if at least one of the child items is enable, {@code false} otherwise.
* @see #isOrderChildren()
* @see ExtensionPopupMenuComponent
* @see ExtensionPopupMenuComponent#isEnableForComponent(Component)
* @see ExtensionPopupMenuComponent#isEnableForMessageContainer(MessageContainer)
* @see ExtensionPopupMenuComponent#precedeWithSeparator()
* @see ExtensionPopupMenuComponent#succeedWithSeparator()
* @see ExtensionPopupMenuComponent#isSafe()
* @see ExtensionPopupMenuComponent#getMenuIndex()
*/
protected boolean processExtensionPopupChildren(PopupMenuUtils.PopupMenuInvokerWrapper invokerWrapper) {
if (isOrderChildren()) {
PopupMenuUtils.removeAllSeparators(this);
List<ExtensionPopupMenuComponent> components = new ArrayList<>();
for (int i = 0; i < getMenuComponentCount(); i++) {
Component component = getMenuComponent(i);
if (PopupMenuUtils.isExtensionPopupMenuComponent(component)) {
ExtensionPopupMenuComponent menuComponent = (ExtensionPopupMenuComponent) component;
if (menuComponent.getMenuIndex() >= 0) {
components.add(menuComponent);
remove(i);
i--;
}
}
}
Collections.sort(components, new Comparator<ExtensionPopupMenuComponent>() {
@Override
public int compare(ExtensionPopupMenuComponent component, ExtensionPopupMenuComponent otherComponent) {
if (component.getMenuIndex() > otherComponent.getMenuIndex()) {
return 1;
} else if (component.getMenuIndex() < otherComponent.getMenuIndex()) {
return -1;
}
return 0;
}
;
});
for (int i = 0; i < components.size(); i++) {
ExtensionPopupMenuComponent component = components.get(i);
int index = Math.max(component.getMenuIndex(), i);
if (index >= getMenuComponentCount()) {
add((Component) component);
} else {
getPopupMenu().insert((Component) component, index);
}
}
}
boolean childEnable = false;
Control.Mode mode = Control.getSingleton().getMode();
for (int i = 0; i < getMenuComponentCount(); ++i) {
Component menuComponent = getMenuComponent(i);
if (PopupMenuUtils.isExtensionPopupMenuComponent(menuComponent)) {
ExtensionPopupMenuComponent extensionMenuComponent = (ExtensionPopupMenuComponent) menuComponent;
boolean enable = invokerWrapper.isEnable(extensionMenuComponent);
if (enable && !extensionMenuComponent.isSafe() && mode.equals(Control.Mode.safe)) {
menuComponent.setEnabled(false);
continue;
}
if (enable) {
childEnable = true;
if (extensionMenuComponent.precedeWithSeparator()) {
if (PopupMenuUtils.insertSeparatorIfNeeded(this, i)) {
i++;
}
}
}
menuComponent.setVisible(enable);
if (enable && extensionMenuComponent.succeedWithSeparator()) {
if (PopupMenuUtils.insertSeparatorIfNeeded(this, i + 1)) {
i++;
}
}
}
}
PopupMenuUtils.removeTopAndBottomSeparators(this);
return childEnable;
}
Aggregations