private void editSelectedGroup() {

    WSISecurityGroup group = groupTableModel.getSecurityGroupAtRow(tblGroupPerms.getSelectedRow());

    if (group == null) return;

    for (WSISecurityGroup grp :
        (ArrayList<WSISecurityGroup>)
            Dictionary.getDictionaryAsArrayList("securityGroupDictionary")) {
      if (grp.getId().equals(group.getId())) {
        group = grp;
        break;
      }
    }

    GroupUIView groupDialog =
        new GroupUIView(
            null, true, group, groupTableModel.getWSIPermissionAt(tblGroupPerms.getSelectedRow()));
    groupDialog.setVisible(true);
  }
 private void resetPermissionsForCurrentGroup() {
   for (int i = 0; i < groupTableModel.getRowCount(); i++) {
     groupTableModel.setRowToDefaultValues(i);
   }
 }
  public void setEntity(ITridas entity) {
    theentity = entity;
    lookupUsersAndGroups();

    userTableModel = new UsersWithPermissionsTableModel(permsList);
    groupTableModel = new GroupsWithPermissionsTableModel(permsList);
    groupTableModel.addTableModelListener(
        new TableModelListener() {

          @Override
          public void tableChanged(TableModelEvent e) {
            updateUsersTable();
          }
        });
    setLayout(new MigLayout("", "[][grow]", "[86px][28.00][328px,grow]"));

    lblPermissionsInfoFor = new JLabel("Permissions info for:");
    add(lblPermissionsInfoFor, "cell 0 1,alignx trailing");

    // TODO : make this code pretty...
    txtLabCode = new JTextField();
    txtLabCode.setText(entity.getTitle());
    txtLabCode.setFocusable(false);

    txtLabCode.setEditable(false);
    add(txtLabCode, "cell 1 1,growx");
    txtLabCode.setColumns(10);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    add(tabbedPane, "cell 0 2 2 1,grow");

    panelGroups = new JPanel();
    tabbedPane.addTab(
        "Group permissions", Builder.getIcon("edit_group.png", 22), panelGroups, null);
    panelGroups.setLayout(new MigLayout("", "[648px,grow]", "[381px,grow][]"));

    JScrollPane scrollGroup = new JScrollPane();
    panelGroups.add(scrollGroup, "cell 0 0,grow");

    tblGroupPerms = new JXTable(groupTableModel);
    tblGroupPerms.setSortable(true);

    searchableGroup = new TableSearchable(tblGroupPerms);
    tblGroupPerms.setSearchable(searchableGroup);

    scrollGroup.setViewportView(tblGroupPerms);

    btnEditGroup = new JButton("View / Edit Group");
    btnEditGroup.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            editSelectedGroup();
          }
        });
    panelGroups.add(btnEditGroup, "flowx,cell 0 1");

    btnRevertToDefault = new JButton("Revert to database defaults");
    btnRevertToDefault.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            resetPermissionsForCurrentGroup();
          }
        });
    panelGroups.add(btnRevertToDefault, "cell 0 1");

    btnGroupRefresh = new JButton("Refresh");
    btnGroupRefresh.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            updateGroupsTable();
          }
        });
    panelGroups.add(btnGroupRefresh, "cell 0 1");

    tblGroupPerms.getColumnModel().getColumn(0).setPreferredWidth(15);
    tblGroupPerms.getColumnModel().getColumn(1).setPreferredWidth(100);
    tblGroupPerms.getColumnModel().getColumn(2).setPreferredWidth(45);
    tblGroupPerms.getColumnModel().getColumn(3).setPreferredWidth(45);
    tblGroupPerms.getColumnModel().getColumn(4).setPreferredWidth(45);
    tblGroupPerms.getColumnModel().getColumn(5).setPreferredWidth(45);
    tblGroupPerms.getColumnModel().getColumn(6).setPreferredWidth(45);
    tblGroupPerms.getColumnModel().getColumn(7).setPreferredWidth(300);

    panelUsers = new JPanel();
    tabbedPane.addTab("Users with access", Builder.getIcon("edit_user.png", 22), panelUsers, null);
    panelUsers.setLayout(new MigLayout("", "[648px,grow]", "[381px,grow][]"));

    JScrollPane scrollUser = new JScrollPane();
    panelUsers.add(scrollUser, "cell 0 0,grow");

    tblUserPerms = new JXTable(userTableModel);

    searchableUser = new TableSearchable(tblUserPerms);
    tblUserPerms.setSearchable(searchableUser);

    tblUserPerms.setSortable(true);
    scrollUser.setViewportView(tblUserPerms);

    btnEditUser = new JButton("View / Edit User");
    btnEditUser.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            editSelectedUser();
          }
        });
    panelUsers.add(btnEditUser, "flowx,cell 0 1");

    btnUserRefresh = new JButton("Refresh");
    btnUserRefresh.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {

            updateUsersTable();
          }
        });
    panelUsers.add(btnUserRefresh, "cell 0 1");

    tblUserPerms.getColumnModel().getColumn(0).setPreferredWidth(15);
    tblUserPerms.getColumnModel().getColumn(1).setPreferredWidth(100);
    tblUserPerms.getColumnModel().getColumn(2).setPreferredWidth(45);
    tblUserPerms.getColumnModel().getColumn(3).setPreferredWidth(45);
    tblUserPerms.getColumnModel().getColumn(4).setPreferredWidth(45);
    tblUserPerms.getColumnModel().getColumn(5).setPreferredWidth(45);
    tblUserPerms.getColumnModel().getColumn(6).setPreferredWidth(45);
    tblUserPerms.getColumnModel().getColumn(7).setPreferredWidth(300);

    tblGroupPerms.addMouseListener(this);
    tblUserPerms.addMouseListener(this);

    panelTitle = new JPanel();
    add(panelTitle, "cell 0 0 2 1,growx,aligny top");
    panelTitle.setBackground(Color.WHITE);
    panelTitle.setLayout(new MigLayout("", "[411.00,grow][]", "[][grow]"));

    lblGroupPermissions = new JLabel("Access Permissions");
    lblGroupPermissions.setFont(new Font("Dialog", Font.BOLD, 14));
    panelTitle.add(lblGroupPermissions, "flowy,cell 0 0");

    panelIcon = new JPanel();
    panelIcon.setBackground(Color.WHITE);
    panelTitle.add(panelIcon, "cell 1 0 1 2,grow");

    lblIcon = new JLabel();
    lblIcon.setIcon(Builder.getIcon("trafficlight.png", 64));
    panelIcon.add(lblIcon);

    txtDescription = new JTextArea();
    txtDescription.setBorder(null);
    txtDescription.setEditable(false);
    txtDescription.setFocusable(false);
    txtDescription.setFont(new Font("Dialog", Font.PLAIN, 10));
    txtDescription.setLineWrap(true);
    txtDescription.setWrapStyleWord(true);
    txtDescription.setText(
        "Permissions are set on groups, not users.  You can set: create; read; "
            + "update; and delete permissions separately.  Permissions are inherited from the default "
            + "database permissions given to the group (editable in the main group dialog). If you "
            + "change permissions here you will override the access for the current entity and any "
            + "child entities in the database. "
            + "The users tab shows the current list of users who have permission to access this "
            + "entity in some way.");
    panelTitle.add(txtDescription, "cell 0 1,grow,wmin 10");
  }
 public void updateGroupsTable() {
   App.dictionary.query();
   lookupUsersAndGroups();
   groupTableModel.fireTableDataChanged();
 }