KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > notes > NotesPlugin


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.notes;
20
21 import org.lucane.client.*;
22 import org.lucane.client.widgets.*;
23 import org.lucane.common.*;
24 import org.lucane.common.net.ObjectConnection;
25
26 import org.lucane.applications.notes.gui.main.*;
27
28
29 public class NotesPlugin
30 extends StandalonePlugin
31 {
32   private ConnectInfo service;
33   private MainFrame mainFrame;
34
35   public NotesPlugin()
36   {
37     this.service = Communicator.getInstance().getConnectInfo("org.lucane.applications.notes");
38   }
39
40   public Plugin newInstance(ConnectInfo[] friends)
41   {
42     return new NotesPlugin();
43   }
44
45   public void start()
46   {
47     mainFrame = new MainFrame(this);
48     
49     mainFrame.setAuthors(getPublishedAuthors());
50     mainFrame.setNotes(getRecentPublishedNotes());
51     mainFrame.show();
52   }
53
54   public Object JavaDoc[] getPublishedAuthors()
55   {
56     Object JavaDoc[] authors = new Object JavaDoc[0];
57
58     try {
59       NotesAction action = new NotesAction(NotesAction.GET_PUBLISHED_AUTHORS);
60       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
61       String JavaDoc ack = oc.readString();
62       if(ack.equals("OK"))
63         authors = (Object JavaDoc[])oc.read();
64       else
65         throw new Exception JavaDoc(ack);
66     } catch(Exception JavaDoc e) {
67       DialogBox.error(tr("error.listPublishedAuthors"));
68       e.printStackTrace();
69     }
70
71     return authors;
72   }
73
74   public Object JavaDoc[] getRecentPublishedNotes()
75   {
76     Object JavaDoc[] notes = new Object JavaDoc[0];
77
78     try {
79       NotesAction action = new NotesAction(NotesAction.GET_RECENT_PUBLISHED_NOTES, new Integer JavaDoc(10));
80       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
81       String JavaDoc ack = oc.readString();
82       if(ack.equals("OK"))
83         notes = (Object JavaDoc[])oc.read();
84       else
85         throw new Exception JavaDoc(ack);
86     } catch(Exception JavaDoc e) {
87       DialogBox.error(tr("error.listRecentPublishedNotes"));
88       e.printStackTrace();
89     }
90
91     return notes;
92   }
93
94   public Object JavaDoc[] getPublishedNotesByAuthor(String JavaDoc author)
95   {
96     Object JavaDoc[] notes = new Object JavaDoc[0];
97
98     try {
99       NotesAction action = new NotesAction(NotesAction.GET_PUBLISHED_NOTES_BY_AUTHOR, author);
100       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
101       String JavaDoc ack = oc.readString();
102       if(ack.equals("OK"))
103         notes = (Object JavaDoc[])oc.read();
104       else
105         throw new Exception JavaDoc(ack);
106     } catch(Exception JavaDoc e) {
107       DialogBox.error(tr("error.listPublishedNotesByAuthor"));
108       e.printStackTrace();
109     }
110
111     return notes;
112   }
113
114   public Object JavaDoc[] getPersonnalNotes()
115   {
116     Object JavaDoc[] notes = new Object JavaDoc[0];
117
118     try {
119       NotesAction action = new NotesAction(NotesAction.GET_PERSONNAL_NOTES);
120       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
121       String JavaDoc ack = oc.readString();
122       if(ack.equals("OK"))
123         notes = (Object JavaDoc[])oc.read();
124       else
125         throw new Exception JavaDoc(ack);
126     } catch(Exception JavaDoc e) {
127       DialogBox.error(tr("error.listPersonnalNotes"));
128       e.printStackTrace();
129     }
130
131     return notes;
132   }
133
134   public Object JavaDoc[] getCommentsForNote(String JavaDoc idNote)
135   {
136     Object JavaDoc[] comments = new Object JavaDoc[0];
137
138     try {
139       NotesAction action = new NotesAction(NotesAction.GET_COMMENTS_FOR_NOTE, idNote);
140       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
141       String JavaDoc ack = oc.readString();
142       if(ack.equals("OK"))
143         comments = (Object JavaDoc[])oc.read();
144       else
145         throw new Exception JavaDoc(ack);
146     } catch(Exception JavaDoc e) {
147       DialogBox.error(tr("error.listCommentsForNote"));
148       e.printStackTrace();
149     }
150
151     return comments;
152   }
153   
154   public void removeNote(String JavaDoc idNote)
155   {
156     try {
157       NotesAction action = new NotesAction(NotesAction.DELETE_NOTE, idNote);
158       ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
159       String JavaDoc ack = oc.readString();
160       if(ack.equals("OK"))
161         DialogBox.info(tr("noteRemoved"));
162       else
163         throw new Exception JavaDoc(ack);
164     } catch(Exception JavaDoc e) {
165       DialogBox.error(tr("error.removeNote"));
166       e.printStackTrace();
167     }
168     
169     mainFrame.setAuthors(getPublishedAuthors());
170     mainFrame.setNotes(getRecentPublishedNotes());
171   }
172
173
174
175     public void saveNote(Note note)
176     {
177         try {
178           NotesAction action = new NotesAction(NotesAction.SAVE_NOTE, note);
179           ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
180           String JavaDoc ack = oc.readString();
181           if(ack.equals("OK"))
182             DialogBox.info(tr("noteSaved"));
183           else
184             throw new Exception JavaDoc(ack);
185         } catch(Exception JavaDoc e) {
186           DialogBox.error(tr("error.saveNote"));
187           e.printStackTrace();
188         }
189         
190         mainFrame.setAuthors(getPublishedAuthors());
191         mainFrame.setNotes(getRecentPublishedNotes());
192     }
193
194
195     public void saveComment(Comment comment)
196     {
197         try {
198           NotesAction action = new NotesAction(NotesAction.SAVE_COMMENT, comment);
199           ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action);
200           String JavaDoc ack = oc.readString();
201           if(ack.equals("OK"))
202             DialogBox.info(tr("commentSaved"));
203           else
204             throw new Exception JavaDoc(ack);
205         } catch(Exception JavaDoc e) {
206           DialogBox.error(tr("error.saveComment"));
207           e.printStackTrace();
208         }
209         
210         mainFrame.setComments(getCommentsForNote(comment.getNoteId()));
211     }
212 }
213
Popular Tags