diff --git a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java index bd91db835dd9..b6abaf5cf37c 100644 --- a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java @@ -47,6 +47,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Set; /** @@ -56,7 +57,7 @@ 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; + protected JPanel myPanel; private JButton myRemoveButton; private JButton myAddButton; private JButton mySpecifyUrlButton; @@ -70,18 +71,17 @@ public abstract class PathEditor { protected abstract boolean isShowUrlButton(); + protected void onSpecifyUrlButtonClicked() { + } + 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; + myModified = modified; } public boolean isModified(){ @@ -116,8 +116,8 @@ public abstract class PathEditor { clearList(); myEnabled = files != null; if(myEnabled){ - for (int i = 0; i < files.length; i++){ - addElement(files[i]); + for (VirtualFile file : files) { + addElement(file); } } setModified(false); @@ -156,20 +156,13 @@ public abstract class PathEditor { }); myRemoveButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ - java.util.List removedItems = ListUtil.removeSelectedItems(myList); + 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}); - } + onSpecifyUrlButtonClicked(); } }); @@ -183,11 +176,7 @@ public abstract class PathEditor { return myPanel; } - protected String getInitialValue() { - return ""; - } - - private void itemsRemoved(java.util.List removedItems) { + private void itemsRemoved(List removedItems) { myAllFiles.removeAll(removedItems); if (removedItems.size() > 0){ setModified(true); @@ -200,10 +189,9 @@ public abstract class PathEditor { FileChooserDescriptor descriptor = createFileChooserDescriptor(); VirtualFile[] files = FileChooser.chooseFiles(myPanel, descriptor); files = adjustAddedFileSet(myPanel, files); - java.util.List added = new ArrayList(files.length); - for (int i = 0; i < files.length; i++){ - VirtualFile vFile = files[i]; - if(addElement(vFile)){ + List added = new ArrayList(files.length); + for (VirtualFile vFile : files) { + if (addElement(vFile)) { added.add(vFile); } } @@ -211,20 +199,20 @@ public abstract class PathEditor { } /** - * Implement this method to ajust adding behavior, this method is called right after the files + * Implement this method to adjust 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. + * The default implementation 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 + * @return adjusted file set */ protected VirtualFile[] adjustAddedFileSet(final Component component, final VirtualFile[] files) { return files; } - private void updateButtons(){ + protected void updateButtons(){ Object[] values = getSelectedRoots(); myRemoveButton.setEnabled((values.length > 0) && myEnabled); myAddButton.setEnabled(myEnabled); @@ -239,7 +227,7 @@ public abstract class PathEditor { return false; } - private void requestDefaultFocus(){ + protected void requestDefaultFocus(){ if (myList != null){ myList.requestFocus(); } @@ -248,9 +236,8 @@ public abstract class PathEditor { 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)){ + for (final VirtualFile path : paths) { + if (addElement(path)) { added = true; } } @@ -270,7 +257,7 @@ public abstract class PathEditor { indicesToRemove.add(idx); } } - final java.util.List list = ListUtil.removeIndices(myList, indicesToRemove.toNativeArray()); + final List list = ListUtil.removeIndices(myList, indicesToRemove.toNativeArray()); itemsRemoved(list); } @@ -292,11 +279,10 @@ public abstract class PathEditor { 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){ + protected void setSelectedRoots(Object[] roots){ + ArrayList rootsList = new ArrayList(roots.length); + for (Object root : roots) { + if (root != null) { rootsList.add(root); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java index 0723886593b7..ac12c56e6d77 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java @@ -21,14 +21,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 FACTORY = new KeyedExtensionFactory(OrderRootTypeUIFactory.class, "com.intellij.OrderRootTypeUI") { @@ -45,7 +43,7 @@ public interface OrderRootTypeUIFactory { private final OrderRootType myOrderRootType; private final FileChooserDescriptor myDescriptor; private final String myDisplayName; - private final Sdk mySdk; + protected final Sdk mySdk; public MyPathsEditor(final String displayName, final OrderRootType orderRootType, @@ -74,21 +72,5 @@ public interface OrderRootTypeUIFactory { 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 ""; - } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java index 73f24a24a68a..847f4be08051 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java @@ -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,44 @@ 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 MyPathsEditor { + + public JavadocPathsEditor(Sdk sdk) { + super(ProjectBundle.message("sdk.configure.javadoc.tab"), + JavadocOrderRootType.getInstance(), + new FileChooserDescriptor(false, true, true, false, true, true), + true, + sdk); + } + + @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 ""; + } } } \ No newline at end of file