mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
integrate https://android-review.googlesource.com/#/c/145848/: add API allowing one RunConfigurationProducer to replace another one
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -92,6 +92,16 @@ public abstract class ConfigurationFromContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this configuration should replace another one, that is if the other should be discarded.
|
||||
*
|
||||
* @see RunConfigurationProducer#shouldReplace(ConfigurationFromContext, ConfigurationFromContext)
|
||||
* @return true if the other configuration should be discarded, false otherwise.
|
||||
*/
|
||||
public boolean shouldReplace(ConfigurationFromContext other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this configuration was created by the specified producer.
|
||||
*
|
||||
@@ -117,9 +127,15 @@ public abstract class ConfigurationFromContext {
|
||||
if (!configuration1.isPreferredTo(configuration2)) {
|
||||
return 1;
|
||||
}
|
||||
if (configuration2.shouldReplace(configuration1)) {
|
||||
return 1;
|
||||
}
|
||||
if (!configuration2.isPreferredTo(configuration1)) {
|
||||
return -1;
|
||||
}
|
||||
if (configuration1.shouldReplace(configuration2)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -55,6 +55,11 @@ public class ConfigurationFromContextImpl extends ConfigurationFromContext {
|
||||
return myConfigurationProducer.isPreferredConfiguration(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldReplace(ConfigurationFromContext other) {
|
||||
return myConfigurationProducer.shouldReplace(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProducedBy(Class<? extends RunConfigurationProducer> producerClass) {
|
||||
return producerClass.isInstance(myConfigurationProducer);
|
||||
|
||||
@@ -119,11 +119,28 @@ public abstract class RunConfigurationProducer<T extends RunConfiguration> {
|
||||
* @param other a configuration created by another producer.
|
||||
* @return true if the configuration created by this producer is at least as good as the other one; false if this configuration
|
||||
* should be discarded and the other one should be used instead.
|
||||
* @see #shouldReplace(ConfigurationFromContext, ConfigurationFromContext)
|
||||
*/
|
||||
public boolean isPreferredConfiguration(ConfigurationFromContext self, ConfigurationFromContext other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* When two configurations are created from the same context by two different producers, checks if the configuration created by
|
||||
* this producer should replace the other one, that is if the other one should be discarded.
|
||||
*
|
||||
* <p>This is the same relationship as {@link #isPreferredConfiguration(ConfigurationFromContext, ConfigurationFromContext)} but
|
||||
* specified from the "replacement" side.
|
||||
*
|
||||
* @param self a configuration created by this producer.
|
||||
* @param other a configuration created by another producer.
|
||||
* @return true if the other configuration should be discarded, false otherwise.
|
||||
* @see #isPreferredConfiguration(ConfigurationFromContext, ConfigurationFromContext)
|
||||
*/
|
||||
public boolean shouldReplace(ConfigurationFromContext self, ConfigurationFromContext other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before a configuration created from context by this producer is first executed. Can be used to show additional UI for
|
||||
* customizing the created configuration.
|
||||
|
||||
+7
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -61,4 +61,10 @@ public class ConfigurationFromContextWrapper extends ConfigurationFromContext {
|
||||
return other instanceof ConfigurationFromContextWrapper &&
|
||||
myProducer.compareTo(((ConfigurationFromContextWrapper) other).myProducer) < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldReplace(ConfigurationFromContext other) {
|
||||
return other instanceof ConfigurationFromContextWrapper &&
|
||||
myProducer.compareTo(((ConfigurationFromContextWrapper) other).myProducer) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user