PDA

View Full Version : How to pass data between popup form and main form



Tomeo
17 Dec 2010, 3:38 AM
Hi folks,

I have a form with button which invokes a new popup form to lookup some data and return selected item (object) back to main form, to be able to populate items with selected data. Problem which I have is with passing a selected data from LookupForm.

Is there any working example how to do it?

Kind regards,
Tomas

sven
17 Dec 2010, 3:52 AM
Normally your controller handles this. You can for example listen to the hide event of the Window that got opened, get the data, and add it to your real form.

You would do that as in any other java application.

Tomeo
17 Dec 2010, 3:54 AM
Here is my code:

Main form:


* Ext GWT 2.2.0 - Ext for GWT
package com.agtransport.agdoprava.client.pages.zakazky;

import java.util.ArrayList;

public class FormsExample extends LayoutContainer {
public FormsExample() {
}

private VerticalPanel vp;

private FormData formData;
private TextField<String> tfStredisko;
private TextField<String> tfTelefon;
private TextField<String> tfEmail;
private TextField<String> fieldFirma;

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
vp = new VerticalPanel();
vp.setSpacing(10);
createFormNewZakazka();
//createForm1();
//createForm2();
add(vp);
}

private void createForm1() {
FormPanel simple = new FormPanel();
simple.setHeading("Simple Form");
simple.setFrame(true);
simple.setWidth(350);

TextField<String> firstName = new TextField<String>();
firstName.setFieldLabel("Name");
firstName.setAllowBlank(false);
firstName.setData("aria-previous", simple.getButtonBar().getId());
simple.add(firstName, formData);

TextField<String> email = new TextField<String>();
email.setFieldLabel("Email");
email.setAllowBlank(false);
simple.add(email, formData);

List<Stock> stocks = TestData.getStocks();
Collections.sort(stocks, new Comparator<Stock>() {
public int compare(Stock arg0, Stock arg1) {
return arg0.getName().compareTo(arg1.getName());
}
});

ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);

ComboBox<Stock> combo = new ComboBox<Stock>();
combo.setFieldLabel("Company");
combo.setDisplayField("name");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(store);

simple.add(combo, formData);

DateField date = new DateField();
date.setFieldLabel("Birthday");
simple.add(date, formData);

TimeField time = new TimeField();
time.setFieldLabel("Time");
simple.add(time, formData);

Slider slider = new Slider();
slider.setMinValue(40);
slider.setMaxValue(90);
slider.setValue(60);
slider.setIncrement(1);
slider.setMessage("{0} inches tall");

final SliderField sf = new SliderField(slider);
sf.setFieldLabel("Size");
simple.add(sf, formData);
CheckBox check1 = new CheckBox();
check1.setBoxLabel("Classical");

CheckBox check2 = new CheckBox();
check2.setBoxLabel("Rock");
check2.setValue(true);

CheckBox check3 = new CheckBox();
check3.setBoxLabel("Blue");

CheckBoxGroup checkGroup = new CheckBoxGroup();
checkGroup.setFieldLabel("Music");
checkGroup.add(check1);
checkGroup.add(check2);
checkGroup.add(check3);
simple.add(checkGroup, formData);

Radio radio = new Radio();
radio.setBoxLabel("Red");
radio.setValue(true);

Radio radio2 = new Radio();
radio2.setBoxLabel("Blue");

RadioGroup radioGroup = new RadioGroup();
radioGroup.setFieldLabel("Favorite Color");
radioGroup.add(radio);
radioGroup.add(radio2);
simple.add(radioGroup, formData);

Radio radio3 = new Radio();
radio3.setBoxLabel("Apple");
radio3.setValue(true);

Radio radio4 = new Radio();
radio4.setBoxLabel("Banana");

RadioGroup radioGroup2 = new RadioGroup();
radioGroup2.setFieldLabel("Favorite Fruit");
radioGroup2.add(radio3);
radioGroup2.add(radio4);
simple.add(radioGroup2, formData);

TextArea description = new TextArea();
description.setPreventScrollbars(true);
description.setFieldLabel("Description");
simple.add(description, formData);

Button b = new Button("Submit");
simple.addButton(b);
simple.addButton(new Button("Cancel"));

simple.setButtonAlign(HorizontalAlignment.CENTER);

FormButtonBinding binding = new FormButtonBinding(simple);
binding.addButton(b);

SpinnerField spinnerField = new SpinnerField();
spinnerField.setIncrement(.1d);
spinnerField.getPropertyEditor().setType(Double.class);
spinnerField.getPropertyEditor().setFormat(NumberFormat.getFormat("00.0"));
spinnerField.setFieldLabel("Duration&nbsp;(s)");
spinnerField.setMinValue(-10d);
spinnerField.setMaxValue(10d);
simple.add(spinnerField, formData);

