Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
irengrig
2010-07-14 14:06:17 +04:00
1311 changed files with 145161 additions and 7663 deletions
@@ -21,11 +21,12 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.MultiValuesMap;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -84,7 +85,7 @@ public class EnableAutodetectionWorker {
}
if (moduleElements.isEmpty()) {
modulesToProcess.addAll(Arrays.asList(moduleManager.getModules()));
ContainerUtil.addAll(modulesToProcess, moduleManager.getModules());
}
if (newElement != null) {
Set<String> toRemove = new THashSet<String>();
@@ -34,12 +34,12 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -115,7 +115,7 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
rootModel.orderEntries().using(myContext.getModulesProvider()).recursively().librariesOnly().forEachLibrary(new Processor<Library>() {
@Override
public boolean process(Library library) {
roots.addAll(Arrays.asList(myContext.getLibrariesContainer().getLibraryFiles(library, OrderRootType.CLASSES)));
ContainerUtil.addAll(roots, myContext.getLibrariesContainer().getLibraryFiles(library, OrderRootType.CLASSES));
return true;
}
});
@@ -34,16 +34,19 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author nik
@@ -176,7 +179,7 @@ public class LibraryCompositionOptionsPanel {
descriptor.setTitle(IdeBundle.message("file.chooser.select.paths.title"));
descriptor.setDescription(IdeBundle.message("file.chooser.multiselect.description"));
final VirtualFile[] files = FileChooser.chooseFiles(myAddJarsButton, descriptor, getBaseDirectory());
myAddedJars.addAll(Arrays.asList(files));
ContainerUtil.addAll(myAddedJars, files);
updateAll();
}
@@ -196,7 +199,7 @@ public class LibraryCompositionOptionsPanel {
List<VirtualFile> roots = new ArrayList<VirtualFile>();
roots.addAll(myAddedJars);
for (Library library : myUsedLibraries) {
roots.addAll(Arrays.asList(myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES)));
ContainerUtil.addAll(roots, myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES));
}
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = new RequiredLibrariesInfo(myLibraryCompositionSettings.getLibraryInfos()).checkLibraries(
VfsUtil.toVirtualFileArray(roots), false);
@@ -24,6 +24,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContaine
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -121,7 +122,7 @@ public class LibraryCompositionSettings {
List<VirtualFile> roots = new ArrayList<VirtualFile>();
roots.addAll(myAddedJars);
for (Library library : myUsedLibraries) {
roots.addAll(Arrays.asList(librariesContainer.getLibraryFiles(library, OrderRootType.CLASSES)));
ContainerUtil.addAll(roots, librariesContainer.getLibraryFiles(library, OrderRootType.CLASSES));
}
VirtualFile[] jars = VfsUtil.toVirtualFileArray(roots);
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = requiredLibraries.checkLibraries(jars, all);
@@ -135,7 +136,7 @@ public class LibraryCompositionSettings {
if (files.length != downloadingInfos.length) {
return false;
}
myAddedJars.addAll(Arrays.asList(files));
ContainerUtil.addAll(myAddedJars, files);
}
}
}
@@ -16,6 +16,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContaine
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -40,6 +41,7 @@ public class AddFrameworkSupportDialog extends DialogWrapper {
return contentRootPath;
}
});
Disposer.register(myDisposable, myAddSupportPanel);
init();
}
@@ -26,8 +26,10 @@ import com.intellij.facet.ui.libraries.RemoteRepositoryInfo;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurableListener;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator;
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
@@ -60,7 +62,7 @@ import java.util.List;
/**
* @author nik
*/
public class AddSupportForFrameworksPanel {
public class AddSupportForFrameworksPanel implements Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksStep");
@NonNls private static final String UNCHECKED_CARD = "unchecked";
@NonNls private static final String EMPTY_CARD = "empty";
@@ -135,6 +137,10 @@ public class AddSupportForFrameworksPanel {
}
}
@Override
public void dispose() {
}
private void applyLibraryOptionsForSelected() {
if (myLastSelectedNode != null) {
final LibraryCompositionOptionsPanel optionsPanel = myLastSelectedNode.getLibraryCompositionOptionsPanel(myLibrariesContainer, myMirrorsMap);
@@ -286,7 +292,7 @@ public class AddSupportForFrameworksPanel {
}
parentNode = createNode(parentProvider, nodes, groups);
}
node = new FrameworkSupportNode(provider, parentNode, myModel, myBaseDirForLibrariesGetter);
node = new FrameworkSupportNode(provider, parentNode, myModel, myBaseDirForLibrariesGetter, this);
nodes.put(provider.getId(), node);
groups.put(provider.getGroupId(), node);
}
@@ -336,9 +342,10 @@ public class AddSupportForFrameworksPanel {
List<Library> addedLibraries = new ArrayList<Library>();
List<FrameworkSupportNode> selectedFrameworks = getFrameworkNodes(true);
sortFrameworks(selectedFrameworks);
List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<FrameworkSupportConfigurable>();
for (FrameworkSupportNode node : selectedFrameworks) {
FrameworkSupportConfigurable configurable = node.getConfigurable();
selectedConfigurables.add(configurable);
final LibraryCompositionSettings settings = node.getLibraryCompositionSettings();
Library library = settings != null ? settings.addLibraries(rootModel, addedLibraries) : null;
configurable.addSupport(module, rootModel, library);
@@ -349,6 +356,9 @@ public class AddSupportForFrameworksPanel {
((FacetBasedFrameworkSupportProvider)provider).processAddedLibraries(module, addedLibraries);
}
}
for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) {
communicator.onFrameworkSupportAdded(module, rootModel, selectedConfigurables, myModel);
}
}
private void sortFrameworks(final List<FrameworkSupportNode> nodes) {
@@ -15,18 +15,19 @@
*/
package com.intellij.ide.util.newProjectWizard;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionOptionsPanel;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.facet.impl.ui.libraries.LibraryDownloadingMirrorsMap;
import com.intellij.facet.ui.libraries.LibraryInfo;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
import com.intellij.ide.util.frameworkSupport.FrameworkVersion;
import com.intellij.facet.ui.libraries.LibraryInfo;
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.CheckedTreeNode;
import com.intellij.ui.GuiUtils;
import com.intellij.util.ui.UIUtil;
@@ -52,7 +53,7 @@ public class FrameworkSupportNode extends CheckedTreeNode {
private LibraryCompositionOptionsPanel myLibraryCompositionOptionsPanel;
FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelImpl model,
Computable<String> baseDirForLibrariesGetter) {
Computable<String> baseDirForLibrariesGetter, Disposable parentDisposable) {
super(provider);
myBaseDirForLibrariesGetter = baseDirForLibrariesGetter;
setChecked(false);
@@ -60,6 +61,7 @@ public class FrameworkSupportNode extends CheckedTreeNode {
myParentNode = parentNode;
model.registerComponent(provider, this);
myConfigurable = provider.createConfigurable(model);
Disposer.register(parentDisposable, myConfigurable);
if (parentNode != null) {
parentNode.add(this);
parentNode.myChildren.add(this);
@@ -5,11 +5,11 @@
package com.intellij.ide.util.newProjectWizard;
import com.intellij.CommonBundle;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil;
import com.intellij.ide.util.projectWizard.JavaModuleBuilder;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
import com.intellij.ide.wizard.CommitStepException;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
@@ -17,6 +17,7 @@ import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -60,6 +61,12 @@ public class SupportForFrameworksStep extends ModuleWizardStep {
return ICON;
}
@Override
public void disposeUIResources() {
Disposer.dispose(mySupportForFrameworksPanel);
super.disposeUIResources();
}
@NonNls
public String getHelpId() {
return "reference.dialogs.new.project.technologies";
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2010 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.ide.util.newProjectWizard.impl;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
import java.util.List;
/**
* @author nik
*/
public abstract class FrameworkSupportCommunicator {
public static final ExtensionPointName<FrameworkSupportCommunicator> EP_NAME = ExtensionPointName.create("com.intellij.frameworkSupportCommunicator");
public abstract void onFrameworkSupportAdded(Module module, ModifiableRootModel rootModel,
List<FrameworkSupportConfigurable> selectedFrameworks,
FrameworkSupportModel model);
}
@@ -26,7 +26,7 @@ import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.ui.ProjectJdksEditor;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.wm.ex.WindowManagerEx;
@@ -152,11 +152,11 @@ public class JdkChooserPanel extends JPanel {
jdks = getCompatibleJdks(type, Arrays.asList(allJdks));
}
else {
final ProjectJdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
if (!projectJdksModel.isInitialized()){ //should be initialized
projectJdksModel.reset(myProject);
}
final Collection<Sdk> collection = projectJdksModel.getProjectJdks().values();
final Collection<Sdk> collection = projectJdksModel.getProjectSdks().values();
jdks = getCompatibleJdks(type, collection);
}
Arrays.sort(jdks, new Comparator<Sdk>() {
@@ -25,7 +25,7 @@ import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.openapi.util.IconLoader;
@@ -80,7 +80,7 @@ public class ProjectJdkForModuleStep extends ModuleWizardStep {
final Project project = getProject(context, type);
final ProjectStructureConfigurable projectConfig = ProjectStructureConfigurable.getInstance(project);
final JdkListConfigurable jdkConfig = JdkListConfigurable.getInstance(project);
final ProjectJdksModel projectJdksModel = projectConfig.getProjectJdksModel();
final ProjectSdksModel projectJdksModel = projectConfig.getProjectJdksModel();
final boolean[] successfullyAdded = new boolean[1];
projectJdksModel.doAdd(type, myPanel, new Consumer<Sdk>() {
public void consume(final Sdk jdk) {
@@ -1,26 +0,0 @@
/*
* Copyright 2000-2009 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.projectRoots.ui;
import com.intellij.openapi.projectRoots.SdkModel;
/**
* @author Eugene Zhuravlev
* Date: Oct 4, 2004
*/
public interface NotifiableSdkModel extends SdkModel{
Listener getMulticaster();
}
@@ -1,417 +0,0 @@
/*
* Copyright 2000-2009 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.projectRoots.ui;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
import com.intellij.ui.ListUtil;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.components.JBList;
import com.intellij.util.Icons;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.UIUtil;
import gnu.trove.TIntArrayList;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
/**
* @author MYakovlev
*/
public abstract class PathEditor {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.projectRoots.ui.PathEditor");
public static final Color INVALID_COLOR = new Color(210, 0, 0);
private JPanel myPanel;
private JButton myRemoveButton;
private JButton myAddButton;
private JButton mySpecifyUrlButton;
private JList myList;
private DefaultListModel myModel;
private final Set<VirtualFile> myAllFiles = new HashSet<VirtualFile>();
private boolean myModified = false;
private boolean myEnabled = false;
private static final Icon ICON_INVALID = IconLoader.getIcon("/nodes/ppInvalid.png");
private static final Icon ICON_EMPTY = IconLoader.getIcon("/nodes/emptyNode.png");
protected abstract boolean isShowUrlButton();
protected abstract OrderRootType getRootType();
protected abstract FileChooserDescriptor createFileChooserDescriptor();
public abstract String getDisplayName();
public Icon getIcon(){
return null;
}
protected void setModified(boolean modified){
this.myModified = modified;
}
public boolean isModified(){
return myModified;
}
public void apply(SdkModificator sdkModificator) {
final OrderRootType rootType = getRootType();
sdkModificator.removeRoots(rootType);
// add all items
for (int i = 0; i < getRowCount(); i++){
sdkModificator.addRoot(getValueAt(i), rootType);
}
setModified(false);
updateButtons();
}
public VirtualFile[] getRoots() {
final int count = getRowCount();
if (count == 0) {
return VirtualFile.EMPTY_ARRAY;
}
final VirtualFile[] roots = new VirtualFile[count];
for (int i = 0; i < count; i++){
roots[i] = getValueAt(i);
}
return roots;
}
public void reset(VirtualFile[] files) {
keepSelectionState();
clearList();
myEnabled = files != null;
if(myEnabled){
for (int i = 0; i < files.length; i++){
addElement(files[i]);
}
}
setModified(false);
updateButtons();
}
public JComponent createComponent(){
myPanel = new JPanel(new GridBagLayout());
Insets anInsets = new Insets(2, 2, 2, 2);
myModel = new DefaultListModel();
myList = new JBList(myModel);
myList.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
updateButtons();
}
});
myList.setCellRenderer(new MyCellRenderer());
myRemoveButton = new JButton(ProjectBundle.message("button.remove"));
myAddButton = new JButton(ProjectBundle.message("button.add"));
mySpecifyUrlButton = new JButton(ProjectBundle.message("sdk.paths.specify.url.button"));
mySpecifyUrlButton.setVisible(isShowUrlButton());
myAddButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
final VirtualFile[] added = doAdd();
if (added.length > 0){
setModified(true);
}
updateButtons();
requestDefaultFocus();
setSelectedRoots(added);
}
});
myRemoveButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
java.util.List removedItems = ListUtil.removeSelectedItems(myList);
itemsRemoved(removedItems);
}
});
mySpecifyUrlButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, getInitialValue());
if(virtualFile != null){
addElement(virtualFile);
setModified(true);
updateButtons();
requestDefaultFocus();
setSelectedRoots(new Object[]{virtualFile});
}
}
});
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myList);
scrollPane.setPreferredSize(new Dimension(500, 500));
myPanel.add(scrollPane, new GridBagConstraints(0, 0, 1, 8, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, anInsets, 0, 0));
myPanel.add(myAddButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0));
myPanel.add(myRemoveButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0));
myPanel.add(mySpecifyUrlButton, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0));
myPanel.add(Box.createRigidArea(new Dimension(mySpecifyUrlButton.getPreferredSize().width, 4)), new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, anInsets, 0, 0));
return myPanel;
}
protected String getInitialValue() {
return "";
}
private void itemsRemoved(java.util.List removedItems) {
myAllFiles.removeAll(removedItems);
if (removedItems.size() > 0){
setModified(true);
}
updateButtons();
requestDefaultFocus();
}
private VirtualFile[] doAdd(){
FileChooserDescriptor descriptor = createFileChooserDescriptor();
VirtualFile[] files = FileChooser.chooseFiles(myPanel, descriptor);
files = adjustAddedFileSet(myPanel, files);
java.util.List<VirtualFile> added = new ArrayList<VirtualFile>(files.length);
for (int i = 0; i < files.length; i++){
VirtualFile vFile = files[i];
if(addElement(vFile)){
added.add(vFile);
}
}
return VfsUtil.toVirtualFileArray(added);
}
/**
* Implement this method to ajust adding behavior, this method is called right after the files
* or directories are selected for added. This method allows adding UI that modify file set.
*
* The default implemenation returns a value passed the parameter files and does nothing.
*
* @param component a component that could be used as a parent.
* @param files a selected file set
* @return ajusted file set
*/
protected VirtualFile[] adjustAddedFileSet(final Component component, final VirtualFile[] files) {
return files;
}
private void updateButtons(){
Object[] values = getSelectedRoots();
myRemoveButton.setEnabled((values.length > 0) && myEnabled);
myAddButton.setEnabled(myEnabled);
mySpecifyUrlButton.setEnabled(myEnabled && !isUrlInserted());
mySpecifyUrlButton.setVisible(isShowUrlButton());
}
private boolean isUrlInserted(){
if(getRowCount() > 0){
return ((VirtualFile)myModel.lastElement()).getFileSystem() instanceof HttpFileSystem;
}
return false;
}
private void requestDefaultFocus(){
if (myList != null){
myList.requestFocus();
}
}
public void addPaths(VirtualFile... paths){
boolean added = false;
keepSelectionState();
for (int i = 0; i < paths.length; i++){
final VirtualFile path = paths[i];
if(addElement(path)){
added = true;
}
}
if (added){
setModified(true);
updateButtons();
}
}
public void removePaths(VirtualFile... paths) {
final Set<VirtualFile> pathsSet = new java.util.HashSet<VirtualFile>(Arrays.asList(paths));
int size = getRowCount();
final TIntArrayList indicesToRemove = new TIntArrayList(paths.length);
for (int idx = 0; idx < size; idx++) {
VirtualFile path = getValueAt(idx);
if (pathsSet.contains(path)) {
indicesToRemove.add(idx);
}
}
final java.util.List list = ListUtil.removeIndices(myList, indicesToRemove.toNativeArray());
itemsRemoved(list);
}
/** Method adds element only if it is not added yet. */
protected boolean addElement(VirtualFile item){
if(item == null){
return false;
}
if (myAllFiles.contains(item)){
return false;
}
if(isUrlInserted()){
myModel.insertElementAt(item, myModel.size() - 1);
}
else{
myModel.addElement(item);
}
myAllFiles.add(item);
return true;
}
private void setSelectedRoots(Object[] roots){
ArrayList rootsList = new ArrayList(roots.length);
for (int i = 0; i < roots.length; i++){
Object root = roots[i];
if(root != null){
rootsList.add(root);
}
}
myList.getSelectionModel().clearSelection();
int rowCount = myModel.getSize();
for (int i = 0; i < rowCount; i++){
Object currObject = myModel.get(i);
LOG.assertTrue(currObject != null);
if (rootsList.contains(currObject)){
myList.getSelectionModel().addSelectionInterval(i, i);
}
}
}
private void keepSelectionState(){
final Object[] selectedItems = getSelectedRoots();
SwingUtilities.invokeLater(new Runnable(){
public void run(){
if (selectedItems != null){
setSelectedRoots(selectedItems);
}
}
});
}
protected Object[] getSelectedRoots(){
return myList.getSelectedValues();
}
private int getRowCount(){
return myModel.getSize();
}
private VirtualFile getValueAt(int row){
return (VirtualFile)myModel.get(row);
}
public void clearList(){
myModel.clear();
myAllFiles.clear();
setModified(true);
}
private static boolean isJarFile(final VirtualFile file){
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
public Boolean compute() {
VirtualFile tempFile = file;
if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null){
//[myakovlev] It was bug - directories with *.jar extensions was saved as files of JarFileSystem.
// so we can not just return true, we should filter such directories.
String path = file.getPath().substring(0, file.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
tempFile = LocalFileSystem.getInstance().findFileByPath(path);
}
if (tempFile != null && !tempFile.isDirectory()){
return Boolean.valueOf(FileTypeManager.getInstance().getFileTypeByFile(tempFile).equals(FileTypes.ARCHIVE));
}
return Boolean.FALSE;
}
} ).booleanValue();
}
/**
* @return icon for displaying parameter (ProjectRoot or VirtualFile)
* If parameter is not ProjectRoot or VirtualFile, returns empty icon "/nodes/emptyNode.png"
*/
private static Icon getIconForRoot(Object projectRoot){
if (projectRoot instanceof VirtualFile){
final VirtualFile file = (VirtualFile)projectRoot;
if (!file.isValid()){
return ICON_INVALID;
}
else if (isHttpRoot(file)){
return Icons.WEB_ICON;
}
else{
return isJarFile(file) ? Icons.JAR_ICON : Icons.FILE_ICON;
}
}
return ICON_EMPTY;
}
private static boolean isHttpRoot(VirtualFile virtualFileOrProjectRoot){
if(virtualFileOrProjectRoot != null){
return (virtualFileOrProjectRoot.getFileSystem() instanceof HttpFileSystem);
}
return false;
}
private final class MyCellRenderer extends DefaultListCellRenderer{
private String getPresentableString(final Object value){
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
public String compute() {
//noinspection HardCodedStringLiteral
return (value instanceof VirtualFile)? ((VirtualFile)value).getPresentableUrl() : "UNKNOWN OBJECT";
}
});
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){
super.getListCellRendererComponent(list, getPresentableString(value), index, isSelected, cellHasFocus);
if (isSelected){
setForeground(UIUtil.getListSelectionForeground());
}
else{
if (value instanceof VirtualFile){
VirtualFile file = (VirtualFile)value;
if (!file.isValid()){
setForeground(INVALID_COLOR);
}
}
}
setIcon(getIconForRoot(value));
return this;
}
}
}
@@ -18,13 +18,12 @@ package com.intellij.openapi.projectRoots.ui;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.*;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
import com.intellij.openapi.ui.Messages;
@@ -32,9 +31,7 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.navigation.History;
@@ -75,7 +72,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
// GUI components
private JPanel myMainPanel;
private TabbedPaneWrapper myTabbedPane;
private final NotifiableSdkModel mySdkModel;
private final SdkModel mySdkModel;
private JLabel myHomeFieldLabel;
private String myVersionString;
@@ -85,7 +82,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
private final Disposable myDisposable = Disposer.newDisposable();
public SdkEditor(NotifiableSdkModel sdkModel, History history, final ProjectJdkImpl sdk) {
public SdkEditor(SdkModel sdkModel, History history, final ProjectJdkImpl sdk) {
mySdkModel = sdkModel;
myHistory = history;
mySdk = sdk;
@@ -218,7 +215,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
else{
final SdkModificator sdkModificator = mySdk.getSdkModificator();
for (OrderRootType type : myPathEditors.keySet()) {
myPathEditors.get(type).reset(sdkModificator.getRoots(type));
myPathEditors.get(type).reset(sdkModificator);
}
sdkModificator.commitChanges();
setHomePathValue(mySdk.getHomePath().replace('/', File.separatorChar));
@@ -275,28 +272,9 @@ public class SdkEditor implements Configurable, Place.Navigator {
myHomeComponent.getTextField().setForeground(fg);
}
@Nullable
public static String selectSdkHome(final Component parentComponent, final SdkType sdkType){
final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
VirtualFile[] files = FileChooser.chooseFiles(parentComponent, descriptor, getSuggestedSdkRoot(sdkType));
if (files.length != 0){
final String path = files[0].getPath();
if (sdkType.isValidSdkHome(path)) return path;
return SystemInfo.isMac && sdkType.isValidSdkHome(path + SdkType.MAC_HOME_PATH) ? path + SdkType.MAC_HOME_PATH : null;
}
return null;
}
@Nullable
private static VirtualFile getSuggestedSdkRoot(SdkType sdkType) {
final String homepath = sdkType.suggestHomePath();
if (homepath == null) return null;
return LocalFileSystem.getInstance().findFileByPath(homepath);
}
private void doSelectHomePath(){
final SdkType sdkType = mySdk.getSdkType();
final String homePath = selectSdkHome(myHomeComponent, sdkType);
final String homePath = SdkConfigurationUtil.selectSdkHome(myHomeComponent, sdkType);
doSetHomePath(homePath, sdkType);
}
@@ -55,6 +55,7 @@ import com.intellij.ui.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.EventDispatcher;
import com.intellij.util.Icons;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.ItemRemovable;
import com.intellij.util.ui.Table;
import org.jetbrains.annotations.NotNull;
@@ -1091,7 +1092,7 @@ public class ClasspathPanel extends JPanel {
final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
final Library[] libraries = myLibraryTable.getLibraries();
for (Library library : libraries) {
alreadyAdded.addAll(Arrays.asList(library.getFiles(OrderRootType.CLASSES)));
ContainerUtil.addAll(alreadyAdded, library.getFiles(OrderRootType.CLASSES));
}
chosenFilesSet.removeAll(alreadyAdded);
return VfsUtil.toVirtualFileArray(chosenFilesSet);
@@ -23,12 +23,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.ScreenUtil;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Consumer;
import javax.swing.*;
@@ -47,7 +47,7 @@ import java.util.Comparator;
class JdkComboBox extends JComboBox{
private final JButton myEditButton = new JButton(ApplicationBundle.message("button.edit"));
public JdkComboBox(final ProjectJdksModel jdksModel) {
public JdkComboBox(final ProjectSdksModel jdksModel) {
super(new JdkComboBoxModel(jdksModel));
setRenderer(new ProjectJdkListRenderer() {
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
@@ -59,7 +59,7 @@ class JdkComboBox extends JComboBox{
else if (value instanceof ProjectJdkComboBoxItem){
final ProjectJdkComboBoxItem item = (ProjectJdkComboBoxItem)value;
final String str = item.toString();
final Sdk jdk = jdksModel.getProjectJdk();
final Sdk jdk = jdksModel.getProjectSdk();
if (jdk != null){
setIcon(jdk.getSdkType().getIcon());
append(ProjectBundle.message("project.roots.project.jdk.inherited"), SimpleTextAttributes.REGULAR_ATTRIBUTES);
@@ -97,13 +97,13 @@ class JdkComboBox extends JComboBox{
return minSize;
}
public JButton createSetupButton(final Project project, final ProjectJdksModel jdksModel, final JdkComboBoxItem firstItem) {
public JButton createSetupButton(final Project project, final ProjectSdksModel jdksModel, final JdkComboBoxItem firstItem) {
return createSetupButton(project, jdksModel, firstItem, null, false);
}
public JButton createSetupButton(final Project project,
final ProjectJdksModel jdksModel,
final ProjectSdksModel jdksModel,
final JdkComboBoxItem firstItem,
final Condition<Sdk> additionalSetup,
final boolean moduleJdkSetup) {
@@ -144,7 +144,7 @@ class JdkComboBox extends JComboBox{
public void actionPerformed(ActionEvent e) {
final JdkComboBoxItem selectedItem = getSelectedItem();
if (selectedItem instanceof ProjectJdkComboBoxItem) {
myEditButton.setEnabled(ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectJdk() != null);
myEditButton.setEnabled(ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectSdk() != null);
} else {
myEditButton.setEnabled(!(selectedItem instanceof InvalidJdkComboBoxItem) && selectedItem != null && selectedItem.getJdk() != null);
}
@@ -212,7 +212,8 @@ class JdkComboBox extends JComboBox{
final DefaultComboBoxModel model = ((DefaultComboBoxModel)getModel());
model.removeAllElements();
model.addElement(firstItem);
final ArrayList<Sdk> projectJdks = new ArrayList<Sdk>(ProjectJdksModel.getInstance(project).getProjectJdks().values());
final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
final ArrayList<Sdk> projectJdks = new ArrayList<Sdk>(projectJdksModel.getProjectSdks().values());
Collections.sort(projectJdks, new Comparator<Sdk>() {
public int compare(final Sdk o1, final Sdk o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
@@ -224,7 +225,7 @@ class JdkComboBox extends JComboBox{
}
private static class JdkComboBoxModel extends DefaultComboBoxModel {
public JdkComboBoxModel(final ProjectJdksModel jdksModel) {
public JdkComboBoxModel(final ProjectSdksModel jdksModel) {
super();
final Sdk[] jdks = jdksModel.getSdks();
Arrays.sort(jdks, new Comparator<Sdk>() {
@@ -37,6 +37,7 @@ import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.navigation.History;
import com.intellij.ui.navigation.Place;
import com.intellij.util.EventDispatcher;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -187,8 +188,8 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
private static ModuleConfigurationEditorProvider[] collectProviders(final Module module) {
List<ModuleConfigurationEditorProvider> result = new ArrayList<ModuleConfigurationEditorProvider>();
result.addAll(Arrays.asList(module.getComponents(ModuleConfigurationEditorProvider.class)));
result.addAll(Arrays.asList(Extensions.getExtensions(ModuleConfigurationEditorProvider.EP_NAME, module)));
ContainerUtil.addAll(result, module.getComponents(ModuleConfigurationEditorProvider.class));
ContainerUtil.addAll(result, Extensions.getExtensions(ModuleConfigurationEditorProvider.EP_NAME, module));
return result.toArray(new ModuleConfigurationEditorProvider[result.size()]);
}
@@ -208,7 +209,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
private void processEditorsProvider(final ModuleConfigurationEditorProvider provider, final ModuleConfigurationState state) {
final ModuleConfigurationEditor[] editors = provider.createEditors(state);
myEditors.addAll(Arrays.asList(editors));
ContainerUtil.addAll(myEditors, editors);
}
private JPanel createPanel() {
@@ -24,7 +24,7 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModel;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
import com.intellij.openapi.ui.DialogWrapper;
@@ -47,7 +47,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
private Sdk mySelectedModuleJdk = null;
private JPanel myJdkPanel;
private ClasspathEditor myModuleEditor;
private final ProjectJdksModel myJdksModel;
private final ProjectSdksModel myJdksModel;
private boolean myFreeze = false;
private final SdkModel.Listener myListener = new SdkModel.Listener() {
public void sdkAdded(Sdk sdk) {
@@ -67,7 +67,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
}
};
public ModuleJdkConfigurable(ClasspathEditor moduleEditor, ProjectJdksModel jdksModel) {
public ModuleJdkConfigurable(ClasspathEditor moduleEditor, ProjectSdksModel jdksModel) {
myModuleEditor = moduleEditor;
myJdksModel = jdksModel;
myJdksModel.addListener(myListener);
@@ -122,7 +122,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
final JButton setUpButton = myCbModuleJdk
.createSetupButton(project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(), new Condition<Sdk>(){
public boolean value(Sdk jdk) {
final Sdk projectJdk = myJdksModel.getProjectJdk();
final Sdk projectJdk = myJdksModel.getProjectSdk();
if (projectJdk == null){
final int res =
Messages.showYesNoDialog(myJdkPanel,
@@ -130,7 +130,7 @@ public abstract class ModuleJdkConfigurable implements Disposable {
ProjectBundle.message("project.roots.no.jdk.on.projecct.title"),
Messages.getInformationIcon());
if (res == DialogWrapper.OK_EXIT_CODE){
myJdksModel.setProjectJdk(jdk);
myJdksModel.setProjectSdk(jdk);
return true;
}
}
@@ -41,7 +41,7 @@ import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.impl.ProjectRootManagerImpl;
import com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
import com.intellij.openapi.ui.Messages;
@@ -91,7 +91,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
private StructureConfigurableContext myContext;
private final List<ModuleEditor.ChangeListener> myAllModulesChangeListeners = new ArrayList<ModuleEditor.ChangeListener>();
public ModulesConfigurator(Project project, ProjectJdksModel projectJdksModel) {
public ModulesConfigurator(Project project, ProjectSdksModel projectJdksModel) {
myProject = project;
myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel();
myProjectConfigurable = new ProjectConfigurable(project, this, projectJdksModel);
@@ -20,15 +20,12 @@
*/
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ui.PathEditor;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryElement;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableTreeContentElement;
import com.intellij.openapi.util.KeyedExtensionFactory;
import com.intellij.pom.java.LanguageLevel;
public interface OrderRootTypeUIFactory {
KeyedExtensionFactory<OrderRootTypeUIFactory, OrderRootType> FACTORY = new KeyedExtensionFactory<OrderRootTypeUIFactory, OrderRootType>(OrderRootTypeUIFactory.class, "com.intellij.OrderRootTypeUI") {
@@ -39,56 +36,4 @@ public interface OrderRootTypeUIFactory {
LibraryTableTreeContentElement createElement(final LibraryElement parentElement);
PathEditor createPathEditor(Sdk sdk);
class MyPathsEditor extends PathEditor {
private final boolean myShowUrl;
private final OrderRootType myOrderRootType;
private final FileChooserDescriptor myDescriptor;
private final String myDisplayName;
private final Sdk mySdk;
public MyPathsEditor(final String displayName,
final OrderRootType orderRootType,
final FileChooserDescriptor descriptor,
final boolean showUrl,
Sdk sdk) {
myShowUrl = showUrl;
myOrderRootType = orderRootType;
myDescriptor = descriptor;
myDisplayName = displayName;
mySdk = sdk;
}
protected boolean isShowUrlButton() {
return myShowUrl;
}
protected OrderRootType getRootType() {
return myOrderRootType;
}
protected FileChooserDescriptor createFileChooserDescriptor() {
return myDescriptor;
}
public String getDisplayName() {
return myDisplayName;
}
@Override
protected String getInitialValue() {
if (mySdk != null) {
final String versionString = mySdk.getVersionString();
if (versionString != null) {
final LanguageLevel level = LanguageLevelUtil.getDefaultLanguageLevel(versionString);
if (level == LanguageLevel.JDK_1_5) {
return "http://java.sun.com/j2se/1.5.0/docs/api/";
} else if (level == LanguageLevel.JDK_1_6) {
return "http://java.sun.com/j2se/6/docs/api/";
}
}
}
return "";
}
}
}
@@ -27,7 +27,7 @@ import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.DetailsComponent;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.NamedConfigurable;
@@ -82,7 +82,7 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
private boolean myFreeze = false;
private DetailsComponent myDetailsComponent;
public ProjectConfigurable(Project project, ModulesConfigurator configurator, ProjectJdksModel model) {
public ProjectConfigurable(Project project, ModulesConfigurator configurator, ProjectSdksModel model) {
myProject = project;
myModulesConfigurator = configurator;
init(model);
@@ -103,7 +103,7 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
return myDetailsComponent.getComponent();
}
private void init(final ProjectJdksModel model) {
private void init(final ProjectSdksModel model) {
myPanel = new MyJPanel();
myPanel.setPreferredSize(new Dimension(700, 500));
@@ -25,7 +25,7 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModel;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
import com.intellij.openapi.util.Comparing;
@@ -45,7 +45,7 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
private JdkComboBox myCbProjectJdk;
private JPanel myJdkPanel;
private final Project myProject;
private final ProjectJdksModel myJdksModel;
private final ProjectSdksModel myJdksModel;
private final SdkModel.Listener myListener = new SdkModel.Listener() {
public void sdkAdded(Sdk sdk) {
reloadModel();
@@ -66,7 +66,7 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
private boolean myFreeze = false;
public ProjectJdkConfigurable(Project project, final ProjectJdksModel jdksModel) {
public ProjectJdkConfigurable(Project project, final ProjectSdksModel jdksModel) {
myProject = project;
myJdksModel = jdksModel;
myJdksModel.addListener(myListener);
@@ -84,7 +84,7 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
private void reloadModel() {
myFreeze = true;
final Sdk projectJdk = myJdksModel.getProjectJdk();
final Sdk projectJdk = myJdksModel.getProjectSdk();
myCbProjectJdk.reloadModel(new JdkComboBox.NoneJdkComboBoxItem(), myProject);
final String sdkName = projectJdk == null ? ProjectRootManager.getInstance(myProject).getProjectJdkName() : projectJdk.getName();
if (sdkName != null) {
@@ -108,8 +108,8 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
myCbProjectJdk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (myFreeze) return;
final Sdk oldJdk = myJdksModel.getProjectJdk();
myJdksModel.setProjectJdk(myCbProjectJdk.getSelectedJdk());
final Sdk oldJdk = myJdksModel.getProjectSdk();
myJdksModel.setProjectSdk(myCbProjectJdk.getSelectedJdk());
clearCaches();
}
});
@@ -120,7 +120,7 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
myCbProjectJdk.appendEditButton(myProject, myJdkPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0), new Computable<Sdk>() {
@Nullable
public Sdk compute() {
return myJdksModel.getProjectJdk();
return myJdksModel.getProjectSdk();
}
});
}
@@ -32,7 +32,7 @@ import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.intellij.openapi.roots.ui.configuration.projectRoot.JdkConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
@@ -56,7 +56,7 @@ import java.util.Set;
public class ProjectJdksConfigurable extends MasterDetailsComponent implements Configurable.Assistant {
private final ProjectJdksModel myProjectJdksModel;
private final ProjectSdksModel myProjectJdksModel;
private final Project myProject;
@NonNls
private static final String SPLITTER_PROPORTION = "project.jdk.splitter";
@@ -64,7 +64,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent implements C
public ProjectJdksConfigurable(Project project) {
super();
myProject = project;
myProjectJdksModel = ProjectJdksModel.getInstance(project);
myProjectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
MasterDetailsStateService.getInstance(project).register("ProjectJDKs.UI", this);
initTree();
}
@@ -86,12 +86,12 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent implements C
myProjectJdksModel.reset(myProject);
myRoot.removeAllChildren();
final HashMap<Sdk, Sdk> sdks = myProjectJdksModel.getProjectJdks();
final HashMap<Sdk, Sdk> sdks = myProjectJdksModel.getProjectSdks();
for (Sdk sdk : sdks.keySet()) {
final JdkConfigurable configurable = new JdkConfigurable((ProjectJdkImpl)sdks.get(sdk), myProjectJdksModel, TREE_UPDATER, myHistory, myProject);
addNode(new MyNode(configurable), myRoot);
}
selectJdk(myProjectJdksModel.getProjectJdk()); //restore selection
selectJdk(myProjectJdksModel.getProjectSdk()); //restore selection
final String value = PropertiesComponent.getInstance().getValue(SPLITTER_PROPORTION);
if (value != null) {
try {
@@ -127,7 +127,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent implements C
}
if (myProjectJdksModel.isModified() || modifiedJdks) myProjectJdksModel.apply(this);
myProjectJdksModel.setProjectJdk(getSelectedJdk());
myProjectJdksModel.setProjectSdk(getSelectedJdk());
}
@@ -168,17 +168,17 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent implements C
final NamedConfigurable namedConfigurable = (NamedConfigurable)node.getUserObject();
jdks.add(((JdkConfigurable)namedConfigurable).getEditableObject());
}
final HashMap<Sdk, Sdk> sdks = new HashMap<Sdk, Sdk>(myProjectJdksModel.getProjectJdks());
final HashMap<Sdk, Sdk> sdks = new HashMap<Sdk, Sdk>(myProjectJdksModel.getProjectSdks());
for (Sdk sdk : sdks.values()) {
if (!jdks.contains(sdk)) {
myProjectJdksModel.removeJdk(sdk);
myProjectJdksModel.removeSdk(sdk);
}
}
}
protected boolean wasObjectStored(Object editableObject) {
//noinspection RedundantCast
return myProjectJdksModel.getProjectJdks().containsKey((Sdk)editableObject);
return myProjectJdksModel.getProjectSdks().containsKey((Sdk)editableObject);
}
@Nullable
@@ -84,7 +84,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
private Configurable mySelectedConfigurable;
private final ProjectJdksModel myProjectJdksModel = new ProjectJdksModel();
private final ProjectSdksModel myProjectJdksModel = new ProjectSdksModel();
private ProjectConfigurable myProjectConfig;
private final ProjectLibrariesConfigurable myProjectLibrariesConfig;
@@ -473,7 +473,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
return ShowSettingsUtil.getInstance().findProjectConfigurable(project, ProjectStructureConfigurable.class);
}
public ProjectJdksModel getProjectJdksModel() {
public ProjectSdksModel getProjectJdksModel() {
return myProjectJdksModel;
}
@@ -22,7 +22,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.impl.RootConfigurationAccessor;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import org.jetbrains.annotations.Nullable;
@@ -51,7 +51,7 @@ public class UIRootConfigurationAccessor extends RootConfigurationAccessor {
@Nullable
public Sdk getSdk(final Sdk sdk, final String sdkName) {
final ProjectJdksModel model = ProjectStructureConfigurable.getInstance(myProject).getJdkConfig().getJdksTreeModel();
final ProjectSdksModel model = ProjectStructureConfigurable.getInstance(myProject).getJdkConfig().getJdksTreeModel();
return sdkName != null ? model.findSdk(sdkName) : sdk;
}
@@ -63,9 +63,10 @@ public class UIRootConfigurationAccessor extends RootConfigurationAccessor {
}
public Sdk getProjectSdk(final Project project) {
return ProjectJdksModel.getInstance(project).getProjectJdk();
return ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectSdk();
}
@Nullable
public String getProjectSdkName(final Project project) {
final String projectJdkName = ProjectRootManager.getInstance(project).getProjectJdkName();
final Sdk projectJdk = getProjectSdk(project);
@@ -73,7 +74,8 @@ public class UIRootConfigurationAccessor extends RootConfigurationAccessor {
return projectJdk.getName();
}
else {
return ProjectJdksModel.getInstance(project).findSdk(projectJdkName) == null ? projectJdkName : null;
final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
return projectJdksModel.findSdk(projectJdkName) == null ? projectJdkName : null;
}
}
}
@@ -19,6 +19,7 @@ import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ComplexPackag
import com.intellij.packaging.elements.ComplexPackagingElement;
import com.intellij.packaging.elements.ComplexPackagingElementType;
import com.intellij.packaging.elements.PackagingElementFactory;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -31,7 +32,7 @@ public class ComplexElementSubstitutionParameters {
private final Set<ComplexPackagingElement<?>> mySubstituted = new HashSet<ComplexPackagingElement<?>>();
public void setSubstituteAll() {
myTypesToSubstitute.addAll(Arrays.asList(PackagingElementFactory.getInstance().getComplexElementTypes()));
ContainerUtil.addAll(myTypesToSubstitute, PackagingElementFactory.getInstance().getComplexElementTypes());
mySubstituted.clear();
}
@@ -33,7 +33,7 @@ public class AnnotationsOrderRootTypeUIFactory implements OrderRootTypeUIFactory
}
public PathEditor createPathEditor(Sdk sdk) {
return new MyPathsEditor(ProjectBundle.message("sdk.configure.annotations.tab"), AnnotationOrderRootType.getInstance(),
FileChooserDescriptorFactory.createSingleFolderDescriptor(), false, sdk);
return new PathEditor(ProjectBundle.message("sdk.configure.annotations.tab"), AnnotationOrderRootType.getInstance(),
FileChooserDescriptorFactory.createSingleFolderDescriptor());
}
}
@@ -33,7 +33,6 @@ public class ClassesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
}
public PathEditor createPathEditor(Sdk sdk) {
return new MyPathsEditor(ProjectBundle.message("sdk.configure.classpath.tab"), OrderRootType.CLASSES, new FileChooserDescriptor(true, true, true, false, true, true), false,
sdk);
return new PathEditor(ProjectBundle.message("sdk.configure.classpath.tab"), OrderRootType.CLASSES, new FileChooserDescriptor(true, true, true, false, true, true));
}
}
@@ -21,11 +21,15 @@
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ui.PathEditor;
import com.intellij.openapi.projectRoots.ui.Util;
import com.intellij.openapi.roots.JavadocOrderRootType;
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
public class JavadocOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
public LibraryTableTreeContentElement createElement(final LibraryElement parentElement) {
@@ -33,7 +37,49 @@ public class JavadocOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
}
public PathEditor createPathEditor(Sdk sdk) {
return new MyPathsEditor(ProjectBundle.message("sdk.configure.javadoc.tab"), JavadocOrderRootType.getInstance(), new FileChooserDescriptor(false, true, true, false, true, true), true,
sdk);
return new JavadocPathsEditor(sdk);
}
static class JavadocPathsEditor extends PathEditor {
private final Sdk mySdk;
public JavadocPathsEditor(Sdk sdk) {
super(ProjectBundle.message("sdk.configure.javadoc.tab"),
JavadocOrderRootType.getInstance(),
new FileChooserDescriptor(false, true, true, false, true, true));
mySdk = sdk;
}
@Override
protected boolean isShowUrlButton() {
return true;
}
@Override
protected void onSpecifyUrlButtonClicked() {
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, getInitialValue());
if(virtualFile != null){
addElement(virtualFile);
setModified(true);
updateButtons();
requestDefaultFocus();
setSelectedRoots(new Object[]{virtualFile});
}
}
private String getInitialValue() {
if (mySdk != null) {
final String versionString = mySdk.getVersionString();
if (versionString != null) {
final LanguageLevel level = LanguageLevelUtil.getDefaultLanguageLevel(versionString);
if (level == LanguageLevel.JDK_1_5) {
return "http://java.sun.com/j2se/1.5.0/docs/api/";
} else if (level == LanguageLevel.JDK_1_6) {
return "http://java.sun.com/j2se/6/docs/api/";
}
}
}
return "";
}
}
}
@@ -30,9 +30,7 @@ import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.ui.Util;
import com.intellij.openapi.roots.AnnotationOrderRootType;
import com.intellij.openapi.roots.JavadocOrderRootType;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
import com.intellij.openapi.roots.libraries.Library;
@@ -62,6 +60,7 @@ import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Icons;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -471,10 +470,11 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
final List<Module> modules = new ArrayList<Module>();
modules.addAll(Arrays.asList(rootConfigurable.getModules()));
ContainerUtil.addAll(modules, rootConfigurable.getModules());
final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
modules, ProjectBundle.message("choose.modules.dialog.title"),
ProjectBundle.message("choose.modules.dialog.description", libraryToSelect.getName()));
ProjectBundle
.message("choose.modules.dialog.description", libraryToSelect.getName()));
dlg.show();
if (dlg.isOK()) {
final List<Module> choosenModules = dlg.getChosenElements();
@@ -596,12 +596,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
final Library[] libraries = myTableModifiableModel.getLibraries();
for (Library library : libraries) {
final VirtualFile[] libraryFiles = getLibraryEditor(library).getFiles(rootType);
alreadyAdded.addAll(Arrays.asList(libraryFiles));
ContainerUtil.addAll(alreadyAdded, libraryFiles);
}
}
else {
final VirtualFile[] libraryFiles = getLibraryEditor(lib).getFiles(rootType);
alreadyAdded.addAll(Arrays.asList(libraryFiles));
ContainerUtil.addAll(alreadyAdded, libraryFiles);
}
chosenFilesSet.removeAll(alreadyAdded);
return VfsUtil.toVirtualFileArray(chosenFilesSet);
@@ -37,8 +37,7 @@ public class SourcesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
}
public PathEditor createPathEditor(Sdk sdk) {
return new MyPathsEditor(ProjectBundle.message("sdk.configure.sourcepath.tab"), OrderRootType.SOURCES, new FileChooserDescriptor(true, true, true, false, true, true), false,
sdk) {
return new PathEditor(ProjectBundle.message("sdk.configure.sourcepath.tab"), OrderRootType.SOURCES, new FileChooserDescriptor(true, true, true, false, true, true)) {
@Override
protected VirtualFile[] adjustAddedFileSet(final Component component, final VirtualFile[] files) {
return PathUIUtils.scanAndSelectDetectedJavaSourceRoots(component, files);
@@ -43,7 +43,7 @@ public class JdkConfigurable extends ProjectStructureElementConfigurable<Sdk> im
private final SdkProjectStructureElement myProjectStructureElement;
public JdkConfigurable(final ProjectJdkImpl projectJdk,
final ProjectJdksModel configurable,
final ProjectSdksModel configurable,
final Runnable updateTree, @NotNull History history, Project project) {
super(true, updateTree);
myProjectJdk = projectJdk;
@@ -56,7 +56,7 @@ import java.util.List;
)
public class JdkListConfigurable extends BaseStructureConfigurable {
private final ProjectJdksModel myJdksTreeModel;
private final ProjectSdksModel myJdksTreeModel;
SdkModel.Listener myListener = new SdkModel.Listener() {
@@ -124,7 +124,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
}
protected void loadTree() {
final HashMap<Sdk,Sdk> sdks = myJdksTreeModel.getProjectJdks();
final HashMap<Sdk,Sdk> sdks = myJdksTreeModel.getProjectSdks();
for (Sdk sdk : sdks.keySet()) {
final JdkConfigurable configurable = new JdkConfigurable((ProjectJdkImpl)sdks.get(sdk), myJdksTreeModel, TREE_UPDATER, myHistory,
myProject);
@@ -136,7 +136,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
@Override
protected Collection<? extends ProjectStructureElement> getProjectStructureElements() {
final List<ProjectStructureElement> result = new ArrayList<ProjectStructureElement>();
for (Sdk sdk : myJdksTreeModel.getProjectJdks().values()) {
for (Sdk sdk : myJdksTreeModel.getProjectSdks().values()) {
result.add(new SdkProjectStructureElement(myContext, sdk));
}
return result;
@@ -159,7 +159,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
myJdksTreeModel.disposeUIResources();
}
public ProjectJdksModel getJdksTreeModel() {
public ProjectSdksModel getJdksTreeModel() {
return myJdksTreeModel;
}
@@ -179,7 +179,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
}
if (myJdksTreeModel.isModified() || modifiedJdks) myJdksTreeModel.apply(this);
myJdksTreeModel.setProjectJdk(ProjectRootManager.getInstance(myProject).getProjectJdk());
myJdksTreeModel.setProjectSdk(ProjectRootManager.getInstance(myProject).getProjectJdk());
}
public boolean isModified() {
@@ -205,7 +205,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
}
protected void removeJdk(final Sdk jdk) {
myJdksTreeModel.removeJdk(jdk);
myJdksTreeModel.removeSdk(jdk);
myContext.getDaemonAnalyzer().removeElement(new SdkProjectStructureElement(myContext, jdk));
}
@@ -1,87 +0,0 @@
/*
* Copyright 2000-2009 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.roots.ui.configuration.projectRoot;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.ui.PanelWithText;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* User: anna
* Date: 05-Jun-2006
*/
public class JdksConfigurable extends NamedConfigurable<ProjectJdksModel> {
private final ProjectJdksModel myJdkTableConfigurable;
public static final String JDKS = ProjectBundle.message("jdks.node.display.name");
public static final Icon ICON = IconLoader.getIcon("/modules/jdks.png");
public JdksConfigurable(final ProjectJdksModel jdksTreeModel) {
myJdkTableConfigurable = jdksTreeModel;
}
public void setDisplayName(final String name) {
//do nothing
}
public ProjectJdksModel getEditableObject() {
return myJdkTableConfigurable;
}
public String getBannerSlogan() {
return JDKS;
}
public String getDisplayName() {
return JDKS;
}
public Icon getIcon() {
return ICON;
}
@Nullable
@NonNls
public String getHelpTopic() { //todo help
return "preferences.jdks";
}
public JComponent createOptionsPanel() {
return new PanelWithText(ProjectBundle.message("project.roots.jdks.node.text"));
}
public boolean isModified() {
return false;
}
public void apply() throws ConfigurationException {
}
public void reset() {
}
public void disposeUIResources() {
}
}
@@ -63,6 +63,7 @@ import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.navigation.Place;
import com.intellij.util.Consumer;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -649,7 +650,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
result.add(new Separator(ProjectBundle.message("add.group.facet.separator")));
}
result.addAll(Arrays.asList(facets));
ContainerUtil.addAll(result, facets);
return result.toArray(new AnAction[result.size()]);
}
@@ -1,271 +0,0 @@
/*
* Copyright 2000-2009 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.roots.ui.configuration.projectRoot;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.*;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
import com.intellij.openapi.projectRoots.ui.NotifiableSdkModel;
import com.intellij.openapi.projectRoots.ui.SdkEditor;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
/**
* User: anna
* Date: 05-Jun-2006
*/
public class ProjectJdksModel implements NotifiableSdkModel {
private static final Logger LOG = Logger.getInstance("com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel");
private final HashMap<Sdk, Sdk> myProjectJdks = new HashMap<Sdk, Sdk>();
private final EventDispatcher<Listener> mySdkEventsDispatcher = EventDispatcher.create(SdkModel.Listener.class);
private boolean myModified = false;
private Sdk myProjectJdk;
private boolean myInitialized = false;
public static ProjectJdksModel getInstance(Project project){
return ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
}
public Listener getMulticaster() {
return mySdkEventsDispatcher.getMulticaster();
}
public Sdk[] getSdks() {
return myProjectJdks.values().toArray(new Sdk[myProjectJdks.size()]);
}
@Nullable
public Sdk findSdk(String sdkName) {
for (Sdk projectJdk : myProjectJdks.values()) {
if (Comparing.strEqual(projectJdk.getName(), sdkName)) return projectJdk;
}
return null;
}
public void addListener(Listener listener) {
mySdkEventsDispatcher.addListener(listener);
}
public void removeListener(Listener listener) {
mySdkEventsDispatcher.removeListener(listener);
}
public void reset(Project project) {
myProjectJdks.clear();
final Sdk[] projectJdks = ProjectJdkTable.getInstance().getAllJdks();
for (Sdk jdk : projectJdks) {
try {
myProjectJdks.put(jdk, (Sdk)jdk.clone());
}
catch (CloneNotSupportedException e) {
//can't be
}
}
myProjectJdk = findSdk(ProjectRootManager.getInstance(project).getProjectJdkName());
myModified = false;
myInitialized = true;
}
public void disposeUIResources() {
myProjectJdks.clear();
myInitialized = false;
}
public HashMap<Sdk, Sdk> getProjectJdks() {
return myProjectJdks;
}
public boolean isModified(){
return myModified;
}
public void apply(MasterDetailsComponent configurable) throws ConfigurationException {
String[] errorString = new String[1];
if (!canApply(errorString, configurable)) {
throw new ConfigurationException(errorString[0]);
}
final Sdk[] allFromTable = ProjectJdkTable.getInstance().getAllJdks();
final ArrayList<Sdk> itemsInTable = new ArrayList<Sdk>();
// Delete removed and fill itemsInTable
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
for (final Sdk tableItem : allFromTable) {
if (myProjectJdks.containsKey(tableItem)) {
itemsInTable.add(tableItem);
}
else {
jdkTable.removeJdk(tableItem);
}
}
}
});
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
// Now all removed items are deleted from table, itemsInTable contains all items in table
final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
for (Sdk originalJdk : itemsInTable) {
final Sdk modifiedJdk = myProjectJdks.get(originalJdk);
LOG.assertTrue(modifiedJdk != null);
jdkTable.updateJdk(originalJdk, modifiedJdk);
}
// Add new items to table
final Sdk[] allJdks = jdkTable.getAllJdks();
for (final Sdk projectJdk : myProjectJdks.keySet()) {
LOG.assertTrue(projectJdk != null);
if (ArrayUtil.find(allJdks, projectJdk) == -1) {
jdkTable.addJdk(projectJdk);
}
}
}
});
myModified = false;
}
private boolean canApply(String[] errorString, MasterDetailsComponent rootConfigurable) throws ConfigurationException {
ArrayList<String> allNames = new ArrayList<String>();
Sdk itemWithError = null;
for (Sdk currItem : myProjectJdks.values()) {
String currName = currItem.getName();
if (currName.length() == 0) {
itemWithError = currItem;
errorString[0] = ProjectBundle.message("sdk.list.name.required.error");
break;
}
if (allNames.contains(currName)) {
itemWithError = currItem;
errorString[0] = ProjectBundle.message("sdk.list.unique.name.required.error");
break;
}
final SdkAdditionalData sdkAdditionalData = currItem.getSdkAdditionalData();
if (sdkAdditionalData != null) {
try {
sdkAdditionalData.checkValid(this);
}
catch (ConfigurationException e) {
final Object projectJdk = rootConfigurable.getSelectedObject();
if (!(projectJdk instanceof Sdk) ||
!Comparing.strEqual(((Sdk)projectJdk).getName(), currName)){ //do not leave current item with current name
rootConfigurable.selectNodeInTree(currName);
}
throw new ConfigurationException(ProjectBundle.message("sdk.configuration.exception", currName) + " " + e.getMessage());
}
}
allNames.add(currName);
}
if (itemWithError == null) return true;
rootConfigurable.selectNodeInTree(itemWithError.getName());
return false;
}
public void removeJdk(final Sdk editableObject) {
Sdk projectJdk = null;
for (Sdk jdk : myProjectJdks.keySet()) {
if (myProjectJdks.get(jdk) == editableObject) {
projectJdk = jdk;
break;
}
}
if (projectJdk != null) {
myProjectJdks.remove(projectJdk);
mySdkEventsDispatcher.getMulticaster().beforeSdkRemove(projectJdk);
myModified = true;
}
}
public void createAddActions(DefaultActionGroup group, final JComponent parent, final Consumer<Sdk> updateTree) {
final SdkType[] types = SdkType.getAllTypes();
for (final SdkType type : types) {
final AnAction addAction = new DumbAwareAction(type.getPresentableName(),
null,
type.getIconForAddAction()) {
public void actionPerformed(AnActionEvent e) {
doAdd(type, parent, updateTree);
}
};
group.add(addAction);
}
}
public void doAdd(final SdkType type, JComponent parent, final Consumer<Sdk> updateTree) {
myModified = true;
final String home = SdkEditor.selectSdkHome(parent, type);
if (home == null) {
return;
}
String newSdkName = SdkConfigurationUtil.createUniqueSdkName(type, home, myProjectJdks.values());
final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, type);
newJdk.setHomePath(home);
if (!type.setupSdkPaths(newJdk, this)) return;
if (newJdk.getVersionString() == null) {
Messages.showMessageDialog(ProjectBundle.message("sdk.java.corrupt.error", home),
ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
}
myProjectJdks.put(newJdk, newJdk);
updateTree.consume(newJdk);
mySdkEventsDispatcher.getMulticaster().sdkAdded(newJdk);
}
@Nullable
public Sdk findSdk(@Nullable final Sdk modelJdk) {
for (Sdk jdk : myProjectJdks.keySet()) {
if (Comparing.equal(myProjectJdks.get(jdk), modelJdk)) return jdk;
}
return null;
}
@Nullable
public Sdk getProjectJdk() {
if (!myProjectJdks.containsValue(myProjectJdk)) return null;
return myProjectJdk;
}
public void setProjectJdk(final Sdk projectJdk) {
myProjectJdk = projectJdk;
}
public boolean isInitialized() {
return myInitialized;
}
}
@@ -34,9 +34,7 @@ import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.InvalidDataException;
@@ -73,11 +71,22 @@ public abstract class ProjectOpenProcessorBase extends ProjectOpenProcessor {
public boolean canOpenProject(final VirtualFile file) {
final String[] supported = getSupportedExtensions();
if (supported != null) {
final String fileName = file.getName();
for (String name : supported) {
if (fileName.equals(name)) {
return true;
if (file.isDirectory()) {
for (VirtualFile child : file.getChildren()) {
if (canOpenFile(child, supported)) return true;
}
return false;
}
if (canOpenFile(file, supported)) return true;
}
return false;
}
protected static boolean canOpenFile(VirtualFile file, String[] supported) {
final String fileName = file.getName();
for (String name : supported) {
if (fileName.equals(name)) {
return true;
}
}
return false;
@@ -98,6 +107,15 @@ public abstract class ProjectOpenProcessorBase extends ProjectOpenProcessor {
public Project doOpenProject(@NotNull VirtualFile virtualFile, Project projectToClose, boolean forceOpenInNewFrame) {
try {
final WizardContext wizardContext = new WizardContext(null);
if (virtualFile.isDirectory()) {
final String[] supported = getSupportedExtensions();
for (VirtualFile file : virtualFile.getChildren()) {
if (canOpenFile(file, supported)) {
virtualFile = file;
break;
}
}
}
if (!doQuickImport(virtualFile, wizardContext)) return null;
if (wizardContext.getProjectName() == null) {