mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
decouple ComponentManagerImpl from ProgressManager; move to core-impl
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.progress;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class ProgressIndicatorProvider {
|
||||
@Nullable
|
||||
public static ProgressIndicatorProvider ourInstance;
|
||||
|
||||
@Nullable
|
||||
public static ProgressIndicatorProvider getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
public abstract ProgressIndicator getProgressIndicator();
|
||||
|
||||
protected abstract void doCheckCanceled() throws ProcessCanceledException;
|
||||
|
||||
public static boolean ourNeedToCheckCancel = false;
|
||||
public static void checkCanceled() throws ProcessCanceledException {
|
||||
// smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds
|
||||
if (ourNeedToCheckCancel && ourInstance != null) {
|
||||
ourInstance.doCheckCanceled();
|
||||
ourNeedToCheckCancel = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-21
@@ -23,7 +23,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
@@ -68,7 +68,6 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
private final ComponentManager myParentComponentManager;
|
||||
private Boolean myHeadless;
|
||||
private ComponentsRegistry myComponentsRegistry = new ComponentsRegistry();
|
||||
private boolean myHaveProgressManager = false;
|
||||
private final Condition myDisposedCondition = new Condition() {
|
||||
public boolean value(final Object o) {
|
||||
return isDisposed();
|
||||
@@ -101,9 +100,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
|
||||
final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces();
|
||||
for (Class componentInterface : componentInterfaces) {
|
||||
if (myHaveProgressManager) {
|
||||
ProgressManager.checkCanceled();
|
||||
}
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
try {
|
||||
createComponent(componentInterface);
|
||||
}
|
||||
@@ -204,20 +201,15 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
}
|
||||
|
||||
private void initComponent(Object component) {
|
||||
if (myHaveProgressManager) {
|
||||
final ProgressManager progressManager = ProgressManager.getInstance();
|
||||
final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance();
|
||||
|
||||
final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null;
|
||||
if (indicator != null) {
|
||||
String name = getComponentName(component);
|
||||
indicator.checkCanceled();
|
||||
indicator.setText2(name);
|
||||
indicator.setIndeterminate(false);
|
||||
indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded());
|
||||
}
|
||||
}
|
||||
if (component instanceof ProgressManager) {
|
||||
myHaveProgressManager = true;
|
||||
final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null;
|
||||
if (indicator != null) {
|
||||
String name = getComponentName(component);
|
||||
indicator.checkCanceled();
|
||||
indicator.setText2(name);
|
||||
indicator.setIndeterminate(false);
|
||||
indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded());
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -290,9 +282,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
Class[] componentClasses = myComponentsRegistry.getComponentInterfaces();
|
||||
ArrayList<Object> components = new ArrayList<Object>(componentClasses.length);
|
||||
for (Class<?> interfaceClass : componentClasses) {
|
||||
if (myHaveProgressManager) {
|
||||
ProgressManager.checkCanceled();
|
||||
}
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
Object component = getComponent(interfaceClass);
|
||||
if (component != null) components.add(component);
|
||||
}
|
||||
@@ -26,6 +26,20 @@ import javax.swing.*;
|
||||
public abstract class ProgressManager {
|
||||
private static final ProgressManager ourInstance = ServiceManager.getService(ProgressManager.class);
|
||||
|
||||
static {
|
||||
ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() {
|
||||
@Override
|
||||
public ProgressIndicator getProgressIndicator() {
|
||||
return ProgressManager.ourInstance.getProgressIndicator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doCheckCanceled() throws ProcessCanceledException {
|
||||
ProgressManager.ourInstance.doCheckCanceled();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ProgressManager getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
catch (InterruptedException ignored) {
|
||||
}
|
||||
ourNeedToCheckCancel = true;
|
||||
ProgressIndicatorProvider.ourNeedToCheckCancel = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -86,6 +87,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
if (ourLockedCheckCounter > 10) {
|
||||
ourLockedCheckCounter = 0;
|
||||
ourNeedToCheckCancel = true;
|
||||
ProgressIndicatorProvider.ourNeedToCheckCancel = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -98,6 +100,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
|
||||
public static void canceled() {
|
||||
ourNeedToCheckCancel = true;
|
||||
ProgressIndicatorProvider.ourNeedToCheckCancel = true;
|
||||
}
|
||||
|
||||
private static class NonCancelableIndicator extends EmptyProgressIndicator implements NonCancelableSection {
|
||||
@@ -458,6 +461,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
|
||||
@TestOnly
|
||||
public static void setNeedToCheckCancel(boolean needToCheckCancel) {
|
||||
ourNeedToCheckCancel = needToCheckCancel;
|
||||
ProgressIndicatorProvider.ourNeedToCheckCancel = true;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
|
||||
Reference in New Issue
Block a user