001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2012 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.plugins.design.ui.libraries.client;
021    
022    import com.google.gwt.i18n.client.Dictionary;
023    import com.google.gwt.user.client.ui.Anchor;
024    import com.google.gwt.user.client.ui.CheckBox;
025    import com.google.gwt.user.client.ui.Grid;
026    import com.google.gwt.user.client.ui.Label;
027    import org.sonar.gwt.Configuration;
028    import org.sonar.gwt.Links;
029    import org.sonar.wsclient.services.Resource;
030    
031    public class Filters extends Grid {
032    
033      private static final String PARAM_TEST = "test";
034    
035      private KeywordFilter keywordFilter;
036      private CheckBox testCheckbox;
037      private Anchor expandCollapse;
038      private boolean isExpanded;
039      private Anchor usageLink;
040    
041    
042      public Filters(Resource resource) {
043        super(1, 5);
044    
045        setStyleName("libFilter");
046        Dictionary l10n = Dictionary.getDictionary("l10n");
047    
048        keywordFilter = new KeywordFilter();
049        setWidget(0, 0, new Label(l10n.get("libs.filter")));
050        setWidget(0, 1, keywordFilter);
051    
052        testCheckbox = new CheckBox(l10n.get("libs.displayTests"));
053        testCheckbox.getElement().setId("testCb");
054        testCheckbox.setValue(Boolean.valueOf(Configuration.getRequestParameter(PARAM_TEST, "false")));
055        setWidget(0, 2, testCheckbox);
056    
057        expandCollapse = new Anchor(l10n.get("libs.collapse"));
058        isExpanded = true;
059        setWidget(0, 3, expandCollapse);
060    
061        usageLink = new Anchor(l10n.get("libs.usageLink"), Links.baseUrl() + "/dependencies/index?search=" + resource.getKey());
062        setWidget(0, 4, usageLink);
063      }
064    
065      public KeywordFilter getKeywordFilter() {
066        return keywordFilter;
067      }
068    
069      public CheckBox getTestCheckbox() {
070        return testCheckbox;
071      }
072    
073      public boolean isTestDisplayed() {
074        return testCheckbox.getValue();
075      }
076    
077      public boolean isTestFiltered() {
078        return !isTestDisplayed();
079      }
080    
081      public boolean hasKeyword() {
082        return getKeywordFilter().hasKeyword();
083      }
084    
085      public Anchor getExpandCollapseLink() {
086        return expandCollapse;
087      }
088    
089      public boolean isExpanded() {
090        return isExpanded;
091      }
092    
093      public boolean isCollapsed() {
094        return !isExpanded;
095      }
096    
097      public Anchor getUsageLink() {
098        return usageLink;
099      }
100    
101      public void expand() {
102        if (!isExpanded) {
103          expandCollapse.setText(Dictionary.getDictionary("l10n").get("libs.collapse"));
104          isExpanded = true;
105        }
106      }
107    
108      public void collapse() {
109        if (isExpanded) {
110          expandCollapse.setText(Dictionary.getDictionary("l10n").get("libs.expand"));
111          isExpanded = false;
112        }
113      }
114    
115      public String toUrlParams() {
116        return PARAM_TEST + '=' + testCheckbox.getValue() + '&' + KeywordFilter.PARAM_FILTER + '=' + getKeywordFilter();
117      }
118    }