Ejemplo n.º 1
0
        private void EditFiniteAnnotationValue(TimeIntervalAnnotationDisplayData displayData, int trackId)
        {
            // Get the schema definition
            AnnotationSchemaDefinition schemaDefinition = displayData.Definition.SchemaDefinitions[trackId];

            // Get the collection of possible values
            Type        schemaType     = schemaDefinition.Schema.GetType();
            MethodInfo  valuesProperty = schemaType.GetProperty("Values").GetGetMethod();
            IEnumerable values         = (IEnumerable)valuesProperty.Invoke(schemaDefinition.Schema, new object[] { });

            // Create a new context menu
            ContextMenu contextMenu = new ContextMenu();

            // Create a menuitem for each value, with a command to update the value on the annotation.
            foreach (object value in values)
            {
                var metadata = this.GetAnnotationValueMetadata(value, schemaDefinition.Schema);
                contextMenu.Items.Add(MenuItemHelper.CreateAnnotationMenuItem(
                                          value.ToString(),
                                          metadata.BorderColor,
                                          metadata.FillColor,
                                          new PsiCommand(() => this.StreamVisualizationObject.SetAnnotationValue(displayData.Annotation, schemaDefinition.Name, value))));
            }

            // Add a handler so that the timeline visualization panel continues to receive mouse move messages
            // while the context menu is displayed, and remove the handler once the context menu closes.
            MouseEventHandler mouseMoveHandler = new MouseEventHandler(this.FindTimelineVisualizationPanelView().ContextMenuMouseMove);

            contextMenu.AddHandler(MouseMoveEvent, mouseMoveHandler, true);
            contextMenu.Closed += (sender, e) => contextMenu.RemoveHandler(MouseMoveEvent, mouseMoveHandler);

            // Show the context menu
            contextMenu.IsOpen = true;
        }
        private void AddAnnotationEditMenuItems(List <MenuItem> menuItems)
        {
            // All of the following must be true to edit an annotation:
            //
            // 1) We must be bound to a source
            // 2) Edit annotations values must be enabled.
            // 3) The cursor must be over an annotation.
            if (this.IsBound && this.EnableAnnotationValueEdit)
            {
                int index = this.GetAnnotationIndexByTime(this.Container.Navigator.Cursor);
                if (index >= 0)
                {
                    // Get the annotation to be edited
                    Message <TimeIntervalAnnotation> annotation = this.Data[index];

                    // Get the collection of schema definitions in the annotation
                    foreach (AnnotationSchemaDefinition schemaDefinition in this.Definition.SchemaDefinitions)
                    {
                        // Create a menuitem for the value
                        var valueMenuItem = MenuItemHelper.CreateMenuItem(IconSourcePath.Annotation, schemaDefinition.Name, null);

                        // If this is a finite schema, then get the list of possible values
                        if (schemaDefinition.Schema.IsFiniteAnnotationSchema)
                        {
                            // Get the collection of possible values
                            Type        schemaType     = schemaDefinition.Schema.GetType();
                            MethodInfo  valuesProperty = schemaType.GetProperty("Values").GetGetMethod();
                            IEnumerable values         = (IEnumerable)valuesProperty.Invoke(schemaDefinition.Schema, new object[] { });

                            // Create a menuitem for each value, with a command to update the value on the annotation.
                            foreach (object value in values)
                            {
                                var metadata = this.GetAnnotationValueMetadata(value, schemaDefinition.Schema);
                                valueMenuItem.Items.Add(MenuItemHelper.CreateAnnotationMenuItem(
                                                            value.ToString(),
                                                            metadata.BorderColor,
                                                            metadata.FillColor,
                                                            new PsiCommand(() => this.SetAnnotationValue(annotation, schemaDefinition.Name, value))));
                            }
                        }
                        else
                        {
                            valueMenuItem.Items.Add(MenuItemHelper.CreateMenuItem(
                                                        null,
                                                        annotation.Data.Values[schemaDefinition.Name].ToString(),
                                                        null));
                        }

                        menuItems.Add(valueMenuItem);
                    }
                }
            }
        }