Solved

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

Posted on 2013-01-17
7
245 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 52
servlet doXXX methods 3 49
couple of eclipse 5 38
varialbe initialization 11 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

803 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