Skip to content

Commit 15b547c

Browse files
author
saharmehrpour
committed
client is updated
1 parent b79ddbd commit 15b547c

25 files changed

Lines changed: 857 additions & 987 deletions

.idea/libraries/json_20090211.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/json_simple_1_1_1.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 487 additions & 315 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IntelliJTestPlugin.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</content>
1010
<orderEntry type="inheritedJdk" />
1111
<orderEntry type="sourceFolder" forTests="false" />
12-
<orderEntry type="library" name="json-simple-1.1.1" level="project" />
1312
<orderEntry type="library" name="json-20090211" level="project" />
1413
</component>
1514
</module>
11 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
788 Bytes
Binary file not shown.
286 Bytes
Binary file not shown.

src/ChatServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void onMessage(WebSocket conn, String message) {
7676
JsonParser parser = new JsonParser();
7777
final JsonObject messageAsJson = parser.parse(message).getAsJsonObject();
7878
System.out.println("(onMessage) " /*+ messageAsJson*/);
79-
79+
System.out.println(message);
8080
manager.processReceivedMessages(messageAsJson);
8181

8282
}

src/FileChangeManager.java

Lines changed: 87 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ public class FileChangeManager implements ProjectComponent {
3636
private ChatServer s;
3737
private List<VirtualFile> ignoredFiles/* = new ArrayList<>()*/;
3838
private SRCMLxml srcml;
39-
// private String rules;
4039
private List<List<String>> ruleIndexText; // index - text
4140
private List<List<String>> tagNameText; // tagName - text
4241

43-
FileChangeManager(ChatServer server, SRCMLxml xmlP, /*String rule,*/ List<List<String>> ruleList, List<List<String>> tagList) {
42+
FileChangeManager(ChatServer server, SRCMLxml xmlP, List<List<String>> ruleList, List<List<String>> tagList) {
4443
connection = ApplicationManager.getApplication().getMessageBus().connect();
4544
s = server;
4645

@@ -124,18 +123,7 @@ SRCMLxml getSrcml() {
124123
}
125124

126125

127-
/**
128-
* change the srcml and send some messages to clients if the srcml is updated
129-
*
130-
* @param filePath String
131-
* @param newXml String
132-
*/
133-
private void updateSrcml(String filePath, String newXml) {
134-
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "UPDATE_XML",
135-
MessageProcessor.encodeNewXMLData(new Object[]{filePath, newXml})
136-
}).toString());
137-
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "CHECK_RULES", filePath}).toString());
138-
}
126+
//---------------------------
139127

