Arc Dockable Window


Having got our Dockable Window on the screen, we'll now try and dump our results into it.

To do this, we're going to need our RiskButton to call the window's setText method with the results String it generates at the end of the onClick method.

Make sure you understand this before going on -- it is going to get a little complicated, and you want to keep this core goal in mind!


Let's look at how you might imagine we could do this, but can't.

Let's look again at the RiskButton init code we wrote. You might imagine we could do this kind of thing (albeit after we've generated the results).

	try{
		IDockableWindowManager dwm = new IDockableWindowManagerProxy(app);
		UID uid = new UID();
		uid.setValue("uk.ac.leeds.geog.pgiaa.RiskOutput");
		docWin = dwm.getDockableWindow(uid);
		docWin.show(true);
		((RiskOutput)docWin).setText(results);
	} catch (Exception e){
		JOptionPane.showMessageDialog(null, "ex3: " + e.getMessage());
	}

That is, cast the DockableWindow into our specific type of DockableWindow, RiskOutput, and then use the setText method in it (remember, this is specific to that RiskOutput class that we wrote, not the generic DockableWindow).

However, remember that the DockableWindow Arc uses isn't the class we've generated -- Arc wraps a DockableWindow around that and uses our code to set that window up. In actual fact, they are two completely different types of thing. Our addin inherits from com.esri.arcgis.addins.desktop.DockableWindow, whereas the code above gets something that inherits com.esri.arcgis.framework.IDockableWindow. This is problematic then. How do we get at the GUI, which is initially set up in our class and is lost somewhere inside an IDockableWindow we didn't make, poor thing?

This is where our Singletons come in. Our DockableWindow code is held as a static variable inside the Arc IDockableWindow proper. This means that if we build it as a Singleton, we should be able to get hold of it and run its methods -- which, in turn, have access to the GUI. Sooooo. Let's do that now.


Add in the code to turn the RiskOutput DockableWindow we've written into a Singleton - this is in your lecture notes (remember the Singleton class is called RiskOutput here, so you'll need to change the lecture code, which is for AddIn or the Cookbook code, which is for OurWindowClass).


Once you've done that, and checked it compiles ok, we'll go on to get a copy of the Singleton in RiskButton.

Open up RiskButton, remove the line that writes the results array to a JOptionPane and alter the code at the end of onClick to this (you'll have to import uk.ac.leeds.geog.pgiaas.RiskOutput, and, as with last practical, you'll need to think through scoping issues):

if (docWin != null) {
 RiskOutput ro = RiskOutput.getInstance();
 ro.setText(results);
 docWin.show(true);
}


Give that a go -- the results should now appear in the DockableWindow. You may find that the JOptionPanes refuse to respond to mouse clicks. If this is the case, open up windows task manager and "End Process" each message box as it appears (to open task manager, right-click the bar at the bottom of your desktop and select it). You may also find that the dockable window is minimised the first time it appears. If you can't see it, minimise any other dockable windows on the correct side (for example, the Table of Contents), then grab the border and drag it out towards the centre of the application. Next time you restart Arc it should work fine.

If you're a bit confused, I don't blame you at all - ask, and we'll go through it. If you're not confused, congrats -- you're done for today. If you want to have a play with something, why not have a go at editing some data?