diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountService.java index 2fad82ee3d..b4fc55dc4d 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountService.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/AccountService.java @@ -16,6 +16,7 @@ package com.google.gerrit.common.data; import com.google.gerrit.common.auth.SignInRequired; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountGeneralPreferences; import com.google.gerrit.reviewdb.AccountProjectWatch; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -32,10 +33,17 @@ public interface AccountService extends RemoteJsonService { @SignInRequired void myAccount(AsyncCallback callback); + @SignInRequired + void myDiffPreferences(AsyncCallback callback); + @SignInRequired void changePreferences(AccountGeneralPreferences pref, AsyncCallback gerritCallback); + @SignInRequired + void changeDiffPreferences(AccountDiffPreference diffPref, + AsyncCallback callback); + @SignInRequired void myProjectWatch(AsyncCallback> callback); diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java index e2dc1a7c66..717a49287f 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java @@ -15,9 +15,11 @@ package com.google.gerrit.common.data; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; /** Data sent as part of the host page, to bootstrap the UI. */ public class HostPageData { public Account account; + public AccountDiffPreference accountDiffPref; public GerritConfig config; } diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java index 2c1fd721aa..f2a2af1906 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java @@ -14,17 +14,16 @@ package com.google.gerrit.common.data; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT; - -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.common.EditList; import com.google.gerrit.prettify.common.PrettyFormatter; import com.google.gerrit.prettify.common.PrettySettings; import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseHtmlFile; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.Patch; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import com.google.gerrit.reviewdb.Patch.ChangeType; import org.eclipse.jgit.diff.Edit; @@ -178,7 +177,7 @@ public class PatchScript { public Iterable getHunks() { int ctx = settings.getContext(); - if (ctx == WHOLE_FILE_CONTEXT) { + if (ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT) { ctx = Math.max(a.size(), b.size()); } return new EditList(edits, ctx, a.size(), b.size()).getHunks(); diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScriptSettings.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScriptSettings.java index cd43ba41e6..09fd241651 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScriptSettings.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScriptSettings.java @@ -15,33 +15,16 @@ package com.google.gerrit.common.data; import com.google.gerrit.prettify.common.PrettySettings; -import com.google.gerrit.reviewdb.AccountGeneralPreferences; -import com.google.gerrit.reviewdb.CodedEnum; +import com.google.gerrit.reviewdb.AccountDiffPreference; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; public class PatchScriptSettings { - public static enum Whitespace implements CodedEnum { - IGNORE_NONE('N'), // - IGNORE_SPACE_AT_EOL('E'), // - IGNORE_SPACE_CHANGE('S'), // - IGNORE_ALL_SPACE('A'); - - private final char code; - - private Whitespace(final char c) { - code = c; - } - - public char getCode() { - return code; - } - } - protected int context; protected Whitespace whitespace; protected PrettySettings pretty; public PatchScriptSettings() { - context = AccountGeneralPreferences.DEFAULT_CONTEXT; + context = AccountDiffPreference.DEFAULT_CONTEXT; whitespace = Whitespace.IGNORE_NONE; pretty = new PrettySettings(); } @@ -65,7 +48,7 @@ public class PatchScriptSettings { } public void setContext(final int ctx) { - assert 0 <= ctx || ctx == AccountGeneralPreferences.WHOLE_FILE_CONTEXT; + assert 0 <= ctx || ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT; context = ctx; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java index e1b0c15b23..9af36af27e 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java @@ -27,6 +27,7 @@ import com.google.gerrit.common.data.GerritConfig; import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.common.data.SystemInfoService; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountGeneralPreferences; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; @@ -70,6 +71,7 @@ public class Gerrit implements EntryPoint { private static String myHost; private static GerritConfig myConfig; private static Account myAccount; + private static AccountDiffPreference myAccountDiffPref; private static TabPanel menuLeft; private static LinkMenuBar menuRight; @@ -172,6 +174,15 @@ public class Gerrit implements EntryPoint { return myAccount; } + /** @return the currently signed in users's diff preferences; null if no diff preferences defined for the account */ + public static AccountDiffPreference getAccountDiffPreference() { + return myAccountDiffPref; + } + + public static void setAccountDiffPreference(AccountDiffPreference accountDiffPref) { + myAccountDiffPref = accountDiffPref; + } + /** @return true if the user is currently authenticated */ public static boolean isSignedIn() { return getUserAccount() != null; @@ -203,6 +214,7 @@ public class Gerrit implements EntryPoint { static void deleteSessionCookie() { Cookies.removeCookie(SESSION_COOKIE); myAccount = null; + myAccountDiffPref = null; refreshMenuBar(); } @@ -234,6 +246,9 @@ public class Gerrit implements EntryPoint { if (result.account != null) { myAccount = result.account; } + if (result.accountDiffPref != null) { + myAccountDiffPref = result.accountDiffPref; + } onModuleLoad2(); } }); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java index c43b3f6f8a..bc93034322 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java @@ -24,7 +24,6 @@ public interface AccountConstants extends Constants { String registeredOn(); String accountId(); - String defaultContextFieldLabel(); String maximumPageSizeFieldLabel(); String contextWholeFile(); String showSiteHeader(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/PreferencePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/PreferencePanel.java index f5f803a018..904fb38ae7 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/PreferencePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/PreferencePanel.java @@ -14,11 +14,8 @@ package com.google.gerrit.client.account; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.CONTEXT_CHOICES; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.DEFAULT_CONTEXT; import static com.google.gerrit.reviewdb.AccountGeneralPreferences.DEFAULT_PAGESIZE; import static com.google.gerrit.reviewdb.AccountGeneralPreferences.PAGESIZE_CHOICES; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT; import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.rpc.GerritCallback; @@ -41,7 +38,6 @@ class PreferencePanel extends Composite { private CheckBox showSiteHeader; private CheckBox useFlashClipboard; private CheckBox copySelfOnEmails; - private ListBox defaultContext; private ListBox maximumPageSize; private Button save; @@ -76,18 +72,6 @@ class PreferencePanel extends Composite { } maximumPageSize.addChangeHandler(onChangeSave); - defaultContext = new ListBox(); - for (final short v : CONTEXT_CHOICES) { - final String label; - if (v == WHOLE_FILE_CONTEXT) { - label = Util.C.contextWholeFile(); - } else { - label = Util.M.lines(v); - } - defaultContext.addItem(label, String.valueOf(v)); - } - defaultContext.addChangeHandler(onChangeSave); - final int labelIdx, fieldIdx; if (LocaleInfo.getCurrentLocale().isRTL()) { labelIdx = 1; @@ -96,7 +80,7 @@ class PreferencePanel extends Composite { labelIdx = 0; fieldIdx = 1; } - final Grid formGrid = new Grid(5, 2); + final Grid formGrid = new Grid(4, 2); int row = 0; formGrid.setText(row, labelIdx, ""); @@ -115,10 +99,6 @@ class PreferencePanel extends Composite { formGrid.setWidget(row, fieldIdx, maximumPageSize); row++; - formGrid.setText(row, labelIdx, Util.C.defaultContextFieldLabel()); - formGrid.setWidget(row, fieldIdx, defaultContext); - row++; - body.add(formGrid); save = new Button(Util.C.buttonSaveChanges()); @@ -150,7 +130,6 @@ class PreferencePanel extends Composite { useFlashClipboard.setEnabled(on); copySelfOnEmails.setEnabled(on); maximumPageSize.setEnabled(on); - defaultContext.setEnabled(on); } private void display(final AccountGeneralPreferences p) { @@ -158,7 +137,6 @@ class PreferencePanel extends Composite { useFlashClipboard.setValue(p.isUseFlashClipboard()); copySelfOnEmails.setValue(p.isCopySelfOnEmails()); setListBox(maximumPageSize, DEFAULT_PAGESIZE, p.getMaximumPageSize()); - setListBox(defaultContext, DEFAULT_CONTEXT, p.getDefaultContext()); } private void setListBox(final ListBox f, final short defaultValue, @@ -189,7 +167,6 @@ class PreferencePanel extends Composite { p.setUseFlashClipboard(useFlashClipboard.getValue()); p.setCopySelfOnEmails(copySelfOnEmails.getValue()); p.setMaximumPageSize(getListBox(maximumPageSize, DEFAULT_PAGESIZE)); - p.setDefaultContext(getListBox(defaultContext, DEFAULT_CONTEXT)); enable(false); save.setEnabled(false); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java index dfcbb7e362..d576097ac2 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java @@ -14,8 +14,6 @@ package com.google.gerrit.client.patches; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT; - import com.google.gerrit.client.Dispatcher; import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.RpcStatus; @@ -33,6 +31,7 @@ import com.google.gerrit.common.data.PatchScriptSettings; import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.common.PrettyFactory; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.Patch; import com.google.gerrit.reviewdb.PatchSet; @@ -234,7 +233,7 @@ public abstract class PatchScreen extends Screen implements } final int ctx = s.getContext(); - if (ctx == WHOLE_FILE_CONTEXT && !last.getA().isWholeFile()) { + if (ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT && !last.getA().isWholeFile()) { // We don't have the entire file here, so we can't render it. return false; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java index 5a461edc6b..3804580be3 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java @@ -14,16 +14,14 @@ package com.google.gerrit.client.patches; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.DEFAULT_CONTEXT; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT; - import com.google.gerrit.client.Gerrit; +import com.google.gerrit.client.account.Util; +import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.ui.NpIntTextBox; import com.google.gerrit.common.data.PatchScriptSettings; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.prettify.common.PrettySettings; -import com.google.gerrit.reviewdb.Account; -import com.google.gerrit.reviewdb.AccountGeneralPreferences; +import com.google.gerrit.reviewdb.AccountDiffPreference; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.KeyCodes; @@ -43,6 +41,7 @@ import com.google.gwt.user.client.ui.FocusWidget; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; +import com.google.gwtjsonrpc.client.VoidResult; public class PatchScriptSettingsPanel extends Composite implements HasValueChangeHandlers { @@ -71,7 +70,7 @@ public class PatchScriptSettingsPanel extends Composite implements CheckBox intralineDifference; @UiField - CheckBox showFullFile; + ListBox context; @UiField CheckBox whitespaceErrors; @@ -85,9 +84,24 @@ public class PatchScriptSettingsPanel extends Composite implements @UiField Button update; + /** + * Counts +1 for every setEnabled(true) and -1 for every setEnabled(false) + * + * The purpose is to prevent enabling widgets too early. It might happen that + * setEnabled(false) is called from this class and from an event handler + * of ValueChangeEvent in another class. The first setEnabled(true) would then + * enable widgets too early i.e. before the second setEnabled(true) is called. + * + * With this counter the setEnabled(true) will enable widgets only when + * setEnabledCounter == 0. Until it is less than zero setEnabled(true) will + * not enable the widgets. + */ + private int setEnabledCounter; + public PatchScriptSettingsPanel() { initWidget(uiBinder.createAndBindUi(this)); initIgnoreWhitespace(ignoreWhitespace); + initContext(context); if (!Gerrit.isSignedIn()) { reviewed.setVisible(false); } @@ -103,15 +117,11 @@ public class PatchScriptSettingsPanel extends Composite implements tabWidth.addKeyPressHandler(onEnter); colWidth.addKeyPressHandler(onEnter); - final PatchScriptSettings s = new PatchScriptSettings(); - if (Gerrit.isSignedIn()) { - final Account u = Gerrit.getUserAccount(); - final AccountGeneralPreferences pref = u.getGeneralPreferences(); - s.setContext(pref.getDefaultContext()); + if (Gerrit.isSignedIn() && Gerrit.getAccountDiffPreference() != null) { + setValue(createPatchScriptSettings(Gerrit.getAccountDiffPreference())); } else { - s.setContext(DEFAULT_CONTEXT); + setValue(new PatchScriptSettings()); } - setValue(s); } @Override @@ -121,12 +131,19 @@ public class PatchScriptSettingsPanel extends Composite implements } public void setEnabled(final boolean on) { - for (Widget w : (HasWidgets) getWidget()) { - if (w instanceof FocusWidget) { - ((FocusWidget) w).setEnabled(on); - } + if (on) { + setEnabledCounter++; + } else { + setEnabledCounter--; } - toggleEnabledStatus(on); + if (on && setEnabledCounter == 0 || !on) { + for (Widget w : (HasWidgets) getWidget()) { + if (w instanceof FocusWidget) { + ((FocusWidget) w).setEnabled(on); + } + } + toggleEnabledStatus(on); + }; } public void setEnableSmallFileFeatures(final boolean on) { @@ -135,10 +152,8 @@ public class PatchScriptSettingsPanel extends Composite implements final PrettySettings p = getValue().getPrettySettings(); syntaxHighlighting.setValue(p.isSyntaxHighlighting()); - showFullFile.setValue(getValue().getContext() == WHOLE_FILE_CONTEXT); } else { syntaxHighlighting.setValue(false); - showFullFile.setValue(false); } toggleEnabledStatus(update.isEnabled()); } @@ -157,12 +172,10 @@ public class PatchScriptSettingsPanel extends Composite implements private void toggleEnabledStatus(final boolean on) { intralineDifference.setEnabled(on & enableIntralineDifference); syntaxHighlighting.setEnabled(on & enableSmallFileFeatures); - showFullFile.setEnabled(on & enableSmallFileFeatures); final String title = enableSmallFileFeatures ? null : PatchUtil.C.disabledOnLargeFiles(); syntaxHighlighting.setTitle(title); - showFullFile.setTitle(title); } public CheckBox getReviewedCheckBox() { @@ -178,12 +191,11 @@ public class PatchScriptSettingsPanel extends Composite implements setIgnoreWhitespace(s.getWhitespace()); if (enableSmallFileFeatures) { - showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT); syntaxHighlighting.setValue(p.isSyntaxHighlighting()); } else { - showFullFile.setValue(false); syntaxHighlighting.setValue(false); } + setContext(s.getContext()); tabWidth.setIntValue(p.getTabSize()); colWidth.setIntValue(p.getLineLength()); @@ -204,20 +216,7 @@ public class PatchScriptSettingsPanel extends Composite implements PrettySettings p = s.getPrettySettings(); s.setWhitespace(getIgnoreWhitespace()); - if (showFullFile.getValue()) { - s.setContext(WHOLE_FILE_CONTEXT); - } else if (Gerrit.isSignedIn()) { - final Account u = Gerrit.getUserAccount(); - final AccountGeneralPreferences pref = u.getGeneralPreferences(); - if (pref.getDefaultContext() == WHOLE_FILE_CONTEXT) { - s.setContext(DEFAULT_CONTEXT); - } else { - s.setContext(pref.getDefaultContext()); - } - } else { - s.setContext(DEFAULT_CONTEXT); - } - + s.setContext(getContext()); p.setTabSize(tabWidth.getIntValue()); p.setLineLength(colWidth.getIntValue()); p.setSyntaxHighlighting(syntaxHighlighting.getValue()); @@ -227,6 +226,35 @@ public class PatchScriptSettingsPanel extends Composite implements value = s; fireEvent(new ValueChangeEvent(s) {}); + + if (Gerrit.isSignedIn()) { + persistDiffPreferences(); + } + } + + private void persistDiffPreferences() { + setEnabled(false); + final AccountDiffPreference diffPref = new AccountDiffPreference(Gerrit.getUserAccount().getId()); + diffPref.setIgnoreWhitespace(getIgnoreWhitespace()); + diffPref.setTabSize(tabWidth.getIntValue()); + diffPref.setLineLength(colWidth.getIntValue()); + diffPref.setSyntaxHighlighting(syntaxHighlighting.getValue()); + diffPref.setShowWhitespaceErrors(whitespaceErrors.getValue()); + diffPref.setIntralineDifference(intralineDifference.getValue()); + diffPref.setShowTabs(showTabs.getValue()); + diffPref.setContext(getContext()); + Util.ACCOUNT_SVC.changeDiffPreferences(diffPref, new GerritCallback() { + @Override + public void onSuccess(VoidResult result) { + Gerrit.setAccountDiffPreference(diffPref); + setEnabled(true); + } + + @Override + public void onFailure(Throwable caught) { + setEnabled(true); + } + }); } private void initIgnoreWhitespace(ListBox ws) { @@ -240,6 +268,18 @@ public class PatchScriptSettingsPanel extends Composite implements Whitespace.IGNORE_ALL_SPACE.name()); } + private void initContext(ListBox context) { + for (final short v : AccountDiffPreference.CONTEXT_CHOICES) { + final String label; + if (v == AccountDiffPreference.WHOLE_FILE_CONTEXT) { + label = Util.C.contextWholeFile(); + } else { + label = Util.M.lines(v); + } + context.addItem(label, String.valueOf(v)); + } + } + private Whitespace getIgnoreWhitespace() { final int sel = ignoreWhitespace.getSelectedIndex(); if (0 <= sel) { @@ -257,4 +297,39 @@ public class PatchScriptSettingsPanel extends Composite implements } ignoreWhitespace.setSelectedIndex(0); } + + private short getContext() { + final int sel = context.getSelectedIndex(); + if (0 <= sel) { + return Short.parseShort(context.getValue(sel)); + } + return (short) value.getContext(); + } + + private void setContext(int ctx) { + String v = String.valueOf(ctx); + for (int i = 0; i < context.getItemCount(); i++) { + if (context.getValue(i).equals(v)) { + context.setSelectedIndex(i); + return; + } + } + context.setSelectedIndex(0); + } + + private PatchScriptSettings createPatchScriptSettings(AccountDiffPreference diffPref) { + final PatchScriptSettings s = new PatchScriptSettings(); + if (diffPref != null) { + s.setWhitespace(diffPref.getIgnoreWhitespace()); + s.setContext(diffPref.getContext()); + final PrettySettings p = s.getPrettySettings(); + p.setTabSize(diffPref.getTabSize()); + p.setLineLength(diffPref.getLineLength()); + p.setSyntaxHighlighting(diffPref.isSyntaxHighlighting()); + p.setIntralineDifference(diffPref.isIntralineDifference()); + p.setShowWhiteSpaceErrors(diffPref.isShowWhitespaceErrors()); + p.setShowTabs(diffPref.isShowTabs()); + } + return s; + } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.ui.xml index 9d7303dfa1..7bbc8fe3ab 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.ui.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.ui.xml @@ -49,6 +49,7 @@ limitations under the License. .controls .gwt-ListBox { font-size: fontSize; padding: 0; + margin-right: 1em; } .updateButton { @@ -61,13 +62,24 @@ limitations under the License. - + + + + @@ -75,20 +87,13 @@ limitations under the License. + tabIndex='5'>
- - -
- @@ -131,28 +136,27 @@ limitations under the License. - + + + + - - +
- - Ignore Whitespace: - + + Ignore Whitespace: + + + Tab Width: +
- Tab Width: - - - Context: + + + Columns: + tabIndex='4'/>
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java index d3a9059c2e..45213487da 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java @@ -158,6 +158,10 @@ public class HostPageServlet extends HttpServlet { w.write(HPD_ID + ".account="); json(((IdentifiedUser) user).getAccount(), w); w.write(";"); + w.write(HPD_ID + ".accountDiffPref="); + json(((IdentifiedUser) user).getAccountDiffPreference(), w); + w.write(";"); + final byte[] userData = w.toString().getBytes("UTF-8"); raw = concat(page.part1, userData, page.part2); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java index 9c1f530a64..aa2e95b4c4 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java @@ -20,6 +20,7 @@ import com.google.gerrit.common.data.AgreementInfo; import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountGeneralPreferences; import com.google.gerrit.reviewdb.AccountProjectWatch; import com.google.gerrit.reviewdb.Project; @@ -64,6 +65,16 @@ class AccountServiceImpl extends BaseServiceImplementation implements callback.onSuccess(currentUser.get().getAccount()); } + @Override + public void myDiffPreferences(AsyncCallback callback) { + run(callback, new Action() { + @Override + public AccountDiffPreference run(ReviewDb db) throws OrmException { + return currentUser.get().getAccountDiffPreference(); + } + }); + } + public void changePreferences(final AccountGeneralPreferences pref, final AsyncCallback callback) { run(callback, new Action() { @@ -80,6 +91,23 @@ class AccountServiceImpl extends BaseServiceImplementation implements }); } + @Override + public void changeDiffPreferences(final AccountDiffPreference diffPref, + AsyncCallback callback) { + run(callback, new Action(){ + public VoidResult run(ReviewDb db) throws OrmException { + Account.Id accountId = getAccountId(); + if (!diffPref.getAccountId().equals(getAccountId())) { + throw new IllegalArgumentException("diffPref.getAccountId() " + + diffPref.getAccountId() + " doesn't match" + + " the accountId of the signed in user " + getAccountId()); + } + db.accountDiffPreferences().upsert(Collections.singleton(diffPref)); + return VoidResult.INSTANCE; + } + }); + } + public void myProjectWatch( final AsyncCallback> callback) { run(callback, new Action>() { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java index bca7599970..a8176bdfe2 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java @@ -18,13 +18,13 @@ import com.google.gerrit.common.data.CommentDetail; import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScriptSettings; import com.google.gerrit.common.data.PatchScript.DisplayMethod; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.prettify.common.EditList; import com.google.gerrit.prettify.common.SparseFileContent; -import com.google.gerrit.reviewdb.AccountGeneralPreferences; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.Patch; import com.google.gerrit.reviewdb.PatchLineComment; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import com.google.gerrit.reviewdb.Patch.PatchType; import com.google.gerrit.server.FileTypeRegistry; import com.google.gerrit.server.patch.PatchListEntry; @@ -96,7 +96,7 @@ class PatchScriptBuilder { settings = s; context = settings.getContext(); - if (context == AccountGeneralPreferences.WHOLE_FILE_CONTEXT) { + if (context == AccountDiffPreference.WHOLE_FILE_CONTEXT) { context = MAX_CONTEXT; } else if (context > MAX_CONTEXT) { context = MAX_CONTEXT; diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java index bfc207431d..969dcc9e33 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptFactory.java @@ -17,7 +17,6 @@ package com.google.gerrit.httpd.rpc.patch; import com.google.gerrit.common.data.CommentDetail; import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScriptSettings; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.httpd.rpc.Handler; import com.google.gerrit.reviewdb.Account; import com.google.gerrit.reviewdb.Change; @@ -26,6 +25,7 @@ import com.google.gerrit.reviewdb.PatchLineComment; import com.google.gerrit.reviewdb.PatchSet; import com.google.gerrit.reviewdb.Project; import com.google.gerrit.reviewdb.ReviewDb; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import com.google.gerrit.reviewdb.Patch.ChangeType; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/Account.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/Account.java index bc5495f8a0..f428a22790 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/Account.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/Account.java @@ -52,6 +52,10 @@ import java.sql.Timestamp; *
  • {@link StarredChange}: user has starred the change, tracking * notifications of updates on that change, or just book-marking it for faster * future reference. One record per starred change.
  • + * + *
  • {@link AccountDiffPreference}: user's preferences for rendering side-to-side + * and unified diff
  • + * * */ public final class Account { diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreference.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreference.java new file mode 100644 index 0000000000..426eb375de --- /dev/null +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreference.java @@ -0,0 +1,175 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.reviewdb; + +import com.google.gwtorm.client.Column; + +/** Diff formatting preferences of an account */ +public class AccountDiffPreference { + + /** Default number of lines of context. */ + public static final short DEFAULT_CONTEXT = 10; + + /** Context setting to display the entire file. */ + public static final short WHOLE_FILE_CONTEXT = -1; + + /** Typical valid choices for the default context setting. */ + public static final short[] CONTEXT_CHOICES = + {3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT}; + + public static enum Whitespace implements CodedEnum { + IGNORE_NONE('N'), // + IGNORE_SPACE_AT_EOL('E'), // + IGNORE_SPACE_CHANGE('S'), // + IGNORE_ALL_SPACE('A'); + + private final char code; + + private Whitespace(final char c) { + code = c; + } + + public char getCode() { + return code; + } + + public static Whitespace forCode(final char c) { + for (final Whitespace s : Whitespace.values()) { + if (s.code == c) { + return s; + } + } + return null; + } + } + + public static AccountDiffPreference createDefault(Account.Id accountId) { + AccountDiffPreference p = new AccountDiffPreference(accountId); + p.setIgnoreWhitespace(Whitespace.IGNORE_NONE); + p.setTabSize(8); + p.setLineLength(100); + p.setSyntaxHighlighting(true); + p.setShowWhitespaceErrors(true); + p.setIntralineDifference(true); + p.setShowTabs(true); + p.setContext(DEFAULT_CONTEXT); + return p; + } + + @Column(id = 1, name = Column.NONE) + protected Account.Id accountId; + + @Column(id = 2) + protected char ignoreWhitespace; + + @Column(id = 3) + protected int tabSize; + + @Column(id = 4) + protected int lineLength; + + @Column(id = 5) + protected boolean syntaxHighlighting; + + @Column(id = 6) + protected boolean showWhitespaceErrors; + + @Column(id = 7) + protected boolean intralineDifference; + + @Column(id = 8) + protected boolean showTabs; + + /** Number of lines of context when viewing a patch. */ + @Column(id = 9) + protected short context; + + protected AccountDiffPreference() { + } + + public AccountDiffPreference(Account.Id accountId) { + this.accountId = accountId; + } + + public Account.Id getAccountId() { + return accountId; + } + + public Whitespace getIgnoreWhitespace() { + return Whitespace.forCode(ignoreWhitespace); + } + + public void setIgnoreWhitespace(Whitespace ignoreWhitespace) { + this.ignoreWhitespace = ignoreWhitespace.getCode(); + } + + public int getTabSize() { + return tabSize; + } + + public void setTabSize(int tabSize) { + this.tabSize = tabSize; + } + + public int getLineLength() { + return lineLength; + } + + public void setLineLength(int lineLength) { + this.lineLength = lineLength; + } + + public boolean isSyntaxHighlighting() { + return syntaxHighlighting; + } + + public void setSyntaxHighlighting(boolean syntaxHighlighting) { + this.syntaxHighlighting = syntaxHighlighting; + } + + public boolean isShowWhitespaceErrors() { + return showWhitespaceErrors; + } + + public void setShowWhitespaceErrors(boolean showWhitespaceErrors) { + this.showWhitespaceErrors = showWhitespaceErrors; + } + + public boolean isIntralineDifference() { + return intralineDifference; + } + + public void setIntralineDifference(boolean intralineDifference) { + this.intralineDifference = intralineDifference; + } + + public boolean isShowTabs() { + return showTabs; + } + + public void setShowTabs(boolean showTabs) { + this.showTabs = showTabs; + } + + /** Get the number of lines of context when viewing a patch. */ + public short getContext() { + return context; + } + + /** Set the number of lines of context when viewing a patch. */ + public void setContext(final short s) { + context = s; + } +} diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreferenceAccess.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreferenceAccess.java new file mode 100644 index 0000000000..d1d134bc10 --- /dev/null +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountDiffPreferenceAccess.java @@ -0,0 +1,26 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.reviewdb; + +import com.google.gwtorm.client.Access; +import com.google.gwtorm.client.OrmException; +import com.google.gwtorm.client.PrimaryKey; + +public interface AccountDiffPreferenceAccess extends Access { + + @PrimaryKey("accountId") + AccountDiffPreference get(Account.Id key) throws OrmException; + +} diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountGeneralPreferences.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountGeneralPreferences.java index 0153e41b1a..9b607b0e98 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountGeneralPreferences.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/AccountGeneralPreferences.java @@ -18,15 +18,6 @@ import com.google.gwtorm.client.Column; /** Preferences about a single user. */ public final class AccountGeneralPreferences { - /** Default number of lines of context. */ - public static final short DEFAULT_CONTEXT = 10; - - /** Context setting to display the entire file. */ - public static final short WHOLE_FILE_CONTEXT = -1; - - /** Typical valid choices for the default context setting. */ - public static final short[] CONTEXT_CHOICES = - {3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT}; /** Default number of items to display per page. */ public static final short DEFAULT_PAGESIZE = 25; @@ -44,10 +35,6 @@ public final class AccountGeneralPreferences { REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH; } - /** Default number of lines of context when viewing a patch. */ - @Column(id = 1) - protected short defaultContext; - /** Number of changes to show in a screen. */ @Column(id = 2) protected short maximumPageSize; @@ -75,16 +62,6 @@ public final class AccountGeneralPreferences { public AccountGeneralPreferences() { } - /** Get the default number of lines of context when viewing a patch. */ - public short getDefaultContext() { - return defaultContext; - } - - /** Set the number of lines of context when viewing a patch. */ - public void setDefaultContext(final short s) { - defaultContext = s; - } - public short getMaximumPageSize() { return maximumPageSize; } @@ -148,7 +125,6 @@ public final class AccountGeneralPreferences { } public void resetToDefaults() { - defaultContext = DEFAULT_CONTEXT; maximumPageSize = DEFAULT_PAGESIZE; showSiteHeader = true; useFlashClipboard = true; diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/ReviewDb.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/ReviewDb.java index c592cb1360..f9b3cfae1e 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/ReviewDb.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/ReviewDb.java @@ -75,6 +75,9 @@ public interface ReviewDb extends Schema { @Relation AccountGroupAgreementAccess accountGroupAgreements(); + @Relation + AccountDiffPreferenceAccess accountDiffPreferences(); + @Relation StarredChangeAccess starredChanges(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java b/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java index 60d6d81331..58b872ebbd 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java @@ -15,6 +15,7 @@ package com.google.gerrit.server; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountGroup; import com.google.gerrit.reviewdb.AccountProjectWatch; import com.google.gerrit.reviewdb.Change; @@ -178,6 +179,20 @@ public class IdentifiedUser extends CurrentUser { return state().getAccount(); } + public AccountDiffPreference getAccountDiffPreference() { + AccountDiffPreference diffPref; + try { + diffPref = dbProvider.get().accountDiffPreferences().get(getAccountId()); + if (diffPref == null) { + diffPref = AccountDiffPreference.createDefault(getAccountId()); + } + } catch (OrmException e) { + log.warn("Cannot query account diff preferences", e); + diffPref = AccountDiffPreference.createDefault(getAccountId()); + } + return diffPref; + } + public Set getEmailAddresses() { if (emailAddresses == null) { emailAddresses = state().getEmailAddresses(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCache.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCache.java index 209d0b74d4..1a6d2ae1ed 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCache.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCache.java @@ -14,9 +14,9 @@ package com.google.gerrit.server.patch; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.PatchSet; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; /** Provides a cached list of {@link PatchListEntry}. */ public interface PatchListCache { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java index 835db514b6..cd089d600e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java @@ -14,12 +14,11 @@ package com.google.gerrit.server.patch; -import static com.google.gerrit.common.data.PatchScriptSettings.Whitespace.IGNORE_NONE; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.PatchSet; import com.google.gerrit.reviewdb.Project; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import com.google.gerrit.server.cache.Cache; import com.google.gerrit.server.cache.CacheModule; import com.google.gerrit.server.cache.EvictionPolicy; @@ -116,7 +115,7 @@ public class PatchListCacheImpl implements PatchListCache { } public PatchList get(final Change change, final PatchSet patchSet) { - return get(change, patchSet, IGNORE_NONE); + return get(change, patchSet, Whitespace.IGNORE_NONE); } public PatchList get(final Change change, final PatchSet patchSet, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java index 35dd5710c3..26ee17bdac 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java @@ -21,8 +21,8 @@ import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull; -import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.reviewdb.Project; +import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.ObjectId; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java index abab0b9a2d..96c8df0a74 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java @@ -32,7 +32,7 @@ import java.util.List; /** A version of the database schema. */ public abstract class SchemaVersion { /** The current schema version. */ - private static final Class C = Schema_37.class; + private static final Class C = Schema_38.class; public static class Module extends AbstractModule { @Override diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_38.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_38.java new file mode 100644 index 0000000000..59d6fa24ea --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_38.java @@ -0,0 +1,67 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.schema; + +import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; +import com.google.gerrit.reviewdb.ReviewDb; +import com.google.gwtorm.client.OrmException; +import com.google.gwtorm.jdbc.JdbcSchema; +import com.google.inject.Inject; +import com.google.inject.Provider; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +public class Schema_38 extends SchemaVersion { + @Inject + Schema_38(Provider prior) { + super(prior); + } + + /** + * Migrate the account.default_context column to account_diff_preferences.context column. + *

    + * Other fields in account_diff_preferences will be filled in with their defaults as + * defined in the {@link AccountDiffPreference#createDefault(com.google.gerrit.reviewdb.Account.Id)} + */ + @Override + protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, + SQLException { + List newPrefs = + new ArrayList(); + + Statement stmt = ((JdbcSchema) db).getConnection().createStatement(); + try { + ResultSet result = + stmt.executeQuery("SELECT account_id, default_context" + + " FROM accounts WHERE default_context <> 10"); + while (result.next()) { + int accountId = result.getInt(1); + short defaultContext = result.getShort(2); + AccountDiffPreference diffPref = AccountDiffPreference.createDefault(new Account.Id(accountId)); + diffPref.setContext(defaultContext); + newPrefs.add(diffPref); + } + } finally { + stmt.close(); + } + + db.accountDiffPreferences().insert(newPrefs); + } +}