vp.add(simple);
}

private void createForm2() {
FormPanel form2 = new FormPanel();
form2.setFrame(true);
form2.setHeading("Simple Form with FieldSets");
form2.setWidth(350);
form2.setLayout(new FlowLayout());

FieldSet fieldSet = new FieldSet();
fieldSet.setHeading("User Information");
fieldSet.setCheckboxToggle(true);

FormLayout layout = new FormLayout();
layout.setLabelWidth(75);
fieldSet.setLayout(layout);

TextField<String> firstName = new TextField<String>();
firstName.setFieldLabel("First Name");
firstName.setAllowBlank(false);
fieldSet.add(firstName, formData);

TextField<String> lastName = new TextField<String>();
lastName.setFieldLabel("Last Name");
fieldSet.add(lastName, formData);

TextField<String> company = new TextField<String>();
company.setFieldLabel("Company");
fieldSet.add(company, formData);

TextField<String> email = new TextField<String>();
email.setFieldLabel("Email");
fieldSet.add(email, formData);

form2.add(fieldSet);

fieldSet = new FieldSet();
fieldSet.setHeading("Phone Numbers");
fieldSet.setCollapsible(true);

layout = new FormLayout();
layout.setLabelWidth(75);
fieldSet.setLayout(layout);

TextField<String> field = new TextField<String>();
field.setFieldLabel("Home");
fieldSet.add(field, formData);

field = new TextField<String>();
field.setFieldLabel("Business");
fieldSet.add(field, formData);

field = new TextField<String>();
field.setFieldLabel("Mobile");
fieldSet.add(field, formData);

field = new TextField<String>();
field.setFieldLabel("Fax");
fieldSet.add(field, formData);

form2.add(fieldSet);
form2.setButtonAlign(HorizontalAlignment.CENTER);
form2.addButton(new Button("Save"));
form2.addButton(new Button("Cancel"));

vp.add(form2);
}


private void createFormNewZakazka() {
final Uzivatel uzivatel = (Uzivatel) Registry.get(Agdoprava.UZIVATEL);

FormPanel form3 = new FormPanel();
form3.setFrame(true);
form3.setHeading("Nová zakázka");
form3.setWidth(700);
form3.setLayout(new FormLayout());
form3.setLabelAlign(LabelAlign.TOP);

HorizontalPanel hp = new HorizontalPanel();
CenterLayout hpLayout = new CenterLayout();
hp.setLayout(hpLayout);
hp.setStyleName("agt-label");
hp.setAutoHeight(true);
hp.setAutoWidth(true);
hp.setBorders(true);
hp.setHorizontalAlign(HorizontalAlignment.CENTER);
hp.setTableHeight("25");
hp.setSpacing(5);
//AdapterField ad = new AdapterField(hp);

Text lblLoggedUzivatelInfo = new Text(uzivatel.getUzivatelLastName() + " " + uzivatel.getUzivatelFirstName() + ", " + uzivatel.getUzivatelNazovStrediska() );
lblLoggedUzivatelInfo.setAutoWidth(true);
hp.add(lblLoggedUzivatelInfo);


java.util.Date today = new java.util.Date();
hp.add(new Label(today.toLocaleString() ));
//form3.add(ad, new FormData("0"));
form3.add(hp, new FormData("100%"));

LayoutContainer main = new LayoutContainer();
main.setLayout(new ColumnLayout());

LayoutContainer col1 = new LayoutContainer();
col1.setStyleAttribute("paddingRight", "5px");

FieldSet fsObjFirma = new FieldSet();
fsObjFirma.setHeading("Objednavatel - Firma");
fsObjFirma.setCollapsible(false);
fsObjFirma.setHeight("165");

FormLayout layout = new FormLayout();
layout.setLabelWidth(65);
fsObjFirma.setLayout(layout);

Button btnVyhledatObjFirma = new Button("Vyhledat");
fsObjFirma.add(btnVyhledatObjFirma, new FormData("100%"));

HorizontalPanel hp3 = new HorizontalPanel();
hp3.setBorders(false);
hp3.setSpacing(2);
hp3.setTableWidth("100%");
fieldFirma = new TextField<String>();
fieldFirma.disable();
hp3.add(new Label("Firma:"));
hp3.add(fieldFirma);
TableData td = new TableData();
td.setHorizontalAlign(HorizontalAlignment.RIGHT);
//hp3.add(new Label("Firma:"), td);
//hp3.add(fieldFirma, td);

Button btnLookUp = new Button();
btnLookUp.setToolTip("Vyhledat");
btnLookUp.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Info.display("Oznámení", "Vyhledat button pressed!");
}
});
btnLookUp.setIcon(IconHelper.createStyle("icon-lookup"));
hp3.add(btnLookUp, td);
//hp3.add(btnLookUp);
fsObjFirma.add(hp3, new FormData("-10"));
/*
TriggerField trgrfldNazev = new TriggerField();
trgrfldNazev.setEditable(false);
trgrfldNazev.setReadOnly(true);
fieldSet.add(trgrfldNazev, new FormData("100%"));
trgrfldNazev.setFieldLabel("Firma");
*/

