use of org.geosdi.geoplatform.gui.client.model.GuiComponentDetail in project geo-platform by geosdi.
the class ManageRolesWidget method loadPermissions.
private void loadPermissions() {
mask(UserModuleMessages.INSTANCE.retrievingRolePermissionsMessage(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.getRolePermission(role, GPAccountLogged.getInstance().getOrganization(), new AsyncCallback<HashMap<String, Boolean>>() {
@Override
public void onFailure(Throwable caught) {
setSearchStatus(EnumSearchStatus.STATUS_SEARCH_ERROR, UserModuleMessages.INSTANCE.errorRetrievingRolePermissionsMessage(role));
}
@Override
public void onSuccess(HashMap<String, Boolean> result) {
grid.stopEditing(true);
ManageRolesWidget.this.store.removeAll();
for (GuiComponentDetail gc : guiComponents) {
Boolean booleanPermission = result.get(gc.getComponentId());
gc.setPermission(GuiPermission.fromBoolean(booleanPermission));
ManageRolesWidget.this.store.add(gc);
}
// i.e. MANAGE_ROLES will not be modified for a ADMIN role
if (role.equals(GPRole.ADMIN.getRole())) {
for (GuiComponentDetail gc : guiComponents) {
if (gc.getComponentId().equals("manageRoles")) {
ManageRolesWidget.this.store.remove(gc);
break;
}
}
}
setSearchStatus(EnumSearchStatus.STATUS_SEARCH, UserModuleMessages.INSTANCE.rolePermissionsSuccesfullyRetrievedMessage(role));
enableModifyButtons();
ManageRolesWidget.this.unmask();
}
});
}
});
}
use of org.geosdi.geoplatform.gui.client.model.GuiComponentDetail 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.GuiComponentDetail in project geo-platform by geosdi.
the class ManageRolesWidget method setGuiComponentIDs.
public void setGuiComponentIDs(List<String> guiComponentIDs) {
this.guiComponentIDs = guiComponentIDs;
Collections.sort(guiComponentIDs);
this.guiComponents = new ArrayList<GuiComponentDetail>(guiComponentIDs.size());
for (String componentId : guiComponentIDs) {
GuiComponentDetail gc = this.createGuiComponentDetail(componentId);
guiComponents.add(gc);
}
}
use of org.geosdi.geoplatform.gui.client.model.GuiComponentDetail in project geo-platform by geosdi.
the class ManageRolesWidget method createGuiComponentDetail.
private GuiComponentDetail createGuiComponentDetail(String componentId) {
GuiComponentDetail gc = new GuiComponentDetail();
gc.setComponentId(componentId);
// gc.setDescription(action.get....()); // TODO Manage description
// TODO Manage icon
MenuActionRegistar menuRegistar = BasicGinInjector.MainInjector.getInstance().getMenuActionRegistar();
GeoPlatformAction action = menuRegistar.get(componentId);
if (action != null) {
if (action instanceof MenuBaseAction) {
AbstractImagePrototype image = ((MenuBaseAction) action).getImage();
if (image != null) {
gc.setImage(image);
}
// }else{
// action = ToolbarActionRegistar.get(entry.getKey(), null)
}
}
if (gc.getImage() == null) {
gc.setImage(defaultImage);
}
return gc;
}
use of org.geosdi.geoplatform.gui.client.model.GuiComponentDetail in project geo-platform by geosdi.
the class ManageRolesWidget method saveNewRole.
private void saveNewRole() {
mask(UserModuleMessages.INSTANCE.savingNewRoleMessage(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.saveRole(role, GPAccountLogged.getInstance().getOrganization(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
setSearchStatus(EnumSearchStatus.STATUS_SEARCH_ERROR, UserModuleMessages.INSTANCE.errorSavingNewRoleMessage(role));
}
@Override
public void onSuccess(Boolean result) {
// Set default permission NONE for all permissions
store.removeAll();
for (GuiComponentDetail gc : guiComponents) {
gc.setPermission(GuiPermission.NONE);
store.add(gc);
}
roles.add(role);
rolesComboBox.add(role);
rolesComboBox.setSimpleValue(role);
addRoleMenuItem(role);
setSearchStatus(EnumSearchStatus.STATUS_SEARCH, UserModuleMessages.INSTANCE.newRoleCreatedMessage(role));
enableModifyButtons();
unmask();
}
});
}
});
}
Aggregations