Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Moving a OperationListener Class from a nested class to a separate Class

I have a dialog class that has a nested class called MyOperationListener

private void startPrinterListOperation() {
      listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session);
      listOp.addOperationListener(new MyOperationListener(this) { etc..

Open in new window


public abstract class MyOperationListener implements InterfaceAIFOperationListener {
      AplotBaseDialog w = null;
     
      public MyOperationListener(AplotBaseDialog win) {
         w = win;
      } 

      public void startOperation(String startMessage) {
         Display.getDefault().asyncExec(new Runnable() {
            public void run() {
               w.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT));
               w.getShell().setEnabled(false);
            }
         });
      }  etc...

Open in new window


I know that the class is nested in AplotBaseDialog.  
So I just use this when adding the listener class

listOp.addOperationListener(new MyOperationListener(this) {

Open in new window


I also set the constructor in the MyOperationListener for AplotBaseDialog

AplotBaseDialog w = null;

public MyOperationListener(AplotBaseDialog win) {
         w = win;
      } 

Open in new window


This works as designed.

So I removed MyOperationListener from being nested and created AplotOperationListener class.  

I was using that Listener class in about 4 different dialog classes.  That is why I decided to just create a common class.

In the Dialog, I am importing the new class and only changing the Listener Class Name.
listOp.addOperationListener(new AplotOperationListener(this) 

Open in new window


 AplotOperationListener, I am trying to make it as generic as possible.  So I replaced the AplotBaseDialog with Dialog

public abstract class AplotOperationListener implements InterfaceAIFOperationListener {
   Dialog w = null;
  
   public AplotOperationListener(Dialog dialog) {
      w = dialog;
   } 

   public void startOperation(String startMessage) {
      Display.getDefault().asyncExec(new Runnable() {
         public void run() {
            w.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT));
            w.getShell().setEnabled(false);
         }
      });
   } 

Open in new window


When I execute the code, it is not working correctly.

Is this the correct way to make the listener more generic, so it can be used in any Dialog Class?
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkteater

ASKER

It compiles and the application runs.  The operation starts and runs after the button click, but the problem is, when the operation opens showAplotPlotterDialog, that dialog flashes on the screen, then the Application closes.

Display.getDefault().asyncExec(new Runnable() {
                  public void run() {
                     showAplotPlotterDialog();
                  }
               });

Open in new window

>> It compiles and the application runs.
Then, can you show us what the class Dialog looks like?
Sorry, I was out of office for a while.  I did discover the problem.  The problem was actually in my operation listener.  I was closing the dialog at the end of every operation, being I made it a separate class.  In a couple of places the dialog needs to stay open. So I added a check to see which of my dialog's is running the operation and closing the ones that need closing and leaving open the ones that need to stay open.
Thanks for your time and suggestions - Always Appreciated!
You're welcome.
Thanx 4 axxepting