Skocz do zawartości

SmartGWT własne klasy z gwt showcase


Recommended Posts

Napisano

Witam! Postanowiłem się wkręcić w programowanie javy i na pierwszy strzał padło na smartgwt. Przerobiłem przykład z: http://www.javacodegeeks.com/2011/01/advanced-smartgwt-tutorial-part-1.html

Ale jedna rzecz nie daje mi spokoju.

Jeśli w konstruktorze klasy MainArea.java stworze kod gridu dodającego nowy wpis apliakcja działa dobrze, błąd wyświetlania zaczyna się gdy stworze klasę dajmy na to MyDataGrid.java

package com.javacodegeeks.smartgwt.appui.client.ui;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.types.RowEndEditAction;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class MyDataGrid extends HLayout {

    public MyDataGrid() {
        ListGridRecord[] data = new ListGridRecord[]{
                createRecord("US", "United States", 298444215),
                createRecord("CH", "China", 1313973713),
                createRecord("JA", "Japan", 127463611)
        };

        final ListGrid countryGrid = new ListGrid();
        countryGrid.setWidth(500);
        countryGrid.setAutoFitMaxRecords(6);
        countryGrid.setAutoFitData(Autofit.VERTICAL);
        countryGrid.setCanEdit(true);
        countryGrid.setEditEvent(ListGridEditEvent.CLICK);
        countryGrid.setListEndEditAction(RowEndEditAction.NEXT);

        ListGridField countryCodeField = new ListGridField("countryCode", "Country Code");
        ListGridField nameField = new ListGridField("countryName", "Country");
        ListGridField populationField = new ListGridField("population", "Population");

        countryGrid.setFields(countryCodeField, nameField, populationField);
        countryGrid.setData(data);

        IButton button = new IButton("Dodaj nowy");
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                countryGrid.startEditingNew();
            }
        });

        VLayout vLayout = new VLayout(20);
        vLayout.addMember(countryGrid);
        vLayout.addMember(button);

        vLayout.draw();
    }

      public ListGridRecord createRecord(String countryCode, String countryName, int population) {
            ListGridRecord record = new ListGridRecord();
            record.setAttribute("countryCode", countryCode);
            record.setAttribute("countryName", countryName);
            record.setAttribute("population", population);
            return record;
        }

}

Oraz dodam to do MainArea.java

package com.javacodegeeks.smartgwt.appui.client.ui;

import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class MainArea extends VLayout {

    private HLayout hLayout;
    private VLayout mainLayout;

    public MainArea() {
        super();
        mainLayout = new VLayout();
        mainLayout.setWidth100();
        mainLayout.setHeight100();
        hLayout = new MyDataGrid();
        mainLayout.addMember(hLayout);
        this.addMember(mainLayout);
    }

}

W tedy dostaje dość nie pożądany efekt, który wygląda tak: enter image description here

Napisano

Klasa MainArea jest rozszerzona o VLayout którego konstruktor jest wywołany przez super(). Później tworzysz nowy Vlayout: mainLayout = new VLayout(); i wpisujesz go w już istniejący: this.addMember(mainLayout); Podobnie z MyDataGrid. Jeśli jest już rozszerzona o hlayout to nie ma sensu wpisywać tego w nowy hlayout, przynajmniej nie w tym przypadku. Może tak będzie lepiej:

public MainArea() {
    super();
    setWidth100();
    setHeight100();
    this.addMember(new MyDataGrid());
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...