Solved

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

Posted on 2013-01-17
7
241 Views
Last Modified: 2013-01-28
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?
0
Comment
Question by:jkteater
  • 3
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 125 total points
ID: 38789855
When I execute the code, it is not working correctly
Ummm... OK, but my crystal ball is a bit cloudy today. Do you mind telling WHAT is happening that is not correct?

My guess is that your error is due to changing from a specific subclass (AplotBaseDialog) to a more generic superclass/interface (Dialog), and the Dialog class DOESN'T have the .getShell() method that you are trying to call on it. You can use a superclass (or interface) of AplotBaseDialog but it needs to be one in the heirarchy where the .getShell() method exists. (And without you giving us ANY clue as to what these classes are or which library they come from, that is about as much as I can guess)
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 125 total points
ID: 38792087
>> When I execute the code, it is not working correctly.
So you are able to compile that code? I doubt that.
Dialog doesn't have a getShell() method, so when trying to compile AplotOperationListener I would expect a compiler error.
0
 

Author Comment

by:jkteater
ID: 38793425
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

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 37

Expert Comment

by:zzynx
ID: 38793490
>> It compiles and the application runs.
Then, can you show us what the class Dialog looks like?
0
 

Author Comment

by:jkteater
ID: 38827052
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.
0
 

Author Closing Comment

by:jkteater
ID: 38827059
Thanks for your time and suggestions - Always Appreciated!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38827121
You're welcome.
Thanx 4 axxepting
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now