KickJava   Java API By Example, From Geeks To Geeks.

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


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

134     public void mouseEntered(MouseEvent e) {}
135     public void mouseExited(MouseEvent e) {}
136     public void mousePressed(MouseEvent e) {}
137     public void mouseReleased(MouseEvent e) {}
138     public void mouseClicked(MouseEvent e)
139     {
140         if(e.getClickCount() < 2)
141             return;
142         
143         int row = pluginGroups.getSelectedRow();
144         if(row < 0)
145             return;
146         
147         panel.showConcept(pluginGroups.getConceptAt(row));
148     }
149     
150     //-- action listener
151
public void actionPerformed(ActionEvent ae)
152    {
153        PluginConcept concept = new PluginConcept(pluginName.getText(), pluginVersion.getText());
154        concept.setDescription(pluginDescription.getText());
155        
156         if(ae.getSource() == btnUpdate)
157         {
158             if(concept.getVersion().length() == 0)
159             {
160                 DialogBox.error(tr("err.pluginVersionIsMandatory"));
161                 return;
162             }
163             plugin.updateConcept(concept);
164             panel.refresh();
165         }
166         else if(ae.getSource() == btnRemove)
167         {
168             plugin.removeConcept(concept);
169             panel.refresh();
170             panel.showConcept(null);
171         }
172    }
173 }
Popular Tags