{"id":21512016,"url":"https://github.com/strvcom/java-intellij-plugin-workshop","last_synced_at":"2025-03-17T15:26:03.307Z","repository":{"id":97727732,"uuid":"50177821","full_name":"strvcom/Java-IntelliJ-Plugin-Workshop","owner":"strvcom","description":null,"archived":false,"fork":false,"pushed_at":"2016-01-28T16:06:08.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-24T01:43:40.570Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/strvcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-22T11:37:40.000Z","updated_at":"2022-09-03T13:02:52.000Z","dependencies_parsed_at":"2023-04-22T14:08:24.033Z","dependency_job_id":null,"html_url":"https://github.com/strvcom/Java-IntelliJ-Plugin-Workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2FJava-IntelliJ-Plugin-Workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2FJava-IntelliJ-Plugin-Workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2FJava-IntelliJ-Plugin-Workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2FJava-IntelliJ-Plugin-Workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strvcom","download_url":"https://codeload.github.com/strvcom/Java-IntelliJ-Plugin-Workshop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056748,"owners_count":20390783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T22:25:35.782Z","updated_at":"2025-03-17T15:26:03.285Z","avatar_url":"https://github.com/strvcom.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Code Manager - STRV Developer Meetup Workshop\n============\nThis plugin was created as an example for STRV Android meetup 2016. It shows how to create kind of basic plugin for IntelliJ based IDE. \nIntroducing three most used ways of user interaction, as menu item, toolbar button and toolWindow.\n\n\nPrerequisites\n=============\nYou have to have installed IntelliJ IDEA IDE version 9.0 or later, and Java JDK, preferably version 7 or later. That should be all you need to start developing your own plugin, and running this example.\n\nYou can download IntelliJ IDEA Community edition here: [https://www.jetbrains.com/idea/download/](https://www.jetbrains.com/idea/download/)\n\n\nFunctionality\n=============\n1. Menu item for creating new example entity class.  \n   Clicking on the \"Create Entity\" menu item results in displaying two dialogs. First one for selecting location, and the second one for specifying entity class name.  \n   New entity class with some example content will be created, and user will be notified about success of this operation by message dialog afterwards.\n   \n2. Toolbar button for highlighting methods declaration lines in code.  \n   Methods declaration lines in currently opened java code get highlighted upon clicking the small red \"S\" in the toolbar. Hitting this button again will clear the highlights in currently opened file.\n\n3. ToolWindow displaying all classes and method names in currently opened file.  \n   Upon clicking on the \"Method List\" toolWindow at the right side of the editor, new tool window will be opened.  \n   This toolWindow will contain labels containing class names and method names in currently opened file. Each time the selected file in the editor is changed, the content of the toolWindow is also changed.\n\n\nImplementation\n==============\nYou can find prepared utility classes in com.strv.codemanager.utility package. These classes are providing methods for quicker and also easier implementation. Implementation of each action is described in detail.\n\n\nCreating entity class\n---------------------\n**File to edit:** CreateEntityAction.java  \n**Utility classes and methods used:**\n\n* ProjectManager\n    * createSampleEntity(Project project, File directory, String entityName)\n* DialogManager\n    * pickDirectory(Project project)\n    * showInputEntityNameDialog(Project project)\n    * showMessageDialog(Project project)\n\nWe are going to edit **actionPerformed** method.\u003cbr\u003e\nFirst we need to obtain Project instance from action event:\u003cbr\u003e\n```\nProject project = anActionEvent.getProject();\nif (project == null)\n    return;\n```\n\nWe are going to need directory path for storing generated file:\u003cbr\u003e\n```\nFile file = DialogManager.pickDirectory(project);\nif (file == null)\n    return;\n```\n\nAnd the name of the generated file:\u003cbr\u003e\n```\nString fileName = DialogManager.showInputEntityNameDialog(project);\nif (fileName == null)\n    return;\n```\n\nWith these information we can just call **createSampleEntity** method, and based on return value let user know if the creation was successful:\u003cbr\u003e\n```\nif (ProjectManager.createSampleEntity(project, file, fileName))\n    DialogManager.showMessageDialog(project, \"File created successfully!\");\nelse\n    DialogManager.showMessageDialog(project, \"File creation failed!\");\n```\n\n\nText highlighting\n-----------------\n**File to edit:** HighlightAction.java  \n**Utility classes and methods used:**\n\n* UIManager\n    * clearAllHighlights(Editor editor)\n    * highlightAllMethods(Editor editor, Project project)\n\nWe are going to edit **actionPerformed** method.\u003cbr\u003e\nThis time, we do not only need project, but we need editor instance also. Lets get them from action event again:\u003cbr\u003e\n```\nEditor editor = anActionEvent.getData(LangDataKeys.EDITOR);\nProject project = anActionEvent.getProject();\nif (editor == null || project == null)\n    return;\n```\n\nWe will clear or highlight all methods declaration starting lines based on the count of highlighters in current file:\u003cbr\u003e\n```\nif (editor.getMarkupModel().getAllHighlighters().length \u003e 0)\n    UIManager.clearAllHighlights(editor);\nelse\n    UIManager.highlightAllMethods(editor, project);\n```\n\n\nMethods list\n------------\n**File to edit:** MainToolWindow.java  \n**Utility classes and methods used:**\n\n* ProjectManager\n    * getClassEntityList(Project project)\n* UIManager\n    * initUI(ToolWindow toolWindow)\n    * addClassLabel(JPanel panel, String text)\n    * addMethodLabel(JPanel panel, String text)\n\n\nWe are going to edit **editorSelectionChanged** method.\u003cbr\u003e\nThis time we going to need some kind of panel for storing UI elements. Lets create one and initialize it using prepared **initUI** method:\u003cbr\u003e\n```\nJPanel panel = UIManager.initUI(toolWindow);\n```\n\nTo be able to display list of classes and methods, we first need to obtain it. So lets create list of **ClassEntity**, which contains class name and method list. We can than fill this list using prepared **getClassEntityList** method.\u003cbr\u003e\n```\nList\u003cClassEntity\u003e classList = ProjectManager.getClassEntityList(project);\n```\n\nAll wee need to do now is to iterate through the **ClassEntity** list and print the class label using **addClassLabel** method, and then go through all methods inside the ClassEntity, We can print them using **addMethodLabel** method.\u003cbr\u003e\n```\nfor (ClassEntity entity : classList) {\n    UIManager.addClassLabel(panel, entity.getName());\n\n    for (String method : entity.getMethodList()) {\n        UIManager.addMethodLabel(panel, method);\n    }\n}\n```\n\n\nBuilding project\n================\nYou don't need to install Gradle on your system, because there is a [Gradle Wrapper](http://www.gradle.org/docs/current/userguide/gradle_wrapper.html). The wrapper is a batch script on Windows, and a shell script for other operating systems. When you start a Gradle build via the wrapper, Gradle will be automatically downloaded and used to run the build.\n\n1. Clone this repository\n2. Run `gradlew buildPlugin` in console\n3. ZIP file should be available in project root directory\n\nYou can also test plugin implementation by launching new instance of IntelliJ IDEA with plugin installed, using `gradlew runPlugin`.\n\n\nDeveloped by\n============\n* Lukáš Hermann ([lukas.hermann@strv.com](lukas.hermann@strv.com))\n* STRV ([http://www.strv.com](http://www.strv.com))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrvcom%2Fjava-intellij-plugin-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrvcom%2Fjava-intellij-plugin-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrvcom%2Fjava-intellij-plugin-workshop/lists"}