001package org.nasdanika.models.gitlab.util;
002
003import java.util.Date;
004import java.util.concurrent.Executor;
005
006import org.nasdanika.common.ProgressMonitor;
007import org.nasdanika.models.gitlab.GitLab;
008
009/**
010 * Performs multi-object, multi-stage loading leveraging {@link Loader}. 
011 */
012public class LoadingEngine {
013        
014        private Loader loader;
015
016        public LoadingEngine(Loader loader) {
017                this.loader = loader;
018        }
019        
020        public LoadingEngine(Loader loader, Executor executor) {
021                this.loader = loader;
022                this.executor = executor;
023        }       
024                
025        // Caller thread executor
026        private Executor executor = r -> r.run();
027        
028        public Executor getExecutor() {
029                return executor;
030        }
031        
032        /**
033         * @param executor To execute loading in parallel
034         */
035        public void setExecutor(Executor executor) {
036                this.executor = executor;
037        }
038        
039        /**
040         * @param modelGroup
041         * @return true if sub-groups of this group shall be (re) loaded
042         */
043        protected boolean isLoadSubGroups(org.nasdanika.models.gitlab.Group modelGroup) {
044                return true;
045        }
046        
047        /**
048         * @param modelGroup
049         * @return true if projects of this group shall be (re) loaded
050         */
051        protected boolean isLoadProjects(org.nasdanika.models.gitlab.Group modelGroup) {
052                return true;
053        }
054        
055        /**
056         * @param modelProject
057         * @return true if branches of this project shall be (re) loaded
058         */
059        protected boolean isLoadBranches(org.nasdanika.models.gitlab.Project modelProject) {
060                return true;
061        }
062        
063        /**
064         * @param modelTreeItem
065         * @return true if content of this tree item shall be (re) loaded
066         */
067        protected boolean isLoadTreeItem(org.nasdanika.models.gitlab.TreeItem modelTreeItem) {
068                return true;
069        }
070                
071//      /**
072//       * Loads groups, their projects, sub-groups, members and other related objects into a new {@link GitLab} instance.
073//       * @param progressMonitor
074//       * @return Populated {@link GitLab} instance.
075//       */
076//      public GitLab loadGitLabGroups(ProgressMonitor progressMonitor) {
077//              GitLab ret = getFactory().createGitLab();       
078//              ret.setLoaded(new Date());
079//              loadGroups(ret, progressMonitor);                               
080//              return ret;
081//      }
082        
083
084}