1 19 package org.lucane.client.acl; 20 21 import org.lucane.common.acl.AclInfo; 22 import org.lucane.client.util.Translation; 23 import org.lucane.client.Plugin; 24 25 import javax.swing.table.AbstractTableModel ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 29 public class AclTableModel extends AbstractTableModel 30 { 31 private static final String [] columns = {"acl.lbl.permission", "acl.lbl.allow", "acl.lbl.deny"}; 32 33 private Plugin plugin; 34 private AclEditor editor; 35 private ArrayList acls; 36 private String [] accesses; 37 38 public AclTableModel(Plugin plugin, AclEditor editor, String [] accesses, ArrayList acls) 39 { 40 this.plugin = plugin; 41 this.editor = editor; 42 this.accesses = accesses; 43 this.acls = acls; 44 } 45 46 public String getColumnName(int column) { 47 return Translation.tr(columns[column]); 48 } 49 50 public int getColumnCount() { 51 return columns.length; 52 } 53 54 public int getRowCount() { 55 return this.accesses.length; 56 } 57 58 public boolean isCellEditable(int row, int col) { 59 return col != 0; 60 } 61 62 public Object getValueAt(int rowIndex, int columnIndex) { 63 String access = (String )this.accesses[rowIndex]; 64 if(columnIndex == 0) 65 return plugin.tr("acl." + access); 66 67 Iterator infos = this.acls.iterator(); 68 while(infos.hasNext()) 69 { 70 AclInfo info = (AclInfo)infos.next(); 71 if(info.getAccess().equals(access)) 72 { 73 if(columnIndex == 1) 74 return Boolean.valueOf(info.isAllow()); 75 else if(columnIndex == 2) 76 return Boolean.valueOf(info.isDeny()); 77 } 78 } 79 80 return Boolean.FALSE; 81 } 82 83 public Class getColumnClass(int columnIndex) { 84 if(columnIndex == 0) 85 return String .class; 86 87 return Boolean .class; 88 } 89 90 public void setValueAt(Object aValue, int row, int column) 91 { 92 String access = (String )accesses[row]; 93 boolean value = aValue.equals(Boolean.TRUE); 94 boolean allow = (column == 1); 95 96 if(value && allow) 97 editor.allowAccess(access); 98 else if(value) 99 editor.denyAccess(access); 100 else 101 editor.removeAccess(access); 102 } 103 } | Popular Tags |