/*
 * Copyright (c) 2006-2011 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.ui_swing.dialogs.channellist;

import com.dmdirc.lists.GroupListManager;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

/**
 * Gathers input for a group list search and begins the search.
 */
public class SearchTermsPanel extends JPanel implements ActionListener {

    /** Serial version UID. */
    private static final long serialVersionUID = 1L;
    /** Group list manager to perform searches on. */
    private GroupListManager manager;
    /** Search terms input field. */
    private JTextField searchTerms;

    /**
     * Creates a new panel to gather input for a group list search.
     *
     * @param manager Group list manager to perform search with
     */
    public SearchTermsPanel(final GroupListManager manager) {
        this.manager = manager;
        searchTerms = new JTextField();
        layoutComponents();
    }

    /** Lays out the components in the panel. */
    private void layoutComponents() {
        final JButton search = new JButton("Search");
        search.addActionListener(this);
        setLayout(new MigLayout("fill, hidemode 3, ins 0"));
        add(new JLabel("Search terms: "), "align label");
        add(searchTerms, "growx, pushx");
        add(search, "");
    }

    /**
     * {@inheritDoc}
     *
     * @param e Action event
     */
    @Override
    public void actionPerformed(final ActionEvent e) {
        manager.startSearch(searchTerms.getText());
    }
}

@@ -1219,16 +1219,59 @@
 Manager;
+%0Aimport com.dmdirc.lists.GroupListObserver;
 %0A%0Aimport
@@ -1495,19 +1495,16 @@
 ut;%0A%0A/**
-%0A *
  Gathers
@@ -1556,17 +1556,16 @@
  search.
-%0A
  */%0Apubl
@@ -1630,16 +1630,35 @@
 Listener
+, GroupListObserver
  %7B%0A%0A    
@@ -1901,16 +1901,70 @@
 chTerms;
+%0A    /** Search button. */%0A    private JButton search;
 %0A%0A    /*
@@ -2270,24 +2270,68 @@
 mponents();%0A
+        manager.addGroupListObserver(this);%0A
     %7D%0A%0A    /
@@ -2424,22 +2424,8 @@
     
-final JButton 
 sear
@@ -2823,24 +2823,24 @@
 nEvent e) %7B%0A
-
         mana
@@ -2875,20 +2875,319 @@
 getText());%0A
+        search.setEnabled(false);%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    @Override%0A    public void onGroupListStarted() %7B%0A        //Ignore%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    @Override%0A    public void onGroupListFinished() %7B%0A        if (search != null) %7B%0A            search.setEnabled(true);%0A        %7D%0A
     %7D%0A%7D%0A

Disable search button until the list has finished.