Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-17
7
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 500 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 500 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

715 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