State/condition for selected feature class/table in a geodatabase

1004
3
Jump to solution
07-20-2021 10:55 AM
MarvisKisakye1
Occasional Contributor

I need to locate a state or condition for enabling a button when there's a selected feature class or table in a geodatabase (file geodatabase and sde). 

I utilized this sample https://github.com/Esri/arcgis-pro-sdk-comunity-samples/tree/44183d0d5a9bc5da6fb8b9229211cc707dd2b87... but these states/conditions are not exposed. I have also searched the daml files at https://github.com/esri/arcgis-pro-sdk/wiki/ArcGIS-Pro-DAML-ID-Reference to no avail. @CharlesMacleod @Wolf @UmaHarano 

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hi Marvis, 

 

I had a look at the existing conditions that live in the ADGeodatabase.daml file (which can be found in (installPath\bin\Extensions\Catalog). And it doesn't appear that there is anything that will help you in what you're trying to achieve.  

 

However this may be a workaround for you.  Subscribe to the ArcGIS.Desktop.Core.Events.ProjectWindowSelectedItemsChangedEvent.   In your delegate, examine the TypeID of the selected item and activate or deactivate your own states.   Then in your daml file, create your own condition based on your state.  Here's a bit of a snippet to get you started

 

protected override void OnClick()
    {
      if (subscribed)
        ProjectWindowSelectedItemsChangedEvent.Unsubscribe(OnProjectWindowSelectedItem);
      else
        ProjectWindowSelectedItemsChangedEvent.Subscribe(OnProjectWindowSelectedItem);

      subscribed = !subscribed;
    }

    private async void OnProjectWindowSelectedItem(ProjectWindowSelectedItemsChangedEventArgs args)
    {
      if (args.IProjectWindow.SelectionCount > 0)
      {
        // get the first selected item
        var selectedItem = args.IProjectWindow.SelectedItems.First();
        string typeID = selectedItem.TypeID;

        // TypeID for file gdb is "database_fgdb"
        // TypeID for file gdb items are "fgdb_table", "fgdb_relationship", "fgdb_fc_point", "fgdb_fc_polygon" etc
        if (IsFGDBItem(typeID))
          FrameworkApplication.State.Activate("FGDBItemSelected");
        else
          FrameworkApplication.State.Deactivate("FGDBItemSelected");

        // TypeID for enterprise gdb is "database_egdb"
        // TypeID for enterprise gdb items are "egdb_table", "egdb_relationship", "egdb_fc_point", "egdb_fc_polygon" etc
        if (IsEGDBItem(typeID))
          FrameworkApplication.State.Activate("EGDBItemSelected");
        else
          FrameworkApplication.State.Deactivate("EGDBItemSelected");
      }
    }
    private bool IsFGDBItem(string typeID)
    {
      if (typeID.StartsWith("fgdb_"))
        return true;
      return false;
    }

    private bool IsEGDBItem(string typeID)
    {
      if (typeID.StartsWith("egdb_"))
        return true;
      return false;
    }

 

And the daml

    <insertCondition id="myCondition" caption="">
      <or>
        <state id="FGDBItemSelected"/>
        <state id="EGDBItemSelected"/>
      </or>
    </insertCondition>

 

You can of course make the IsFGDBItem and IsEGDBItem routines more restrictive if you're only looking for feature classes or tables and not other data items like relationships, topologies etc.  Search the ADGeodatabase.daml file for specific TypeID strings for specific dataset types. 

 

Hope this helps.  

Narelle

View solution in original post

0 Kudos
3 Replies
CharlesMacleod
Esri Regular Contributor

I'll take a look and get back to you - but - FYI, there is no such thing as a private state or condition....if u did not "see" a state or condition being set then that probably means that there isn't one. 

0 Kudos
NarelleChedzey
Esri Contributor

Hi Marvis, 

 

I had a look at the existing conditions that live in the ADGeodatabase.daml file (which can be found in (installPath\bin\Extensions\Catalog). And it doesn't appear that there is anything that will help you in what you're trying to achieve.  

 

However this may be a workaround for you.  Subscribe to the ArcGIS.Desktop.Core.Events.ProjectWindowSelectedItemsChangedEvent.   In your delegate, examine the TypeID of the selected item and activate or deactivate your own states.   Then in your daml file, create your own condition based on your state.  Here's a bit of a snippet to get you started

 

protected override void OnClick()
    {
      if (subscribed)
        ProjectWindowSelectedItemsChangedEvent.Unsubscribe(OnProjectWindowSelectedItem);
      else
        ProjectWindowSelectedItemsChangedEvent.Subscribe(OnProjectWindowSelectedItem);

      subscribed = !subscribed;
    }

    private async void OnProjectWindowSelectedItem(ProjectWindowSelectedItemsChangedEventArgs args)
    {
      if (args.IProjectWindow.SelectionCount > 0)
      {
        // get the first selected item
        var selectedItem = args.IProjectWindow.SelectedItems.First();
        string typeID = selectedItem.TypeID;

        // TypeID for file gdb is "database_fgdb"
        // TypeID for file gdb items are "fgdb_table", "fgdb_relationship", "fgdb_fc_point", "fgdb_fc_polygon" etc
        if (IsFGDBItem(typeID))
          FrameworkApplication.State.Activate("FGDBItemSelected");
        else
          FrameworkApplication.State.Deactivate("FGDBItemSelected");

        // TypeID for enterprise gdb is "database_egdb"
        // TypeID for enterprise gdb items are "egdb_table", "egdb_relationship", "egdb_fc_point", "egdb_fc_polygon" etc
        if (IsEGDBItem(typeID))
          FrameworkApplication.State.Activate("EGDBItemSelected");
        else
          FrameworkApplication.State.Deactivate("EGDBItemSelected");
      }
    }
    private bool IsFGDBItem(string typeID)
    {
      if (typeID.StartsWith("fgdb_"))
        return true;
      return false;
    }

    private bool IsEGDBItem(string typeID)
    {
      if (typeID.StartsWith("egdb_"))
        return true;
      return false;
    }

 

And the daml

    <insertCondition id="myCondition" caption="">
      <or>
        <state id="FGDBItemSelected"/>
        <state id="EGDBItemSelected"/>
      </or>
    </insertCondition>

 

You can of course make the IsFGDBItem and IsEGDBItem routines more restrictive if you're only looking for feature classes or tables and not other data items like relationships, topologies etc.  Search the ADGeodatabase.daml file for specific TypeID strings for specific dataset types. 

 

Hope this helps.  

Narelle

0 Kudos
MarvisKisakye1
Occasional Contributor

This is a good workaround. Thank you!

0 Kudos