Search in sources :

Example 1 with GuiPermission

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);
}
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 2 with GuiPermission

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

Example 3 with GuiPermission

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;
}
Also used : GuiComponentDetail(org.geosdi.geoplatform.gui.client.model.GuiComponentDetail) GuiPermission(org.geosdi.geoplatform.gui.client.model.GuiPermission) MenuItem(com.extjs.gxt.ui.client.widget.menu.MenuItem) Record(com.extjs.gxt.ui.client.store.Record) Menu(com.extjs.gxt.ui.client.widget.menu.Menu) ComponentEvent(com.extjs.gxt.ui.client.event.ComponentEvent) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

GuiPermission (org.geosdi.geoplatform.gui.client.model.GuiPermission)3 Record (com.extjs.gxt.ui.client.store.Record)2 GuiComponentDetail (org.geosdi.geoplatform.gui.client.model.GuiComponentDetail)2 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 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 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)1 GridCellRenderer (com.extjs.gxt.ui.client.widget.grid.GridCellRenderer)1 Menu (com.extjs.gxt.ui.client.widget.menu.Menu)1 MenuItem (com.extjs.gxt.ui.client.widget.menu.MenuItem)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1