private void generateClass(TreeLogger logger, GeneratorContext context) {

    // get print writer that receives the source code
    PrintWriter printWriter = null;
    printWriter = context.tryCreate(logger, packageName, className);
    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) {
      return;
    }

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composer = null;
    composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImplementedInterface("org.pentaho.ui.xul.gwt.binding.TypeController");
    composer.addImport("org.pentaho.ui.xul.gwt.binding.*");
    composer.addImport("java.util.Map");
    composer.addImport("java.util.HashMap");
    composer.addImport("org.pentaho.ui.xul.XulException");

    SourceWriter sourceWriter = null;
    sourceWriter = composer.createSourceWriter(context, printWriter);

    // generator constructor source code
    generateConstructor(sourceWriter);

    writeMethods(sourceWriter);

    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);
  }
Exemple #2
0
 protected void generateCheckRpcTokenTypeOverride(
     SourceWriter srcWriter, TypeOracle typeOracle, SerializableTypeOracle typesSentFromBrowser) {
   JClassType rpcTokenType = typeOracle.findType(RpcToken.class.getName());
   JClassType[] rpcTokenSubtypes = rpcTokenType.getSubtypes();
   String rpcTokenImplementation = "";
   for (JClassType rpcTokenSubtype : rpcTokenSubtypes) {
     if (typesSentFromBrowser.isSerializable(rpcTokenSubtype)) {
       if (rpcTokenImplementation.length() > 0) {
         // >1 implematation of RpcToken, bail
         rpcTokenImplementation = "";
         break;
       } else {
         rpcTokenImplementation = rpcTokenSubtype.getQualifiedSourceName();
       }
     }
   }
   if (rpcTokenImplementation.length() > 0) {
     srcWriter.println("@Override");
     srcWriter.println("protected void checkRpcTokenType(RpcToken token) {");
     srcWriter.indent();
     srcWriter.println("if (!(token instanceof " + rpcTokenImplementation + ")) {");
     srcWriter.indent();
     srcWriter.println(
         "throw new RpcTokenException(\"Invalid RpcToken type: "
             + "expected '"
             + rpcTokenImplementation
             + "' but got '\" + "
             + "token.getClass() + \"'\");");
     srcWriter.outdent();
     srcWriter.println("}");
     srcWriter.outdent();
     srcWriter.println("}");
   }
 }
 /**
  * Writes the class's static fields.
  *
  * <pre>
  * private static final Map&lt;String, String&gt; methodMapJava;
  * private static final MethodMap methodMapNative;
  * private static final Map&lt;String&lt;?&gt;, String&gt; signatureMapJava;
  * private static final JsArrayString signatureMapNative;
  * </pre>
  */
 private void writeStaticFields() {
   if (context.isProdMode()) {
     srcWriter.println("private static final MethodMap methodMapNative;");
     srcWriter.println("private static final JsArrayString signatureMapNative;");
   } else {
     srcWriter.println("private static final Map<String, String> methodMapJava;");
     srcWriter.println("private static final Map<String, String> signatureMapJava;");
   }
   srcWriter.println();
 }
 /**
  * Writes constructor.
  *
  * <pre>
  * public SchoolCalendarService_TypeSerializer() {
  *   super(methodMapJava, methodMapNative, signatureMapJava, signatureMapNative);
  * }
  * </pre>
  */
 private void writeConstructor() {
   srcWriter.println("public " + typeSerializerSimpleName + "() {");
   if (context.isProdMode()) {
     srcWriter.indentln("super(null, methodMapNative, null, signatureMapNative);");
   } else {
     srcWriter.indentln("super(methodMapJava, null, signatureMapJava, null);");
   }
   srcWriter.println("}");
   srcWriter.println();
 }
 /**
  * Writes a loadNamesMapJava method for the current locale, based on its the supplied names map
  * and its superclass (if any).
  *
  * <p>If no new names are added for this locale over its superclass, the method is omitted
  * entirely.
  *
  * @param writer SourceWriter instance to use for writing the class
  * @param currencies array of valid currency names in the order they should be listed
  * @param allCurrencyData map of currency codes to currency data for the current locale, including
  *     all inherited currencies data
  */
 private void writeNamesMethodJava(
     SourceWriter writer, String[] currencies, Map<String, CurrencyInfo> allCurrencyData) {
   boolean needHeader = true;
   for (String currencyCode : currencies) {
     // TODO(jat): only emit new data where it differs from superclass!
     CurrencyInfo currencyInfo = allCurrencyData.get(currencyCode);
     String displayName = currencyInfo.getDisplayName();
     if (displayName != null && !currencyCode.equals(displayName)) {
       if (needHeader) {
         needHeader = false;
         writer.println();
         writer.println("@Override");
         writer.println("protected HashMap<String, String> loadNamesMapJava() {");
         writer.indent();
         writer.println("HashMap<String, String> result = super.loadNamesMapJava();");
       }
       writer.println(
           "result.put(\"" + quote(currencyCode) + "\", \"" + quote(displayName) + "\");");
     }
   }
   if (!needHeader) {
     writer.println("return result;");
     writer.outdent();
     writer.println("}");
   }
 }
  /**
   * Writes a method to produce a map of class name to type string for Java.
   *
   * <pre>
   * private static Map&lt;String&lt;?&gt;, String&gt; loadSignaturesJava() {
   *   Map&lt;String&lt;?&gt;, String&gt; result = new HashMap&lt;String&lt;?&gt;, String&gt;();
   *   result.put(
   *       com.google.gwt.user.client.rpc.core.java.lang.String_FieldSerializer.concreteType(),
   *       &quot;java.lang.String/2004016611&quot;);
   *   ...
   *   return result;
   * }
   * </pre>
   */
  private void writeLoadSignaturesJava() {
    srcWriter.println("@SuppressWarnings(\"deprecation\")");
    srcWriter.println("private static Map<String, String> loadSignaturesJava() {");
    srcWriter.indent();
    srcWriter.println("Map<String, String> result = new HashMap<String, String>();");

    for (JType type : getSerializableTypes()) {
      String typeString = typeStrings.get(type);

      if (!serializationOracle.maybeInstantiated(type)
          && !deserializationOracle.maybeInstantiated(type)) {
        continue;
      }

      String typeRef;
      JClassType customSerializer =
          SerializableTypeOracleBuilder.findCustomFieldSerializer(typeOracle, type);
      if (customSerializer != null
          && CustomFieldSerializerValidator.getConcreteTypeMethod(customSerializer) != null) {
        typeRef = customSerializer.getQualifiedSourceName() + ".concreteType()";
      } else {
        typeRef = '"' + SerializationUtils.getRpcTypeName(type) + '"';
      }

      srcWriter.println("result.put(" + typeRef + ", \"" + typeString + "\");");
    }

    srcWriter.println("return result;");
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println();
  }
  /**
   * Writes a method to produce a map of type string -> class name of {@link TypeHandler} for Java.
   *
   * <pre>
   * private static Map&lt;String, String&gt; loadMethodsJava() {
   *   Map&lt;String, String&gt; result = new HashMap&lt;String, String&gt;();
   *   result.put(
   *       &quot;java.lang.String/2004016611&quot;,
   *       &quot;com.google.gwt.user.client.rpc.core.java.lang.String_FieldSerializer&quot;
   *   ...
   *   return result;
   * }
   * </pre>
   */
  private void writeLoadMethodsJava() {
    srcWriter.println("@SuppressWarnings(\"deprecation\")");
    srcWriter.println("private static Map<String, String> loadMethodsJava() {");
    srcWriter.indent();
    srcWriter.println("Map<String, String> result = new HashMap<String, String>();");

    List<JType> filteredTypes = new ArrayList<JType>();
    JType[] types = getSerializableTypes();
    int n = types.length;
    for (int index = 0; index < n; ++index) {
      JType type = types[index];
      if (serializationOracle.maybeInstantiated(type)
          || deserializationOracle.maybeInstantiated(type)) {
        filteredTypes.add(type);
      }
    }

    for (JType type : filteredTypes) {
      String typeString = typeStrings.get(type);
      assert typeString != null : "Missing type signature for " + type.getQualifiedSourceName();
      srcWriter.println(
          "result.put(\""
              + typeString
              + "\", \""
              + SerializationUtils.getStandardSerializerName((JClassType) type)
              + "\");");
    }

    srcWriter.println("return result;");
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println();
  }
  /** Writes the map of the owner Models */
  private void writeOwnerModels() {
    logger.log(Type.DEBUG, "Starting to write OwnerModels"); // $NON-NLS-1$
    sw.println();
    sw.println("@Override"); // $NON-NLS-1$
    sw.println(
        "protected java.util.Map<String, org.ovirt.engine.ui.uicommonweb.models.Model> getOwnerModels() {"); //$NON-NLS-1$
    sw.indent();

    sw.println(
        "java.util.Map<String, org.ovirt.engine.ui.uicommonweb.models.Model> regs = new java.util.HashMap<String, org.ovirt.engine.ui.uicommonweb.models.Model>();"); //$NON-NLS-1$

    logger.log(Type.DEBUG, "Going over Editor Fields"); // $NON-NLS-1$
    for (EditorData editorData : model.getEditorData()) {
      logger.log(Type.DEBUG, "Going over Field: " + editorData); // $NON-NLS-1$
      String path = editorData.getPath();
      if (path.length() == 0) {
        continue;
      }

      JClassType propertyOwnerType = eraseType(editorData.getPropertyOwnerType());

      if (propertyOwnerType == listModelType || propertyOwnerType == entityModelType) {
        logger.log(Type.DEBUG, "Found owner Model Field: " + editorData); // $NON-NLS-1$
        sw.println(
            "regs.put(\"%s\", getObject()%s);",
            path, editorData.getBeanOwnerExpression()); // $NON-NLS-1$
      }
    }
    sw.println("return regs;"); // $NON-NLS-1$
    sw.outdent();
    sw.println("}"); // $NON-NLS-1$
  }
