Eclipse disable "Run in Background" - java

eclipse (3.7) does provide a nice abstract class Job for running tasks in a separate jobs. Using this opens a dialog with three buttons, "Run in Background", "Chancel" and "Details".
Is there any implementation or even a simple setting to remove the button "Run in Background" (and the checkbox "Always run in background")? Or do I have to provide my own implementation for this?
Update - Workaround
A co-worker had an idea, this workaround seems to be a good alternative.
new ProgressMonitorDialog(this.getPage().getShell()).run(true, true, new IRunnableWithProgress() {
#Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Konfiguration speichern...", IProgressMonitor.UNKNOWN);
// Do something here
}
});

The dialog is display by the Eclipse progress manager org.eclipse.ui.internal.progress.ProgressManager. It is not really practical to replace this.
The dialog is not displayed at all if setUser(false) is called on the Job.

Related

Eclipse plugin "Run As" submenu disappearing

I have an eclipse plugin which configures a set of resources as a customized project and runs it. I have added run and debug choices to "Run As" and "Debug As" menus and also shortcuts in the tool bar. So when I put mouse over "Run As", I have two submenus:
Run on Server
My Customized project
I can click on "My customized project" and everything runs as desired.
However after I ran it once, I no longer have "My customized project" as a "Run As" submenus, it's gone. "Run on Server" is also gone and instead I have an "XSL Transformation" there.
I found a post with similar question here:
http://www.sigasi.com/content/run-menu-item-strangely-disappearing-context-menu
but his solution won't work for me. I already have the extension point defined.
Does anyone have an idea why this happens?
UPDATE:
I think I know where exactly the problem is but I still have no solution.
I have the following code when a customized project is finished running:
IJobManager manager = Job.getJobManager();
manager.addJobChangeListener(new JobChangeAdapter() {
#Override
public void done(final IJobChangeEvent event) {
if (event.getJob().getName() == "Processing with selected modules" && event.getResult() == Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
#Override
public void run() {
actionExport.setEnabled(true);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("customized.output");
} catch (CoreException e) {
e.printStackTrace();
}
}
});
manager.removeJobChangeListener(this);
}
}
});
the line PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("customized.output"); is the source of the problem. I just want to switch to another view when the project finishes to show the result. There will be no problem with disappearing "Run As" submenu if I remove this line. But I want to show the view after running a project. Anyone has any clue about it?

eclipse wizard performFinish slowness

I am creating an Eclipse wizard... I am overriding the method
public boolean performFinish()
Inside the method, I want there to be a progress monitor... So I am doing the following:
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor mainMonitor) throws InvocationTargetException {
//do stuff
}
};
I have ran the wizard in debug and have found that it is not my code that is making it run slow. I can simply print out something with the monitor and it still takes a little while for the performFinish to be kicked off. Is there something I am missing with performFinish? Has anyone else seen this issue?
I have not seen this.
You would normally use the progress bar built in to the wizard like this:
getContainer().run(true, true, runnableWithProgress);
in the performFinish.
You wizard should call
setNeedsProgressMonitor(true);
in its constructor to enable the wizard progress monitor.

UISpec4J and external application

I am trying to launch an external application for testing using UISpec4J.
Here are the questions and their answers I referred so far:
How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?
Getting all windows using UISpec4J
UISpec4J Capturing modal dialog, before the trigger finish
my.exe referred below is a Java application wrapped in exe using some tool. Internally it uses the jars and is Java GUI application.
This executable launches a splash screen first, then a dialog to choose where you want to connect to and after that main window is shown. Unless I can automate where I can connect to I won't get main window.
Based on these questions I have come up with following code fragments:
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
return WindowInterceptor.run(new Trigger() {
#Override
public void run() throws Exception {
// running jnlp by netx launcher
Runtime.getRuntime().exec("C:\\my.exe");
Thread.sleep(10000);
}
});
}
});
In the approach above I simple get "No window was shown" error.
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
final Window[] result = new Window[1];
WindowInterceptor
.init(new Trigger() {
#Override
public void run() throws Exception {
Runtime.getRuntime().exec("C:\\my.exe");
//Thread.sleep(10000);
}
})
//.processTransientWindow()
.process(new WindowHandler() {
public Trigger process(Window window) throws Exception {
result[0] = window;
return Trigger.DO_NOTHING;
}
})
.run();
return result[0];
}
});
In the second approach above, I still get "No window shown" error AND control never reaches to overriden "process" method.
I referred to http://www.uispec4j.org/reports/apidocs/org/uispec4j/interception/WindowInterceptor.html and recommended approach is to use init to capture modal dialog is init\process sequence.
To capture non-modal it is recommended that we should use following:
Window window = WindowInterceptor.run(panel.getButton("open").triggerClick());
But I have NO idea where and how I am supposed to call it..
From the first question I referred, mentioned above, we should be able to do that because the answer to it mentions launching jnlp application which is external application.
I tried with jre 6 update 0 and I can at least run test. In java update 37, from the third question I referred above, I get abstract method not implemented error.
What am I doing wrong? Any idea?
I am using latest UISpec4J package - version 2.4.
Thanks in advance,
-Neel.
I'm very new to UISpec4J but I'm guessing it needs to run in the same JVM in order to intercept and interact with the GUI components. When you start the exe file with exec, it will create a new process and a new, separate JVM. That'll not work, if I understand UISpec4J correctly.
Regarding the non-modal example, the documentation says "You would retrieve the window from within the test...", so in a setup method or in a test should work.