TextArea txtrAdresa = new TextArea();
txtrAdresa.setPreventScrollbars(true);
txtrAdresa.setReadOnly(true);
fsObjFirma.add(txtrAdresa, new FormData("100%"));
txtrAdresa.setFieldLabel("Adresa");
col1.add(fsObjFirma, new FormData("-10"));
main.add(col1, new ColumnData(0.5));

LayoutContainer col2 = new LayoutContainer();

FieldSet fsObjKontakt = new FieldSet();
fsObjKontakt.setHeight("165");
FormLayout fl_fsObjKontakt = new FormLayout();
fl_fsObjKontakt.setLabelWidth(65);
fsObjKontakt.setLayout(fl_fsObjKontakt);

Button btnVyhledatObjOsoba = new Button("Vyhledat");
fsObjKontakt.add(btnVyhledatObjOsoba, new FormData("100%"));

TextField tfJmeno = new TextField();
fsObjKontakt.add(tfJmeno, new FormData("100%"));
tfJmeno.setFieldLabel("Jméno");

tfStredisko = new TextField<String>();
fsObjKontakt.add(tfStredisko, new FormData("100%"));
tfStredisko.setFieldLabel("Stredisko");

tfTelefon = new TextField<String>();
fsObjKontakt.add(tfTelefon, new FormData("100%"));
tfTelefon.setFieldLabel("Telefon");

tfEmail = new TextField<String>();
fsObjKontakt.add(tfEmail, new FormData("100%"));
tfEmail.setFieldLabel("Email");

col2.add(fsObjKontakt, new FormData("-10"));
fsObjKontakt.setHeading("Objednavatel - kontaktní osoba");
main.add(col2, new ColumnData(0.5));

/*
formData = new FormData("-10");

LayoutContainer col3x = new LayoutContainer();
col3x.setStyleAttribute("paddingRight", "10px");
layout = new FormLayout();
layout.setLabelAlign(LabelAlign.TOP);
col3x.setLayout(layout);
TextField<String> first = new TextField<String>();
first.setFieldLabel("Zakázku vystavil / Stredisko");
first.disable();
first.setValue(uzivatel.getUzivatelLastName() + " " + uzivatel.getUzivatelFirstName() + " - " + uzivatel.getUzivatelNazovStrediska());
col3x.add(first, new FormData("-10"));

TextField<String> extCisloZakazky = new TextField<String>();
extCisloZakazky.setFieldLabel("Externí číslo zakázky");
col3x.add(extCisloZakazky, new FormData("-10"));

DateField datum = new DateField();
datum.setFieldLabel("Datum");

col3x.add(datum, formData);
//form3.add(fieldSet);
main.add(col3x, new ColumnData(.33));
*/
//main.add(col2, new ColumnData(.5));
form3.add(main, new FormData("100%"));

ContentPanel cp = new ContentPanel();
cp.setHeaderVisible(false);

FormLayout cpLayout = new FormLayout();
cpLayout.setLabelAlign(LabelAlign.TOP);
cp.setLayout(cpLayout);
TextField<String> upozorneni = new TextField<String>();
upozorneni.setFieldLabel("Upozornění objednavatele jízdy");
cp.add(upozorneni, new FormData("100%"));
form3.add(cp, new FormData("100%"));

form3.add(createNakladkyVykladky(), new FormData("100%"));

//form3.setLayout(new FormLayout());
//form3.setLabelAlign(LabelAlign.TOP);

form3.setButtonAlign(HorizontalAlignment.CENTER);
form3.addButton(new Button("Save"));
form3.addButton(new Button("Cancel"));

vp.add(form3);

// listeners
btnVyhledatObjFirma.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Vyhledat firmu button pressed!");
LookupFirma lookupFirma = new LookupFirma();
lookupFirma.showLookupFirmaWindow();
//fieldFirma.setValue(lookupFirma.getSelectedFirma().getFirmaFirma());
//Tracing.Log("Firma: " + lookupFirma.getSelectedFirma().getFirmaFirma() );
}
});
}

public void setFirmaDetails(Firma lookupFirma){
fieldFirma.setValue(lookupFirma.getFirmaFirma());
}