Exemple #9
0
 /**
  * Generate the proxy constructor and delegate to the superclass constructor using the default
  * address for the {@link com.google.gwt.user.client.rpc.RemoteService RemoteService}.
  */
 protected void generateProxyContructor(SourceWriter srcWriter) {
   srcWriter.println("public " + getProxySimpleName() + "() {");
   srcWriter.indent();
   srcWriter.println("super(GWT.getModuleBaseURL(),");
   srcWriter.indent();
   srcWriter.println(getRemoteServiceRelativePath() + ", ");
   srcWriter.println("SERIALIZATION_POLICY, ");
   srcWriter.println("SERIALIZER);");
   srcWriter.outdent();
   srcWriter.outdent();
   srcWriter.println("}");
 }
 /**
  * Statically initializes the class fields either for script or JVM.
  *
  * <pre>
  * static {
  *   if (GWT.isScript()) {
  *     methodMapJava = null;
  *     methodMapNative = loadMethodsNative();
  *     signatureMapJava = null;
  *     signatureMapNative = loadSignaturesNative();
  *   } else {
  *     methodMapJava = loadMethodsJava();
  *     methodMapNative = null;
  *     signatureMapJava = loadSignaturesJava();
  *     signatureMapNative = null;
  *   }
  * }
  * </pre>
  */
 private void writeStaticInitializer() {
   srcWriter.println("static {");
   srcWriter.indent();
   if (context.isProdMode()) {
     srcWriter.println("methodMapNative = loadMethodsNative();");
     srcWriter.println("signatureMapNative = loadSignaturesNative();");
   } else {
     srcWriter.println("methodMapJava = loadMethodsJava();");
     srcWriter.println("signatureMapJava = loadSignaturesJava();");
   }
   srcWriter.outdent();
   srcWriter.println("}");
   srcWriter.println();
 }
