2929import javax .swing .*;
3030import javax .swing .table .TableColumn ;
3131import java .awt .*;
32- import java .awt .event .ActionEvent ;
33- import java .io .Serial ;
34- import java .util .List ;
3532import java .util .*;
33+ import java .util .List ;
3634import java .util .stream .Collectors ;
3735
3836import static java .util .Objects .requireNonNullElseGet ;
@@ -266,18 +264,9 @@ public PluginConfiguration getPluginConfiguration() {
266264 /**
267265 * Process the addition of a configuration location.
268266 */
269- private final class AddLocationAction extends ToolbarAction {
270- @ Serial
271- private static final long serialVersionUID = -7266120887003483814L ;
272-
273- AddLocationAction () {
274- putValue (Action .NAME , CheckStyleBundle .message ("config.file.add.text" ));
275- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.file.add.tooltip" ));
276- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.file.add.tooltip" ));
277- }
278-
267+ private final class AddLocationAction implements AnActionButtonRunnable {
279268 @ Override
280- public void actionPerformed (final ActionEvent e ) {
269+ public void run (final AnActionButton anActionButton ) {
281270 final LocationDialogue dialogue = new LocationDialogue (
282271 parentDialogue (),
283272 project ,
@@ -306,18 +295,9 @@ private Dialog parentDialogue() {
306295 /**
307296 * Process the removal of a configuration location.
308297 */
309- private final class RemoveLocationAction extends ToolbarAction {
310- @ Serial
311- private static final long serialVersionUID = -799542186049804472L ;
312-
313- RemoveLocationAction () {
314- putValue (Action .NAME , CheckStyleBundle .message ("config.file.remove.text" ));
315- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.file.remove.tooltip" ));
316- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.file.remove.tooltip" ));
317- }
318-
298+ private final class RemoveLocationAction implements AnActionButtonRunnable {
319299 @ Override
320- public void actionPerformed (final ActionEvent e ) {
300+ public void run (final AnActionButton anActionButton ) {
321301 final int selectedIndex = locationTable .getSelectedRow ();
322302 if (selectedIndex == -1 ) {
323303 return ;
@@ -330,18 +310,9 @@ public void actionPerformed(final ActionEvent e) {
330310 /**
331311 * Edit the properties of a configuration location.
332312 */
333- private final class EditPropertiesAction extends ToolbarAction {
334- @ Serial
335- private static final long serialVersionUID = -799542186049804472L ;
336-
337- EditPropertiesAction () {
338- putValue (Action .NAME , CheckStyleBundle .message ("config.file.properties.text" ));
339- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.file.properties.tooltip" ));
340- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.file.properties.tooltip" ));
341- }
342-
313+ private final class EditPropertiesAction implements AnActionButtonRunnable {
343314 @ Override
344- public void actionPerformed (final ActionEvent e ) {
315+ public void run (final AnActionButton anActionButton ) {
345316 final int selectedIndex = locationTable .getSelectedRow ();
346317 if (selectedIndex == -1 ) {
347318 return ;
@@ -360,39 +331,13 @@ public void actionPerformed(final ActionEvent e) {
360331 }
361332 }
362333
363- abstract static class ToolbarAction extends AbstractAction implements AnActionButtonRunnable {
364- @ Serial
365- private static final long serialVersionUID = 7091312536206510956L ;
366-
367- @ Override
368- public void run (final AnActionButton anActionButton ) {
369- actionPerformed (null );
370- }
371- }
372-
373334 /**
374335 * Process the addition of a path element.
375336 */
376- private final class AddPathAction extends ToolbarAction {
377- @ Serial
378- private static final long serialVersionUID = -1389576037231727360L ;
379-
380- /**
381- * Create a new add path action.
382- */
383- AddPathAction () {
384- putValue (Action .NAME , CheckStyleBundle .message ("config.path.add.text" ));
385- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.path.add.tooltip" ));
386- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.path.add.tooltip" ));
387- }
388-
337+ private final class AddPathAction implements AnActionButtonRunnable {
389338 @ Override
390- public void actionPerformed (final ActionEvent e ) {
391- final FileChooserDescriptor descriptor = new ExtensionFileChooserDescriptor (
392- (String ) getValue (Action .NAME ),
393- (String ) getValue (Action .SHORT_DESCRIPTION ),
394- false , "jar" );
395- final VirtualFile chosen = FileChooser .chooseFile (descriptor , CheckStyleConfigPanel .this , project , ProjectUtil .guessProjectDir (project ));
339+ public void run (final AnActionButton anActionButton ) {
340+ final VirtualFile chosen = FileChooser .chooseFile (checkStyleRulesFileChooserDescriptor (), CheckStyleConfigPanel .this , project , ProjectUtil .guessProjectDir (project ));
396341 if (chosen != null ) {
397342 (pathListModel ()).addElement (
398343 VfsUtilCore .virtualToIoFile (chosen ).getAbsolutePath ());
@@ -401,24 +346,20 @@ public void actionPerformed(final ActionEvent e) {
401346 }
402347 }
403348
349+ private FileChooserDescriptor checkStyleRulesFileChooserDescriptor () {
350+ return new FileChooserDescriptor (true , false , true , true , false , false )
351+ .withFileFilter ((file ) -> {
352+ final String currentExtension = file .getExtension ();
353+ return currentExtension != null && "jar" .equalsIgnoreCase (currentExtension .trim ());
354+ });
355+ }
356+
404357 /**
405358 * Process the editing of a path element.
406359 */
407- private final class EditPathAction extends ToolbarAction {
408- @ Serial
409- private static final long serialVersionUID = -1455378231580505750L ;
410-
411- /**
412- * Create a new edit path action.
413- */
414- EditPathAction () {
415- putValue (Action .NAME , CheckStyleBundle .message ("config.path.edit.text" ));
416- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.path.edit.tooltip" ));
417- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.path.edit.tooltip" ));
418- }
419-
360+ private final class EditPathAction implements AnActionButtonRunnable {
420361 @ Override
421- public void actionPerformed (final ActionEvent e ) {
362+ public void run (final AnActionButton anActionButton ) {
422363 final int selected = pathList .getSelectedIndex ();
423364 if (selected < 0 ) {
424365 return ;
@@ -427,12 +368,8 @@ public void actionPerformed(final ActionEvent e) {
427368 final DefaultListModel <String > listModel = pathListModel ();
428369 final String selectedFile = listModel .get (selected );
429370
430- final FileChooserDescriptor descriptor = new ExtensionFileChooserDescriptor (
431- (String ) getValue (Action .NAME ),
432- (String ) getValue (Action .SHORT_DESCRIPTION ),
433- false , "jar" );
434371 final VirtualFile toSelect = LocalFileSystem .getInstance ().findFileByPath (selectedFile );
435- final VirtualFile chosen = FileChooser .chooseFile (descriptor , project , toSelect );
372+ final VirtualFile chosen = FileChooser .chooseFile (checkStyleRulesFileChooserDescriptor () , project , toSelect );
436373 if (chosen != null ) {
437374 listModel .remove (selected );
438375 listModel .add (selected , VfsUtilCore .virtualToIoFile (chosen ).getAbsolutePath ());
@@ -445,21 +382,9 @@ public void actionPerformed(final ActionEvent e) {
445382 /**
446383 * Process the removal of a path element.
447384 */
448- private final class RemovePathAction extends ToolbarAction {
449- @ Serial
450- private static final long serialVersionUID = 7339136485307147623L ;
451-
452- /**
453- * Create a new add path action.
454- */
455- RemovePathAction () {
456- putValue (Action .NAME , CheckStyleBundle .message ("config.path.remove.text" ));
457- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.path.remove.tooltip" ));
458- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.path.remove.tooltip" ));
459- }
460-
385+ private final class RemovePathAction implements AnActionButtonRunnable {
461386 @ Override
462- public void actionPerformed (final ActionEvent e ) {
387+ public void run (final AnActionButton anActionButton ) {
463388 final int [] selected = pathList .getSelectedIndices ();
464389 if (selected == null || selected .length == 0 ) {
465390 return ;
@@ -475,21 +400,9 @@ public void actionPerformed(final ActionEvent e) {
475400 /**
476401 * Process the move up of a path element.
477402 */
478- private final class MoveUpPathAction extends ToolbarAction {
479- @ Serial
480- private static final long serialVersionUID = -1230778908605654344L ;
481-
482- /**
483- * Create a new move-up path action.
484- */
485- MoveUpPathAction () {
486- putValue (Action .NAME , CheckStyleBundle .message ("config.path.move-up.text" ));
487- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.path.move-up.tooltip" ));
488- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.path.move-up.tooltip" ));
489- }
490-
403+ private final class MoveUpPathAction implements AnActionButtonRunnable {
491404 @ Override
492- public void actionPerformed (final ActionEvent e ) {
405+ public void run (final AnActionButton anActionButton ) {
493406 final int selected = pathList .getSelectedIndex ();
494407 if (selected < 1 ) {
495408 return ;
@@ -506,21 +419,9 @@ public void actionPerformed(final ActionEvent e) {
506419 /**
507420 * Process the move down of a path element.
508421 */
509- private final class MoveDownPathAction extends ToolbarAction {
510- @ Serial
511- private static final long serialVersionUID = 1222511743014969175L ;
512-
513- /**
514- * Create a new move-down path action.
515- */
516- MoveDownPathAction () {
517- putValue (Action .NAME , CheckStyleBundle .message ("config.path.move-down.text" ));
518- putValue (Action .SHORT_DESCRIPTION , CheckStyleBundle .message ("config.path.move-down.tooltip" ));
519- putValue (Action .LONG_DESCRIPTION , CheckStyleBundle .message ("config.path.move-down.tooltip" ));
520- }
521-
422+ private final class MoveDownPathAction implements AnActionButtonRunnable {
522423 @ Override
523- public void actionPerformed (final ActionEvent e ) {
424+ public void run (final AnActionButton anActionButton ) {
524425 final DefaultListModel <String > listModel = pathListModel ();
525426 final int selected = pathList .getSelectedIndex ();
526427 if (selected == -1 || selected == (listModel .getSize () - 1 )) {
0 commit comments