Search in sources :

Example 1 with GPGridCellRenderer

use of org.geosdi.geoplatform.gui.client.widget.grid.renderer.GPGridCellRenderer 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)

Aggregations

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 GuiComponentDetail (org.geosdi.geoplatform.gui.client.model.GuiComponentDetail)1 GuiPermission (org.geosdi.geoplatform.gui.client.model.GuiPermission)1 GPGridCellRenderer (org.geosdi.geoplatform.gui.client.widget.grid.renderer.GPGridCellRenderer)1