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 com
.intellij
.util
.NotNullFunction
;
19 import org
.jetbrains
.annotations
.NotNull
;
20 import org
.jetbrains
.idea
.svn
.dialogs
.RepositoryBrowserComponent
;
21 import org
.jetbrains
.idea
.svn
.dialogs
.RepositoryTreeNode
;
22 import org
.jetbrains
.idea
.svn
.dialogs
.browserCache
.Expander
;
24 import javax
.swing
.tree
.TreeNode
;
25 import java
.util
.LinkedList
;
26 import java
.util
.List
;
28 public class OpeningExpander
extends AbstractOpeningExpander
{
29 private final List
<String
> pathElements
;
30 private final String myLongest
;
32 public OpeningExpander(final TreeNode
[] path
, final RepositoryBrowserComponent browser
, final RepositoryTreeNode selectionPath
) {
33 super(browser
, selectionPath
.getURL().toString());
34 pathElements
= new LinkedList
<String
>();
36 for (TreeNode aPath
: path
) {
37 RepositoryTreeNode node
= (RepositoryTreeNode
)aPath
;
38 pathElements
.add(node
.getURL().toString());
40 myLongest
= pathElements
.get(pathElements
.size() - 1);
43 protected ExpandVariants
expandNode(final String url
) {
44 if (pathElements
.contains(url
)) {
45 if (myLongest
.equals(url
)) {
46 return ExpandVariants
.EXPAND_AND_EXIT
;
48 return ExpandVariants
.EXPAND_CONTINUE
;
50 return ExpandVariants
.DO_NOTHING
;
53 protected boolean checkChild(final String childUrl
) {
54 return pathElements
.contains(childUrl
);
57 public static class Factory
implements NotNullFunction
<RepositoryBrowserComponent
, Expander
> {
58 private final TreeNode
[] myPath
;
59 private final RepositoryTreeNode mySelectionPath
;
61 public Factory(final TreeNode
[] path
, final RepositoryTreeNode selectionPath
) {
63 mySelectionPath
= selectionPath
;
67 public Expander
fun(final RepositoryBrowserComponent repositoryBrowserComponent
) {
68 return new OpeningExpander(myPath
, repositoryBrowserComponent
, mySelectionPath
);