KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.lucane.applications.administrator.gui;
20
21 import java.util.*;
22 import java.awt.*;
23 import java.awt.event.*;
24
25 import javax.swing.*;
26
27 import org.lucane.applications.administrator.AdministratorPlugin;
28 import org.lucane.common.concepts.*;
29
30 public class ServicePanel extends JPanel
31 implements MouseListener, ActionListener
32 {
33     private transient AdministratorPlugin plugin;
34     
35     private JTextField serviceName;
36     private JCheckBox serviceInstalled;
37     private JTextArea serviceDescription;
38
39     private JButton btnUpdate;
40     private JButton btnRemove;
41     
42     private ConceptTable serviceGroups;
43
44     private ConceptPanel panel;
45     
46     public ServicePanel(AdministratorPlugin plugin, ConceptPanel panel)
47     {
48         super(new BorderLayout());
49         this.plugin = plugin;
50         this.panel = panel;
51         
52         //-- attributes
53
serviceName = new JTextField();
54         serviceName.setEnabled(false);
55         serviceInstalled = new JCheckBox();
56         serviceDescription = new JTextArea();
57         serviceGroups = new ConceptTable(plugin, tr("groups"));
58         serviceGroups.addMouseListener(this);
59         
60         //-- name and installed
61
JPanel labels = new JPanel(new GridLayout(2,1));
62         labels.add(new JLabel(tr("name")));
63         labels.add(new JLabel(tr("installed")));
64
65         JPanel fields = new JPanel(new GridLayout(2, 1));
66         fields.add(serviceName);
67         fields.add(serviceInstalled);
68         
69         JPanel nameAndInstalled = new JPanel(new BorderLayout());
70         nameAndInstalled.add(labels, BorderLayout.WEST);
71         nameAndInstalled.add(fields, BorderLayout.CENTER);
72         
73         //-- description
74
JPanel description = new JPanel(new BorderLayout());
75         description.add(new JLabel(tr("description")), BorderLayout.NORTH);
76         description.add(new JScrollPane(serviceDescription), BorderLayout.CENTER);
77                 
78         //-- groups
79
JPanel groups = new JPanel(new BorderLayout());
80         groups.add(new JLabel(tr("groups")), BorderLayout.NORTH);
81         groups.add(new JScrollPane(serviceGroups));
82         
83         //-- description and groups
84
JPanel descriptionAndGroups = new JPanel(new GridLayout(2, 1));
85         descriptionAndGroups.add(description);
86         descriptionAndGroups.add(groups);
87
88         //buttons
89
JPanel buttonsContainer = new JPanel(new BorderLayout());
90         JPanel buttons = new JPanel(new GridLayout(1, 2));
91         btnRemove = new JButton(tr("btn.remove"));
92         btnRemove.addActionListener(this);
93         buttons.add(btnRemove);
94         btnUpdate = new JButton(tr("btn.save"));
95         btnUpdate.addActionListener(this);
96         buttons.add(btnUpdate);
97         buttonsContainer.add(buttons, BorderLayout.EAST);
98         
99         //-- complete
100
this.add(nameAndInstalled, BorderLayout.NORTH);
101         this.add(descriptionAndGroups, BorderLayout.CENTER);
102         this.add(buttonsContainer, BorderLayout.SOUTH);
103     }
104     
105     public void showConcept(ServiceConcept concept)
106     {
107         serviceName.setText(concept.getName());
108         serviceInstalled.setSelected(concept.isInstalled());
109         serviceDescription.setText(concept.getDescription());
110         setGroups(concept);
111     }
112     
113     public void setGroups(ServiceConcept service)
114     {
115         ArrayList groups = new ArrayList();
116         Iterator allGroups = plugin.getAllGroups(false).iterator();
117         
118         while(allGroups.hasNext())
119         {
120             GroupConcept group = (GroupConcept)allGroups.next();
121             if(group.hasService(service))
122                 groups.add(group);
123         }
124         
125         serviceGroups.setConcepts(groups);
126     }
127     
128     private String JavaDoc tr(String JavaDoc s)
129     {
130         return plugin.tr(s);
131     }
132     
133     //-- mouse listener
134

135      public void mouseEntered(MouseEvent e) {}
136      public void mouseExited(MouseEvent e) {}
137      public void mousePressed(MouseEvent e) {}
138      public void mouseReleased(MouseEvent e) {}
139      public void mouseClicked(MouseEvent e)
140      {
141         if(e.getClickCount() < 2)
142             return;
143         
144          int row = serviceGroups.getSelectedRow();
145          if(row < 0)
146             return;
147         
148           panel.showConcept(serviceGroups.getConceptAt(row));
149       }
150       
151      //-- action listener
152
public void actionPerformed(ActionEvent ae)
153     {
154         ServiceConcept concept = new ServiceConcept(serviceName.getText(), serviceInstalled.isSelected());
155         if(ae.getSource() == btnUpdate)
156         {
157             plugin.updateConcept(concept);
158             panel.refresh();
159         }
160         else if(ae.getSource() == btnRemove)
161         {
162             plugin.removeConcept(concept);
163             panel.refresh();
164             panel.showConcept(null);
165         }
166     }
167 }
Popular Tags