diff --git a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java index 14769572ad6c..88641107057c 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java @@ -1,14 +1,25 @@ +/* + * Copyright 2000-2011 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.projectView; import com.intellij.JavaTestUtil; import com.intellij.ide.favoritesTreeView.FavoritesManager; -import com.intellij.ide.favoritesTreeView.FavoritesProjectViewPane; import com.intellij.ide.projectView.ProjectView; -import com.intellij.ide.projectView.impl.AbstractProjectViewPane; import com.intellij.ide.projectView.impl.ProjectViewImpl; import com.intellij.ide.projectView.impl.ProjectViewPane; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.testFramework.TestSourceBasedTestCase; public class ProjectViewSwitchingTest extends TestSourceBasedTestCase { @@ -42,22 +53,22 @@ public class ProjectViewSwitchingTest extends TestSourceBasedTestCase { assertEquals(ProjectViewPane.ID, projectView.getCurrentViewId()); - FavoritesManager favoritesManager = FavoritesManager.getInstance(getProject()); - favoritesManager.createNewList("xxxx"); - - AbstractProjectViewPane currentPane = projectView.getCurrentProjectViewPane(); - assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); - assertEquals("xxxx", currentPane.getSubId()); - - favoritesManager.createNewList("yyyy"); - currentPane = projectView.getCurrentProjectViewPane(); - assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); - assertEquals("yyyy", currentPane.getSubId()); - - favoritesManager.removeFavoritesList("xxxx"); - currentPane = projectView.getCurrentProjectViewPane(); - assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); - assertEquals("yyyy", currentPane.getSubId()); + //FavoritesManager favoritesManager = FavoritesManager.getInstance(getProject()); + //favoritesManager.createNewList("xxxx"); + // + //AbstractProjectViewPane currentPane = projectView.getCurrentProjectViewPane(); + //assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); + //assertEquals("xxxx", currentPane.getSubId()); + // + //favoritesManager.createNewList("yyyy"); + //currentPane = projectView.getCurrentProjectViewPane(); + //assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); + //assertEquals("yyyy", currentPane.getSubId()); + // + //favoritesManager.removeFavoritesList("xxxx"); + //currentPane = projectView.getCurrentProjectViewPane(); + //assertEquals(FavoritesProjectViewPane.ID, currentPane.getId()); + //assertEquals("yyyy", currentPane.getSubId()); } @Override diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesListNode.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesListNode.java new file mode 100644 index 000000000000..c75631b50c16 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesListNode.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2011 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.favoritesTreeView; + +import com.intellij.ide.projectView.PresentationData; +import com.intellij.ide.projectView.ProjectViewNode; +import com.intellij.ide.projectView.ViewSettings; +import com.intellij.ide.projectView.impl.AbstractUrl; +import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * @author Konstantin Bulenkov + */ +public class FavoritesListNode extends AbstractTreeNode { + private final Project myProject; + private final String myListName; + + protected FavoritesListNode(Project project, String listName) { + super(project, listName); + myProject = project; + myListName = listName; + } + + @NotNull + @Override + public Collection getChildren() { + return getFavoritesRoots(myProject, myListName); + } + + @Override + protected void update(PresentationData presentation) { + presentation.setIcons(IconLoader.getIcon("/general/toolWindowFavorites.png")); + presentation.setPresentableText(myListName); + } + + @NotNull public static Collection getFavoritesRoots(Project project, String listName) { + final Collection> pairs = FavoritesManager.getInstance(project).getFavoritesListRootUrls(listName); + if (pairs == null) return Collections.emptyList(); + return createFavoriteRoots(project, pairs); + } + + @NotNull + private static Collection createFavoriteRoots(Project project, @NotNull Collection> urls) { + List result = new ArrayList(); + for (Pair pair : urls) { + AbstractUrl abstractUrl = pair.getFirst(); + final Object[] path = abstractUrl.createPath(project); + if (path == null || path.length < 1 || path[0] == null) { + continue; + } + try { + final String className = pair.getSecond(); + + @SuppressWarnings("unchecked") + final Class nodeClass = (Class)Class.forName(className); + + final AbstractTreeNode node = ProjectViewNode.createTreeNode(nodeClass, project, path[path.length - 1], ViewSettings.DEFAULT); + result.add(node); + } catch (Exception ignored) { + } + } + return result; + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java index a95d0b92b8e6..69acdb8697e0 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -26,8 +26,8 @@ import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; -import com.intellij.openapi.project.Project; import com.intellij.openapi.project.DumbAwareRunnable; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.*; @@ -135,14 +135,19 @@ public class FavoritesManager implements ProjectComponent, JDOMExternalizable { AbstractUrl url = createUrlByElement(element, myProject); if (url == null) return false; Collection> list = getFavoritesListRootUrls(name); + Pair found = null; for (Pair pair : list) { if (url.equals(pair.getFirst())) { - list.remove(pair); + found = pair; break; } } - fireListeners.rootsChanged(name); - return true; + if (found != null) { + list.remove(found); + fireListeners.rootsChanged(name); + return true; + } + return false; } public synchronized boolean renameFavoritesList(@NotNull String oldName, @NotNull String newName) { @@ -216,7 +221,7 @@ public class FavoritesManager implements ProjectComponent, JDOMExternalizable { ourAbstractUrlProviders.add(new ModuleGroupUrl(null)); - ourAbstractUrlProviders.add(new PsiFileUrl(null, null)); + ourAbstractUrlProviders.add(new PsiFileUrl(null)); ourAbstractUrlProviders.add(new LibraryModuleGroupUrl(null)); ourAbstractUrlProviders.add(new NamedLibraryUrl(null, null)); } @@ -380,8 +385,7 @@ public class FavoritesManager implements ProjectComponent, JDOMExternalizable { if (module == null) return; AbstractUrl childUrl = null; if (child instanceof PsiFile) { - childUrl = - new PsiFileUrl(((PsiDirectory)newParent).getVirtualFile().getUrl() + "/" + ((PsiFile)child).getName(), module.getName()); + childUrl = new PsiFileUrl(((PsiDirectory)newParent).getVirtualFile().getUrl() + "/" + ((PsiFile)child).getName()); } else if (child instanceof PsiDirectory) { childUrl = @@ -418,7 +422,7 @@ public class FavoritesManager implements ProjectComponent, JDOMExternalizable { final Module module = ModuleUtil.findModuleForPsiElement(psiElement); if (module == null) return; final String url = ((PsiDirectory)psiElement.getParent()).getVirtualFile().getUrl() + "/" + event.getNewValue(); - final AbstractUrl childUrl = psiElement instanceof PsiFile ? new PsiFileUrl(url, module.getName()) : new DirectoryUrl(url, module.getName()); + final AbstractUrl childUrl = psiElement instanceof PsiFile ? new PsiFileUrl(url) : new DirectoryUrl(url, module.getName()); for (String listName : myName2FavoritesRoots.keySet()) { final LinkedHashSet> roots = myName2FavoritesRoots.get(listName); final LinkedHashSet> newRoots = new LinkedHashSet>(); diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesPanel.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesPanel.java new file mode 100644 index 000000000000..df11b34d9456 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesPanel.java @@ -0,0 +1,108 @@ +/* + * Copyright 2000-2011 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.favoritesTreeView; + +import com.intellij.ide.dnd.*; +import com.intellij.ide.dnd.aware.DnDAwareTree; +import com.intellij.ide.util.treeView.AbstractTreeBuilder; +import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.ide.util.treeView.NodeDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; +import com.intellij.util.Function; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.util.Comparator; + +/** + * @author Konstantin Bulenkov + */ +public class FavoritesPanel { + private Project myProject; + private FavoritesTreeViewPanel myViewPanel; + private DnDAwareTree myTree; + private AbstractTreeBuilder myTreeBuilder; + private FavoritesTreeStructure myTreeStructure; + + public FavoritesPanel(Project project) { + myProject = project; + myViewPanel = new FavoritesTreeViewPanel(myProject, null); + myTree = myViewPanel.getTree(); + myTreeBuilder = myViewPanel.getBuilder(); + if (myTreeBuilder != null) { + Disposer.register(myProject, myTreeBuilder); + myTreeBuilder.setNodeDescriptorComparator(new Comparator() { + @Override + public int compare(NodeDescriptor nd1, NodeDescriptor nd2) { + if (nd1 instanceof FavoritesTreeNodeDescriptor && nd2 instanceof FavoritesTreeNodeDescriptor) { + FavoritesTreeNodeDescriptor fd1 = (FavoritesTreeNodeDescriptor)nd1; + FavoritesTreeNodeDescriptor fd2 = (FavoritesTreeNodeDescriptor)nd2; + return 0;//super.compare(fd1.getElement(), fd2.getElement()); todo + } + return 0; + } + }); + } + myTreeStructure = myViewPanel.getFavoritesTreeStructure(); + setupDnD(); + } + + public JComponent getPanel() { + return myViewPanel; + } + + private void setupDnD() { + DnDSupport.createBuilder(myTree) + .setBeanProvider(new Function() { + @Override + public DnDDragStartBean fun(DnDActionInfo dnDActionInfo) { + return new DnDDragStartBean(4); + } + }) + .setTargetChecker(new DnDTargetChecker() { + @Override + public boolean update(DnDEvent event) { + final Point p = event.getPoint(); + final TreePath path = myTree.getPathForLocation(p.x, p.y); + if (path != null && path.getPathCount() > 1) { + final Object o = path.getPath()[1]; + if (o instanceof DefaultMutableTreeNode) { + final Object obj = ((DefaultMutableTreeNode)o).getUserObject(); + if (obj instanceof FavoritesTreeNodeDescriptor) { + final AbstractTreeNode node = ((FavoritesTreeNodeDescriptor)obj).getElement(); + if (node instanceof FavoritesListNode) { + //todo + } + } + } + } + event.setDropPossible(false, null); + return false; + } + }) + .setDropHandler(new DnDDropHandler() { + @Override + public void drop(DnDEvent event) { + + } + }) + .setDisposableParent(myProject) + .install(); + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesProjectViewPane.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesProjectViewPane.java index 52a354def41b..c93ead819955 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesProjectViewPane.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesProjectViewPane.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -101,7 +101,7 @@ public class FavoritesProjectViewPane extends AbstractProjectViewPane { final String subId = getSubId(); LOG.assertTrue(subId != null, getSubIds()); - myViewPanel = new FavoritesTreeViewPanel(myProject, null, subId); + myViewPanel = new FavoritesTreeViewPanel(myProject, null); myTree = myViewPanel.getTree(); setTreeBuilder(myViewPanel.getBuilder()); myTreeStructure = myViewPanel.getFavoritesTreeStructure(); diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesRootNode.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesRootNode.java new file mode 100644 index 000000000000..03b690e33698 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesRootNode.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 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.favoritesTreeView; + +import com.intellij.ide.projectView.PresentationData; +import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Konstantin Bulenkov + */ +public class FavoritesRootNode extends AbstractTreeNode { + private Collection myFavoritesRoots; + private final Project myProject; + + public FavoritesRootNode(Project project) { + super(project, ""); + myProject = project; + } + + @NotNull + public Collection getChildren() { + if (myFavoritesRoots == null) { + myFavoritesRoots = new ArrayList(); + for (String list : FavoritesManager.getInstance(myProject).getAvailableFavoritesLists()) { + myFavoritesRoots.add(new FavoritesListNode(myProject, list)); + } + } + return myFavoritesRoots; + } + + public void rootsChanged() { + myFavoritesRoots = null; + } + + public void update(final PresentationData presentation) { + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeStructure.java index 894489b6ea46..442685b29c7f 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeStructure.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -18,38 +18,32 @@ package com.intellij.ide.favoritesTreeView; import com.intellij.ide.IdeBundle; import com.intellij.ide.projectView.PresentationData; -import com.intellij.ide.projectView.ProjectViewNode; import com.intellij.ide.projectView.ViewSettings; -import com.intellij.ide.projectView.impl.AbstractUrl; import com.intellij.ide.projectView.impl.ProjectTreeStructure; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; import com.intellij.psi.SmartPsiElementPointer; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; /** - * User: anna - * Date: Feb 15, 2005 + * @author Konstantin Bulenkov */ public class FavoritesTreeStructure extends ProjectTreeStructure { - private final FavoritesManager myFavoritesManager; - private final String myListName; - - public FavoritesTreeStructure(Project project, @NotNull final String name) { + public FavoritesTreeStructure(Project project) { super(project, FavoritesProjectViewPane.ID); - myListName = name; - myFavoritesManager = FavoritesManager.getInstance(project); } protected AbstractTreeNode createRoot(final Project project, ViewSettings settings) { - return new FavoritesRootNode(); + return new FavoritesRootNode(project); } public void rootsChanged() { @@ -57,49 +51,40 @@ public class FavoritesTreeStructure extends ProjectTreeStructure { } - //for tests only - @NotNull public Collection getFavoritesRoots() { - Collection> urls = myFavoritesManager.getFavoritesListRootUrls(myListName); - if (urls == null) return Collections.emptyList(); - return createFavoritesRoots(urls); - } - public Object[] getChildElements(Object element) { - if (!(element instanceof AbstractTreeNode)) { + if (! (element instanceof AbstractTreeNode)) { return ArrayUtil.EMPTY_OBJECT_ARRAY; } - final AbstractTreeNode favoritesTreeElement = (AbstractTreeNode)element; + + final AbstractTreeNode favTreeElement = (AbstractTreeNode)element; try { - if (element != getRootElement()) { - return super.getChildElements(favoritesTreeElement); - } - Set result = new HashSet(); - for (AbstractTreeNode abstractTreeNode : getFavoritesRoots()) { - final Object val = abstractTreeNode.getValue(); - if (val == null) { - continue; - } - if (val instanceof PsiElement && !((PsiElement)val).isValid()) { - continue; - } - if (val instanceof SmartPsiElementPointer && ((SmartPsiElementPointer)val).getElement() == null) { - continue; - } - boolean isInvalid = false; + if (!(element instanceof FavoritesListNode)) { + return super.getChildElements(favTreeElement); + } + + final Set result = new HashSet(); + for (AbstractTreeNode abstractTreeNode : FavoritesListNode.getFavoritesRoots(myProject, ((FavoritesListNode)element).getName())) { + final Object value = abstractTreeNode.getValue(); + + if (value == null) continue; + if (value instanceof PsiElement && !((PsiElement)value).isValid()) continue; + if (value instanceof SmartPsiElementPointer && ((SmartPsiElementPointer)value).getElement() == null) continue; + + boolean invalid = false; for(FavoriteNodeProvider nodeProvider: Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) { - if (nodeProvider.isInvalidElement(val)) { - isInvalid = true; + if (nodeProvider.isInvalidElement(value)) { + invalid = true; break; } } - if (isInvalid) continue; + if (invalid) continue; result.add(abstractTreeNode); } //myFavoritesRoots = result; - if (result.isEmpty()) { - result.add(getEmptyScreen()); - } + //if (result.isEmpty()) { + // result.add(getEmptyScreen()); + //} return ArrayUtil.toObjectArray(result); } catch (Exception e) { @@ -139,47 +124,4 @@ public class FavoritesTreeStructure extends ProjectTreeStructure { public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) { return new FavoritesTreeNodeDescriptor(myProject, parentDescriptor, (AbstractTreeNode)element); } - - @NotNull private Collection createFavoritesRoots(@NotNull Collection> urls) { - List result = new ArrayList(); - for (Pair pair : urls) { - AbstractUrl abstractUrl = pair.getFirst(); - final Object[] path = abstractUrl.createPath(myProject); - if (path == null || path.length < 1 || path[0] == null) { - continue; - } - try { - String className = pair.getSecond(); - Class nodeClass = (Class)Class.forName(className); - AbstractTreeNode node = ProjectViewNode.createTreeNode(nodeClass, myProject, path[path.length - 1], this); - result.add(node); - } - catch (Exception e) { - } - } - return result; - } - - private class FavoritesRootNode extends AbstractTreeNode { - private Collection myFavoritesRoots; - - public FavoritesRootNode() { - super(FavoritesTreeStructure.this.myProject, ""); - } - - @NotNull - public Collection getChildren() { - if (myFavoritesRoots == null) { - myFavoritesRoots = getFavoritesRoots(); - } - return myFavoritesRoots; - } - - public void rootsChanged() { - myFavoritesRoots = null; - } - - public void update(final PresentationData presentation) { - } - } } diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java index 6d337cfa60f4..38e2b7d1aa4e 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -23,6 +23,8 @@ import com.intellij.ide.DeleteProvider; import com.intellij.ide.IdeBundle; import com.intellij.ide.IdeView; import com.intellij.ide.dnd.aware.DnDAwareTree; +import com.intellij.ide.favoritesTreeView.actions.AddNewFavoritesListAction; +import com.intellij.ide.favoritesTreeView.actions.DeleteFromFavoritesAction; import com.intellij.ide.projectView.impl.ModuleGroup; import com.intellij.ide.projectView.impl.nodes.LibraryGroupElement; import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement; @@ -49,15 +51,13 @@ import com.intellij.pom.Navigatable; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiUtilBase; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.TreeSpeedSearch; +import com.intellij.ui.*; import com.intellij.util.ArrayUtil; import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.EditSourceOnEnterKeyHandler; +import com.intellij.util.PlatformIcons; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -72,19 +72,14 @@ import java.util.Arrays; import java.util.List; public class FavoritesTreeViewPanel extends JPanel implements DataProvider { - @NonNls public static final String ABSTRACT_TREE_NODE_TRANSFERABLE = "AbstractTransferable"; - private final FavoritesTreeStructure myFavoritesTreeStructure; private FavoritesViewTreeBuilder myBuilder; private final CopyPasteDelegator myCopyPasteDelegator; private final MouseListener myTreePopupHandler; public static final DataKey CONTEXT_FAVORITES_ROOTS_DATA_KEY = DataKey.create("FavoritesRoot"); - @Deprecated public static final String CONTEXT_FAVORITES_ROOTS = CONTEXT_FAVORITES_ROOTS_DATA_KEY.getName(); public static final DataKey FAVORITES_LIST_NAME_DATA_KEY = DataKey.create("FavoritesListName"); - @Deprecated public static final String FAVORITES_LIST_NAME = FAVORITES_LIST_NAME_DATA_KEY.getName(); - protected Project myProject; private final String myHelpId; protected DnDAwareTree myTree; @@ -92,21 +87,19 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { private final MyDeletePSIElementProvider myDeletePSIElementProvider = new MyDeletePSIElementProvider(); private final ModuleDeleteProvider myDeleteModuleProvider = new ModuleDeleteProvider(); - private String myListName; private final IdeView myIdeView = new MyIdeView(); - public FavoritesTreeViewPanel(Project project, String helpId, @NotNull String name) { + public FavoritesTreeViewPanel(Project project, String helpId) { super(new BorderLayout()); myProject = project; myHelpId = helpId; - myListName = name; - myFavoritesTreeStructure = new FavoritesTreeStructure(project, myListName); + myFavoritesTreeStructure = new FavoritesTreeStructure(project); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); root.setUserObject(myFavoritesTreeStructure.getRootElement()); final DefaultTreeModel treeModel = new DefaultTreeModel(root); myTree = new DnDAwareTree(treeModel); - myBuilder = new FavoritesViewTreeBuilder(myProject, myTree, treeModel, myFavoritesTreeStructure, myListName); + myBuilder = new FavoritesViewTreeBuilder(myProject, myTree, treeModel, myFavoritesTreeStructure); TreeUtil.installActions(myTree); UIUtil.setLineStyleAngled(myTree); @@ -136,7 +129,7 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { if (locationString != null && locationString.length() > 0) { append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); } - else if (node.getParent() != null && node.getParent().getParent() == null) { + else if (node.getParent() != null && node.getParent().getParent() != null && node.getParent().getParent().getParent() == null) { final String location = favoritesTreeNodeDescriptor.getLocation(); if (location != null && location.length() > 0) { append(" (" + location + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); @@ -146,9 +139,7 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { } } }); - JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); myTreePopupHandler = CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_FAVORITES_VIEW_POPUP, ActionPlaces.FAVORITES_VIEW_POPUP); - add(scrollPane, BorderLayout.CENTER); //add(createActionsToolbar(), BorderLayout.NORTH); EditSourceOnDoubleClickHandler.install(myTree); @@ -159,6 +150,33 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { return getSelectedPsiElements(); } }; + + final JPanel panel = ToolbarDecorator.createDecorator(myTree) + .setAddAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton button) { + AddNewFavoritesListAction.doAddNewFavoritesList(myProject); + } + }) + .setAddActionName("New Favorites List") + .disableRemoveAction() + .disableDownAction() + .disableUpAction() + .addExtraAction(new DeleteFromFavoritesAction() { + { + getTemplatePresentation().setIcon(PlatformIcons.DELETE_ICON); + } + + @Override + public ShortcutSet getShortcut() { + return CustomShortcutSet.fromString("DELETE"); + } + }) + .setLineBorder(0, 0, 0, 0) + .createPanel(); + panel.setBorder(IdeBorderFactory.createEmptyBorder(0)); + add(panel, BorderLayout.CENTER); + setBorder(IdeBorderFactory.createEmptyBorder(0)); } public void selectElement(final Object selector, final VirtualFile file, final boolean requestFocus) { @@ -174,14 +192,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { return myTree; } - public String getName() { - return myListName; - } - - public void setName(String name) { - myListName = name; - } - @NotNull private PsiElement[] getSelectedPsiElements() { final Object[] elements = getSelectedNodeElements(); @@ -298,14 +308,21 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider { FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = getSelectedNodeDescriptors(); for (FavoritesTreeNodeDescriptor selectedNodeDescriptor : selectedNodeDescriptors) { FavoritesTreeNodeDescriptor root = selectedNodeDescriptor.getFavoritesRoot(); - if (root != null && !(root.getElement().getValue() instanceof String)) { - result.add(root); + if (root != null && root.getElement() instanceof FavoritesListNode) { + result.add(selectedNodeDescriptor); } } return result.toArray(new FavoritesTreeNodeDescriptor[result.size()]); } if (FAVORITES_LIST_NAME_DATA_KEY.is(dataId)) { - return myListName; + final FavoritesTreeNodeDescriptor[] descriptors = getSelectedNodeDescriptors(); + if (descriptors.length == 1) { + final AbstractTreeNode node = descriptors[0].getElement(); + if (node instanceof FavoritesListNode) { + return node.getValue(); + } + } + return null; } FavoritesTreeNodeDescriptor[] descriptors = getSelectedNodeDescriptors(); if (descriptors.length > 0) { diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesViewTreeBuilder.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesViewTreeBuilder.java index 474f7127a175..1361916c33be 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesViewTreeBuilder.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesViewTreeBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -52,15 +52,12 @@ public class FavoritesViewTreeBuilder extends BaseProjectTreeBuilder { private final FileStatusListener myFileStatusListener; private final CopyPasteUtil.DefaultCopyPasteListener myCopyPasteListener; private final FavoritesManager.FavoritesListener myFavoritesListener; - private final String myListName; public FavoritesViewTreeBuilder(Project project, JTree tree, DefaultTreeModel treeModel, - ProjectAbstractTreeStructureBase treeStructure, - final String name) { + ProjectAbstractTreeStructureBase treeStructure) { super(project, tree, treeModel, treeStructure, null); - myListName = name; final MessageBusConnection connection = myProject.getMessageBus().connect(this); myPsiTreeChangeListener = new ProjectViewPsiTreeChangeListener(myProject) { protected DefaultMutableTreeNode getRootNode() { @@ -99,9 +96,9 @@ public class FavoritesViewTreeBuilder extends BaseProjectTreeBuilder { myFavoritesListener = new FavoritesManager.FavoritesListener() { public void rootsChanged(String listName) { - if (myListName.equals(listName)) { + //if (myListName.equals(listName)) { //todo[kb]: add optimizations? updateFromRoot(); - } + //} } public void listAdded(String listName) { diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/DeleteFromFavoritesAction.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/DeleteFromFavoritesAction.java index ede6f68f4a7e..5bde3e57bfb9 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/DeleteFromFavoritesAction.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/DeleteFromFavoritesAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -17,22 +17,25 @@ package com.intellij.ide.favoritesTreeView.actions; import com.intellij.ide.IdeBundle; +import com.intellij.ide.favoritesTreeView.FavoritesListNode; import com.intellij.ide.favoritesTreeView.FavoritesManager; import com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor; import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel; -import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.ui.AnActionButton; /** - * User: anna - * Date: Feb 23, 2005 + * @author anna + * @author Konstantin Bulenkov */ -public class DeleteFromFavoritesAction extends AnAction implements DumbAware { +public class DeleteFromFavoritesAction extends AnActionButton implements DumbAware { private static final Logger LOG = Logger.getInstance("#" + DeleteFromFavoritesAction.class.getName()); public DeleteFromFavoritesAction() { @@ -47,25 +50,43 @@ public class DeleteFromFavoritesAction extends AnAction implements DumbAware { } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext); - String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext); assert roots != null; - assert listName != null; for (FavoritesTreeNodeDescriptor root : roots) { - final Object value = root.getElement().getValue(); - LOG.assertTrue(value != null, root.getElement()); - favoritesManager.removeRoot(listName, value); + final AbstractTreeNode node = root.getElement(); + if (node instanceof FavoritesListNode) { + favoritesManager.removeFavoritesList((String)node.getValue()); + } + else { + final Object value = node.getValue(); + LOG.assertTrue(value != null, node); + final NodeDescriptor parent = root.getParentDescriptor(); + if (parent instanceof FavoritesTreeNodeDescriptor) { + final String name = ((FavoritesTreeNodeDescriptor)parent).getName(); + favoritesManager.removeRoot(name, value); + } + } } } public void update(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); Project project = PlatformDataKeys.PROJECT.getData(dataContext); - if (project == null){ + if (project == null) { e.getPresentation().setEnabled(false); return; } - final String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext); FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext); - e.getPresentation().setEnabled(listName != null && roots != null && roots.length != 0); + if (roots == null) { + e.getPresentation().setEnabled(false); + return; + } + + if (roots.length == 1 + && roots[0].getElement() instanceof FavoritesListNode + && project.getName().equals(roots[0].getElement().getValue())) { + e.getPresentation().setEnabled(false); + return; + } + e.getPresentation().setEnabled(true); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/FavoritesViewToolWindowFactory.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/FavoritesViewToolWindowFactory.java new file mode 100644 index 000000000000..8a41b1b1d19b --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/FavoritesViewToolWindowFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2011 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.projectView.impl; + +import com.intellij.ide.favoritesTreeView.FavoritesPanel; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowFactory; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentManager; + +import javax.swing.*; + +/** + * @author Konstantin Bulenkov + */ +public class FavoritesViewToolWindowFactory implements ToolWindowFactory, DumbAware { + public void createToolWindowContent(Project project, ToolWindow toolWindow) { + if (toolWindow != null) { + final ContentManager contentManager = toolWindow.getContentManager(); + final JComponent panel = new FavoritesPanel(project).getPanel(); + final Content content = contentManager.getFactory().createContent(panel, null, false); + contentManager.addContent(content); + } + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 9e69fe33ae91..1572624eb0ea 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -582,6 +582,8 @@ factoryClass="com.intellij.ide.todo.TodoToolWindowFactory" canCloseContents="true"/> + @@ -600,7 +602,7 @@ - + diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index 7b79cfac606b..0d531152aa72 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -748,7 +748,7 @@ - +