Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 581393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:34:25+00:00 2026-05-13T14:34:25+00:00

I am about to refactor a Swing application from using ActionListeners to Action classes

  • 0

I am about to refactor a Swing application from using ActionListeners to Action classes because I realized that a lot of my menu items are going to be used in a toolbar as well.

Right now I have a class called ImportExport which deals with the state of the underlying model and then displays the appropriate user dialogs. ImportExport has the functions save(), saveAs() and open(). When a user clicks on the “Open” menu item, the action listener calls open(), open() first checks if the model has changes and if that’s the case displays a dialog asking the user if he wants to save first. Now if the user clicks “Yes” open() calls save() which again performs some checks and displays user dialogs. save() is pretty persistent: The only way to get out of this action is either by saving successfully or the user deciding that he wants to cancel. I strongly rely on the feedback that save() provides and if a user wants to cancel I also cancel the calling open() function.

I wanted to split up the ImportExport class into three classes (OpenAction, SaveAction & SaveAsAction), each of them subclassing AbstractAction and eventually get rid of the ImportExport class. And this is where my problem arises: How do I tell the SaveAction to execute if the user wants to save the model before opening another one? And how do I get feedback if the user decides to cancel?

Is this even the right approach? I don’t like to have duplicated code in the save and open action and I have already put as much functionality as possible into my underlying model but user dialogs are obiously out of place there so this is no option. Was Action designed at all to hold this kind of functionality or sould I just keep my ImportExport class and simply delegate all action calls to the appropriate functions in ImportExport. How do you use Actions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:34:26+00:00Added an answer on May 13, 2026 at 2:34 pm

    I sometimes add a ‘controller’ action when there is a decision tree involved. OpenAction, SaveAction and SaveAsAction would subclass this controller Action. The controller action would determine the state of the model and request more info from the user if appropriate and then call the correct subclass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php application that has about 50-55 code files. The file that
I work on a UI java application composed from: top header left menu header
I am working on an application that is about 250,000 lines of code. I'm
about click and submit example below: <form action=url method=post> <input type=text id=input1/> <input type=submit
About 10 years ago, I was using a computer language called INFO on an
About five years ago I started using Generic lookup Tables for applications I was
About to create a form using Zend Form, all the form elements should have
I'm trying to refactor an old web service project using new structure (with Maven)
I have been developing a web application for about six months with no framework
I am using Hibernate for a few years but am not sure about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.