jkteater
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
I know that the class is nested in AplotBaseDialog.
So I just use this when adding the listener class
I also set the constructor in the MyOperationListener for AplotBaseDialog
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.
AplotOperationListener, I am trying to make it as generic as possible. So I replaced the AplotBaseDialog with Dialog
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?
private void startPrinterListOperation() {
listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session);
listOp.addOperationListener(new MyOperationListener(this) { etc..
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...
I know that the class is nested in AplotBaseDialog.
So I just use this when adding the listener class
listOp.addOperationListener(new MyOperationListener(this) {
I also set the constructor in the MyOperationListener for AplotBaseDialog
AplotBaseDialog w = null;
public MyOperationListener(AplotBaseDialog win) {
w = win;
}
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)
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);
}
});
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> It compiles and the application runs.
Then, can you show us what the class Dialog looks like?
Then, can you show us what the class Dialog looks like?
ASKER
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.
ASKER
Thanks for your time and suggestions - Always Appreciated!
You're welcome.
Thanx 4 axxepting
Thanx 4 axxepting
ASKER
Open in new window