Search in sources :

Example 6 with CallbackGroup

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

the class DraftBox method onDiscard.

@UiHandler({ "discard1", "discard2" })
void onDiscard(ClickEvent e) {
    e.stopPropagation();
    if (isNew()) {
        removeUI();
        restoreSelection();
    } else {
        setEdit(false);
        pendingGroup = new CallbackGroup();
        CommentApi.deleteDraft(psId, comment.id(), pendingGroup.addFinal(new GerritCallback<JavaScriptObject>() {

            @Override
            public void onSuccess(JavaScriptObject result) {
                pendingGroup = null;
                removeUI();
            }
        }));
    }
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 7 with CallbackGroup

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

the class DiffScreen method onLoad.

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

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

        @Override
        public void onSuccess(Void result) {
            // Load theme after CM library to ensure theme can override CSS.
            ThemeLoader.loadTheme(prefs.theme(), themeCallback);
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    DiffApi.diff(revision, path).base(base.asPatchSetId()).wholeFile().intraline(prefs.intralineDifference()).ignoreWhitespace(prefs.ignoreWhitespace()).get(group1.addFinal(new GerritCallback<DiffInfo>() {

        final AsyncCallback<Void> modeInjectorCb = group2.addEmpty();

        @Override
        public void onSuccess(DiffInfo diffInfo) {
            diff = diffInfo;
            fileSize = bucketFileSize(diffInfo);
            if (prefs.syntaxHighlighting()) {
                if (fileSize.compareTo(FileSize.SMALL) > 0) {
                    modeInjectorCb.onSuccess(null);
                } else {
                    injectMode(diffInfo, modeInjectorCb);
                }
            } else {
                modeInjectorCb.onSuccess(null);
            }
        }
    }));
    if (Gerrit.isSignedIn()) {
        ChangeApi.edit(changeId.get(), group2.add(new AsyncCallback<EditInfo>() {

            @Override
            public void onSuccess(EditInfo result) {
                edit = result;
            }

            @Override
            public void onFailure(Throwable caught) {
            }
        }));
    }
    final CommentsCollections comments = new CommentsCollections(base, revision, path);
    comments.load(group2);
    countParents(group2);
    RestApi call = ChangeApi.detail(changeId.get());
    ChangeList.addOptions(call, EnumSet.of(ListChangesOption.ALL_REVISIONS));
    call.get(group2.add(new AsyncCallback<ChangeInfo>() {

        @Override
        public void onSuccess(ChangeInfo info) {
            changeStatus = info.status();
            info.revisions().copyKeysIntoChildren("name");
            if (edit != null) {
                edit.setName(edit.commit().commit());
                info.setEdit(edit);
                info.revisions().put(edit.name(), RevisionInfo.fromEdit(edit));
            }
            String currentRevision = info.currentRevision();
            boolean current = currentRevision != null && revision.get() == info.revision(currentRevision)._number();
            JsArray<RevisionInfo> list = info.revisions().values();
            RevisionInfo.sortRevisionInfoByNumber(list);
            getDiffTable().set(prefs, list, parents, diff, edit != null, current, changeStatus.isOpen(), diff.binary());
            header.setChangeInfo(info);
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    ConfigInfoCache.get(changeId, group2.addFinal(getScreenLoadCallback(comments)));
}
Also used : RestApi(com.google.gerrit.client.rpc.RestApi) ChangeInfo(com.google.gerrit.client.info.ChangeInfo) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) EditInfo(com.google.gerrit.client.info.ChangeInfo.EditInfo) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo)

Example 8 with CallbackGroup

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

the class DiffScreen method onUnload.

@Override
protected void onUnload() {
    super.onUnload();
    removeKeyHandlerRegistrations();
    if (getCommentManager() != null) {
        CallbackGroup group = new CallbackGroup();
        getCommentManager().saveAllDrafts(group);
        group.done();
    }
    if (resizeHandler != null) {
        resizeHandler.removeHandler();
        resizeHandler = null;
    }
    for (CodeMirror cm : getCms()) {
        if (cm != null) {
            cm.getWrapperElement().removeFromParent();
        }
    }
    if (prefsAction != null) {
        prefsAction.hide();
    }
    Window.enableScrolling(true);
    Gerrit.setHeaderVisible(true);
}
Also used : CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) CodeMirror(net.codemirror.lib.CodeMirror)

Example 9 with CallbackGroup

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

the class DiffScreen method upToChange.

private Runnable upToChange(boolean openReplyBox) {
    return () -> {
        CallbackGroup group = new CallbackGroup();
        getCommentManager().saveAllDrafts(group);
        group.done();
        group.addListener(new GerritCallback<Void>() {

            @Override
            public void onSuccess(Void result) {
                String rev = String.valueOf(revision.get());
                Gerrit.display(PageLinks.toChange(changeId, base.asString(), rev), new ChangeScreen(changeId, base, rev, openReplyBox, FileTable.Mode.REVIEW));
            }
        });
    };
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) ChangeScreen(com.google.gerrit.client.change.ChangeScreen) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup)

Example 10 with CallbackGroup

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

the class DraftBox method onKeyDown.

@UiHandler("editArea")
void onKeyDown(KeyDownEvent e) {
    resizeTimer.cancel();
    if ((e.isControlKeyDown() || e.isMetaKeyDown()) && !e.isAltKeyDown() && !e.isShiftKeyDown()) {
        switch(e.getNativeKeyCode()) {
            case 's':
            case 'S':
                e.preventDefault();
                CallbackGroup group = new CallbackGroup();
                save(group);
                group.done();
                return;
        }
    } else if (e.getNativeKeyCode() == KeyCodes.KEY_ESCAPE && !isDirty()) {
        if (isNew()) {
            removeUI();
            restoreSelection();
            return;
        }
        setEdit(false);
        if (autoClosed) {
            setOpen(false);
        }
        getCm().focus();
        return;
    }
    expandTimer.schedule(250);
}
Also used : CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) UiHandler(com.google.gwt.uibinder.client.UiHandler)

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