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);
}
}
});
}
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");
}
}
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);
}
Aggregations