KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > administrator > gui > ConceptListPanel


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.administrator.gui;
21  
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.util.ArrayList JavaDoc;
25
26 import javax.swing.*;
27 import javax.swing.event.*;
28
29 import org.lucane.client.Client;
30 import org.lucane.client.widgets.DialogBox;
31 import org.lucane.common.concepts.*;
32 import org.lucane.applications.administrator.AdministratorPlugin;
33  
34 class ConceptListPanel extends JPanel
35 implements ActionListener
36 {
37     private transient AdministratorPlugin plugin;
38     private ConceptPanel panel;
39     
40     private JButton refresh;
41     private JButton create;
42     private JComboBox conceptsTypes;
43     private ConceptTable concepts;
44     
45     private String JavaDoc[] types;
46     
47     public ConceptListPanel(AdministratorPlugin plugin, ConceptPanel panel)
48     {
49         super(new BorderLayout());
50         this.plugin = plugin;
51         this.panel = panel;
52         
53         types = new String JavaDoc []{tr("users"), tr("groups"), tr("plugins"), tr("services")};
54         
55         //-- top widgets
56
JPanel top = new JPanel(new BorderLayout());
57         JPanel temp = new JPanel(new BorderLayout());
58         
59         try {
60             refresh = new JButton(Client.getImageIcon("refresh.png"));
61         } catch(Exception JavaDoc e) {
62             refresh = new JButton("R");
63         }
64         refresh.setToolTipText(tr("btn.refresh"));
65         refresh.addActionListener(this);
66         create = new JButton(tr("btn.new"));
67         create.addActionListener(this);
68         conceptsTypes = new JComboBox(types);
69         conceptsTypes.addActionListener(this);
70         temp.add(conceptsTypes, BorderLayout.CENTER);
71         temp.add(refresh, BorderLayout.EAST);
72         top.add(temp, BorderLayout.CENTER);
73         top.add(create, BorderLayout.EAST);
74             
75         //-- main list
76
concepts = new ConceptTable(plugin, tr("concepts"));
77         this.add(top, BorderLayout.NORTH);
78         this.add(new JScrollPane(concepts), BorderLayout.CENTER);
79         
80         //-- fetch data
81
this.refresh();
82     }
83     
84     public void refresh()
85     {
86         ArrayList JavaDoc data;
87         
88         switch(conceptsTypes.getSelectedIndex())
89         {
90             case 0:
91                 data = plugin.getAllUsers(true);
92                 break;
93             case 1:
94                 data = plugin.getAllGroups(true);
95                 break;
96             case 2:
97                 data = plugin.getAllPlugins(true);
98                 break;
99             case 3:
100                 data = plugin.getAllServices(true);
101                 break;
102             default:
103                 data = plugin.getAllGroups(true);
104         }
105         
106         concepts.setConcepts(data);
107     }
108
109     public void actionPerformed(ActionEvent e)
110     {
111         if(e.getSource().equals(create))
112         {
113             String JavaDoc name = null;
114             Concept concept = null;
115             switch(conceptsTypes.getSelectedIndex())
116             {
117                 case 0: //users
118
name = DialogBox.input(plugin.getTitle(), tr("msg.new.user"));
119                     if(name != null)
120                     {
121                         concept = new UserConcept(name, "password", name, "",
122                             Client.getInstance().getConfig().getLanguage(), false,
123                             "org.lucane.applications.quicklaunch");
124                     }
125                     break;
126                 case 1: //groups
127
name = DialogBox.input(plugin.getTitle(), tr("msg.new.group"));
128                     if(name != null)
129                         concept = new GroupConcept(name);
130                     break;
131                 case 2: //plugins
132
name = DialogBox.input(plugin.getTitle(), tr("msg.new.plugin"));
133                     if(name != null)
134                         concept = new PluginConcept(name, "version");
135                     break;
136                 case 3: //services
137
name = DialogBox.input(plugin.getTitle(), tr("msg.new.service"));
138                     if(name != null)
139                         concept = new ServiceConcept(name, false);
140                     break;
141             }
142             if(concept != null)
143             {
144                 plugin.storeConcept(concept);
145                 panel.showConcept(concept);
146             }
147         }
148         
149         refresh();
150     }
151
152     public void addListSelectionListener(ListSelectionListener lsl)
153     {
154         concepts.getSelectionModel().addListSelectionListener(lsl);
155     }
156
157     public int getSelectedRow()
158     {
159         return concepts.getSelectedRow();
160     }
161
162     public Concept getConceptAt(int row)
163     {
164         return concepts.getConceptAt(row);
165     }
166     
167     private String JavaDoc tr(String JavaDoc s)
168     {
169         return plugin.tr(s);
170     }
171 }
Popular Tags