1 |
//(c): Tuomas J. Lukka and Matti Katila |
//(c): Tuomas J. Lukka and Matti Katila |
2 |
|
|
3 |
package org.fenfire.modules.pp; |
package org.fenfire.modules.pp; |
4 |
|
import org.fenfire.*; |
5 |
import org.fenfire.vocab.*; |
import org.fenfire.vocab.*; |
6 |
import org.fenfire.util.*; |
import org.fenfire.util.*; |
7 |
import java.io.IOException; |
import java.io.IOException; |
19 |
protected static void p(String s) { if(dbg) pa(s); } |
protected static void p(String s) { if(dbg) pa(s); } |
20 |
protected static void pa(String s) { System.out.println(s); } |
protected static void pa(String s) { System.out.println(s); } |
21 |
|
|
22 |
private Model model; |
private Space space; |
23 |
public void setModel(Model model) { this.model = model; } |
public void setSpace(Space space) { this.space = space; } |
24 |
|
|
25 |
public PPActionsImpl(Model model) throws RemoteException { |
public PPActionsImpl(Space space) throws RemoteException { |
26 |
super(); |
super(); |
27 |
setModel(model); |
setSpace(space); |
28 |
} |
} |
29 |
|
|
30 |
|
|
32 |
// --- implement PPActions |
// --- implement PPActions |
33 |
// |
// |
34 |
public String newPaper() throws RemoteException |
public String newPaper() throws RemoteException |
35 |
{ synchronized(model) { try { |
{ synchronized(space) { try { |
36 |
|
|
37 |
// We need a unique uri for paper |
Resource paper = (Resource)ShortRDF.newNode(space.getModel(), PP.paperType); |
|
String uri = URN5Namespace.instance.generateId(); |
|
|
Resource paper = model.createResource(uri); |
|
|
|
|
|
// and resource must be also paper.. |
|
|
paper.addProperty(RDF.type, PP.paperType); |
|
38 |
|
|
39 |
// set creation time |
// set creation time |
40 |
// XXX we need iso 8601 time presentation here |
// XXX we need iso 8601 time presentation here |
41 |
paper.addProperty(PP.creationTime, "123"); |
paper.addProperty(PP.creationTime, "123"); |
42 |
|
|
43 |
return uri; |
return paper.toString(); |
44 |
} catch (RDFException e) { |
} catch (RDFException e) { |
45 |
return ""; |
return ""; |
46 |
}}} |
}}} |
47 |
|
|
48 |
|
|
49 |
public void deletePaper(String paperURI) throws RemoteException |
public void deletePaper(String paperURI) throws RemoteException |
50 |
{ synchronized(model) { |
{ synchronized(space) { |
51 |
/* |
/* |
52 |
// must delete all notes first |
// must delete all notes first |
53 |
Cell paper = space.getCell(paperId).h(d.contains, -1); |
Cell paper = space.getCell(paperId).h(d.contains, -1); |
69 |
|
|
70 |
public String newNote(String paperURI, int x, int y, String text) |
public String newNote(String paperURI, int x, int y, String text) |
71 |
throws RemoteException |
throws RemoteException |
72 |
{ synchronized(model) { try { |
{ synchronized(space) { try { |
73 |
|
|
74 |
// find the paper |
// find the paper |
75 |
Resource paper = model.getResource(paperURI); |
Resource paper = space.getModel().getResource(paperURI); |
76 |
|
if (paper == null) { |
77 |
|
pa("Paper is NULL!!"); |
78 |
|
return ""; |
79 |
|
} |
80 |
|
|
81 |
// note doesn't exist so we need to make one |
// note doesn't exist so we need to make one |
82 |
String note_uri = URN5Namespace.instance.generateId(); |
Resource note = (Resource)space.N(text, paper, PP.contains); |
|
Resource note = model.createResource(note_uri); |
|
83 |
note.addProperty(RDF.type, PP.noteType); |
note.addProperty(RDF.type, PP.noteType); |
84 |
|
|
|
// set note to paper |
|
|
paper.addProperty(PP.contains, note); |
|
|
|
|
85 |
// set coords |
// set coords |
86 |
note.addProperty(SPATIAL.coordX, ""+x); |
note.addProperty(SPATIAL.coordX, ""+x); |
87 |
note.addProperty(SPATIAL.coordY, ""+y); |
note.addProperty(SPATIAL.coordY, ""+y); |
91 |
|
|
92 |
// scale etc.. XXX |
// scale etc.. XXX |
93 |
|
|
94 |
|
return note.toString(); |
|
// XXX use real Alph!!!! |
|
|
note.addProperty(ALPH.content, text); |
|
|
return note_uri; |
|
95 |
|
|
96 |
} catch (RDFException e) { |
} catch (RDFException e) { |
97 |
pa("Fault creating a new note: "+e); |
pa("Fault creating a new note: "+e); |
101 |
|
|
102 |
public void deleteNote(String noteURI) |
public void deleteNote(String noteURI) |
103 |
throws RemoteException |
throws RemoteException |
104 |
{ synchronized(model) { try { |
{ synchronized(space) { try { |
105 |
/* |
/* |
106 |
// MUST DELETE ALL ASSOCS FIRST |
// MUST DELETE ALL ASSOCS FIRST |
107 |
|
|
137 |
// not implemented |
// not implemented |
138 |
// =============== |
// =============== |
139 |
|
|
140 |
Resource note = model.getResource(noteURI); |
Resource note = space.getModel().getResource(noteURI); |
141 |
|
|
142 |
} catch (RDFException e) { |
} catch (RDFException e) { |
143 |
pa("Fault deleting a note: "+e); |
pa("Fault deleting a note: "+e); |
145 |
|
|
146 |
public void moveNote(String noteURI, int x, int y) |
public void moveNote(String noteURI, int x, int y) |
147 |
throws RemoteException |
throws RemoteException |
148 |
{ synchronized(model) { try { |
{ synchronized(space) { try { |
149 |
|
|
150 |
Resource note = model.getResource(noteURI); |
Resource note = space.getModel().getResource(noteURI); |
151 |
if (note == null) return; |
if (note == null) return; |
152 |
|
|
153 |
// delete all old coords |
// delete all old coords |
154 |
ShortRDF.rmObj(model, note, SPATIAL.coordX); |
ShortRDF.rmObj(space.getModel(), note, SPATIAL.coordX); |
155 |
ShortRDF.rmObj(model, note, SPATIAL.coordY); |
ShortRDF.rmObj(space.getModel(), note, SPATIAL.coordY); |
156 |
|
|
157 |
// set coords |
// set coords |
158 |
note.addProperty(SPATIAL.coordX, ""+x); |
note.addProperty(SPATIAL.coordX, ""+x); |
164 |
|
|
165 |
public void assocNotes(String noteURI, int side, String assocURI) |
public void assocNotes(String noteURI, int side, String assocURI) |
166 |
throws RemoteException |
throws RemoteException |
167 |
{ synchronized(model) { try { |
{ synchronized(space) { try { |
168 |
Resource note = model.getResource(noteURI); |
Resource note = space.getModel().getResource(noteURI); |
169 |
Resource assoc = model.getResource(assocURI); |
Resource assoc = space.getModel().getResource(assocURI); |
170 |
|
|
171 |
if (note == assoc) { |
if (note == assoc) { |
172 |
pa("link to itself???"); |
pa("link to itself???"); |
175 |
|
|
176 |
if (side < 0) { |
if (side < 0) { |
177 |
// check if already associated |
// check if already associated |
178 |
if (((ModelCom)model).contains(assoc, PP.association, (RDFNode)note)) { |
if (((ModelCom)space.getModel()).contains(assoc, PP.association, (RDFNode)note)) { |
179 |
pa("Already associated!"); |
pa("Already associated!"); |
180 |
return; |
return; |
181 |
} |
} |
184 |
assoc.addProperty(PP.association, note); |
assoc.addProperty(PP.association, note); |
185 |
} else { |
} else { |
186 |
// check if already associated |
// check if already associated |
187 |
if (((ModelCom)model).contains(note, PP.association, (RDFNode)assoc)) { |
if (((ModelCom)space.getModel()).contains(note, PP.association, (RDFNode)assoc)) { |
188 |
pa("Already associated!"); |
pa("Already associated!"); |
189 |
return; |
return; |
190 |
} |
} |
198 |
|
|
199 |
public void detachNotes(String id1, int side, String id2) |
public void detachNotes(String id1, int side, String id2) |
200 |
throws RemoteException |
throws RemoteException |
201 |
{ synchronized(model) { |
{ synchronized(space) { |
202 |
|
|
203 |
/* |
/* |
204 |
Cell c1 = space.getCell(id1).h(d.clone); |
Cell c1 = space.getCell(id1).h(d.clone); |
227 |
|
|
228 |
public void insertText(String noteURI, int offs, String text) |
public void insertText(String noteURI, int offs, String text) |
229 |
throws RemoteException |
throws RemoteException |
230 |
{ synchronized(model) { //try { |
{ synchronized(space) { //try { |
231 |
/* |
/* |
232 |
Cell note = space.getCell(noteId); |
Cell note = space.getCell(noteId); |
233 |
note.insertText(offs, text); |
note.insertText(offs, text); |
270 |
|
|
271 |
public void deleteText(String noteURI, int begin, int end) |
public void deleteText(String noteURI, int begin, int end) |
272 |
throws RemoteException |
throws RemoteException |
273 |
{ synchronized(model) { // try { |
{ synchronized(space) { // try { |
274 |
/* |
/* |
275 |
Cell note = space.getCell(noteId); |
Cell note = space.getCell(noteId); |
276 |
note.deleteText(begin, end); |
note.deleteText(begin, end); |