001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2002 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.forumadmin;
020:
021: import org.lucane.client.*;
022: import org.lucane.client.acl.AclEditor;
023: import org.lucane.client.widgets.*;
024: import org.lucane.common.*;
025: import org.lucane.common.acl.AclInfo;
026: import org.lucane.common.acl.AclProducer;
027: import org.lucane.common.net.ObjectConnection;
028:
029: import java.awt.*;
030: import java.awt.event.*;
031: import java.util.ArrayList;
032: import javax.swing.*;
033:
034: public class ForumAdmin extends StandalonePlugin implements
035: ActionListener, AclProducer {
036:
037: private ManagedWindow mainWindow;
038: private JButton btnCreate;
039: private JButton btnDelete;
040: private JButton btnACL;
041: private JButton btnClose;
042: private JList lstForums;
043: private ConnectInfo service;
044:
045: public ForumAdmin() {
046: }
047:
048: public Plugin newInstance(ConnectInfo[] friends) {
049: return new ForumAdmin();
050: }
051:
052: public void start() {
053: this .service = Communicator.getInstance().getConnectInfo(
054: "org.lucane.applications.forumadmin");
055:
056: mainWindow = new ManagedWindow(this , getTitle());
057: lstForums = new JList();
058: btnCreate = new JButton(tr("btn.create"));
059: btnDelete = new JButton(tr("btn.remove"));
060: btnACL = new JButton(tr("btn.accessControl"));
061: btnClose = new JButton(tr("btn.close"));
062: btnCreate.addActionListener(this );
063: btnDelete.addActionListener(this );
064: btnACL.addActionListener(this );
065: btnClose.addActionListener(this );
066: mainWindow.getContentPane().setLayout(new BorderLayout());
067: mainWindow.getContentPane().add(lstForums, BorderLayout.CENTER);
068:
069: JPanel pnlBtns = new JPanel(new BorderLayout());
070: JPanel pnlTop = new JPanel(new GridLayout(0, 1));
071: pnlTop.add(btnCreate);
072: pnlTop.add(btnDelete);
073: pnlTop.add(btnACL);
074: pnlBtns.add(pnlTop, BorderLayout.NORTH);
075: pnlBtns.add(btnClose, BorderLayout.SOUTH);
076: mainWindow.getContentPane().add(pnlBtns, BorderLayout.EAST);
077: mainWindow.setPreferredSize(new Dimension(400, 300));
078: mainWindow.show();
079: getForumList();
080: }
081:
082: public void actionPerformed(ActionEvent ae) {
083: if (ae.getSource() == btnCreate)
084: createForum();
085: else if (ae.getSource() == btnDelete)
086: deleteForum();
087: else if (ae.getSource() == btnClose) {
088: mainWindow.dispose();
089: exit();
090: } else if (ae.getSource() == btnACL)
091: editAcl();
092: }
093:
094: private void getForumList() {
095: try {
096: ForumAdminAction action = new ForumAdminAction(
097: ForumAdminAction.LIST_FORUMS);
098: ObjectConnection oc = Communicator.getInstance()
099: .sendMessageTo(service, getName(), action);
100:
101: String ack = oc.readString();
102: if (ack.equals("OK")) {
103: ArrayList forums = (ArrayList) oc.read();
104: lstForums.setListData(forums.toArray());
105: } else
106: DialogBox.error(ack);
107:
108: oc.close();
109: } catch (Exception e) {
110: DialogBox.error(tr("err.list"));
111: }
112: }
113:
114: private void createForum() {
115: String forum = JOptionPane.showInputDialog(tr("msg.newForum"));
116:
117: if (forum == null || forum.equals(""))
118: return;
119:
120: try {
121: ForumAdminAction action = new ForumAdminAction(
122: ForumAdminAction.CREATE_FORUM, forum);
123: ObjectConnection oc = Communicator.getInstance()
124: .sendMessageTo(service, getName(), action);
125:
126: String ack = (String) oc.read();
127: oc.close();
128:
129: if (ack.equals("OK"))
130: getForumList();
131: else
132: DialogBox.error(ack);
133:
134: } catch (Exception e) {
135: DialogBox.error(tr("err.create"));
136: }
137: }
138:
139: private void deleteForum() {
140: String forum = (String) lstForums.getSelectedValue();
141:
142: if (forum == null)
143: return;
144:
145: try {
146: ForumAdminAction action = new ForumAdminAction(
147: ForumAdminAction.DELETE_FORUM, forum);
148:
149: ObjectConnection oc = Communicator.getInstance()
150: .sendMessageTo(service, getName(), action);
151: String ack = (String) oc.read();
152: oc.close();
153:
154: if (ack.equals("OK"))
155: getForumList();
156: else
157: DialogBox.error(ack);
158: } catch (Exception e) {
159: DialogBox.error(tr("err.delete"));
160: }
161: }
162:
163: private void editAcl() {
164: String forum = (String) lstForums.getSelectedValue();
165:
166: if (forum == null)
167: return;
168:
169: try {
170: AclEditor editor = new AclEditor(this , this , forum);
171: editor.show();
172: } catch (Exception e) {
173: DialogBox.error(tr("err.unableToEditAcl"));
174: e.printStackTrace();
175: }
176: }
177:
178: public AclInfo[] getAcls(String forum) throws Exception {
179: AclInfo[] acl = null;
180:
181: ForumAdminAction action = new ForumAdminAction(
182: ForumAdminAction.GET_ACLS, forum);
183: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
184: service, getName(), action);
185: String ack = (String) oc.read();
186:
187: if (ack.equals("OK")) {
188: acl = (AclInfo[]) oc.read();
189: oc.close();
190:
191: return acl;
192: }
193: oc.close();
194: throw new Exception(ack);
195: }
196:
197: public ArrayList getAllGroups() throws Exception {
198: ArrayList groups = null;
199:
200: ForumAdminAction action = new ForumAdminAction(
201: ForumAdminAction.GET_GROUPS);
202: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
203: service, getName(), action);
204: String ack = (String) oc.read();
205:
206: if (ack.equals("OK")) {
207: groups = (ArrayList) oc.read();
208: oc.close();
209:
210: return groups;
211: }
212: oc.close();
213: throw new Exception(ack);
214: }
215:
216: public ArrayList getAllUsers() throws Exception {
217: ArrayList users = null;
218:
219: ForumAdminAction action = new ForumAdminAction(
220: ForumAdminAction.GET_USERS);
221: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
222: service, getName(), action);
223: String ack = (String) oc.read();
224:
225: if (ack.equals("OK")) {
226: users = (ArrayList) oc.read();
227: oc.close();
228:
229: return users;
230: }
231: oc.close();
232: throw new Exception(ack);
233: }
234:
235: public void addAcl(String forum, AclInfo info) throws Exception {
236: ForumAdminAction action = new ForumAdminAction(
237: ForumAdminAction.ADD_ACL, forum, info);
238: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
239: service, getName(), action);
240: String ack = (String) oc.read();
241: oc.close();
242:
243: if (!ack.equals("OK"))
244: throw new Exception(ack);
245: }
246:
247: public void removeAcl(String forum, AclInfo info) throws Exception {
248: ForumAdminAction action = new ForumAdminAction(
249: ForumAdminAction.REMOVE_ACL, forum, info);
250: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
251: service, getName(), action);
252: String ack = (String) oc.read();
253: oc.close();
254:
255: if (!ack.equals("OK"))
256: throw new Exception(ack);
257: }
258:
259: //introduced for acl webapp
260: public String[] getAccesses() {
261: return new String[] { "Moderate", "Write", "Read" };
262: }
263:
264: public String getItemName(String itemId) {
265: return itemId;
266: }
267: }
|