Creating ArcMap addins with Java SDk

5364
19
03-20-2014 11:50 AM
KevinYanuk
Occasional Contributor
Hello,

I am trying to create a simple Dockable Window addin using the ArcObjects Java SDK, but I am having a small issue.  I am able to create the addin successfully, with a button and dockable window, but when I install the addin using the .esriAddin installer, I cannot see the addin located in the category I chose... here is my code:

button:
import java.io.IOException;

import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.framework.IDockableWindow;
import com.esri.arcgis.framework.IDockableWindowManager;
import com.esri.arcgis.framework.IDockableWindowManagerProxy;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.UID;


public final class btnMain extends Button
{
 private IDockableWindow docWin;

 @Override 
 public void init(IApplication app) {
     try {
         IDockableWindowManager dwm = new IDockableWindowManagerProxy(app);
         UID uid = new UID();
         uid.setValue("com.esri.arcgis.arcmap.addin.frmMain");
         docWin = dwm.getDockableWindow(uid);
     }
     catch (Exception e) {
         e.printStackTrace();
     }
 }
 
 @Override
 public void onClick() throws IOException, AutomationException {
  try {
         if (docWin != null) {
             docWin.show(!docWin.isVisible());
         }
     }
     catch (Exception e) {
         e.printStackTrace();
     }
 }
}


dockable window:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.esri.arcgis.addins.desktop.DockableWindow;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.interop.AutomationException;


public final class frmMain extends DockableWindow
{
 private JButton jButton;
 private JPanel jPanel;
 private IApplication app;
 
 public static void main(String[] args){
 }

 @Override
 public Component createUI() {
  jButton = new JButton("Click Me!");
     jPanel = new JPanel();

     jButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
             JOptionPane.showMessageDialog(null, "Hello, World"); 
         } 
     });
     
     jPanel.setLayout(new BorderLayout());
     jPanel.add(jButton, BorderLayout.NORTH);

     return jPanel;
 }
 
 @Override 
 public void init(IApplication app) {
     this.app = app;
     try {
   IMxDocument mxDocument = (IMxDocument)app.getDocument();
  } catch (AutomationException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}



Any help is greatly appreciated.

Thanks
0 Kudos
19 Replies
KevinYanuk
Occasional Contributor
EDIT: I was able to get the Java Commands category to show up once using 1.6, but have not been able to reproduce it... I tried remaking the addin using the same steps, and it is missing once again... below are my steps using JRE 1.6:

[ATTACH=CONFIG]32689[/ATTACH]
[ATTACH=CONFIG]32690[/ATTACH]
[ATTACH=CONFIG]32691[/ATTACH]
[ATTACH=CONFIG]32692[/ATTACH]
[ATTACH=CONFIG]32693[/ATTACH]


continued:

[ATTACH=CONFIG]32694[/ATTACH]
[ATTACH=CONFIG]32695[/ATTACH]
[ATTACH=CONFIG]32696[/ATTACH]


Walking through the steps to create this simple button seems to install the addin, but I am unable to actually find it in my categories... not sure where I am going wrong.
0 Kudos
KevinYanuk
Occasional Contributor
bump... looking for some more technical assistance with this issue
0 Kudos
LeoDonahue
Occasional Contributor III
Look at the source of your config.xml.

<ArcMap>
  <Commands>
    <Button ... in here is where you want to check the following:
  </Commands>

1. The category value is correct.
2. The class value contains the full package name of the class, if you put your Button1 class in a package.
3. If you used an image for your button, make sure the path is correct.
0 Kudos
KevinYanuk
Occasional Contributor
Look at the source of your config.xml.

<ArcMap>
  <Commands>
    <Button ... in here is where you want to check the following:
  </Commands>

1. The category value is correct.
2. The class value contains the full package name of the class, if you put your Button1 class in a package.
3. If you used an image for your button, make sure the path is correct.



Here is what is created:
[ATTACH=CONFIG]32955[/ATTACH]



[ATTACH=CONFIG]32956[/ATTACH]

I've noticed that even with the SDK for 10.1, the version it creates is 10.0 ... I've tried changing that to 10.1 before and after exporting the addin, but the Java Commands category still is not showing up.
0 Kudos
LeoDonahue
Occasional Contributor III
A screenshot of your project expanded would help.

Your java source files are in a folder called:  src or java ?

Did you place the Button1 class in a package of your own?

Such as:

My Project[INDENT]java (or src)[/INDENT]
[INDENT=2]your.package.name[/INDENT]
[INDENT=3]Button1.java
[/INDENT]
0 Kudos
LeoDonahue
Occasional Contributor III
Also, the thing that is not the same in your environment is you have a value of "default" for the <AddInID> tag, whereas I have a value that looks like this:

<AddInID>473e3189-0145-1000-5000-0a09186f0000</AddInID>

The Add-in project wizzard places that value there for me, I don't do anything to generate it.

Why is that?
0 Kudos
KevinYanuk
Occasional Contributor
A screenshot of your project expanded would help.

Your java source files are in a folder called:  src or java ?

Did you place the Button1 class in a package of your own?

Such as:

My Project[INDENT]java (or src)[/INDENT]
[INDENT=2]your.package.name[/INDENT]
[INDENT=3]Button1.java
[/INDENT]



Expanded project:

[ATTACH=CONFIG]32958[/ATTACH]
0 Kudos
KevinYanuk
Occasional Contributor
Also, the thing that is not the same in your environment is you have a value of "default" for the <AddInID> tag, whereas I have a value that looks like this:

<AddInID>473e3189-0145-1000-5000-0a09186f0000</AddInID>

The Add-in project wizzard places that value there for me, I don't do anything to generate it.

Why is that?



Good question... doesn't look like mine is being generated... not sure why?  Perhaps that may be an issue, however, the addin itself is being recognized in ArcMap, just not the button.


EDIT:  It has something to do with the fact that the template being autogenerated is for 10.0 ...
[ATTACH=CONFIG]32963[/ATTACH]
0 Kudos
LeoDonahue
Occasional Contributor III
Ok, you solved it.

The class name in the config.xml needs to include your package name, which I said before.

In the config.xml gui or the source, change the class value to:  my.pkg.Button1.java
0 Kudos
KevinYanuk
Occasional Contributor
Ok, you solved it.

The class name in the config.xml needs to include your package name, which I said before.

In the config.xml gui or the source, change the class value to:  my.pkg.Button1.java



Updated the config, and exported and reinstalled the addin... still nothing.
0 Kudos