use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.
the class AccountView method getAccountsGrid.
private Grid<GwtAccount> getAccountsGrid() {
//
// Column Configuration
ColumnConfig column = null;
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
column = new ColumnConfig("status", 30);
column.setAlignment(HorizontalAlignment.CENTER);
GridCellRenderer<GwtAccount> setStatusIcon = new GridCellRenderer<GwtAccount>() {
public String render(GwtAccount model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtAccount> employeeList, Grid<GwtAccount> grid) {
return "<image src=\"eclipse/org/eclipse/kapua/app/console/icon/green.gif\" width=\"12\" height=\"12\" style=\"vertical-align: bottom\" title=\"" + MSGS.enabled() + "\"/>";
}
};
column.setRenderer(setStatusIcon);
configs.add(column);
column = new ColumnConfig("name", 120);
column.setHeader(MSGS.accountTableName());
column.setWidth(150);
configs.add(column);
column = new ColumnConfig("modifiedOnFormatted", MSGS.accountTableModifiedOn(), 130);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
m_columnModel = new ColumnModel(configs);
// rpc data proxy
RpcProxy<ListLoadResult<GwtAccount>> proxy = new RpcProxy<ListLoadResult<GwtAccount>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtAccount>> callback) {
gwtAccountService.findChildren(m_currentSession.getSelectedAccount().getId(), false, callback);
}
};
// grid loader
m_accountLoader = new BaseListLoader<ListLoadResult<GwtAccount>>(proxy);
SwappableListStore<GwtAccount> store = new SwappableListStore<GwtAccount>(m_accountLoader);
store.setKeyProvider(new ModelKeyProvider<GwtAccount>() {
public String getKey(GwtAccount gwtAccount) {
return String.valueOf(gwtAccount.getId());
}
});
//
// Grid
m_grid = new Grid<GwtAccount>(store, m_columnModel);
m_grid.setBorders(false);
m_grid.setStateful(false);
m_grid.setLoadMask(true);
m_grid.setStripeRows(true);
m_grid.setTrackMouseOver(false);
m_grid.setAutoExpandColumn("name");
m_grid.mask(MSGS.loading());
m_grid.getView().setAutoFill(true);
GridView gridView = m_grid.getView();
gridView.setEmptyText(MSGS.accountTableNoAccounts());
m_accountLoader.addLoadListener(new DataLoadListener(m_grid));
GridSelectionModel<GwtAccount> selectionModel = new GridSelectionModel<GwtAccount>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_grid.setSelectionModel(selectionModel);
m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtAccount>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtAccount> se) {
// Manage buttons
if (se.getSelectedItem() != null) {
m_editButton.setEnabled(m_currentSession.hasAccountUpdatePermission());
m_deleteButton.setEnabled(m_currentSession.hasAccountDeletePermission());
} else {
m_editButton.setEnabled(false);
m_deleteButton.setEnabled(false);
}
// Set account on tabs
if (se.getSelectedItem() != null) {
m_accountTabs.setAccount(m_grid.getSelectionModel().getSelectedItem());
}
}
});
//
// populate with initial status
updateAccountGrid(null);
return m_grid;
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.
the class DeviceConfigComponents method initConfigPanel.
@SuppressWarnings("unchecked")
private void initConfigPanel() {
m_configPanel = new ContentPanel();
m_configPanel.setBorders(false);
m_configPanel.setBodyBorder(false);
m_configPanel.setHeaderVisible(false);
m_configPanel.setStyleAttribute("background-color", "white");
m_configPanel.setScrollMode(Scroll.AUTO);
BorderLayout borderLayout = new BorderLayout();
m_configPanel.setLayout(borderLayout);
// center
m_centerData = new BorderLayoutData(LayoutRegion.CENTER);
m_centerData.setMargins(new Margins(0));
// west
BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 200);
westData.setSplit(true);
westData.setCollapsible(true);
westData.setMargins(new Margins(0, 5, 0, 0));
// loader and store
RpcProxy<List<GwtConfigComponent>> proxy = new RpcProxy<List<GwtConfigComponent>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<GwtConfigComponent>> callback) {
if (m_selectedDevice != null && m_dirty && m_initialized) {
if (m_selectedDevice.isOnline()) {
m_tree.mask(MSGS.loading());
gwtDeviceManagementService.findDeviceConfigurations(m_selectedDevice, callback);
} else {
List<GwtConfigComponent> comps = new ArrayList<GwtConfigComponent>();
GwtConfigComponent comp = new GwtConfigComponent();
comp.setId(MSGS.deviceNoDeviceSelected());
comp.setName(MSGS.deviceNoComponents());
comp.setDescription(MSGS.deviceNoConfigSupported());
comps.add(comp);
callback.onSuccess(comps);
}
} else {
List<GwtConfigComponent> comps = new ArrayList<GwtConfigComponent>();
GwtConfigComponent comp = new GwtConfigComponent();
comp.setId(MSGS.deviceNoDeviceSelected());
comp.setName(MSGS.deviceNoDeviceSelected());
comp.setDescription(MSGS.deviceNoDeviceSelected());
comps.add(comp);
callback.onSuccess(comps);
}
m_dirty = false;
}
};
m_loader = new BaseTreeLoader<GwtConfigComponent>(proxy);
m_loader.addLoadListener(new DataLoadListener());
m_treeStore = new TreeStore<ModelData>(m_loader);
m_tree = new TreePanel<ModelData>(m_treeStore);
m_tree.setWidth(200);
m_tree.setDisplayProperty("componentName");
m_tree.setBorders(true);
m_tree.setAutoSelect(true);
m_tree.setStyleAttribute("background-color", "white");
m_configPanel.add(m_tree, westData);
//
// Selection Listener for the component
// make sure the form is not dirty before switching.
m_tree.getSelectionModel().addListener(Events.BeforeSelect, new Listener<BaseEvent>() {
@SuppressWarnings("rawtypes")
@Override
public void handleEvent(BaseEvent be) {
final BaseEvent theEvent = be;
SelectionEvent<ModelData> se = (SelectionEvent<ModelData>) be;
final GwtConfigComponent componentToSwitchTo = (GwtConfigComponent) se.getModel();
if (m_devConfPanel != null && m_devConfPanel.isDirty()) {
// cancel the event first
theEvent.setCancelled(true);
// need to reselect the current entry
// as the BeforeSelect event cleared it
// we need to do this without raising events
TreePanelSelectionModel selectionModel = (TreePanelSelectionModel) m_tree.getSelectionModel();
selectionModel.setFiresEvents(false);
selectionModel.select(false, m_devConfPanel.getConfiguration());
selectionModel.setFiresEvents(true);
// ask for confirmation before switching
MessageBox.confirm(MSGS.confirm(), MSGS.deviceConfigDirty(), new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
// if confirmed, delete
Dialog dialog = ce.getDialog();
if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
m_devConfPanel.removeFromParent();
m_devConfPanel = null;
m_tree.getSelectionModel().select(false, componentToSwitchTo);
}
}
});
} else {
refreshConfigPanel(componentToSwitchTo);
// this is needed to select the item in the Tree
// Temporarly disable the firing of the selection events
// to avoid an infinite loop as BeforeSelect would be invoked again.
TreePanelSelectionModel selectionModel = (TreePanelSelectionModel) m_tree.getSelectionModel();
selectionModel.setFiresEvents(false);
selectionModel.select(false, componentToSwitchTo);
// renable firing of the events
selectionModel.setFiresEvents(true);
}
}
});
m_tree.setIconProvider(new ModelIconProvider<ModelData>() {
public AbstractImagePrototype getIcon(ModelData model) {
if (model instanceof GwtConfigComponent) {
String icon = ((GwtConfigComponent) model).getComponentIcon();
if ("CloudService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.cloud16());
} else if ("ClockService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.clock16());
} else if ("DataService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.databaseConnect());
} else if ("DiagnosticsService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.diagnostics());
} else if ("MqttDataTransport".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.mqtt());
} else if ("PositionService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.gps16());
} else if ("SslManagerService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.lock16());
} else if ("WatchdogService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.dog16());
} else if ("CommandPasswordService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.terminal());
} else if ("VpnService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.vpn());
} else if ("ProvisioningService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.provisioning16());
} else if ("DenaliService".equals(icon)) {
// WebConsole: DenaliService
return AbstractImagePrototype.create(Resources.INSTANCE.monitorDenali());
} else if ("BluetoothService".equals(icon)) {
// Bluetooth: BluetoothService
return AbstractImagePrototype.create(Resources.INSTANCE.bluetooth());
} else if (icon != null && icon.toLowerCase().startsWith("img://")) {
// Replace the base fake protocol with the console base URL
// that was not available on the server side.
icon = icon.replaceFirst("img://", GWT.getHostPageBaseURL());
return new ScaledAbstractImagePrototype(IconHelper.createPath(icon, 16, 16));
} else {
return AbstractImagePrototype.create(Resources.INSTANCE.plugin16());
}
}
return null;
}
});
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.
the class DeviceForm method onRender.
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
FormData formData = new FormData("-20");
m_formPanel = new FormPanel();
m_formPanel.setFrame(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setHeaderVisible(false);
m_formPanel.setWidth(310);
m_formPanel.setScrollMode(Scroll.AUTOY);
m_formPanel.setStyleAttribute("padding-bottom", "0px");
m_formPanel.setLayout(new FlowLayout());
// Device general info fieldset
FieldSet fieldSet = new FieldSet();
FormLayout layout = new FormLayout();
layout.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
fieldSet.setLayout(layout);
fieldSet.setHeading(MSGS.deviceFormFieldsetGeneralInfo());
// Device Client ID
clientIdLabel = new LabelField();
clientIdLabel.setFieldLabel(MSGS.deviceFormClientID());
clientIdLabel.setLabelSeparator(":");
clientIdLabel.setWidth(225);
fieldSet.add(clientIdLabel, formData);
clientIdField = new TextField<String>();
clientIdField.setAllowBlank(false);
clientIdField.setName("clientID");
clientIdField.setFieldLabel(MSGS.deviceFormClientID());
clientIdField.setValidator(new TextFieldValidator(clientIdField, FieldType.DEVICE_CLIENT_ID));
clientIdField.setWidth(225);
fieldSet.add(clientIdField, formData);
// Display name
displayNameField = new TextField<String>();
displayNameField.setAllowBlank(true);
displayNameField.setName("displayName");
displayNameField.setFieldLabel(MSGS.deviceFormDisplayName());
displayNameField.setWidth(225);
fieldSet.add(displayNameField, formData);
// Device Status
statusCombo = new SimpleComboBox<GwtDeviceQueryPredicates.GwtDeviceStatus>();
statusCombo.setName("status");
statusCombo.setFieldLabel(MSGS.deviceFormStatus());
statusCombo.setEditable(false);
statusCombo.setTriggerAction(TriggerAction.ALL);
statusCombo.setEmptyText(MSGS.deviceFilteringPanelStatusEmptyText());
statusCombo.add(GwtDeviceQueryPredicates.GwtDeviceStatus.ENABLED);
statusCombo.add(GwtDeviceQueryPredicates.GwtDeviceStatus.DISABLED);
fieldSet.add(statusCombo, formData);
// Tag fieldset
FieldSet fieldSetTags = new FieldSet();
FormLayout layoutTags = new FormLayout();
layoutTags.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
fieldSetTags.setLayout(layoutTags);
fieldSetTags.setHeading(MSGS.deviceFormFieldsetTags());
ContentPanel panel = new ContentPanel();
panel.setBorders(false);
panel.setBodyBorder(false);
panel.setHeaderVisible(false);
panel.setLayout(new RowLayout(Orientation.HORIZONTAL));
panel.setBodyStyle("background-color:transparent");
panel.setHeight(35);
// Device Custom attributes fieldset
FormLayout layoutSecurityOptions = new FormLayout();
layoutSecurityOptions.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
FieldSet fieldSetSecurityOptions = new FieldSet();
fieldSetSecurityOptions.setLayout(layoutSecurityOptions);
fieldSetSecurityOptions.setHeading(MSGS.deviceFormFieldsetSecurityOptions());
// Provisioned Credentials Tight
credentialsTightCombo = new SimpleComboBox<String>();
credentialsTightCombo.setName("provisionedCredentialsTight");
credentialsTightCombo.setEditable(false);
credentialsTightCombo.setTypeAhead(false);
credentialsTightCombo.setAllowBlank(false);
credentialsTightCombo.setFieldLabel(MSGS.deviceFormProvisionedCredentialsTight());
credentialsTightCombo.setToolTip(MSGS.deviceFormProvisionedCredentialsTightTooltip());
credentialsTightCombo.setTriggerAction(TriggerAction.ALL);
fieldSetSecurityOptions.add(credentialsTightCombo, formData);
credentialsTightCombo.add(GwtDeviceCredentialsTight.INHERITED.getLabel());
credentialsTightCombo.add(GwtDeviceCredentialsTight.LOOSE.getLabel());
credentialsTightCombo.add(GwtDeviceCredentialsTight.STRICT.getLabel());
credentialsTightCombo.setSimpleValue(GwtDeviceCredentialsTight.INHERITED.getLabel());
// Device User
RpcProxy<ListLoadResult<GwtUser>> deviceUserProxy = new RpcProxy<ListLoadResult<GwtUser>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtUser>> callback) {
gwtUserService.findAll(m_currentSession.getSelectedAccount().getId(), callback);
}
};
BaseListLoader<ListLoadResult<GwtUser>> deviceUserLoader = new BaseListLoader<ListLoadResult<GwtUser>>(deviceUserProxy);
ListStore<GwtUser> deviceUserStore = new ListStore<GwtUser>(deviceUserLoader);
deviceUserCombo = new ComboBox<GwtUser>();
deviceUserCombo.setName("deviceUserCombo");
deviceUserCombo.setEditable(false);
deviceUserCombo.setTypeAhead(false);
deviceUserCombo.setAllowBlank(false);
deviceUserCombo.setFieldLabel(MSGS.deviceFormDeviceUser());
deviceUserCombo.setTriggerAction(TriggerAction.ALL);
deviceUserCombo.setStore(deviceUserStore);
deviceUserCombo.setDisplayField("username");
deviceUserCombo.setValueField("id");
fieldSetSecurityOptions.add(deviceUserCombo, formData);
// Allow credential change
allowCredentialsChangeCheckbox = new CheckBox();
allowCredentialsChangeCheckbox.setName("allowNewUnprovisionedDevicesCheckbox");
allowCredentialsChangeCheckbox.setFieldLabel(MSGS.deviceFormAllowCredentialsChange());
allowCredentialsChangeCheckbox.setToolTip(MSGS.deviceFormAllowCredentialsChangeTooltip());
allowCredentialsChangeCheckbox.setBoxLabel("");
fieldSetSecurityOptions.add(allowCredentialsChangeCheckbox, formData);
// Device Custom attributes fieldset
FieldSet fieldSetCustomAttributes = new FieldSet();
FormLayout layoutCustomAttributes = new FormLayout();
layoutCustomAttributes.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
fieldSetCustomAttributes.setLayout(layoutCustomAttributes);
fieldSetCustomAttributes.setHeading(MSGS.deviceFormFieldsetCustomAttributes());
// Custom Attribute #1
customAttribute1Field = new TextField<String>();
customAttribute1Field.setName("customAttribute1");
customAttribute1Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute1());
customAttribute1Field.setWidth(225);
fieldSetCustomAttributes.add(customAttribute1Field, formData);
// Custom Attribute #2
customAttribute2Field = new TextField<String>();
customAttribute2Field.setName("customAttribute2");
customAttribute2Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute2());
customAttribute2Field.setWidth(225);
fieldSetCustomAttributes.add(customAttribute2Field, formData);
// Custom Attribute #3
customAttribute3Field = new TextField<String>();
customAttribute3Field.setName("customAttribute3");
customAttribute3Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute3());
customAttribute3Field.setWidth(225);
fieldSetCustomAttributes.add(customAttribute3Field, formData);
// Custom Attribute #4
customAttribute4Field = new TextField<String>();
customAttribute4Field.setName("customAttribute4");
customAttribute4Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute4());
customAttribute4Field.setWidth(225);
fieldSetCustomAttributes.add(customAttribute4Field, formData);
// Custom Attribute #5
customAttribute5Field = new TextField<String>();
customAttribute5Field.setName("customAttribute5");
customAttribute5Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute5());
customAttribute5Field.setWidth(225);
fieldSetCustomAttributes.add(customAttribute5Field, formData);
// Optlock
optlock = new NumberField();
optlock.setName("optlock");
optlock.setEditable(false);
optlock.setVisible(false);
fieldSet.add(optlock, formData);
m_formPanel.add(fieldSet);
m_formPanel.add(fieldSetTags);
m_formPanel.add(fieldSetSecurityOptions);
m_formPanel.add(fieldSetCustomAttributes);
m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
Button submitButton = new Button(MSGS.deviceFormSubmitButton());
submitButton.addListener(Events.OnClick, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
// make sure all visible fields are valid before performing the action
for (Field<?> field : m_formPanel.getFields()) {
if (field.isVisible() && !field.isValid()) {
MessageBox.alert(MSGS.error(), MSGS.formErrors(), null);
return;
}
}
if (m_selectedDevice == null) {
final GwtDeviceCreator gwtDeviceCreator = new GwtDeviceCreator();
gwtDeviceCreator.setScopeId(m_currentSession.getSelectedAccount().getId());
gwtDeviceCreator.setClientId(clientIdField.getValue());
gwtDeviceCreator.setDisplayName(displayNameField.getValue());
// Security Options
gwtDeviceCreator.setGwtCredentialsTight(credentialsTightCombo.getSimpleValue());
gwtDeviceCreator.setGwtPreferredUserId(deviceUserCombo.getValue().getId());
// Custom attributes
gwtDeviceCreator.setCustomAttribute1(unescapeValue(customAttribute1Field.getValue()));
gwtDeviceCreator.setCustomAttribute2(unescapeValue(customAttribute2Field.getValue()));
gwtDeviceCreator.setCustomAttribute3(unescapeValue(customAttribute3Field.getValue()));
gwtDeviceCreator.setCustomAttribute4(unescapeValue(customAttribute4Field.getValue()));
gwtDeviceCreator.setCustomAttribute5(unescapeValue(customAttribute5Field.getValue()));
//
// Getting XSRF token
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtDeviceService.createDevice(token, gwtDeviceCreator, new AsyncCallback<GwtDevice>() {
@Override
public void onFailure(Throwable caught) {
FailureHandler.handle(caught);
}
public void onSuccess(final GwtDevice gwtDevice) {
//
// Getting XSRF token
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
hide();
ConsoleInfo.display(MSGS.info(), MSGS.deviceUpdateSuccess());
}
});
}
});
}
});
} else // Edit
{
// General info
m_selectedDevice.setDisplayName(unescapeValue(displayNameField.getValue()));
m_selectedDevice.setGwtDeviceStatus(statusCombo.getSimpleValue().name());
// Security Options
m_selectedDevice.setCredentialsTight(GwtDeviceCredentialsTight.getEnumFromLabel(credentialsTightCombo.getSimpleValue()).name());
m_selectedDevice.setCredentialsAllowChange(allowCredentialsChangeCheckbox.getValue());
m_selectedDevice.setDeviceUserId(deviceUserCombo.getValue().getId());
// Custom attributes
m_selectedDevice.setCustomAttribute1(unescapeValue(customAttribute1Field.getValue()));
m_selectedDevice.setCustomAttribute2(unescapeValue(customAttribute2Field.getValue()));
m_selectedDevice.setCustomAttribute3(unescapeValue(customAttribute3Field.getValue()));
m_selectedDevice.setCustomAttribute4(unescapeValue(customAttribute4Field.getValue()));
m_selectedDevice.setCustomAttribute5(unescapeValue(customAttribute5Field.getValue()));
// Optlock
m_selectedDevice.setOptlock(optlock.getValue().intValue());
//
// Getting XSRF token
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtDeviceService.updateAttributes(token, m_selectedDevice, new AsyncCallback<GwtDevice>() {
public void onFailure(Throwable caught) {
FailureHandler.handle(caught);
}
public void onSuccess(GwtDevice gwtDevice) {
//
// Getting XSRF token
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
hide();
ConsoleInfo.display(MSGS.info(), m_selectedDevice == null ? MSGS.deviceCreationSuccess() : MSGS.deviceUpdateSuccess());
}
});
}
});
}
});
}
}
});
Button cancelButton = new Button(MSGS.deviceFormCancelButton());
cancelButton.addListener(Events.OnClick, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
hide();
}
});
m_formPanel.addButton(submitButton);
m_formPanel.addButton(cancelButton);
add(m_formPanel);
// Hide components according to NEW/EDIT mode
makeNewEditAppearance();
// Populate fields if we are in EDIT mode
if (m_selectedDevice != null) {
populateFields();
}
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.
the class DeviceTabBundles method initGrid.
private void initGrid() {
RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
if (m_selectedDevice != null) {
if (m_selectedDevice.isOnline()) {
gwtDeviceManagementService.findBundles(m_selectedDevice, callback);
} else {
m_grid.getStore().removeAll();
m_grid.unmask();
}
}
}
};
m_loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
m_loader.addLoadListener(new DataLoadListener());
m_store = new ListStore<GwtGroupedNVPair>(m_loader);
ColumnConfig id = new ColumnConfig("id", MSGS.deviceBndId(), 10);
ColumnConfig name = new ColumnConfig("name", MSGS.deviceBndName(), 50);
ColumnConfig status = new ColumnConfig("statusLoc", MSGS.deviceBndState(), 20);
ColumnConfig version = new ColumnConfig("version", MSGS.deviceBndVersion(), 20);
List<ColumnConfig> config = new ArrayList<ColumnConfig>();
config.add(id);
config.add(name);
config.add(status);
config.add(version);
ColumnModel cm = new ColumnModel(config);
GridView view = new GridView();
view.setForceFit(true);
view.setEmptyText(MSGS.deviceNoDeviceSelectedOrOffline());
m_grid = new Grid<GwtGroupedNVPair>(m_store, cm);
m_grid.setView(view);
m_grid.setBorders(false);
m_grid.setLoadMask(true);
m_grid.setStripeRows(true);
GridSelectionModel<GwtGroupedNVPair> selectionModel = new GridSelectionModel<GwtGroupedNVPair>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_grid.setSelectionModel(selectionModel);
m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtGroupedNVPair>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtGroupedNVPair> se) {
if (m_grid.getSelectionModel().getSelectedItem() != null) {
GwtGroupedNVPair selectedBundle = m_grid.getSelectionModel().getSelectedItem();
if ("bndActive".equals(selectedBundle.getStatus())) {
m_startButton.disable();
m_stopButton.enable();
} else {
m_stopButton.disable();
m_startButton.enable();
}
}
}
});
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.
the class DeviceTabProfile method onRender.
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FitLayout());
setBorders(false);
ContentPanel tabProfileContentPanel = new ContentPanel();
tabProfileContentPanel.setLayout(new FitLayout());
tabProfileContentPanel.setBorders(false);
tabProfileContentPanel.setBodyBorder(false);
tabProfileContentPanel.setHeaderVisible(false);
tabProfileContentPanel.setTopComponent(getToolbar());
RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
if (m_selectedDevice != null) {
gwtDeviceService.findDeviceProfile(m_selectedDevice.getScopeId(), m_selectedDevice.getClientId(), callback);
}
}
};
m_loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
m_loader.addLoadListener(new DataLoadListener());
m_store = new GroupingStore<GwtGroupedNVPair>(m_loader);
m_store.groupBy("groupLoc");
ColumnConfig name = new ColumnConfig("nameLoc", MSGS.devicePropName(), 50);
ColumnConfig value = new ColumnConfig("value", MSGS.devicePropValue(), 50);
GridCellRenderer<GwtGroupedNVPair> renderer = new GridCellRenderer<GwtGroupedNVPair>() {
@Override
public Object render(GwtGroupedNVPair model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtGroupedNVPair> store, Grid<GwtGroupedNVPair> grid) {
if (model.getName().equals("devLastEventOn") && model.getValue().compareTo("N/A") != 0) {
return DateUtils.formatDateTime(new Date(Long.parseLong(model.getValue())));
}
return model.getValue();
}
};
value.setRenderer(renderer);
List<ColumnConfig> config = new ArrayList<ColumnConfig>();
config.add(name);
config.add(value);
ColumnModel cm = new ColumnModel(config);
GroupingView view = new GroupingView();
view.setShowGroupedColumn(false);
view.setForceFit(true);
view.setEmptyText(MSGS.deviceNoDeviceSelected());
m_grid = new Grid<GwtGroupedNVPair>(m_store, cm);
m_grid.setView(view);
m_grid.setBorders(false);
m_grid.setLoadMask(true);
m_grid.setStripeRows(true);
m_grid.disableTextSelection(false);
tabProfileContentPanel.add(m_grid);
add(tabProfileContentPanel);
m_initialized = true;
}
Aggregations