TextFieldWithHistoryWithBrowseButton#setTextAndAddToHistory method added to simplify...
[idea/community.git] / platform / platform-api / src / com / intellij / ui / TextFieldWithHistoryWithBrowseButton.java
1 /*
2  * Copyright 2000-2014 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.ui;
17
18 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
19 import com.intellij.openapi.fileChooser.FileChooserFactory;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.ui.ComponentWithBrowseButton;
22 import com.intellij.openapi.ui.TextComponentAccessor;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25
26 /**
27  * User: anna
28  */
29 public class TextFieldWithHistoryWithBrowseButton extends ComponentWithBrowseButton<TextFieldWithHistory> {
30   public TextFieldWithHistoryWithBrowseButton() {
31     super(new TextFieldWithHistory(), null);
32   }
33
34   @Override
35   public void addBrowseFolderListener(@Nullable String title,
36                                       @Nullable String description,
37                                       @Nullable Project project,
38                                       FileChooserDescriptor fileChooserDescriptor,
39                                       TextComponentAccessor<TextFieldWithHistory> accessor) {
40     super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor);
41     FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
42   }
43
44   @Override
45   public void addBrowseFolderListener(@Nullable String title,
46                                       @Nullable String description,
47                                       @Nullable Project project,
48                                       FileChooserDescriptor fileChooserDescriptor,
49                                       TextComponentAccessor<TextFieldWithHistory> accessor,
50                                       boolean autoRemoveOnHide) {
51     super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor, autoRemoveOnHide);
52     FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
53   }
54
55   public String getText() {
56     return getChildComponent().getText();
57   }
58
59   public void setText(@NotNull String text) {
60     getChildComponent().setText(text);
61   }
62
63   public void setTextAndAddToHistory(@NotNull String text) {
64     getChildComponent().setTextAndAddToHistory(text);
65   }
66 }