Search in sources :

Example 1 with CallbackGroup

use of com.google.gerrit.client.rpc.CallbackGroup in project gerrit by GerritCodeReview.

the class Gerrit method onModuleLoad.

@Override
public void onModuleLoad() {
    if (!canLoadInIFrame()) {
        UserAgent.assertNotInIFrame();
    }
    setXsrfToken();
    KeyUtil.setEncoderImpl(new KeyUtil.Encoder() {

        @Override
        public String encode(String e) {
            e = URL.encodeQueryString(e);
            e = fixPathImpl(e);
            e = fixColonImpl(e);
            e = fixDoubleQuote(e);
            return e;
        }

        @Override
        public String decode(final String e) {
            return URL.decodeQueryString(e);
        }

        private native String fixPathImpl(String path);

        private native String fixColonImpl(String path);

        private native String fixDoubleQuote(String path);
    });
    initHostname();
    Window.setTitle(M.windowTitle1(myHost));
    RpcStatus.INSTANCE = new RpcStatus();
    CallbackGroup cbg = new CallbackGroup();
    getDocIndex(cbg.add(new GerritCallback<DocInfo>() {

        @Override
        public void onSuccess(DocInfo indexInfo) {
            hasDocumentation = indexInfo != null;
            docUrl = selfRedirect("/Documentation/");
        }
    }));
    ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() {

        @Override
        public void onSuccess(ServerInfo info) {
            myServerInfo = info;
            urlAliasMatcher = new UrlAliasMatcher(info.urlAliases());
            String du = info.gerrit().docUrl();
            if (du != null && !du.isEmpty()) {
                hasDocumentation = true;
                docUrl = du;
            }
            docSearch = info.gerrit().docSearch();
        }
    }));
    HostPageDataService hpd = GWT.create(HostPageDataService.class);
    hpd.load(cbg.addFinal(new GerritCallback<HostPageData>() {

        @Override
        public void onSuccess(final HostPageData result) {
            Document.get().getElementById("gerrit_hostpagedata").removeFromParent();
            myTheme = result.theme;
            isNoteDbEnabled = result.isNoteDbEnabled;
            if (result.accountDiffPref != null) {
                myAccountDiffPref = result.accountDiffPref;
            }
            if (result.accountDiffPref != null) {
                // TODO: Support options on the GetDetail REST endpoint so that it can
                // also return the preferences. Then we can fetch everything with a
                // single request and we don't need the callback group anymore.
                CallbackGroup cbg = new CallbackGroup();
                AccountApi.self().view("detail").get(cbg.add(new GerritCallback<AccountInfo>() {

                    @Override
                    public void onSuccess(AccountInfo result) {
                        myAccount = result;
                    }
                }));
                AccountApi.self().view("preferences").get(cbg.add(new GerritCallback<GeneralPreferences>() {

                    @Override
                    public void onSuccess(GeneralPreferences prefs) {
                        myPrefs = prefs;
                        onModuleLoad2(result);
                    }
                }));
                AccountApi.getEditPreferences(cbg.addFinal(new GerritCallback<EditPreferences>() {

                    @Override
                    public void onSuccess(EditPreferences prefs) {
                        EditPreferencesInfo prefsInfo = new EditPreferencesInfo();
                        prefs.copyTo(prefsInfo);
                        editPrefs = prefsInfo;
                    }
                }));
            } else {
                myAccount = AccountInfo.create(0, null, null, null);
                myPrefs = GeneralPreferences.createDefault();
                editPrefs = null;
                onModuleLoad2(result);
            }
        }
    }));
}
Also used : DocInfo(com.google.gerrit.client.documentation.DocInfo) ServerInfo(com.google.gerrit.client.info.ServerInfo) GeneralPreferences(com.google.gerrit.client.info.GeneralPreferences) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) EditPreferences(com.google.gerrit.client.account.EditPreferences) HostPageData(com.google.gerrit.common.data.HostPageData) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo) AccountInfo(com.google.gerrit.client.info.AccountInfo) KeyUtil(com.google.gwtorm.client.KeyUtil)

Example 2 with CallbackGroup

