Code for making and using a DockableWindow addin


Details

Code to make a DockableWindow addin, and then, below it, code to use the DockableWindow in a Button addin.


Original author/s: ESRI
Original location/s: How to create an add-in dockable window
Adapted by: Andy Evans
License: unknown
Other info: This code shows how to start a DockableWindow from a Button, but says nothing about how to communicate between the two, so the Button can run code in the Window. For this, see Communicating between addins.


DockableWindow: Imports and instance variables

	import com.esri.arcgis.addins.desktop.DockableWindow;
	import javax.swing.*;
	import com.esri.arcgis.framework.IApplication;

 


 

DockableWindow: Code

	public class OurWindowClass extends DockableWindow {

		private IApplication app = null;
	
		public void init(IApplication app) {
			this.app = app;
		}
				
		@Override
		public Component createUI() {
			JPanel jPanel = new JPanel();
			// Add stuff to the panel.
			return jPanel;
		}

	}

 


 

Button: Imports and instance variables

	// Note, critically, that we don't import com.esri.arcgis.addins.desktop.DockableWindow;
	// This is suprising, as this is the class extended above. See below.
	import com.esri.arcgis.framework.IApplication;
	import com.esri.arcgis.framework.IDockableWindow;
	import com.esri.arcgis.framework.IDockableWindowManager;
	import com.esri.arcgis.framework.IDockableWindowManagerProxy;

 


 

Button: Code

	public class OurButton extends Button {

		private IApplication app = null;
		private IDockableWindow docWin = null;
	
	
		@Override
		public void onClick() throws IOException, AutomationException {
			if (docWin != null) {
				docWin.show(true);
			}
		}
	
	
		public void init (IApplication app) {
			this.app = app;
		
			try{
				IDockableWindowManager dwm = new IDockableWindowManagerProxy(app);
				UID uid = new UID();
				uid.setValue("uk.ac.leeds.geog.pgiaa.OurWindowClass");
				
				// Note that the next line returns our com.esri.arcgis.addins.desktop.DockableWindow 
				// but wrapped up inside a com.esri.arcgis.framework.DockableWindow. We cannot therefore 
				// cast the DockableWindow we get into either the original [OurWindowClass] class, or com.esri.arcgis.addins.desktop.DockableWindow. 
				// This causes us considerable issues if we want to get the original object to run methods inside. For the solution see "More info", above.
			
				docWin = dwm.getDockableWindow(uid);
				
				docWin.show(false);
			} catch (Exception e){
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}