update copyright
[fedora-idea.git] / plugins / properties / src / com / intellij / lang / properties / structureView / PropertiesFileStructureViewModel.java
blob054ae36383ee4c36a4a84838100241f76b6e8607
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 com.intellij.lang.properties.structureView;
18 import com.intellij.ide.IdeBundle;
19 import com.intellij.ide.structureView.StructureViewTreeElement;
20 import com.intellij.ide.structureView.TextEditorBasedStructureViewModel;
21 import com.intellij.ide.util.treeView.smartTree.ActionPresentation;
22 import com.intellij.ide.util.treeView.smartTree.ActionPresentationData;
23 import com.intellij.ide.util.treeView.smartTree.Grouper;
24 import com.intellij.ide.util.treeView.smartTree.Sorter;
25 import com.intellij.lang.properties.editor.PropertiesGroupingStructureViewModel;
26 import com.intellij.lang.properties.psi.PropertiesFile;
27 import com.intellij.lang.properties.psi.Property;
28 import com.intellij.openapi.util.IconLoader;
29 import com.intellij.psi.PsiFile;
30 import org.jetbrains.annotations.NonNls;
31 import org.jetbrains.annotations.NotNull;
33 import java.util.Comparator;
35 /**
36 * @author max
38 public class PropertiesFileStructureViewModel extends TextEditorBasedStructureViewModel implements PropertiesGroupingStructureViewModel {
39 private final PropertiesFile myPropertiesFile;
40 private final GroupByWordPrefixes myGroupByWordPrefixes;
41 @NonNls public static final String KIND_SORTER_ID = "KIND_SORTER";
42 private static final Sorter KIND_SORTER = new Sorter() {
43 public Comparator getComparator() {
44 return new Comparator() {
45 public int compare(final Object o1, final Object o2) {
46 int weight1 = o1 instanceof PropertiesPrefixGroup ? 1 : 0;
47 int weight2 = o2 instanceof PropertiesPrefixGroup ? 1 : 0;
48 return weight1 - weight2;
53 public boolean isVisible() {
54 return true;
57 @NotNull
58 public ActionPresentation getPresentation() {
59 String name = IdeBundle.message("action.sort.by.type");
60 return new ActionPresentationData(name, name, IconLoader.getIcon("/objectBrowser/sortByType.png"));
63 @NotNull
64 public String getName() {
65 return KIND_SORTER_ID;
69 public PropertiesFileStructureViewModel(final PropertiesFile root) {
70 super(root);
71 myPropertiesFile = root;
72 String separator = PropertiesSeparatorManager.getInstance().getSeparator(root.getProject(), root.getVirtualFile());
73 myGroupByWordPrefixes = new GroupByWordPrefixes(separator);
76 public void setSeparator(String separator) {
77 myGroupByWordPrefixes.setSeparator(separator);
78 PropertiesSeparatorManager.getInstance().setSeparator(myPropertiesFile.getVirtualFile(), separator);
81 public String getSeparator() {
82 return myGroupByWordPrefixes.getSeparator();
85 @NotNull
86 public StructureViewTreeElement getRoot() {
87 return new PropertiesFileStructureViewElement(myPropertiesFile);
90 @NotNull
91 public Grouper[] getGroupers() {
92 return new Grouper[]{myGroupByWordPrefixes};
95 @NotNull
96 public Sorter[] getSorters() {
97 return new Sorter[] {Sorter.ALPHA_SORTER, KIND_SORTER};
100 protected PsiFile getPsiFile() {
101 return myPropertiesFile;
104 @NotNull
105 protected Class[] getSuitableClasses() {
106 return new Class[] {Property.class};