1 / 12

Arc: Communications between Addins

Arc: Communications between Addins. Dr Andy Evans. Communication between addins. There are various ways of getting hold of other addins, built into the system. However, these are addin specific. Eg. IDockableWindowManager dwm = new IDockableWindowManagerProxy(app); UID uid = new UID();

Télécharger la présentation

Arc: Communications between Addins

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arc: Communications between Addins Dr Andy Evans

  2. Communication between addins There are various ways of getting hold of other addins, built into the system. However, these are addin specific. Eg. IDockableWindowManager dwm = new IDockableWindowManagerProxy(app); UID uid = new UID(); uid.setValue(uk.ac.leeds.geog.geog5790.OurWindow); IDockableWindow tableWin = dwm.getDockableWindow(uid);

  3. More generic method Every addin is held as a static variable within ArcGIS. That is, there is only one copy of it. We could get hold of this, if only we had a method to do so. To understand how we can build such a method, we need to understand Singletons.

  4. Singletons Singletons are both a class and a static variable. Because they are static, there is only ever one copy of them. However, they are not troubled by the problems of containing static code, as they are also perfectly normal classes. How is this amazing trick done?

  5. Simple Singleton class Singleton { static Singleton single = null; static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. }

  6. Use Note that as getInstance is static, we can call it using the class: Singleton s = Singleton.getInstance(); But it returns to us the class as an object we can use: s.whateverMethodInSingletonWeWant(); But the object is static, so if we call getInstance somewhere else, we get exactly the same object, including any changes we’ve made to it in other code.

  7. Simple Singleton However, we want to make sure no one does this: Singleton s = new Singleton(); Let alone this: s.single = someOtherSingleton; So the constructor (unusually) and the variable are set to private, so no one outside the Singleton class can use them. We must include the empty (or otherwise) constructor, to force it to be private.

  8. Simple Singleton class Singleton { private static Singleton single = null; private Singleton() {} public static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. } Here the constructor is called from within the class, so it works fine, even though the constructor is private.

  9. Uses Wherever you need one specific version of something, e.g. for storage, that everything else can get at. Wherever you need to communicate between different code running on the JVM. e.g. between Applets running in different webpage frames. Note, however, that which can see it will depend on how the JVM classloader is activated.

  10. AddIns As addins are static variables in Arc, if we build them to be Singletons, we can use the Class’ getInstance() method to get hold of them in other code. Note, however, that as Arc is making the static variable, from the class, we shouldn’t. We don’t need to call the constructor. Arc, however, does need access to it, so it must be public.

  11. AddIn Singleton class AddIn{ private static AddInaddIn = null; public AddIn() { addIn = this; // Grab our static } // variable as Arc makes it. public static AddIngetInstance() { return addIn; } // other methods. } Note the use of “this” to get the object we are currently inside.

  12. Use Again, then, we can: AddIn a = AddIn.getInstance(); a.whateverMethodInSingletonWeWant();

More Related