/*
* 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 com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import org.gwtoolbox.ioc.core.client.Disposable;
import org.gwtoolbox.ioc.core.client.Initializable;
import org.gwtoolbox.ioc.core.client.annotation.Inject;
import org.gwtoolbox.ioc.core.client.event.ApplicationEventMulticaster;
import org.gwtoolbox.ioc.core.client.event.ApplicationEventMulticasterAware;
import org.gwtoolbox.sample.ioc.client.event.MessageEvent;
/**
* @author Uri Boness
*/
public class PersonPanel extends Composite implements Initializable, Disposable, ApplicationEventMulticasterAware {
private VerticalPanel panel;
private Person person;
private String color = "white";
private ApplicationEventMulticaster multicaster;
public PersonPanel() {
panel = new VerticalPanel();
initWidget(panel);
}
public void init() throws Exception {
if (person == null) {
throw new IllegalArgumentException("Property 'person' is required");
}
panel.add(new HTML("<b>Name:</b> " + person.getName()));
panel.add(new HTML("<b>Age:</b> " + person.getAge()));
panel.add(new HTML("<b>Friend:</b> " + ((person.getFriend() == null) ? "null" : person.getFriend().getName())));
panel.add(new HTML("<b>System Id:</b> " + person));
panel.add(new Button("Send Message", new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
String message = "Person '" + person.getName() + "' sent this message!!!";
multicaster.notifyEvent(new MessageEvent(null, message));
}
}));
DOM.setStyleAttribute(panel.getElement(), "color", color);
}
public void dispose() throws Exception {
}
public void setApplicationEventMulticaster(ApplicationEventMulticaster multicaster) {
this.multicaster = multicaster;
}
//============================================== Setter/Getter =====================================================
@Inject
public void setPerson(Person person) {
this.person = person;
}
public Person getPerson() {
return person;
}
public void setColor(String color) {
this.color = color;
}
}