Example #1
0
        private ContextMenuStrip GetMenuIfExists(object o)
        {
            var many = o as ICollection;

            if (many != null)
            {
                var menu = new ContextMenuStrip();

                var factory = new AtomicCommandUIFactory(_activator);

                if (many.Cast <object>().All(d => d is IDeleteable))
                {
                    var mi = factory.CreateMenuItem(new ExecuteCommandDelete(_activator, many.Cast <IDeleteable>().ToList()));
                    mi.ShortcutKeys = Keys.Delete;
                    menu.Items.Add(mi);
                }

                return(menu);
            }

            if (o != null)
            {
                //is o masquerading as someone else?
                IMasqueradeAs masquerader = o as IMasqueradeAs;

                //if so this is who he is pretending to be
                object masqueradingAs = null;

                if (masquerader != null)
                {
                    masqueradingAs = masquerader.MasqueradingAs(); //yes he is masquerading!
                }
                var menu = GetMenuWithCompatibleConstructorIfExists(o);

                //If no menu takes the object o try checking the object it is masquerading as as a secondary preference
                if (menu == null && masqueradingAs != null)
                {
                    menu = GetMenuWithCompatibleConstructorIfExists(masqueradingAs, masquerader);
                }

                //found a menu with compatible constructor arguments
                if (menu != null)
                {
                    if (!Settings.AllowPinning)
                    {
                        var miPin = menu.Items.OfType <AtomicCommandMenuItem>().SingleOrDefault(mi => mi.Tag is ExecuteCommandPin);

                        if (miPin != null)
                        {
                            miPin.Enabled     = false;
                            miPin.ToolTipText = "Pinning is disabled in this collection";
                        }
                    }

                    return(menu);
                }

                //no compatible menus so just return default menu
                var defaultMenu = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(_activator, Tree, o), o);
                defaultMenu.AddCommonMenuItems(this);
                return(defaultMenu);
            }
            else
            {
                //it's a right click in whitespace (nothing right clicked)

                AtomicCommandUIFactory factory = new AtomicCommandUIFactory(_activator);

                if (WhitespaceRightClickMenuCommandsGetter != null)
                {
                    var menu = factory.CreateMenu(_activator, Tree, _collection, WhitespaceRightClickMenuCommandsGetter(_activator));
                    menu.AddCommonMenuItems(this);
                    return(menu);
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Creates a menu compatible with object <paramref name="o"/>.  Returns null if no compatible menu exists.
        /// Errors are reported to <see cref="IBasicActivateItems.GlobalErrorCheckNotifier"/> (if set up).
        ///
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public ContextMenuStrip GetMenuIfExists(object o)
        {
            try
            {
                var many = o as ICollection;

                if (many != null)
                {
                    var menu = new ContextMenuStrip();

                    var factory = new AtomicCommandUIFactory(_activator);

                    if (many.Cast <object>().All(d => d is IDisableable))
                    {
                        var mi = factory.CreateMenuItem(new ExecuteCommandDisableOrEnable(_activator, many.Cast <IDisableable>().ToArray()));
                        menu.Items.Add(mi);
                    }

                    if (many.Cast <object>().All(d => d is IDeleteable))
                    {
                        var mi = factory.CreateMenuItem(new ExecuteCommandDelete(_activator, many.Cast <IDeleteable>().ToArray()));
                        mi.ShortcutKeys = Keys.Delete;
                        menu.Items.Add(mi);
                    }
                    MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(menu, o));
                    return(menu);
                }

                if (o != null)
                {
                    //is o masquerading as someone else?
                    IMasqueradeAs masquerader = o as IMasqueradeAs;

                    //if so this is who he is pretending to be
                    object masqueradingAs = null;

                    if (masquerader != null)
                    {
                        masqueradingAs = masquerader.MasqueradingAs(); //yes he is masquerading!
                    }
                    var menu = GetMenuWithCompatibleConstructorIfExists(o);

                    //If no menu takes the object o try checking the object it is masquerading as as a secondary preference
                    if (menu == null && masqueradingAs != null)
                    {
                        menu = GetMenuWithCompatibleConstructorIfExists(masqueradingAs, masquerader);
                    }

                    //found a menu with compatible constructor arguments
                    if (menu != null)
                    {
                        if (!Settings.AllowPinning)
                        {
                            var miPin = menu.Items.OfType <AtomicCommandMenuItem>().SingleOrDefault(mi => mi.Tag is ExecuteCommandPin);

                            if (miPin != null)
                            {
                                miPin.Enabled     = false;
                                miPin.ToolTipText = "Pinning is disabled in this collection";
                            }
                        }

                        MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(menu, o));
                        return(menu);
                    }

                    //no compatible menus so just return default menu
                    var defaultMenu = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(_activator, Tree, o), o);
                    defaultMenu.AddCommonMenuItems(this);

                    MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(defaultMenu, o));
                    return(defaultMenu);
                }
                else
                {
                    //it's a right click in whitespace (nothing right clicked)

                    AtomicCommandUIFactory factory = new AtomicCommandUIFactory(_activator);

                    if (WhitespaceRightClickMenuCommandsGetter != null)
                    {
                        var menu = factory.CreateMenu(_activator, Tree, _collection, WhitespaceRightClickMenuCommandsGetter(_activator));
                        menu.AddCommonMenuItems(this);
                        return(menu);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                if (_activator?.GlobalErrorCheckNotifier == null)
                {
                    throw;
                }

                _activator.GlobalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs($"Failed to build menu for {o} of Type {o?.GetType()}", CheckResult.Fail, ex));
                return(null);
            }
        }
