private Set<Key> getActiveProviderKeys() { Set<Key> result = new HashSet<Key>(); for (BeforeRunTask task : myModel.getItems()) { result.add(task.getProviderId()); } return result; }
void doAddAction(AnActionButton button) { if (isUnknown()) { return; } final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions( BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject()); Set<Key> activeProviderKeys = getActiveProviderKeys(); DefaultActionGroup actionGroup = new DefaultActionGroup(null, false); for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) { if (provider.createTask(myRunConfiguration) == null) continue; if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) continue; AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) { @Override public void actionPerformed(AnActionEvent e) { BeforeRunTask task = provider.createTask(myRunConfiguration); if (task != null) { provider.configureTask(myRunConfiguration, task); if (!provider.canExecuteTask(myRunConfiguration, task)) return; } else { return; } task.setEnabled(true); Set<RunConfiguration> configurationSet = new HashSet<RunConfiguration>(); getAllRunBeforeRuns(task, configurationSet); if (configurationSet.contains(myRunConfiguration)) { JOptionPane.showMessageDialog( BeforeRunStepsPanel.this, ExecutionBundle.message( "before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)), ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE); return; } addTask(task); myListener.fireStepsBeforeRunChanged(); } }; actionGroup.add(providerAction); } final ListPopup popup = popupFactory.createActionGroupPopup( ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1, Condition.TRUE); popup.show(button.getPreferredPopupPoint()); }
private void updateRightTreeModel() { Set<PsiFile> deps = new HashSet<PsiFile>(); Set<PsiFile> scope = getSelectedScope(myLeftTree); myIllegalsInRightTree = new HashSet<PsiFile>(); for (PsiFile psiFile : scope) { Map<DependencyRule, Set<PsiFile>> illegalDeps = myIllegalDependencies.get(psiFile); if (illegalDeps != null) { for (final DependencyRule rule : illegalDeps.keySet()) { myIllegalsInRightTree.addAll(illegalDeps.get(rule)); } } final Set<PsiFile> psiFiles = myDependencies.get(psiFile); if (psiFiles != null) { for (PsiFile file : psiFiles) { if (file != null && file.isValid()) { deps.add(file); } } } } deps.removeAll(scope); myRightTreeExpansionMonitor.freeze(); myRightTree.setModel(buildTreeModel(deps, myRightTreeMarker)); myRightTreeExpansionMonitor.restore(); expandFirstLevel(myRightTree); }
private void checkForEmptyAndDuplicatedNames( MyNode rootNode, String prefix, String title, Class<? extends NamedConfigurable> configurableClass, boolean recursively) throws ConfigurationException { final Set<String> names = new HashSet<String>(); for (int i = 0; i < rootNode.getChildCount(); i++) { final MyNode node = (MyNode) rootNode.getChildAt(i); final NamedConfigurable scopeConfigurable = node.getConfigurable(); if (configurableClass.isInstance(scopeConfigurable)) { final String name = scopeConfigurable.getDisplayName(); if (name.trim().length() == 0) { selectNodeInTree(node); throw new ConfigurationException("Name should contain non-space characters"); } if (names.contains(name)) { final NamedConfigurable selectedConfigurable = getSelectedConfigurable(); if (selectedConfigurable == null || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) { selectNodeInTree(node); } throw new ConfigurationException( CommonBundle.message("smth.already.exist.error.message", prefix, name), title); } names.add(name); } if (recursively) { checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true); } } }
@Nullable public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) { Set<PsiElement> parents = getAllParents(element); FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode) myAbstractTreeBuilder.getRootElement(); while (node != null) { boolean changed = false; for (FilteringTreeStructure.FilteringNode n : node.children()) { final PsiElement psiElement = getPsi(n); if (psiElement != null && parents.contains(psiElement)) { node = n; changed = true; break; } } if (!changed) { myAbstractTreeBuilder.select(node); if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) { TreeUtil.selectFirstNode(myTree); } myInitialNodeIsLeaf = node.getChildren().length == 0; return node; } } TreeUtil.selectFirstNode(myTree); return null; }
private void calculateRoots() { final ModuleManager moduleManager = ModuleManager.getInstance(myProject); // assertion for read access inside final Module[] modules = ApplicationManager.getApplication() .runReadAction( new Computable<Module[]>() { public Module[] compute() { return moduleManager.getModules(); } }); final TreeSet<VirtualFile> checkSet = new TreeSet<VirtualFile>(FilePathComparator.getInstance()); myRoots = new HashSet<VirtualFile>(); myRoots.addAll(myInitialRoots); checkSet.addAll(myInitialRoots); for (Module module : modules) { final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots(); for (VirtualFile file : files) { final VirtualFile floor = checkSet.floor(file); if (floor != null) { myModulesSet.put(file, module.getName()); myRoots.add(file); } } } }
private boolean checkReadonlyUsages() { final Set<VirtualFile> readOnlyUsages = getReadOnlyUsagesFiles(); return readOnlyUsages.isEmpty() || !ReadonlyStatusHandler.getInstance(myProject) .ensureFilesWritable(VfsUtil.toVirtualFileArray(readOnlyUsages)) .hasReadonlyFiles(); }
private static Set<PsiElement> getAllParents(PsiElement element) { Set<PsiElement> parents = new java.util.HashSet<PsiElement>(); while (element != null) { parents.add(element); if (element instanceof PsiFile) break; element = element.getParent(); } return parents; }
private void editRemoteSdk(Sdk currentSdk) { PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance(); if (remoteInterpreterManager != null) { final SdkModificator modificator = myModificators.get(currentSdk); Set<Sdk> existingSdks = Sets.newHashSet(myProjectSdksModel.getSdks()); existingSdks.remove(currentSdk); if (remoteInterpreterManager.editSdk(myProject, modificator, existingSdks)) { myModifiedModificators.add(modificator); } } }
@NotNull private Set<Usage> getReadOnlyUsages() { final Set<Usage> result = new THashSet<Usage>(); final Set<Map.Entry<Usage, UsageNode>> usages = myUsageNodes.entrySet(); for (Map.Entry<Usage, UsageNode> entry : usages) { Usage usage = entry.getKey(); UsageNode node = entry.getValue(); if (node != null && node != NULL_NODE && !node.isExcluded() && usage.isReadOnly()) { result.add(usage); } } return result; }
@Nullable private Object findClosestTo(PsiElement path, ArrayList<ObjectWithWeight> paths) { if (path == null || myInitialPsiElement == null) { return paths.get(0).node; } final Set<PsiElement> parents = getAllParents(myInitialPsiElement); ArrayList<ObjectWithWeight> cur = new ArrayList<ObjectWithWeight>(); int max = -1; for (ObjectWithWeight p : paths) { final Object last = ((TreePath) p.node).getLastPathComponent(); final List<PsiElement> elements = new ArrayList<PsiElement>(); final Object object = ((DefaultMutableTreeNode) last).getUserObject(); if (object instanceof FilteringTreeStructure.FilteringNode) { FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode) object; FilteringTreeStructure.FilteringNode candidate = node; while (node != null) { elements.add(getPsi(node)); node = node.getParentNode(); } final int size = ContainerUtil.intersection(parents, elements).size(); if (size == elements.size() - 1 && size == parents.size() - (myInitialNodeIsLeaf ? 1 : 0) && candidate.children().isEmpty()) { return p.node; } if (size > max) { max = size; cur.clear(); cur.add(p); } else if (size == max) { cur.add(p); } } } Collections.sort( cur, new Comparator<ObjectWithWeight>() { @Override public int compare(ObjectWithWeight o1, ObjectWithWeight o2) { final int i = o1.compareWith(o2); return i != 0 ? i : ((TreePath) o2.node).getPathCount() - ((TreePath) o1.node).getPathCount(); } }); return cur.isEmpty() ? null : cur.get(0).node; }
private void reloadSdk() { final Sdk currentSdk = getSelectedSdk(); if (currentSdk != null) { myModifiedModificators.add(myModificators.get(currentSdk)); reloadSdk(currentSdk); } }
private void removeSdk() { final Sdk currentSdk = getSelectedSdk(); if (currentSdk != null) { final Sdk sdk = myProjectSdksModel.findSdk(currentSdk); final PySdkService sdkService = PySdkService.getInstance(); sdkService.removeSdk(currentSdk); DumbService.allowStartingDumbModeInside( DumbModePermission.MAY_START_MODAL, () -> SdkConfigurationUtil.removeSdk(sdk)); myProjectSdksModel.removeSdk(sdk); myProjectSdksModel.removeSdk(currentSdk); if (myModificators.containsKey(currentSdk)) { SdkModificator modificator = myModificators.get(currentSdk); myModifiedModificators.remove(modificator); myModificators.remove(currentSdk); } refreshSdkList(); mySdkListChanged = true; // TODO select initially selected SDK if (mySdkList.getSelectedIndex() < 0) { mySdkList.setSelectedIndex(0); } } }
private void editSdk(final Sdk currentSdk) { final SdkModificator modificator = myModificators.get(currentSdk); final EditSdkDialog dialog = new EditSdkDialog( myProject, modificator, s -> { if (isDuplicateSdkName(s, currentSdk)) { return PyBundle.message("sdk.details.dialog.error.duplicate.name"); } return null; }); if (dialog.showAndGet()) { mySdkList.repaint(); final boolean pathChanged = !Comparing.equal(currentSdk.getHomePath(), dialog.getHomePath()); if (!modificator.getName().equals(dialog.getName()) || pathChanged || dialog.isAssociateChanged()) { myModifiedModificators.add(modificator); modificator.setName(dialog.getName()); modificator.setHomePath(dialog.getHomePath()); if (dialog.isAssociateChanged()) { setSdkAssociated(modificator, dialog.associateWithProject()); } if (pathChanged) { reloadSdk(currentSdk); } } } }
private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) { if (sdk != null) { final PySdkService sdkService = PySdkService.getInstance(); sdkService.restoreSdk(sdk); boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk); if (isVirtualEnv && !newVirtualEnv) { AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel); dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) { return; } SdkModificator modificator = myModificators.get(sdk); setSdkAssociated(modificator, !dialog.makeAvailableToAll()); myModifiedModificators.add(modificator); } final Sdk oldSdk = myProjectSdksModel.findSdk(sdk); if (oldSdk == null) { myProjectSdksModel.addSdk(sdk); } refreshSdkList(); mySdkList.setSelectedValue(myProjectSdksModel.findSdk(sdk.getName()), true); mySdkListChanged = true; } }
@Override @NotNull public Set<Usage> getExcludedUsages() { Set<Usage> result = new THashSet<Usage>(); for (Map.Entry<Usage, UsageNode> entry : myUsageNodes.entrySet()) { UsageNode node = entry.getValue(); Usage usage = entry.getKey(); if (node == NULL_NODE || node == null) { continue; } if (node.isExcluded()) { result.add(usage); } } return result; }
public void apply() throws ConfigurationException { if (!myModifiedModificators.isEmpty()) { mySdkSettingsWereModified.run(); } for (SdkModificator modificator : myModifiedModificators) { /* This should always be true barring bug elsewhere, log error on else? */ if (modificator.isWritable()) { modificator.commitChanges(); } } myModificators.clear(); myModifiedModificators.clear(); mySdkListChanged = false; final Sdk sdk = getSelectedSdk(); myShowMoreCallback.consume(sdk); PyPackageManagers.getInstance().clearCache(sdk); Disposer.dispose(getDisposable()); }
private InspectionProfile guessProfileToSelect( final InspectionProjectProfileManager profileManager) { final Set<InspectionProfile> profiles = new HashSet<InspectionProfile>(); final RefEntity[] selectedElements = myTree.getSelectedElements(); for (RefEntity selectedElement : selectedElements) { if (selectedElement instanceof RefElement) { final RefElement refElement = (RefElement) selectedElement; final PsiElement element = refElement.getElement(); if (element != null) { profiles.add(profileManager.getInspectionProfile()); } } } if (profiles.isEmpty()) { return (InspectionProfile) profileManager.getProjectProfileImpl(); } return profiles.iterator().next(); }
private void reloadSdk(@NotNull Sdk currentSdk) { /* PythonSdkUpdater.update invalidates the modificator so we need to create a new one for further changes */ if (PythonSdkUpdater.update(currentSdk, myModificators.get(currentSdk), myProject, null)) { myModifiedModificators.remove(myModificators.get(currentSdk)); myModificators.put(currentSdk, currentSdk.getSdkModificator()); } }
public boolean isModified() { Sdk projectSdk = getSdk(); if (projectSdk != null) { projectSdk = myProjectSdksModel.findSdk(projectSdk.getName()); } return getSelectedSdk() != projectSdk || mySdkListChanged || myProjectSdksModel.isModified() || !myModifiedModificators.isEmpty(); }
private boolean checkBeforeRunTasksAbility(boolean checkOnlyAddAction) { if (isUnknown()) { return false; } Set<Key> activeProviderKeys = getActiveProviderKeys(); final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions( BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject()); for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) { if (provider.createTask(myRunConfiguration) != null) { if (!checkOnlyAddAction) { return true; } else if (!provider.isSingleton() || !activeProviderKeys.contains(provider.getId())) { return true; } } } return false; }
@Nullable private UsageTarget[] getSelectedUsageTargets() { TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) return null; Set<UsageTarget> targets = new THashSet<UsageTarget>(); for (TreePath selectionPath : selectionPaths) { Object lastPathComponent = selectionPath.getLastPathComponent(); if (lastPathComponent instanceof UsageTargetNode) { UsageTargetNode usageTargetNode = (UsageTargetNode) lastPathComponent; UsageTarget target = usageTargetNode.getTarget(); if (target != null && target.isValid()) { targets.add(target); } } } return targets.isEmpty() ? null : targets.toArray(new UsageTarget[targets.size()]); }
@NotNull public static List<GotoRelatedItem> collectRelatedItems( @NotNull PsiElement contextElement, @Nullable DataContext dataContext) { Set<GotoRelatedItem> items = ContainerUtil.newLinkedHashSet(); for (GotoRelatedProvider provider : Extensions.getExtensions(GotoRelatedProvider.EP_NAME)) { items.addAll(provider.getItems(contextElement)); if (dataContext != null) { items.addAll(provider.getItems(dataContext)); } } GotoRelatedItem[] result = items.toArray(new GotoRelatedItem[items.size()]); Arrays.sort( result, (i1, i2) -> { String o1 = i1.getGroup(); String o2 = i2.getGroup(); return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2); }); return Arrays.asList(result); }
private void collectGroupingRules() { for (BreakpointPanelProvider provider : myBreakpointsPanelProviders) { provider.createBreakpointsGroupingRules(myRulesAvailable); } myRulesEnabled.clear(); XBreakpointsDialogState settings = (getBreakpointManager()).getBreakpointsDialogSettings(); for (XBreakpointGroupingRule rule : myRulesAvailable) { if (rule.isAlwaysEnabled() || (settings != null && settings.getSelectedGroupingRules().contains(rule.getId()))) { myRulesEnabled.add(rule); } } for (XBreakpointGroupingRule rule : myRulesAvailable) { if (!rule.isAlwaysEnabled()) { myToggleRuleActions.add(new ToggleBreakpointGroupingRuleEnabledAction(rule)); } } }
private void combineToResourceBundleIfNeed(Collection<PsiFile> files) { Collection<PropertiesFile> createdFiles = ContainerUtil.map( files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> { final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom); LOG.assertTrue(file != null, dom.getName()); return file; }); ResourceBundle mainBundle = myResourceBundle; final Set<ResourceBundle> allBundles = new HashSet<>(); if (mainBundle != null) { allBundles.add(mainBundle); } boolean needCombining = false; for (PropertiesFile file : createdFiles) { final ResourceBundle rb = file.getResourceBundle(); if (mainBundle == null) { mainBundle = rb; } else if (!mainBundle.equals(rb)) { needCombining = true; } allBundles.add(rb); } if (needCombining) { final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles); final String baseName = getBaseName(); if (myResourceBundle != null) { toCombine.addAll(myResourceBundle.getPropertiesFiles()); } ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject()); for (ResourceBundle bundle : allBundles) { manager.dissociateResourceBundle(bundle); } manager.combineToResourceBundle(toCombine, baseName); } }
private void rulesChanged() { ApplicationManager.getApplication().assertIsDispatchThread(); final ArrayList<UsageState> states = new ArrayList<UsageState>(); captureUsagesExpandState(new TreePath(myTree.getModel().getRoot()), states); final List<Usage> allUsages = new ArrayList<Usage>(myUsageNodes.keySet()); Collections.sort(allUsages, USAGE_COMPARATOR); final Set<Usage> excludedUsages = getExcludedUsages(); reset(); myBuilder.setGroupingRules(getActiveGroupingRules(myProject)); myBuilder.setFilteringRules(getActiveFilteringRules(myProject)); ApplicationManager.getApplication() .runReadAction( new Runnable() { @Override public void run() { for (Usage usage : allUsages) { if (!usage.isValid()) { continue; } if (usage instanceof MergeableUsage) { ((MergeableUsage) usage).reset(); } appendUsage(usage); } } }); excludeUsages(excludedUsages.toArray(new Usage[excludedUsages.size()])); if (myCentralPanel != null) { setupCentralPanel(); } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (isDisposed) return; restoreUsageExpandState(states); updateImmediately(); } }); }
private String canCreateAllFilesForAllLocales() { final String name = getBaseName(); if (name.isEmpty()) { return "Base name is empty"; } final Set<String> files = getFileNamesToCreate(); if (files.isEmpty()) { return "No locales added"; } for (PsiElement element : myDirectory.getChildren()) { if (element instanceof PsiFile) { if (element instanceof PropertiesFile) { PropertiesFile propertiesFile = (PropertiesFile) element; final String propertiesFileName = propertiesFile.getName(); if (files.contains(propertiesFileName)) { return "Some of files already exist"; } } } } return null; }
public void disposeUIResources() { myState.getProportions().saveSplitterProportions(myWholePanel); myAutoScrollHandler.cancelAllRequests(); myDetails.disposeUIResources(); myInitializedConfigurables.clear(); clearChildren(); final String key = getComponentStateKey(); final MasterDetailsStateService stateService = getStateService(); if (key != null && stateService != null) { stateService.setComponentState(key, getState()); } myCurrentConfigurable = null; }
@Nullable private AnalysisScope getScope() { final Set<PsiFile> selectedScope = getSelectedScope(myRightTree); Set<PsiFile> result = new HashSet<PsiFile>(); ((PackageDependenciesNode) myLeftTree.getModel().getRoot()) .fillFiles(result, !mySettings.UI_FLATTEN_PACKAGES); selectedScope.removeAll(result); if (selectedScope.isEmpty()) return null; List<VirtualFile> files = new ArrayList<VirtualFile>(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); for (PsiFile psiFile : selectedScope) { final VirtualFile file = psiFile.getVirtualFile(); LOG.assertTrue(file != null); if (fileIndex.isInContent(file)) { files.add(file); } } if (!files.isEmpty()) { return new AnalysisScope(myProject, files); } return null; }
private static void collectUsages( @NotNull DefaultMutableTreeNode node, @NotNull Set<Usage> usages) { if (node instanceof UsageNode) { UsageNode usageNode = (UsageNode) node; final Usage usage = usageNode.getUsage(); usages.add(usage); } Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) enumeration.nextElement(); collectUsages(child, usages); } }