private static void GetOwnerWindows(DicomExplorerComponent explorerComponent,
                                            out IDesktopWindow parentDesktopWindow, out IDesktopObject parentShelfOrWorkspace)
        {
            parentDesktopWindow    = null;
            parentShelfOrWorkspace = null;

            foreach (IDesktopWindow desktopWindow in Application.DesktopWindows)
            {
                foreach (IWorkspace workspace in desktopWindow.Workspaces)
                {
                    if (workspace.Component == explorerComponent)
                    {
                        parentDesktopWindow    = desktopWindow;
                        parentShelfOrWorkspace = workspace;
                        return;
                    }
                }

                foreach (IShelf shelf in desktopWindow.Shelves)
                {
                    if (shelf.Component == explorerComponent)
                    {
                        parentDesktopWindow    = desktopWindow;
                        parentShelfOrWorkspace = shelf;
                        return;
                    }
                }
            }
        }
        public SearchLocalStudiesResult SearchLocalStudies(SearchLocalStudiesRequest request)
        {
            if (request == null)
            {
                throw new FaultException("The request cannot be null.");
            }

            if (!StudyStore.IsSupported)
            {
                throw new FaultException <NoLocalStoreFault>(new NoLocalStoreFault(), "No local store was found.");
            }

            DicomExplorerComponent explorerComponent = GetDicomExplorer();

            if (request.SearchCriteria == null)
            {
                request.SearchCriteria = new DicomExplorerSearchCriteria();
            }

            //Select the local server node.
            explorerComponent.ServerTreeComponent.SetSelection(explorerComponent.ServerTreeComponent.ServerTree.LocalServer);

            SynchronizationContext.Current.Post(
                ignore => explorerComponent.StudyBrowserComponent.Search(request.SearchCriteria.ToIdentifier(true)), null);

            return(new SearchLocalStudiesResult());
        }
        private static DicomExplorerComponent GetDicomExplorer()
        {
            List <DicomExplorerComponent> explorerComponents = DicomExplorerComponent.GetActiveComponents();

            if (explorerComponents.Count == 0)
            {
                throw new FaultException <DicomExplorerNotFoundFault>(new DicomExplorerNotFoundFault(), "No dicom explorers were found.");
            }

            IDesktopWindow parentDesktopWindow;
            IDesktopObject parentShelfOrWorkspace;

            GetOwnerWindows(explorerComponents[0], out parentDesktopWindow, out parentShelfOrWorkspace);
            if (parentDesktopWindow != null)             //activate the owner, if it was found.
            {
                parentDesktopWindow.Activate();
            }
            if (parentShelfOrWorkspace != null)
            {
                parentShelfOrWorkspace.Activate();
            }

            //there's only ever one of these right now anyway.
            return(explorerComponents[0]);
        }
        public static DicomExplorerComponent Create()
        {
            var serverTreeComponent = new ServerTreeComponent {
                ShowLocalServerNode = StudyStore.IsSupported
            };

            bool hasEditPermission = PermissionsHelper.IsInRole(AuthorityTokens.Configuration.MyServers);

            serverTreeComponent.IsReadOnly = !hasEditPermission;

            var studyBrowserComponent
                = CreateComponentFromExtensionPoint <StudyBrowserComponentExtensionPoint, IStudyBrowserComponent>()
                  ?? new StudyBrowserComponent();

            serverTreeComponent.SelectedServerChanged +=
                delegate { studyBrowserComponent.SelectedServers = serverTreeComponent.SelectedServers; };

            var searchPanelComponent
                = CreateComponentFromExtensionPoint <SearchPanelComponentExtensionPoint, ISearchPanelComponent>()
                  ?? new SearchPanelComponent();

            SelectPriorsServerNode(serverTreeComponent);

            var leftPane  = new SplitPane(SR.TitleServerTreePane, serverTreeComponent, 0.25f);
            var rightPane = new SplitPane(SR.TitleStudyBrowserPane, studyBrowserComponent, 0.75f);

            var bottomContainer =
                new SplitComponentContainer(
                    leftPane,
                    rightPane,
                    SplitOrientation.Vertical);

            var topPane    = new SplitPane(SR.TitleSearchPanelPane, searchPanelComponent, true);
            var bottomPane = new SplitPane(SR.TitleStudyNavigatorPane, bottomContainer, false);

            var component = new DicomExplorerComponent(topPane, bottomPane)
            {
                _studyBrowserComponent = studyBrowserComponent,
                _searchPanelComponent  = searchPanelComponent,
                _serverTreeComponent   = serverTreeComponent
            };

            return(component);
        }
        public SearchRemoteStudiesResult SearchRemoteStudies(SearchRemoteStudiesRequest request)
        {
            if (request == null)
            {
                throw new FaultException("The request cannot be null.");
            }

            DicomExplorerComponent explorerComponent = GetDicomExplorer();

            if (request.SearchCriteria == null)
            {
                request.SearchCriteria = new DicomExplorerSearchCriteria();
            }

            string aeTitle = (request.AETitle ?? "").Trim();

            if (String.IsNullOrEmpty(aeTitle))
            {
                explorerComponent.SelectPriorsServers();
            }
            else
            {
                var server = explorerComponent.ServerTreeComponent.ServerTree.RootServerGroup
                             .GetAllServers().OfType <IServerTreeDicomServer>().FirstOrDefault(s => s.AETitle == aeTitle);
                if (server == null)
                {
                    throw new FaultException <ServerNotFoundFault>(new ServerNotFoundFault(), String.Format("Server '{0}' not found.", aeTitle));
                }

                explorerComponent.ServerTreeComponent.SetSelection(server);
            }

            SynchronizationContext.Current.Post(
                ignore => explorerComponent.StudyBrowserComponent.Search(request.SearchCriteria.ToIdentifier(true)), null);

            return(new SearchRemoteStudiesResult());
        }