SVN auth
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / dialogs / browser / AbstractOpeningExpander.java
blob04f6d95fe67d65b725181abd25945c3715c48611
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.jetbrains.idea.svn.dialogs.browser;
18 import org.jetbrains.idea.svn.dialogs.RepositoryBrowserComponent;
19 import org.jetbrains.idea.svn.dialogs.RepositoryTreeNode;
20 import org.jetbrains.idea.svn.dialogs.browserCache.Expander;
21 import org.jetbrains.idea.svn.dialogs.browserCache.KeepingExpandedExpander;
23 import javax.swing.tree.TreeNode;
24 import java.util.Enumeration;
26 public abstract class AbstractOpeningExpander implements Expander {
27 private final RepositoryBrowserComponent myBrowser;
28 private final KeepingExpandedExpander myKeepingExpander;
29 private final String mySelectionPath;
31 protected AbstractOpeningExpander(final RepositoryBrowserComponent browser, final String selectionPath) {
32 myBrowser = browser;
33 myKeepingExpander = new KeepingExpandedExpander(browser);
34 mySelectionPath = selectionPath;
37 public void onBeforeRefresh(final RepositoryTreeNode node) {
38 myKeepingExpander.onBeforeRefresh(node);
41 protected enum ExpandVariants {
42 DO_NOTHING,
43 EXPAND_AND_EXIT,
44 EXPAND_CONTINUE
47 protected abstract ExpandVariants expandNode(final String url);
48 protected abstract boolean checkChild(final String childUrl);
50 public void onAfterRefresh(final RepositoryTreeNode node) {
51 myKeepingExpander.onAfterRefresh(node);
53 if (node.isLeaf()) {
54 return;
57 final String myUrl = node.getURL().toString();
58 final ExpandVariants expandVariant = expandNode(myUrl);
60 if (ExpandVariants.DO_NOTHING.equals(expandVariant)) {
61 return;
64 // then expanded
65 myBrowser.expandNode(node);
67 if (ExpandVariants.EXPAND_AND_EXIT.equals(expandVariant)) {
68 removeSelf();
69 } else {
70 final Enumeration children = node.children();
71 while (children.hasMoreElements()) {
72 final TreeNode treeNode = (TreeNode) children.nextElement();
73 if (treeNode instanceof RepositoryTreeNode) {
74 final RepositoryTreeNode repositoryTreeNode = (RepositoryTreeNode) treeNode;
75 final String childUrl = repositoryTreeNode.getURL().toString();
76 if (checkChild(childUrl)) {
77 if ((mySelectionPath != null) && (mySelectionPath.equals(childUrl))) {
78 myBrowser.setSelectedNode(repositoryTreeNode);
80 repositoryTreeNode.reload(this, false);
81 return;
85 removeSelf();
89 private void removeSelf() {
90 myBrowser.setLazyLoadingExpander(new KeepingExpandedExpander.Factory());