140128
public void initComponent() {
141129
s.start();
@@ -214,6 +202,7 @@ public void projectClosed() {
214202
System.out.println("(project Closed)");
215203
}
216204

205+
//-------------------------------
217206

218207
/**
219208
* process the message received from the client
@@ -260,19 +249,23 @@ void processReceivedMessages(JsonObject messageAsJson) {
260249
this.setRuleIndexText(ruleIndex, ruleText);
261250
this.writeToFile("ruleJson.txt");
262251

263-
// TODO send message
252+
// send message
253+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "UPDATE_RULE",
254+
MessageProcessor.encodeModifiedRule(new Object[]{ruleIndex, ruleText})
255+
}).toString());
264256

265257
break;
266258

267259
case "MODIFIED_TAG":
268260

269-
String tagName = Integer.toString(messageAsJson.get("data").getAsJsonObject().get("tagName").getAsInt());
261+
String tagName = messageAsJson.get("data").getAsJsonObject().get("tagName").getAsString();
270262
String tagText = messageAsJson.get("data").getAsJsonObject().get("tagText").getAsJsonObject().toString();
271263

272264
this.setTagNameText(tagName, tagText);
273265
this.writeToFile("tagJson.txt");
274266

275-
// TODO send message
267+
// send message
268+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "UPDATE_TAG", tagText}).toString());
276269

277270
break;
278271

@@ -287,24 +280,6 @@ void processReceivedMessages(JsonObject messageAsJson) {
287280
}
288281

289282

290-
/** checks if we should ignore a file
291-
* @param s virtual file
292-
* @return true/false
293-
*/
294-
private boolean shouldIgnoreFile(VirtualFile s) {
295-
if (ignoredFiles == null) {
296-
return false;
297-
}
298-
for (VirtualFile vfile : ignoredFiles) {
299-
if (vfile.getCanonicalPath().equals(s.getCanonicalPath())) {
300-
return true;
301-
} else if (utilities.isFileAChildOf(s, vfile)) {
302-
return true;
303-
}
304-
}
305-
return false;
306-
}
307-
308283
//------------------ handle file events
309284

310285
// when the text of a file changes
@@ -313,8 +288,12 @@ private void handleVFileChangeEvent(VFileEvent event) {
313288

314289
// if we are dealing with ruleJson.txt
315290
if (file.getName().equals("ruleJson.txt")) {
316-
//TODO
317-
// this.setRules(MessageProcessor.getInitialRules().toString());
291+
updateRules();
292+
return;
293+
}
294+
// if we are dealing with tagJson.txt
295+
if (file.getName().equals("tagJson.txt")) {
296+
updateTags();
318297
return;
319298
}
320299

@@ -336,8 +315,12 @@ private void handleVFileCreateEvent(VFileEvent event) {
336315

337316
// if we are dealing with ruleJson.txt
338317
if (file.getName().equals("ruleJson.txt")) {
339-
// TODO
340-
// this.setRules(MessageProcessor.getInitialRules().toString());
318+
updateRules();
319+
return;
320+
}
321+
// if we are dealing with tagJson.txt
322+
if (file.getName().equals("tagJson.txt")) {
323+
updateTags();
341324
return;
342325
}
343326

@@ -349,7 +332,6 @@ private void handleVFileCreateEvent(VFileEvent event) {
349332
System.out.println("CREATE");
350333
String newXml = SRCMLHandler.addXMLForProject(this.getSrcml(), file.getPath());
351334
this.updateSrcml(file.getPath(), newXml);
352-
//this.setSrcml(SRCMLHandler.addXMLForProject(this.getSrcml(), file.getPath()));
353335

354336
}
355337

@@ -379,8 +361,12 @@ private void handleVFileDeleteEvent(VFileEvent event) {
379361

380362
// if we are dealing with ruleJson.txt
381363
if (file.getName().equals("ruleJson.txt")) {
382-
// TODO
383-
// this.setRules("");
364+
updateRules();
365+
return;
366+
}
367+
// if we are dealing with tagJson.txt
368+
if (file.getName().equals("tagJson.txt")) {
369+
updateTags();
384370
return;
385371
}
386372

@@ -393,6 +379,27 @@ private void handleVFileDeleteEvent(VFileEvent event) {
393379

394380
//----------------------------------
395381

382+
/**
383+
* checks if we should ignore a file
384+
*
385+
* @param s virtual file
386+
* @return true/false
387+
*/
388+
private boolean shouldIgnoreFile(VirtualFile s) {
389+
if (ignoredFiles == null) {
390+
return false;
391+
}
392+
for (VirtualFile vfile : ignoredFiles) {
393+
if (vfile.getCanonicalPath().equals(s.getCanonicalPath())) {
394+
return true;
395+
} else if (utilities.isFileAChildOf(s, vfile)) {
396+
return true;
397+
}
398+
}
399+
return false;
400+
}
401+
402+
396403
/**
397404
* check whether we should consider the file change
398405
*
@@ -466,6 +473,7 @@ void checkChangedProject() {
466473

467474
/**
468475
* write in file
476+
*
469477
* @param fileName either ruleJson.txt or tagJson.txt
470478
*/
471479
private void writeToFile(String fileName) {
@@ -500,4 +508,41 @@ private void writeToFile(String fileName) {
500508
}
501509

502510
}
511+
512+
513+
/**
514+
* update the ruleIndexText and send messages to clients
515+
*/
516+
private void updateRules() {
517+
this.ruleIndexText = MessageProcessor.getInitialRulesAsList();
518+
519+
// send the message
520+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "RULE_TABLE", this.getAllRules()}).toString());
521+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "VERIFY_RULES", ""}).toString());
522+
}
523+
524+
/**
525+
* update the tagNameText and send messages to clients
526+
*/
527+
private void updateTags() {
528+
this.tagNameText = MessageProcessor.getInitialTagsAsList();
529+
530+
// send the message
531+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "TAG_TABLE", this.getAllTags()}).toString());
532+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "VERIFY_RULES", ""}).toString());
533+
}
534+
535+
/**
536+
* change the srcml and send some messages to clients if the srcml is updated
537+
*
538+
* @param filePath String
539+
* @param newXml String
540+
*/
541+
private void updateSrcml(String filePath, String newXml) {
542+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "UPDATE_XML",
543+
MessageProcessor.encodeNewXMLData(new Object[]{filePath, newXml})
544+
}).toString());
545+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "CHECK_RULES_FOR_FILE", filePath}).toString());
546+
}
547+
503548
}

0 commit comments

Comments
 (0)