Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rd510069b9f0375adf108e8c9ffdb7668e7bb11f4 -r1eed3e3f652618c52a462edc502cfd4250772314 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision d510069b9f0375adf108e8c9ffdb7668e7bb11f4) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) @@ -55,6 +55,7 @@ using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HydraRing.Data; using Ringtoets.HydraRing.IO; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.Forms; @@ -74,6 +75,7 @@ using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using UtilsResources = Core.Common.Utils.Properties.Resources; using BaseResources = Core.Common.Base.Properties.Resources; +using GuiResources = Core.Common.Gui.Properties.Resources; namespace Ringtoets.Integration.Plugin { @@ -222,6 +224,50 @@ } } + public IAssessmentSection GetAssessmentSectionFromFile() + { + if (Gui == null) + { + return null; + } + + IAssessmentSection assessmentSection = null; + try + { + var assessmentSectionHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow); + var path = RingtoetsSettingsHelper.GetCommonDocumentsRingtoetsShapeFileDirectory(); + assessmentSection = assessmentSectionHandler.CreateAssessmentSectionFromFile(path); + } + catch (CriticalFileValidationException exception) + { + MessageBox.Show(exception.Message, BaseResources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + log.Warn(exception.Message, exception.InnerException); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message, exception.InnerException); + } + + return assessmentSection; + } + + public void SetAssessmentSectionToProject(RingtoetsProject ringtoetsProject, AssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + return; + } + assessmentSection.Name = GetUniqueForAssessmentSectionName(ringtoetsProject.Items, assessmentSection.Name); + ringtoetsProject.Items.Add(assessmentSection); + ringtoetsProject.NotifyObservers(); + + if (Gui != null && (Gui.Selection == null || Gui.Selection.Equals(assessmentSection))) + { + Gui.Selection = assessmentSection; + Gui.DocumentViewController.OpenViewForData(Gui.Selection); + } + } + /// /// Returns all instances provided for data of . /// @@ -322,31 +368,10 @@ public override IEnumerable GetDataItemInfos() { - if (Gui == null) - { - return Enumerable.Empty(); - } + IAssessmentSection assessmentSection = GetAssessmentSectionFromFile(); - IAssessmentSection assessmentSection = null; - try - { - var assessmentSectionHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow); - var path = RingtoetsSettingsHelper.GetCommonDocumentsRingtoetsShapeFileDirectory(); - assessmentSection = assessmentSectionHandler.CreateAssessmentSectionFromFile(path); - } - catch (CriticalFileValidationException exception) - { - MessageBox.Show(exception.Message, BaseResources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - log.Warn(exception.Message, exception.InnerException); - } - catch (CriticalFileReadException exception) - { - log.Error(exception.Message, exception.InnerException); - } - if (assessmentSection == null) { - return Enumerable.Empty(); } return new DataItemInfo[] @@ -358,8 +383,8 @@ Image = RingtoetsFormsResources.AssessmentSectionFolderIcon, CreateData = owner => { - var project = (Project) owner; - assessmentSection.Name = GetUniqueForAssessmentSectionName(project, assessmentSection.Name); + var project = (RingtoetsProject) owner; + assessmentSection.Name = GetUniqueForAssessmentSectionName(project.Items, assessmentSection.Name); return assessmentSection; } } @@ -373,6 +398,15 @@ /// Sequence of child data. public override IEnumerable GetChildDataWithViewDefinitions(object dataObject) { + var project = dataObject as RingtoetsProject; + if (project != null) + { + foreach (var item in project.Items) + { + yield return item; + } + } + var assessmentSection = dataObject as IAssessmentSection; if (assessmentSection != null) { @@ -490,10 +524,42 @@ .AddPropertiesItem() .Build() }; + + yield return new TreeNodeInfo + { + Text = project => project.Name, + Image = project => GuiResources.ProjectIcon, + ChildNodeObjects = nodeData => nodeData.Items.Cast().ToArray(), + ContextMenuStrip = (nodeData, parentData, treeViewControl) => + { + var addItem = new StrictContextMenuItem( + RingtoetsCommonFormsResources.RingtoetsProject_DisplayName, + RingtoetsCommonFormsResources.RingtoetsProject_ToolTip, + GuiResources.PlusIcon, + (s, e) => SetAssessmentSectionFromFileToProject(nodeData)); + + return Gui.Get(nodeData, treeViewControl) + .AddCustomItem(addItem) + .AddSeparator() + .AddImportItem() + .AddExportItem() + .AddSeparator() + .AddExpandAllItem() + .AddCollapseAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + }; } - private static ViewInfo, IEnumerable, TView> - CreateFailureMechanismResultViewInfo() + private void SetAssessmentSectionFromFileToProject(RingtoetsProject ringtoetsProject) + { + var assessmentSection = GetAssessmentSectionFromFile(); + SetAssessmentSectionToProject(ringtoetsProject, (AssessmentSection) assessmentSection); + } + + private static ViewInfo, IEnumerable, TView> CreateFailureMechanismResultViewInfo() where TResult : FailureMechanismSectionResult where TView : FailureMechanismResultView { @@ -510,7 +576,8 @@ }; } - private TreeNodeInfo> CreateFailureMechanismSectionResultTreeNodeInfo() where T : FailureMechanismSectionResult + private TreeNodeInfo> CreateFailureMechanismSectionResultTreeNodeInfo() + where T : FailureMechanismSectionResult { return new TreeNodeInfo> { @@ -538,11 +605,16 @@ } } - private static void VerifyHydraulicBoundaryDatabasePath(Project project) + private static void VerifyHydraulicBoundaryDatabasePath(IProject project) { - var sectionsWithDatabase = project.Items.OfType().Where(i => i.HydraulicBoundaryDatabase != null); - foreach (IAssessmentSection section in sectionsWithDatabase) + var ringtoetsProject = project as RingtoetsProject; + if (ringtoetsProject == null) { + return; + } + var sectionsWithDatabase = ringtoetsProject.Items.Where(i => i.HydraulicBoundaryDatabase != null); + foreach (AssessmentSection section in sectionsWithDatabase) + { string selectedFile = section.HydraulicBoundaryDatabase.FilePath; var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(selectedFile); if (validationProblem != null) @@ -695,9 +767,9 @@ #region AssessmentSection - private static string GetUniqueForAssessmentSectionName(Project project, string baseName) + private static string GetUniqueForAssessmentSectionName(IEnumerable assessmentSections, string baseName) { - return NamingHelper.GetUniqueName(project.Items.OfType(), baseName, a => a.Name); + return NamingHelper.GetUniqueName(assessmentSections, baseName, a => a.Name); } private object[] AssessmentSectionChildNodeObjects(IAssessmentSection nodeData) @@ -734,9 +806,9 @@ private void AssessmentSectionOnNodeRemoved(IAssessmentSection nodeData, object parentNodeData) { - var parentProject = (Project) parentNodeData; - - parentProject.Items.Remove(nodeData); + var parentProject = (RingtoetsProject) parentNodeData; + var assessmentSection = (AssessmentSection) nodeData; + parentProject.Items.Remove(assessmentSection); parentProject.NotifyObservers(); }