How to view the attributes table like arcmap in arcgis engine application using java?

1623
7
02-23-2011 11:30 AM
ViridianaGO
New Contributor III
Hi again! I have a question, how can I view the attributes table like Arcmap in an Arcgis Engine application using Java? Thanks a lot.
0 Kudos
7 Replies
ViridianaGO
New Contributor III
Anyone have an idea? Thanks a lot.
0 Kudos
OlaRennemo
New Contributor III
Anyone have an idea? Thanks a lot.


If using a geodatabase, try to connect via a normal database connection, and display content in "normal" controls as with any other data source.
But beware that ArcGIS components buffers data, and updates made from the "outside" are not  displayed immediately.
0 Kudos
ViridianaGO
New Contributor III
Thanks for your answer, unfortunately this is not the case, I am not using a geodatabase. If someone have another idea I will appreciate your help, thanks.
0 Kudos
OlaRennemo
New Contributor III
Thanks for your answer, unfortunately this is not the case, I am not using a geodatabase. If someone have another idea I will appreciate your help, thanks.


Then I think I would have tried something like this:

-Read data:
Get a FeatureClass reference, make a TableSort instance, get Cursor form it, and read the data source row by row, including the objectid.
-Show data:
For each row, insert data into a java TableModel compatible object.
Then use it as dataMode for a JTable.
-Update data:
Read the objectid, and get a feature referende from the FeatureClass, and update it with new values.
0 Kudos
ViridianaGO
New Contributor III
Hi!, thanks for your answer. I have implemented the Read and Show data to a determinated layer, but how can I know which feature layer is selected with the mouse to see the attribute table? If you can share some code for this I will appreciate your help. Thank you very much.
0 Kudos
OlaRennemo
New Contributor III
Hi!, thanks for your answer. I have implemented the Read and Show data to a determinated layer, but how can I know which feature layer is selected with the mouse to see the attribute table? If you can share some code for this I will appreciate your help. Thank you very much.


I am sure you can find a lot of good examples in the ESRI site. Also I am currently using DotNet for my GIS programming. But since C# and Java have much in common, these methods might give you some ideas to work on:
(As you see, they are not complete as is, since they rely on some other settings.)


        // Select features with specified geometry and mode.
// selectGeometry is usually a point derived from "IMxDocument.CurrentLocation"
// Assuming interesting layers are made selectable first.
public void selectByGeometry(IGeometry selectGeometry, esriSelectionResultEnum mode, bool justOne)
{
  if(selectGeometry==null){return;}
  if(selectGeometry.IsEmpty){return;}           
  // Make the selection:
  IMxApplication mxapp =  ...
  ISelectionEnvironment env = mxapp.SelectionEnvironment;
  env.CombinationMethod = mode;
  //env.PointSelectionMethod =
  //env.LinearSelectionMethod =
  //env.AreaSelectionMethod =               
  IMap map = mxDoc.FocusMap; // From IMxDocument
  if(map!=null)
  {
   map.SelectByShape(selectGeometry,env,justOne);
  }
  else
  {
   System.Exception e = new System.Exception("Document.FocusMap not defined.\nSelct not possible");
   throw e;
  }
}

// Get list of selected features for specific layer:
public IFeature[] getSelectedFeatures(IFeatureLayer fl)
{
  IFeatureSelection fs = (IFeatureSelection)fl;
  IFeature[] fList = new IFeature[fs.SelectionSet.Count];
  IEnumIDs en = fs.SelectionSet.IDs;
  en.Reset();
  for(int i=0; i<fs.SelectionSet.Count; i++)
  {
   Int32 fid = en.Next();
   IFeature f = fl.FeatureClass.GetFeature(fid);
   fList = f;
  }
  return fList;
}




// Get all featurelayers in document:
public static ArrayList getFeatureLayersArray(IMxDocument doc)
        {
            featureLayerUID = new UIDClass();
            featureLayerUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
            ArrayList list = new ArrayList();
            for (int i = 0; i < doc.Maps.Count; i++)
            {
                IMap map = doc.Maps.get_Item(i);
                IEnumLayer en = map.get_Layers(GisGlobals.featureLayerUID, true);
                do
                {
                    ILayer layer = en.Next();
                    if (layer == null) { break; }
                    try
                    {
                        IFeatureLayer fl = (IFeatureLayer)layer;
                        list.Add(fl);
                    }
                    catch
                    {
                    }
                } while (true);
            }
            return list;
        }
0 Kudos
ViridianaGO
New Contributor III
Thank you for your answer, I will try to implement your ideas. Thanks for your time.
0 Kudos