Skip to content

Commit

Permalink
removed main functionality from tool window, the tool is functional i…
Browse files Browse the repository at this point in the history
…mmediately without the need to launch tool window
  • Loading branch information
saharmehrpour committed Apr 18, 2019
1 parent 72b7487 commit c8b54be
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 119 deletions.
13 changes: 9 additions & 4 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<idea-plugin>
<id>active_doc_plugin</id>
<name>ActiveDoc Plugin</name>
<version>2.0</version>
<version>3.0</version>
<vendor email="[email protected]" url="http://mason.gmu.edu/~smehrpou/">GMU DevUXD</vendor>

<description><![CDATA[
ActiveDocumentation Tool
]]></description>

<change-notes><![CDATA[
initial release
The tool window in the plugin is not functional. Instead the plugin runs in background and is accessible in the browser immediately.
]]>
</change-notes>

Expand All @@ -22,9 +22,14 @@
<depends>com.intellij.modules.lang</depends>
-->

<project-components>
<component>
<implementation-class>FileChangeManager</implementation-class>
</component>
</project-components>

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<toolWindow id="ActiveDocs" anchor="right" factoryClass="GrepServerToolWindowFactory"/>
<toolWindow id="ActiveDocs" anchor="right" factoryClass="CustomToolWindowFactory"/>
</extensions>

<actions>
Expand Down
3 changes: 1 addition & 2 deletions src/ChatServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.LinkedList;
import java.util.List;

/**
/*
* edited by saharmehrpour
*/