Display.getDefault().asyncExec not running correctly

I am using eclipse's jobs API to run big task as a job, once task is completed I am setting boolean variable to true and if that variable is true I am executing WizardDialog in UI thread. My current code looks like this:
Job longRunningJob = new Job("Long running job...") {
#Override
protected IStatus run(IProgressMonitor monitor) {
boolean shouldShowDialog = doLongRunningJob();
if(shouldShowDialog) {
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
//Will open wizard dialog here
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), new TestWizard());
wizardDialog.setBlockOnOpen(true);
wizardDialog.open();
}
});
}
}
}
longRunningJob.setUser(true);
longRunningJob.schedule();
My problem is run inside Display thread not executing in reliable way, means sometime it goes inside run method where as sometimes it doesn't, I tried putting breakpoint inside run method and testing it out but same happens.
My question is, is what I am doing is correct way? Is this expected behaviour? So how do I handle this scenario ie once shouldShowDialog is true how do I execute code inside Display thread?
Edit: One behaviour I observed while debugging is dialog gets displayed but suddenly it get closes, I think it's exiting the thread.
The problem with disappearing dialogs is most commonly caused by using currently active Shell as the parent for the dialog. E.g. if there is a ProgressDialog open when you create your dialog then that other dialog will be the parent of your dialog. And when the other dialog closes, so does yours.
Instead, use something like:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

Rendering Problem with Swing App and Modal Dialogs

I have a Java/Swing desktop application (Java 6u16 on Windows XP) which occasionally appears to the users to hang. I say appears to because in reality what is happening is that the application is showing a modal dialog but this dialog is not being rendered. If the user uses Alt-Tab to switch away from the application and then subsequently returns to it, the dialog gets rendered correctly. Additionally, if a remote user connects to the session via NetOp (a VNC/Remote Desktop workalike) this also causes the GUI to be redrawn correctly.
The app runs via JavaWebstart. Since I've heard of rendering issues being caused by DirectDraw, I added the following to the JNLP
<property name="sun.java2d.noddraw" value="true"/>
but the problem still occurs (If I have understood correctly, this will switch off DirectDraw and Direct3d completely: see http://download.oracle.com/javase/1.5.0/docs/guide/2d/flags.html#noddraw)
I'm out of ideas on this one, any suggestions would be greatly appreciated.
Thanks,
Phil
Edit...
I have an abstract dialog class which extends JDialog and which all other dialogs extend. It contains the following method:
public void showDialog() {
initKeyBindings();
Application.getApplication().deactivateScannerListener();
setVisible(true);
}
Whenever I want to display a dialog, I call showDialog(). The initKeyBindings method sets up an ActionMap while the second line is application specific (Application is a singleton, I'm disabling the JPOS scanner listener while the dialog is displaying).
There is a corresponding hideDialog() method as follows:
public void hideDialog() {
setVisible(false);
Application.getApplication().activateScannerListener();
dispose();
}
Thanks,
Phil
Edit...
Sorry about this, one more edit: all of the dialogs have a parent. The AbstractDialog class will default to the main application frame if no other parent is specified.
FYI
For anyone following this, I've added the following to my code:
if (SwingUtilities.isEventDispatchThread()) {
initialiseAndShowDialog();
} else {
SwingUtilities.invokeAndWait(new Runnable() {
#Override
public void run() {
initialiseAndShowDialog();
}
});
}
This ensures that the dialog is only opened from the EDT.
Which thread are you calling showDialog() from? Swing components should be accessed on the Event Dispatch Thread only.
You could try SwingUtilities.invokeAndWait()
and the Runnable argument passed to it should call showDialog().
Let us know if it fixed the problem.

Categories