private ContentPanel createNakladkyVykladky() {
List<Stock> stocks = TestData.getStocks();

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

CheckBoxSelectionModel<Stock> sm = new CheckBoxSelectionModel<Stock>();
//GridCellRenderer<Stock> gridNumber;
//GridCellRenderer<Stock> change;

configs.add(sm.getColumn());

ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Adresa");
column.setWidth(300);
configs.add(column);

column = new ColumnConfig();
column.setId("symbol");
column.setHeader("m3");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
configs.add(column);

column = new ColumnConfig();
column.setId("last");
column.setHeader("palet");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
//column.setRenderer(gridNumber);
configs.add(column);

column = new ColumnConfig("change", "Change", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
//column.setRenderer(change);
configs.add(column);

column = new ColumnConfig("date", "Last Updated", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);

ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);

ColumnModel cm = new ColumnModel(configs);

ContentPanel cp = new ContentPanel();
cp.setHeading("Seznam měst nakládek i vykládek");
cp.setFrame(true);
//cp.setIcon(Resources.ICONS.table());
//cp.addButton(new Button("Save"));
//cp.addButton(new Button("Cancel"));
//cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setSize(600, 150);

ToolBar toolBar = new ToolBar();
toolBar.getAriaSupport().setLabel("Grid Options");
toolBar.add(new Button("Přidat nakládku"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new Button("Přidat vykládku"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new Button("Odstranit"));
toolBar.add(new SeparatorToolItem());
//toolBar.add(new Button("Configure", Resources.ICONS.plugin()));
cp.setTopComponent(toolBar);

Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.setSelectionModel(sm);
grid.setAutoExpandColumn("name");
grid.setColumnReordering(true);
grid.setBorders(true);
grid.addPlugin(sm);
grid.getAriaSupport().setLabelledBy(cp.getHeader().getId() + "-label");
cp.add(grid);
return cp;
}

}



In above code, button "btnVyhledatObjFirma" invokes a new popup window (form) to look up an object of type "Firma"



* Ext GWT 2.2.0 - Ext for GWT
package com.agtransport.agdoprava.client.widget;

import java.util.ArrayList;

public class LookupFirma extends LayoutContainer {
public LookupFirma() {
}

private Grid<Firma> grid;
private Firma selectedFirma;


private PagingToolBar pagingToolBar;
Button btnSelect, btnCancel;
//FormsExample formExample;

Window window;
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
createFormLookupFirma();
/*
vp = new VerticalPanel();
vp.setSpacing(10);
createFormLookupFirma();
add(vp);
*/
}



private void createFormLookupFirma() {
setLayout(new FlowLayout(10));

window = new Window();
window.setSize(650, 500);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setHeading("Seznam firem");
window.setLayout(new FitLayout());
/*
window.addWindowListener(new WindowListener() {
@Override
public void windowHide(WindowEvent we) {
Button open = we.getWindow().getData("open");
open.focus();
}
});
*/

final Uzivatel uzivatel = (Uzivatel) Registry.get(Agdoprava.UZIVATEL);

FormPanel form3 = new FormPanel();
form3.setFrame(true);
//form3.setHeading("Seznam firem");
form3.setWidth(500);
form3.setLayout(new FormLayout());
form3.setLabelAlign(LabelAlign.TOP);

ContentPanel cp = new ContentPanel();
cp.setHeaderVisible(false);
FitLayout cpLayout = new FitLayout();
cp.setLayout(cpLayout);

// toolbar
ToolBar toolBar = new ToolBar();
toolBar.getAriaSupport().setLabel("Grid Options");
final TextField<String> filterString = new TextField<String>();
final IconButton filterBtn = new IconButton("icon-filter");

filterString.addKeyListener(new KeyListener() {
public void componentKeyPress(ComponentEvent event) {
if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
Tracing.Log("Enter pressed button pressed!");
filterBtn.focus();
}
}
});

toolBar.add(filterString);

filterBtn.setWidth(50);
filterBtn.addSelectionListener(new SelectionListener<IconButtonEvent>() {
public void componentSelected(IconButtonEvent ce) {
Tracing.Log("Filter button pressed!");
//showAddZakazka();
pagingToolBar.refresh();
}
});
toolBar.add(filterBtn);

toolBar.add(new SeparatorToolItem());

Button btnAdd = new Button();
btnAdd.setToolTip("Nová firma");
btnAdd.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Nova firma button pressed!");
//showAddZakazka();
}
});
btnAdd.setIcon(IconHelper.createStyle("icon-add"));
toolBar.add(btnAdd);
toolBar.add(new SeparatorToolItem());
Button btnDelete = new Button();
btnDelete.setToolTip("Smazat firmu");
btnDelete.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Smazat firmu button pressed!");
//showAddZakazka();
}
});
btnDelete.setIcon(IconHelper.createStyle("icon-delete"));
toolBar.add(btnDelete);

btnAdd.disable();
btnDelete.disable();
cp.setTopComponent(toolBar);


form3.add(cp, new FormData("100%"));

// grid
final DatabaseServiceAsync service = (DatabaseServiceAsync) Registry.get("DatabaseService");