Expand All @@ -28,7 +28,6 @@ public class ChatServer extends WebSocketServer {
private FileChangeManager manager; // to process received messages

/**
* only used in GrepServerToolWindowFactory.run()
*
* @param port = 8887
* @throws UnknownHostException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
* This module creates the GUI for the plugin
*/

import core.model.SRCMLxml;
import core.model.SRCMLHandler;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import org.java_websocket.WebSocketImpl;
import org.jetbrains.annotations.NotNull;

import com.intellij.openapi.project.Project;
Expand All @@ -21,13 +17,8 @@

import javax.swing.*;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;

public class GrepServerToolWindowFactory implements ToolWindowFactory {
public class CustomToolWindowFactory implements ToolWindowFactory {

private ChatServer chatServer;
private WebEngine webEngine;
private WebView browser;

Expand All @@ -37,34 +28,6 @@ public class GrepServerToolWindowFactory implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {

// start the connection when the project is loaded and indexing is done
try {
WebSocketImpl.DEBUG = false;
// int port = findAvailablePort(new int[]{8887, 8888, 8889, 8885, 8886}); // 843 flash policy port
chatServer = new ChatServer(8887);
// System.out.println("-> started on port: " + port);

} catch (Exception e) {
System.out.println("Error in creating a Chat server.");
e.printStackTrace();
}

// This will allow file changes to be sent to the web client

System.out.println("-> project path: " + project.getBasePath());

SRCMLxml srcml = new SRCMLxml(FileChangeManager.getFilePaths(project), project.getBasePath());
SRCMLHandler.createXMLForProject(srcml);
System.out.println("XML data is created.");

FileChangeManager fcm = new FileChangeManager(project, chatServer, srcml/*, MessageProcessor.getInitialRules().toString()*/
, MessageProcessor.getInitialRulesAsList(project)
, MessageProcessor.getInitialTagsAsList(project));
chatServer.setManager(fcm);

fcm.initComponent();


// generate the GUI

System.out.println("(createToolWindowContent)");
Expand Down Expand Up @@ -126,31 +89,5 @@ private synchronized void publishServices() {
}


private int findAvailablePort(int[] ports) throws IOException {
ServerSocket tempSocket = null;
boolean found = false;
int foundPort = 0;
for (int port : ports) {

try {
tempSocket = new ServerSocket(port);
found = true;
foundPort = port;
break;
} catch (IOException e) {
//e.printStackTrace();
}
}

if (!found)
throw new IOException("no free port found");

else {
tempSocket.close();
return foundPort;
}
}


}

100 changes: 51 additions & 49 deletions src/FileChangeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.openapi.vfs.VirtualFileManager;
Expand All @@ -14,16 +15,16 @@
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import org.java_websocket.WebSocketImpl;
import org.jetbrains.annotations.NotNull;

import core.model.SRCMLHandler;
import core.model.SRCMLxml;
import org.jetbrains.annotations.Nullable;


import java.util.*;
Expand All @@ -44,18 +45,20 @@ public class FileChangeManager implements ProjectComponent {
private List<List<String>> ruleIndexText; // index - text
private List<List<String>> tagNameText; // tagName - text
private Project currentProject;
public String projectPath;
String projectPath;

FileChangeManager(Project project, ChatServer server, SRCMLxml xmlP, List<List<String>> ruleList, List<List<String>> tagList) {
connection = ApplicationManager.getApplication().getMessageBus().connect();
s = server;

srcml = xmlP;
ruleIndexText = ruleList;
tagNameText = tagList;
FileChangeManager(Project project) {

connection = ApplicationManager.getApplication().getMessageBus().connect();
currentProject = project;
projectPath = project.getBasePath();

srcml = new SRCMLxml(FileChangeManager.getFilePaths(project), project.getBasePath());
SRCMLHandler.createXMLForProject(srcml);

ruleIndexText = MessageProcessor.getInitialRulesAsList(project);
tagNameText = MessageProcessor.getInitialTagsAsList(project);

}


Expand Down Expand Up @@ -140,31 +143,21 @@ SRCMLxml getSrcml() {
//---------------------------

public void initComponent() {
s.start();

System.out.println("(initComponent) ChatServer started on port: " + s.getPort());

ignoredFiles = utilities.createIgnoredFileList(currentProject);

connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {

// update rules in ChatServer

for (VFileEvent event : events) {
if (shouldIgnoreFile(event.getFile()))
continue;

if (event instanceof VFileCreateEvent) { // Create files
handleVFileCreateEvent(event);

} else if (event instanceof VFileContentChangeEvent) { // Text Change
handleVFileChangeEvent(event);

} else if (event instanceof VFileDeleteEvent) { // Delete files
handleVFileDeleteEvent(event);

} else if (event instanceof VFilePropertyChangeEvent) { // Property Change
handleVFilePropertyChangeEvent(event);
}
Expand All @@ -183,46 +176,55 @@ public void selectionChanged(@NotNull FileEditorManagerEvent event) {

/**
* Overridden method
* Not working
*/
public void disposeComponent() {
System.out.println("(disposeComponent)");
connection.disconnect();
try {
s.stop();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
ruleIndexText = new ArrayList<>();
tagNameText = new ArrayList<>();

Project[] AllProjects = ProjectManager.getInstance().getOpenProjects();
if (AllProjects.length == 0) {
try {
s.stop();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

@NotNull
@Override
public String getComponentName() {
System.out.println("(Component Name)");
return "";
}

// ProjectComponent

/**
* Overridden method
* Not working
*/
@Override
public void projectOpened() {
System.out.println("(project Opened)");
Project[] AllProjects = ProjectManager.getInstance().getOpenProjects();
if (AllProjects.length == 1) {
try {
WebSocketImpl.DEBUG = false;
s = new ChatServer(8887);
s.setManager(this);
s.start();
} catch (Exception e) {
System.out.println("Error in creating a Chat server.");
e.printStackTrace();
}
}
}

/**
* Overridden method
* Not working
*/
@Override
public void projectClosed() {
System.out.println("(project Closed)");
}
public void projectClosed() { }

//-------------------------------

Expand Down Expand Up @@ -665,16 +667,21 @@ JsonObject generateProjectHierarchyAsJSON() {
propertiesOfChild.addProperty("isDirectory", false);
propertiesOfChild.addProperty("fileType", childOfItem.getFileType().getName());
jsonChildOfItem.add("properties", propertiesOfChild);
PsiFile psiFile = PsiManager.getInstance(project).findFile(childOfItem);
// propertiesOfChild.addProperty("text", psiFile.getText());
// propertiesOfChild.add("ast", generateASTAsJSON(psiFile));

try {
propertiesOfChild.addProperty("fileName", psiFile.getName());
}
catch (NullPointerException e) {
// System.out.println("error! null pointer exception");
if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@Nullable
@Override
public PsiFile compute() {
return PsiManager.getInstance(project).findFile(childOfItem);
}
});
if (psiFile != null)
propertiesOfChild.addProperty("fileName", psiFile.getName());
}

// propertiesOfChild.addProperty("text", psiFile.getText());
// propertiesOfChild.add("ast", generateASTAsJSON(psiFile));
}
canonicalToJsonMap.get(item.getCanonicalPath()).get("children").getAsJsonArray().add(jsonChildOfItem);
canonicalToJsonMap.put(childOfItem.getCanonicalPath(), jsonChildOfItem);
Expand All @@ -688,9 +695,4 @@ JsonObject generateProjectHierarchyAsJSON() {

}

// static Project getProject() {
// DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
// return DataKeys.PROJECT.getData(dataContext);
// }

}

0 comments on commit c8b54be

Please sign in to comment.