@NotNull public Change[] getSelectedChanges() { Set<Change> changes = new LinkedHashSet<Change>(); final TreePath[] paths = getSelectionPaths(); if (paths == null) { return new Change[0]; } for (TreePath path : paths) { ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent(); changes.addAll(node.getAllChangesUnder()); } if (changes.isEmpty()) { final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing(); if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) { for (VirtualFile file : selectedModifiedWithoutEditing) { AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file); if (vcs == null) continue; final VcsCurrentRevisionProxy before = VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod()); if (before != null) { ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file)); changes.add(new Change(before, afterRevision, FileStatus.HIJACKED)); } } } } return changes.toArray(new Change[changes.size()]); }
@Override @NotNull public Document[] getUncommittedDocuments() { ApplicationManager.getApplication().assertIsDispatchThread(); Document[] documents = myUncommittedDocuments.toArray(new Document[myUncommittedDocuments.size()]); return ArrayUtil.stripTrailingNulls(documents); }
@NotNull private static GlobalSearchScope forDirectory( @NotNull Project project, boolean withSubdirectories, @NotNull VirtualFile directory) { Set<VirtualFile> result = new LinkedHashSet<>(); result.add(directory); addSourceDirectoriesFromLibraries(project, directory, result); VirtualFile[] array = result.toArray(new VirtualFile[result.size()]); return GlobalSearchScopesCore.directoriesScope(project, withSubdirectories, array); }
@Override public void calcData(final DataKey key, final DataSink sink) { Node node = getSelectedNode(); if (key == PlatformDataKeys.PROJECT) { sink.put(PlatformDataKeys.PROJECT, myProject); } else if (key == USAGE_VIEW_KEY) { sink.put(USAGE_VIEW_KEY, UsageViewImpl.this); } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) { sink.put(PlatformDataKeys.NAVIGATABLE_ARRAY, getNavigatablesForNodes(getSelectedNodes())); } else if (key == PlatformDataKeys.EXPORTER_TO_TEXT_FILE) { sink.put(PlatformDataKeys.EXPORTER_TO_TEXT_FILE, myTextFileExporter); } else if (key == USAGES_KEY) { final Set<Usage> selectedUsages = getSelectedUsages(); sink.put( USAGES_KEY, selectedUsages != null ? selectedUsages.toArray(new Usage[selectedUsages.size()]) : null); } else if (key == USAGE_TARGETS_KEY) { sink.put(USAGE_TARGETS_KEY, getSelectedUsageTargets()); } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) { final Set<Usage> usages = getSelectedUsages(); Usage[] ua = usages != null ? usages.toArray(new Usage[usages.size()]) : null; VirtualFile[] data = UsageDataUtil.provideVirtualFileArray(ua, getSelectedUsageTargets()); sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, data); } else if (key == PlatformDataKeys.HELP_ID) { sink.put(PlatformDataKeys.HELP_ID, HELP_ID); } else if (key == PlatformDataKeys.COPY_PROVIDER) { sink.put(PlatformDataKeys.COPY_PROVIDER, this); } else if (node != null) { Object userObject = node.getUserObject(); if (userObject instanceof TypeSafeDataProvider) { ((TypeSafeDataProvider) userObject).calcData(key, sink); } else if (userObject instanceof DataProvider) { DataProvider dataProvider = (DataProvider) userObject; Object data = dataProvider.getData(key.getName()); if (data != null) { sink.put(key, data); } } } }
public void actionPerformed(AnActionEvent e) { final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return; final Set<TreePath> pathsToRemove = new HashSet<TreePath>(); for (TreePath path : paths) { if (removeFromModel(path)) { pathsToRemove.add(path); } } removePaths(pathsToRemove.toArray(new TreePath[pathsToRemove.size()])); }
private Change[] getLeadSelection() { final Set<Change> changes = new LinkedHashSet<Change>(); final TreePath[] paths = getSelectionPaths(); if (paths == null) return new Change[0]; for (TreePath path : paths) { ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent(); if (node instanceof ChangesBrowserChangeNode) { changes.add(((ChangesBrowserChangeNode) node).getUserObject()); } } return changes.toArray(new Change[changes.size()]); }
@NotNull private ChangeList[] getSelectedChangeLists() { Set<ChangeList> lists = new HashSet<ChangeList>(); final TreePath[] paths = getSelectionPaths(); if (paths == null) return new ChangeList[0]; for (TreePath path : paths) { ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject instanceof ChangeList) { lists.add((ChangeList) userObject); } } return lists.toArray(new ChangeList[lists.size()]); }
private boolean checkReferencedRastersIncluded() { final Set<String> notIncludedNames = new TreeSet<String>(); final List<String> includedNodeNames = Arrays.asList(productSubsetDef.getNodeNames()); for (final String nodeName : includedNodeNames) { final RasterDataNode rasterDataNode = product.getRasterDataNode(nodeName); if (rasterDataNode != null) { collectNotIncludedReferences(rasterDataNode, notIncludedNames); } } boolean ok = true; if (!notIncludedNames.isEmpty()) { StringBuilder nameListText = new StringBuilder(); for (String notIncludedName : notIncludedNames) { nameListText.append(" '").append(notIncludedName).append("'\n"); } final String pattern = "The following dataset(s) are referenced but not included\n" + "in your current subset definition:\n" + "{0}\n" + "If you do not include these dataset(s) into your selection,\n" + "you might get unexpected results while working with the\n" + "resulting product.\n\n" + "Do you wish to include the referenced dataset(s) into your\n" + "subset definition?\n"; /*I18N*/ final MessageFormat format = new MessageFormat(pattern); int status = JOptionPane.showConfirmDialog( getJDialog(), format.format(new Object[] {nameListText.toString()}), "Incomplete Subset Definition", /*I18N*/ JOptionPane.YES_NO_CANCEL_OPTION); if (status == JOptionPane.YES_OPTION) { final String[] nodenames = notIncludedNames.toArray(new String[notIncludedNames.size()]); productSubsetDef.addNodeNames(nodenames); ok = true; } else if (status == JOptionPane.NO_OPTION) { ok = true; } else if (status == JOptionPane.CANCEL_OPTION) { ok = false; } } return ok; }
@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 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(); } }); }
/** * Returns an array of all shapes currently in the game. * * @return an array of all shapes currently in the game. */ public static Shape[] getAllShapes() { return allShapes.toArray(new Shape[0]); }
static Shape[] getSolids() { return solidShapes.toArray(new Shape[0]); }
@NotNull public EditorWindow[] getWindows() { return myWindows.toArray(new EditorWindow[myWindows.size()]); }
@Override @NotNull public Document[] getUncommittedDocuments() { ApplicationManager.getApplication().assertIsDispatchThread(); return myUncommittedDocuments.toArray(new Document[myUncommittedDocuments.size()]); }
private void warnAboutMissedDependencies( final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) { final Set<PluginId> deps = new HashSet<PluginId>(); final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<IdeaPluginDescriptor>(); if (newVal) { Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors); } else { descriptorsToCheckDependencies.addAll(view); descriptorsToCheckDependencies.addAll(filtered); descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors)); for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator(); iterator.hasNext(); ) { IdeaPluginDescriptor descriptor = iterator.next(); final Boolean enabled = myEnabled.get(descriptor.getPluginId()); if (enabled == null || !enabled.booleanValue()) { iterator.remove(); } } } for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) { PluginManager.checkDependants( ideaPluginDescriptor, new Function<PluginId, IdeaPluginDescriptor>() { @Nullable public IdeaPluginDescriptor fun(final PluginId pluginId) { return PluginManager.getPlugin(pluginId); } }, new Condition<PluginId>() { public boolean value(final PluginId pluginId) { Boolean enabled = myEnabled.get(pluginId); if (enabled == null) { return false; } if (newVal && !enabled.booleanValue()) { deps.add(pluginId); } if (!newVal) { final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId(); for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) { if (pluginId.equals(descriptor.getPluginId())) { deps.add(pluginDescriptorId); break; } } } return true; } }); } if (!deps.isEmpty()) { final String listOfSelectedPlugins = StringUtil.join( ideaPluginDescriptors, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", "); final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<IdeaPluginDescriptor>(); final String listOfDependencies = StringUtil.join( deps, new Function<PluginId, String>() { public String fun(final PluginId pluginId) { final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId); assert pluginDescriptor != null; pluginDependencies.add(pluginDescriptor); return pluginDescriptor.getName(); } }, "<br>"); final String message = !newVal ? "<html>The following plugins <br>" + listOfDependencies + "<br>are enabled and depend" + (deps.size() == 1 ? "s" : "") + " on selected plugins. " + "<br>Would you like to disable them too?</html>" : "<html>The following plugins on which " + listOfSelectedPlugins + " depend" + (ideaPluginDescriptors.length == 1 ? "s" : "") + " are disabled:<br>" + listOfDependencies + "<br>Would you like to enable them?</html>"; if (Messages.showOkCancelDialog( message, newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this", Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { for (PluginId pluginId : deps) { myEnabled.put(pluginId, newVal); } updatePluginDependencies(); hideNotApplicablePlugins( newVal, pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()])); } } }
Config[] getCopyOfExpandedNodes() { return (Config[]) expandedNodes.toArray(new Config[0]); }
public CreateXmlResourceDialog( @NotNull Module module, @NotNull ResourceType resourceType, @Nullable String predefinedName, @Nullable String predefinedValue, boolean chooseName, @Nullable VirtualFile defaultFile) { super(module.getProject()); myResourceType = resourceType; if (predefinedName != null && predefinedName.length() > 0) { if (!chooseName) { myNameLabel.setVisible(false); myNameField.setVisible(false); } myNameField.setText(predefinedName); } if (predefinedValue != null && predefinedValue.length() > 0) { myValueLabel.setVisible(false); myValueField.setVisible(false); myValueField.setText(predefinedValue); } final Set<Module> modulesSet = new HashSet<Module>(); modulesSet.add(module); for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, true)) { modulesSet.add(depFacet.getModule()); } assert modulesSet.size() > 0; if (modulesSet.size() == 1) { myModule = module; myModuleLabel.setVisible(false); myModuleCombo.setVisible(false); } else { myModule = null; final Module[] modules = modulesSet.toArray(new Module[modulesSet.size()]); Arrays.sort( modules, new Comparator<Module>() { @Override public int compare(Module m1, Module m2) { return m1.getName().compareTo(m2.getName()); } }); myModuleCombo.setModel(new DefaultComboBoxModel(modules)); myModuleCombo.setSelectedItem(module); myModuleCombo.setRenderer(new ModuleListCellRendererWrapper(myModuleCombo.getRenderer())); } if (defaultFile == null) { final String defaultFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType); if (defaultFileName != null) { myFileNameCombo.getEditor().setItem(defaultFileName); } } myDirectoriesList = new CheckBoxList(); myDirectoriesLabel.setLabelFor(myDirectoriesList); final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myDirectoriesList); decorator.setEditAction(null); decorator.disableUpDownActions(); decorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doAddNewDirectory(); } }); decorator.setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doDeleteDirectory(); } }); final AnActionButton selectAll = new AnActionButton("Select All", null, PlatformIcons.SELECT_ALL_ICON) { @Override public void actionPerformed(AnActionEvent e) { doSelectAllDirs(); } }; decorator.addExtraAction(selectAll); final AnActionButton unselectAll = new AnActionButton("Unselect All", null, PlatformIcons.UNSELECT_ALL_ICON) { @Override public void actionPerformed(AnActionEvent e) { doUnselectAllDirs(); } }; decorator.addExtraAction(unselectAll); myDirectoriesPanel.add(decorator.createPanel()); updateDirectories(true); myModuleCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateDirectories(true); } }); final JCheckBox valuesCheckBox = myCheckBoxes.get(SdkConstants.FD_RES_VALUES); if (valuesCheckBox != null) { valuesCheckBox.setSelected(true); } if (defaultFile != null) { resetFromFile(defaultFile, module.getProject()); } init(); }
private static boolean suggestToEnableInstalledPlugins( InstalledPluginsTableModel pluginsModel, Set<IdeaPluginDescriptor> disabled, Set<IdeaPluginDescriptor> disabledDependants, List<PluginNode> list) { if (!disabled.isEmpty() || !disabledDependants.isEmpty()) { String message = ""; if (disabled.size() == 1) { message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled."; } else if (!disabled.isEmpty()) { message += "Updated plugins " + StringUtil.join( disabled, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", ") + " are disabled."; } if (!disabledDependants.isEmpty()) { message += "<br>"; message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled"; if (disabledDependants.size() == 1) { message += " plugin '" + disabledDependants.iterator().next().getName() + "'."; } else { message += " plugins " + StringUtil.join( disabledDependants, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", ") + "."; } } message += " Disabled plugins " + (disabled.isEmpty() ? "and plugins which depend on disabled " : "") + "won't be activated after restart."; int result; if (!disabled.isEmpty() && !disabledDependants.isEmpty()) { result = Messages.showYesNoCancelDialog( XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), "Enable all", "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (result == Messages.CANCEL) return false; } else { message += "<br>Would you like to enable "; if (!disabled.isEmpty()) { message += "updated plugin" + (disabled.size() > 1 ? "s" : ""); } else { //noinspection SpellCheckingInspection message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y"); } message += "?"; result = Messages.showYesNoDialog( XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), Messages.getQuestionIcon()); if (result == Messages.NO) return false; } if (result == Messages.YES) { disabled.addAll(disabledDependants); pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true); } else if (result == Messages.NO && !disabled.isEmpty()) { pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true); } return true; } return false; }