001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.applications.administrator.gui;
020:
021: import java.util.*;
022: import java.awt.*;
023: import java.awt.event.*;
024: import javax.swing.*;
025:
026: import org.lucane.applications.administrator.AdministratorPlugin;
027: import org.lucane.client.widgets.DialogBox;
028: import org.lucane.common.concepts.*;
029:
030: public class PluginPanel extends JPanel implements MouseListener,
031: ActionListener {
032: private transient AdministratorPlugin plugin;
033:
034: private JTextField pluginName;
035: private JTextField pluginVersion;
036: private JTextArea pluginDescription;
037:
038: private JButton btnUpdate;
039: private JButton btnRemove;
040:
041: private ConceptTable pluginGroups;
042: private ConceptPanel panel;
043:
044: public PluginPanel(AdministratorPlugin plugin, ConceptPanel panel) {
045: super (new BorderLayout());
046: this .plugin = plugin;
047: this .panel = panel;
048:
049: //-- attributes
050: pluginName = new JTextField();
051: pluginName.setEnabled(false);
052: pluginVersion = new JTextField();
053: pluginDescription = new JTextArea();
054: pluginGroups = new ConceptTable(plugin, tr("groups"));
055: pluginGroups.addMouseListener(this );
056:
057: //-- name and version
058: JPanel labels = new JPanel(new GridLayout(2, 1));
059: labels.add(new JLabel(tr("name")));
060: labels.add(new JLabel(tr("plugin.version")));
061:
062: JPanel fields = new JPanel(new GridLayout(2, 1));
063: fields.add(pluginName);
064: fields.add(pluginVersion);
065:
066: JPanel nameAndVersion = new JPanel(new BorderLayout());
067: nameAndVersion.add(labels, BorderLayout.WEST);
068: nameAndVersion.add(fields, BorderLayout.CENTER);
069:
070: //-- description
071: JPanel description = new JPanel(new BorderLayout());
072: description.add(new JLabel(tr("description")),
073: BorderLayout.NORTH);
074: description.add(new JScrollPane(pluginDescription),
075: BorderLayout.CENTER);
076:
077: //-- groups
078: JPanel groups = new JPanel(new BorderLayout());
079: groups.add(new JLabel(tr("groups")), BorderLayout.NORTH);
080: groups.add(new JScrollPane(pluginGroups));
081:
082: //-- description and groups
083: JPanel descriptionAndGroups = new JPanel(new GridLayout(2, 1));
084: descriptionAndGroups.add(description);
085: descriptionAndGroups.add(groups);
086:
087: //buttons
088: JPanel buttonsContainer = new JPanel(new BorderLayout());
089: JPanel buttons = new JPanel(new GridLayout(1, 2));
090: btnRemove = new JButton(tr("btn.remove"));
091: btnRemove.addActionListener(this );
092: buttons.add(btnRemove);
093: btnUpdate = new JButton(tr("btn.save"));
094: btnUpdate.addActionListener(this );
095: buttons.add(btnUpdate);
096: buttonsContainer.add(buttons, BorderLayout.EAST);
097:
098: //-- complete
099: 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: pluginName.setText(concept.getName());
106: pluginVersion.setText(concept.getVersion());
107: pluginDescription.setText(concept.getDescription());
108: setGroups(concept);
109: }
110:
111: public void setGroups(PluginConcept plugin) {
112: ArrayList groups = new ArrayList();
113: Iterator allGroups = this .plugin.getAllGroups(false).iterator();
114:
115: while (allGroups.hasNext()) {
116: GroupConcept group = (GroupConcept) allGroups.next();
117: if (group.hasPlugin(plugin))
118: groups.add(group);
119: }
120:
121: pluginGroups.setConcepts(groups);
122: }
123:
124: private String tr(String s) {
125: return plugin.tr(s);
126: }
127:
128: //-- mouse listener
129:
130: public void mouseEntered(MouseEvent e) {
131: }
132:
133: public void mouseExited(MouseEvent e) {
134: }
135:
136: public void mousePressed(MouseEvent e) {
137: }
138:
139: public void mouseReleased(MouseEvent e) {
140: }
141:
142: public void mouseClicked(MouseEvent e) {
143: if (e.getClickCount() < 2)
144: return;
145:
146: int row = pluginGroups.getSelectedRow();
147: if (row < 0)
148: return;
149:
150: panel.showConcept(pluginGroups.getConceptAt(row));
151: }
152:
153: //-- action listener
154: public void actionPerformed(ActionEvent ae) {
155: PluginConcept concept = new PluginConcept(pluginName.getText(),
156: pluginVersion.getText());
157: concept.setDescription(pluginDescription.getText());
158:
159: if (ae.getSource() == btnUpdate) {
160: if (concept.getVersion().length() == 0) {
161: DialogBox.error(tr("err.pluginVersionIsMandatory"));
162: return;
163: }
164: plugin.updateConcept(concept);
165: panel.refresh();
166: } else if (ae.getSource() == btnRemove) {
167: plugin.removeConcept(concept);
168: panel.refresh();
169: panel.showConcept(null);
170: }
171: }
172: }
|