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

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

Introduction

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

Prototype

void outdent();

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(// ww w  .j a  v  a2  s. c  o  m
            "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();
        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));
    }//from www.  java2s . c  om
    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(//from w  w w  . j a v  a  2  s  .  com
            "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();
        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));
    }//from  w  w  w . j av a  2 s .  co  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.InjectPresenterCreator.java

License:Open Source License

@Override
public void writePresent(SourceWriter srcWriter) {
    for (JMethod presenterMethod : this.presenterMethods) {
        if (presenterMethod.getParameters().length == 0) {
            srcWriter.println("super.%s();", presenterMethod.getName());
        } else if (presenterMethod.getParameters().length > 0) {
            JType placeType = presenterMethod.getParameters()[0].getType();
            srcWriter.println("if(place instanceof %s){", placeType.getSimpleSourceName());
            srcWriter.indent();/*from   ww w  .ja  v a2 s .  c om*/
            srcWriter.println("super.%s((%s) place);", presenterMethod.getName(),
                    placeType.getSimpleSourceName());
            srcWriter.outdent();
            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(//from  w w w  .  j av a2s .co  m
            "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();
        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.SuspendServiceOnPresentCreator.java

License:Open Source License

@Override
public void writeAfterPresent(SourceWriter srcWriter) {
    if (!this.hasService) {
        srcWriter.println("displayer.setWidget(%s.this);", this.injectorName);
    } else {/*  ww w. ja  va  2  s  . c o m*/
        srcWriter.println("commandController.flush(new CallbackAdapter<List<CommandResponse>>() {");
        srcWriter.indent();
        srcWriter.println("@Override");
        srcWriter.println("public void onSuccess(List<CommandResponse> result) {");
        srcWriter.indent();
        srcWriter.println("displayer.setWidget(%s.this);", this.injectorName);
        srcWriter.outdent();
        srcWriter.println("};");
        srcWriter.outdent();
        srcWriter.println("});");
        srcWriter.println("commandController.setSuspended(isSuspended);");
    }
}

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  w w w.  ja v  a2  s .co m

    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/*w  w w .j av a 2 s  . c  om*/
    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("}");
}

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

public String create(TreeLogger logger, GeneratorContext context) {
    PrintWriter printWriter = this.getPrintWriter(logger, context, this.proxyModelQualifiedName);
    if (printWriter == null) {
        return this.proxyModelQualifiedName;
    }/* w ww.  j av a  2 s  .  co m*/

    JField[] fields = this.beanType.getFields();
    JMethod[] methods = this.beanType.getMethods();

    this.parentType = this.beanType.getSuperclass();
    this.imports.add(this.parentType);

    this.listPublicFields(fields);
    this.listGetters(methods);
    this.listSetters(methods);

    this.createSubModels(logger, context);

    SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

    srcWriter.indent();
    srcWriter.println();
    this.generateSingleton(logger, srcWriter);
    srcWriter.println();
    srcWriter.println();
    this.generateStaticInitializer(logger, srcWriter);
    srcWriter.println();
    this.generateConstructor(logger, srcWriter);
    srcWriter.println();
    this.generateCreate(logger, srcWriter);
    srcWriter.println();
    this.generateInternalSet(logger, srcWriter);
    srcWriter.println();
    this.generateInternalGet(logger, srcWriter);

    srcWriter.outdent();

    srcWriter.commit(logger);
    return this.proxyModelQualifiedName;
}