mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: extract base class for DiffRequestChain
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* 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.intellij.diff.chains;
|
||||
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
|
||||
public abstract class DiffRequestChainBase extends UserDataHolderBase implements DiffRequestChain {
|
||||
private int myIndex;
|
||||
|
||||
public DiffRequestChainBase() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DiffRequestChainBase(int index) {
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
assert index >= 0 && index < getRequests().size();
|
||||
myIndex = index;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,9 +26,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleDiffRequestChain extends UserDataHolderBase implements DiffRequestChain {
|
||||
public class SimpleDiffRequestChain extends DiffRequestChainBase {
|
||||
@NotNull private final List<DiffRequestProducerWrapper> myRequests;
|
||||
private int myIndex = 0;
|
||||
|
||||
public SimpleDiffRequestChain(@NotNull DiffRequest request) {
|
||||
this(Collections.singletonList(request));
|
||||
@@ -45,17 +43,6 @@ public class SimpleDiffRequestChain extends UserDataHolderBase implements DiffRe
|
||||
return myRequests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
assert index >= 0 && index < myRequests.size();
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
public static class DiffRequestProducerWrapper implements DiffRequestProducer {
|
||||
@NotNull private final DiffRequest myRequest;
|
||||
|
||||
|
||||
+4
-17
@@ -18,7 +18,7 @@ package com.intellij.openapi.vcs.changes.patch;
|
||||
import com.intellij.diff.DiffDialogHints;
|
||||
import com.intellij.diff.DiffManager;
|
||||
import com.intellij.diff.actions.impl.GoToChangePopupBuilder;
|
||||
import com.intellij.diff.chains.DiffRequestChain;
|
||||
import com.intellij.diff.chains.DiffRequestChainBase;
|
||||
import com.intellij.diff.chains.DiffRequestProducer;
|
||||
import com.intellij.diff.chains.DiffRequestProducerException;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
@@ -1184,17 +1184,15 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
};
|
||||
}
|
||||
|
||||
private static class MyDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain {
|
||||
private static class MyDiffRequestChain extends DiffRequestChainBase implements GoToChangePopupBuilder.Chain {
|
||||
private final List<DiffRequestProducer> myRequests;
|
||||
private final List<? extends Change> myChanges;
|
||||
private int myIndex;
|
||||
|
||||
public MyDiffRequestChain(@NotNull List<DiffRequestProducer> requests, @NotNull List<? extends Change> changes, int index) {
|
||||
super(index);
|
||||
assert requests.size() == changes.size();
|
||||
myRequests = requests;
|
||||
myChanges = changes;
|
||||
|
||||
myIndex = index >= 0 ? index : 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1203,21 +1201,10 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
return myRequests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
assert index >= 0 && index < myRequests.size();
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction createGoToChangeAction(@NotNull Consumer<Integer> onSelected) {
|
||||
return new ChangeGoToChangePopupAction<MyDiffRequestChain>(this, myIndex) {
|
||||
return new ChangeGoToChangePopupAction<MyDiffRequestChain>(this, getIndex()) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected DefaultTreeModel buildTreeModel(@NotNull Project project, boolean showFlatten) {
|
||||
|
||||
+4
-17
@@ -16,11 +16,10 @@
|
||||
package com.intellij.openapi.vcs.changes.ui;
|
||||
|
||||
import com.intellij.diff.actions.impl.GoToChangePopupBuilder;
|
||||
import com.intellij.diff.chains.DiffRequestChain;
|
||||
import com.intellij.diff.chains.DiffRequestChainBase;
|
||||
import com.intellij.diff.chains.DiffRequestProducer;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction;
|
||||
@@ -32,13 +31,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain {
|
||||
public class ChangeDiffRequestChain extends DiffRequestChainBase implements GoToChangePopupBuilder.Chain {
|
||||
@NotNull private final List<? extends Producer> myProducers;
|
||||
private int myIndex;
|
||||
|
||||
public ChangeDiffRequestChain(@NotNull List<? extends Producer> producers, int index) {
|
||||
super(index);
|
||||
myProducers = producers;
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,21 +45,10 @@ public class ChangeDiffRequestChain extends UserDataHolderBase implements DiffRe
|
||||
return myProducers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
assert index >= 0 && index < myProducers.size();
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction createGoToChangeAction(@NotNull Consumer<Integer> onSelected) {
|
||||
return new ChangeGoToChangePopupAction<ChangeDiffRequestChain>(this, myIndex) {
|
||||
return new ChangeGoToChangePopupAction<ChangeDiffRequestChain>(this, getIndex()) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected DefaultTreeModel buildTreeModel(@NotNull Project project, boolean showFlatten) {
|
||||
|
||||
Reference in New Issue
Block a user