Exemple #11
0
  private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException {
    for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() != Node.ELEMENT_NODE) continue;

      Element child = (Element) n;

      if (child.getTagName().equals("cmd")) {
        String cmdId = child.getAttribute("refid");
        writer.print("callback.addCommand(");
        writer.print("\"" + Generator.escape(cmdId) + "\", ");
        writer.println("this.cmds." + cmdId + "());");
      } else if (child.getTagName().equals("separator")) {
        writer.println("callback.addSeparator();");
      } else if (child.getTagName().equals("menu")) {
        String label = child.getAttribute("label");
        writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");");
        emitMenu(writer, child);
        writer.println("callback.endMenu();");
      } else if (child.getTagName().equals("dynamic")) {
        String dynamicClass = child.getAttribute("class");
        writer.println("new " + dynamicClass + "().execute(callback);");
      } else {
        logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu");
        throw new UnableToCompleteException();
      }
    }
  }
  @Override
  void toJS(FragmentGeneratorContext context) throws UnableToCompleteException {
    TreeLogger logger =
        context.parentLogger.branch(
            TreeLogger.DEBUG, "Writing function() wrapper for JSFunction", null);

    SourceWriter sw = context.sw;
    TypeOracle typeOracle = context.typeOracle;
    JClassType functionClass = context.returnType.isClassOrInterface();

    if (functionClass.equals(typeOracle.findType(JSFunction.class.getName()))) {
      logger.log(
          TreeLogger.ERROR,
          "You must use a subinterface of JSFunction"
              + " so that the generator can extract a method signature.",
          null);
      throw new UnableToCompleteException();
    }

    // This is to support the JSFunction having the same lifetime as the
    // JSFunction object without having to use GWT.create on every JSFunction
    // object as that would discourage anonymous classes.

    sw.print("(");
    sw.print(context.parameterName);
    //  sw.print("[email protected]::exportedFunction || (");
    sw.print(".@" + JSFunction.class.getName() + "::exportedFunction || (");
    sw.print(context.parameterName);
    //    sw.print("[email protected]::exportedFunction = ");
    sw.print(".@" + JSFunction.class.getName() + "::exportedFunction = ");
    writeFunctionForMethod(context, findExportedMethod(logger, functionClass));
    sw.print("))");
  }
    public String generate() throws Exception {
      String simpleName = baseType_.getName().replace('.', '_') + "__Impl";

      PrintWriter printWriter = context_.tryCreate(logger_, packageName_, simpleName);
      if (printWriter != null) {
        ClassSourceFileComposerFactory factory =
            new ClassSourceFileComposerFactory(packageName_, simpleName);
        factory.addImplementedInterface(baseType_.getName());
        SourceWriter writer = factory.createSourceWriter(context_, printWriter);

        emitBody(writer);

        // Close the class and commit it
        writer.outdent();
        writer.println("}");
        context_.commit(logger_, printWriter);
      }
      return packageName_ + "." + simpleName;
    }
