Example #1
0
        private void MenuItem_Activate(object sender, EventArgs e)
        {
            try {
                TreeNode treeNode = this.treeView1.SelectedNode;
                if (treeNode == null)
                {
                    return;
                }
                TreeNodeTable treeNodeTable = treeNode as TreeNodeTable;
                if (treeNodeTable == null)
                {
                    return;
                }
                EsriTable table = treeNodeTable.Table;
                if (table == null)
                {
                    return;
                }

                if (sender == this.menuButtonItemScroll)
                {
                    this._model.ScrollToElement(table);
                }
                else if (sender == this.menuButtonItemFlash)
                {
                    table.Flash();
                }
            }
            catch (Exception ex) {
                ExceptionDialog.HandleException(ex);
            }
        }
        private void MenuItem_Activate(object sender, EventArgs e)
        {
            try {
                //
                // Error List Context Menu
                //
                if (sender == this.menuButtonItemScroll)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count != 1)
                    {
                        return;
                    }

                    // Get EsriTable containing the error
                    ListViewItemError item  = (ListViewItemError)this.listViewErrorList.SelectedItems[0];
                    EsriTable         table = null;
                    if (item.Error is ErrorTable)
                    {
                        ErrorTable errorTable = (ErrorTable)item.Error;
                        table = errorTable.Table;
                    }
                    else if (item.Error is ErrorTableRow)
                    {
                        ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                        EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                        table = (EsriTable)esriTableRow.Table;
                    }
                    else if (item.Error is ErrorObject)
                    {
                        ErrorObject errorObject = (ErrorObject)item.Error;
                        table = errorObject.Table;
                    }
                    if (table == null)
                    {
                        return;
                    }

                    // Get Containing Model
                    EsriModel model = (EsriModel)table.Container;

                    // Scroll to Table
                    model.ScrollToElement(table);

                    // Flash Table
                    table.Flash();
                }
                else if (sender == this.menuButtonItemSelect)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0)
                    {
                        return;
                    }

                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        EsriModel model = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            EsriTable  table      = errorTable.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            EsriTable     table         = (EsriTable)esriTableRow.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            EsriTable   table       = errorObject.Table;
                            model = (EsriModel)table.Container;
                        }
                        if (model == null)
                        {
                            continue;
                        }

                        // Clear Model Selection
                        model.SelectElements(false);
                    }
                    //
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null)
                        {
                            continue;
                        }

                        // Flash Table
                        table.Selected = true;
                    }
                }
                else if (sender == this.menuButtonItemFlashError)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0)
                    {
                        return;
                    }

                    //
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null)
                        {
                            continue;
                        }

                        // Flash Table
                        table.Flash();
                    }
                }
                else if (sender == this.menuButtonItemClearError)
                {
                    // Remove Selected Items
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        if (this.m_errors.Contains(item.Error))
                        {
                            this.m_errors.Remove(item.Error);
                        }
                    }

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                else if (sender == menuButtonItemClearAllErrors)
                {
                    // Remove All Errors
                    this.m_errors.Clear();

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                //
                // Validator Dropdown Menu
                //
                else if (sender == this.menuButtonItemPGdb)
                {
                    WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemFGdb)
                {
                    WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemSelectGeodatabase)
                {
                    // Create GxObjectFilter for GxDialog
                    IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass();

                    // Create GxDialog
                    IGxDialog gxDialog = new GxDialogClass();
                    gxDialog.AllowMultiSelect = false;
                    gxDialog.ButtonCaption    = Resources.TEXT_SELECT;
                    gxDialog.ObjectFilter     = gxObjectFilter;
                    gxDialog.RememberLocation = true;
                    gxDialog.Title            = Resources.TEXT_SELECT_EXISTING_GEODATABASE;

                    // Declare Enumerator to hold selected objects
                    IEnumGxObject enumGxObject = null;

                    // Open Dialog
                    if (!gxDialog.DoModalOpen(0, out enumGxObject))
                    {
                        return;
                    }
                    if (enumGxObject == null)
                    {
                        return;
                    }

                    // Get Selected Object (if any)
                    IGxObject gxObject = enumGxObject.Next();
                    if (gxObject == null)
                    {
                        return;
                    }
                    if (!gxObject.IsValid)
                    {
                        return;
                    }

                    // Get GxDatabase
                    if (!(gxObject is IGxDatabase))
                    {
                        return;
                    }
                    IGxDatabase gxDatabase = (IGxDatabase)gxObject;

                    // Get Workspace
                    IWorkspace workspace = gxDatabase.Workspace;
                    if (workspace == null)
                    {
                        return;
                    }

                    // Get Workspace Factory
                    IWorkspaceFactory workspaceFactory = workspace.WorkspaceFactory;
                    if (workspaceFactory == null)
                    {
                        return;
                    }

                    // Get Workspace Factory ID
                    IUID   uid  = workspaceFactory.GetClassID();
                    string guid = uid.Value.ToString().ToUpper();

                    switch (guid)
                    {
                    case EsriRegistry.GEODATABASE_PERSONAL:
                        WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator(workspace);
                        break;

                    case EsriRegistry.GEODATABASE_FILE:
                        WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator(workspace);
                        break;

                    case EsriRegistry.GEODATABASE_SDE:
                        WorkspaceValidator.Default.Validator = new SdeValidator(workspace);
                        break;

                    default:
                        break;
                    }
                }
                else if ((sender is MenuButtonItem) && (((MenuButtonItem)sender).Parent == this.menuButtonItemSdeConnection))
                {
                    MenuButtonItem item = (MenuButtonItem)sender;
                    if (item.Tag == null)
                    {
                        return;
                    }
                    WorkspaceValidator.Default.Validator = new SdeValidator(item.Tag.ToString());
                }
            }
            catch (Exception ex) {
                ExceptionDialog.HandleException(ex);
            }
        }