private void lookupUsersAndGroups() {
    PermissionsEntityType pEntityType;

    if (theentity instanceof TridasObject) {
      pEntityType = PermissionsEntityType.OBJECT;
    } else if (theentity instanceof TridasElement) {
      pEntityType = PermissionsEntityType.ELEMENT;
    } else if (theentity instanceof TridasMeasurementSeries) {
      pEntityType = PermissionsEntityType.MEASUREMENT_SERIES;
    } else if (theentity instanceof TridasDerivedSeries) {
      pEntityType = PermissionsEntityType.DERIVED_SERIES;
    } else {
      Alert.error(
          "Error", "Permissions information is only available for objects, elements and series");
      return;
    }

    PermissionsResource resource = new PermissionsResource();

    for (WSISecurityUser user :
        (ArrayList<WSISecurityUser>)
            Dictionary.getDictionaryAsArrayList("securityUserDictionary")) {
      if (!user.isIsActive()) continue;

      resource.addPermission(pEntityType, theentity.getIdentifier().getValue(), user);
    }

    for (WSISecurityGroup grp :
        (ArrayList<WSISecurityGroup>)
            Dictionary.getDictionaryAsArrayList("securityGroupDictionary")) {
      resource.addPermission(pEntityType, theentity.getIdentifier().getValue(), grp);
    }

    // Query db
    TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(resource);
    resource.query();
    dialog.setVisible(true);

    if (!dialog.isSuccessful()) {
      log.error("Error getting permissions info");
      Alert.error("Error", "Error getting permissions info");
      return;
    }

    permsList = resource.getAssociatedResult();

    if (tblGroupPerms != null) tblGroupPerms.repaint();
    if (tblUserPerms != null) tblUserPerms.repaint();

    if (permsList.size() == 0) {
      Alert.error("Error", "No records found");
      return;
    }
  }
  /** Save changes to the current entity */
  private void doSave() {
    Class<? extends ITridas> type;

    if (temporaryEditingEntity == null) throw new IllegalStateException();

    // if nothing actually changed, just ignore it like a cancel
    if (!hasChanged) {
      editEntityCancel.doClick();
      return;
    }

    propertiesPanel.writeToObject(temporaryEditingEntity);

    // the resource we'll use
    EntityResource<? extends ITridas> resource;

    if (temporaryEditingEntity instanceof TridasObject) {
      resource =
          new EntityResource<TridasObject>(
              temporaryEditingEntity, TellervoRequestType.UPDATE, TridasObject.class);
      type = TridasObject.class;
    } else if (temporaryEditingEntity instanceof TridasElement) {
      resource =
          new EntityResource<TridasElement>(
              temporaryEditingEntity, TellervoRequestType.UPDATE, TridasElement.class);
      type = TridasElement.class;
    } else if (temporaryEditingEntity instanceof TridasSample) {
      resource =
          new EntityResource<TridasSample>(
              temporaryEditingEntity, TellervoRequestType.UPDATE, TridasSample.class);
      type = TridasSample.class;
    } else if (temporaryEditingEntity instanceof TridasRadius) {
      resource =
          new EntityResource<TridasRadius>(
              temporaryEditingEntity, TellervoRequestType.UPDATE, TridasRadius.class);
      type = TridasRadius.class;
    } else if (temporaryEditingEntity instanceof TridasMeasurementSeries) {
      resource =
          new EntityResource<TridasMeasurementSeries>(
              temporaryEditingEntity, TellervoRequestType.UPDATE, TridasMeasurementSeries.class);
      type = TridasMeasurementSeries.class;
    } else {
      log.debug("Can't save entity.  Unsupported entity class.");
      return;
    }

    // set up a dialog...
    Window parentWindow = SwingUtilities.getWindowAncestor(this);
    TellervoResourceAccessDialog dialog =
        TellervoResourceAccessDialog.forWindow(parentWindow, resource);

    // query the resource
    resource.query();
    dialog.setVisible(true);

    // on failure, just return
    if (!dialog.isSuccessful()) {
      JOptionPane.showMessageDialog(
          this,
          I18n.getText("error.savingChanges")
              + "\r\n"
              + I18n.getText("error")
              + ": "
              + dialog.getFailException().getLocalizedMessage(),
          I18n.getText("error"),
          JOptionPane.ERROR_MESSAGE);
      return;
    }

    // replace the saved result
    temporaryEditingEntity = resource.getAssociatedResult();

    // sanity check the result
    if (temporaryEditingEntity == null) {
      new BugDialog(new IllegalStateException("CREATE or UPDATE entity returned null"));
      return;
    }

    setEntity(temporaryEditingEntity, type, true);

    // Inform the tree to update itself
    if (nodeSelected != null) {
      if (nodeSelected.getParent() == null) {

      } else if (nodeSelected.getParent().equals(nodeSelected.getRoot())) {
        ((TridasTreeViewPanel) treepanel).refreshNode(nodeSelected);
      } else {
        ((TridasTreeViewPanel) treepanel)
            .refreshNode((DefaultMutableTreeNode) nodeSelected.getParent());
      }
    }

    hasChanged = false;
  }