Search in sources :

Example 1 with GuiComponentDetail

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();
                }
            });
        }
    });
}
Also used : GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail) HashMap(java.util.HashMap) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) RpcTokenException(com.google.gwt.user.client.rpc.RpcTokenException) XsrfToken(com.google.gwt.user.client.rpc.XsrfToken)

Example 2 with GuiComponentDetail

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);
}
Also used : SimpleComboBox(com.extjs.gxt.ui.client.widget.form.SimpleComboBox) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) GuiPermission(org.geosdi.geoplatform.gui.client.model.GuiPermission) CellEditor(com.extjs.gxt.ui.client.widget.grid.CellEditor) SimpleComboValue(com.extjs.gxt.ui.client.widget.form.SimpleComboValue) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) EditorGrid(com.extjs.gxt.ui.client.widget.grid.EditorGrid) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) ListStore(com.extjs.gxt.ui.client.store.ListStore) GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail) GridCellRenderer(com.extjs.gxt.ui.client.widget.grid.GridCellRenderer) GPGridCellRenderer(org.geosdi.geoplatform.gui.client.widget.grid.renderer.GPGridCellRenderer) SplitButton(com.extjs.gxt.ui.client.widget.button.SplitButton) Button(com.extjs.gxt.ui.client.widget.button.Button) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 3 with GuiComponentDetail

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);
    }
}
Also used : GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail)

Example 4 with GuiComponentDetail

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;
}
Also used : AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail) MenuActionRegistar(org.geosdi.geoplatform.gui.action.menu.MenuActionRegistar) MenuBaseAction(org.geosdi.geoplatform.gui.action.menu.MenuBaseAction) GeoPlatformAction(org.geosdi.geoplatform.gui.configuration.action.GeoPlatformAction)

Example 5 with GuiComponentDetail

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();
                }
            });
        }
    });
}
Also used : GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) RpcTokenException(com.google.gwt.user.client.rpc.RpcTokenException) XsrfToken(com.google.gwt.user.client.rpc.XsrfToken)

Aggregations

GuiComponentDetail (org.geosdi.geoplatform.gui.client.model.GuiComponentDetail)7 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 RpcTokenException (com.google.gwt.user.client.rpc.RpcTokenException)3 XsrfToken (com.google.gwt.user.client.rpc.XsrfToken)3 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)2 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)2 Record (com.extjs.gxt.ui.client.store.Record)2 MenuItem (com.extjs.gxt.ui.client.widget.menu.MenuItem)2 HashMap (java.util.HashMap)2 GuiPermission (org.geosdi.geoplatform.gui.client.model.GuiPermission)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 Button (com.extjs.gxt.ui.client.widget.button.Button)1 SplitButton (com.extjs.gxt.ui.client.widget.button.SplitButton)1 SimpleComboBox (com.extjs.gxt.ui.client.widget.form.SimpleComboBox)1 SimpleComboValue (com.extjs.gxt.ui.client.widget.form.SimpleComboValue)1 CellEditor (com.extjs.gxt.ui.client.widget.grid.CellEditor)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 EditorGrid (com.extjs.gxt.ui.client.widget.grid.EditorGrid)1