Exemple #14
0
  public String generate() throws UnableToCompleteException {
    String className = bundleType_.getSimpleSourceName() + "__Menu_" + menuId_;

    PrintWriter printWriter = context_.tryCreate(logger_, packageName_, className);
    if (printWriter == null) return null;

    ClassSourceFileComposerFactory factory =
        new ClassSourceFileComposerFactory(packageName_, className);
    factory.addImport("org.rstudio.core.client.Debug");
    factory.addImport("org.rstudio.core.client.command.MenuCallback");
    SourceWriter writer = factory.createSourceWriter(context_, printWriter);

    emitFields(writer);
    emitConstructor(writer, className);
    emitMethod(writer);
    writer.outdent();
    writer.println("}");
    context_.commit(logger_, printWriter);

    return packageName_ + "." + className;
  }
  private void writeIntrospectables(
      TreeLogger logger, List introspectables, MethodWrapper[] methods, SourceWriter writer) {
    for (Iterator it = introspectables.iterator(); it.hasNext(); ) {
      BeanResolver bean = (BeanResolver) it.next();

      logger.branch(
          TreeLogger.DEBUG, "Introspecting: " + bean.getType().getQualifiedSourceName(), null);

      try {
        if (bean.getProperties().size() == 0) {
          continue;
        }

        writer.print("private static BeanDescriptor ");
        writer.print(bean.getType().getQualifiedSourceName().replaceAll("\\.", "_"));

        writer.println(" = null;");
      } catch (Exception e) {
        logger.log(TreeLogger.ERROR, "Unable to introspect class. Is class a bean?", e);
      }
    }
  }
  private boolean unbox(JType type, String reference, SourceWriter writer) {
    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.INT)) {
      writer.print("((Integer) " + reference + ").intValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.LONG)) {
      writer.print("((Long) " + reference + ").longValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.FLOAT)) {
      writer.print("((Float) " + reference + ").floatValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.DOUBLE)) {
      writer.print("((Double) " + reference + ").doubleValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.CHAR)) {
      writer.print("((Character) " + reference + ").charValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BYTE)) {
      writer.print("((Byte) " + reference + ").byteValue()");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BOOLEAN)) {
      writer.print("((Boolean) " + reference + ").booleanValue()");

      return true;
    }

    writer.print("(" + type.getQualifiedSourceName() + ") " + reference);

    return false;
  }
Exemple #17
0
 /**
  * Generate any fields required by the proxy.
  *
  * @param serializableTypeOracle the type oracle
  */
 protected void generateProxyFields(
     SourceWriter srcWriter,
     SerializableTypeOracle serializableTypeOracle,
     String serializationPolicyStrongName,
     String remoteServiceInterfaceName) {
   // Initialize a field with binary name of the remote service interface
   srcWriter.println(
       "private static final String REMOTE_SERVICE_INTERFACE_NAME = "
           + "\""
           + remoteServiceInterfaceName
           + "\";");
   srcWriter.println(
       "private static final String SERIALIZATION_POLICY =\""
           + serializationPolicyStrongName
           + "\";");
   String typeSerializerName = SerializationUtils.getTypeSerializerQualifiedName(serviceIntf);
   srcWriter.println(
       "private static final "
           + typeSerializerName
           + " SERIALIZER = new "
           + typeSerializerName
           + "();");
   srcWriter.println();
 }
  /** Simply prints a JSNI reference to the exported function. */
  private static void writeIdentityInvocation(FragmentGeneratorContext context, JMethod m)
      throws UnableToCompleteException {
    SourceWriter sw = context.sw;
    JParameter[] parameters = m.getParameters();

    sw.print("@");
    sw.print(m.getEnclosingType().getQualifiedSourceName());
    sw.print("::");
    sw.print(m.getName());
    sw.print("(");

    // Argument list for the Java invocation
    for (int i = 0; i < parameters.length; i++) {
      sw.print(parameters[i].getType().getJNISignature());
    }

    sw.print(")");
  }
Exemple #19
0
  private void emitMethod(SourceWriter writer) throws UnableToCompleteException {
    writer.println("public void createMenu(MenuCallback callback) {");
    writer.indent();

    writer.println("callback.beginMainMenu();");
    // Vertical defaults to true
    emitMenu(writer, menuEl_);
    writer.println("callback.endMainMenu();");

    writer.outdent();
    writer.println("}");
  }
  private void generateConstructor(SourceWriter sourceWriter) {

    sourceWriter.println(
        "public Map<String, GwtBindingMethod> wrappedTypes = new HashMap<String, GwtBindingMethod>();");

    // start constructor source generation
    sourceWriter.println("public " + className + "() { ");
    sourceWriter.indent();
    sourceWriter.println("super();");

    sourceWriter.outdent();
    sourceWriter.println("}");
  }
  private boolean box(JType type, SourceWriter writer) {
    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.INT)) {
      writer.print("new Integer( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.LONG)) {
      writer.print("new Long( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.FLOAT)) {
      writer.print("new Float( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.DOUBLE)) {
      writer.print("new Double( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.CHAR)) {
      writer.print("new Character( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BYTE)) {
      writer.print("new Byte( ");

      return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BOOLEAN)) {
      writer.print("new Boolean( ");

      return true;
    }

    return false;
  }
  public String realize(TreeLogger logger) {
    logger =
        logger.branch(
            TreeLogger.DEBUG,
            "Generating TypeSerializer for service interface '" + typeSerializerClassName + "'",
            null);

    createFieldSerializers(logger, context);

    int index = 0;
    for (JType type : getSerializableTypes()) {

      String typeString;
      if (elideTypeNames) {
        typeString = Integer.toString(++index, Character.MAX_RADIX);
      } else {
        typeString = getTypeString(type);
      }
      typeStrings.put(type, typeString);
    }

    if (srcWriter != null) {
      writeStaticFields();
      writeStaticInitializer();

      if (context.isProdMode()) {
        writeLoadMethodsNative();
        writeLoadSignaturesNative();
      } else {
        writeLoadMethodsJava();
        writeLoadSignaturesJava();
      }

      writeConstructor();
      srcWriter.commit(logger);
    }

    return typeSerializerClassName;
  }
  private void writeResolver(List introspectables, SourceWriter writer) {
    writer.println("public Class resolveClass(Object object){");
    writer.indent();

    for (Iterator it = introspectables.iterator(); it.hasNext(); ) {
      BeanResolver type = (BeanResolver) it.next();
      writer.println(
          "if( object instanceof "
              + type.getType().getQualifiedSourceName()
              + " ) return "
              + type.getType().getQualifiedSourceName()
              + ".class;");
    }

    writer.println("throw new RuntimeException( \"Object \"+object+\"could not be resolved.\" );");
    writer.outdent();
    writer.println("}");
  }
  /** Writes the UiCommonEventMap for the edited model */
  private void writeEventMap() {
    logger.log(Type.DEBUG, "Starting to write EventMap"); // $NON-NLS-1$

    sw.println();
    sw.println("@Override"); // $NON-NLS-1$
    sw.println(
        "protected "
            + UiCommonEventMap.class.getName()
            + " getEventMap() {"); //$NON-NLS-1$ //$NON-NLS-2$
    sw.indent();

    sw.println(
        UiCommonEventMap.class.getName()
            + " eventMap = new "
            + UiCommonEventMap.class.getName()
            + "();"); //$NON-NLS-1$ //$NON-NLS-2$

    logger.log(Type.DEBUG, "Looking for Model Fields"); // $NON-NLS-1$

    for (EditorData editorData : model.getEditorData()) {
      logger.log(Type.DEBUG, "Going over Field: " + editorData); // $NON-NLS-1$

      String path = editorData.getPath();
      if (path.length() == 0) {
        continue;
      }

      JClassType propertyOwnerType = eraseType(editorData.getPropertyOwnerType());

      if (propertyOwnerType == entityModelType) {
        logger.log(Type.DEBUG, "Found EntityModel Field: " + editorData); // $NON-NLS-1$

        sw.println(
            "eventMap.addEvent(\"%s\", \"EntityChanged\", getObject()%s.getEntityChangedEvent());", //$NON-NLS-1$
            path, editorData.getBeanOwnerExpression());

      } else if (propertyOwnerType == listModelType) {
        logger.log(Type.DEBUG, "Found ListModel Field: " + editorData); // $NON-NLS-1$

        sw.println(
            "eventMap.addEvent(\"%s\", \"ItemsChanged\", getObject()%s.getItemsChangedEvent());", //$NON-NLS-1$
            path, editorData.getBeanOwnerExpression());
        sw.println(
            "eventMap.addEvent(\"%s\", \"SelectedItemsChanged\", getObject()%s.getSelectedItemsChangedEvent());", //$NON-NLS-1$
            path, editorData.getBeanOwnerExpression());
        sw.println(
            "eventMap.addEvent(\"%s\", \"SelectedItemChanged\", getObject()%s.getSelectedItemChangedEvent());", //$NON-NLS-1$
            path, editorData.getBeanOwnerExpression());
      }
    }

    sw.println("return eventMap;"); // $NON-NLS-1$
    sw.outdent();
    sw.println("}"); // $NON-NLS-1$
  }
Exemple #25
0
 private void emitConstructor(SourceWriter writer, String className) {
   writer.println(
       "public " + className + "(" + bundleType_.getQualifiedSourceName() + " commands) {");
   writer.indentln("this.cmds = commands;");
   writer.println("}");
 }
Exemple #26
0
 private void emitFields(SourceWriter writer) {
   writer.println("private " + bundleType_.getQualifiedSourceName() + " cmds;");
 }
  /** Writes the UiCommonListenerMap for the edited model */
  private void writeListenerMap() {
    logger.log(Type.DEBUG, "Starting to write ListenerMap"); // $NON-NLS-1$
    sw.println();
    sw.println("@Override"); // $NON-NLS-1$
    sw.println(
        "protected "
            + UiCommonListenerMap.class.getName()
            + " getListenerMap() {"); //$NON-NLS-1$ //$NON-NLS-2$
    sw.indent();

    sw.println(
        UiCommonListenerMap.class.getName()
            + " listenerMap = new "
            + UiCommonListenerMap.class.getName() // $NON-NLS-1$
            + "();"); //$NON-NLS-1$
    sw.println();

    logger.log(Type.DEBUG, "Looking for top-level Editor Fields"); // $NON-NLS-1$

    for (EditorData editorData : model.getEditorData()) {
      logger.log(Type.DEBUG, "Going over Field: " + editorData); // $NON-NLS-1$
      String path = editorData.getPath();
      // Change first letter to Upper to comply with UiCommon Property Names
      path = Character.toUpperCase(path.charAt(0)) + path.substring(1, path.length());

      if (path.length() == 0) {
        continue;
      }

      // only relevant for top-level properties
      if (!editorData.isDeclaredPathNested()) {
        logger.log(Type.DEBUG, "Found top-level Field: " + editorData); // $NON-NLS-1$

        sw.println(
            "listenerMap.addListener(\"%s\", \"PropertyChanged\", new org.ovirt.engine.ui.uicompat.IEventListener() {", //$NON-NLS-1$
            path);
        sw.indent();
        sw.println("@Override"); // $NON-NLS-1$
        sw.println(
            "public void eventRaised(org.ovirt.engine.ui.uicompat.Event ev, Object sender, org.ovirt.engine.ui.uicompat.EventArgs args) {"); //$NON-NLS-1$
        sw.indent();
        sw.println(
            "getEditor().%s.setValue(getObject()%s);", //$NON-NLS-1$
            editorData.getExpression(), editorData.getGetterExpression());
        sw.outdent();
        sw.println("}"); // $NON-NLS-1$
        sw.outdent();
        sw.println("});"); // $NON-NLS-1$
        sw.println();
      }
    }

    sw.println("return listenerMap;"); // $NON-NLS-1$
    sw.outdent();
    sw.println("}"); // $NON-NLS-1$
  }
  private void writeCleanup() {
    logger.log(
        Type.DEBUG,
        "Starting to write cleanup impl. for editor " //$NON-NLS-1$
            + model.getEditorType().getQualifiedSourceName());

    sw.println();
    sw.println("@Override"); // $NON-NLS-1$
    sw.println("public void cleanup() {"); // $NON-NLS-1$
    sw.indent();

    // 1. clean up the Editor instance
    Set<String> editorFieldExpressions = getEditorFieldCleanupExpressions();

    for (String expr : editorFieldExpressions) {
      sw.println(String.format("if (%s != null) {", expr)); // $NON-NLS-1$
      sw.indent();

      sw.println(String.format("%s.cleanup();", expr)); // $NON-NLS-1$

      sw.outdent();
      sw.println("}"); // $NON-NLS-1$
    }

    // 2. clean up the edited Model object
    Set<String> modelExpressions = getModelCleanupExpressions();

    if (!modelExpressions.isEmpty()) {
      sw.println("if (getObject() != null) {"); // $NON-NLS-1$
      sw.indent();

      for (String expr : modelExpressions) {
        sw.println(String.format("%s.cleanup();", expr)); // $NON-NLS-1$
      }

      sw.outdent();
      sw.println("}"); // $NON-NLS-1$
    }

    sw.outdent();
    sw.println("}"); // $NON-NLS-1$
  }
Exemple #29
0
 /**
  * @param syncMethod
  * @param asyncMethod
  * @param statsContextName
  */
 protected void generateRpcStatsContext(
     SourceWriter w, JMethod syncMethod, JMethod asyncMethod, String statsContextName) {
   w.println("RpcStatsContext " + statsContextName + " = new RpcStatsContext();");
 }
Exemple #30
0
 protected void generateStreamWriterOverride(SourceWriter srcWriter) {
   srcWriter.println("@Override");
   srcWriter.println("public SerializationStreamWriter createStreamWriter() {");
   srcWriter.indent();
   /*
    * Need an explicit cast since we've widened the declaration of the method
    * in RemoteServiceProxy.
    */
   srcWriter.println("ClientSerializationStreamWriter toReturn =");
   srcWriter.indentln("(ClientSerializationStreamWriter) super.createStreamWriter();");
   if (elideTypeNames) {
     srcWriter.println(
         "toReturn.addFlags(ClientSerializationStreamWriter." + "FLAG_ELIDE_TYPE_NAMES);");
   }
   srcWriter.println("if (getRpcToken() != null) {");
   srcWriter.indent();
   srcWriter.println(
       "toReturn.addFlags(ClientSerializationStreamWriter." + "FLAG_RPC_TOKEN_INCLUDED);");
   srcWriter.outdent();
   srcWriter.println("}");
   srcWriter.println("return toReturn;");
   srcWriter.outdent();
   srcWriter.println("}");
 }