private void PrepareAutoSynonymy(TaxonDropContext context)
        {
            bool showAutoSynonymy = Preferences.PromptForAvailableWhenSynonymizing.Value;

            if (context.Target == null || context.Source == null)
            {
                showAutoSynonymy = false;
            }
            else
            {
                if (!context.TargetRank.AvailableNameAllowed.HasValue || !context.TargetRank.AvailableNameAllowed.Value)
                {
                    showAutoSynonymy = false;
                }
            }

            if (!showAutoSynonymy)
            {
                chkCreateAvailable.IsChecked  = false;
                chkCreateAvailable.Visibility = Visibility.Hidden;
                return;
            }

            chkCreateAvailable.Visibility = Visibility.Visible;
            chkCreateAvailable.Content    = String.Format("Make '{0}' a {2} Available Name of '{1}'", context.Source.DisplayLabel.Trim(), context.Target.DisplayLabel.Trim(), context.TargetRank.LongName);
        }
Beispiel #2
0
        public void ProcessTaxonDragDrop(TaxonViewModel source, TaxonViewModel target)
        {
            try {
                // There are 4 possible outcomes from a taxon drop
                // 1) The drop is invalid, so do nothing (display an error message)
                // 2) The drop is a valid move, no conversion or merging required (simplest case)
                // 3) The drop is to that of a sibling rank, and so a decision is made to either merge or move as child (if possible)
                // 4) The drop is valid, but requires the source to be converted into a valid child of the target

                if (!IsUnlocked) {
                    return;
                }

                if (!CheckPermission(PERMISSION_MASK.UPDATE, target)) {
                    return;
                }

                TaxonDropContext context = new TaxonDropContext(source, target, Owner);

                //Basic sanity checks first....
                if (target == source.Parent) {
                    throw new IllegalTaxonMoveException(source.Taxon, target.Taxon, _R("TaxonExplorer.DropError.AlreadyAChild", source.Epithet, target.Epithet));
                }

                if (source.IsAncestorOf(target)) {
                    throw new IllegalTaxonMoveException(source.Taxon, target.Taxon, _R("TaxonExplorer.DropError.SourceAncestorOfDest", source.Epithet, target.Epithet));
                }

                if (!target.IsExpanded) {
                    target.IsExpanded = true;
                }

                DragDropAction action = CreateAndValidateDropAction(context);

                if (action != null) {
                    // process the action...
                    List<DatabaseCommand> dbActions = action.ProcessUI();
                    if (dbActions != null && dbActions.Count > 0) {
                        RegisterPendingChanges(dbActions, this);
                    }
                }
            } catch (IllegalTaxonMoveException ex) {
                MessageBox.Show(ex.Message, String.Format("Cannot move '{0}'", source.Epithet), MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            source.IsSelected = true;
        }
Beispiel #3
0
 private DragDropAction PromptSourceTargetSame(TaxonDropContext context)
 {
     DragDropOptions form = new DragDropOptions(Owner);
     return form.ShowChooseMergeOrConvert(context);
 }
Beispiel #4
0
        private DragDropAction PromptConvert(TaxonDropContext context)
        {
            DragDropOptions form = new DragDropOptions(Owner);
            List<TaxonRank> validChildren = Service.GetChildRanks(context.TargetRank);
            TaxonRank choice = form.ShowChooseConversion(context.SourceRank, validChildren);
            if (choice != null) {
                return new ConvertingMoveDropAction(context, choice);
            }

            return null;
        }
Beispiel #5
0
        private DragDropAction PromptChangeAvailableName(TaxonDropContext context)
        {
            if (context.TargetRank != null) {
                if (context.SourceRank.Category == context.TargetRank.Category) {
                    return new ConvertingMoveDropAction(context, context.TargetChildRank);
                } else {
                    if (this.Question(_R("TaxonExplorer.prompt.ConvertAvailableName", context.SourceRank.LongName, context.TargetRank.LongName), _R("TaxonExplorer.prompt.ConvertAvailableName.Caption"))) {
                        return new ConvertingMoveDropAction(context, context.TargetRank);
                    }
                }
            }

            return null;
        }
Beispiel #6
0
        private DragDropAction CreateAndValidateDropAction(TaxonDropContext context)
        {
            if (context.Target.AvailableName.GetValueOrDefault(false) || context.Target.LiteratureName.GetValueOrDefault(false)) {
                // Can'note drop on to an Available or Literature Name
                throw new IllegalTaxonMoveException(context.Source.Taxon, context.Target.Taxon, _R("TaxonExplorer.DropError.AvailableName", context.Source.Epithet, context.Target.Epithet));
            } else if (context.Source.AvailableName.GetValueOrDefault(false) || context.Source.LiteratureName.GetValueOrDefault(false)) {
                // if the source is an Available or Literature Name
                if (context.Source.ElemType != context.Target.ElemType) {
                    // If the target is not of the same type as the source, confirm the conversion of available name type (mouseEventArgs.g. species available name to Genus available name)
                    return PromptChangeAvailableName(context);
                } else {
                    return new MoveDropAction(context);
                }
            } else if (context.TargetRank == null || context.SourceRank == null || context.TargetRank.Order.GetValueOrDefault(-1) < context.SourceRank.Order.GetValueOrDefault(-1)) {
                // If the target element is a higher rank than the source, then the drop is acceptable as long as there are no children of the target,
                // or they were of the same type.
                // Check the drag drop rules as defined in the database...
                DataValidationResult result = Service.ValidateTaxonMove(context.Source.Taxon, context.Target.Taxon);
                if (!result.Success) {
                    // Can'note automatically move - check to see if a conversion is a) possible b) desired
                    if (context.TargetChildRank == null) {
                        return PromptConvert(context);
                    } else {
                        if (this.Question(_R("TaxonExplorer.prompt.ConvertTaxon", context.Source.DisplayLabel, context.TargetChildRank.LongName, context.Target.DisplayLabel), _R("TaxonExplorer.prompt.ConfirmAction.Caption"))) {
                            return new ConvertingMoveDropAction(context, context.TargetChildRank);
                        } else {
                            return null;
                        }
                    }
                } else if (context.Source.ElemType == TaxaService.SPECIES_INQUIRENDA || context.Source.ElemType == TaxaService.INCERTAE_SEDIS || context.SourceRank == null) {
                    // Special 'unplaced' ranks - no real rules for drag and drop (TBA)...
                    return new MoveDropAction(context);
                } else if (context.TargetChildRank == null || context.TargetChildRank.Code == context.Source.ElemType) {
                    // Not sure what this means, the old BioLink did it...
                    return new MoveDropAction(context);
                } else {
                    var sourceRank = context.SourceRank == null ? "Unranked" : context.SourceRank.LongName;
                    throw new IllegalTaxonMoveException(context.Source.Taxon, context.Target.Taxon, _R("TaxonExplorer.DropError.CannotCoexist", context.TargetChildRank.LongName, sourceRank));
                }
            } else if (context.Source.ElemType == context.Target.ElemType) {
                // Determine what the user wishes to do when the drag/drop source and target are the same type.
                return PromptSourceTargetSame(context);
            }

            return null;
        }
        internal DragDropAction ShowChooseMergeOrConvert(TaxonDropContext context)
        {
            optMerge.Content = _owner.GetCaption("DragDropOptions.lblMerge", context.Source.Epithet, context.Target.Epithet);

            List <TaxonRank> conversionOptions = new List <TaxonRank>();

            if (context.TargetChildRank == null)
            {
                conversionOptions.AddRange(context.TaxaPlugin.Service.GetChildRanks(context.TargetRank));
            }
            else
            {
                conversionOptions.Add(context.TargetChildRank);
            }

            // Prepare the form depending on how many conversion options there all
            if (conversionOptions.Count == 0)
            {
                // No conversion options - only show the merge option
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Zero;
                grid.RowDefinitions[2].Height = Zero;
            }
            else if (conversionOptions.Count == 1)
            {
                var targetRank = conversionOptions[0];
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Forty;
                grid.RowDefinitions[2].Height = Zero;
                optConvert.Content            = _owner.GetCaption("DragDropOptions.lblConvertAsChild", targetRank.LongName, context.Target.Epithet);
            }
            else
            {
                cmbRanks.ItemsSource          = conversionOptions;
                cmbRanks.SelectedIndex        = 0;
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Forty;
                grid.RowDefinitions[2].Height = Forty;
                optConvert.Content            = _owner.GetCaption("DragDropOptions.lblConvert", context.SourceRank.LongName);
            }

            DragDropAction result = null;

            PrepareAutoSynonymy(context);

            optMerge.IsChecked = true;
            if (ShowDialog().GetValueOrDefault(false))
            {
                if (optMerge.IsChecked.GetValueOrDefault(false))
                {
                    result = new MergeDropAction(context, chkCreateIDRecord.IsChecked.GetValueOrDefault(false));
                    if (chkCreateAvailable.IsChecked.HasValue && chkCreateAvailable.IsChecked.Value)
                    {
                        var availableName = _owner.TaxonExplorer.AddAvailableName(context.Target, false, false);
                        availableName.Epithet   = context.Source.Epithet;
                        availableName.Author    = context.Source.Author;
                        availableName.YearOfPub = context.Source.YearOfPub;
                        availableName.ChgComb   = context.Source.ChgComb;
                    }
                }
                else
                {
                    TaxonRank convertToRank = null;
                    if (conversionOptions.Count == 1)
                    {
                        convertToRank = conversionOptions[0];
                    }
                    else
                    {
                        convertToRank = cmbRanks.SelectedItem as TaxonRank;
                    }

                    result = new ConvertingMoveDropAction(context, convertToRank);
                }
            }

            return(result);
        }
 public DragDropAction(TaxonDropContext context)
 {
     _context = context;
 }
Beispiel #9
0
 public ConvertingMoveDropAction(TaxonDropContext context, TaxonRank RankToConvertTo)
     : base(context)
 {
     this.ConvertRank = RankToConvertTo;
 }
Beispiel #10
0
 public MergeDropAction(TaxonDropContext context, bool createNewIdRecord)
     : base(context)
 {
     _createNewIdRecord = createNewIdRecord;
 }
Beispiel #11
0
 public MoveDropAction(TaxonDropContext context)
     : base(context)
 {
 }
Beispiel #12
0
 public DragDropAction(TaxonDropContext context)
 {
     _context = context;
 }
 public ConvertingMoveDropAction(TaxonDropContext context, TaxonRank RankToConvertTo)
     : base(context)
 {
     this.ConvertRank = RankToConvertTo;
 }
 public MoveDropAction(TaxonDropContext context)
     : base(context)
 {
 }
Beispiel #15
0
        private void PrepareAutoSynonymy(TaxonDropContext context)
        {
            bool showAutoSynonymy = Preferences.PromptForAvailableWhenSynonymizing.Value;

            if (context.Target == null || context.Source == null) {
                showAutoSynonymy = false;
            } else {
                if (!context.TargetRank.AvailableNameAllowed.HasValue || !context.TargetRank.AvailableNameAllowed.Value) {
                    showAutoSynonymy = false;
                }
            }

            if (!showAutoSynonymy) {
                chkCreateAvailable.IsChecked = false;
                chkCreateAvailable.Visibility = Visibility.Hidden;
                return;
            }

            chkCreateAvailable.Visibility = Visibility.Visible;
            chkCreateAvailable.Content = String.Format("Make '{0}' a {2} Available Name of '{1}'", context.Source.DisplayLabel.Trim(), context.Target.DisplayLabel.Trim(), context.TargetRank.LongName);
        }
Beispiel #16
0
        internal DragDropAction ShowChooseMergeOrConvert(TaxonDropContext context)
        {
            optMerge.Content = _owner.GetCaption("DragDropOptions.lblMerge", context.Source.Epithet, context.Target.Epithet);

            List<TaxonRank> conversionOptions = new List<TaxonRank>();
            if (context.TargetChildRank == null) {
                conversionOptions.AddRange(context.TaxaPlugin.Service.GetChildRanks(context.TargetRank));
            } else {
                conversionOptions.Add(context.TargetChildRank);
            }

            // Prepare the form depending on how many conversion options there all
            if (conversionOptions.Count == 0) {
                // No conversion options - only show the merge option
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Zero;
                grid.RowDefinitions[2].Height = Zero;
            } else if (conversionOptions.Count == 1) {
                var targetRank = conversionOptions[0];
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Forty;
                grid.RowDefinitions[2].Height = Zero;
                optConvert.Content = _owner.GetCaption("DragDropOptions.lblConvertAsChild", targetRank.LongName, context.Target.Epithet);
            } else {
                cmbRanks.ItemsSource = conversionOptions;
                cmbRanks.SelectedIndex = 0;
                grid.RowDefinitions[0].Height = new GridLength(80);
                grid.RowDefinitions[1].Height = Forty;
                grid.RowDefinitions[2].Height = Forty;
                optConvert.Content = _owner.GetCaption("DragDropOptions.lblConvert", context.SourceRank.LongName);
            }

            DragDropAction result = null;

            PrepareAutoSynonymy(context);

            optMerge.IsChecked = true;
            if (ShowDialog().GetValueOrDefault(false)) {
                if (optMerge.IsChecked.GetValueOrDefault(false)) {
                    result = new MergeDropAction(context, chkCreateIDRecord.IsChecked.GetValueOrDefault(false));
                    if (chkCreateAvailable.IsChecked.HasValue && chkCreateAvailable.IsChecked.Value) {
                        var availableName = _owner.TaxonExplorer.AddAvailableName(context.Target, false, false);
                        availableName.Epithet = context.Source.Epithet;
                        availableName.Author = context.Source.Author;
                        availableName.YearOfPub = context.Source.YearOfPub;
                        availableName.ChgComb = context.Source.ChgComb;
                    }
                } else {

                    TaxonRank convertToRank = null;
                    if (conversionOptions.Count == 1) {
                        convertToRank = conversionOptions[0];
                    } else {
                        convertToRank = cmbRanks.SelectedItem as TaxonRank;
                    }

                    result = new ConvertingMoveDropAction(context, convertToRank);
                }
            }

            return result;
        }
 public MergeDropAction(TaxonDropContext context, bool createNewIdRecord)
     : base(context)
 {
     _createNewIdRecord = createNewIdRecord;
 }