RpcProxy<PagingLoadResult<Firma>> proxy = new RpcProxy<PagingLoadResult<Firma>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<Firma>> callback) {
Tracing.Log("LookupFirma.RpcProxy.load.before");
//service.getZakazky((PagingLoadConfig) loadConfig, callback);
service.getFirmy(filterString.getValue(), (FilterPagingLoadConfig) loadConfig, callback);
Tracing.Log("LookupFirma.RpcProxy.load.after");
}
};

// loader
//final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy) {
@Override
protected Object newLoadConfig() {
BasePagingLoadConfig config = new BaseFilterPagingLoadConfig();
return config;
}
};

loader.setRemoteSort(true);

ListStore<Firma> store = new ListStore<Firma>(loader);
pagingToolBar = new PagingToolBar(30);
pagingToolBar.bind(loader);


List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
//columns.add(new ColumnConfig("object_id", "Object Id", 80));
ColumnConfig created = new ColumnConfig("created", "Dátum vytvorenia", 105);
created.setDateTimeFormat(DateTimeFormat.getFormat("dd.MM.yyyy HH:mm:ss"));
//columns.add(created);
columns.add(new ColumnConfig("kod_firmy", "Kód", 80));
columns.add(new ColumnConfig("firma", "Firma", 220));
columns.add(new ColumnConfig("ico", "IČO", 80));
columns.add(new ColumnConfig("dic", "DIČ", 90));
columns.add(new ColumnConfig("mesto", "Město", 80));
columns.add(new ColumnConfig("ulice", "Ulice", 80));
columns.add(new ColumnConfig("psc", "PSC", 60));


columns.add(new ColumnConfig("tel1", "Tel.1", 100));
columns.add(new ColumnConfig("tel2", "Tel.2", 100));
columns.add(new ColumnConfig("fax", "Fax", 100));
columns.add(new ColumnConfig("email", "Email", 100));
columns.add(new ColumnConfig("poznamka", "Poznamka", 150));


ColumnModel cm = new ColumnModel(columns);

GridFilters filters = new GridFilters();
StringFilter filterKodFirmy = new StringFilter("kod_firmy");
StringFilter filterFirma = new StringFilter("firma");
StringFilter filterICO = new StringFilter("ico");
filters.addFilter(filterKodFirmy);
filters.addFilter(filterFirma);
filters.addFilter(filterICO);


grid = new Grid<Firma>(store, cm);
grid.setStateId("pagingGridLookupFirma");
grid.setStateful(true);

grid.addListener(Events.Attach, new Listener<GridEvent<Firma>>() {
public void handleEvent(GridEvent<Firma> be) {
//PagingLoadConfig config = new BasePagingLoadConfig();
PagingLoadConfig config = new BaseFilterPagingLoadConfig();

config.setOffset(0);
config.setLimit(30);

Map<String, Object> state = grid.getState();
if (state.containsKey("offset")) {
int offset = (Integer)state.get("offset");
int limit = (Integer)state.get("limit");
config.setOffset(offset);
config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config.setSortField((String)state.get("sortField"));
config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
}
loader.load(config);
}
});

grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<Firma>>() {
public void handleEvent(SelectionChangedEvent<Firma> be) {
if (be.getSelection().size() > 0) {
Tracing.Log("Grid selection changed - Selected firma ObjectID:" + be.getSelectedItem().getFirmaObjectId() );
btnSelect.enable();
selectedFirma = new Firma();
selectedFirma = be.getSelectedItem();
} else {
Tracing.Log("Nothing selected [2]");
btnSelect.disable();
selectedFirma = new Firma();
}
}
});

loader.addLoadListener(new LoadListener() {
@Override
public void loaderLoad(LoadEvent le)
{
// Run your selection logic here
Tracing.Log("loaderLoad invoked!");
if (grid.getSelectionModel().getSelection().size() == 0 ) {
Tracing.Log("Nothing selected [1]");
btnSelect.disable();
selectedFirma = new Firma();
}
//Tracing.Log("selectedZakazka selected " + grid.getSelectionModel().getSelectedItem().getZakazkaObjectId() + " " + grid.getSelectionModel().getSelectedItem().getZakazkaStavZakazkyId());
}
});



grid.setLoadMask(true);
grid.setBorders(true);

grid.setStripeRows(true);
grid.setColumnLines(true);
grid.addPlugin(filters);

//grid.setAutoExpandColumn("cislo_dokladu");


cp.add(grid);
cp.setSize(600, 300);
cp.setBottomComponent(pagingToolBar);
grid.getAriaSupport().setLabelledBy(cp.getId());
//cp.add(grid, new FormData("100%"));

