Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Help with ListGrid and Select Item

    Hi, I have two tables in my oracle database. I created 2 datasources for each table and created a ListGrid which is associated with table 1 (arrivalschedule). It has a column that is a foreign key to table 2 (gate). I want to display the description of the gate, not the id it is associated with, so I need to do a lookup on the gate table. I also want the ListGrid to be editable and want a dropdown of all existing gate descriptions for the user to select. I read other posts but they were of no help to me.

    ARRIVALSCHEDULE.ds.xml

    <!-- Auto-generated from database table REF_AIRLINE -->

    <DataSource
    schema="MySchema"
    dbName="Oracle"
    tableName="ARRIVALSCHEDULE"
    ID="ARRIVALSCHEDULE"
    dataSourceVersion="1"
    generatedBy="SC_SNAPSHOT-2011-03-01/EVAL Deployment 2011-03-01"
    serverType="sql"
    >
    <fields>
    <field primaryKey="true" name="scheduleid" length="10" title="Schedule ID" type="number" required="true" hidden= "true"/>
    <field name="flightid" type="text" length="10" title="Flight ID" required="true" />
    <field name="arrivaldate" type="datetime" title="Arrival Date" required="true" />
    <field name="gateid" type="number" length="10" title="Gate ID" foreignKey="gate.gateid" required="true" hidden="true"/>
    <field name="description" type="text" tableName="GATE" />

    </fields>
    <operationBindings>
    <operationBinding operationType="add" operationId="addRecord" >
    <serverObject className="com.reliable.app.server.DMI.MiscHandler" lookupStyle="new" /> <serverMethod>addRecord</serverMethod>
    </operationBinding>
    <operationBinding operationType="update" operationId="updateRecord">
    <serverObject className="com.reliable.app.server.DMI.MiscHandler" lookupStyle="new" />
    <serverMethod>updateRecord</serverMethod>
    </operationBinding>
    <operationBinding operationType="fetch">
    <tableClause>arrivalschedule, gate</tableClause>
    <whereClause>arrivalschedule.gateid = gate.gateid AND ($defaultWhereClause)</whereClause>
    </operationBinding>
    </operationBindings>
    </DataSource>



    GATE.ds.xml

    <!-- Auto-generated from database table REF_AIRLINE -->

    <DataSource
    schema="mySchema"
    dbName="Oracle"
    tableName="GATE"
    ID="GATE"
    dataSourceVersion="1"
    generatedBy="SC_SNAPSHOT-2011-03-01/EVAL Deployment 2011-03-01"
    serverType="sql"
    >
    <fields>
    <field primaryKey="true" name="gate" length="10" title="Gate ID" type="number" required="true" hidden= "true" tableName="GATE" customSQL="true"/>
    <field name= "description" type="text" length="50" title="Description" required="true" customSQL="true" />
    </fields>
    <operationBindings>
    <operationBinding operationType="add" operationId="addRecord" >
    <serverObject className="com.reliable.app.server.DMI.MiscHandler" lookupStyle="new" />
    <serverMethod>addRecord</serverMethod>
    </operationBinding>
    <operationBinding operationType="update" operationId="updateRecord">
    <serverObject className="com.reliable.app.server.DMI.MiscHandler" lookupStyle="new" />
    <serverMethod>updateRecord</serverMethod>
    </operationBinding>

    </operationBindings>
    </DataSource>



    Java Code

    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.client.NumberFormat;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.calendar.Calendar;
    import com.smartgwt.client.widgets.events.CloseClickEvent;
    import com.smartgwt.client.widgets.events.CloseClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.core.DataClass;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.SimpleType;
    import com.smartgwt.client.data.SimpleTypeFormatter;
    import com.smartgwt.client.data.fields.DataSourceDateTimeField;
    import com.smartgwt.client.data.fields.DataSourceSequenceField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.DataBoundComponent;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Img;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.tab.Tab;
    import com.smartgwt.client.widgets.tab.TabSet;
    import com.smartgwt.client.widgets.viewer.DetailViewer;
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    //import com.smartgwt.client.widgets.form.validator.Validator;
    /**
    * <p><code>GreetingPage</code>
    * Entry Point Class for Application. Main controller page for the appication. Manages the menu display and invocation
    * </p>
    *
    * @author Reliable Software Solutions Ltd.
    * @version 1.0
    */
    @SuppressWarnings("unused")
    public class GreetingPage implements EntryPoint {

    private Boolean userOk = false;

    /**
    * Constructor function
    */
    public void onModuleLoad() {


    RootPanel.get().add(getCanvas());
    }



    public Canvas getCanvas() {

    VLayout layout = new VLayout();

    final DataSource ds = DataSource.get("ARRIVALSCHEDULE");
    final DataSource dsgate = DataSource.get("GATE");


    /*------------------------------------------------------------
    Sets up ListGrid
    */
    final ListGrid flightScheduleGrid = new ListGrid();
    flightScheduleGrid.setWidth(800);
    flightScheduleGrid.setHeight(275);
    flightScheduleGrid.setDataSource(ds);
    flightScheduleGrid.setEditByCell(true);
    flightScheduleGrid.setShowAllRecords(true);
    flightScheduleGrid.setAlternateRecordStyles(true);
    flightScheduleGrid.setAutoFetchData(true);
    flightScheduleGrid.setAutoSaveEdits(false);
    flightScheduleGrid.setShowFilterEditor(true);
    flightScheduleGrid.setFilterOnKeypress(true);
    flightScheduleGrid.setEditEvent(ListGridEditEvent.CLICK);

    //------------------------------------------------------------



    /*---------------------------------------------------------------------------
    Sets up ListGridFields
    */
    ListGridField flightid = new ListGridField("flightid",100);
    flightid.setWidth("25%");
    ListGridField arrivaldate = new ListGridField("arrivaldate",100);
    arrivaldate.setWidth("25%");

    ListGridField gatedescription = new ListGridField("Gate");
    gatedescription.setWidth("25%");
    gatedescription.setCanEdit(true);
    gatedescription.setEditorType(new SelectItem());
    gatedescription.setFilterEditorType(new ComboBoxItem());
    gatedescription.setDisplayField("description");
    gatedescription.setValueField("gateid");

    FormItem felist = new FormItem () {{ setOptionDataSource(dsgate); }};
    felist.setCanEdit(true);
    gatedescription.setFilterEditorProperties(felist);



    //---------------------------------------------------------------------------

    /*---------------------------------------------------------------------------
    Sets up Save, Cancel and Refresh Buttons

    */

    IButton cancelButton = new IButton("Cancel");
    cancelButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    flightScheduleGrid.discardAllEdits();
    flightScheduleGrid.refreshFields();
    }
    });

    IButton saveButton = new IButton("Save");
    saveButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    flightScheduleGrid.saveAllEdits();

    }
    });

    IButton refreshButton = new IButton("Refresh");
    refreshButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    flightScheduleGrid.invalidateCache();

    }
    });
    //------------------------------------------------------------------



    flightScheduleGrid.setFields(flightid,arrivaldate,gatedescription);
    layout.addMember(flightScheduleGrid);
    layout.addMember(cancelButton);
    layout.addMember(saveButton);
    layout.addMember(refreshButton);
    layout.setTop(40);
    layout.setLeft("20%");



    return layout;
    }


    }

    #2
    See DataSourceField.includeFrom.

    Comment

    Working...
    X