Example usage for com.google.gwt.user.rebind SourceWriter println

List of usage examples for com.google.gwt.user.rebind SourceWriter println

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind SourceWriter println.

Prototype

void println(String s);

Source Link

Usage

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectErrorHandlerCreator.java

License:Open Source License

@Override
public void writePresent(SourceWriter srcWriter) {

    srcWriter.println(
            "final List<fr.putnami.pwt.core.error.client.ErrorHandler> errorHandlers = Lists.newArrayList();");
    for (JMethod handlerMethod : this.presenterMethods) {
        srcWriter.println("errorHandlers.add(new fr.putnami.pwt.core.error.client.ErrorHandler() {");
        srcWriter.indent();//w  w w  .  j a  v a  2  s  .co  m
        srcWriter.println("@Override public boolean handle(Throwable error) { return %s.this.%s(error); }",
                this.injectorName, handlerMethod.getName());
        srcWriter.println("@Override public int getPriority() { return HIGH_PRIORITY; }");
        srcWriter.outdent();
        srcWriter.println("});");
    }

    srcWriter.println("for (fr.putnami.pwt.core.error.client.ErrorHandler errorHandler : errorHandlers) {");
    srcWriter.indent();
    srcWriter.println("ErrorManager.get().registerErrorHandler(errorHandler);");
    srcWriter.outdent();
    srcWriter.println("}");

    srcWriter.println("final HandlerRegistrationCollection errorHandlerRegistrations "
            + "= new HandlerRegistrationCollection();");
    srcWriter.println("errorHandlerRegistrations.add("
            + "EventBus.get().addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {");
    srcWriter.indent();
    srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {");
    srcWriter.indent();
    srcWriter.println("for (fr.putnami.pwt.core.error.client.ErrorHandler handler : errorHandlers) {");
    srcWriter.indent();
    srcWriter.println("ErrorManager.get().registerErrorHandler(handler);");
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.outdent();
    srcWriter.println("errorHandlerRegistrations.removeHandler();");
    srcWriter.outdent();
    srcWriter.println("}}));");
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectErrorManagerCreator.java

License:Open Source License

@Override
public void writeEntryPoint(SourceWriter srcWriter) {
    srcWriter.println("ErrorManager.get();");
    if (!ErrorDisplayer.class.equals(this.errorDisplay)) {
        srcWriter.println("ErrorManager.get().setErrorDisplayer(GWT.<ErrorDisplayer> create(%s.class));",
                InjectCreatorUtil.toClassName(this.errorDisplay));
    }// w ww.j a v  a  2 s  .co  m
    if (this.errorHandlers != null) {
        for (Class<? extends ErrorHandler> handlerClass : this.errorHandlers) {
            srcWriter.println("ErrorManager.get().registerErrorHandler(new %s());",
                    InjectCreatorUtil.toClassName(handlerClass));
        }
    }
    if (this.errorHandlers != null) {
        for (JMethod handlerMethod : this.handlerMethods) {
            srcWriter.println("ErrorManager.get().registerErrorHandler("
                    + "new fr.putnami.pwt.core.error.client.ErrorHandler() {");
            srcWriter.indent();
            srcWriter.println("@Override public boolean handle(Throwable error) { return %s.this.%s(error); }",
                    this.injectorName, handlerMethod.getName());
            srcWriter.println("@Override public int getPriority() { return HIGH_PRIORITY; }");
            srcWriter.outdent();
            srcWriter.println("});");
        }
    }
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectMayStopActivityCreator.java

License:Open Source License

@Override
public void writePresent(SourceWriter srcWriter) {
    srcWriter.println(
            "final HandlerRegistrationCollection mayStopRegistrations = new HandlerRegistrationCollection();");
    for (JMethod mayStopMethod : this.presenterMethods) {
        srcWriter.println("mayStopRegistrations.add(EventBus.get()"
                + ".addHandlerToSource(MayStopActivityEvent.TYPE, place, new MayStopActivityEvent.Handler() {");
        srcWriter.indent();/*from ww w  .j a v a  2 s  . co  m*/
        srcWriter.println("@Override public void onMayStopActivity(MayStopActivityEvent event) {");
        srcWriter.indent();
        srcWriter.println("if (event.getMessage() == null) { event.setMessage(%s.this.%s()); }",
                this.injectorName, mayStopMethod.getName());
        srcWriter.outdent();
        srcWriter.outdent();
        srcWriter.println("}}));");
    }
    srcWriter.println("mayStopRegistrations.add(EventBus.get()"
            + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {");
    srcWriter.indent();
    srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {");
    srcWriter.indent();
    srcWriter.println("mayStopRegistrations.removeHandler();");
    srcWriter.outdent();
    srcWriter.outdent();
    srcWriter.println("}}));");
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectMvpDescriptionCreator.java

License:Open Source License

@Override
public void writeEntryPoint(SourceWriter srcWriter) {
    srcWriter.println("MvpController mvpController = MvpController.get();");
    srcWriter.println("AcceptsOneWidget mvpDisplay = null;");
    if (this.display != null && !AcceptsOneWidget.class.equals(this.display)) {
        srcWriter.println("mvpDisplay = GWT.create(%s.class);", InjectCreatorUtil.toClassName(this.display));
    }// w w w .j a v a2 s  .c o  m
    srcWriter.println("if(mvpDisplay != null){");
    srcWriter.indent();
    srcWriter.println("mvpController.setDisplay(mvpDisplay);");
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println("if(mvpDisplay instanceof IsWidget){");
    srcWriter.indent();
    srcWriter.println("RootPanel.get().add((IsWidget) mvpDisplay);");
    srcWriter.outdent();
    srcWriter.println("}");

    if (this.defaultPlace != null && !Place.class.equals(this.defaultPlace)) {
        srcWriter.println("mvpController.setDefaultPlace(new %s());",
                InjectCreatorUtil.toClassName(this.defaultPlace));
    }
    for (Class<?> activity : this.activities) {
        srcWriter.println("mvpController.registerActivity(GWT.<ActivityFactory> create(%s.class));",
                InjectCreatorUtil.toClassName(activity));
    }
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectSecuritedCreator.java

License:Open Source License

@Override
public void writeBeforePresent(SourceWriter srcWriter) {
    if (this.securedAnnotation.value() != null) {
        srcWriter.print("SessionController.get().checkAuthorized(place");
        for (String value : this.securedAnnotation.value()) {
            srcWriter.print(", \"%s\"", value);
        }// w  w  w.  j  a  v  a  2  s  .c o m
        srcWriter.println(");");
    }
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectStopActivityCreator.java

License:Open Source License

@Override
public void writePresent(SourceWriter srcWriter) {
    srcWriter.println(
            "final HandlerRegistrationCollection stopRegistrations = new HandlerRegistrationCollection();");
    for (JMethod mayStopMethod : this.presenterMethods) {
        srcWriter.println("stopRegistrations.add(EventBus.get()"
                + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {");
        srcWriter.indent();/*from w  w w .j  av  a2s  .c o  m*/
        srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {");
        srcWriter.indent();
        srcWriter.println("%s.this.%s();", this.injectorName, mayStopMethod.getName());
        srcWriter.outdent();
        srcWriter.outdent();
        srcWriter.println("}}));");
    }
    srcWriter.println("stopRegistrations.add(EventBus.get()"
            + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {");
    srcWriter.indent();
    srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {");
    srcWriter.indent();
    srcWriter.println("stopRegistrations.removeHandler();");
    srcWriter.outdent();
    srcWriter.outdent();
    srcWriter.println("}}));");
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectThemeCreator.java

License:Open Source License

@Override
public void writeEntryPoint(SourceWriter srcWriter) {
    srcWriter.println("Theme theme = new Theme();");
    for (String style : this.styles) {
        srcWriter.println("theme.addLink(new CssLink(\"%s\", 0));", style);
    }// w  w w .  ja  v a 2  s.co m
    srcWriter.println("ThemeController.get().installTheme(theme);");
}

From source file:fr.putnami.pwt.core.inject.rebind.delegate.SuspendServiceOnPresentCreator.java

License:Open Source License

@Override
public void writeBeforePresent(SourceWriter srcWriter) {
    if (this.hasService) {
        srcWriter.println("CommandController commandController = CommandController.get();");
        srcWriter.println("boolean isSuspended = commandController.isSuspended();");
        srcWriter.println("commandController.setSuspended(true);");
    }//  w w  w  . j a  va2 s . co  m
}

From source file:fr.putnami.pwt.core.inject.rebind.InjectorModuleCreator.java

License:Open Source License

@Override
protected void doCreate(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) {
    super.doCreate(logger, context, srcWriter);

    srcWriter.println("@Override public void onModuleLoad() {");
    srcWriter.indent();/*from   ww w.j  a va2 s.com*/

    try {
        if (this.injectableType.getMethod("onModuleLoad", new JType[] {}) != null) {
            srcWriter.println("super.onModuleLoad();");
        }
    } catch (NotFoundException e) {
        srcWriter.println("");
    }

    for (InjectorWritterEntryPoint delegate : Iterables.filter(this.delegates,
            InjectorWritterEntryPoint.class)) {
        delegate.writeEntryPoint(srcWriter);
        srcWriter.println();
    }

    for (JMethod method : InjectCreatorUtil.listMethod(this.injectableType, EntryPointHandler.class)) {
        srcWriter.println("super.%s();", method.getName());
    }

    srcWriter.println();
    MvpDescription mvpAnnotation = this.injectableType.getAnnotation(MvpDescription.class);
    if (mvpAnnotation != null && mvpAnnotation.handleCurrentHistory()) {
        srcWriter.println("MvpController.get().handleCurrentHistory();");
    }
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.inject.rebind.InjectorViewCreator.java

License:Open Source License

@Override
protected void doCreate(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) {
    super.doCreate(logger, context, srcWriter);

    // presenter//from www.  ja v a  2  s. c  o m
    srcWriter.println("public <P extends Place> void present(P place, final AcceptsOneWidget displayer){");
    srcWriter.indent();

    for (InjectorWritterBeforePresent delegate : Iterables.filter(this.delegates,
            InjectorWritterBeforePresent.class)) {
        delegate.writeBeforePresent(srcWriter);
    }
    for (InjectorWritterPresent delegate : Iterables.filter(this.delegates, InjectorWritterPresent.class)) {
        delegate.writePresent(srcWriter);
    }
    for (InjectorWritterAfterPresent delegate : Iterables.filter(this.delegates,
            InjectorWritterAfterPresent.class)) {
        delegate.writeAfterPresent(srcWriter);
    }
    srcWriter.outdent();
    srcWriter.println("}");
}