private void AddSopClassesToDataGridFromDirectories() { DvtkApplicationLayer.Session theSession = GetSessionTreeViewManager().GetSession(); Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.Implementation.DefinitionManagement.DefinitionFileDirectoryList; foreach (string theDefinitionFileDirectory in theDefinitionFileDirectoryList) { DirectoryInfo theDirectoryInfo = new DirectoryInfo(theDefinitionFileDirectory); if (theDirectoryInfo.Exists) { FileInfo[] theFilesInfo; theFilesInfo = theDirectoryInfo.GetFiles("*.def"); foreach (FileInfo theDefinitionFileInfo in theFilesInfo) { try { AddSopClassToDataGridFromDefinitionFile(theDefinitionFileInfo.FullName); } catch (Exception exception) { string theErrorText; theErrorText = string.Format("Definition file {0} could not be interpreted while reading directory:\n{1}\n\n", theDefinitionFileInfo.FullName, exception.Message); _RichTextBoxInfo.AppendText(theErrorText); } } } } }
/// <summary> /// Update the Specify SOP classes tab. /// </summary> public void Update() { if (_SessionUsedForContentsOfTabSpecifySopClasses == GetSessionTreeViewManager().GetSelectedSession()) { // No need to update, this tab already contains the correct session information. _DataGridSopClasses.SetDataBinding(_DefinitionFilesInfoForDataGrid, ""); } else { Cursor.Current = Cursors.WaitCursor; Dvtk.Sessions.Session theSession = GetSessionTreeViewManager().GetSelectedSession(); Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.DefinitionManagement.DefinitionFileDirectoryList; // Update the definition file directories list box. _ListBoxDefinitionFileDirectories.Items.Clear(); UpdateRemoveButton(); foreach (string theDefinitionFileDirectory in theDefinitionFileDirectoryList) { _ListBoxDefinitionFileDirectories.Items.Add(theDefinitionFileDirectory); } // Update the SOP classes data grid. // For every definition file directory, use the .def files present in the directory. _RichTextBoxInfo.Clear(); _ComboBoxAeTitle.Items.Clear(); _ComboBoxAeTitle.Items.Add(_DefaultAeTitleVersion); _DefinitionFilesInfoForDataGrid.Clear(); // Add the correct information to the datagrid by inspecting the definition directory. // When doing this, also fill the combobox with available ae title - version combinations. AddSopClassesToDataGridFromDirectories(); // Add the correct information to the datagrid by inspecting the loaded definitions. // When doing this, also fill the combobox with available ae title - version combinations. // Only add an entry if it does not already exist. AddSopClassesToDataGridFromLoadedDefinitions(); // Make the correct AE title - version in the combo box the current one. SetSelectedAeTitleVersion(); // Workaround for following problem: // If the SOP classes tab has already been filled, and another session contains less // records for the datagrid, windows gets confused and thinks there are more records // then actually present in _DefinitionFilesInfoForDataGrid resulting in an assertion. _DataGridSopClasses.SetDataBinding(null, ""); // Actually refresh the data grid. _DataGridSopClasses.SetDataBinding(_DefinitionFilesInfoForDataGrid, ""); //_DataGridSopClasses.DataSource = _DefinitionFilesInfoForDataGrid; _DataGridSopClasses.Refresh(); _SessionUsedForContentsOfTabSpecifySopClasses = GetSessionTreeViewManager().GetSelectedSession(); Cursor.Current = Cursors.Default; } }
/// <summary> /// Add a definition file direcotory. /// </summary> public void AddDefinitionFileDirectory() { DvtkApplicationLayer.Session theSession = GetSessionTreeViewManager().GetSession(); Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.Implementation.DefinitionManagement.DefinitionFileDirectoryList; FolderBrowserDialog theFolderBrowserDialog = new FolderBrowserDialog(); theFolderBrowserDialog.Description = "Select the directory where definition files are located."; if (theFolderBrowserDialog.ShowDialog() == DialogResult.OK) { bool isExistingDirectory = false; string theNewDirectory = GetDirectoryWithTrailingSlashesRemoved(theFolderBrowserDialog.SelectedPath); // Find out if this new directory already exists. foreach (string theExistingDirectory in theDefinitionFileDirectoryList) { if (theNewDirectory == GetDirectoryWithTrailingSlashesRemoved(theExistingDirectory)) { isExistingDirectory = true; break; } } theNewDirectory = theNewDirectory + "\\"; // Only add this new directory if it does not already exist. if (!isExistingDirectory) { DirectoryInfo theDirectoryInfo = new DirectoryInfo(theNewDirectory); // If the new directory is not valid, show an error message. if (!theDirectoryInfo.Exists) { MessageBox.Show("The directory \"" + theNewDirectory + "\" is not a valid directory.", "Directory not added", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { theDefinitionFileDirectoryList.Add(theNewDirectory); // Notify the rest of the world. // This will implicitly also update this specify SOP classes tab. SessionChange theSessionChange = new SessionChange(theSession, SessionChange.SessionChangeSubTypEnum.SOP_CLASSES_OTHER); Notify(theSessionChange); } } else { MessageBox.Show("The directory \"" + theNewDirectory + "\" is already present in\nthe list of definition file directories.", "Directory not added", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void RemoveDefinitionFileDirectory() { string theSelectedDirectory; Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.DefinitionManagement.DefinitionFileDirectoryList; theSelectedDirectory = (string)ListBoxSpecifySopClassesDefinitionFileDirectories.SelectedItem; theDefinitionFileDirectoryList.Remove(theSelectedDirectory); UpdateDataGrid((Dvtk.Sessions.ScriptSession)theSession); }
/// <summary> /// Add a definition file direcotory. /// </summary> private void AddDefinitionFileDirectory() { Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.DefinitionManagement.DefinitionFileDirectoryList; FolderBrowserDialog theFolderBrowserDialog = new FolderBrowserDialog(); theFolderBrowserDialog.Description = "Select the directory where definition files are located."; if (theFolderBrowserDialog.ShowDialog() == DialogResult.OK) { bool isExistingDirectory = false; string theNewDirectory = GetDirectoryWithTrailingSlashesRemoved(theFolderBrowserDialog.SelectedPath); // Find out if this new directory already exists. foreach (string theExistingDirectory in theDefinitionFileDirectoryList) { if (theNewDirectory == GetDirectoryWithTrailingSlashesRemoved(theExistingDirectory)) { isExistingDirectory = true; break; } } theNewDirectory = theNewDirectory + "\\"; // Only add this new directory if it does not already exist. if (!isExistingDirectory) { DirectoryInfo theDirectoryInfo = new DirectoryInfo(theNewDirectory); // If the new directory is not valid, show an error message. if (!theDirectoryInfo.Exists) { MessageBox.Show("The directory \"" + theNewDirectory + "\" is not a valid directory.", "Directory not added", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { theDefinitionFileDirectoryList.Add(theNewDirectory); UpdateDataGrid((Dvtk.Sessions.ScriptSession)theSession); } } else { MessageBox.Show("The directory \"" + theNewDirectory + "\" is already present in\nthe list of definition file directories.", "Directory not added", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void RemoveDefinitionFileDirectory() { string theSelectedDirectory; DvtkApplicationLayer.Session theSession = GetSessionTreeViewManager().GetSession(); Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.Implementation.DefinitionManagement.DefinitionFileDirectoryList; theSelectedDirectory = (string)_ListBoxDefinitionFileDirectories.SelectedItem; theDefinitionFileDirectoryList.Remove(theSelectedDirectory); theSession.HasSessionChanged = true; // Notify the rest of the world. // This will implicitly also update this specify SOP classes tab. // TO DO Update(); SessionChange theSessionChange = new SessionChange(theSession, SessionChange.SessionChangeSubTypEnum.SOP_CLASSES_OTHER); Notify(theSessionChange); }
/// <summary> /// Update the Specify SOP classes tab. /// </summary> public void UpdateDataGrid(Dvtk.Sessions.ScriptSession session) { theSession = session; Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.DefinitionManagement.DefinitionFileDirectoryList; // Update the definition file directories list box. ListBoxSpecifySopClassesDefinitionFileDirectories.Items.Clear(); UpdateRemoveButton(); foreach (string theDefinitionFileDirectory in theDefinitionFileDirectoryList) { ListBoxSpecifySopClassesDefinitionFileDirectories.Items.Add(theDefinitionFileDirectory); } // Update the SOP classes data grid. // For every definition file directory, use the .def files present in the directory. RichTextBoxSpecifySopClassesInfo.Clear(); _DefinitionFilesInfoForDataGrid.Clear(); // Add the correct information to the datagrid by inspecting the definition directory. // When doing this, also fill the combobox with available ae title - version combinations. AddSopClassesToDataGridFromDirectories(); // Add the correct information to the datagrid by inspecting the loaded definitions. // When doing this, also fill the combobox with available ae title - version combinations. // Only add an entry if it does not already exist. AddSopClassesToDataGridFromLoadedDefinitions(); // Workaround for following problem: // If the SOP classes tab has already been filled, and another session contains less // records for the datagrid, windows gets confused and thinks there are more records // then actually present in _DefinitionFilesInfoForDataGrid resulting in an assertion. DataGridSpecifySopClasses.SetDataBinding(null, ""); // Actually refresh the data grid. DataGridSpecifySopClasses.SetDataBinding(_DefinitionFilesInfoForDataGrid, ""); //DataGridSpecifySopClasses.DataSource = _DefinitionFilesInfoForDataGrid; DataGridSpecifySopClasses.Refresh(); }