use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.
the class CommentCallerHandler method createComment.
private IComment createComment(File commentFile) {
IComment comment = new Comment();
String commentID = commentFile.getName();
commentID = commentID.substring(0, commentID.indexOf(this.getCommentFilenameExtension()));
comment.setID(commentID);
comment.setDate(new Date(commentFile.lastModified()));
try {
FileReader commentReader = new FileReader(commentFile);
BufferedReader bufReader = new BufferedReader(commentReader);
StringBuffer text = new StringBuffer();
while (bufReader.ready()) {
text.append(bufReader.readLine());
text.append(IJAMConst.CRLF);
}
bufReader.close();
commentReader.close();
comment.setText(text.substring(0));
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find comment file " + commentFile);
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + commentFile);
}
File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
if (commentAttributesFile.exists() && commentAttributesFile.isFile()) {
Properties commentAttributes = new Properties();
try {
FileInputStream in = new FileInputStream(commentAttributesFile);
commentAttributes.load(in);
in.close();
Iterator it = commentAttributes.keySet().iterator();
IAttribute a = null;
String key = null;
while (it.hasNext()) {
key = (String) it.next();
a = PIMRuntime.getInstance().getCallerFactory().createAttribute(key, commentAttributes.getProperty(key));
comment.addAttribute(a);
}
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + commentAttributesFile.getAbsolutePath());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + commentAttributesFile.getAbsolutePath());
}
}
return comment;
}
use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.
the class CommentCallerHandler method storeComments.
private void storeComments(List comments, String directory) {
// clean up old comments
File[] oldComments = new File(directory).listFiles(new FileFilter() {
public boolean accept(File pathname) {
if (pathname.getAbsolutePath().endsWith(getCommentFilenameExtension())) {
return true;
}
return false;
}
});
for (int i = 0; i < oldComments.length; i++) oldComments[i].delete();
for (int i = 0; i < comments.size(); i++) {
IComment comment = (IComment) comments.get(i);
File commentFile = new File(directory + comment.getID() + this.getCommentFilenameExtension());
try {
FileWriter commentWriter = new FileWriter(commentFile);
BufferedWriter bufWriter = new BufferedWriter(commentWriter);
bufWriter.write(comment.getText());
bufWriter.flush();
bufWriter.close();
commentWriter.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + directory + comment.getID());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + directory + comment.getID());
}
commentFile.setLastModified(comment.getDate().getTime());
Properties commentAttributes = new Properties();
IAttributeMap m = comment.getAttributes();
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
commentAttributes.setProperty(a.getName(), a.getValue());
}
File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
try {
FileOutputStream fos = new FileOutputStream(commentAttributesFile);
commentAttributes.store(fos, "");
fos.flush();
fos.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + directory + comment.getID());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + directory + comment.getID());
}
commentAttributesFile.setLastModified(comment.getDate().getTime());
// TODO: removed due to performance reasons
// this.storeAttachments(comment.getAttachments(), directory + comment.getID());
}
}
use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.
the class DeleteAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof IComment) {
List l = new ArrayList();
l.add(o);
if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "delete", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "delete", "description", this.getLanguage()))) {
this.m_app.getController().deleteElements(l);
this.m_app.getApplication().initializeController();
this.m_app.updateViews(true);
}
}
}
}
}
use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.
the class ExportAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
List l = selection.toList();
if (l.size() > 0) {
FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
dialog.setFilterExtensions(new String[] { "*.txt" });
dialog.setFilterNames(new String[] { getI18nManager().getString(getNamespace(), "exportfilter", "label", getLanguage()) });
dialog.setText(getI18nManager().getString(getNamespace(), "export", "label", getLanguage()));
String filename = dialog.open();
if (filename != null && filename.length() > 0) {
File f = new File(filename);
f.getParentFile().mkdirs();
try {
FileOutputStream fos = new FileOutputStream(f);
IComment c = null;
for (int i = 0; i < l.size(); i++) {
c = (IComment) l.get(i);
fos.write(c.getText().getBytes());
fos.write(IJAMConst.CRLF.getBytes());
}
fos.flush();
fos.close();
} catch (FileNotFoundException ex) {
m_logger.severe(ex.getMessage());
} catch (IOException ex) {
m_logger.severe(ex.toString() + ": " + ex.getMessage());
}
}
}
}
}
}
use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.
the class NewAction method run.
public void run() {
Object callableObject = null;
if (this.m_app instanceof Comment) {
callableObject = ((Comment) this.m_app).getCallableObject();
}
CommentDialog cd = new CommentDialog(DisplayManager.getDefaultDisplay().getActiveShell(), null, callableObject);
int result = cd.open();
if (result == CommentDialog.OK) {
IComment c = cd.getResult();
this.m_app.getController().updateElement(c);
this.m_app.updateViews(true);
}
}
Aggregations