001    /*
002     *  Licensed under the Apache License, Version 2.0 (the "License");
003     *  you may not use this file except in compliance with the License.
004     *  You may obtain a copy of the License at
005     *
006     *      http://www.apache.org/licenses/LICENSE-2.0
007     *
008     *  Unless required by applicable law or agreed to in writing, software
009     *  distributed under the License is distributed on an "AS IS" BASIS,
010     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011     *  See the License for the specific language governing permissions and
012     *  limitations under the License.
013     */
014    /*
015     * This file has been modified by Chris Pheby in accordance with Section 4.2
016     * of the Apache Software License
017     */
018    package org.jadira.dependencynavigator.controller;
019    
020    public class Controller {
021    
022        // TODO all resolution over multiple repositories (file/http/workspace)
023        // TODO optional caching for remote repositories?
024        // TODO allow user to load a file for a given dependency from the tree
025        // TODO indicate different repositories in tree
026    
027        private BooleanController checkShowCompile = new BooleanController(true);
028        private BooleanController checkShowTest = new BooleanController(false);
029        private BooleanController checkShowRuntime = new BooleanController(true);
030        private BooleanController checkShowProvided = new BooleanController(true);
031        private BooleanController resolveExclusions = new BooleanController(true);
032    
033        boolean includeScope(String scope) {
034            if ("compile".equalsIgnoreCase(scope) && !checkShowCompile.value) {
035                return false;
036            }
037            if ("test".equalsIgnoreCase(scope) && !checkShowTest.value) {
038                return false;
039            }
040            if ("runtime".equalsIgnoreCase(scope) && !checkShowRuntime.value) {
041                return false;
042            }
043            if ("provided".equalsIgnoreCase(scope) && !checkShowProvided.value) {
044                return false;
045            }
046            return true;
047        }
048    
049        /**
050         * a mutable boolean, used as a lightweight non-swing dependant model
051         */
052        public class BooleanController {
053    
054            private boolean value;
055    
056            private BooleanController(boolean value) {
057                this.value = value;
058            }
059    
060            public boolean getValue() {
061                return value;
062            }
063    
064            public void toggle() {
065                value = !value;
066            }
067    
068        }
069    
070        public BooleanController getCheckShowCompile() {
071            return checkShowCompile;
072        }
073    
074        public BooleanController getCheckShowProvided() {
075            return checkShowProvided;
076        }
077    
078        public BooleanController getCheckShowRuntime() {
079            return checkShowRuntime;
080        }
081    
082        public BooleanController getCheckShowTest() {
083            return checkShowTest;
084        }
085    
086        public BooleanController getResolveExclusions() {
087            return resolveExclusions;
088        }
089    }