svn: Refactored "QuickMergeInteractionImpl" - code simplified
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Sun, 25 Sep 2016 21:15:01 +0000 (00:15 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Tue, 11 Oct 2016 01:28:23 +0000 (04:28 +0300)
Updated corresponding "QuickMergeInteraction" interface methods

plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CopiesPanel.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/LocalChangesAction.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/MergeAllWithBranchCopyPointTask.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/QuickMerge.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/QuickMergeInteraction.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/QuickMergeInteractionImpl.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ShowRecentInDialogTask.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/QuickMergeTestInteraction.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnQuickMergeTest.java

index e53136fe2c852446e1cf34af8a8b324350ef7828..d40e91cd1c901367a92d68fafc00fdceeec48989 100644 (file)
@@ -369,7 +369,7 @@ public class CopiesPanel {
         String workingCopyUrlInSelectedBranch = getCorrespondingUrlInOtherBranch(configuration, wcInfo.getUrl(), branchUrl);
         MergeContext mergeContext = new MergeContext(myVcs, workingCopyUrlInSelectedBranch, wcInfo, SVNPathUtil.tail(branchUrl), root);
 
-        new QuickMerge(mergeContext).execute(new QuickMergeInteractionImpl(myProject));
+        new QuickMerge(mergeContext).execute(new QuickMergeInteractionImpl(mergeContext));
       }
     }, "Select branch", mergeLabel);
   }
index 4dfe3fabc4a07e343aa9349318976c6ad1749b8a..f41ccd572e3130d543bce72e07e6a9bf9735500a 100644 (file)
  */
 package org.jetbrains.idea.svn.integrate;
 
-/**
-* Created with IntelliJ IDEA.
-* User: Irina.Chernushina
-* Date: 3/27/13
-* Time: 12:37 PM
-*/
+import org.jetbrains.annotations.NotNull;
+
 public enum LocalChangesAction {
-  cancel,
-  continueMerge,
-  shelve,
-  inspect
+  cancel("Cancel"),
+  continueMerge("Continue merge"),
+  shelve("Shelve local changes"),
+  inspect("Inspect changes");
+
+  @NotNull private final String myTitle;
+
+  LocalChangesAction(@NotNull String title) {
+    myTitle = title;
+  }
+
+  @Override
+  public String toString() {
+    return myTitle;
+  }
 }
