mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
vcs: Refactoring - inlined "ValueConsumer" logic to "GenericDetailsLoader"
This commit is contained in:
@@ -23,8 +23,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GenericDetailsLoader<Id, Data> implements Details<Id, Data> {
|
||||
private final Consumer<Id> myLoader;
|
||||
private final ValueConsumer<Id, Data> myValueConsumer;
|
||||
private final PairConsumer<Id, Data> myValueConsumer;
|
||||
private Id myCurrentlySelected;
|
||||
private Id mySetId;
|
||||
|
||||
/**
|
||||
* @param loader - is called in AWT. Should call {@link #take} with data when ready. Also in AWT
|
||||
@@ -32,15 +33,14 @@ public class GenericDetailsLoader<Id, Data> implements Details<Id, Data> {
|
||||
*/
|
||||
public GenericDetailsLoader(Consumer<Id> loader, PairConsumer<Id, Data> valueConsumer) {
|
||||
myLoader = loader;
|
||||
myValueConsumer = new ValueConsumer<>(valueConsumer);
|
||||
myValueConsumer = valueConsumer;
|
||||
}
|
||||
|
||||
@CalledInAwt
|
||||
public void updateSelection(@Nullable Id id, boolean force) {
|
||||
myValueConsumer.setId(id);
|
||||
|
||||
Id previousId = myCurrentlySelected;
|
||||
myCurrentlySelected = id;
|
||||
mySetId = null;
|
||||
if (force || !Comparing.equal(id, previousId)) {
|
||||
myLoader.consume(id);
|
||||
}
|
||||
@@ -49,7 +49,10 @@ public class GenericDetailsLoader<Id, Data> implements Details<Id, Data> {
|
||||
@CalledInAwt
|
||||
@Override
|
||||
public void take(Id id, Data data) {
|
||||
myValueConsumer.consume(id, data);
|
||||
if (!id.equals(mySetId) && id.equals(myCurrentlySelected)) {
|
||||
mySetId = id;
|
||||
myValueConsumer.consume(id, data);
|
||||
}
|
||||
}
|
||||
|
||||
@CalledInAwt
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.openapi.vcs;
|
||||
|
||||
import com.intellij.util.PairConsumer;
|
||||
|
||||
public class ValueConsumer<Id, Data> {
|
||||
private Id myId;
|
||||
private Id mySetId;
|
||||
private final PairConsumer<Id, Data> myConsumer;
|
||||
|
||||
protected ValueConsumer(PairConsumer<Id, Data> consumer) {
|
||||
myConsumer = consumer;
|
||||
}
|
||||
|
||||
public void consume(Id id, Data data) {
|
||||
if (!id.equals(mySetId) && id.equals(myId)) {
|
||||
mySetId = id;
|
||||
myConsumer.consume(id, data);
|
||||
}
|
||||
}
|
||||
|
||||
public void setId(Id id) {
|
||||
myId = id;
|
||||
mySetId = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user