Example #1
0
  @Override
  protected Sheet createSheet() {
    sheetInitialised = true;
    final Sheet sheet = Sheet.createDefault();
    final Sheet.Set set = Sheet.createPropertiesSet();
    final Sheet.Set setUG = Sheet.createPropertiesSet();

    try {
      // <editor-fold defaultstate="collapsed" desc=" Create Property: ID ">
      final Property<Integer> idProp =
          new PropertySupport.Reflection<Integer>(user, Integer.class, "getId", null); // NOI18N
      idProp.setName(
          NbBundle.getMessage(UserNode.class, "UserNode.createSheet().idProp.name")); // NOI18N
      // </editor-fold>
      // <editor-fold defaultstate="collapsed" desc=" Create Property: PasswordChange ">
      final Property<Date> pwchangeProp =
          new PropertySupport<Date>(
              "lastPWChange", // NOI18N
              Date.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().pwchangeProp.lastPWChange"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class,
                  "UserNode.createSheet().pwchangeProp.timestampLastPWChange"), // NOI18N
              true,
              false) {

            @Override
            public Date getValue() throws IllegalAccessException, InvocationTargetException {
              return user.getLastPwdChange();
            }

            @Override
            public void setValue(final Date object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              // not needed
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Name ">
      final Property<String> nameProp =
          new PropertySupport<String>(
              "name", // NOI18N
              String.class,
              NbBundle.getMessage(UserNode.class, "UserNode.createSheet().nameProp.name"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().nameProp.userLogin"), // NOI18N
              true,
              true) {

            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
              return user.getLoginname();
            }

            @Override
            public void setValue(final String object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              final User old = user;
              try {
                user.setLoginname(object);
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              fireDisplayNameChange(null, object);
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Password ">
      final PasswordPropertyEditor pwEditor = new PasswordPropertyEditor();
      final Property<String> passProp =
          new PropertySupport<String>(
              "password", // NOI18N
              String.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().passProp.password"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().passProp.passwordOfUser"), // NOI18N
              true,
              true) {

            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
              return "****"; // NOI18N
            }

            @Override
            public PropertyEditor getPropertyEditor() {
              return pwEditor;
            }

            @Override
            public void setValue(final String object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              if ((object == null) || object.toString().equals("****")) { // NOI18N
                // ignore
                return;
              }

              final User old = user;
              try {
                user.setPassword(object);
                user.setLastPwdChange(Calendar.getInstance().getTime());
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              firePropertyChange(
                  "lastPWChange", // NOI18N
                  null,
                  user.getLastPwdChange());
            }
          };
      passProp.setValue("canEditAsText", Boolean.FALSE); // NOI18N
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Administrator ">
      final Property<Boolean> adminProp =
          new PropertySupport<Boolean>(
              "admin", // NOI18N
              Boolean.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().adminProp.admin"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().adminProp.isUserAdmin"), // NOI18N
              true,
              true) {

            @Override
            public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
              return user.isAdmin();
            }

            @Override
            public void setValue(final Boolean object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              final User old = user;
              try {
                user.setAdmin(object);
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              fireIconChange();
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: GroupInfo ">
      final List<UserGroup> ugs = new ArrayList<UserGroup>(user.getUserGroups());
      Collections.sort(ugs, new Comparators.UserGroups());
      for (final UserGroup ug : user.getUserGroups()) {
        setUG.put(
            new PropertySupport.ReadOnly<Integer>(
                "ug" // NOI18N
                    + ug.getId(),
                Integer.class,
                ug.getName(),
                ug.getDescription()) {

              @Override
              public Integer getValue() throws IllegalAccessException, InvocationTargetException {
                return ug.getId();
              }
            });
      } // </editor-fold>

      setUG.setName("usergroups"); // NOI18N
      setUG.setDisplayName(
          NbBundle.getMessage(
              UserNode.class, "UserNode.createSheet().setUG.displayName")); // NOI18N

      set.put(nameProp);
      set.put(passProp);
      set.put(pwchangeProp);
      set.put(adminProp);
      set.put(idProp);

      sheet.put(set);
      sheet.put(setUG);

      // <editor-fold defaultstate="collapsed" desc=" Create Property: ConfigAttrs legacy">
      if (Boolean.valueOf(
          project
              .getProperties()
              .getProperty(
                  DomainserverProjectCustomizer.PROP_USER_SHOW_LEGACY_CFGATTR_PROPS,
                  "false"))) { // NOI18N
        populateLegacyConfigAttrSet(project, sheet, null, user);
      }
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: ConfigAttrs">
      if (Boolean.valueOf(
          project
              .getProperties()
              .getProperty(
                  DomainserverProjectCustomizer.PROP_USER_SHOW_CFGATTR_PROPS, "false"))) { // NOI18N
        populateConfigAttrSet(sheet);
      }
      // </editor-fold>
    } catch (final Exception ex) {
      LOG.error("could not create property sheet", ex); // NOI18N
      ErrorManager.getDefault().notify(ex);
    }

    return sheet;
  }