Home » Eclipse Projects » JFace » When can I use run() from ApplicationWindow?
When can I use run() from ApplicationWindow? [message #657] |
Wed, 06 May 2009 04:58 |
Allen D. McDonald Messages: 13 Registered: July 2009 |
Junior Member |
|
|
I have a middling little tool that uses a TreeViewer to display book files
and edit, open and build them. I built this strictly in SWT, but had a
lot of trouble with data/view synchronization. Then I ran across your
databinding and decided that was just the answer. So, version 2
commences. A lot more study and poking around and I decided to use
ApplicationWindow as my base. This si working out very nice, but it has
some distinct differences in application from SWT! Those for later.
Right now, my major problem is getting the data to the tree. I version
one, I used a set of threads, one to read the XML files from the disk, one
to parse those files into dataobjects, and the last to build the tree.
TreeViewer just takes an array on startup. Doesn't need building. I have
to go this way for the databinding, I think...
So, some snippets:
public class BookManager extends ApplicationWindow {
//some declarations
public BookManager() {
// Create a top level shell.
super(null);
// Create menu actions
exit_action = new ExitAction(this);
// Set up internal ApplicationWindow widgets
addStatusLine();
addMenuBar();
}
protected Control createContents(Composite parent) {
shell = getShell();
shell.setText("Book Manager");
SashForm sForm = new SashForm(parent, SWT.HORIZONTAL);
tv = new TreeViewer(sForm);
tv.setUseHashlookup(true);
tv.setAutoExpandLevel(2);
tv.setComparator(new ViewerComparator(usCollator));
tv.setContentProvider(new LibraryTreeContentProvider());
tv.setLabelProvider(new LibraryTreeLabelProvider());
// some more stuff
Line 127 initData(tv);
return sForm;
}
public static void main(String[] args) {
final Display display = Display.getDefault();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
w = new BookManager();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
savePropValues();
}
});
}
private static void initData(TreeViewer tv) {
authors = new Vector<AuthorDO>();
line 159 authors = getAuthorBooks();
tv.setInput(authors);
}
private static List<AuthorDO> getAuthorBooks(){
authors = new Vector<AuthorDO>();
try {
Line 227 w.run(true, false, new FindOPFs());
w.run(true, false, new ParseOPFs());
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return authors;
}
This is the stacktrace:
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.jface.window.ApplicationWindow.run(ApplicationWi ndow.java:702)
at com.admac.BookManager.getAuthorBooks(BookManager.java:227)
at com.admac.BookManager.initData(BookManager.java:159)
at com.admac.BookManager.createContents(BookManager.java:127)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.admac.BookManager$1.run(BookManager.java:150)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at com.admac.BookManager.main(BookManager.java:146)
My rough conclusion from looking at ApplicationWindow:702 is that the
window is not completely initialized. Is this true?
I was hoping to be able to use the IProgressMonitor while building the
data, but I can go back to popping a dialog box with a progressBar, I
guess.
I am using 3.5M6 build of Galileo.
Oh, and I feel for Mr. Ganapolsky. The docs on this are pretty raw as
yet, but the code is great. I have been looking for something to write
light GUI apps in Java with and this is now my new platform!
(In my working life I use Eclipse to write Enterprise level web apps.)
|
|
|
Re: When can I use run() from ApplicationWindow? [message #668 is a reply to message #657] |
Wed, 06 May 2009 08:33 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
At the time you are calling initData the createContents() is no finished
and hence you get the NPE.
Tom
Allen D. McDonald schrieb:
> I have a middling little tool that uses a TreeViewer to display book
> files and edit, open and build them. I built this strictly in SWT, but
> had a lot of trouble with data/view synchronization. Then I ran across
> your databinding and decided that was just the answer. So, version 2
> commences. A lot more study and poking around and I decided to use
> ApplicationWindow as my base. This si working out very nice, but it has
> some distinct differences in application from SWT! Those for later.
> Right now, my major problem is getting the data to the tree. I version
> one, I used a set of threads, one to read the XML files from the disk,
> one to parse those files into dataobjects, and the last to build the tree.
> TreeViewer just takes an array on startup. Doesn't need building. I
> have to go this way for the databinding, I think...
> So, some snippets:
>
> public class BookManager extends ApplicationWindow {
>
> //some declarations
>
> public BookManager() {
> // Create a top level shell.
> super(null);
> // Create menu actions
> exit_action = new ExitAction(this);
> // Set up internal ApplicationWindow widgets
> addStatusLine();
> addMenuBar();
> }
>
> protected Control createContents(Composite parent) {
> shell = getShell();
> shell.setText("Book Manager");
> SashForm sForm = new SashForm(parent, SWT.HORIZONTAL);
> tv = new TreeViewer(sForm);
> tv.setUseHashlookup(true);
> tv.setAutoExpandLevel(2);
> tv.setComparator(new ViewerComparator(usCollator));
> tv.setContentProvider(new LibraryTreeContentProvider());
> tv.setLabelProvider(new LibraryTreeLabelProvider());
>
> // some more stuff
> Line 127 initData(tv);
> return sForm;
> }
>
> public static void main(String[] args) {
> final Display display = Display.getDefault();
> Realm.runWithDefault(SWTObservables.getRealm(display), new
> Runnable() {
> public void run() {
> w = new BookManager();
> w.setBlockOnOpen(true);
> w.open();
> Display.getCurrent().dispose();
> savePropValues();
> }
> });
> }
>
> private static void initData(TreeViewer tv) {
> authors = new Vector<AuthorDO>();
> line 159 authors = getAuthorBooks();
> tv.setInput(authors);
> }
>
> private static List<AuthorDO> getAuthorBooks(){
> authors = new Vector<AuthorDO>();
>
> try {
> Line 227 w.run(true, false, new FindOPFs());
> w.run(true, false, new ParseOPFs());
> } catch (InvocationTargetException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (InterruptedException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> return authors;
> }
>
> This is the stacktrace:
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.jface.window.ApplicationWindow.run(ApplicationWi ndow.java:702)
> at com.admac.BookManager.getAuthorBooks(BookManager.java:227)
> at com.admac.BookManager.initData(BookManager.java:159)
> at com.admac.BookManager.createContents(BookManager.java:127)
> at org.eclipse.jface.window.Window.create(Window.java:431)
> at org.eclipse.jface.window.Window.open(Window.java:790)
> at com.admac.BookManager$1.run(BookManager.java:150)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
>
> at com.admac.BookManager.main(BookManager.java:146)
>
> My rough conclusion from looking at ApplicationWindow:702 is that the
> window is not completely initialized. Is this true?
> I was hoping to be able to use the IProgressMonitor while building the
> data, but I can go back to popping a dialog box with a progressBar, I
> guess.
> I am using 3.5M6 build of Galileo.
> Oh, and I feel for Mr. Ganapolsky. The docs on this are pretty raw as
> yet, but the code is great. I have been looking for something to write
> light GUI apps in Java with and this is now my new platform!
> (In my working life I use Eclipse to write Enterprise level web apps.)
>
|
|
| |
Goto Forum:
Current Time: Sat Dec 21 13:18:26 GMT 2024
Powered by FUDForum. Page generated in 0.03093 seconds
|