use of org.geosdi.geoplatform.gui.client.model.GuiPermission in project geo-platform by geosdi.
the class ManageRolesWidget method prepareColumnModel.
private ColumnModel prepareColumnModel() {
List<ColumnConfig> configs = Lists.<ColumnConfig>newArrayList();
ColumnConfig iconColumn = new ColumnConfig();
iconColumn.setId("icon");
iconColumn.setHeaderHtml(UserModuleConstants.INSTANCE.ManageRolesWidget_iconText());
iconColumn.setWidth(35);
iconColumn.setFixed(true);
iconColumn.setResizable(false);
iconColumn.setSortable(false);
iconColumn.setRenderer(new GPGridCellRenderer<GuiComponentDetail>() {
@Override
public Object render(GuiComponentDetail model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GuiComponentDetail> store, Grid<GuiComponentDetail> grid) {
Button button = new Button();
button.setIcon(model.getImage());
button.setAutoWidth(true);
return button;
}
});
configs.add(iconColumn);
ColumnConfig idColumn = new ColumnConfig();
idColumn.setId(GuiComponentDetailKeyValue.COMPONENT_ID.toString());
idColumn.setHeaderHtml(UserModuleConstants.INSTANCE.ManageRolesWidget_componentIDText());
idColumn.setFixed(true);
configs.add(idColumn);
final SimpleComboBox<GuiPermission> permissionComboBox = new SimpleComboBox<GuiPermission>();
permissionComboBox.setEditable(false);
permissionComboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
permissionComboBox.add(Arrays.asList(GuiPermission.values()));
CellEditor comboEditor = new CellEditor(permissionComboBox) {
@Override
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return permissionComboBox.findModel((GuiPermission) value);
}
@Override
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((SimpleComboValue<GuiPermission>) value).getValue();
}
};
GridCellRenderer<GuiComponentDetail> rendererPermission = new GridCellRenderer<GuiComponentDetail>() {
@Override
public Object render(GuiComponentDetail model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GuiComponentDetail> store, Grid<GuiComponentDetail> grid) {
GuiPermission permission = model.getPermission();
return "<span style='color:" + permission.toStringColor() + "'>" + permission + "</span>";
}
};
ColumnConfig permissionColumn = new ColumnConfig();
permissionColumn.setId(GuiComponentDetailKeyValue.PERMISSION.toString());
permissionColumn.setHeaderHtml(UserModuleConstants.INSTANCE.ManageRolesWidget_permissionsText());
permissionColumn.setWidth(150);
permissionColumn.setFixed(true);
permissionColumn.setEditor(comboEditor);
permissionColumn.setRenderer(rendererPermission);
configs.add(permissionColumn);
return new ColumnModel(configs);
}
use of org.geosdi.geoplatform.gui.client.model.GuiPermission in project geo-platform by geosdi.
the class ManageRolesWidget method savePermissions.
private void savePermissions() {
grid.stopEditing(true);
List<Record> modifiedElements = store.getModifiedRecords();
final HashMap<String, Boolean> permissionMap = Maps.<String, Boolean>newHashMapWithExpectedSize(modifiedElements.size());
for (Record record : modifiedElements) {
String componentId = record.get(GuiComponentDetailKeyValue.COMPONENT_ID.toString()).toString();
GuiPermission permission = (GuiPermission) record.get(GuiComponentDetailKeyValue.PERMISSION.toString());
permissionMap.put(componentId, permission.toBoolean());
}
mask(UserModuleMessages.INSTANCE.savingRolePermissionsMessage(role));
xsrf.getNewXsrfToken(new AsyncCallback<XsrfToken>() {
@Override
public void onFailure(Throwable caught) {
try {
throw caught;
} catch (RpcTokenException e) {
// Can be thrown for several reasons:
// - duplicate session cookie, which may be a sign of a cookie
// overwrite attack
// - XSRF token cannot be generated because session cookie isn't
// present
} catch (Throwable e) {
// unexpected
}
}
@Override
public void onSuccess(XsrfToken token) {
((HasRpcToken) userRemote).setRpcToken(token);
userRemote.updateRolePermission(role, GPAccountLogged.getInstance().getOrganization(), permissionMap, new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
setSearchStatus(EnumSearchStatus.STATUS_SEARCH_ERROR, UserModuleMessages.INSTANCE.errorSavingRolePermissionsMessage(role));
}
@Override
public void onSuccess(Boolean result) {
store.commitChanges();
disableGridButtons();
setSearchStatus(EnumSearchStatus.STATUS_SEARCH, UserModuleMessages.INSTANCE.permissionsRoleSuccesfullySavedMessage(role));
unmask();
}
});
}
});
}
use of org.geosdi.geoplatform.gui.client.model.GuiPermission in project geo-platform by geosdi.
the class ManageRolesWidget method createPermissionsMenu.
private Menu createPermissionsMenu() {
Menu permissionMenu = new Menu();
for (final GuiPermission permission : GuiPermission.values()) {
MenuItem permissionItem = new MenuItem(permission.toString());
permissionItem.addSelectionListener(new SelectionListener() {
@Override
public void componentSelected(ComponentEvent ce) {
// Set selected permission for all permissions
for (GuiComponentDetail gc : guiComponents) {
Record r = store.getRecord(gc);
r.set(GuiComponentDetailKeyValue.PERMISSION.toString(), permission);
}
setSearchStatus(EnumSearchStatus.STATUS_SEARCH, UserModuleMessages.INSTANCE.permissionsValueSettedMessage(permission.toString()));
}
});
permissionMenu.add(permissionItem);
}
return permissionMenu;
}
Aggregations