Ejemplo n.º 1
0
  @Override
  public void exec() throws TransformationNotApplicable {
    // TODO Auto-generated method stub
    String nameMenu =
        o.getProperty("app.menu.prefix") + "MainMenu" + o.getProperty("app.menu.suffix");
    Menu menu = new Menu(nameMenu);
    d.setMainMenu(menu);

    // Falta login i main form si cal
    Iterator<Package> p = s.getPackages().iterator();
    while (p.hasNext()) {
      Package package1 = (Package) p.next();
      processPackage(package1, menu);
    }
  }
  public void generate(Project _p, PrintWriter _out, Options _o, LangManager _l)
      throws IOException, PythonDomainGenerationException {
    p = _p;
    m = p.getStaticModel();
    l = _l;
    o = _o;
    out = _out;
    out.println(
        nestedString()
            + commentSymbol()
            + l.getString("heading.python.admin.script")
            + p.getName()
            + commentSymbolEnd());
    out.println();
    Vector<Class> allClasses = m.getAllPersistentClasses();

    // importing the admin module

    out.println(nestedString() + "from django.contrib import admin" + commentSymbolEnd());

    // Generation of the admin information for each class

    // first iteration is used to generate the imports

    Iterator<Class> itClImp = allClasses.iterator();

    while (itClImp.hasNext()) {
      Class cl = itClImp.next();
      out.println(
          nestedString() + "from " + p.getName().toLowerCase() + ".models import " + cl.getName());
    }

    // second to generate the admin info for each class
    out.println();
    Iterator<Class> itCl = allClasses.iterator();
    while (itCl.hasNext()) {
      Class cl = itCl.next();
      generateClass(cl, out);
    }
    out.flush();
    out.close();
  }
Ejemplo n.º 3
0
  protected void processPackage(Package pack, Menu menu) {
    if (pack.getAllClasses().size() > 0) {
      MenuItem menuPack =
          new MenuItem(
              o.getProperty("app.menu.item.prefix")
                  + "Pack"
                  + pack.getName()
                  + o.getProperty("app.menu.item.suffix"));
      menuPack.setCaption(pack.getName());
      Iterator<Class> c = pack.getAllPersistentClasses().iterator();
      while (c.hasNext()) {
        Class class1 = (Class) c.next();
        // General item for all the forms associated to the class
        MenuItem mi =
            new MenuItem(
                o.getProperty("app.menu.item.prefix")
                    + class1.getName()
                    + o.getProperty("app.menu.item.suffix"));
        mi.setCaption(class1.getName());

        // Specific forms (and menu items) for each individual form
        MenuItem miVis =
            new MenuItem(
                o.getProperty("app.menu.item.prefix")
                    + "Vis"
                    + class1.getName()
                    + o.getProperty("app.menu.item.suffix"));
        Form fVis =
            new Form(
                o.getProperty("app.form.prefix")
                    + "Vis"
                    + class1.getName()
                    + o.getProperty("app.form.suffix"));
        fVis.setCaption(l.getString("app.caption.form.visualization") + class1.getName());
        fVis.setActionKind(FormActionKind.FA_VISUALIZE);
        fVis.setBaseClass(class1);
        d.addForm(fVis);
        mi.addItem(miVis);
        miVis.setDestination(fVis);
        miVis.setCaption(l.getString("app.caption.menu.item.visualize"));
        if (!class1
            .isReadOnly()) // For non-read only classes we create a form for inserting data and
                           // another for updating it
        {
          Form fIns =
              new Form(
                  o.getProperty("app.form.prefix")
                      + "Ins"
                      + class1.getName()
                      + o.getProperty("app.form.suffix"));
          fIns.setCaption(l.getString("app.caption.form.insert") + class1.getName());
          fIns.setActionKind(FormActionKind.FA_INSERT);
          fIns.setBaseClass(class1);
          d.addForm(fIns);
          fVis.addRelatedForm(fIns);
          if (o.getProperty("app.menu.item.insert")
              .equals("true")) // We create a separate menu entry for the insert form
          {
            MenuItem miIns =
                new MenuItem(
                    o.getProperty("app.menu.item.prefix")
                        + "Ins"
                        + class1.getName()
                        + o.getProperty("app.menu.item.suffix"));
            mi.addItem(miIns);
            miIns.setDestination(fIns);
            miIns.setCaption(l.getString("app.caption.menu.item.insert"));
          }

          Form fUpd =
              new Form(
                  o.getProperty("app.form.prefix")
                      + "Upd"
                      + class1.getName()
                      + o.getProperty("app.form.suffix"));
          fUpd.setCaption(l.getString("app.caption.form.update") + class1.getName());
          fUpd.setActionKind(FormActionKind.FA_UPDATE);
          fUpd.setBaseClass(class1);
          d.addForm(fUpd);
          fVis.addRelatedForm(fUpd);
        } else // if it is read only we just create a form to visualize the details of the row
        {
          Form fDet =
              new Form(
                  o.getProperty("app.form.prefix")
                      + "Det"
                      + class1.getName()
                      + o.getProperty("app.form.suffix"));
          fDet.setCaption(l.getString("app.caption.form.visdetails") + class1.getName());
          fDet.setActionKind(FormActionKind.FA_VISDETAILS);
          fDet.setBaseClass(class1);
          d.addForm(fDet);
          fVis.addRelatedForm(fDet);
        }
        if (o.getProperty("app.menu.groupby.package").equals("true")
            && !s.getPackages().get(0).getName().equals(o.getProperty("db.package.default.name"))) {
          menuPack.addItem(mi);
        } // We create submenu for each package
        else {
          menu.addItem(mi);
        }
      }
      if (o.getProperty("app.menu.groupby.package").equals("true")
          && !s.getPackages().get(0).getName().equals(o.getProperty("db.package.default.name"))) {
        menu.addItem(menuPack);
      }
    }
    if (pack.getFirstLevelPackages().size() > 0) {
      Iterator<Package> p = pack.getFirstLevelPackages().iterator();
      while (p.hasNext()) {
        Package package1 = (Package) p.next();
        processPackage(package1, menu);
      }
    }
  }