Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-17
7
Medium Priority
?
254 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

876 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