use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.
the class GwtDeviceServiceImpl method findDeviceEvents.
public PagingLoadResult<GwtDeviceEvent> findDeviceEvents(PagingLoadConfig loadConfig, GwtDevice gwtDevice, Date startDate, Date endDate) throws GwtKapuaException {
ArrayList<GwtDeviceEvent> gwtDeviceEvents = new ArrayList<GwtDeviceEvent>();
BasePagingLoadResult<GwtDeviceEvent> gwtResults = null;
KapuaLocator locator = KapuaLocator.getInstance();
DeviceEventService des = locator.getService(DeviceEventService.class);
DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
try {
// prepare the query
BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig;
DeviceEventQuery query = deviceEventFactory.newQuery(KapuaEid.parseShortId(gwtDevice.getScopeId()));
KapuaAndPredicate andPredicate = new AndPredicate();
andPredicate.and(new AttributePredicate<KapuaId>(DeviceEventPredicates.DEVICE_ID, KapuaEid.parseShortId(gwtDevice.getId())));
// .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.GREATER_THAN));
// .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.LESS_THAN));
query.setPredicate(andPredicate);
query.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, SortOrder.DESCENDING));
query.setOffset(bplc.getOffset());
query.setLimit(bplc.getLimit());
// query execute
KapuaListResult<DeviceEvent> deviceEvents = des.query(query);
// prepare results
for (DeviceEvent deviceEvent : deviceEvents.getItems()) {
gwtDeviceEvents.add(KapuaGwtConverter.convert(deviceEvent));
}
gwtResults = new BasePagingLoadResult<GwtDeviceEvent>(gwtDeviceEvents);
gwtResults.setOffset(loadConfig.getOffset());
gwtResults.setTotalLength((int) des.count(query));
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtResults;
}
use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.
the class DeviceTabHistory method initGrid.
private void initGrid() {
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("receivedOnFormatted", MSGS.deviceEventTime(), 75);
column.setSortable(false);
column.setAlignment(HorizontalAlignment.CENTER);
columns.add(column);
column = new ColumnConfig("eventType", MSGS.deviceEventType(), 50);
column.setSortable(false);
column.setAlignment(HorizontalAlignment.CENTER);
columns.add(column);
TreeGridCellRenderer<GwtDeviceEvent> eventMessageRenderer = new TreeGridCellRenderer<GwtDeviceEvent>() {
@Override
public Object render(GwtDeviceEvent model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDeviceEvent> store, Grid<GwtDeviceEvent> grid) {
StringBuilder message = new StringBuilder("");
if (model.getEventMessage() != null) {
message.append("<label title='").append(model.getUnescapedEventMessage()).append("'>").append(model.getUnescapedEventMessage()).append("</label>");
}
return message.toString();
}
};
column = new ColumnConfig("eventMessage", MSGS.deviceEventMessage(), 200);
column.setSortable(false);
column.setAlignment(HorizontalAlignment.LEFT);
column.setRenderer(eventMessageRenderer);
columns.add(column);
// loader and store
RpcProxy<PagingLoadResult<GwtDeviceEvent>> proxy = new RpcProxy<PagingLoadResult<GwtDeviceEvent>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtDeviceEvent>> callback) {
if (m_selectedDevice != null) {
PagingLoadConfig pagingConfig = (BasePagingLoadConfig) loadConfig;
((BasePagingLoadConfig) pagingConfig).setLimit(DEVICE_PAGE_SIZE);
gwtDeviceService.findDeviceEvents(pagingConfig, m_selectedDevice, m_dateRangeSelector.getStartDate(), m_dateRangeSelector.getEndDate(), callback);
}
}
};
m_loader = new BasePagingLoader<PagingLoadResult<GwtDeviceEvent>>(proxy);
m_loader.setSortDir(SortDir.DESC);
m_loader.setSortField("receivedOnFormatted");
m_loader.setRemoteSort(true);
m_loader.addLoadListener(new DataLoadListener());
ListStore<GwtDeviceEvent> store = new ListStore<GwtDeviceEvent>(m_loader);
m_grid = new Grid<GwtDeviceEvent>(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.setAutoExpandColumn("eventMessage");
m_grid.disableTextSelection(false);
m_grid.getView().setAutoFill(true);
m_grid.getView().setEmptyText(MSGS.deviceHistoryTableNoHistory());
m_pagingToolBar = new PagingToolBar(DEVICE_PAGE_SIZE);
m_pagingToolBar.bind(m_loader);
GridSelectionModel<GwtDeviceEvent> selectionModel = new GridSelectionModel<GwtDeviceEvent>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_grid.setSelectionModel(selectionModel);
}
use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.
the class DevicesMap method refresh.
public void refresh(GwtDeviceQueryPredicates predicates) {
// clean-up the Marker list
m_markerLayer.destroyFeatures();
if (m_popup != null) {
m_map.removePopup(m_popup);
}
// reload the devices for this account
final DevicesMap theDeviceMap = this;
theDeviceMap.mask(MSGS.loading());
BasePagingLoadConfig loadConfig = new BasePagingLoadConfig(0, 500);
gwtDeviceService.findDevices(loadConfig, m_currentSession.getSelectedAccount().getId(), predicates, new AsyncCallback<PagingLoadResult<GwtDevice>>() {
public void onFailure(Throwable caught) {
FailureHandler.handle(caught);
theDeviceMap.unmask();
}
public void onSuccess(PagingLoadResult<GwtDevice> loadResult) {
placeMarkers(loadResult.getData());
theDeviceMap.unmask();
}
});
}
use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.
the class DevicesTable method initDevicesGrid.
private void initDevicesGrid() {
//
// Column Configuration
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("status", MSGS.deviceTableStatus(), 50);
column.setAlignment(HorizontalAlignment.CENTER);
GridCellRenderer<GwtDevice> setStatusIcon = new GridCellRenderer<GwtDevice>() {
public String render(GwtDevice gwtDevice, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDevice> deviceList, Grid<GwtDevice> grid) {
if (gwtDevice.getGwtDeviceStatus().compareTo("ENABLED") == 0) {
if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("CONNECTED") == 0) {
return ImageUtils.toHTML(Resources.INSTANCE.greenBullet14(), MSGS.connected(), "10");
} else if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("MISSING") == 0) {
return ImageUtils.toHTML(Resources.INSTANCE.redBullet14(), MSGS.missing(), "10");
} else if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("DISCONNECTED") == 0) {
return ImageUtils.toHTML(Resources.INSTANCE.yellowBullet14(), MSGS.disconnected(), "10");
}
return gwtDevice.getGwtDeviceConnectionStatus();
} else {
if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("CONNECTED") == 0) {
return ImageUtils.toHTML(Resources.INSTANCE.greenAndBlackBullet14(), MSGS.disabledButConnected(), "10");
}
return ImageUtils.toHTML(Resources.INSTANCE.blackBullet14(), MSGS.disabled(), "10");
}
}
};
column.setRenderer(setStatusIcon);
column.setAlignment(HorizontalAlignment.CENTER);
column.setSortable(false);
configs.add(column);
column = new ColumnConfig("clientId", MSGS.deviceTableClientID(), 175);
column.setSortable(true);
configs.add(column);
column = new ColumnConfig("displayName", MSGS.deviceTableDisplayName(), 150);
column.setSortable(true);
configs.add(column);
column = new ColumnConfig("lastEventOnFormatted", MSGS.deviceTableLastReportedDate(), 130);
column.setSortable(true);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("lastEventType", MSGS.deviceTableLastEventType(), 130);
column.setSortable(false);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("serialNumber", MSGS.deviceTableSerialNumber(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
//
// Device Management Certificate
column = new ColumnConfig("Device Management Certificate Status", "DM", 50);
column.setAlignment(HorizontalAlignment.CENTER);
GridCellRenderer<GwtDevice> setDmStatusIcon = new GridCellRenderer<GwtDevice>() {
public String render(GwtDevice gwtDevice, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDevice> deviceList, Grid<GwtDevice> grid) {
if (gwtDevice.getSignedCertificateId() == null) {
// Device Management Communication is not signed
return ImageUtils.toHTML(Resources.INSTANCE.dmUnlock16(), MSGS.deviceTableCertificateDMTooltipStatusNotSigned(), "14");
} else {
// Device Management Communication is signed
return ImageUtils.toHTML(Resources.INSTANCE.lockGreen16(), MSGS.deviceTableCertificateDMTooltipStatusSigned(), "14");
}
}
};
column.setRenderer(setDmStatusIcon);
column.setAlignment(HorizontalAlignment.CENTER);
column.setSortable(false);
configs.add(column);
column = new ColumnConfig("applicationIdentifiers", MSGS.deviceTableApplications(), 100);
column.setSortable(false);
column.setHidden(false);
configs.add(column);
column = new ColumnConfig("esfKuraVersion", MSGS.deviceTableEsfKuraVersion(), 80);
column.setSortable(false);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("customAttribute1", MSGS.deviceTableCustomAttribute1(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("customAttribute2", MSGS.deviceTableCustomAttribute2(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("connectionIp", MSGS.deviceTableIpAddress(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("modelId", MSGS.deviceTableModelId(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("firmwareVersion", MSGS.deviceTableFirmwareVersion(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("biosVersion", MSGS.deviceTableBiosVersion(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("osVersion", MSGS.deviceTableOsVersion(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("jvmVersion", MSGS.deviceTableJvmVersion(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("osgiFrameworkVersion", MSGS.deviceTableOsgiVersion(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("imei", MSGS.deviceTableImei(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("imsi", MSGS.deviceTableImsi(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
column = new ColumnConfig("iccid", MSGS.deviceTableIccid(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
// signedCertificateId
column = new ColumnConfig("signedCertificateId", MSGS.deviceTableCertificate(), 100);
column.setSortable(false);
column.setHidden(true);
configs.add(column);
// loader and store
RpcProxy<PagingLoadResult<GwtDevice>> proxy = new RpcProxy<PagingLoadResult<GwtDevice>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtDevice>> callback) {
PagingLoadConfig pagingConfig = (BasePagingLoadConfig) loadConfig;
((BasePagingLoadConfig) pagingConfig).setLimit(DEVICE_PAGE_SIZE);
gwtDeviceService.findDevices(pagingConfig, m_currentSession.getSelectedAccount().getId(), m_filterPredicates, callback);
}
};
m_loader = new BasePagingLoader<PagingLoadResult<GwtDevice>>(proxy);
m_loader.setSortDir(SortDir.ASC);
m_loader.setSortField("clientId");
m_loader.setRemoteSort(true);
SwappableListStore<GwtDevice> store = new SwappableListStore<GwtDevice>(m_loader);
store.setKeyProvider(new ModelKeyProvider<GwtDevice>() {
public String getKey(GwtDevice device) {
return device.getScopeId() + ":" + device.getClientId();
}
});
m_devicesGrid = new Grid<GwtDevice>(store, new ColumnModel(configs));
m_devicesGrid.setBorders(false);
m_devicesGrid.setStateful(false);
m_devicesGrid.setLoadMask(true);
m_devicesGrid.setStripeRows(true);
m_devicesGrid.setAutoExpandColumn("displayName");
m_devicesGrid.getView().setAutoFill(true);
m_devicesGrid.getView().setEmptyText(MSGS.deviceTableNoDevices());
m_devicesGrid.disableTextSelection(false);
m_devicesGrid.addListener(Events.HeaderClick, new Listener<GridEvent<GwtDevice>>() {
@Override
public void handleEvent(GridEvent<GwtDevice> be) {
if (be.getColIndex() == 1) {
if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name())) {
if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name());
} else if (be.getColIndex() == 2) {
if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name())) {
if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name());
} else if (be.getColIndex() == 3) {
if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name())) {
if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
} else {
m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
}
m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name());
} else {
return;
}
refresh(m_filterPredicates);
}
});
m_loader.addLoadListener(new DataLoadListener(m_devicesGrid));
m_pagingToolBar = new PagingToolBar(DEVICE_PAGE_SIZE);
m_pagingToolBar.bind(m_loader);
m_pagingToolBar.enable();
GridSelectionModel<GwtDevice> selectionModel = new GridSelectionModel<GwtDevice>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_devicesGrid.setSelectionModel(selectionModel);
m_devicesGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtDevice>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtDevice> se) {
m_selectedDevice = se.getSelectedItem();
if (m_selectedDevice != null) {
m_deleteDeviceButton.setEnabled(true);
m_devicesView.setDevice(m_selectedDevice);
} else {
// m_editDeviceButton.setEnabled(false);
m_deleteDeviceButton.setEnabled(false);
}
}
});
}
use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.
the class GwtDeviceServiceImpl method findDevices.
public PagingLoadResult<GwtDevice> findDevices(PagingLoadConfig loadConfig, String scopeIdString, GwtDeviceQueryPredicates predicates) throws GwtKapuaException {
KapuaLocator locator = KapuaLocator.getInstance();
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class);
List<GwtDevice> gwtDevices = new ArrayList<GwtDevice>();
BasePagingLoadResult<GwtDevice> gwtResults;
int totalResult = 0;
try {
BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig;
DeviceQuery deviceQuery = deviceFactory.newQuery(KapuaEid.parseShortId(scopeIdString));
deviceQuery.setLimit(bplc.getLimit() + 1);
deviceQuery.setOffset(bplc.getOffset());
AndPredicate andPred = new AndPredicate();
if (predicates.getClientId() != null) {
andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.CLIENT_ID, predicates.getUnescapedClientId(), Operator.STARTS_WITH));
}
if (predicates.getDisplayName() != null) {
andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.DISPLAY_NAME, predicates.getUnescapedDisplayName(), Operator.STARTS_WITH));
}
if (predicates.getSerialNumber() != null) {
andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.SERIAL_NUMBER, predicates.getUnescapedSerialNumber()));
}
if (predicates.getDeviceStatus() != null) {
andPred = andPred.and(new AttributePredicate<DeviceStatus>(DevicePredicates.STATUS, DeviceStatus.valueOf(predicates.getDeviceStatus())));
}
if (predicates.getSortAttribute() != null) {
SortOrder sortOrder = SortOrder.ASCENDING;
if (predicates.getSortOrder().equals(SortOrder.DESCENDING.name())) {
sortOrder = SortOrder.DESCENDING;
}
if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name())) {
deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.CLIENT_ID, sortOrder));
} else if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name())) {
deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.DISPLAY_NAME, sortOrder));
} else if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name())) {
deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.LAST_EVENT_ON, sortOrder));
}
} else {
deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.CLIENT_ID, SortOrder.ASCENDING));
}
deviceQuery.setPredicate(andPred);
KapuaListResult<Device> devices = deviceRegistryService.query(deviceQuery);
totalResult = (int) deviceRegistryService.count(deviceQuery);
DeviceConnectionService deviceConnectionService = locator.getService(DeviceConnectionService.class);
DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
DeviceEventQuery eventQuery = deviceEventFactory.newQuery(deviceQuery.getScopeId());
eventQuery.setLimit(1);
eventQuery.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, SortOrder.DESCENDING));
for (Device d : devices.getItems()) {
DeviceConnection deviceConnection = deviceConnectionService.findByClientId(d.getScopeId(), d.getClientId());
// Connection info
GwtDevice gwtDevice = KapuaGwtConverter.convert(d);
gwtDevice.setConnectionIp(deviceConnection.getClientIp());
gwtDevice.setGwtDeviceConnectionStatus(deviceConnection.getStatus().name());
gwtDevice.setLastEventOn(deviceConnection.getModifiedOn());
// Event infos
eventQuery.setPredicate(new AttributePredicate<KapuaId>(DeviceEventPredicates.DEVICE_ID, d.getId()));
KapuaListResult<DeviceEvent> events = deviceEventService.query(eventQuery);
if (!events.isEmpty()) {
DeviceEvent lastEvent = events.getItem(0);
gwtDevice.setLastEventType(lastEvent.getResource());
gwtDevice.setLastEventOn(lastEvent.getReceivedOn());
}
gwtDevices.add(gwtDevice);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
gwtResults = new BasePagingLoadResult<GwtDevice>(gwtDevices);
gwtResults.setOffset(loadConfig.getOffset());
gwtResults.setTotalLength(totalResult);
return gwtResults;
}
Aggregations