1 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 [] getPublishedAuthors() 55 { 56 Object [] authors = new Object [0]; 57 58 try { 59 NotesAction action = new NotesAction(NotesAction.GET_PUBLISHED_AUTHORS); 60 ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action); 61 String ack = oc.readString(); 62 if(ack.equals("OK")) 63 authors = (Object [])oc.read(); 64 else 65 throw new Exception (ack); 66 } catch(Exception e) { 67 DialogBox.error(tr("error.listPublishedAuthors")); 68 e.printStackTrace(); 69 } 70 71 return authors; 72 } 73 74 public Object [] getRecentPublishedNotes() 75 { 76 Object [] notes = new Object [0]; 77 78 try { 79 NotesAction action = new NotesAction(NotesAction.GET_RECENT_PUBLISHED_NOTES, new Integer (10)); 80 ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action); 81 String ack = oc.readString(); 82 if(ack.equals("OK")) 83 notes = (Object [])oc.read(); 84 else 85 throw new Exception (ack); 86 } catch(Exception e) { 87 DialogBox.error(tr("error.listRecentPublishedNotes")); 88 e.printStackTrace(); 89 } 90 91 return notes; 92 } 93 94 public Object [] getPublishedNotesByAuthor(String author) 95 { 96 Object [] notes = new Object [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 ack = oc.readString(); 102 if(ack.equals("OK")) 103 notes = (Object [])oc.read(); 104 else 105 throw new Exception (ack); 106 } catch(Exception e) { 107 DialogBox.error(tr("error.listPublishedNotesByAuthor")); 108 e.printStackTrace(); 109 } 110 111 return notes; 112 } 113 114 public Object [] getPersonnalNotes() 115 { 116 Object [] notes = new Object [0]; 117 118 try { 119 NotesAction action = new NotesAction(NotesAction.GET_PERSONNAL_NOTES); 120 ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action); 121 String ack = oc.readString(); 122 if(ack.equals("OK")) 123 notes = (Object [])oc.read(); 124 else 125 throw new Exception (ack); 126 } catch(Exception e) { 127 DialogBox.error(tr("error.listPersonnalNotes")); 128 e.printStackTrace(); 129 } 130 131 return notes; 132 } 133 134 public Object [] getCommentsForNote(String idNote) 135 { 136 Object [] comments = new Object [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 ack = oc.readString(); 142 if(ack.equals("OK")) 143 comments = (Object [])oc.read(); 144 else 145 throw new Exception (ack); 146 } catch(Exception e) { 147 DialogBox.error(tr("error.listCommentsForNote")); 148 e.printStackTrace(); 149 } 150 151 return comments; 152 } 153 154 public void removeNote(String idNote) 155 { 156 try { 157 NotesAction action = new NotesAction(NotesAction.DELETE_NOTE, idNote); 158 ObjectConnection oc = Communicator.getInstance().sendMessageTo(service, getName(), action); 159 String ack = oc.readString(); 160 if(ack.equals("OK")) 161 DialogBox.info(tr("noteRemoved")); 162 else 163 throw new Exception (ack); 164 } catch(Exception 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 ack = oc.readString(); 181 if(ack.equals("OK")) 182 DialogBox.info(tr("noteSaved")); 183 else 184 throw new Exception (ack); 185 } catch(Exception 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 ack = oc.readString(); 201 if(ack.equals("OK")) 202 DialogBox.info(tr("commentSaved")); 203 else 204 throw new Exception (ack); 205 } catch(Exception e) { 206 DialogBox.error(tr("error.saveComment")); 207 e.printStackTrace(); 208 } 209 210 mainFrame.setComments(getCommentsForNote(comment.getNoteId())); 211 } 212 } 213 | Popular Tags |