01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package org.romaframework.aspect.view.echo2.area.impl;
16:
17: import nextapp.echo2.app.Color;
18: import nextapp.echo2.app.Component;
19:
20: import org.romaframework.aspect.view.echo2.area.AbstractComponentAreaMode;
21: import org.romaframework.aspect.view.echo2.component.DynaWidget;
22: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
23: import org.romaframework.core.flow.ObjectContext;
24:
25: import tucana.echo2.app.WidgetDash;
26: import tucana.echo2.app.widgetdash.WidgetIdentifier;
27: import tucana.echo2.app.widgetdash.WidgetPosition;
28:
29: public class DashboardAreaMode extends AbstractComponentAreaMode {
30:
31: private static final String LAST_COLUMN_PAR = "lastColumn";
32:
33: public Object createComponent(int iSize) {
34: WidgetDash widgetDash = new WidgetDash();
35: widgetDash.setColumnCount(iSize);
36: widgetDash.setProperty(LAST_COLUMN_PAR, -1);
37:
38: ObjectContext.getInstance().getComponent(
39: LookAndFeelManager.class).assignStyle(widgetDash);
40:
41: return widgetDash;
42: }
43:
44: @Override
45: public String toString() {
46: return "dashboard";
47: }
48:
49: @Override
50: public Object placeComponent(Object iComponentContainer,
51: Object iComponentToPlace) {
52: WidgetIdentifier id = new WidgetIdentifier("widget"
53: + iComponentToPlace);
54:
55: WidgetDash dash = (WidgetDash) iComponentContainer;
56:
57: int col = updateCurrentColumnNumber(dash);
58:
59: DynaWidget container = new DynaWidget(id,
60: (Component) iComponentToPlace, "");
61: container.setWidgetPosition(new WidgetPosition(col, dash
62: .getComponentCount()));
63: container.setBackground(Color.BLUE);
64:
65: ObjectContext.getInstance().getComponent(
66: LookAndFeelManager.class).assignStyle(container);
67:
68: return super .placeComponent(iComponentContainer, container);
69: }
70:
71: /**
72: * Update current column where to render next component based on column number.
73: *
74: * @param dash
75: * @return
76: */
77: private int updateCurrentColumnNumber(WidgetDash dash) {
78: int col = (Integer) dash.getProperty(LAST_COLUMN_PAR);
79: if (col >= dash.getColumnCount() - 1)
80: col = 0;
81: else
82: ++col;
83:
84: dash.setProperty(LAST_COLUMN_PAR, col);
85: return col;
86: }
87: }
|