JavaAutoImportOptions. Toolbar decorator.

This commit is contained in:
Evgeny Zakrevsky
2012-03-11 22:17:19 +04:00
parent a6ce0c999f
commit 45d1f39145
2 changed files with 33 additions and 77 deletions
@@ -59,50 +59,15 @@
</hspacer>
</children>
</grid>
<grid id="e67c2" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<grid id="e67c2" binding="myExcludeFromImportAndCompletionPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="400" height="150"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="9c6c" class="com.intellij.ui.components.JBScrollPane">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="75463" class="com.intellij.ui.components.JBList" binding="myExcludePackagesList">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="82013" class="javax.swing.JButton" binding="myAddPackageButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ApplicationBundle" key="exclude.from.imports.add"/>
</properties>
</component>
<component id="9c559" class="javax.swing.JButton" binding="myRemoveButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text resource-bundle="messages/ApplicationBundle" key="action.remove"/>
</properties>
</component>
<vspacer id="c69dd">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
<children/>
</grid>
<component id="64f08" class="com.intellij.ui.TitledSeparator">
<constraints>
@@ -31,16 +31,15 @@ import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.AnActionButton;
import com.intellij.ui.AnActionButtonRunnable;
import com.intellij.ui.ListScrollingUtil;
import com.intellij.ui.ListUtil;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.components.JBList;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.util.Arrays;
import java.util.regex.Pattern;
@@ -52,12 +51,10 @@ public class JavaAutoImportOptions implements AutoImportOptionsProvider {
private JComboBox mySmartPasteCombo;
private JCheckBox myCbShowImportPopup;
private JPanel myWholePanel;
private JBList myExcludePackagesList;
private JButton myAddPackageButton;
private JButton myRemoveButton;
private JCheckBox myCbAddUnambiguousImports;
private JCheckBox myCbOptimizeImports;
private JPanel myExcludeFromImportAndCompletionPanel;
private JBList myExcludePackagesList;
private DefaultListModel myExcludePackagesModel;
@NonNls private static final Pattern ourPackagePattern = Pattern.compile("(\\w+\\.)*\\w+");
@@ -66,34 +63,28 @@ public class JavaAutoImportOptions implements AutoImportOptionsProvider {
mySmartPasteCombo.addItem(INSERT_IMPORTS_ASK);
mySmartPasteCombo.addItem(INSERT_IMPORTS_NONE);
myAddPackageButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
InputValidator validator = new InputValidator() {
myExcludePackagesList = new JBList();
myExcludeFromImportAndCompletionPanel.add(
ToolbarDecorator.createDecorator(myExcludePackagesList)
.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
InputValidator validator = new InputValidator() {
public boolean checkInput(String inputString) {
return ourPackagePattern.matcher(inputString).matches();
}
public boolean checkInput(String inputString) {
return ourPackagePattern.matcher(inputString).matches();
}
public boolean canClose(String inputString) {
return checkInput(inputString);
public boolean canClose(String inputString) {
return checkInput(inputString);
}
};
String packageName = Messages.showInputDialog(myWholePanel, ApplicationBundle.message("exclude.from.completion.prompt"),
ApplicationBundle.message("exclude.from.completion.title"),
Messages.getWarningIcon(), "", validator);
addExcludePackage(packageName);
}
};
String packageName = Messages.showInputDialog(myWholePanel, ApplicationBundle.message("exclude.from.completion.prompt"),
ApplicationBundle.message("exclude.from.completion.title"),
Messages.getWarningIcon(), "", validator);
addExcludePackage(packageName);
}
});
myExcludePackagesList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
myRemoveButton.setEnabled(myExcludePackagesList.getSelectedValue() != null);
}
});
myRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ListUtil.removeSelectedItems(myExcludePackagesList);
}
});
}).disableUpDownActions().createPanel(), BorderLayout.CENTER);
myExcludePackagesList.getEmptyText().setText(ApplicationBundle.message("exclude.from.imports.no.exclusions"));
}
@@ -104,7 +95,7 @@ public class JavaAutoImportOptions implements AutoImportOptionsProvider {
}
int index = -Arrays.binarySearch(myExcludePackagesModel.toArray(), packageName) - 1;
if (index < 0) return;
myExcludePackagesModel.add(index, packageName);
myExcludePackagesList.setSelectedValue(packageName, true);
ListScrollingUtil.ensureIndexIsVisible(myExcludePackagesList, index, 0);
@@ -135,7 +126,7 @@ public class JavaAutoImportOptions implements AutoImportOptionsProvider {
myCbAddUnambiguousImports.setSelected(codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY);
myExcludePackagesModel = new DefaultListModel();
for(String aPackage: codeInsightSettings.EXCLUDED_PACKAGES) {
for (String aPackage : codeInsightSettings.EXCLUDED_PACKAGES) {
myExcludePackagesModel.add(myExcludePackagesModel.size(), aPackage);
}
myExcludePackagesList.setModel(myExcludePackagesModel);
@@ -167,7 +158,7 @@ public class JavaAutoImportOptions implements AutoImportOptionsProvider {
private String[] getExcludedPackages() {
String[] excludedPackages = new String[myExcludePackagesModel.size()];
for (int i = 0; i < myExcludePackagesModel.size(); i++) {
excludedPackages [i] = (String)myExcludePackagesModel.elementAt(i);
excludedPackages[i] = (String)myExcludePackagesModel.elementAt(i);
}
Arrays.sort(excludedPackages);
return excludedPackages;