EditorConfig documentation test
[idea/community.git] / java / java-impl / src / com / intellij / ui / ReferenceEditorComboWithBrowseButton.java
1 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.ui;
3
4 import com.intellij.openapi.fileTypes.StdFileTypes;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.openapi.ui.ComponentWithBrowseButton;
7 import com.intellij.openapi.util.text.StringUtil;
8 import com.intellij.psi.JavaCodeFragment;
9 import com.intellij.util.ArrayUtilRt;
10 import org.jetbrains.annotations.NotNull;
11
12 import java.awt.event.ActionListener;
13 import java.util.List;
14
15 /**
16  * @author ven
17  */
18 public class ReferenceEditorComboWithBrowseButton extends ComponentWithBrowseButton<EditorComboBox> implements TextAccessor {
19   public ReferenceEditorComboWithBrowseButton(final ActionListener browseActionListener,
20                                               final String text,
21                                               @NotNull final Project project,
22                                               boolean toAcceptClasses, final String recentsKey) {
23     this(browseActionListener, text, project, toAcceptClasses, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, recentsKey);
24   }
25
26   public ReferenceEditorComboWithBrowseButton(final ActionListener browseActionListener,
27                                               final String text,
28                                               @NotNull final Project project,
29                                               boolean toAcceptClasses,
30                                               final JavaCodeFragment.VisibilityChecker visibilityChecker, final String recentsKey) {
31     super(new EditorComboBox(JavaReferenceEditorUtil.createDocument(StringUtil.isEmpty(text) ? "" : text, project, toAcceptClasses, visibilityChecker), project, StdFileTypes.JAVA),
32           browseActionListener);
33     final List<String> recentEntries = RecentsManager.getInstance(project).getRecentEntries(recentsKey);
34     if (recentEntries != null) {
35       setHistory(ArrayUtilRt.toStringArray(recentEntries));
36     }
37     if (text != null && text.length() > 0) {
38       prependItem(text);
39     }
40     else if (text != null) {
41       getChildComponent().setSelectedItem(null);
42     }
43   }
44
45   @Override
46   public String getText(){
47     return getChildComponent().getText().trim();
48   }
49
50   @Override
51   public void setText(final String text){
52     getChildComponent().setText(text);
53   }
54
55   public boolean isEditable() {
56     return !getChildComponent().getEditorEx().isViewer();
57   }
58
59   public void setHistory(String[] history) {
60     getChildComponent().setHistory(history);
61   }
62
63   public void prependItem(String item) {
64     getChildComponent().prependItem(item);
65   }
66
67   public void appendItem(String item) {
68     getChildComponent().appendItem(item);
69   }
70 }