cp.setButtonAlign(HorizontalAlignment.CENTER);
btnSelect = new Button("Vybrat");
btnCancel = new Button("Zrušit");
btnSelect.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Selected firma: " + selectedFirma.getFirmaFirma() + " " + selectedFirma.getFirmaKodFirmy());
//formExample.setFirmaDetails(selectedFirma);
window.hide();
}
});
btnCancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
window.hide();
}
});



cp.addButton(btnSelect);
cp.addButton(btnCancel);
window.add(cp, new FitData(4));
}

public void showLookupFirmaWindow() {
createFormLookupFirma();
window.show();
}

public Firma getSelectedFirma() {
return selectedFirma;
}

}


Tomas

Tomeo
17 Dec 2010, 7:02 AM
Hi sven,

in LookupFirma popup form in "Select" button I added a code to register selected object and dispatcher call.


btnSelect.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Selected firma: " + selectedFirma.getFirmaFirma() + " " + selectedFirma.getFirmaKodFirmy());
Registry.register(Agdoprava.LOOKED_UP_FIRMA, selectedFirma);
Dispatcher.forwardEvent(AppEvents.LookupFirma);
//formExample.setFirmaDetails(selectedFirma);
window.hide();
}
});


At the moment my problem is to catch this event within main form (FormsExample), so I would be able to call "setFirmaDetails".



Tomas

sven
17 Dec 2010, 7:27 AM
At the moment my problem is to catch this event within main form (FormsExample), so I would be able to call "setFirmaDetails".

You need to register one controller, that is able to handle this event. You maybe should also pass the selection with this event.

Tomeo
17 Dec 2010, 7:33 AM
Thanks Sven for your reply.

I've registered this event, and while testing this event is invoked correctly. But, my problem is to access a "FormsExample" from it.



/*
* Ext GWT 2.2.0 - Ext for GWT
* Copyright(c) 2007-2010, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
package com.agtransport.agdoprava.client.controller;

import com.agtransport.agdoprava.client.AppEvents;
import com.agtransport.agdoprava.client.Agdoprava;
import com.agtransport.agdoprava.client.DatabaseServiceAsync;
import com.agtransport.agdoprava.client.Tracing;
import com.agtransport.agdoprava.client.model.Folder;
import com.agtransport.agdoprava.client.model.Uzivatel;
import com.agtransport.agdoprava.client.widget.LoginDialog;
import com.agtransport.agdoprava.server.UzivatelManager;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class AppController extends Controller {


private AppView appView;
private DatabaseServiceAsync service;


public AppController() {
Tracing.Log("Constructor - registerEventTypes");
registerEventTypes(AppEvents.Init);
registerEventTypes(AppEvents.Login);
registerEventTypes(AppEvents.Error);
registerEventTypes(AppEvents.Logout);
registerEventTypes(AppEvents.LookupFirma);
}

public void handleEvent(AppEvent event) {
EventType type = event.getType();
if (type == AppEvents.Init) {
Tracing.Log("AppEvents.Init");
onInit(event);
} else if (type == AppEvents.Login) {
Tracing.Log("AppEvents.Login");
onLogin(event);
} else if (type == AppEvents.Logout) {
Tracing.Log("AppEvents.Logout");
Cookies.removeCookie("username");
Cookies.removeCookie("password");
initialize();
onLogin(event);
} else if (type == AppEvents.Error) {
Tracing.Log("AppEvents.Error");
onError(event);
} else if (type == AppEvents.LookupFirma) {
Tracing.Log("LOOKUP FIRMA EVENT");
// How to access a existing FormsExample from this place, so I will be able to call " setFirmaDetails()" from "FormsExample"?
}

}

public void initialize() {
Tracing.Log();
appView = new AppView(this);
}

protected void onError(AppEvent ae) {
Tracing.Log("error: " + ae.<Object>getData());
}

private void onInit(AppEvent event) {
Tracing.Log();
forwardToView(appView, event);
}

private void onLogin(AppEvent event) {
Tracing.Log("event:" + event.getType().toString());
forwardToView(appView, event);
}

}



FormsExample.java


* Ext GWT 2.2.0 - Ext for GWT
package com.agtransport.agdoprava.client.pages.zakazky;

import java.util.ArrayList;

public class FormsExample extends LayoutContainer {
public FormsExample() {
}

private VerticalPanel vp;

private FormData formData;
private TextField<String> tfStredisko;
private TextField<String> tfTelefon;
private TextField<String> tfEmail;
private TextField<String> fieldFirma;

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
vp = new VerticalPanel();
vp.setSpacing(10);
createFormNewZakazka();
//createForm1();
//createForm2();
add(vp);
}

private void createFormNewZakazka() {
final Uzivatel uzivatel = (Uzivatel) Registry.get(Agdoprava.UZIVATEL);

FormPanel form3 = new FormPanel();
form3.setFrame(true);
form3.setHeading("Nová zakázka");
form3.setWidth(700);
form3.setLayout(new FormLayout());
form3.setLabelAlign(LabelAlign.TOP);

HorizontalPanel hp = new HorizontalPanel();
CenterLayout hpLayout = new CenterLayout();
hp.setLayout(hpLayout);
hp.setStyleName("agt-label");
hp.setAutoHeight(true);
hp.setAutoWidth(true);
hp.setBorders(true);
hp.setHorizontalAlign(HorizontalAlignment.CENTER);
hp.setTableHeight("25");
hp.setSpacing(5);
//AdapterField ad = new AdapterField(hp);

Text lblLoggedUzivatelInfo = new Text(uzivatel.getUzivatelLastName() + " " + uzivatel.getUzivatelFirstName() + ", " + uzivatel.getUzivatelNazovStrediska() );
lblLoggedUzivatelInfo.setAutoWidth(true);
hp.add(lblLoggedUzivatelInfo);


java.util.Date today = new java.util.Date();
hp.add(new Label(today.toLocaleString() ));
//form3.add(ad, new FormData("0"));
form3.add(hp, new FormData("100%"));

LayoutContainer main = new LayoutContainer();
main.setLayout(new ColumnLayout());

LayoutContainer col1 = new LayoutContainer();
col1.setStyleAttribute("paddingRight", "5px");

FieldSet fsObjFirma = new FieldSet();
fsObjFirma.setHeading("Objednavatel - Firma");
fsObjFirma.setCollapsible(false);
fsObjFirma.setHeight("165");

FormLayout layout = new FormLayout();
layout.setLabelWidth(65);
fsObjFirma.setLayout(layout);

Button btnVyhledatObjFirma = new Button("Vyhledat");
fsObjFirma.add(btnVyhledatObjFirma, new FormData("100%"));

HorizontalPanel hp3 = new HorizontalPanel();
hp3.setBorders(false);
hp3.setSpacing(2);
hp3.setTableWidth("100%");
fieldFirma = new TextField<String>();
fieldFirma.disable();
hp3.add(new Label("Firma:"));
hp3.add(fieldFirma);
TableData td = new TableData();
td.setHorizontalAlign(HorizontalAlignment.RIGHT);
//hp3.add(new Label("Firma:"), td);
//hp3.add(fieldFirma, td);

Button btnLookUp = new Button();
btnLookUp.setToolTip("Vyhledat");
btnLookUp.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Info.display("Oznámení", "Vyhledat button pressed!");
}
});
btnLookUp.setIcon(IconHelper.createStyle("icon-lookup"));
hp3.add(btnLookUp, td);
//hp3.add(btnLookUp);
fsObjFirma.add(hp3, new FormData("-10"));
/*
TriggerField trgrfldNazev = new TriggerField();
trgrfldNazev.setEditable(false);
trgrfldNazev.setReadOnly(true);
fieldSet.add(trgrfldNazev, new FormData("100%"));
trgrfldNazev.setFieldLabel("Firma");
*/

