mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Modifiable model merge fixes
This commit is contained in:
@@ -152,13 +152,6 @@ public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootL
|
||||
final ModifiableRootModel model = getModel();
|
||||
final Sdk oldSdk = model.getSdk();
|
||||
|
||||
//final List<OrderEntry> entries = myPanel.getEntries();
|
||||
//for (OrderEntry entry : entries) {
|
||||
// if (entry instanceof JdkOrderEntry) {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
if (newJDK != null) {
|
||||
model.setSdk(newJDK);
|
||||
}
|
||||
|
||||
@@ -331,14 +331,14 @@ public class ClasspathPanel extends JPanel {
|
||||
if (orderEntry == null) {
|
||||
continue;
|
||||
}
|
||||
ModuleStructureConfigurable.getInstance(myState.getProject()).getContext().clearCaches(orderEntry);
|
||||
|
||||
getRootModel().removeOrderEntry(orderEntry);
|
||||
}
|
||||
final int[] selectedRows = myEntryTable.getSelectedRows();
|
||||
myModel.fireTableDataChanged();
|
||||
TableUtil.selectRows(myEntryTable, selectedRows);
|
||||
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
|
||||
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, myRootModel.getModule()));
|
||||
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext();
|
||||
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -500,7 +500,7 @@ public class ClasspathPanel extends JPanel {
|
||||
TableUtil.scrollSelectionToVisible(myEntryTable);
|
||||
|
||||
final StructureConfigurableContext context = rootConfigurable.getContext();
|
||||
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, myRootModel.getModule()));
|
||||
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule()));
|
||||
}
|
||||
finally {
|
||||
if (dialog instanceof ChooseNamedLibraryAction.MyChooserDialog) {
|
||||
|
||||
+7
-13
@@ -106,17 +106,11 @@ public abstract class ModuleJdkConfigurable implements Disposable {
|
||||
myCbModuleJdk.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (myFreeze) return;
|
||||
final Sdk oldJdk = getRootModel().getSdk();
|
||||
mySelectedModuleJdk = myCbModuleJdk.getSelectedJdk();
|
||||
final Sdk selectedModuleJdk = getSelectedModuleJdk();
|
||||
if (selectedModuleJdk != null) {
|
||||
getRootModel().setSdk(selectedModuleJdk);
|
||||
}
|
||||
else {
|
||||
getRootModel().inheritSdk();
|
||||
}
|
||||
clearCaches(oldJdk, selectedModuleJdk);
|
||||
myModuleEditor.flushChangesToModel();
|
||||
|
||||
final Sdk newJdk = myCbModuleJdk.getSelectedJdk();
|
||||
myModuleEditor.setSdk(newJdk);
|
||||
|
||||
clearCaches();
|
||||
}
|
||||
});
|
||||
myJdkPanel.add(new JLabel(ProjectBundle.message("module.libraries.target.jdk.module.radio")),
|
||||
@@ -154,7 +148,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
private void clearCaches(final Sdk oldJdk, final Sdk selectedModuleJdk) {
|
||||
private void clearCaches() {
|
||||
final Module module = getRootModel().getModule();
|
||||
final Project project = module.getProject();
|
||||
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(project).getContext();
|
||||
@@ -170,7 +164,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
|
||||
myCbModuleJdk.setSelectedJdk(mySelectedModuleJdk);
|
||||
} else {
|
||||
myCbModuleJdk.setInvalidJdk(jdkName);
|
||||
clearCaches(null, null);
|
||||
clearCaches();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
|
||||
}
|
||||
}
|
||||
|
||||
myContext.clearCaches(false);
|
||||
myContext.getDaemonAnalyzer().clearCaches();
|
||||
myContext.resetLibraries();
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -341,7 +341,6 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
|
||||
public void disposeUIResources() {
|
||||
super.disposeUIResources();
|
||||
myFacetEditorFacade.clearMaps();
|
||||
myContext.clearCaches(true);
|
||||
myContext.myModulesConfigurator.disposeUIResources();
|
||||
ModuleStructureConfigurable.super.disposeUIResources();
|
||||
}
|
||||
|
||||
+1
-302
@@ -38,21 +38,6 @@ import java.util.Map;
|
||||
|
||||
public class StructureConfigurableContext implements Disposable {
|
||||
private final ProjectStructureDaemonAnalyzer myDaemonAnalyzer;
|
||||
private static final Logger LOG = Logger.getInstance("#" + StructureConfigurableContext.class.getName());
|
||||
|
||||
public enum ValidityLevel { VALID, WARNING, ERROR }
|
||||
|
||||
public static final String NO_JDK = ProjectBundle.message("project.roots.module.jdk.problem.message");
|
||||
public static final String DUPLICATE_MODULE_NAME = ProjectBundle.message("project.roots.module.duplicate.name.message");
|
||||
@NonNls public static final String DELETED_LIBRARIES = "lib";
|
||||
|
||||
public final Map<String, Set<String>> myLibraryDependencyCache = new HashMap<String, Set<String>>();
|
||||
public final Map<Sdk, Set<String>> myJdkDependencyCache = new HashMap<Sdk, Set<String>>();
|
||||
public final Map<Module, Map<String, Set<String>>> myValidityCache = new HashMap<Module, Map<String, Set<String>>>();
|
||||
public final Map<Library, ValidityLevel> myLibraryPathValidityCache = new HashMap<Library, ValidityLevel>(); //can be invalidated on startup only
|
||||
public final Map<Module, Set<String>> myModulesDependencyCache = new HashMap<Module, Set<String>>();
|
||||
|
||||
private final ModuleManager myModuleManager;
|
||||
public final ModulesConfigurator myModulesConfigurator;
|
||||
public final Map<String, LibrariesModifiableModel> myLevel2Providers = new THashMap<String, LibrariesModifiableModel>();
|
||||
private final Project myProject;
|
||||
@@ -73,299 +58,13 @@ public class StructureConfigurableContext implements Disposable {
|
||||
return myDaemonAnalyzer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<String> getCachedDependencies(final Object selectedObject, boolean force) {
|
||||
if (selectedObject instanceof Library){
|
||||
final Library library = (Library)selectedObject;
|
||||
if (myLibraryDependencyCache.containsKey(library.getName())){
|
||||
return myLibraryDependencyCache.get(library.getName());
|
||||
}
|
||||
} else if (selectedObject instanceof Sdk){
|
||||
final Sdk projectJdk = (Sdk)selectedObject;
|
||||
if (myJdkDependencyCache.containsKey(projectJdk)){
|
||||
return myJdkDependencyCache.get(projectJdk);
|
||||
}
|
||||
} else if (selectedObject instanceof Module) {
|
||||
final Module module = (Module)selectedObject;
|
||||
if (myModulesDependencyCache.containsKey(module)) {
|
||||
return myModulesDependencyCache.get(module);
|
||||
}
|
||||
}
|
||||
if (force){
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
|
||||
final Set<String> dep = getDependencies(selectedObject);
|
||||
updateCache(selectedObject, dep);
|
||||
return dep;
|
||||
} else {
|
||||
myUpdateDependenciesAlarm.addRequest(new Runnable(){
|
||||
public void run() {
|
||||
final Set<String> dep = getDependencies(selectedObject);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (!myDisposed) {
|
||||
updateCache(selectedObject, dep);
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCache(final Object selectedObject, final Set<String> dep) {
|
||||
if (selectedObject instanceof Library) {
|
||||
myLibraryDependencyCache.put(((Library)selectedObject).getName(), dep);
|
||||
}
|
||||
else if (selectedObject instanceof Sdk) {
|
||||
myJdkDependencyCache.put((Sdk)selectedObject, dep);
|
||||
}
|
||||
else if (selectedObject instanceof Module) {
|
||||
myModulesDependencyCache.put((Module)selectedObject, dep);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getDependencies(final Condition<OrderEntry> condition) {
|
||||
final Set<String> result = new TreeSet<String>();
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final Module[] modules = myModulesConfigurator.getModules();
|
||||
for (final Module module : modules) {
|
||||
final ModuleEditor moduleEditor = myModulesConfigurator.getModuleEditor(module);
|
||||
if (moduleEditor != null) {
|
||||
final OrderEntry[] entries = moduleEditor.getOrderEntries();
|
||||
for (OrderEntry entry : entries) {
|
||||
if (myDisposed) return;
|
||||
if (condition.value(entry)) {
|
||||
result.add(module.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Set<String> getDependencies(final Object selectedObject) {
|
||||
if (selectedObject instanceof Module) {
|
||||
return getDependencies(new Condition<OrderEntry>() {
|
||||
public boolean value(final OrderEntry orderEntry) {
|
||||
return orderEntry instanceof ModuleOrderEntry && Comparing.equal(((ModuleOrderEntry)orderEntry).getModule(), selectedObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (selectedObject instanceof Library) {
|
||||
Library library = (Library)selectedObject;
|
||||
if (library.getTable() == null) { //module library navigation
|
||||
HashSet<String> deps = new HashSet<String>();
|
||||
Module module = ((LibraryImpl)library).getModule();
|
||||
if (module != null) {
|
||||
deps.add(module.getName());
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
return getDependencies(new Condition<OrderEntry>() {
|
||||
@SuppressWarnings({"SimplifiableIfStatement"})
|
||||
public boolean value(final OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof LibraryOrderEntry){
|
||||
final LibraryImpl library = (LibraryImpl)((LibraryOrderEntry)orderEntry).getLibrary();
|
||||
if (Comparing.equal(library, selectedObject)) return true;
|
||||
return library != null && Comparing.equal(library.getSource(), selectedObject);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (selectedObject instanceof Sdk) {
|
||||
return getDependencies(new Condition<OrderEntry>() {
|
||||
public boolean value(final OrderEntry orderEntry) {
|
||||
return orderEntry instanceof JdkOrderEntry && Comparing.equal(((JdkOrderEntry)orderEntry).getJdk(), selectedObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
clearCaches(true);
|
||||
myDisposed = true;
|
||||
}
|
||||
|
||||
public void invalidateModules(final Set<String> modules) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (modules != null) {
|
||||
for (String module : modules) {
|
||||
myValidityCache.remove(myModuleManager.findModuleByName(module));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public void invalidateModuleName(final Module module) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final Map<String, Set<String>> problems = myValidityCache.remove(module);
|
||||
if (problems != null) {
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ModulesConfigurator getModulesConfigurator() {
|
||||
return myModulesConfigurator;
|
||||
}
|
||||
|
||||
public void clearCaches(final boolean cleanCacheUpdaters) {
|
||||
myJdkDependencyCache.clear();
|
||||
myLibraryDependencyCache.clear();
|
||||
myValidityCache.clear();
|
||||
myLibraryPathValidityCache.clear();
|
||||
myModulesDependencyCache.clear();
|
||||
|
||||
fireOnCacheChanged();
|
||||
if (cleanCacheUpdaters) {
|
||||
myCacheUpdaters.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCaches(final Module module, final List<Library> chosen) {
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
|
||||
for (Library library : chosen) {
|
||||
myLibraryDependencyCache.remove(library.getName());
|
||||
}
|
||||
myValidityCache.remove(module);
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
|
||||
public void clearCaches(final Module module, final Sdk oldJdk, final Sdk selectedModuleJdk) {
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
|
||||
myJdkDependencyCache.remove(oldJdk);
|
||||
myJdkDependencyCache.remove(selectedModuleJdk);
|
||||
myValidityCache.remove(module);
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
|
||||
public void clearCaches(final OrderEntry entry) {
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
|
||||
if (entry instanceof ModuleOrderEntry) {
|
||||
final Module module = ((ModuleOrderEntry)entry).getModule();
|
||||
myValidityCache.remove(module);
|
||||
myModulesDependencyCache.remove(module);
|
||||
} else if (entry instanceof JdkOrderEntry) {
|
||||
invalidateModules(myJdkDependencyCache.remove(((JdkOrderEntry)entry).getJdk()));
|
||||
} else if (entry instanceof LibraryOrderEntry) {
|
||||
invalidateModules(myLibraryDependencyCache.remove(((LibraryOrderEntry)entry).getLibraryName()));
|
||||
}
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
|
||||
public ValidityLevel isInvalid(final Object object) {
|
||||
if (object instanceof Module){
|
||||
final Module module = (Module)object;
|
||||
if (myValidityCache.containsKey(module)) {
|
||||
boolean valid = myValidityCache.get(module) == null;
|
||||
return valid ? ValidityLevel.VALID : ValidityLevel.ERROR;
|
||||
}
|
||||
myUpdateDependenciesAlarm.addRequest(new Runnable(){
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
updateModuleValidityCache(module);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
} else if (object instanceof LibraryEx) {
|
||||
final LibraryEx library = (LibraryEx)object;
|
||||
if (myLibraryPathValidityCache.containsKey(library)) return myLibraryPathValidityCache.get(library);
|
||||
myUpdateDependenciesAlarm.addRequest(new Runnable(){
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
updateLibraryValidityCache(library);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
return ValidityLevel.VALID;
|
||||
}
|
||||
|
||||
private void updateLibraryValidityCache(final LibraryEx library) {
|
||||
if (myLibraryPathValidityCache.containsKey(library)) return; //do not check twice
|
||||
ValidityLevel level = ValidityLevel.VALID;
|
||||
if (!(library.allPathsValid(JavadocOrderRootType.getInstance()) && library.allPathsValid(OrderRootType.SOURCES))) {
|
||||
level = ValidityLevel.WARNING;
|
||||
}
|
||||
if (!library.allPathsValid(OrderRootType.CLASSES)) {
|
||||
level = ValidityLevel.ERROR;
|
||||
}
|
||||
|
||||
final ValidityLevel finalLevel = level;
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run() {
|
||||
if (!myDisposed){
|
||||
myLibraryPathValidityCache.put(library, finalLevel);
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateModuleValidityCache(final Module module) {
|
||||
if (myValidityCache.containsKey(module)) return; //do not check twice
|
||||
|
||||
if (myDisposed) return;
|
||||
|
||||
Map<String, Set<String>> problems = null;
|
||||
final ModifiableModuleModel moduleModel = myModulesConfigurator.getModuleModel();
|
||||
final Module[] all = moduleModel.getModules();
|
||||
for (Module each : all) {
|
||||
if (each != module && getRealName(each).equals(getRealName(module))) {
|
||||
problems = new HashMap<String, Set<String>>();
|
||||
problems.put(DUPLICATE_MODULE_NAME, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final ModuleRootModel rootModel = myModulesConfigurator.getRootModel(module);
|
||||
if (rootModel == null) return; //already disposed
|
||||
final OrderEntry[] entries = rootModel.getOrderEntries();
|
||||
for (OrderEntry entry : entries) {
|
||||
if (myDisposed) return;
|
||||
if (!entry.isValid()){
|
||||
if (problems == null) {
|
||||
problems = new HashMap<String, Set<String>>();
|
||||
}
|
||||
if (entry instanceof JdkOrderEntry && ((JdkOrderEntry)entry).getJdkName() == null) {
|
||||
problems.put(NO_JDK, null);
|
||||
} else {
|
||||
Set<String> deletedLibraries = problems.get(DELETED_LIBRARIES);
|
||||
if (deletedLibraries == null){
|
||||
deletedLibraries = new HashSet<String>();
|
||||
problems.put(DELETED_LIBRARIES, deletedLibraries);
|
||||
}
|
||||
deletedLibraries.add(entry.getPresentableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
final Map<String, Set<String>> finalProblems = problems;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (!myDisposed) {
|
||||
myValidityCache.put(module, finalProblems);
|
||||
fireOnCacheChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Module[] getModules() {
|
||||
return myModulesConfigurator.getModules();
|
||||
}
|
||||
@@ -454,4 +153,4 @@ public class StructureConfigurableContext implements Disposable {
|
||||
resetLibraries();
|
||||
myModulesConfigurator.resetModuleEditors();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user