ie.wombat.ha.ui.client.AboutDeviceDialog.java Source code

Java tutorial

Introduction

Here is the source code for ie.wombat.ha.ui.client.AboutDeviceDialog.java

Source

/*
 * Copyright 2007 Google Inc.
 * 
 * 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 ie.wombat.ha.ui.client;

import com.google.gwt.core.client.GWT;

import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * A simple example of an 'about' dialog box.
 */
public class AboutDeviceDialog extends DialogBox {

    interface Binder extends UiBinder<Widget, AboutDeviceDialog> {
    }

    private static final Binder binder = GWT.create(Binder.class);

    private final GetDevicesServiceAsync devicesService = GWT.create(GetDevicesService.class);
    private final ZigBeeServiceAsync zigbeeService = GWT.create(ZigBeeService.class);

    private Long deviceId;

    @UiField
    SpanElement zclVersionEl;
    @UiField
    SpanElement appVersionEl;
    @UiField
    SpanElement stackVersionEl;
    @UiField
    SpanElement hwVersionEl;
    @UiField
    SpanElement manufacturerEl;
    @UiField
    SpanElement modelIdEl;
    @UiField
    SpanElement dateEl;
    @UiField
    SpanElement powerEl;

    @UiField
    Button closeButton;

    public AboutDeviceDialog(Long deviceId) {

        this.deviceId = deviceId;

        //setText("About ZigBee Console App");
        setWidget(binder.createAndBindUi(this));

        setAnimationEnabled(true);
        setGlassEnabled(true);

        getDeviceInfo();
        getBasicAttribute(deviceId, 0x0000, zclVersionEl);
        getBasicAttribute(deviceId, 0x0001, appVersionEl);
        getBasicAttribute(deviceId, 0x0002, stackVersionEl);
        getBasicAttribute(deviceId, 0x0003, hwVersionEl);

        getBasicAttribute(deviceId, 0x0004, manufacturerEl);
        getBasicAttribute(deviceId, 0x0005, modelIdEl);
        getBasicAttribute(deviceId, 0x0006, dateEl);
        getBasicAttribute(deviceId, 0x0007, powerEl);
    }

    private void getDeviceInfo() {
        devicesService.getDeviceInfo(deviceId, new AsyncCallback<DeviceInfo>() {

            public void onSuccess(DeviceInfo result) {
                setText("Device View. " + result.name + " " + result.addr64.toString());
            }

            public void onFailure(Throwable caught) {
                Window.alert(caught.toString());
            }
        });
    }

    private void getBasicAttribute(final Long deviceId, final int attrId, final SpanElement el) {
        int[] attrIds = { attrId };
        zigbeeService.getAttributeValues(deviceId, 1, 0x104, 0x0, attrIds, new AsyncCallback<String[]>() {

            public void onSuccess(String[] result) {
                el.setInnerText("" + result[0]);
            }

            public void onFailure(Throwable caught) {
                Window.alert(caught.toString());
            }

        });
    }

    @UiHandler("closeButton")
    void onSignOutClicked(ClickEvent event) {
        hide();
    }
}