ItEr30S15RFVisualizacionMultiplesProxectosItEr29S18: When type changes the tab being shown changes too
This commit is contained in:
parent
4277d7451d
commit
b7a76ecc03
2 changed files with 62 additions and 2 deletions
|
|
@ -19,6 +19,9 @@
|
|||
*/
|
||||
package org.navalplanner.web.planner.tabs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
|
||||
|
|
@ -36,6 +39,20 @@ public class Mode {
|
|||
return new Mode(new OrderCase(order));
|
||||
}
|
||||
|
||||
public interface ModeTypeChangedListener {
|
||||
public void typeChanged(ModeType oldType, ModeType newType);
|
||||
}
|
||||
|
||||
private List<ModeTypeChangedListener> listeners = new ArrayList<ModeTypeChangedListener>();
|
||||
|
||||
public void addListener(ModeTypeChangedListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ModeTypeChangedListener listener) {
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
private ModeCase current;
|
||||
|
||||
Mode(ModeCase current) {
|
||||
|
|
@ -48,7 +65,28 @@ public class Mode {
|
|||
}
|
||||
|
||||
public void goToOrderMode(Order order) {
|
||||
current = current.createOrderMode(order);
|
||||
changeTo(current.createOrderMode(order));
|
||||
}
|
||||
|
||||
private void changeTo(ModeCase newCase) {
|
||||
if (current == newCase) {
|
||||
return;
|
||||
}
|
||||
ModeType previousType = current.getModeType();
|
||||
current = newCase;
|
||||
ModeType newType = current.getModeType();
|
||||
if (previousType != newType) {
|
||||
fireModeTypeChanged(previousType);
|
||||
}
|
||||
}
|
||||
|
||||
private void fireModeTypeChanged(ModeType previousType) {
|
||||
Validate.notNull(previousType);
|
||||
ModeType newType = this.getType();
|
||||
Validate.notNull(newType);
|
||||
for (ModeTypeChangedListener listener : listeners) {
|
||||
listener.typeChanged(previousType, newType);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOf(ModeType type) {
|
||||
|
|
@ -56,7 +94,7 @@ public class Mode {
|
|||
}
|
||||
|
||||
public void up() {
|
||||
current = current.up();
|
||||
changeTo(current.up());
|
||||
}
|
||||
|
||||
public ModeType getType() {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.Collection;
|
|||
import java.util.EnumMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.web.planner.tabs.Mode.ModeTypeChangedListener;
|
||||
import org.zkoss.ganttz.extensions.ITab;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
|
|
@ -37,6 +38,8 @@ public class TabOnModeType implements ITab {
|
|||
|
||||
private final EnumMap<ModeType, ITab> tabs;
|
||||
|
||||
private boolean beingShown = false;
|
||||
|
||||
public static WithType forMode(Mode mode) {
|
||||
return new WithType(mode, new EnumMap<ModeType, ITab>(ModeType.class));
|
||||
}
|
||||
|
|
@ -68,6 +71,23 @@ public class TabOnModeType implements ITab {
|
|||
+ tabs.keySet());
|
||||
this.mode = mode;
|
||||
this.tabs = new EnumMap<ModeType, ITab>(tabs);
|
||||
this.mode.addListener(new ModeTypeChangedListener() {
|
||||
|
||||
@Override
|
||||
public void typeChanged(ModeType oldType, ModeType newType) {
|
||||
if (beingShown) {
|
||||
changeTab(oldType, newType);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void changeTab(ModeType oldType, ModeType newType) {
|
||||
ITab previousTab = tabs.get(oldType);
|
||||
previousTab.hide();
|
||||
ITab newTab = tabs.get(newType);
|
||||
newTab.show();
|
||||
}
|
||||
|
||||
private boolean handleAllCases(EnumMap<ModeType, ITab> tabs) {
|
||||
|
|
@ -98,11 +118,13 @@ public class TabOnModeType implements ITab {
|
|||
|
||||
@Override
|
||||
public void hide() {
|
||||
beingShown = false;
|
||||
getCurrentTab().hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
beingShown = true;
|
||||
getCurrentTab().show();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue