Package org.molgenis.model.elements

Examples of org.molgenis.model.elements.Form


      {
        if (name.isEmpty())
        {
          name = element.getAttribute("entity");
        }
        Form form = new Form(name, parent);
        form.setLabel(label);
        form.setGroup(group);
        form.setGroupRead(groupRead);

        if (group != null && groupRead != null && group.equals(groupRead))
        {
          throw new MolgenisModelException(
              "You cannot assign both read/write and read rights on a single form");
        }

        /** Optional custom header for the selected form screen */
        String header = element.getAttribute("header");
        if (!header.isEmpty()) form.setHeader(header);

        /** Optional description for the selected form screen */
        String description = element.getAttribute("description");
        if (!description.isEmpty()) form.setDescription(description);

        form.setNamespace(namespace);
        new_parent = form;

        // VIEWTYPE
        if (element.getAttribute("view").equals("record"))
        {
          element.setAttribute("view", "edit");
        }
        if (element.getAttribute("view").isEmpty())
        {
          if (element.getChildNodes().getLength() > 0)
          {
            element.setAttribute("view", "edit");
          }
          else
          {
            element.setAttribute("view", "list");
          }
        }
        if (Form.ViewType.parseViewType(element.getAttribute("view")) == Form.ViewType.VIEWTYPE_UNKNOWN)
        {
          throw new MolgenisModelException("view '" + element.getAttribute("view") + "' unknown for form '"
              + form.getName() + "'");
        }
        form.setViewType(Form.ViewType.parseViewType(element.getAttribute("view")));

        // LIMIT
        form.setLimit(10);
        String limit = element.getAttribute("limit");
        if (limit != null && !limit.isEmpty())
        {
          form.setLimit(Integer.parseInt(limit));
        }

        // ACTIONS
        form.setCommands(new ArrayList<String>());
        String commands = element.getAttribute("commands");
        if (commands != null && !commands.isEmpty())
        {
          String[] commandArray = commands.split(",");
          for (String command : commandArray)
          {
            form.getCommands().add(command.trim());
          }
        }

        // SORT
        String sortby = element.getAttribute("sortby");
        if (sortby != null && !sortby.isEmpty())
        {
          // TODO ensure valid sort field
          form.setSortby(sortby);
        }
        String sortorder = element.getAttribute("sortorder");
        if (sortorder != null && !sortorder.isEmpty())
        {
          if (!sortorder.equalsIgnoreCase(Form.SortOrder.ASC.toString())
              && !sortorder.equalsIgnoreCase(Form.SortOrder.DESC.toString()))
          {
            throw new MolgenisModelException(
                "sortorder can only be 'asc' or 'desc'. Parser found <form name=\"" + form.getName()
                    + "\" sortorder=\"" + sortorder + "\"");
          }
          else
          {

            form.setSortorder(SortOrder.parse(sortorder));
          }
        }

        // FILTER
        String filter = element.getAttribute("filter");
        if (filter != null && filter.equals("true"))
        {
          if (element.getAttribute("filterfield") != null && element.getAttribute("filterfield").isEmpty())
          {
            throw new MolgenisModelException("filterfield is missing for subform of screen '"
                + parent.getName() + "'");
          }
          if (element.getAttribute("filtertype") != null && element.getAttribute("filtertype").isEmpty())
          {
            throw new MolgenisModelException("filtertype is missing for subform of screen '"
                + parent.getName() + "'");
          }
          if (element.getAttribute("filtervalue") != null && element.getAttribute("filtervalue").isEmpty())
          {
            logger.warn("filtervalue is missing for subform of screen '" + parent.getName() + "'");
          }
          form.setFilter(true);
          form.setFilterfield(element.getAttribute("filterfield"));
          form.setFiltertype(element.getAttribute("filtertype"));
          form.setFiltervalue(element.getAttribute("filtervalue"));
        }

        // READONLY
        form.setReadOnly(false);
        String readonly = element.getAttribute("readonly");
        if (readonly != null)
        {
          form.setReadOnly(Boolean.parseBoolean(readonly));
        }

        // ENTITY
        // TODO: whould have expected this in the constructor!
        Entity entity = (Entity) model.getDatabase().getChild(element.getAttribute("entity"));
        if (entity == null)
        {
          throw new MolgenisModelException("Could not find the specified entity '"
              + element.getAttribute("entity") + "' for form '" + form.getName() + "'");
        }
        form.setRecord((Record) entity);// form.setEntity(entity);

        // HIDDEN FIELDS
        form.setHideFields(new ArrayList<String>());
        String hide_fields = element.getAttribute("hide_fields");
        if (hide_fields != null && !hide_fields.isEmpty())
        {
          String[] hiddenFieldArray = hide_fields.split(",");
          for (String field : hiddenFieldArray)
          {
            Field f = entity.getAllField(field.trim());
            if (f == null)
            {
              throw new MolgenisModelException("Could not find field '" + field
                  + "' defined in hide_fields='" + element.getAttribute("hide_fields")
                  + "' in form '" + form.getName() + "'");
            }
            // use name from 'f' to correct for case problems
            form.getHideFields().add(f.getName());
          }
        }

        // COMPACT_FIELDS
        if (!element.getAttribute("compact_view").isEmpty())
        {
          String[] fields = element.getAttribute("compact_view").split(",");
          // check if the fields are there
          List<String> compact_fields = new ArrayList<String>();
          for (String field : fields)
          {
            Field f = entity.getAllField(field);
            if (f == null)
            {
              throw new MolgenisModelException("Could not find field '" + field
                  + "' defined in compact_view='" + element.getAttribute("compact_view")
                  + "' in form '" + form.getName() + "'");
            }
            // use name from 'f' to correct for case problems

            compact_fields.add(form.getEntity().getName() + "_" + f.getName());
          }
          form.setCompactView(compact_fields);
        }
      }
      else if (element.getTagName().equals("tree"))
      {
        // check required properties
View Full Code Here

TOP

Related Classes of org.molgenis.model.elements.Form

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.