Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » view problem
view problem [message #317116] Tue, 26 June 2007 08:01 Go to next message
Eclipse UserFriend
Originally posted by: karl.lindsten.com

I'm trying to make a eclipse plug-in view with a button that making a filebrowser. I have a filebrowser witch using a display for browsing. this is working great when i run it as a swt application, but then i want to run it from a button in a view. when i then running this as a eclipse application it can't make the display.


the action that generates look like this:

private void makeActions() {

fileBrowser = new Action() {
public void run() {
SimpleFileBrowser fileBrowser = new SimpleFileBrowser();
fileBrowser.run();
}
};
fileBrowser.setText("Open file...");
fileBrowser.setToolTipText("Open file... settolltiptext");


and my filebrowser construktor look like this:

public SimpleFileBrowser() {
display = new Display();
// doesn't get here!!!
shell = new Shell(display);
}
Re: view problem [message #317139 is a reply to message #317116] Tue, 26 June 2007 18:56 Go to previous messageGo to next message
Eclipse UserFriend
karl wrote:
> public SimpleFileBrowser() {
> display = new Display();
> // doesn't get here!!!
> shell = new Shell(display);
> }

You generally don't want to create a new Display instance when you're
writing Eclipse plug-ins (actually, maybe that's a _never_, but I can't
say for sure). You can pass in your Button's display with getDisplay()
or use PlatformUI.getWorkbench().getDisplay().

Regards,
Rem
Re: view problem [message #317143 is a reply to message #317139] Wed, 27 June 2007 02:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

Thanks!!!

Now I got a display, but I still don't get it. I suppose I shouldn't create new objects. But the next question is how does I get the button?

fileBrowser = new Action() {
public void run() {
SimpleFileBrowser fileBrowser = new SimpleFileBrowser();

System.out.println("action1 : miten: wiihiiii!");

fileBrowser.run();
System.out.println("action1 : efter");
}


// SimpleFileBrowser class
public SimpleFileBrowser() {
display = PlatformUI.getWorkbench().getDisplay();
shell = new Shell(display);
shell.setText("File Browser");
shell.setLayout(new GridLayout(1, true));
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


public void run(){
init();
shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}



private void init() {
shell.setText("File Browser");
shell.setLayout(new GridLayout(1, true));

// here comes the problem!

Button button = shell.getDefaultButton();

//Button button = new Button(shell, SWT.PUSH);
button.setText("Browse ...");
System.out.println("SimpleFileBrowser: init(): button vreated");
button.addSelectionListener(new SelectionAdapter() {
Re: view problem [message #317155 is a reply to message #317116] Wed, 27 June 2007 07:13 Go to previous messageGo to next message
Eclipse UserFriend
For getting the display, I'd change your SimpleFileBrowser constructor
to take the display. That way it will continue to work in an SWT program:

SimpleFileBrowser fileBrowser
= new SimpleFileBrowser(PlatformUI.getWorkbench().getDisplay());

public SimpleFileBrowser(Display display) {
....
}

As for the button ... for creating actions in menus and toolbars, check out:

http://www.eclipse.org/articles/article.php?file=Article-act ion-contribution/index.html

If it really is just a button that you want, what's wrong with your
snippet, except for an SWT faux pas [1]?

shell.setText("File Browser");
shell.setLayout(new GridLayout(1, true));Button button = new
Button(shell, SWT.PUSH);
button.setText("Browse ...");
....


That should work. The other part you have won't though:
shell.getDefaultButton() is used to retrieve a button that has been set
using setDefaultButton(*).

Later,
PW

[1] don't create and dispose the Display in an SWT program in random
classes. Do it in main(String[]) and pass it into whatever classes need
it. Otherwise reuse becomes problemmatic.
Re: view problem [message #317159 is a reply to message #317155] Wed, 27 June 2007 08:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

Thanks a lot!

But still when I'm closing my filebrowsewindow everyting disepears.
Re: view problem [message #317162 is a reply to message #317159] Wed, 27 June 2007 09:15 Go to previous message
Eclipse UserFriend
karl wrote:
> Thanks a lot!
>
> But still when I'm closing my filebrowsewindow everyting disepears.

yes ... and did you remove the display.dispose() like I implied in [1]?

Also, your SimpleFileBrowser that was posted has a wide variety of
exciting display.readAndDispatch() event loops ...

My suggestion is "don't do that either". Try subclassing
org.eclipse.swt.widgets.Dialog (the class javadoc even have an example
of where to put the code that creates controls).

PW
Previous Topic:Plugin dependency problem
Next Topic:Annoying Search view appears in 3.3RC4
Goto Forum:
  


Current Time: Wed Sep 17 17:20:12 EDT 2025

Powered by FUDForum. Page generated in 0.04556 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top