Example #3
0
        public ICommand Create(object modelObject)
        {
            IMasqueradeAs masquerader = modelObject as IMasqueradeAs;

            if (masquerader != null)
            {
                modelObject = masquerader.MasqueradingAs();
            }

            //Extractable column e.g. ExtractionInformation,AggregateDimension etc
            var icolumn = modelObject as IColumn;

            if (icolumn != null)
            {
                return(new ColumnCommand(icolumn));
            }

            var pipeline = modelObject as Pipeline;

            if (pipeline != null)
            {
                return(new PipelineCommand(pipeline));
            }

            //table column pointers (not extractable)
            var columnInfo       = modelObject as ColumnInfo; //ColumnInfo is not an IColumn btw because it does not have column order or other extraction rule stuff (alias, hash etc)
            var linkedColumnInfo = modelObject as LinkedColumnInfoNode;

            if (columnInfo != null || linkedColumnInfo != null)
            {
                return(new ColumnInfoCommand(columnInfo ?? linkedColumnInfo.ColumnInfo));
            }

            var columnInfoArray = IsArrayOf <ColumnInfo>(modelObject);

            if (columnInfoArray != null)
            {
                return(new ColumnInfoCommand(columnInfoArray));
            }

            var tableInfo = modelObject as TableInfo;

            if (tableInfo != null)
            {
                return(new TableInfoCommand(tableInfo));
            }

            //catalogues
            var catalogues = IsArrayOf <Catalogue>(modelObject);

            if (catalogues != null)
            {
                if (catalogues.Length == 1)
                {
                    return(new CatalogueCommand(catalogues[0]));
                }
                else
                {
                    return(new ManyCataloguesCommand(catalogues));
                }
            }

            //filters
            var filter = modelObject as IFilter;

            if (filter != null)
            {
                return(new FilterCommand(filter));
            }

            //containers
            var container = modelObject as IContainer;

            if (container != null)
            {
                return(new ContainerCommand(container));
            }

            //aggregates
            var aggregate = modelObject as AggregateConfiguration;

            if (aggregate != null)
            {
                return(new AggregateConfigurationCommand(aggregate));
            }

            //aggregate containers
            var aggregateContainer = modelObject as CohortAggregateContainer;

            if (aggregateContainer != null)
            {
                return(new CohortAggregateContainerCommand(aggregateContainer));
            }

            var extractableCohort = modelObject as ExtractableCohort;

            if (extractableCohort != null)
            {
                return(new ExtractableCohortCommand(extractableCohort));
            }

            //extractable data sets
            var extractableDataSets = IsArrayOf <ExtractableDataSet>(modelObject);

            if (extractableDataSets != null)
            {
                return(new ExtractableDataSetCommand(extractableDataSets));
            }

            var extractableDataSetPackage = modelObject as ExtractableDataSetPackage;

            if (extractableDataSetPackage != null)
            {
                return(new ExtractableDataSetCommand(extractableDataSetPackage));
            }

            var dataAccessCredentials = modelObject as DataAccessCredentials;

            if (dataAccessCredentials != null)
            {
                return(new DataAccessCredentialsCommand(dataAccessCredentials));
            }

            var processTask = modelObject as ProcessTask;

            if (processTask != null)
            {
                return(new ProcessTaskCommand(processTask));
            }

            var cacheProgress = modelObject as CacheProgress;

            if (cacheProgress != null)
            {
                return(new CacheProgressCommand(cacheProgress));
            }

            var cic            = modelObject as CohortIdentificationConfiguration;
            var cicAssociation = modelObject as ProjectCohortIdentificationConfigurationAssociation;

            if (cic != null || cicAssociation != null)
            {
                return(new CohortIdentificationConfigurationCommand(cic ?? cicAssociation.CohortIdentificationConfiguration));
            }

            var commandSource = modelObject as ICommandSource;

            if (commandSource != null)
            {
                return(commandSource.GetCommand());
            }

            return(null);
        }