Ejemplo n.º 1
0
 static {
   INTERFACES = new Vector();
   INTERFACES.addElement("SubmitListener");
   INTERFACES.addElement("PageListener");
 }
Ejemplo n.º 2
0
  private static void addListeners(PrintWriter pw) {
    // add SubmitListener
    if (INTERFACES.contains("SubmitListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the given submit event");
      println(pw, " * @param " + EVENT_PARAMETER + " the submit event to be processed");
      println(pw, " * @return true to continue processing events, false to stop processing events");
      println(pw, " */");
      println(pw, "public boolean submitPerformed(SubmitEvent " + EVENT_PARAMETER + ") {");
      println(pw, TAB + "return true;");
      println(pw, "}");
    }

    // Add PageListener
    if (INTERFACES.contains("PageListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the page requested event");
      println(pw, " * @param " + EVENT_PARAMETER + " the page event to be processed");
      println(pw, " */");
      println(pw, "public void pageRequested(PageEvent " + EVENT_PARAMETER + ") {");
      println(pw, "}");

      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the page request end event");
      println(pw, " * @param " + EVENT_PARAMETER + " the page event to be processed");
      println(pw, " */");
      println(pw, "public void pageRequestEnd(PageEvent " + EVENT_PARAMETER + ") {");
      println(pw, "}");

      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the page submit end event");
      println(pw, " * @param " + EVENT_PARAMETER + " the page event to be processed");
      println(pw, " */");
      println(pw, "public void pageSubmitEnd(PageEvent " + EVENT_PARAMETER + ") {");
      println(pw, "}");

      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the page submit event");
      println(pw, " * @param " + EVENT_PARAMETER + " the page event to be processed");
      println(pw, " */");
      println(pw, "public void pageSubmitted(PageEvent " + EVENT_PARAMETER + "){");
      println(pw, "}");
    }

    // add ValueChangeListener
    if (INTERFACES.contains("ValueChangedListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the value change event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " * @return true to continue processing events, false to stop processing events");
      println(pw, " *");
      println(pw, " */");
      println(pw, "public boolean valueChanged(ValueChangedEvent " + EVENT_PARAMETER + "){");
      println(pw, TAB + "return true;");
      println(pw, "}");
    }

    // add TreeListener
    if (INTERFACES.contains("TreeListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the item contracted event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " */");
      println(pw, "public void itemContracted(TreeExpandContractEvent " + EVENT_PARAMETER + "){");
      println(pw, "}");

      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the item expanded event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " */");
      println(pw, "public void itemExpanded(TreeExpandContractEvent " + EVENT_PARAMETER + ")");
      println(pw, "{");
      println(pw, "}");
    }

    // FileUploadListener
    if (INTERFACES.contains("FileUploadListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the file upload event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " */");
      println(pw, "void fileUploaded(FileUploadEvent " + EVENT_PARAMETER + "){");
      println(pw, "}");
    }

    // Calendar Listener
    if (INTERFACES.contains("CalendarListener")) {
      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the calendar date selection event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " */");
      println(pw, "void dateSelected(CalendarDateSelectedEvent " + EVENT_PARAMETER + "){");
      println(pw, "}");

      println(pw, SPACE);
      println(pw, "/**");
      println(pw, " * Process the month change event");
      println(pw, " *");
      println(pw, " * @param " + EVENT_PARAMETER + " the event to be processed");
      println(pw, " *");
      println(pw, " * @return true to continue processing events, false to stop processing events");
      println(pw, " *");
      println(pw, " */");
      println(pw, "boolean monthChanged(CalendarMonthChangeEvent " + EVENT_PARAMETER + "){");
      println(pw, TAB + "return true;");
      println(pw, "}");
    }
  }
Ejemplo n.º 3
0
  /** Generates a stub controller for a view. */
  public static void generateCode(
      java.io.PrintWriter p, Hashtable hashFields, JspController cont, String controllerName) {
    try {
      PrintWriter pw = p;
      println(pw, "<BR>");
      println(pw, "");
      String cName = controllerName;
      String packageName = "";
      if (cName == null || cName.equals("") || cName.equals("com.salmonllc.jsp.JspController"))
        cName = "GeneratedController";
      int pos = cName.lastIndexOf(".");
      if (pos > 0) {
        packageName = cName.substring(0, pos);
        cName = cName.substring(pos + 1);
      }

      // create the package statement
      println(pw, "//package statement");
      if (packageName != null) println(pw, PACKAGE + SPACE + packageName + ";");

      // create some standard import statements
      println(pw, "");
      println(pw, "//Salmon import statements");
      println(pw, IMPORT + SPACE + "com.salmonllc.jsp.*;");
      println(pw, IMPORT + SPACE + "com.salmonllc.html.events.*;");
      println(pw, "");
      println(pw, "");

      // Start the Class definition
      println(pw, "/**");
      println(pw, " * " + cName + ": a SOFIA generated controller");
      println(pw, " */");
      pw.print(CLASSDEF + SPACE + cName + SPACE);
      pw.print(EXTENDS + SPACE + BASECLASS + SPACE);

      if (INTERFACES != null && INTERFACES.size() > 0) {
        pw.print(IMPLEMENTS + SPACE);
        pw.print(INTERFACES.elementAt(0));
        for (int i = 1; i < INTERFACES.size(); i++) {
          pw.print(COMMA + SPACE);
          pw.print(INTERFACES.elementAt(i));
        }
      }
      println(pw, " {");

      // Add the variables
      cont.printVars(pw);

      // add the Initialize Method
      println(pw, SPACE);
      println(pw, "/**");
      println(
          pw,
          " * Initialize the page. Set up listeners and perform other initialization activities.");
      println(pw, " */");
      println(pw, INITMETHOD + "{");

      // For Page Listeners
      if (INTERFACES.contains(new String("PageListener")))
        println(pw, TAB + "addPageListener(this);");

      if (hashFields != null) {
        Enumeration en = hashFields.keys();
        while (en.hasMoreElements() && INTERFACES != null) {
          String key = (String) en.nextElement();
          Object obj = hashFields.get(key);

          // For Buttons
          if (INTERFACES.contains(new String("SubmitListener"))) {
            if (obj instanceof com.salmonllc.html.HtmlSubmitButton
                || obj instanceof com.salmonllc.html.HtmlSubmitImage)
              println(pw, TAB + computeFieldName(key) + ".addSubmitListener(this);");
          }

          // For Value Change Listeners
          if (INTERFACES.contains(new String("ValueChangedListener"))) {
            if (obj instanceof com.salmonllc.html.HtmlCheckBox
                || obj instanceof com.salmonllc.html.HtmlRadioButton
                || obj instanceof com.salmonllc.html.HtmlDropDownList)
              println(pw, TAB + computeFieldName(key) + ".addValueChangeListener(this);");
          }

          // For Tree Listeners
          if (INTERFACES.contains(new String("TreeListener"))) {
            if (obj instanceof com.salmonllc.html.HtmlTreeControl)
              println(pw, TAB + computeFieldName(key) + ".addTreeListener(this);");
          }
        } // while loop
      } // hashatable not null

      println(pw, "}");

      // add the listeners
      addListeners(pw);

      // End the class definition
      println(pw, "");
      println(pw, "}");

      pw.flush();

    } catch (java.io.IOException e) {
      System.out.println("Cannot create Java File.");
      e.printStackTrace();
    }
  }