ItEr30S15RFVisualizacionMultiplesProxectosItEr29S18: When changing of tab calling directly the show method of TabsRegistr, the selected menu button is changed.
This commit is contained in:
parent
12742e2a39
commit
59c2fed86b
3 changed files with 40 additions and 9 deletions
|
|
@ -21,7 +21,9 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zkoss.ganttz.extensions.ITab;
|
||||
import org.zkoss.ganttz.util.IMenuItemsRegister;
|
||||
|
|
@ -35,6 +37,10 @@ public class TabsRegistry {
|
|||
|
||||
private final Component parent;
|
||||
|
||||
private Map<ITab, Object> fromTabToMenuKey = new HashMap<ITab, Object>();
|
||||
|
||||
private IMenuItemsRegister menu;
|
||||
|
||||
public TabsRegistry(Component parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
|
@ -48,6 +54,13 @@ public class TabsRegistry {
|
|||
hideAllExcept(tab);
|
||||
tab.show();
|
||||
parent.invalidate();
|
||||
activateMenuIfRegistered(tab);
|
||||
}
|
||||
|
||||
private void activateMenuIfRegistered(ITab tab) {
|
||||
if (fromTabToMenuKey.containsKey(tab)) {
|
||||
menu.activateMenuItem(fromTabToMenuKey.get(tab));
|
||||
}
|
||||
}
|
||||
|
||||
private void hideAllExcept(ITab tab) {
|
||||
|
|
@ -65,14 +78,16 @@ public class TabsRegistry {
|
|||
}
|
||||
|
||||
public void registerAtMenu(IMenuItemsRegister menu) {
|
||||
this.menu = menu;
|
||||
for (final ITab t : tabs) {
|
||||
menu.addMenuItem(t.getName(), new EventListener() {
|
||||
Object key = menu.addMenuItem(t.getName(), new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
show(t);
|
||||
}
|
||||
});
|
||||
fromTabToMenuKey.put(t, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ package org.zkoss.ganttz.util;
|
|||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
||||
public interface IMenuItemsRegister {
|
||||
/**
|
||||
* @return a key to access the new menu item
|
||||
*/
|
||||
public Object addMenuItem(String name, EventListener eventListener);
|
||||
|
||||
public void addMenuItem(String name, EventListener eventListener);
|
||||
public void activateMenuItem(Object key);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
|
|||
private Button currentOne = null;
|
||||
|
||||
@Override
|
||||
public void addMenuItem(String name,
|
||||
public Object addMenuItem(String name,
|
||||
org.zkoss.zk.ui.event.EventListener eventListener) {
|
||||
Hbox insertionPoint = getRegisteredItemsInsertionPoint();
|
||||
Button button = new Button();
|
||||
|
|
@ -217,7 +217,12 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
|
|||
eventListener));
|
||||
insertionPoint.appendChild(button);
|
||||
insertionPoint.appendChild(separator());
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateMenuItem(Object key) {
|
||||
switchCurrentButtonTo((Button) key);
|
||||
}
|
||||
|
||||
private void setSelectClass(final Button button) {
|
||||
|
|
@ -237,12 +242,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
|
|||
if (currentOne == button) {
|
||||
return;
|
||||
}
|
||||
if (currentOne != null) {
|
||||
currentOne.setSclass("sub_menu");
|
||||
setDeselectedClass(currentOne);
|
||||
}
|
||||
setSelectClass(button);
|
||||
currentOne = button;
|
||||
switchCurrentButtonTo(button);
|
||||
originalListener.onEvent(event);
|
||||
}
|
||||
};
|
||||
|
|
@ -258,4 +258,16 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
|
|||
return Executions.getCurrent().getContextPath();
|
||||
}
|
||||
|
||||
private void switchCurrentButtonTo(final Button button) {
|
||||
if (currentOne == button) {
|
||||
return;
|
||||
}
|
||||
if (currentOne != null) {
|
||||
currentOne.setSclass("sub_menu");
|
||||
setDeselectedClass(currentOne);
|
||||
}
|
||||
setSelectClass(button);
|
||||
currentOne = button;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue