blob: 45d037d942186bff52fbbcd1aefc19413a33a74a [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*
*/
package org.eclipse.osbp.ecview.extension.grid.util;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.ecview.extension.grid.CxGrid;
import org.eclipse.osbp.ecview.extension.grid.CxGridColumn;
import org.eclipse.osbp.ui.api.useraccess.AbstractAuthorization.Action;
import org.eclipse.osbp.ui.api.useraccess.AbstractAuthorization.Group;
import org.eclipse.osbp.ui.api.useraccess.IUserAccessService;
/**
* The Class CxGridUtil.
*/
public class CxGridUtil {
/**
* Returns the grid.
*
* @param eObject
* the e object
* @return the grid
*/
public static CxGrid getGrid(EObject eObject) {
if (eObject == null) {
return null;
}
if (eObject instanceof CxGrid) {
return (CxGrid) eObject;
} else {
return getGrid(eObject.eContainer());
}
}
/**
* Modifies the columns of the grid due to the existing user permissions
*
* @param userAccessService
* @param grid
* @return
*/
public static CxGrid setPermissions(IUserAccessService userAccessService, CxGrid grid) {
if (userAccessService == null) {
grid.setVisible(true);
} else {
String dtoName = grid.getTypeQualifiedName();
for (CxGridColumn column : grid.getColumns()) {
String dtoProperty = column.getPropertyId();
if (userAccessService.isGranted(Group.DTO, Action.READABLE, dtoName)) {
column.setHidden(false);
column.setEditable(true);
boolean columnHidden = userAccessService.isVetoed(Group.DTO, Action.INVISIBLE ,dtoName, dtoProperty);
if (!columnHidden) {
boolean columnEditable = !userAccessService.isVetoed(Group.DTO, Action.NONEDITABLE ,dtoName, dtoProperty);
boolean columnEnabled = !userAccessService.isVetoed(Group.DTO, Action.DISABLED ,dtoName, dtoProperty);
column.setEditable(columnEditable && columnEnabled);
} else {
column.setHidden(columnHidden);
}
}
}
}
return grid;
}
}