Skip to content

Commit

Permalink
Generics cleanup for class path UI model
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Jul 1, 2015
1 parent 3e60916 commit 39d2fe7
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Provides a configuration panel for project-level configuration.
*/
public final class CheckStyleConfigPanel extends JPanel {
private final JList pathList = new JBList(new DefaultListModel());
private final JList pathList = new JBList(new DefaultListModel<String>());

private final JCheckBox testClassesCheckbox = new JCheckBox();
private final JCheckBox scanNonJavaFilesCheckbox = new JCheckBox();
Expand Down Expand Up @@ -211,7 +211,7 @@ public void setThirdPartyClasspath(final List<String> classpath) {
thirdPartyClasspath = classpath;
}

final DefaultListModel listModel = (DefaultListModel) pathList.getModel();
final DefaultListModel<String> listModel = pathListModel();
listModel.clear();

for (final String classPathFile : thirdPartyClasspath) {
Expand All @@ -221,6 +221,11 @@ public void setThirdPartyClasspath(final List<String> classpath) {
}
}

@SuppressWarnings("unchecked")
private DefaultListModel<String> pathListModel() {
return (DefaultListModel<String>) pathList.getModel();
}

/**
* Get the third party classpath.
*
Expand All @@ -230,7 +235,7 @@ public void setThirdPartyClasspath(final List<String> classpath) {
public List<String> getThirdPartyClasspath() {
final List<String> classpath = new ArrayList<>();

final DefaultListModel listModel = (DefaultListModel) pathList.getModel();
final DefaultListModel listModel = pathListModel();
for (int i = 0; i < listModel.size(); ++i) {
final String path = (String) listModel.get(i);
classpath.add(path);
Expand Down Expand Up @@ -278,10 +283,10 @@ public List<ConfigurationLocation> getConfigurationLocations() {
return Collections.unmodifiableList(locationModel.getLocations());
}

public void setConfigurationLocations(final List<ConfigurationLocation> locations) {
this.locations = new ArrayList<>(locations);
public void setConfigurationLocations(final List<ConfigurationLocation> newLocations) {
this.locations = new ArrayList<>(newLocations);

final List<ConfigurationLocation> modelLocations = new ArrayList<>(locations);
final List<ConfigurationLocation> modelLocations = new ArrayList<>(newLocations);
Collections.sort(modelLocations);
locationModel.setLocations(modelLocations);
}
Expand Down Expand Up @@ -418,7 +423,7 @@ public void actionPerformed(final ActionEvent e) {
false, "jar");
final VirtualFile chosen = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
if (chosen != null) {
((DefaultListModel) pathList.getModel()).addElement(
(pathListModel()).addElement(
VfsUtilCore.virtualToIoFile(chosen).getAbsolutePath());
}
}
Expand All @@ -445,8 +450,8 @@ public void actionPerformed(final ActionEvent e) {
return;
}

final DefaultListModel listModel = (DefaultListModel) pathList.getModel();
final String selectedFile = (String) listModel.get(selected);
final DefaultListModel<String> listModel = pathListModel();
final String selectedFile = listModel.get(selected);

final FileChooserDescriptor descriptor = new ExtensionFileChooserDescriptor(
(String) getValue(Action.NAME),
Expand Down Expand Up @@ -484,7 +489,7 @@ public void actionPerformed(final ActionEvent e) {
}

for (final int index : selected) {
((DefaultListModel) pathList.getModel()).remove(index);
(pathListModel()).remove(index);
}
}
}
Expand All @@ -510,8 +515,8 @@ public void actionPerformed(final ActionEvent e) {
return;
}

final DefaultListModel listModel = (DefaultListModel) pathList.getModel();
final Object element = listModel.remove(selected);
final DefaultListModel<String> listModel = pathListModel();
final String element = listModel.remove(selected);
listModel.add(selected - 1, element);

pathList.setSelectedIndex(selected - 1);
Expand All @@ -534,14 +539,13 @@ public MoveDownPathAction() {
}

public void actionPerformed(final ActionEvent e) {
final DefaultListModel listModel = (DefaultListModel)
pathList.getModel();
final DefaultListModel<String> listModel = pathListModel();
final int selected = pathList.getSelectedIndex();
if (selected == -1 || selected == (listModel.getSize() - 1)) {
return;
}

final Object element = listModel.remove(selected);
final String element = listModel.remove(selected);
listModel.add(selected + 1, element);

pathList.setSelectedIndex(selected + 1);
Expand Down

0 comments on commit 39d2fe7

Please sign in to comment.