/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gwtoolbox.sample.ioc.client;
import java.util.HashMap;
import java.util.Map;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.Widget;
import org.gwtoolbox.ioc.core.client.Initializable;
import org.gwtoolbox.ioc.core.client.annotation.EventHandler;
import org.gwtoolbox.ioc.core.client.annotation.RootPanelBinding;
import org.gwtoolbox.sample.ioc.client.event.MessageEvent;
/**
* @author Uri Boness
*/
@RootPanelBinding
public class MainPane extends Composite implements Initializable {
private Map<String, Map<String,Widget>> widgetByName;
private String widgetsName;
private DecoratedTabPanel content;
private Alerter alerter;
public MainPane() {
content = new DecoratedTabPanel();
content.addSelectionHandler(new SelectionHandler<Integer>() {
public void onSelection(SelectionEvent<Integer> event) {
alerter.alert("Selected '" + content.getTabBar().getTabHTML(event.getSelectedItem()) + "'");
}
});
widgetByName = new HashMap<String, Map<String, Widget>>();
initWidget(content);
}
public void init() throws Exception {
Map<String, Widget> widgets = widgetByName.get(widgetsName);
for (Map.Entry<String, Widget> entry : widgets.entrySet()) {
String name = entry.getKey();
Widget widget = entry.getValue();
content.add(widget, name);
}
}
@EventHandler
public void handle(MessageEvent event) {
alerter.alert(event.getMessage());
}
//============================================== Setter/Getter =====================================================
public void setWidgetByName(Map<String, Map<String, Widget>> widgetByName) {
this.widgetByName = widgetByName;
}
public void setWidgetsName(String widgetsName) {
this.widgetsName = widgetsName;
}
public void setAlerter(Alerter alerter) {
this.alerter = alerter;
}
}