diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathEditor.java index 2da12ffe5071..44393bdb50b7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathEditor.java @@ -152,13 +152,6 @@ public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootL final ModifiableRootModel model = getModel(); final Sdk oldSdk = model.getSdk(); - //final List entries = myPanel.getEntries(); - //for (OrderEntry entry : entries) { - // if (entry instanceof JdkOrderEntry) { - // - // } - //} - if (newJDK != null) { model.setSdk(newJDK); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java index 31e63740def3..447e1d08e0f2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java @@ -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) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleJdkConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleJdkConfigurable.java index 91552be593e2..728167753479 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleJdkConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleJdkConfigurable.java @@ -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 { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index c152bd469688..3abc96473c9a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -267,7 +267,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } } - myContext.clearCaches(false); + myContext.getDaemonAnalyzer().clearCaches(); myContext.resetLibraries(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index cbf368626556..de6421576fec 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -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(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java index af39f2b98be8..c8a45db598b7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java @@ -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> myLibraryDependencyCache = new HashMap>(); - public final Map> myJdkDependencyCache = new HashMap>(); - public final Map>> myValidityCache = new HashMap>>(); - public final Map myLibraryPathValidityCache = new HashMap(); //can be invalidated on startup only - public final Map> myModulesDependencyCache = new HashMap>(); - - private final ModuleManager myModuleManager; public final ModulesConfigurator myModulesConfigurator; public final Map myLevel2Providers = new THashMap(); private final Project myProject; @@ -73,299 +58,13 @@ public class StructureConfigurableContext implements Disposable { return myDaemonAnalyzer; } - @Nullable - public Set 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 dep = getDependencies(selectedObject); - updateCache(selectedObject, dep); - return dep; - } else { - myUpdateDependenciesAlarm.addRequest(new Runnable(){ - public void run() { - final Set 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 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 getDependencies(final Condition condition) { - final Set result = new TreeSet(); - 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 getDependencies(final Object selectedObject) { - if (selectedObject instanceof Module) { - return getDependencies(new Condition() { - 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 deps = new HashSet(); - Module module = ((LibraryImpl)library).getModule(); - if (module != null) { - deps.add(module.getName()); - } - return deps; - } - return getDependencies(new Condition() { - @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() { - 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 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> 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 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> 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>(); - 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>(); - } - if (entry instanceof JdkOrderEntry && ((JdkOrderEntry)entry).getJdkName() == null) { - problems.put(NO_JDK, null); - } else { - Set deletedLibraries = problems.get(DELETED_LIBRARIES); - if (deletedLibraries == null){ - deletedLibraries = new HashSet(); - problems.put(DELETED_LIBRARIES, deletedLibraries); - } - deletedLibraries.add(entry.getPresentableName()); - } - } - } - final Map> 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(); } -} +} \ No newline at end of file