TextArea txtrAdresa = new TextArea();
txtrAdresa.setPreventScrollbars(true);
txtrAdresa.setReadOnly(true);
fsObjFirma.add(txtrAdresa, new FormData("100%"));
txtrAdresa.setFieldLabel("Adresa");
col1.add(fsObjFirma, new FormData("-10"));
main.add(col1, new ColumnData(0.5));

LayoutContainer col2 = new LayoutContainer();

FieldSet fsObjKontakt = new FieldSet();
fsObjKontakt.setHeight("165");
FormLayout fl_fsObjKontakt = new FormLayout();
fl_fsObjKontakt.setLabelWidth(65);
fsObjKontakt.setLayout(fl_fsObjKontakt);

Button btnVyhledatObjOsoba = new Button("Vyhledat");
fsObjKontakt.add(btnVyhledatObjOsoba, new FormData("100%"));

TextField tfJmeno = new TextField();
fsObjKontakt.add(tfJmeno, new FormData("100%"));
tfJmeno.setFieldLabel("Jméno");

tfStredisko = new TextField<String>();
fsObjKontakt.add(tfStredisko, new FormData("100%"));
tfStredisko.setFieldLabel("Stredisko");

tfTelefon = new TextField<String>();
fsObjKontakt.add(tfTelefon, new FormData("100%"));
tfTelefon.setFieldLabel("Telefon");

tfEmail = new TextField<String>();
fsObjKontakt.add(tfEmail, new FormData("100%"));
tfEmail.setFieldLabel("Email");

col2.add(fsObjKontakt, new FormData("-10"));
fsObjKontakt.setHeading("Objednavatel - kontaktní osoba");
main.add(col2, new ColumnData(0.5));

