0

I'm trying to set up an info table in an addin for ArcGIS 10. I'm using Java and Eclipse IDE. The code I have is here:

public class Tables {

String database = "C:\\GIS";
String nameOfTable = "getOn";
public ITable createInfoTable(String database, String nameOfTable) throws IOException  {



        IPropertySet propertySet = new PropertySet();
        propertySet.setProperty("DATABASE", database);



        IWorkspaceFactory workspaceFactory = new ArcInfoWorkspaceFactory();



        IArcInfoWorkspace workspace = (IArcInfoWorkspace)workspaceFactory.open( propertySet, 0);

        //Fails here (or above actually)  Check out Factory.open


        IArcInfoItems arcInfoItems = new ArcInfoItems();
        ITable  myTable = workspace.createInfoTable("myTable", arcInfoItems);


        return myTable;

I've adapted this code from C# as there are no examples on the Arc pages for Java. You can see with the comment where it is failing. If you can see what's going wrong please let me know. And I will repost if I crack it. (see here for original C# example: http://resources.esri.com/help/9.3/ArcGISEngine/ArcObjects/esriDataSourcesFile/IArcInfoWorkspace.CreateInfoTable_Example.htm)

2
  • It would help to know the error.
    – Chaz
    Commented Apr 11, 2012 at 13:53
  • you're right there Chaz. Unspecified error is all it gives me. Commented Apr 11, 2012 at 20:58

2 Answers 2

1

Okay, I've worked around this in a different way. I'll put everything in to help others out. Firstly I needed a workspace object which can be returned as follows:

    static IWorkspace openWorkspace(String pathToFile)throws Exception
{
    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
    return  workspaceFactory.openFromFile(pathToFile, 0);

}

Following that it was table building time. I've adapted the following code from a C# snippet I found online. Instead of asking for an IWorkspace2 object this javised version asks for an IWorkspace object. There's not a lot of other differences apart from casting the workspace object later on in order to use the IWorkspace2 interface briefly and slight changes to the checkFields inputs.The IGeoprocessor bit is just me trying to find the current workspace of the user which can then obviously be passed to the method above.

public ITable createTable(IWorkspace workspace, String nameOfTable, IFields fields) throws Exception  {

    System.out.println("" + openWorkspace("C:\\GIS\\Test.gdb"));
    /*
    IGeoProcessor geop = new GeoProcessor();
    String userWkSp = (String) geop.getEnvironmentValue("workspace");


    System.out.println("user workpace = " + userWkSp);
    */
      // create the behavior clasid for the featureclass
      UID uid = new UID();

      if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

      IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast
      ITable table;

      System.out.println("Got this far");
      IWorkspace2 wkSp2 = (IWorkspace2) workspace;
      if (wkSp2.isNameExists(esriDatasetType.esriDTTable, nameOfTable))
      {
        // table with that name already exists return that table 
        table = featureWorkspace.openTable(nameOfTable);
        return table;
      }

      uid.setValue("esrigeodatabase.Object");

      IObjectClassDescription objectClassDescription = new ObjectClassDescription();

      // if a fields collection is not passed in then supply our own
      if (fields == null)
      {
        // create the fields using the required fields method
        fields = objectClassDescription.getRequiredFields();
        IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit Cast

        IField field = new Field();

        // create a user defined text field
        IFieldEdit fieldEdit = (IFieldEdit)field; // Explicit Cast

        // setup field properties
        fieldEdit.setName("SampleField");
        fieldEdit.setType(esriFieldType.esriFieldTypeString);

        fieldEdit.setAliasName("Sample Field Column");
        fieldEdit.setDefaultValue("test");

        fieldEdit.setLength(100);

        // add field to field collection
        fieldsEdit.addField(field);
        fields = (IFields)fieldsEdit; // Explicit Cast
      }
      // Use IFieldChecker to create a validated fields collection.
      IFieldChecker fieldChecker = new FieldChecker();
      IEnumFieldError enumFieldError[] = null;
      IFields validatedFields[] = null;

      fieldChecker.setValidateWorkspaceByRef((IWorkspace)workspace);
      fieldChecker.validate(fields, enumFieldError,  validatedFields);

      // The enumFieldError enumerator can be inspected at this point to determine 
      // which fields were modified during validation.


      // create and return the table
      table = featureWorkspace.createTable(nameOfTable, fields, uid, uid, "");



    return table;
    }
0

I think you need to cast the arcInfoItems to IArcInfoItemsEditProxy and call addItem to add items (aka fields) to the table.

Each item is defined using IArcInfoItemEdit.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.