1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.component;
21
22 import org.apache.myfaces.tobago.internal.layout.Interval;
23 import org.apache.myfaces.tobago.internal.layout.IntervalList;
24 import org.apache.myfaces.tobago.internal.layout.LayoutUtils;
25 import org.apache.myfaces.tobago.layout.LayoutComponent;
26 import org.apache.myfaces.tobago.layout.LayoutContainer;
27 import org.apache.myfaces.tobago.layout.LayoutManager;
28 import org.apache.myfaces.tobago.layout.Measure;
29 import org.apache.myfaces.tobago.layout.Orientation;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public abstract class AbstractUITabGroupLayout extends AbstractUILayoutBase implements LayoutManager {
34
35 private static final Logger LOG = LoggerFactory.getLogger(AbstractUIGridLayout.class);
36
37 private boolean horizontalAuto;
38 private boolean verticalAuto;
39
40 public void init() {
41 for (LayoutComponent component : getLayoutContainer().getComponents()) {
42 if (component instanceof LayoutContainer) {
43 ((LayoutContainer) component).getLayoutManager().init();
44 }
45 }
46 }
47
48 public void fixRelativeInsideAuto(Orientation orientation, boolean auto) {
49
50 if (orientation == Orientation.HORIZONTAL) {
51 horizontalAuto = auto;
52 } else {
53 verticalAuto = auto;
54 }
55
56 for (LayoutComponent component : getLayoutContainer().getComponents()) {
57 if (component instanceof LayoutContainer) {
58 ((LayoutContainer) component).getLayoutManager().fixRelativeInsideAuto(orientation, auto);
59 }
60 }
61 }
62
63 public void preProcessing(Orientation orientation) {
64
65
66 IntervalList intervals = new IntervalList();
67 for (LayoutComponent component : getLayoutContainer().getComponents()) {
68
69 if (component instanceof LayoutContainer) {
70 ((LayoutContainer) component).getLayoutManager().preProcessing(orientation);
71 }
72
73 if (orientation == Orientation.HORIZONTAL && horizontalAuto
74 || orientation == Orientation.VERTICAL && verticalAuto) {
75 intervals.add(new Interval(component, orientation));
76 }
77 }
78
79 if (intervals.size() >= 1) {
80 intervals.evaluate();
81 Measure size = intervals.getCurrent();
82
83
84
85
86 LayoutUtils.setCurrentSize(orientation, getLayoutContainer(), size);
87 }
88 }
89
90 public void mainProcessing(Orientation orientation) {
91
92
93 if (orientation == Orientation.HORIZONTAL && !horizontalAuto
94 || orientation == Orientation.VERTICAL && !verticalAuto) {
95
96 LayoutContainer container = getLayoutContainer();
97 Measure available = LayoutUtils.getCurrentSize(orientation, container);
98 if (available != null) {
99 for (LayoutComponent component : getLayoutContainer().getComponents()) {
100 LayoutUtils.setCurrentSize(orientation, component, available);
101 }
102 } else {
103 LOG.warn("No width/height set but needed for *!");
104 }
105 }
106
107
108 for (LayoutComponent component : getLayoutContainer().getComponents()) {
109 if (component instanceof LayoutContainer) {
110 ((LayoutContainer) component).getLayoutManager().mainProcessing(orientation);
111 }
112 }
113 }
114
115 public void postProcessing(Orientation orientation) {
116
117
118 for (LayoutComponent component : getLayoutContainer().getComponents()) {
119
120 if (component instanceof LayoutContainer) {
121 ((LayoutContainer) component).getLayoutManager().postProcessing(orientation);
122 }
123
124
125 }
126 }
127
128 private LayoutContainer getLayoutContainer() {
129
130 return ((LayoutContainer) getParent());
131 }
132
133 @Override
134 public boolean getRendersChildren() {
135 return false;
136 }
137 }