index 9536f38262ce2680def0b925ce783a157b187082..5951998131df8a180d3724c7ce856756131ba4ed 100644 (file)
@@ -80,7 +80,7 @@ public class MergeAllWithBranchCopyPointTask extends BaseMergeTask
   private void runMerge(@NotNull ContinuationContext context, @NotNull SvnBranchPointsCalculator.WrapperInvertor inverter) {
     boolean reintegrate = inverter.isInvertedSense();
 
-    if (reintegrate && !myInteraction.shouldReintegrate(myMergeContext.getSourceUrl(), inverter.inverted().getTarget())) {
+    if (reintegrate && !myInteraction.shouldReintegrate(inverter.inverted().getTarget())) {
       context.cancelEverything();
     }
     else {
index 717bcd548af03f87c310f6315f2f5f00acff3ced..462683f78e8f5955d380e4d3d245822dbf2c1279 100644 (file)
@@ -45,7 +45,6 @@ public class QuickMerge {
   @CalledInAwt
   public void execute(@NotNull final QuickMergeInteraction interaction, @NotNull final TaskDescriptor... finalTasks) {
     myInteraction = interaction;
-    myInteraction.setTitle(myMergeContext.getTitle());
 
     FileDocumentManager.getInstance().saveAllDocuments();
 
index abf196bf61e18bfa97dd14092d3872e29790f9d2..d6c885994f6e6b3e7972005900494edf174415f0 100644 (file)
@@ -26,14 +26,13 @@ import org.jetbrains.idea.svn.mergeinfo.MergeChecker;
 import java.util.List;
 
 public interface QuickMergeInteraction {
-  void setTitle(@NotNull String title);
 
   @NotNull
   QuickMergeContentsVariants selectMergeVariant();
 
   boolean shouldContinueSwitchedRootFound();
 
-  boolean shouldReintegrate(@NotNull String sourceUrl, @NotNull String targetUrl);
+  boolean shouldReintegrate(@NotNull String targetUrl);
 
   @NotNull
   SelectMergeItemsResult selectMergeItems(@NotNull List<CommittedChangeList> lists,
@@ -51,7 +50,6 @@ public interface QuickMergeInteraction {
 
   @NotNull
   List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list,
-                                                        @NotNull String mergeTitle,
                                                         @NotNull MergeChecker mergeChecker,
                                                         @NotNull PairConsumer<Long, MergeDialogI> loader,
                                                         boolean everyThingLoaded);
index 4ec773794e52618dab9198035917f24ac8ffd41b..ce62a167924fd5a65f6742a9176ffc6f3b110dbd 100644 (file)
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogBuilder;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.MessageType;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.vcs.AbstractVcsHelper;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.VcsException;
@@ -33,35 +32,31 @@ import org.jetbrains.idea.svn.mergeinfo.MergeChecker;
 
 import java.util.List;
 
-import static java.util.Collections.emptyList;
+import static com.intellij.openapi.ui.Messages.*;
+import static com.intellij.util.Functions.TO_STRING;
+import static com.intellij.util.containers.ContainerUtil.emptyList;
+import static com.intellij.util.containers.ContainerUtil.map2Array;
+import static org.jetbrains.idea.svn.integrate.LocalChangesAction.*;
 
-/**
- * Created with IntelliJ IDEA.
- * User: Irina.Chernushina
- * Date: 3/27/13
- * Time: 11:40 AM
- */
 public class QuickMergeInteractionImpl implements QuickMergeInteraction {
-  private final Project myProject;
-  private String myTitle;
 
-  public QuickMergeInteractionImpl(Project project) {
-    myProject = project;
-  }
+  @NotNull private final MergeContext myMergeContext;
+  @NotNull private final Project myProject;
+  @NotNull private final String myTitle;
 
-  @Override
-  public void setTitle(@NotNull String title) {
-    myTitle = title;
+  public QuickMergeInteractionImpl(@NotNull MergeContext mergeContext) {
+    myMergeContext = mergeContext;
+    myProject = mergeContext.getProject();
+    myTitle = mergeContext.getTitle();
   }
 
   @NotNull
   @Override
   public QuickMergeContentsVariants selectMergeVariant() {
-    final QuickMergeWayOptionsPanel panel = new QuickMergeWayOptionsPanel();
-    final DialogBuilder builder = new DialogBuilder(myProject);
-    builder.removeAllActions();
-    builder.setTitle("Select Merge Variant");
-    builder.setCenterPanel(panel.getMainPanel());
+    QuickMergeWayOptionsPanel panel = new QuickMergeWayOptionsPanel();
+    DialogBuilder builder = new DialogBuilder(myProject);
+
+    builder.title("Select Merge Variant").centerPanel(panel.getMainPanel()).removeAllActions();
     panel.setWrapper(builder.getDialogWrapper());
     builder.show();
 
@@ -74,8 +69,9 @@ public class QuickMergeInteractionImpl implements QuickMergeInteraction {
   }
 
   @Override
-  public boolean shouldReintegrate(@NotNull String sourceUrl, @NotNull String targetUrl) {
-    return prompt("<html><body>You are going to reintegrate changes.<br><br>This will make branch '" + sourceUrl +
+  public boolean shouldReintegrate(@NotNull String targetUrl) {
+    return prompt("<html><body>You are going to reintegrate changes.<br><br>This will make branch '" +
+                  myMergeContext.getSourceUrl() +
                   "' <b>no longer usable for further work</b>." +
                   "<br>It will not be able to correctly absorb new trunk (" + targetUrl +
                   ") changes,<br>nor can this branch be properly reintegrated to trunk again.<br><br>Are you sure?</body></html>");
@@ -86,17 +82,21 @@ public class QuickMergeInteractionImpl implements QuickMergeInteraction {
   public SelectMergeItemsResult selectMergeItems(@NotNull List<CommittedChangeList> lists,
                                                  @NotNull String mergeTitle,
                                                  @NotNull MergeChecker mergeChecker) {
-    final ToBeMergedDialog dialog = new ToBeMergedDialog(myProject, lists, mergeTitle, mergeChecker, null);
+    ToBeMergedDialog dialog = new ToBeMergedDialog(myProject, lists, mergeTitle, mergeChecker, null);
     dialog.show();
+
     return new SelectMergeItemsResult() {
       @NotNull
       @Override
       public QuickMergeContentsVariants getResultCode() {
-        final int code = dialog.getExitCode();
-        if (ToBeMergedDialog.MERGE_ALL_CODE == code) {
-          return QuickMergeContentsVariants.all;
+        switch (dialog.getExitCode()) {
+          case ToBeMergedDialog.MERGE_ALL_CODE:
+            return QuickMergeContentsVariants.all;
+          case DialogWrapper.OK_EXIT_CODE:
+            return QuickMergeContentsVariants.select;
+          default:
+            return QuickMergeContentsVariants.cancel;
         }
-        return DialogWrapper.OK_EXIT_CODE == code ? QuickMergeContentsVariants.select : QuickMergeContentsVariants.cancel;
       }
 
       @NotNull
@@ -109,21 +109,20 @@ public class QuickMergeInteractionImpl implements QuickMergeInteraction {
 
   @NotNull
   @Override
-  public LocalChangesAction selectLocalChangesAction(final boolean mergeAll) {
-    if (! mergeAll) {
-      final LocalChangesAction[] possibleResults = {LocalChangesAction.shelve, LocalChangesAction.inspect,
-        LocalChangesAction.continueMerge, LocalChangesAction.cancel};
-      final int result = Messages.showDialog("There are local changes that will intersect with merge changes.\nDo you want to continue?", myTitle,
-                                                 new String[]{"Shelve local changes", "Inspect changes", "Continue merge", "Cancel"},
-                                                  0, Messages.getQuestionIcon());
-      return possibleResults[result];
+  public LocalChangesAction selectLocalChangesAction(boolean mergeAll) {
+    LocalChangesAction[] possibleResults;
+    String message;
+
+    if (!mergeAll) {
+      possibleResults = new LocalChangesAction[]{shelve, inspect, continueMerge, cancel};
+      message = "There are local changes that will intersect with merge changes.\nDo you want to continue?";
     } else {
-      final LocalChangesAction[] possibleResults = {LocalChangesAction.shelve, LocalChangesAction.continueMerge, LocalChangesAction.cancel};
-      final int result = Messages.showDialog("There are local changes that can potentially intersect with merge changes.\nDo you want to continue?", myTitle,
-                                                   new String[]{"Shelve local changes", "Continue merge", "Cancel"},
-                                                    0, Messages.getQuestionIcon());
-      return possibleResults[result];
+      possibleResults = new LocalChangesAction[]{shelve, continueMerge, cancel};
+      message = "There are local changes that can potentially intersect with merge changes.\nDo you want to continue?";
     }
+
+    int result = showDialog(message, myTitle, map2Array(possibleResults, String.class, TO_STRING()), 0, getQuestionIcon());
+    return possibleResults[result];
   }
 
   @Override
@@ -145,22 +144,17 @@ public class QuickMergeInteractionImpl implements QuickMergeInteraction {
   @NotNull
   @Override
   public List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list,
-                                                               @NotNull String mergeTitle,
                                                                @NotNull MergeChecker mergeChecker,
                                                                @NotNull PairConsumer<Long, MergeDialogI> loader,
                                                                boolean everyThingLoaded) {
-    final ToBeMergedDialog dialog = new ToBeMergedDialog(myProject, list, mergeTitle, mergeChecker, loader);
+    ToBeMergedDialog dialog = new ToBeMergedDialog(myProject, list, myMergeContext.getTitle(), mergeChecker, loader);
     if (everyThingLoaded) {
       dialog.setEverythingLoaded(true);
     }
-    dialog.show();
-    if (DialogWrapper.OK_EXIT_CODE == dialog.getExitCode()) {
-      return dialog.getSelected();
-    }
-    return emptyList();
+    return dialog.showAndGet() ? dialog.getSelected() : emptyList();
   }
 
   private boolean prompt(@NotNull String question) {
-    return Messages.showOkCancelDialog(myProject, question, myTitle, Messages.getQuestionIcon()) == Messages.OK;
+    return showOkCancelDialog(myProject, question, myTitle, getQuestionIcon()) == OK;
   }
 }
index 718f7145132c75bce53d12fba0ba518d422bdda5..ddd1be144bb94ac2d8727177e9e8e6bff0d1bb4f 100644 (file)
@@ -49,7 +49,6 @@ public class ShowRecentInDialogTask extends BaseMergeTask {
   @Override
   public void run(ContinuationContext context) {
     List<CommittedChangeList> lists = myInteraction.showRecentListsForSelection(myInitialChangeListsLoader.getCommittedChangeLists(),
-                                                                                myMergeContext.getTitle(),
                                                                                 myInitialChangeListsLoader.getHelper(),
                                                                                 createMoreChangeListsLoader(),
                                                                                 myInitialChangeListsLoader.isLastLoaded());
index 15dd10b9abb31c056841189b543365c1c9d75322..7e9ccf67a9ce382e18f38c8ab10b3cbf10f1d8ad 100644 (file)
@@ -43,10 +43,6 @@ public class QuickMergeTestInteraction implements QuickMergeInteraction {
     myExceptions = newArrayList();
   }
 
-  @Override
-  public void setTitle(@NotNull String title) {
-  }
-
   @NotNull
   @Override
   public QuickMergeContentsVariants selectMergeVariant() {
@@ -63,7 +59,7 @@ public class QuickMergeTestInteraction implements QuickMergeInteraction {
   }
 
   @Override
-  public boolean shouldReintegrate(@NotNull String sourceUrl, @NotNull String targetUrl) {
+  public boolean shouldReintegrate(@NotNull String targetUrl) {
     return myReintegrateAnswer;
   }
 
@@ -90,7 +86,6 @@ public class QuickMergeTestInteraction implements QuickMergeInteraction {
   @NotNull
   @Override
   public List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list,
-                                                               @NotNull String mergeTitle,
                                                                @NotNull MergeChecker mergeChecker,
                                                                @NotNull PairConsumer<Long, MergeDialogI> loader,
                                                                boolean everyThingLoaded) {
index 632a83c95214b01441f081810bbbc6215399fd39..e0aa340e59244ba2b5a7e4fa21fbe3728b3c1116 100644 (file)
@@ -177,7 +177,6 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       @NotNull
       @Override
       public List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list,
-                                                                   @NotNull String mergeTitle,
                                                                    @NotNull MergeChecker mergeChecker,
                                                                    @NotNull PairConsumer<Long, MergeDialogI> loader,
                                                                    boolean everyThingLoaded) {
@@ -265,7 +264,6 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       @NotNull
       @Override
       public List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list,
-                                                                   @NotNull String mergeTitle,
                                                                    @NotNull MergeChecker mergeChecker,
                                                                    @NotNull PairConsumer<Long, MergeDialogI> loader,
                                                                    boolean everyThingLoaded) {