use of com.google.gerrit.client.rpc.CallbackGroup in project gerrit by GerritCodeReview.

the class ContactPanelShort method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    onInitUI();
    body.add(save);
    display(Gerrit.getUserAccount());
    emailPick.clear();
    emailPick.setEnabled(false);
    registerNewEmail.setEnabled(false);
    haveAccount = false;
    haveEmails = false;
    CallbackGroup group = new CallbackGroup();
    AccountApi.getName("self", group.add(new GerritCallback<NativeString>() {

        @Override
        public void onSuccess(NativeString result) {
            nameTxt.setText(result.asString());
            haveAccount = true;
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    AccountApi.getEmails("self", group.addFinal(new GerritCallback<JsArray<EmailInfo>>() {

        @Override
        public void onSuccess(JsArray<EmailInfo> result) {
            for (EmailInfo i : Natives.asList(result)) {
                emailPick.addItem(i.email());
                if (i.isPreferred()) {
                    currentEmail = i.email();
                }
            }
            haveEmails = true;
            postLoad();
        }
    }));
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) NativeString(com.google.gerrit.client.rpc.NativeString) JsArray(com.google.gwt.core.client.JsArray) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup)

Example 3 with CallbackGroup

use of com.google.gerrit.client.rpc.CallbackGroup in project gerrit by GerritCodeReview.

the class Loader method initLibrary.

static void initLibrary(final AsyncCallback<Void> cb) {
    if (isLibLoaded()) {
        cb.onSuccess(null);
        return;
    }
    CallbackGroup group = new CallbackGroup();
    injectCss(Lib.I.css(), group.<Void>addEmpty());
    injectScript(Lib.I.js().getSafeUri(), group.add(new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
            Vim.initKeyMap();
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    group.addListener(cb);
    group.done();
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup)

Example 4 with CallbackGroup

use of com.google.gerrit.client.rpc.CallbackGroup in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    CallbackGroup cbs = new CallbackGroup();
    ConfigServerApi.capabilities(cbs.add(new AsyncCallback<NativeMap<CapabilityInfo>>() {

        @Override
        public void onSuccess(NativeMap<CapabilityInfo> result) {
            capabilityMap = result;
        }

        @Override
        public void onFailure(Throwable caught) {
        // Handled by ScreenLoadCallback.onFailure().
        }
    }));
    Util.PROJECT_SVC.projectAccess(getProjectKey(), cbs.addFinal(new ScreenLoadCallback<ProjectAccess>(this) {

        @Override
        public void preDisplay(ProjectAccess access) {
            displayReadOnly(access);
        }
    }));
    savedPanel = ACCESS;
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) ScreenLoadCallback(com.google.gerrit.client.rpc.ScreenLoadCallback) NativeMap(com.google.gerrit.client.rpc.NativeMap) CapabilityInfo(com.google.gerrit.client.config.CapabilityInfo) ProjectAccess(com.google.gerrit.common.data.ProjectAccess)

Example 5 with CallbackGroup

use of com.google.gerrit.client.rpc.CallbackGroup in project gerrit by GerritCodeReview.

the class EditScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    prefs = EditPreferences.create(Gerrit.getEditPreferences());
    CallbackGroup group1 = new CallbackGroup();
    final CallbackGroup group2 = new CallbackGroup();
    final CallbackGroup group3 = new CallbackGroup();
    CodeMirror.initLibrary(group1.add(new AsyncCallback<Void>() {

        final AsyncCallback<Void> themeCallback = group3.addEmpty();

        @Override
        public void onSuccess(Void result) {
            // Load theme after CM library to ensure theme can override CSS.
            ThemeLoader.loadTheme(prefs.theme(), themeCallback);
            group2.done();
            new AddonInjector().add(Addons.I.merge_bundled().getName()).inject(new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(Void result) {
                    if (!prefs.showBase() || revision.get() > 0) {
                        group3.done();
                    }
                }
            });
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    ChangeApi.detail(revision.getParentKey().get(), group1.add(new AsyncCallback<ChangeInfo>() {

        @Override
        public void onSuccess(ChangeInfo c) {
            project.setInnerText(c.project());
            SafeHtml.setInnerHTML(filePath, Header.formatPath(path));
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    if (revision.get() == 0) {
        ChangeEditApi.getMeta(revision, path, group1.add(new AsyncCallback<EditFileInfo>() {

            @Override
            public void onSuccess(EditFileInfo editInfo) {
                editFileInfo = editInfo;
            }

            @Override
            public void onFailure(Throwable e) {
            }
        }));
        if (prefs.showBase()) {
            ChangeEditApi.get(revision, path, true, /* base */
            group1.addFinal(new HttpCallback<NativeString>() {

                @Override
                public void onSuccess(HttpResponse<NativeString> fc) {
                    baseContent = fc;
                    group3.done();
                }

                @Override
                public void onFailure(Throwable e) {
                }
            }));
        } else {
            group1.done();
        }
    } else {
        // TODO(davido): We probably want to create dedicated GET EditScreenMeta
        // REST endpoint. Abuse GET diff for now, as it retrieves links we need.
        DiffApi.diff(revision, path).webLinksOnly().get(group1.addFinal(new AsyncCallback<DiffInfo>() {

            @Override
            public void onSuccess(DiffInfo diffInfo) {
                diffLinks = diffInfo.webLinks();
            }

            @Override
            public void onFailure(Throwable e) {
            }
        }));
    }
    ChangeEditApi.get(revision, path, group2.add(new HttpCallback<NativeString>() {

        final AsyncCallback<Void> modeCallback = group3.addEmpty();

        @Override
        public void onSuccess(HttpResponse<NativeString> fc) {
            content = fc;
            if (revision.get() > 0) {
                baseContent = fc;
            }
            if (prefs.syntaxHighlighting()) {
                injectMode(fc.getContentType(), modeCallback);
            } else {
                modeCallback.onSuccess(null);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            // "Not Found" means it's a new file.
            if (RestApi.isNotFound(e)) {
                content = null;
                modeCallback.onSuccess(null);
            } else {
                GerritCallback.showFailure(e);
            }
        }
    }));
    group3.addListener(new ScreenLoadCallback<Void>(this) {

        @Override
        protected void preDisplay(Void result) {
            initEditor();
            renderLinks(editFileInfo, diffLinks);
            editFileInfo = null;
            diffLinks = null;
            showBase.setValue(prefs.showBase(), true);
            cmBase.refresh();
        }
    });
}
Also used : ChangeInfo(com.google.gerrit.client.info.ChangeInfo) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) HttpCallback(com.google.gerrit.client.rpc.HttpCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) HttpResponse(com.google.gerrit.client.rpc.HttpResponse) AddonInjector(net.codemirror.addon.AddonInjector) DiffInfo(com.google.gerrit.client.diff.DiffInfo)

Aggregations

CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)16 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)8 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)5 ChangeInfo (com.google.gerrit.client.info.ChangeInfo)3 RevisionInfo (com.google.gerrit.client.info.ChangeInfo.RevisionInfo)3 UiHandler (com.google.gwt.uibinder.client.UiHandler)3 AccountInfo (com.google.gerrit.client.info.AccountInfo)2 EditInfo (com.google.gerrit.client.info.ChangeInfo.EditInfo)2 NativeMap (com.google.gerrit.client.rpc.NativeMap)2 NativeString (com.google.gerrit.client.rpc.NativeString)2 RestApi (com.google.gerrit.client.rpc.RestApi)2 ScreenLoadCallback (com.google.gerrit.client.rpc.ScreenLoadCallback)2 JsArray (com.google.gwt.core.client.JsArray)2 NotFoundScreen (com.google.gerrit.client.NotFoundScreen)1 ProjectAccessInfo (com.google.gerrit.client.access.ProjectAccessInfo)1 EditPreferences (com.google.gerrit.client.account.EditPreferences)1 ChangeScreen (com.google.gerrit.client.change.ChangeScreen)1 ChangeList (com.google.gerrit.client.changes.ChangeList)1 CommentInfo (com.google.gerrit.client.changes.CommentInfo)1 CapabilityInfo (com.google.gerrit.client.config.CapabilityInfo)1