Search in sources :

Example 1 with GwtPackageOperation

use of org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method getDownloadOperations.

public ListLoadResult<GwtPackageOperation> getDownloadOperations(String scopeShortId, String deviceShortId) throws GwtKapuaException {
    List<GwtPackageOperation> gwtDeviceOperations = new ArrayList<GwtPackageOperation>();
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        DevicePackageManagementService deviceManagementService = locator.getService(DevicePackageManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(scopeShortId);
        KapuaId deviceId = KapuaEid.parseShortId(deviceShortId);
        DevicePackageDownloadOperation downloadOperation = deviceManagementService.downloadStatus(scopeId, deviceId, null);
        GwtPackageDownloadOperation gwtDownloadOperation = new GwtPackageDownloadOperation();
        gwtDownloadOperation.setId(downloadOperation.getId().getShortId());
        gwtDownloadOperation.setStatus(downloadOperation.getStatus().name());
        gwtDownloadOperation.setSize(downloadOperation.getSize());
        gwtDownloadOperation.setProgress(downloadOperation.getProgress());
        gwtDeviceOperations.add(gwtDownloadOperation);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<>(gwtDeviceOperations);
}
Also used : GwtPackageOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation) DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageDownloadOperation(org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation) GwtPackageDownloadOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageDownloadOperation) ArrayList(java.util.ArrayList) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 2 with GwtPackageOperation

use of org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation in project kapua by eclipse.

the class DeviceTabPackagesInProgress method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    // 
    // Column Configuration
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    GridCellRenderer<GwtPackageOperation> renderer = new GridCellRenderer<GwtPackageOperation>() {

        @Override
        public Object render(GwtPackageOperation model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtPackageOperation> store, Grid<GwtPackageOperation> grid) {
            String operation;
            if (model instanceof GwtPackageDownloadOperation) {
                operation = MSGS.deviceInstallTabInProgressTableOperationInstall();
            } else {
                operation = MSGS.deviceInstallTabInProgressTableOperationUnknow();
            }
            return operation;
        }
    };
    ColumnConfig column = new ColumnConfig();
    column.setId("operation");
    column.setHeader(MSGS.deviceInstallTabInProgressTableOperation());
    column.setAlignment(HorizontalAlignment.CENTER);
    column.setWidth(60);
    column.setRenderer(renderer);
    configs.add(column);
    column.setId("id");
    column.setHeader(MSGS.deviceInstallTabInProgressTableOperationId());
    column.setAlignment(HorizontalAlignment.CENTER);
    column.setWidth(60);
    column.setRenderer(renderer);
    configs.add(column);
    renderer = new GridCellRenderer<GwtPackageOperation>() {

        @Override
        public Object render(GwtPackageOperation model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtPackageOperation> store, Grid<GwtPackageOperation> grid) {
            String sizeString;
            if (model instanceof GwtPackageDownloadOperation) {
                Integer size = ((GwtPackageDownloadOperation) model).getSize();
                if (size > 1024) {
                    size /= 1024;
                    if (size > 1024) {
                        sizeString = (size / 1024) + " MB";
                    } else {
                        sizeString = size.toString() + " KB";
                    }
                } else {
                    sizeString = size.toString() + " B";
                }
            } else {
                sizeString = null;
            }
            return sizeString;
        }
    };
    column = new ColumnConfig();
    column.setId("size");
    column.setHeader(MSGS.deviceInstallTabInProgressTableSize());
    column.setWidth(200);
    column.setRenderer(renderer);
    configs.add(column);
    column = new ColumnConfig();
    column.setId("progress");
    column.setHeader(MSGS.deviceInstallTabInProgressTableProgressPercentage());
    column.setWidth(80);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    ColumnModel columnModel = new ColumnModel(configs);
    RpcProxy<ListLoadResult<GwtPackageOperation>> proxy = new RpcProxy<ListLoadResult<GwtPackageOperation>>() {

        @Override
        protected void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtPackageOperation>> callback) {
            gwtDeviceManagementService.getDownloadOperations(getSelectedDevice().getScopeId(), getSelectedDevice().getId(), callback);
        }
    };
    storeLoader = new BaseListLoader<ListLoadResult<GwtPackageOperation>>(proxy);
    storeLoader.addLoadListener(new InProgressDataLoadListener());
    ListStore<GwtPackageOperation> store = new ListStore<GwtPackageOperation>(storeLoader);
    grid = new Grid<GwtPackageOperation>(store, columnModel);
    grid.setBorders(false);
    grid.setStateful(false);
    grid.setLoadMask(true);
    grid.setStripeRows(true);
    grid.setTrackMouseOver(false);
    grid.disableTextSelection(false);
    grid.setAutoExpandColumn("statusMessage");
    grid.getView().setAutoFill(true);
    grid.getView().setEmptyText(MSGS.deviceInstallTabInProgressTableEmpty());
    grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtPackageOperation>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtPackageOperation> se) {
            ModelData selectedItem = se.getSelectedItem();
        }
    });
    ContentPanel rootContentPanel = new ContentPanel();
    rootContentPanel.setLayout(new FitLayout());
    rootContentPanel.setBorders(false);
    rootContentPanel.setBodyBorder(false);
    rootContentPanel.setHeaderVisible(false);
    rootContentPanel.add(grid);
    add(rootContentPanel);
    componentInitialized = true;
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) GwtPackageDownloadOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageDownloadOperation) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) GwtPackageOperation(org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) GridCellRenderer(com.extjs.gxt.ui.client.widget.grid.GridCellRenderer) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Aggregations

ArrayList (java.util.ArrayList)2 GwtPackageDownloadOperation (org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageDownloadOperation)2 GwtPackageOperation (org.eclipse.kapua.app.console.shared.model.device.management.packages.GwtPackageOperation)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)1 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)1 GridCellRenderer (com.extjs.gxt.ui.client.widget.grid.GridCellRenderer)1 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 DevicePackageManagementService (org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService)1 DevicePackageDownloadOperation (org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation)1