/*
formData = new FormData("-10");

LayoutContainer col3x = new LayoutContainer();
col3x.setStyleAttribute("paddingRight", "10px");
layout = new FormLayout();
layout.setLabelAlign(LabelAlign.TOP);
col3x.setLayout(layout);
TextField<String> first = new TextField<String>();
first.setFieldLabel("Zakázku vystavil / Stredisko");
first.disable();
first.setValue(uzivatel.getUzivatelLastName() + " " + uzivatel.getUzivatelFirstName() + " - " + uzivatel.getUzivatelNazovStrediska());
col3x.add(first, new FormData("-10"));

TextField<String> extCisloZakazky = new TextField<String>();
extCisloZakazky.setFieldLabel("Externí číslo zakázky");
col3x.add(extCisloZakazky, new FormData("-10"));

DateField datum = new DateField();
datum.setFieldLabel("Datum");

col3x.add(datum, formData);
//form3.add(fieldSet);
main.add(col3x, new ColumnData(.33));
*/
//main.add(col2, new ColumnData(.5));
form3.add(main, new FormData("100%"));

ContentPanel cp = new ContentPanel();
cp.setHeaderVisible(false);

FormLayout cpLayout = new FormLayout();
cpLayout.setLabelAlign(LabelAlign.TOP);
cp.setLayout(cpLayout);
TextField<String> upozorneni = new TextField<String>();
upozorneni.setFieldLabel("Upozornění objednavatele jízdy");
cp.add(upozorneni, new FormData("100%"));
form3.add(cp, new FormData("100%"));

form3.add(createNakladkyVykladky(), new FormData("100%"));

//form3.setLayout(new FormLayout());
//form3.setLabelAlign(LabelAlign.TOP);

form3.setButtonAlign(HorizontalAlignment.CENTER);
form3.addButton(new Button("Save"));
form3.addButton(new Button("Cancel"));

vp.add(form3);

// listeners
btnVyhledatObjFirma.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Tracing.Log("Vyhledat firmu button pressed!");
LookupFirma lookupFirma = new LookupFirma();
lookupFirma.showLookupFirmaWindow();
//fieldFirma.setValue(lookupFirma.getSelectedFirma().getFirmaFirma());
//Tracing.Log("Firma: " + lookupFirma.getSelectedFirma().getFirmaFirma() );
}
});
}

public void setFirmaDetails(){
Firma lookupFirma = (Firma) Registry.get(Agdoprava.LOOKED_UP_FIRMA);
fieldFirma.setValue(lookupFirma.getFirmaFirma());
}

private ContentPanel createNakladkyVykladky() {
List<Stock> stocks = TestData.getStocks();

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

CheckBoxSelectionModel<Stock> sm = new CheckBoxSelectionModel<Stock>();
//GridCellRenderer<Stock> gridNumber;
//GridCellRenderer<Stock> change;

configs.add(sm.getColumn());

ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Adresa");
column.setWidth(300);
configs.add(column);

column = new ColumnConfig();
column.setId("symbol");
column.setHeader("m3");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
configs.add(column);

column = new ColumnConfig();
column.setId("last");
column.setHeader("palet");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
//column.setRenderer(gridNumber);
configs.add(column);

column = new ColumnConfig("change", "Change", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
//column.setRenderer(change);
configs.add(column);

column = new ColumnConfig("date", "Last Updated", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);

ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);

ColumnModel cm = new ColumnModel(configs);

ContentPanel cp = new ContentPanel();
cp.setHeading("Seznam měst nakládek i vykládek");
cp.setFrame(true);
//cp.setIcon(Resources.ICONS.table());
//cp.addButton(new Button("Save"));
//cp.addButton(new Button("Cancel"));
//cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setSize(600, 150);

ToolBar toolBar = new ToolBar();
toolBar.getAriaSupport().setLabel("Grid Options");
toolBar.add(new Button("Přidat nakládku"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new Button("Přidat vykládku"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new Button("Odstranit"));
toolBar.add(new SeparatorToolItem());
//toolBar.add(new Button("Configure", Resources.ICONS.plugin()));
cp.setTopComponent(toolBar);

Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.setSelectionModel(sm);
grid.setAutoExpandColumn("name");
grid.setColumnReordering(true);
grid.setBorders(true);
grid.addPlugin(sm);
grid.getAriaSupport().setLabelledBy(cp.getHeader().getId() + "-label");
cp.add(grid);
return cp;
}

}

Tomeo
20 Dec 2010, 2:59 AM
Moving below code to "FormsExample.java" would call correct method on correct place, but not sure how to invoke this event.



public void handleEvent(AppEvent event) {
Tracing.Log(">>>> HANDLE EVENT <<<< ");
EventType type = event.getType();
if (type == AppEvents.LookupFirma) {
Tracing.Log("LOOKUP FIRMA EVENT");
setFirmaDetails();
}
}