Opening a view after launching in eclipse - eclipse

I'm trying to have a view open programatically at the end of an eclipse ILaunchConfigurationDelegate. Currently I'm getting an "invalid thread access" error when I try to call showView(). How do I open a view from the launcher?

Try wrapping your call like this;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// Your code goes here
}
});
This will put it on the Display thread and should fix the errors your seeing.

Related

Eclipse PDE: Programmatically detect opened dialog and close it

On Eclipse Luna, I select a server and click the Start button on Servers view, then the server (for example Tomcat8) will get started. If something is wrong during the start-up process, a dialog will be populated to display the error messages (for example time-out). The dialog is modeless in this test case.
Now I need to start the server programmatically from a plugin. In case that errors occur, how could I programmatically detect that a dialog has been opened and how to close it?
You could use the Display.addFilter method to listen for all SWT.Activate events which will tell you about all Shells (and other things) being activated. You can then detect the shells you want to close.
Something like:
Display.getDefault().addFilter(SWT.Activate, new Listener()
{
#Override
public void handleEvent(final Event event)
{
// Is this a Shell being activated?
if (event.widget instanceof Shell)
{
final Shell shell = (Shell)event.widget;
// Look at the shell title to see if it is the one we want
if ("About".equals(shell.getText()))
{
// Close the shell after it has finished initializing
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
shell.close();
}
});
}
}
}
});
which closes a dialog called 'About'.
In more recent versions of Java the above can be simplified to:
Display.getDefault().addFilter(SWT.Activate, event ->
{
// Is this a Shell being activated?
if (event.widget instanceof Shell shell)
{
// Look at the shell title to see if it is the one we want
if ("About".equals(shell.getText()))
{
// Close the shell after it has finished initializing
Display.getDefault().asyncExec(shell::close);
}
}
});
This uses Java 8 lambdas and method references and Java 16 instanceof type patterns.

Hide Dialog from inside in LWUIT

I have created a Dialog with two buttons Yes, No, and then I have add action listener to them, my problem is that I want no button to hide the Dialog that I have created
the code is looks like:
dialog = new Dialog(title);
dialog.setDialogType(Dialog.TYPE_CONFIRMATION);
ta = new TextArea(text);
ta.getStyle().setBorder(Border.createEmpty());
ta.setEditable(false);
yesCommand = new Button("YES");
noCommand = new Button("NO");
yesCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
LGBMainMidlet.getLGBMidlet().notifyDestroyed();
}
});
noCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Logger.Log("Bye Bye");
dialog = null;
System.gc();
}
});
dialog.addComponent(ta);
dialog.addComponent(yesCommand);
dialog.addComponent(noCommand);
dialog.show();
the code is not working for me, can anyone told me what is the problem?
B.N. I have used dialog.dispose(), but it exit the whole application
It is better to use
dialog.setTimeout(1000); the number show the time limit the dialog box wait in milliseconds. So by doing this you can exit the dialog form automatically.
Dialog.dispose() does not exit the whole application, it just closes the dialog.
If you have nothing in your application you might see nothing if you dispose the dialog.

cannot calling customMapField class from menu item

i've read this article about this "How to show our own icon in BlackBerry Map?" and i want to put it on my project, and calling the Scr() class from the menu item :
MenuItem _openAction = new MenuItem("MyLocation",100000,10) {
public void run()
{
UiApplication.getUiApplication().pushScreen(new Scr());
}
};
but i get error ""jvm error 104 uncaught runtime exception" when i calling it from menu "MyLocation".
i tried before but i calling the Scr() class from the main screen and its working well.
public invokeMaps()
{
pushScreen(new Scr());
}
since I'm new to this whole thing i can't figure it out where the problem is...
any help would be really mean a lot to my project.. thanks before :)
As you can see in this thread, the 104 error is shown for all uncaught exceptions in the simulator. I suggest you wrap the code inside the run method in a try / catch block and see if you can get a more detailed exception.
There are many things that could have gone wrong, for example if you call getLocation inside Scr() you will get an exception, cause this function call cannot be made on the ui thread.
Another thing to try is to separate the creation on the Scr class from the push screen and see where the exception is thrown:
try{
Scr myScr = new Scr();
UiApplication.getUiApplication().pushScreen(myScr);
} catch (Exception ex) {
// take a look at the exception message
}

Can't hit breakpoints for user generated actions when debugging jython code with PyDev in Eclipse

I'm implementing a GUI application in Jython, using Eclipse and PyDev plugin.
The problem is that I have a hard time using the builtin debugger. When I start a debug session it just stops. Of course this should be expected as the program just creates a JFrame and then it's finished.
So any breakpoints I put for different events .e.g. pressing a button, will never happen as the debug session is already terminated.
What should I do ? I'm growing tired of using prints for all my debugging.
For instance, when I tried debugging this small Java example. I have no problem to hit
the breakpoint I had set in the windowClosing-method
import java.awt.event.*;
import javax.swing.*;
public class Test1 {
public static void main(String s[]) {
JFrame frame = new JFrame("JFrame Source Demo");
// Add a window listner for close button
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
And then I tried this somewhat more or less similiar example in jython
from javax.swing import JFrame;
import java.awt.event.WindowListener as WindowListener
class Test1 (JFrame, WindowListener):
def __init__(self):
super(JFrame, self).__init__('Some name goes here', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (800, 800))
self.addWindowListener(self)
self.setVisible(True)
def windowClosing(self, windowEvent):
print 'window closing'
pass # want to hit this breakpoint
someFrame = Test1()
pass #breakpoint here maybe
If I tried to run the jython example in the debugger and it just terminates. Ok then I added a breakpoint after I created someFrame and a breakpoint in the windowClosing method. Still no luck, It doesn't get hit when I close the window but I see it executed as I see the printout.
Can anyone tell me what I'm doing wrong ? I'm sure I forgot something very simple.
Put a breakpoint in the first line of your main method that initiates the application.
If you want to debug certain actions like pressing a button add an action listener to a button and inside the handling method add the breakpoint. For example:
JButton button = new JButton("OK");
button.addActionListener(new ActionListener()
{
#Override
public void action(ActionEvent e)
{
System.out.println("button OK has been pressed"; // add breakpoint here
// call to some code that handles the event
}
});
I had the same problem
btnCompilar = new JButton("Compilar");
btnCompilar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
compile(); //can't hit breakpoint here
}
});
I couldn't hit breakpoints inside actionPerformed, so I just made a method and used breakpoints in it.
void compile(){
//can hit breakpoint here
}

Integration Widget (GWT) with DynamicForm (Smartgwt) - com.google.gwt.user.client.ui.AttachDetachException

I had this problem when I created a Window (Smartgwt) and put a DynamicForm (Smartgwt) in this Window, In this DynamicForm, I have a CanvasItem (Smartgwt) in which I put a RichTextArea (GWT). And when I press "ESC", I can quit the Window (Smartgwt) without probleme. But when I press "F5" to refresh my application, the browser pops up a exception saying "com.google.gwt.user.client.ui.AttachDetachException". To solve this problem, I do the following:
public class MailWindow extends Window {
public MailWindow(){
this.addCloseClickHandler(new CloseClickHandler() {
public void onCloseClick(CloseClientEvent event) {
form.getRichTextArea().removeFromParent();
MailWindow.this.destroy();
}
});
}
}
Which solved my problem! :)
Kewei
Thanks for posting this. We'll try to incorporate the logic in SmartGWT itself so that you don't need to explicitly call removeFromParent()