/platform/platform-api/src/com/intellij/ide/DefaultTreeExpander.java

https://bitbucket.org/nbargnesi/idea · Java · 58 lines · 30 code · 10 blank · 18 comment · 3 complexity · f5bddaf1da72e5ad12765b8d3e61913d MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.ide;
  17. import com.intellij.util.ui.tree.TreeUtil;
  18. import org.jetbrains.annotations.NotNull;
  19. import javax.swing.*;
  20. /**
  21. * @author yole
  22. */
  23. public class DefaultTreeExpander implements TreeExpander {
  24. private final JTree myTree;
  25. public DefaultTreeExpander(@NotNull final JTree tree) {
  26. myTree = tree;
  27. }
  28. public void expandAll() {
  29. TreeUtil.expandAll(myTree);
  30. showSelectionCentered();
  31. }
  32. public boolean canExpand() {
  33. return myTree.isShowing();
  34. }
  35. public void collapseAll() {
  36. TreeUtil.collapseAll(myTree, 1);
  37. showSelectionCentered();
  38. }
  39. private void showSelectionCentered() {
  40. final int[] rowz = myTree.getSelectionRows();
  41. if (rowz != null && rowz.length > 0) {
  42. TreeUtil.showRowCentered(myTree, rowz[0], false);
  43. }
  44. }
  45. public boolean canCollapse() {
  46. return myTree.isShowing();
  47. }
  48. }