Search in sources :

Example 1 with GwtSnapshot

use of org.eclipse.kapua.app.console.shared.model.GwtSnapshot in project kapua by eclipse.

the class DeviceConfigSnapshots method initGrid.

private void initGrid() {
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("snapshotId", MSGS.deviceSnapshotId(), 25);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    column = new ColumnConfig("createdOnFormatted", MSGS.deviceSnapshotCreatedOn(), 75);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.LEFT);
    columns.add(column);
    // loader and store
    RpcProxy<ListLoadResult<GwtSnapshot>> proxy = new RpcProxy<ListLoadResult<GwtSnapshot>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtSnapshot>> callback) {
            if (m_selectedDevice != null && m_dirty && m_initialized) {
                if (m_selectedDevice.isOnline()) {
                    gwtDeviceManagementService.findDeviceSnapshots(m_selectedDevice, callback);
                } else {
                    ListLoadResult<GwtSnapshot> snapshotResults = new ListLoadResult<GwtSnapshot>() {

                        @Override
                        public List<GwtSnapshot> getData() {
                            List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
                            return snapshots;
                        }
                    };
                    callback.onSuccess(snapshotResults);
                }
            } else {
                ListLoadResult<GwtSnapshot> snapshotResults = new ListLoadResult<GwtSnapshot>() {

                    @Override
                    public List<GwtSnapshot> getData() {
                        List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
                        return snapshots;
                    }
                };
                callback.onSuccess(snapshotResults);
            }
            m_dirty = false;
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtSnapshot>>(proxy);
    m_loader.setSortDir(SortDir.DESC);
    m_loader.setSortField("createdOnFormatted");
    m_loader.addLoadListener(new DataLoadListener());
    m_store = new ListStore<GwtSnapshot>(m_loader);
    m_grid = new Grid<GwtSnapshot>(m_store, new ColumnModel(columns));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setTrackMouseOver(false);
    m_grid.getView().setAutoFill(true);
    m_grid.getView().setEmptyText(MSGS.deviceSnapshotsNone());
    GridSelectionModel<GwtSnapshot> selectionModel = new GridSelectionModel<GwtSnapshot>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
    m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtSnapshot>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtSnapshot> se) {
            if (se.getSelectedItem() != null) {
                m_downloadButton.setEnabled(true);
                m_rollbackButton.setEnabled(true);
            } else {
                m_downloadButton.setEnabled(false);
                m_rollbackButton.setEnabled(false);
            }
        }
    });
}
Also used : GwtSnapshot(org.eclipse.kapua.app.console.shared.model.GwtSnapshot) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 2 with GwtSnapshot

use of org.eclipse.kapua.app.console.shared.model.GwtSnapshot in project kapua by eclipse.

the class DeviceConfigSnapshots method downloadSnapshot.

private void downloadSnapshot() {
    GwtSnapshot snapshot = m_grid.getSelectionModel().getSelectedItem();
    if (m_selectedDevice != null && snapshot != null) {
        StringBuilder sbUrl = new StringBuilder();
        if (UserAgentUtils.isSafari() || UserAgentUtils.isChrome()) {
            sbUrl.append("console/device_snapshots?");
        } else {
            sbUrl.append("device_snapshots?");
        }
        sbUrl.append("&scopeId=").append(URL.encodeQueryString(m_currentSession.getSelectedAccount().getId())).append("&deviceId=").append(URL.encodeQueryString(m_selectedDevice.getId())).append("&snapshotId=").append(snapshot.getSnapshotId());
        Window.open(sbUrl.toString(), "_blank", "location=no");
    }
}
Also used : GwtSnapshot(org.eclipse.kapua.app.console.shared.model.GwtSnapshot)

Example 3 with GwtSnapshot

use of org.eclipse.kapua.app.console.shared.model.GwtSnapshot in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method findDeviceSnapshots.

// 
// Snapshots
// 
@Override
public ListLoadResult<GwtSnapshot> findDeviceSnapshots(GwtDevice gwtDevice) throws GwtKapuaException {
    List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
    try {
        // execute the command
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceSnapshotManagementService deviceSnapshotManagementService = locator.getService(DeviceSnapshotManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
        DeviceSnapshots snapshotIds = deviceSnapshotManagementService.get(scopeId, deviceId, null);
        // sort them by most recent first
        // sort the list alphabetically by service name
        Collections.sort(snapshotIds.getSnapshots(), new Comparator<DeviceSnapshot>() {

            @Override
            public int compare(DeviceSnapshot arg0, DeviceSnapshot arg1) {
                DeviceSnapshot snapshotId0 = arg0;
                DeviceSnapshot snapshotId1 = arg1;
                // Descending order
                return -1 * snapshotId0.getTimestamp().compareTo(snapshotId1.getTimestamp());
            }
        });
        for (DeviceSnapshot snapshot : snapshotIds.getSnapshots()) {
            Long timestamp = snapshot.getTimestamp();
            GwtSnapshot gwtSnapshot = new GwtSnapshot();
            gwtSnapshot.setCreatedOn(new Date(timestamp));
            snapshots.add(gwtSnapshot);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtSnapshot>(snapshots);
}
Also used : GwtSnapshot(org.eclipse.kapua.app.console.shared.model.GwtSnapshot) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) ArrayList(java.util.ArrayList) Date(java.util.Date) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) DeviceSnapshotManagementService(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceSnapshot(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot) DeviceSnapshots(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots)

Aggregations

GwtSnapshot (org.eclipse.kapua.app.console.shared.model.GwtSnapshot)3 ArrayList (java.util.ArrayList)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 GridSelectionModel (com.extjs.gxt.ui.client.widget.grid.GridSelectionModel)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Date (java.util.Date)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 DeviceSnapshot (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot)1 DeviceSnapshotManagementService (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService)1 DeviceSnapshots (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots)1