├── LICENSE ├── META-INF └── plugin.xml ├── README.md ├── doc └── img │ ├── AS-create-project.jpg │ ├── AS-use-minsdk-15.jpg │ ├── ASMP-install-plugin.jpg │ ├── ASMP-restart-IDE.jpg │ ├── R2M-download-release.jpg │ ├── R2M-download.jpg │ ├── R2M-generated-classes.jpg │ ├── R2M-install-plugin.jpg │ ├── R2M-installer-file.jpg │ ├── R2M-menu.jpg │ ├── R2M-restart-IDE.jpg │ └── R2M-wizard-description.jpg ├── lib ├── commons-validator-1.4.0.jar ├── gson-2.3.jar └── magnet-tools-cli-simple-1.1.0.jar ├── module_r2m-plugin-android.xml ├── r2m-plugin-android.properties ├── r2m-plugin-android.xml ├── res └── r2m │ ├── check_icon.png │ ├── check_icon@2x.png │ ├── error_icon.png │ ├── error_icon@2x.png │ ├── icon_logo.png │ ├── icon_logo@2x.png │ ├── icon_logo@4x.png │ ├── minus_button.png │ ├── minus_button@2x.png │ ├── minus_button_pressed.png │ ├── minus_button_pressed@2x.png │ ├── plus_button.png │ ├── plus_button@2x.png │ ├── plus_button_pressed.png │ ├── plus_button_pressed@2x.png │ ├── r2m.properties │ ├── warning_icon.png │ └── warning_icon@2x.png ├── src └── com │ └── magnet │ └── plugin │ ├── common │ ├── CommonConstants.java │ ├── FormattedLogger.java │ ├── Logger.java │ ├── helpers │ │ ├── URLHelper.java │ │ └── VerifyHelper.java │ └── ui │ │ ├── HintHelper.java │ │ ├── HintPasswordTextField.java │ │ └── HintTextField.java │ └── r2m │ ├── actions │ ├── AboutAction.java │ ├── AddRestApi.java │ ├── CheckUpdatesAction.java │ └── HelpAction.java │ ├── api │ ├── core │ │ └── RequestFactory.java │ ├── mock │ │ ├── Worker.java │ │ └── WorkerCallback.java │ ├── models │ │ ├── ApiMethodModel.java │ │ ├── Error.java │ │ ├── RequestHeaderModel.java │ │ ├── RequestModel.java │ │ └── ResponseModel.java │ └── requests │ │ ├── DeleteRequest.java │ │ ├── GetRequest.java │ │ ├── PostRequest.java │ │ ├── PutRequest.java │ │ └── abs │ │ ├── AbstractRequest.java │ │ └── BaseRequest.java │ ├── components │ ├── ControllerHistoryComponent.java │ └── HistoryComponent.java │ ├── constants │ ├── Colors.java │ ├── FormConfig.java │ ├── GenerateActions.java │ ├── JSONErrorType.java │ └── PluginIcon.java │ ├── generator │ └── Generator.java │ ├── helpers │ ├── AsyncHelper.java │ ├── ContentTypeHelper.java │ ├── ControllerHistoryManager.java │ ├── FileHelper.java │ ├── FormatHelper.java │ ├── HighlightHelper.java │ ├── HistoryHelper.java │ ├── IOUtils.java │ ├── JSONValidator.java │ ├── JsonErrorConverter.java │ ├── ProjectHelper.java │ ├── R2MConstants.java │ ├── R2MVerifyHelper.java │ ├── ResponseHelper.java │ ├── RestByExampleKeywords.java │ ├── UIHelper.java │ └── UrlParser.java │ ├── listeners │ ├── ControllerActionCallback.java │ ├── CreateMethodCallback.java │ ├── TabRemoveListener.java │ ├── URLFocusListener.java │ └── generator │ │ ├── PostGenerateCallback.java │ │ └── ProgressGenerateCallback.java │ ├── messages │ ├── MessagesSupport.java │ └── R2MMessages.java │ ├── models │ ├── ControllerHistory.java │ ├── ExampleResource.java │ ├── ExamplesManifest.java │ ├── History.java │ ├── JSONError.java │ ├── Method.java │ ├── ParsedUrl.java │ ├── PathPart.java │ └── Query.java │ ├── project │ ├── CacheManager.java │ └── ProjectManager.java │ ├── singletons │ └── Application.java │ └── ui │ ├── AbstractDocumentListener.java │ ├── AddControllerForm.form │ ├── AddControllerForm.java │ ├── ControllerNameBoxItemListener.java │ ├── chooser │ └── ExampleChooserHelper.java │ └── tab │ ├── BasePanel.java │ ├── BaseUrlCallBack.java │ ├── ButtonsSection.java │ ├── ExtendedJPanel.java │ ├── HeaderPanel.java │ ├── HeaderPanelLabel.java │ ├── HeaderSection.java │ ├── MethodNameSection.java │ ├── MethodTabPanel.java │ ├── MethodTypeSection.java │ ├── PathPartLabel.java │ ├── PathPartPanel.java │ ├── PayloadPanel.java │ ├── QueryPanel.java │ ├── QueryPanelLabel.java │ ├── RequestPayloadSection.java │ ├── ResponsePayloadSection.java │ ├── TabManager.java │ └── URLSection.java └── version.properties /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | com.magnet.r2m 20 | Magnet rest2mobile 21 | 1.1.12 22 | Magnet 23 | 29 |
  • Connecting to the server
  • 30 |
  • Building the REST URL and HTTP headers
  • 31 |
  • Marshaling and un-marshaling JSON data
  • 32 |
  • Converting JSON data to type safe objects
  • 33 | 34 | The Magnet rest2mobile Android Studio and Intellij Plugin turns REST services into Java components that you can call from your mobile app. The components are native classes and interfaces that automatically handle server connections and type safety. 35 | ]]>
    36 | 37 | 38 | Changes in 1.1.12 40 |
    - fix for https://github.com/magnetsystems/r2m-plugin-android/issues/31 41 |

    Changes in 1.1.11 42 |
    - fix for https://github.com/magnetsystems/r2m-plugin-android/issues/29 43 |

    Changes in 1.1.10 44 |
    - bring "close Add rest api" window to the front. 45 |

    Changes in 1.1.9 46 |
    - UI cosmetics 47 |
    - lazily create .rest2mobile 48 |
    - fixed https://github.com/magnetsystems/r2m-plugin-android/issues/23 49 |
    - fixed https://github.com/magnetsystems/r2m-plugin-android/issues/22 50 |
    - fixed https://github.com/magnetsystems/r2m-plugin-android/issues/4 51 |

    Changes in 1.1.8 52 |
    - Fix https://github.com/magnetsystems/r2m-plugin-android/issues/26 53 |

    Changes in 1.1.7 54 |
    - Fix https://github.com/magnetsystems/r2m-plugin-android/issues/27 55 |

    Changes in 1.1.6 56 |
    - Fix https://github.com/magnetsystems/r2m-sdk-android/issues/5 57 |

    Changes in 1.1.5 58 |
    - Fix https://github.com/magnetsystems/r2m-sdk-android/issues/4 59 |

    Changes from 1.1.0 60 |
    - Automatically show generated controller class after generation 61 |
    - Show gradle snippet explaining how to include R2M dependencies 62 |
    - Fix URL encoding issue 63 |
    - Fix NPE in URLSection 64 | ]]> 65 | 66 | 67 | 68 | 69 | 70 | 72 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | com.magnet.plugin.r2m.components.HistoryComponent 84 | 85 | 86 | com.magnet.plugin.r2m.components.ControllerHistoryComponent 87 | 88 | 89 | 90 | 91 | 92 | 95 | 100 | 104 | 108 | 112 | 113 | 114 | 115 | 118 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /doc/img/AS-create-project.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/AS-create-project.jpg -------------------------------------------------------------------------------- /doc/img/AS-use-minsdk-15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/AS-use-minsdk-15.jpg -------------------------------------------------------------------------------- /doc/img/ASMP-install-plugin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/ASMP-install-plugin.jpg -------------------------------------------------------------------------------- /doc/img/ASMP-restart-IDE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/ASMP-restart-IDE.jpg -------------------------------------------------------------------------------- /doc/img/R2M-download-release.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-download-release.jpg -------------------------------------------------------------------------------- /doc/img/R2M-download.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-download.jpg -------------------------------------------------------------------------------- /doc/img/R2M-generated-classes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-generated-classes.jpg -------------------------------------------------------------------------------- /doc/img/R2M-install-plugin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-install-plugin.jpg -------------------------------------------------------------------------------- /doc/img/R2M-installer-file.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-installer-file.jpg -------------------------------------------------------------------------------- /doc/img/R2M-menu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-menu.jpg -------------------------------------------------------------------------------- /doc/img/R2M-restart-IDE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-restart-IDE.jpg -------------------------------------------------------------------------------- /doc/img/R2M-wizard-description.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/doc/img/R2M-wizard-description.jpg -------------------------------------------------------------------------------- /lib/commons-validator-1.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/lib/commons-validator-1.4.0.jar -------------------------------------------------------------------------------- /lib/gson-2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/lib/gson-2.3.jar -------------------------------------------------------------------------------- /lib/magnet-tools-cli-simple-1.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/lib/magnet-tools-cli-simple-1.1.0.jar -------------------------------------------------------------------------------- /module_r2m-plugin-android.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /r2m-plugin-android.properties: -------------------------------------------------------------------------------- 1 | path.variable.maven_repository=/Users/etexier/.m2/repository 2 | jdk.home.idea_ic-139.1117.1=/Applications/IntelliJ IDEA 14 CE.app/Contents 3 | idea.home=/Applications/IntelliJ IDEA 14 CE.app/Contents 4 | javac2.instrumentation.includeJavaRuntime=false 5 | java.home=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 6 | 7 | -------------------------------------------------------------------------------- /res/r2m/check_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/check_icon.png -------------------------------------------------------------------------------- /res/r2m/check_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/check_icon@2x.png -------------------------------------------------------------------------------- /res/r2m/error_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/error_icon.png -------------------------------------------------------------------------------- /res/r2m/error_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/error_icon@2x.png -------------------------------------------------------------------------------- /res/r2m/icon_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/icon_logo.png -------------------------------------------------------------------------------- /res/r2m/icon_logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/icon_logo@2x.png -------------------------------------------------------------------------------- /res/r2m/icon_logo@4x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/icon_logo@4x.png -------------------------------------------------------------------------------- /res/r2m/minus_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/minus_button.png -------------------------------------------------------------------------------- /res/r2m/minus_button@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/minus_button@2x.png -------------------------------------------------------------------------------- /res/r2m/minus_button_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/minus_button_pressed.png -------------------------------------------------------------------------------- /res/r2m/minus_button_pressed@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/minus_button_pressed@2x.png -------------------------------------------------------------------------------- /res/r2m/plus_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/plus_button.png -------------------------------------------------------------------------------- /res/r2m/plus_button@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/plus_button@2x.png -------------------------------------------------------------------------------- /res/r2m/plus_button_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/plus_button_pressed.png -------------------------------------------------------------------------------- /res/r2m/plus_button_pressed@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/plus_button_pressed@2x.png -------------------------------------------------------------------------------- /res/r2m/r2m.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014 Magnet Systems, Inc. 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you 6 | # may not use this file except in compliance with the License. You 7 | # may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | # implied. See the License for the specific language governing 15 | # permissions and limitations under the License. 16 | # 17 | 18 | WINDOW_TITLE=API Designer 19 | TEST_API_BEFORE_SAVE_METHOD=Please "Test API" before "Save Method". 20 | EMPTY_METHOD_NAME="Method Name" is empty. 21 | METHOD_NAME_TOOL_TIP=Enter the name of the method to be generated for this REST call 22 | EXPAND_URL_CHECKBOX_TOOL_TIP=Expand to edit URL through URL form wizard and specify path and query params 23 | URL_FIELD_TOOL_TIP=To directly edit URL here, collapse URL form wizard 24 | PROVIDE_VALID_URL=Please provide a valid URL for method {0}: {1} 25 | CANNOT_PARSE_URL=Can''t parse URL {0} 26 | ERROR_REQUEST=Request not successful. Change parameters and try again. 27 | EMPTY_CLASS_NAME="Class Name" is empty. 28 | EMPTY_PACKAGE_NAME="Package Name" is empty. 29 | REQUIRED_FIELD=Required field 30 | MUST_FILL_ALL_REQUIRED_FIELDS=You should fill all required fields. 31 | PLUS_TAB=+ 32 | METHOD_N=Method {0} 33 | SERVICE_WAS_GENERATED=Service was generated 34 | SOURCE_AVAILABLE_CONTINUE_EDITING_QUESTION=Class {0} successfully generated in:\n{1}\n\nDo you want to close the REST API wizard to look at the code? 35 | CLOSE_AND_SHOW_CODE_BUTTON_TEXT=Close 36 | CONTINUE_EDITING_BUTTON_TEXT=Continue Designing API 37 | UPDATES_WINDOW_TITLE=Updates Info 38 | NO_UPDATES_AVAILABLE=No new update available:\nInstalled Version: {0}\nLatest Version: {1} 39 | UPDATES_AVAILABLE=New updates available!\nLatest Version: {1} (current: {0})\n\nDescription:\n{3}\n{4}\n\nDownload plugin at: {2} 40 | NAME_CONFLICTS_WITH_JAVA_KEYWORDS=Invalid value: it cannot be a Java keyword. 41 | ERROR_NULL_VALUE_TEXT=Values must not be null. Specify a value, or remove the entry to exclude it from the generated model. 42 | ERROR_EMPTY_ARRAY_TEXT=Arrays must not be empty. Specify a valid list, or delete the entry to exclude it from the generated model. 43 | ERROR_EMPTY_DICTIONARY_TEXT=Associative arrays must not be empty. Specify a valid object, or delete the entry to exclude it from the generated model. 44 | ERROR_MISSING_COMMA_TEXT=Missing comma 45 | ERROR_MISSING_QUOTES_TEXT=Mising quotes error 46 | ERROR_INVALID_FORMAT=Invalid json format 47 | VALIDATION_WARNING_MESSAGE=The json payload seems incomplete. It''s recommended to set proper value for them to generate complete data type otherwise those properties will be ignored. 48 | VALIDATION_WARNING_TITLE=Incomplete Json Payload For Method {0} 49 | VALIDATION_WARNING_QUESTION=The json payload of method {0} is incomplete. Continue the generation by ignoring the following properties or fix the issues first and then try to generate again. 50 | VALIDATION_WARNING_CONTINUE=Continue generation anyway 51 | VALIDATION_WARNING_CANCEL=Let me fix them 52 | HEADER_SECTION_NAME=Header 53 | SECTION_ADD_NEW=Add new 54 | SECTION_PLUS=+ 55 | SECTION_DELETE=X 56 | 57 | QUERY_SECTION_NAME=Query 58 | 59 | PATH_SECTION_NAME=Path 60 | 61 | BASE_URL_SECTION_NAME=Base URL 62 | 63 | PATH_VARIABLE_NAME=Variable Name 64 | PATH_VARIABLE_CHECKBOX_NAME=Variable? 65 | VARIABLE_CHECKBOX_TOOL_TIP=Check this to indicate that you want the path to be exposed as a path param 66 | VARIABLE_NAME_TEXT_FIELD_TOOL_TIP=Choose a name for the method parameter corresponding to the path param 67 | PATH_PART_NAME=Path 68 | METHOD_NAME_LABEL_TEXT=Method Name 69 | URL_LABEL_TEXT=URL 70 | 71 | CHOOSE_EXAMPLE_LABEL=Enter a URL, path, or Github example 72 | CHOOSE_EXAMPLE_TITLE=Choose a REST example 73 | CHOOSE_EXAMPLE_DEFAULT_VALUE=GoogleDistance 74 | TEST_API_TOOL_TIP=Click here to pre-populate the response, or simply copy-paste it, if you're offline or do not have the right credentials 75 | PAYLOAD_TOOL_TIP=Copy-paste payload here.If it is JSON, you can optionally remove any paragraphs you don''t care about 76 | GENERATE_TOOL_TIP=Generate class for your REST service 77 | REMOVE_METHOD_TOOL_TIP=Clear or remove the current method 78 | TEST_API_TEXT=Test API 79 | REMOVE_METHOD_TEXT=Remove method 80 | LATEST_TEST_CLASS_HEADER=/* AUTO-GENERATED FILE. DO NOT MODIFY.\n \ 81 | *\n \ 82 | * This class was automatically generated by the\n \ 83 | * rest2mobile plugin because {0} already exists. You\n \ 84 | * can merge the code below into {0} manually.\n \ 85 | */\n 86 | CONFIRM_OVERRIDE_FILES=Please, confirm: this will override these existing files: {0} 87 | CONFIRM_OVERRIDE_FILES_TITLE=Override Files 88 | CONFIRM_OVERRIDE_FILES_BUTTON_TEXT=Override 89 | SUCCESS=Success 90 | ERROR_TESTING_API=Couldn''t test the API. Check your request parameters and network connection. {0}\n\ 91 | (copy-paste the expected response , if you can''t auto-generate it) 92 | 93 | -------------------------------------------------------------------------------- /res/r2m/warning_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/warning_icon.png -------------------------------------------------------------------------------- /res/r2m/warning_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/da1e507039127c703062cd3f44a51b22aba660a0/res/r2m/warning_icon@2x.png -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/CommonConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.common; 18 | 19 | public class CommonConstants { 20 | public static final String LOGGER_TAG = "MagnetPlugin"; 21 | } 22 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/FormattedLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.common; 19 | 20 | import com.magnet.plugin.common.Logger; 21 | 22 | /** 23 | * Logger for debugging 24 | */ 25 | public class FormattedLogger { 26 | private StringBuilder message; 27 | private Class aClass; 28 | private static final String CLASS_DIVIDER = " : "; 29 | private static final String ACTION_DIVIDER = " -> "; 30 | 31 | public FormattedLogger(Class aClass) { 32 | message = new StringBuilder(); 33 | this.aClass = aClass; 34 | append(this.aClass.getSimpleName(), CLASS_DIVIDER); 35 | } 36 | 37 | public void append(String... strings) { 38 | for (String s : strings) { 39 | message.append(s); 40 | } 41 | } 42 | 43 | public void appendAction(String strings) { 44 | append(strings, ACTION_DIVIDER); 45 | } 46 | 47 | public void appendAction(String... strings) { 48 | for (String s : strings) { 49 | append(s, ACTION_DIVIDER); 50 | } 51 | } 52 | 53 | public void clearMessage() { 54 | message = new StringBuilder(); 55 | append(this.aClass.getSimpleName(), CLASS_DIVIDER); 56 | } 57 | 58 | public void showInfoLog() { 59 | Logger.showLogInfo(message.toString()); 60 | } 61 | 62 | public void showErrorLog() { 63 | Logger.showLogError(message.toString()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/Logger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.common; 19 | 20 | import com.intellij.notification.Notification; 21 | import com.intellij.notification.NotificationType; 22 | import com.intellij.notification.Notifications; 23 | 24 | public class Logger { 25 | 26 | 27 | public static void info(String message) { 28 | sendNotification(message, "Information", NotificationType.INFORMATION); 29 | } 30 | 31 | public static void error(String message) { 32 | sendNotification(message, "Error", NotificationType.ERROR); 33 | } 34 | 35 | public static void info(Class cls, String message) { 36 | sendNotification(message, cls.getSimpleName(), NotificationType.INFORMATION); 37 | } 38 | 39 | public static void error(Class cls, String message) { 40 | sendNotification(message, cls.getSimpleName(), NotificationType.ERROR); 41 | } 42 | 43 | private static void sendNotification(String message, String tag, NotificationType notificationType) { 44 | if (null == message || message.isEmpty()) { // to prevent Assertion error 45 | return; 46 | } 47 | Notification notification = new Notification(CommonConstants.LOGGER_TAG, tag, escapeString(message), notificationType); 48 | Notifications.Bus.notify(notification); 49 | } 50 | 51 | private static String escapeString(String string) { 52 | // replace with both so that it returns are preserved in the notification balloon and in the event log 53 | return string.replaceAll("\n", "\n
    "); 54 | } 55 | 56 | /** 57 | * Method which provide to show info log only in debug 58 | * 59 | * @param message message 60 | */ 61 | public static void showLogInfo(String message) { 62 | System.out.println("=====> " + message); 63 | } 64 | 65 | /** 66 | * Method which provide to show error log only in debug 67 | * 68 | * @param message message 69 | */ 70 | public static void showLogError(String message) { 71 | System.err.println("=====> " + message); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/helpers/VerifyHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.common.helpers; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | /** 25 | * validation helpers 26 | */ 27 | public class VerifyHelper { 28 | 29 | public static final List KEYWORDS = new ArrayList( 30 | Arrays.asList(new String[]{ 31 | "abstract", "assert", "boolean", "break", "byte", 32 | "case", "catch", "char", "class", "const", 33 | "continue", "default", "do", "double", "else", 34 | "enum", "extends", "final", "finally", "float", 35 | "for", "goto", "if", "implements", "import", "instanceof", 36 | "int", "interface", "long", "native", "new", "package", "private", 37 | "protected", "public", "return", "short", "static", "strictfp", 38 | "super", "switch", "synchronized", "this", "throw", "throws", 39 | "transient", "try", "void", "volatile", "while" 40 | }) 41 | ); 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/ui/HintHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.common.ui; 18 | 19 | import com.intellij.ui.JBColor; 20 | 21 | import javax.swing.*; 22 | import java.awt.*; 23 | 24 | /** 25 | * Support for rendering hint in text field 26 | */ 27 | public class HintHelper { 28 | public static void paint(Graphics g, JTextField f, String hint) { 29 | if (f.getText().length() != 0) { 30 | return; 31 | } 32 | int h = f.getHeight(); 33 | ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 34 | Insets ins = f.getInsets(); 35 | FontMetrics fm = g.getFontMetrics(); 36 | int c0 = f.getBackground().getRGB(); 37 | int c1 = f.getForeground().getRGB(); 38 | int m = 0xfefefefe; 39 | int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1); 40 | g.setColor(new JBColor(new Color(c2, true), new Color(c2, true))); 41 | g.drawString(hint, ins.left, h / 2 + fm.getAscent() / 2 - 2); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/ui/HintPasswordTextField.java: -------------------------------------------------------------------------------- 1 | package com.magnet.plugin.common.ui; 2 | 3 | 4 | import com.magnet.plugin.common.ui.HintHelper; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | /** 10 | * password with hint 11 | */ 12 | public class HintPasswordTextField extends JPasswordField { 13 | private final String hint; 14 | 15 | public HintPasswordTextField(String hint) { 16 | this.hint = hint; 17 | } 18 | @Override 19 | public void paint(Graphics g) { 20 | super.paint(g); 21 | HintHelper.paint(g, this, hint); 22 | } 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/common/ui/HintTextField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.common.ui; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | 22 | /** 23 | * text field with hint 24 | */ 25 | public class HintTextField extends JTextField { 26 | private String hint; 27 | 28 | public HintTextField(String hint) { 29 | this.hint = hint; 30 | } 31 | @Override 32 | public void paint(Graphics g) { 33 | super.paint(g); 34 | HintHelper.paint(g, this, hint); 35 | } 36 | 37 | public void setHint(String hint) { 38 | this.hint = hint; 39 | this.repaint(); 40 | } 41 | 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/actions/AboutAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.actions; 19 | 20 | import com.intellij.ide.plugins.PluginManager; 21 | import com.intellij.openapi.actionSystem.AnAction; 22 | import com.intellij.openapi.actionSystem.AnActionEvent; 23 | import com.intellij.openapi.actionSystem.CommonDataKeys; 24 | import com.intellij.openapi.extensions.PluginId; 25 | import com.intellij.openapi.project.Project; 26 | import com.intellij.openapi.ui.popup.JBPopupFactory; 27 | import com.intellij.openapi.util.IconLoader; 28 | import com.intellij.openapi.wm.WindowManager; 29 | import com.intellij.ui.awt.RelativePoint; 30 | import com.magnet.plugin.r2m.helpers.R2MConstants; 31 | 32 | import javax.swing.*; 33 | import java.awt.*; 34 | 35 | /** 36 | * Action for "About" menu item 37 | */ 38 | public class AboutAction extends AnAction { 39 | 40 | public void actionPerformed(AnActionEvent e) { 41 | Project project = e.getData(CommonDataKeys.PROJECT); 42 | showAboutMessage(project); 43 | } 44 | 45 | private static void showAboutMessage(Project project) { 46 | 47 | Window window = WindowManager.getInstance().suggestParentWindow(project); 48 | JPanel panel = new JPanel(new BorderLayout()); 49 | panel.setPreferredSize(new Dimension(200, 200)); 50 | 51 | // image 52 | Icon image = IconLoader.getIcon("/r2m/icon_logo@4x.png"); 53 | panel.add(new JLabel(image), BorderLayout.CENTER); 54 | 55 | // coordinate 56 | RelativePoint location; 57 | if (window != null) { 58 | Rectangle r = window.getBounds(); 59 | location = new RelativePoint(window, new Point((r.width - image.getIconWidth()) / 2, (r.height - image.getIconHeight()) / 2)); 60 | } 61 | else { 62 | Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds(); 63 | location = new RelativePoint(new Point((r.width - image.getIconWidth()) / 2, (r.height - image.getIconHeight()) / 2)); 64 | } 65 | 66 | String version = PluginManager.getPlugin(PluginId.getId(R2MConstants.PUBLIC_TOOL_PACKAGE)).getVersion(); 67 | String text = R2MConstants.PUBLIC_TOOL_NAME + " " + version + " " + "(" + R2MConstants.MAGNET_DEVELOPER_URL+ ")"; 68 | 69 | // popup 70 | JBPopupFactory.getInstance().createComponentPopupBuilder(panel, panel) 71 | .setRequestFocus(true) 72 | .setFocusable(true) 73 | .setResizable(false) 74 | .setMovable(false) 75 | .setModalContext(false) 76 | .setShowShadow(true) 77 | // .setShowBorder(false) 78 | .setCancelKeyEnabled(true) 79 | .setCancelOnClickOutside(true) 80 | .setCancelOnOtherWindowOpen(true) 81 | .setAdText(text) 82 | .createPopup() 83 | .show(location); 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/actions/AddRestApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.actions; 19 | 20 | import com.intellij.openapi.actionSystem.AnAction; 21 | import com.intellij.openapi.actionSystem.AnActionEvent; 22 | import com.magnet.plugin.r2m.helpers.UIHelper; 23 | 24 | /** 25 | * Action for "Add REST API" menu item 26 | */ 27 | public class AddRestApi extends AnAction { 28 | 29 | public void actionPerformed(AnActionEvent e) { 30 | UIHelper.openAPIDialog(e.getProject(), e); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/actions/CheckUpdatesAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.actions; 19 | 20 | import com.intellij.ide.plugins.PluginManager; 21 | import com.intellij.openapi.actionSystem.AnAction; 22 | import com.intellij.openapi.actionSystem.AnActionEvent; 23 | import com.intellij.openapi.actionSystem.CommonDataKeys; 24 | import com.intellij.openapi.extensions.PluginId; 25 | import com.intellij.openapi.project.Project; 26 | import com.intellij.openapi.ui.Messages; 27 | import com.intellij.util.text.VersionComparatorUtil; 28 | import com.magnet.plugin.common.Logger; 29 | import com.magnet.plugin.r2m.helpers.R2MConstants; 30 | import com.magnet.plugin.r2m.helpers.UIHelper; 31 | import com.magnet.plugin.common.helpers.URLHelper; 32 | import com.magnet.plugin.r2m.messages.R2MMessages; 33 | 34 | import java.io.IOException; 35 | import java.io.InputStream; 36 | import java.util.Properties; 37 | 38 | /** 39 | * Action for "Check Updates" menu 40 | */ 41 | public class CheckUpdatesAction extends AnAction { 42 | 43 | public void actionPerformed(AnActionEvent e) { 44 | 45 | Properties updatesInfo = new Properties(); 46 | InputStream infoStream = null; 47 | 48 | String url = R2MConstants.PUBLIC_VERSION_URL; 49 | try { 50 | infoStream = URLHelper.loadUrl(url); 51 | updatesInfo.load(infoStream); 52 | } catch (Exception ex) { 53 | UIHelper.showErrorMessage("Couldn't access version URL: " + R2MConstants.PUBLIC_VERSION_URL); 54 | Logger.error(CheckUpdatesAction.class, ex.getMessage()); 55 | return; 56 | } finally { 57 | if (infoStream != null) { 58 | try { 59 | infoStream.close(); 60 | } catch (IOException e1) { 61 | // ignore 62 | } 63 | } 64 | } 65 | 66 | String latestVersion = updatesInfo.getProperty(R2MConstants.LATEST_VERSION_KEY); 67 | String installedVersion = getInstalledVersion(); 68 | 69 | Project project = e.getData(CommonDataKeys.PROJECT); 70 | if (VersionComparatorUtil.compare(installedVersion, latestVersion) >= 0) { 71 | showNoUpdateDialog(project, installedVersion, updatesInfo); 72 | return; 73 | } 74 | 75 | showUpdatesAvailableDialog(project, installedVersion, updatesInfo); 76 | 77 | } 78 | 79 | private static String getInstalledVersion() { 80 | return PluginManager.getPlugin(PluginId.getId(R2MConstants.PUBLIC_TOOL_PACKAGE)).getVersion(); 81 | } 82 | 83 | private static void showUpdatesAvailableDialog(Project project, String installedVersion, Properties info) { 84 | String newVersion = info.getProperty(R2MConstants.LATEST_VERSION_KEY); 85 | String url = info.getProperty(R2MConstants.DOWNLOAD_URL_KEY); 86 | String description = info.getProperty(R2MConstants.DESCRIPTION_KEY); 87 | String comments = info.getProperty(R2MConstants.COMMENTS_KEY); 88 | Messages.showInfoMessage(project, 89 | R2MMessages.getMessage("UPDATES_AVAILABLE", installedVersion, newVersion, url, description, comments), 90 | R2MMessages.getMessage("UPDATES_WINDOW_TITLE")); 91 | } 92 | 93 | private static void showNoUpdateDialog(Project project, String installedVersion, Properties info) { 94 | String newVersion = info.getProperty(R2MConstants.LATEST_VERSION_KEY); 95 | Messages.showInfoMessage(project, 96 | R2MMessages.getMessage("NO_UPDATES_AVAILABLE", installedVersion, newVersion), 97 | R2MMessages.getMessage("UPDATES_WINDOW_TITLE")); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/actions/HelpAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.actions; 19 | 20 | import com.intellij.ide.BrowserUtil; 21 | import com.intellij.openapi.actionSystem.AnAction; 22 | import com.intellij.openapi.actionSystem.AnActionEvent; 23 | import com.magnet.plugin.r2m.helpers.R2MConstants; 24 | 25 | /** 26 | * Action for "Help" menu item 27 | */ 28 | public class HelpAction extends AnAction { 29 | 30 | public void actionPerformed(AnActionEvent e) { 31 | BrowserUtil.browse(R2MConstants.DOCUMENTATION_URL); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/core/RequestFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.core; 19 | 20 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 21 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 22 | import com.magnet.plugin.r2m.api.models.RequestModel; 23 | import com.magnet.plugin.r2m.api.requests.DeleteRequest; 24 | import com.magnet.plugin.r2m.api.requests.GetRequest; 25 | import com.magnet.plugin.r2m.api.requests.PostRequest; 26 | import com.magnet.plugin.r2m.api.requests.PutRequest; 27 | import com.magnet.plugin.r2m.api.requests.abs.BaseRequest; 28 | 29 | /** 30 | * Factory for each URL request of type POST, GET, DELETE, PUT 31 | */ 32 | public class RequestFactory { 33 | 34 | public RequestFactory() { 35 | super(); 36 | } 37 | 38 | public static BaseRequest getRequestForMethod(WorkerCallback callback, RequestModel model) { 39 | BaseRequest request = null; 40 | switch (model.getHttpMethod()) { 41 | case POST: 42 | request = new PostRequest(callback, model); 43 | break; 44 | case GET: 45 | request = new GetRequest(callback, model); 46 | break; 47 | case DELETE: 48 | request = new DeleteRequest(callback, model); 49 | break; 50 | case PUT: 51 | request = new PutRequest(callback, model); 52 | break; 53 | default: 54 | break; 55 | } 56 | return request; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/mock/Worker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.mock; 19 | 20 | 21 | public interface Worker { 22 | 23 | void doWork() throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/mock/WorkerCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.mock; 19 | 20 | 21 | public interface WorkerCallback { 22 | 23 | public void onSuccess(T t); 24 | 25 | public void onError(Exception e); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/models/ApiMethodModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.models; 19 | 20 | import org.apache.http.Header; 21 | import org.apache.http.HttpResponse; 22 | 23 | /** 24 | * Represent a Rest By Example model 25 | */ 26 | public class ApiMethodModel { 27 | 28 | 29 | /** the request model */ 30 | private RequestModel requestModel; 31 | /** the response model */ 32 | private ResponseModel responseModel; 33 | 34 | /** a http response from a live test */ 35 | private HttpResponse httpResponse; 36 | /** the request headers */ 37 | private Header[] requestHeaders; 38 | 39 | /** the response body */ 40 | private String responseBody; 41 | 42 | /** 43 | * @return live test http response 44 | */ 45 | public HttpResponse getHttpResponse() { 46 | return httpResponse; 47 | } 48 | 49 | /** 50 | * set live test http response 51 | * @param httpResponse http response 52 | */ 53 | public void setHttpResponse(HttpResponse httpResponse) { 54 | this.httpResponse = httpResponse; 55 | } 56 | 57 | /** 58 | * @return request headers 59 | */ 60 | public Header[] getRequestHeaders() { 61 | return requestHeaders; 62 | } 63 | 64 | /** 65 | * set actual request headers 66 | * @param requestHeaders request headers 67 | */ 68 | public void setRequestHeaders(Header[] requestHeaders) { 69 | this.requestHeaders = requestHeaders; 70 | } 71 | 72 | /** 73 | * @return request model 74 | */ 75 | public RequestModel getRequestModel() { 76 | return requestModel; 77 | } 78 | 79 | /** 80 | * The request model 81 | * @param model model 82 | */ 83 | public void setRequestModel(RequestModel model) { 84 | this.requestModel = model; 85 | } 86 | 87 | /** 88 | * @return method response model 89 | */ 90 | public ResponseModel getResponseModel() { 91 | return responseModel; 92 | } 93 | 94 | /** 95 | * Set response model 96 | * @param responseModel response model 97 | */ 98 | public void setResponseModel(ResponseModel responseModel) { 99 | this.responseModel = responseModel; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/models/Error.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.models; 19 | 20 | /** 21 | * Bean representing an error message 22 | */ 23 | public class Error { 24 | 25 | public Error(String errorMessage) { 26 | this.errorMessage = errorMessage; 27 | } 28 | 29 | public String getErrorMessage() { 30 | return errorMessage; 31 | } 32 | 33 | private final String errorMessage; 34 | } 35 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/models/RequestHeaderModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.models; 19 | 20 | /** 21 | * A HTTP Header in the request model 22 | */ 23 | public class RequestHeaderModel { 24 | 25 | public RequestHeaderModel(String name, String value) { 26 | this.name = name; 27 | this.value = value; 28 | } 29 | 30 | public RequestHeaderModel() { 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public void setValue(String value) { 38 | this.value = value; 39 | } 40 | 41 | private String name; 42 | private String value; 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | 49 | public String getValue() { 50 | return value; 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/models/RequestModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.models; 19 | 20 | import com.intellij.util.net.HTTPMethod; 21 | import com.magnet.plugin.r2m.models.Method; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * Request model 28 | */ 29 | public class RequestModel { 30 | 31 | 32 | private final HTTPMethod httpMethod; 33 | private final String methodName; 34 | 35 | private String testUrl; 36 | private String templateUrl; 37 | private String request; 38 | private String response; 39 | private List headers = new ArrayList(); 40 | 41 | public RequestModel(Method method) { 42 | httpMethod = method.getHttpMethod(); 43 | methodName = method.getMethodName(); 44 | testUrl = method.getTestUrl(); 45 | templateUrl = method.getTemplateUrl(); 46 | request = method.getPayload(); 47 | headers = method.getHeaders(); 48 | } 49 | 50 | public String getMethodName() { 51 | return methodName; 52 | } 53 | 54 | public String getTestUrl() { 55 | return testUrl.replaceAll(" ", "%20"); 56 | } 57 | 58 | public void setTestUrl(String testUrl) { 59 | this.testUrl = testUrl; 60 | } 61 | 62 | public String getTemplateUrl() { 63 | return templateUrl; 64 | } 65 | 66 | public void setTemplateUrl(String templateUrl) { 67 | this.templateUrl = templateUrl; 68 | } 69 | 70 | public String getRequest() { 71 | return request; 72 | } 73 | 74 | public void setRequest(String request) { 75 | this.request = request; 76 | } 77 | 78 | public String getResponse() { 79 | return response; 80 | } 81 | 82 | public void setResponse(String response) { 83 | this.response = response; 84 | } 85 | 86 | public List getHeaders() { 87 | return headers; 88 | } 89 | 90 | public void setHeaders(List headers) { 91 | this.headers = headers; 92 | } 93 | 94 | public HTTPMethod getHttpMethod() { 95 | return httpMethod; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/models/ResponseModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.models; 19 | 20 | /** 21 | * Represent a response in the model 22 | */ 23 | public class ResponseModel { 24 | private final String body; 25 | 26 | public ResponseModel(String body) { 27 | this.body = body; 28 | } 29 | 30 | public String getBody(){ 31 | return body; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests; 19 | 20 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 21 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 22 | import com.magnet.plugin.r2m.api.models.RequestModel; 23 | import com.magnet.plugin.r2m.api.requests.abs.BaseRequest; 24 | import org.apache.http.client.methods.HttpDelete; 25 | import org.apache.http.client.methods.HttpRequestBase; 26 | 27 | 28 | /** 29 | * HTTP Delete request 30 | */ 31 | public class DeleteRequest extends BaseRequest { 32 | 33 | 34 | public DeleteRequest(WorkerCallback callback, RequestModel requestModel) { 35 | super(callback, requestModel); 36 | } 37 | 38 | @Override 39 | protected HttpRequestBase getRequest(RequestModel requestModel) { 40 | return new HttpDelete(requestModel.getTestUrl()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/GetRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests; 19 | 20 | 21 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 22 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 23 | import com.magnet.plugin.r2m.api.models.RequestModel; 24 | import com.magnet.plugin.r2m.api.requests.abs.BaseRequest; 25 | import org.apache.http.client.methods.HttpGet; 26 | import org.apache.http.client.methods.HttpRequestBase; 27 | 28 | /** 29 | * HTTP Get request 30 | */ 31 | public class GetRequest extends BaseRequest { 32 | 33 | 34 | public GetRequest(WorkerCallback callback, RequestModel requestModel) { 35 | super(callback, requestModel); 36 | } 37 | 38 | @Override 39 | protected HttpRequestBase getRequest(RequestModel requestModel) { 40 | HttpGet httpGet = new HttpGet(requestModel.getTestUrl()); 41 | return httpGet; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/PostRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests; 19 | 20 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 21 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 22 | import com.magnet.plugin.r2m.api.models.RequestModel; 23 | import com.magnet.plugin.r2m.api.requests.abs.BaseRequest; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.client.methods.HttpRequestBase; 26 | import org.apache.http.entity.StringEntity; 27 | 28 | public class PostRequest extends BaseRequest { 29 | 30 | 31 | public PostRequest(WorkerCallback callback, RequestModel apiData) { 32 | super(callback, apiData); 33 | } 34 | 35 | @Override 36 | protected HttpRequestBase getRequest(RequestModel requestModel) { 37 | HttpPost httpPost=new HttpPost(requestModel.getTestUrl()); 38 | try { 39 | httpPost.setEntity(new StringEntity(requestModel.getRequest(),"UTF-8")); 40 | } catch (Exception e) { 41 | } 42 | return httpPost; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/PutRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests; 19 | 20 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 21 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 22 | import com.magnet.plugin.r2m.api.models.RequestModel; 23 | import com.magnet.plugin.r2m.api.requests.abs.BaseRequest; 24 | import org.apache.http.client.methods.HttpPut; 25 | import org.apache.http.client.methods.HttpRequestBase; 26 | import org.apache.http.entity.StringEntity; 27 | 28 | /** 29 | * HTTP Put request 30 | */ 31 | 32 | public class PutRequest extends BaseRequest { 33 | 34 | 35 | public PutRequest(WorkerCallback callback, RequestModel apiData) { 36 | super(callback, apiData); 37 | } 38 | 39 | @Override 40 | protected HttpRequestBase getRequest(RequestModel requestModel) { 41 | HttpPut httpPost=new HttpPut(requestModel.getTestUrl()); 42 | try { 43 | httpPost.setEntity(new StringEntity(requestModel.getRequest(),"UTF-8")); 44 | } catch (Exception e) { 45 | } 46 | return httpPost; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/abs/AbstractRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests.abs; 19 | 20 | import com.magnet.plugin.common.Logger; 21 | import com.magnet.plugin.r2m.api.mock.Worker; 22 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 23 | import com.magnet.plugin.r2m.helpers.IOUtils; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.util.concurrent.Executor; 28 | import java.util.concurrent.Executors; 29 | 30 | /** 31 | * Abstract implementation for all HTTP requests 32 | * 33 | * @param 34 | */ 35 | public abstract class AbstractRequest implements Runnable, Worker, WorkerCallback { 36 | 37 | private final Executor executor = Executors.newSingleThreadExecutor(); 38 | private WorkerCallback callback; 39 | 40 | 41 | public AbstractRequest(WorkerCallback callback) { 42 | this.setCallback(callback); 43 | } 44 | 45 | public void execute() { 46 | executor.execute(this); 47 | } 48 | 49 | @Override 50 | public void run() { 51 | try { 52 | doWork(); 53 | } catch (Exception e) { 54 | onError(e); 55 | } 56 | } 57 | 58 | @Override 59 | public void onSuccess(final T t) { 60 | if (getCallback() == null) { 61 | return; 62 | } else { 63 | getCallback().onSuccess(t); 64 | } 65 | setCallback(null); 66 | } 67 | 68 | @Override 69 | public void onError(final Exception e) { 70 | Logger.info(getClass(), "onError: " + e.toString()); 71 | 72 | if (getCallback() != null) { 73 | getCallback().onError(e); 74 | } 75 | setCallback(null); 76 | } 77 | 78 | public WorkerCallback getCallback() { 79 | return callback; 80 | } 81 | 82 | protected void setCallback(WorkerCallback callback) { 83 | this.callback = callback; 84 | } 85 | 86 | protected String toString(InputStream is) throws IOException { 87 | return IOUtils.toString(is); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/api/requests/abs/BaseRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.api.requests.abs; 19 | 20 | import com.magnet.langpack.builder.rest.RestContentType; 21 | import com.magnet.langpack.builder.rest.parser.ExampleParser; 22 | import com.magnet.plugin.r2m.api.mock.WorkerCallback; 23 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 24 | import com.magnet.plugin.r2m.api.models.RequestHeaderModel; 25 | import com.magnet.plugin.r2m.api.models.RequestModel; 26 | import com.magnet.plugin.r2m.helpers.ContentTypeHelper; 27 | import org.apache.http.HttpResponse; 28 | import org.apache.http.client.HttpClient; 29 | import org.apache.http.client.methods.HttpRequestBase; 30 | import org.apache.http.impl.client.HttpClientBuilder; 31 | 32 | import java.util.List; 33 | 34 | /** 35 | * HTTP Base Request implementation 36 | */ 37 | public abstract class BaseRequest extends AbstractRequest { 38 | 39 | private final RequestModel requestModel; 40 | 41 | protected abstract HttpRequestBase getRequest(RequestModel requestModel); 42 | 43 | public BaseRequest(WorkerCallback callback, RequestModel requestModel) { 44 | super(callback); 45 | this.requestModel = requestModel; 46 | } 47 | 48 | 49 | @Override 50 | public void doWork() throws Exception { 51 | HttpClient httpClient = HttpClientBuilder.create().build(); 52 | HttpRequestBase request = getRequest(requestModel); 53 | 54 | List requestModelHeaders = requestModel.getHeaders(); 55 | 56 | for (RequestHeaderModel header : requestModelHeaders) { 57 | request.setHeader(header.getName(), header.getValue()); 58 | } 59 | 60 | // If not specified as a header argument, Content-Type is inferred from the request body 61 | // Add the header here so the request is successful. 62 | if (request.getHeaders(ContentTypeHelper.CONTENT_TYPE_HEADER) == null || 63 | request.getHeaders(ContentTypeHelper.CONTENT_TYPE_HEADER).length == 0) { 64 | RestContentType type = ExampleParser.guessContentType(requestModel.getRequest()); 65 | if (null != type) { 66 | request.setHeader(ContentTypeHelper.CONTENT_TYPE_HEADER, type.getName()); 67 | } 68 | } 69 | // check if content-type is parameterized 70 | HttpResponse httpResponse = httpClient.execute(request); 71 | ApiMethodModel methodModel = new ApiMethodModel(); 72 | methodModel.setRequestHeaders(request.getAllHeaders()); 73 | methodModel.setHttpResponse(httpResponse); 74 | methodModel.setRequestModel(requestModel); 75 | onSuccess(methodModel); 76 | 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/components/ControllerHistoryComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.components; 19 | 20 | import com.intellij.openapi.components.*; 21 | import com.intellij.openapi.project.Project; 22 | import com.magnet.plugin.r2m.models.ControllerHistory; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | /** 27 | * Manage history 28 | */ 29 | @State( 30 | name = ControllerHistoryComponent.NAME, 31 | storages = { 32 | @Storage(id = "default", file = StoragePathMacros.WORKSPACE_FILE), 33 | @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/r2mControllerCache.xml", scheme = StorageScheme.DIRECTORY_BASED) 34 | } 35 | ) 36 | public class ControllerHistoryComponent implements ProjectComponent, PersistentStateComponent { 37 | public final static String NAME = "ControllerCacheComponent"; 38 | 39 | private ControllerHistory cache; 40 | 41 | public ControllerHistoryComponent(Project project) { 42 | this.cache = new ControllerHistory(project); 43 | } 44 | 45 | public void initComponent() {} 46 | 47 | public void disposeComponent() {} 48 | 49 | @NotNull 50 | public String getComponentName() { 51 | return NAME; 52 | } 53 | 54 | public void projectOpened() {} 55 | 56 | public void projectClosed() {} 57 | 58 | @Nullable 59 | @Override 60 | public ControllerHistory getState() { 61 | return cache; 62 | } 63 | 64 | @Override 65 | public void loadState(ControllerHistory cache) { 66 | this.cache = cache; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/components/HistoryComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.components; 19 | 20 | import com.intellij.openapi.components.*; 21 | import com.intellij.openapi.project.Project; 22 | import com.magnet.plugin.r2m.models.History; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | /** 27 | * Manage history 28 | */ 29 | @State( 30 | name = "HistoryComponent", 31 | storages = { 32 | @Storage(id = "default", file = StoragePathMacros.WORKSPACE_FILE), 33 | @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/r2murlcache.xml", scheme = StorageScheme.DIRECTORY_BASED) 34 | } 35 | ) 36 | public class HistoryComponent implements ProjectComponent, PersistentStateComponent { 37 | 38 | public final static String NAME = "HistoryComponent"; 39 | 40 | private History cache; 41 | 42 | public HistoryComponent(Project project) { 43 | this.cache = new History(new String[0]); 44 | } 45 | 46 | public void initComponent() { 47 | } 48 | 49 | public void disposeComponent() { 50 | } 51 | 52 | @NotNull 53 | public String getComponentName() { 54 | return NAME; 55 | } 56 | 57 | public void projectOpened() { 58 | } 59 | 60 | public void projectClosed() { 61 | } 62 | 63 | @Nullable 64 | @Override 65 | public History getState() { 66 | return cache; 67 | } 68 | 69 | @Override 70 | public void loadState(History cache) { 71 | this.cache = cache; 72 | } 73 | 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/constants/Colors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.constants; 19 | 20 | import com.intellij.ui.Gray; 21 | import com.intellij.ui.JBColor; 22 | 23 | import java.awt.*; 24 | 25 | /** 26 | * Color constants 27 | */ 28 | public interface Colors { 29 | 30 | Color PINK = new JBColor(new Color(253, 147, 125), new Color(253, 147, 125)); 31 | Color GREEN = new JBColor(new Color(15, 108, 40), new Color(56, 195, 36)); 32 | Color BLACK = new JBColor(Gray._0, Gray._255); 33 | } 34 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/constants/FormConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | 24 | package com.magnet.plugin.r2m.constants; 25 | 26 | import java.awt.*; 27 | 28 | public interface FormConfig { 29 | int SEPARATOR_CUSTOM_SIZE = 6; 30 | int CUSTOM_GAP = 100; 31 | int CUSTOM_PREF_SIZE = 50; 32 | int PATH_CHECKBOX_PREF_SIZE = 20; 33 | int PATH_CHECKBOX_MAX_SIZE = 70; 34 | int CUSTOM_SCROLL_SIZE = 500; 35 | int CUSTOM_BUTTON_SIZE = 100; 36 | int CUSTOM_TEXTAREA_SIZE = 100; 37 | int MAX_TEXTAREA_SIZE = 300; 38 | int DEFAULT_COMPONENT_SIZE = 20; 39 | int CUSTOM_METHOD_TYPE_GAP = 50; 40 | 41 | Dimension PAYLOAD_TEXT_DIMENSION =new Dimension(500, 100); 42 | Dimension SCREEN_DIMENSION =new Dimension(700, 700); 43 | Dimension PAYLOAD_PANEL_DIMENSION =new Dimension(500, 250); 44 | } 45 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/constants/GenerateActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.constants; 19 | 20 | /** 21 | * Generate action statuses 22 | */ 23 | public enum GenerateActions { 24 | GENERATE_SUCCESS, 25 | START_FILE_OPERATIONS, 26 | FILE_OPERATION_SUCCESS, 27 | } 28 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/constants/JSONErrorType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.constants; 19 | 20 | import com.magnet.plugin.r2m.messages.R2MMessages; 21 | 22 | /** 23 | * JSON errors types 24 | */ 25 | public enum JSONErrorType { 26 | ERROR_NULL_VALUE(R2MMessages.getMessage("ERROR_NULL_VALUE_TEXT")), 27 | ERROR_EMPTY_ARRAY(R2MMessages.getMessage("ERROR_EMPTY_ARRAY_TEXT")), 28 | ERROR_EMPTY_DICTIONARY(R2MMessages.getMessage("ERROR_EMPTY_DICTIONARY_TEXT")), 29 | ERROR_MISSING_COMMA(R2MMessages.getMessage("ERROR_MISSING_COMMA_TEXT")), 30 | ERROR_INVALID_FORMAT(R2MMessages.getMessage("ERROR_INVALID_FORMAT")); 31 | 32 | 33 | private String message; 34 | 35 | JSONErrorType(String message) { 36 | this.message = message; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return message; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/constants/PluginIcon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.constants; 19 | 20 | import com.intellij.openapi.util.IconLoader; 21 | 22 | import javax.swing.*; 23 | 24 | /** 25 | * Icons 26 | */ 27 | public interface PluginIcon { 28 | Icon openIcon = IconLoader.getIcon("/r2m/minus_button.png"); 29 | Icon closeIcon = IconLoader.getIcon("/r2m/plus_button.png"); 30 | Icon closeIconPressed = IconLoader.getIcon("/r2m/plus_button_pressed.png"); 31 | Icon openIconPressed = IconLoader.getIcon("/r2m/minus_button_pressed.png"); 32 | Icon errorIcon = IconLoader.getIcon("/r2m/error_icon.png"); 33 | Icon warningIcon = IconLoader.getIcon("/r2m/warning_icon.png"); 34 | Icon validIcon = IconLoader.getIcon("/r2m/check_icon.png"); 35 | } 36 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/ContentTypeHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import java.util.regex.Matcher; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * Content-type utilities 25 | */ 26 | public class ContentTypeHelper { 27 | 28 | // Supported content types 29 | public static final String CONTENT_TYPE_JSON = "application/json"; 30 | public static final String CONTENT_TYPE_FORM_URL_ENCODED = "application/x-www-form-urlencoded"; 31 | public static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain"; 32 | 33 | /** pattern to discover a form url encoded content */ 34 | public static final Pattern FORM_PARAM_PATTERN = Pattern.compile("(.+=.+)[&(.+=.+)]*"); 35 | 36 | /** HTTP header for content type */ 37 | public static final String CONTENT_TYPE_HEADER = "Content-Type"; 38 | 39 | 40 | /** 41 | * Helper method to guess the content type of a body 42 | * @param body body to guess content-type from 43 | * @return content-type or null if there is no body. 44 | */ 45 | public static String guessContentType(String body) { 46 | if (body == null || body.isEmpty()) { 47 | return null; 48 | } 49 | String result; 50 | String trimedBody = body.trim(); 51 | if (trimedBody.startsWith("{") && trimedBody.endsWith("}") || 52 | trimedBody.startsWith("[") && trimedBody.endsWith("]")) { 53 | result = CONTENT_TYPE_JSON; 54 | } else { 55 | Matcher m = FORM_PARAM_PATTERN.matcher(trimedBody); 56 | if (m.find()) { 57 | result = CONTENT_TYPE_FORM_URL_ENCODED; 58 | } else { 59 | result = CONTENT_TYPE_TEXT_PLAIN; 60 | } 61 | } 62 | 63 | return result; 64 | } 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/ControllerHistoryManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.intellij.openapi.project.Project; 21 | import com.magnet.plugin.r2m.components.ControllerHistoryComponent; 22 | import com.magnet.plugin.r2m.models.ControllerHistory; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Manage access to controller cache 28 | */ 29 | public class ControllerHistoryManager { 30 | 31 | 32 | private static ControllerHistory getCache(Project project) { 33 | return getComponent(project).getState(); 34 | } 35 | 36 | private static ControllerHistoryComponent getComponent(Project project) { 37 | if (project == null) { 38 | return null; 39 | } 40 | 41 | return project.getComponent(ControllerHistoryComponent.class); 42 | } 43 | 44 | public static String[] getCachedControllers(Project project) { 45 | List controllerNames = getCache(project).getControllers(); 46 | String[] array = controllerNames.toArray(new String[controllerNames.size() + 1]); 47 | array[0] = ""; 48 | System.arraycopy(controllerNames.toArray(new String[controllerNames.size()]), 0, array, 1, controllerNames.size()); 49 | return array; 50 | } 51 | 52 | public static void saveController(Project project, String controller) { 53 | ControllerHistory cache = getCache(project); 54 | cache.addController(controller); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/FileHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.intellij.openapi.project.Project; 21 | import com.magnet.plugin.common.Logger; 22 | import com.magnet.plugin.r2m.project.CacheManager; 23 | import com.magnet.plugin.r2m.project.ProjectManager; 24 | 25 | import java.io.File; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * Rest-By-Example specification file helper 31 | */ 32 | public class FileHelper { 33 | 34 | /** 35 | * Check that the folder for the generated controller contains classes that already exist in the project 36 | * @param project project 37 | * @param controllerName controller name 38 | * @param packageName controller package name 39 | * @return the list of common classes 40 | */ 41 | public static List getCommonFiles(Project project, String controllerName, String packageName) { 42 | 43 | File tempSourceDir = new CacheManager(project, packageName, controllerName).getControllerSourceFolder(); 44 | File projectSourceDir = ProjectManager.getSourceFolderFile(project); 45 | 46 | List fileNamesFromTempSource = new ArrayList(); 47 | List fileNamesFromProjectSource = new ArrayList(); 48 | 49 | getRelativeFiles(tempSourceDir, fileNamesFromTempSource); 50 | getRelativeFiles(projectSourceDir, fileNamesFromProjectSource); 51 | 52 | System.out.println(fileNamesFromTempSource); 53 | System.out.println(fileNamesFromProjectSource); 54 | 55 | List list = new ArrayList(); 56 | for (String s : fileNamesFromTempSource) { 57 | if (fileNamesFromProjectSource.contains(s)) { 58 | list.add(s); 59 | } 60 | } 61 | return list; 62 | } 63 | 64 | public static List getCommonTestFiles(Project project, String controllerName, String packageName) { 65 | File tempSourceDir = new CacheManager(project, packageName, controllerName).getTestControllerSourceFolder(); 66 | File projectSourceDir = ProjectManager.getTestSourceFolderFile(project); 67 | 68 | if (projectSourceDir == null) { 69 | return null; 70 | } 71 | 72 | List fileNamesFromTempSource = new ArrayList(); 73 | List fileNamesFromProjectSource = new ArrayList(); 74 | 75 | getRelativeFiles(tempSourceDir, fileNamesFromTempSource); 76 | getRelativeFiles(projectSourceDir, fileNamesFromProjectSource); 77 | 78 | System.out.println(fileNamesFromTempSource); 79 | System.out.println(fileNamesFromProjectSource); 80 | 81 | List list = new ArrayList(); 82 | for (String s : fileNamesFromTempSource) { 83 | if (fileNamesFromProjectSource.contains(s)) { 84 | list.add(s); 85 | } 86 | } 87 | return list; 88 | 89 | } 90 | 91 | /** 92 | * Get all java class (package.class) located under folder 93 | * @param classes list of classes 94 | * @param folder folder to recursively introspect 95 | * @return list of classes 96 | */ 97 | public static List getRelativeFiles(final File folder, final List classes) { 98 | return getClassesFromFolder(folder, folder, classes); 99 | } 100 | 101 | private static List getClassesFromFolder(final File root, final File folder, final List classes) { 102 | if (null == folder || !folder.exists() || !folder.isDirectory()) { 103 | Logger.error(FileHelper.class, "Cache folder does not exist: " + folder); 104 | return null; 105 | } 106 | for (final File fileEntry : folder.listFiles()) { 107 | if (fileEntry.isDirectory()) { 108 | getClassesFromFolder(root, fileEntry, classes); 109 | } else { 110 | String path = fileEntry.getAbsolutePath(); 111 | String relative = root.toURI().relativize(new File(path).toURI()).getPath(); 112 | classes.add(relative); 113 | } 114 | } 115 | return classes; 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/FormatHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.google.gson.Gson; 21 | import com.google.gson.GsonBuilder; 22 | import com.google.gson.JsonElement; 23 | import com.google.gson.JsonParser; 24 | 25 | public class FormatHelper { 26 | public static String formatJSONCode(String code) { 27 | String formatted=""; 28 | try{ 29 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 30 | JsonParser jp = new JsonParser(); 31 | JsonElement je = jp.parse(code); 32 | formatted = gson.toJson(je); 33 | }catch (Exception e){ 34 | code = code.replaceAll(" ", ""); 35 | code = code.replaceAll("\\[\\{", "\\[\n \\{"); 36 | code = code.replaceAll("\\{\"", "\\{\n \""); 37 | code = code.replaceAll(",\"", ",\n \""); 38 | code = code.replaceAll("},\\{", "},\n \\{"); 39 | code = code.replaceAll(":", " : "); 40 | code = code.replaceAll("}", "\n }"); 41 | code = code.replaceAll("]", "\n]"); 42 | formatted=code; 43 | } 44 | return formatted; 45 | } 46 | 47 | public static String unformatJSONCode(String code) { 48 | code = code.replaceAll("\n", " "); 49 | code = code.replaceAll(" ", ""); 50 | return code; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/HighlightHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.magnet.plugin.r2m.models.JSONError; 21 | 22 | import javax.swing.*; 23 | import javax.swing.text.DefaultHighlighter; 24 | import javax.swing.text.Highlighter; 25 | import java.util.List; 26 | 27 | import static com.magnet.plugin.r2m.constants.Colors.PINK; 28 | 29 | 30 | public class HighlightHelper { 31 | 32 | 33 | 34 | public static void highlightErrors(List errors, 35 | JTextArea responseField) { 36 | responseField.getHighlighter().removeAllHighlights(); 37 | for (JSONError error : errors) { 38 | setHighlight(responseField, error); 39 | } 40 | } 41 | 42 | private static void setHighlight(JTextArea highlight, JSONError error) { 43 | Highlighter.HighlightPainter errorHighlighter = 44 | new DefaultHighlighter.DefaultHighlightPainter(PINK); 45 | try { 46 | highlight.getHighlighter().addHighlight(error.getStartIndex(), 47 | error.getEndIndex(), 48 | errorHighlighter); 49 | } catch (Exception ble) { 50 | ble.printStackTrace(); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/HistoryHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.intellij.openapi.project.Project; 21 | import com.magnet.plugin.r2m.components.HistoryComponent; 22 | import com.magnet.plugin.r2m.models.History; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Arrays; 26 | import java.util.List; 27 | 28 | public class HistoryHelper { 29 | 30 | private static final int MAX_COUNT=10; 31 | private static final int START_INDEX=0; 32 | 33 | public static String[] getSavedUrls(Project project){ 34 | HistoryComponent historyComponent=project.getComponent(HistoryComponent.class); 35 | History history=historyComponent.getState(); 36 | String[] savedUrls=history.getUrls(); 37 | String[] urls=new String[savedUrls.length+1]; //need require empty place for current value; 38 | urls[START_INDEX]=""; 39 | System.arraycopy(savedUrls, START_INDEX, urls, 1, savedUrls.length); 40 | 41 | return urls; 42 | } 43 | 44 | public static void saveUrl(Project project, String url){ 45 | HistoryComponent historyComponent=project.getComponent(HistoryComponent.class); 46 | History history=historyComponent.getState(); 47 | String[] savedUrls=history.getUrls(); 48 | List savedList= new ArrayList(); 49 | savedList.addAll(Arrays.asList(savedUrls).subList(START_INDEX, savedUrls.length)); 50 | if(!savedList.contains(url)){ 51 | savedList.add(START_INDEX, url); 52 | } 53 | 54 | if(savedList.size()>MAX_COUNT){ 55 | savedList=savedList.subList(START_INDEX, MAX_COUNT); 56 | } 57 | String[] urls=new String[savedList.size()]; 58 | urls=savedList.toArray(urls); 59 | historyComponent.loadState(new History(urls)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.InputStreamReader; 24 | import java.nio.charset.Charset; 25 | 26 | public class IOUtils { 27 | 28 | public static byte[] toByteArray(InputStream inputStream) throws IOException { 29 | // this dynamically extends to take the bytes you read 30 | ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); 31 | 32 | // this is storage overwritten on each iteration with bytes 33 | int bufferSize = 1024; 34 | byte[] buffer = new byte[bufferSize]; 35 | 36 | // we need to know how may bytes were read to write them to the 37 | // byteBuffer 38 | int len = 0; 39 | while ((len = inputStream.read(buffer)) != -1) { 40 | byteBuffer.write(buffer, 0, len); 41 | } 42 | 43 | // and then we can return your byte array. 44 | return byteBuffer.toByteArray(); 45 | } 46 | 47 | public static String toString(InputStream is) throws IOException { 48 | StringBuilder result = new StringBuilder(); 49 | InputStreamReader in = new InputStreamReader(is); 50 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 51 | 52 | int nRead; 53 | byte[] data = new byte[16384]; 54 | 55 | while ((nRead = is.read(data, 0, data.length)) != -1) { 56 | buffer.write(data, 0, nRead); 57 | } 58 | 59 | buffer.flush(); 60 | 61 | 62 | return new String(buffer.toByteArray(), Charset.forName("UTF-8")); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/JSONValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.magnet.langpack.builder.rest.parser.validation.BodyValidationResult; 21 | import com.magnet.langpack.builder.rest.parser.validation.BodyValidator; 22 | import com.magnet.langpack.builder.rest.parser.validation.ValidationResultEntry; 23 | import com.magnet.plugin.r2m.models.JSONError; 24 | import com.magnet.plugin.r2m.constants.PluginIcon; 25 | import org.jdesktop.swingx.JXLabel; 26 | 27 | import javax.swing.*; 28 | import java.util.List; 29 | import java.util.Collections; 30 | import java.util.regex.Matcher; 31 | import java.util.regex.Pattern; 32 | 33 | /** 34 | * JSON validator according to Rest-By-Example specification 35 | */ 36 | public class JSONValidator { 37 | 38 | private static final String UNUSED_SYMBOLS = "\n|,|:|\"|\t"; 39 | private static final String IS_JSON_VERIFY = "^\\{|^\\[|]$|}$"; 40 | 41 | public static boolean isJSON(String text) { 42 | Pattern pattern = Pattern.compile(IS_JSON_VERIFY); 43 | Matcher matcher = pattern.matcher(removeUnusedSymbols(text.trim())); 44 | int matchCount = 0; 45 | while (matcher.find()) { 46 | matchCount++; 47 | } 48 | return matchCount >= 2; 49 | } 50 | 51 | public static List validateJSON(String text, JComponent field, JTextArea jsonField) { 52 | BodyValidationResult validationResult = BodyValidator.validateBody(text); 53 | if (validationResult.isValid()) { 54 | return Collections.EMPTY_LIST; 55 | } 56 | 57 | JsonErrorConverter jsonErrorConverter = new JsonErrorConverter(text, validationResult.getErrors()); 58 | List errors = jsonErrorConverter.convert(); 59 | 60 | // Highlight error in payload 61 | HighlightHelper.highlightErrors(errors, jsonField); 62 | 63 | return errors; 64 | } 65 | 66 | public static BodyValidationResult validateBody(String text) { 67 | return BodyValidator.validateBody(text); 68 | } 69 | 70 | private static String removeUnusedSymbols(String text) { 71 | return text.replaceAll(UNUSED_SYMBOLS, " "); 72 | } 73 | 74 | public static StringBuilder getErrorMessage(List errors) { 75 | StringBuilder errorMessage = new StringBuilder(); 76 | for (ValidationResultEntry error : errors) { 77 | errorMessage.append(null != error.getMessage() ? error.getMessage() : error.toString()).append("\n"); 78 | } 79 | return errorMessage; 80 | } 81 | 82 | private static void setMessageToField(JComponent field, String text, boolean isNeedVisible) { 83 | if (field instanceof JXLabel) { 84 | ((JXLabel) field).setText(text); 85 | if (isNeedVisible) { 86 | ((JXLabel) field).setIcon(PluginIcon.errorIcon); 87 | } else { 88 | ((JXLabel) field).setIcon(PluginIcon.validIcon); 89 | } 90 | } else if (field instanceof JTextField) { 91 | ((JTextField) field).setText(text); 92 | field.setVisible(isNeedVisible); 93 | } else if (field instanceof JTextArea) { 94 | ((JTextArea) field).setText(text); 95 | field.setVisible(isNeedVisible); 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/JsonErrorConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.r2m.helpers; 18 | 19 | import com.magnet.langpack.builder.rest.parser.validation.DocLocation; 20 | import com.magnet.langpack.builder.rest.parser.validation.ValidationResultEntry; 21 | import com.magnet.plugin.r2m.constants.JSONErrorType; 22 | import com.magnet.plugin.r2m.models.JSONError; 23 | 24 | import java.io.IOException; 25 | import java.io.StringReader; 26 | import java.util.LinkedList; 27 | import java.util.List; 28 | 29 | /** 30 | * Convert raw errors in JSON payload into proper messages errors 31 | */ 32 | public class JsonErrorConverter { 33 | 34 | private int currentLine; 35 | private int currentIndex; 36 | private String text; 37 | private List lines; 38 | private List validationResultEntries; 39 | 40 | public JsonErrorConverter(String text, List validationResultEntries) { 41 | this.text = text; 42 | try { 43 | lines = org.apache.commons.io.IOUtils.readLines(new StringReader(text)); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | this.validationResultEntries = validationResultEntries; 48 | } 49 | 50 | public List convert() { 51 | List result = new LinkedList(); 52 | 53 | for(ValidationResultEntry errorEntry : validationResultEntries) { 54 | int startIndex = 0; 55 | int endIndex = 0; 56 | if (null != errorEntry.getDocLocation()) { 57 | if(errorEntry.getDocLocation().getLine() > lines.size()) { // line number out of bound 58 | int lastLineNum = lines.size() - 1; 59 | startIndex = getLineStartIndex(lines.size()); 60 | endIndex = startIndex + lines.get(lastLineNum).length(); 61 | // Reset location since it seems out of bound 62 | errorEntry = new ValidationResultEntry(errorEntry.getPropertyName(), errorEntry.getErrorType(), 63 | new DocLocation(lines.size(), lines.get(lastLineNum).length()), errorEntry.getMessage()); 64 | } else if(errorEntry.getDocLocation().getCol() > lines.get(errorEntry.getDocLocation().getLine() - 1).length()) { // column out of bound 65 | startIndex = getLineStartIndex(errorEntry.getDocLocation().getLine()) + lines.get(errorEntry.getDocLocation().getLine() - 1).length() -1; 66 | endIndex = startIndex + 1; 67 | 68 | // Reset location since it seems out of bound 69 | errorEntry = new ValidationResultEntry(errorEntry.getPropertyName(), errorEntry.getErrorType(), 70 | new DocLocation(errorEntry.getDocLocation().getLine(), lines.get(errorEntry.getDocLocation().getLine() - 1).length()), 71 | errorEntry.getMessage()); 72 | } else { 73 | startIndex = getLineStartIndex(errorEntry.getDocLocation().getLine()) + errorEntry.getDocLocation().getCol() - 1; 74 | switch (errorEntry.getErrorType()) { 75 | case INVALID_FORMAT: 76 | startIndex = startIndex - 1; 77 | 78 | Integer nextQuota = text.indexOf("\"", startIndex) + 1; 79 | Integer nextComma = text.indexOf(",", startIndex) + 1; 80 | Integer endOfLine = currentIndex + lines.get(currentLine).length() + 1; 81 | if (nextQuota != 0 && nextQuota < nextComma) { 82 | endIndex = nextQuota; 83 | int possibleStartIndex = text.lastIndexOf("\"", startIndex); 84 | if (possibleStartIndex > 0) { 85 | startIndex = possibleStartIndex; 86 | } 87 | } else if (nextComma != 0 && nextQuota < endOfLine) { 88 | endIndex = nextComma; 89 | int possibleStartIndex = startIndex = text.lastIndexOf(":", endIndex); 90 | if (possibleStartIndex > 0) { 91 | startIndex = possibleStartIndex + 1; 92 | } 93 | } else if (endOfLine < text.length()) { 94 | endIndex = endOfLine; 95 | startIndex = currentIndex; 96 | } else { 97 | endIndex = startIndex + 1; 98 | } 99 | break; 100 | case EMPTY_ARRAY: 101 | startIndex = startIndex - 1; 102 | endIndex = text.indexOf("]", startIndex) + 1; 103 | break; 104 | case EMPTY_OBJECT: 105 | startIndex = startIndex - 1; 106 | endIndex = text.indexOf("}", startIndex) + 1; 107 | break; 108 | default: //case NULL_PROPERTY: 109 | endIndex = startIndex + 4; 110 | } 111 | } 112 | } 113 | 114 | result.add(new JSONError(errorEntry, startIndex, endIndex)); 115 | } 116 | return result; 117 | } 118 | 119 | private int getLineStartIndex(int lineRequested) { 120 | if(currentLine < lineRequested - 1) { 121 | for(int i = 0; i < (lineRequested - currentLine - 1); i++) { 122 | currentIndex += lines.get(currentLine + i).length() + 1; 123 | } 124 | 125 | currentLine = lineRequested - 1; 126 | } 127 | 128 | return currentIndex; 129 | } 130 | 131 | private JSONErrorType convertErrorType(ValidationResultEntry.ErrorType validationErrorType) { 132 | switch (validationErrorType) { 133 | case INVALID_FORMAT: 134 | return JSONErrorType.ERROR_MISSING_COMMA; 135 | case EMPTY_ARRAY: 136 | return JSONErrorType.ERROR_EMPTY_ARRAY; 137 | case EMPTY_OBJECT: 138 | return JSONErrorType.ERROR_EMPTY_DICTIONARY; 139 | default: //case NULL_PROPERTY: 140 | return JSONErrorType.ERROR_NULL_VALUE; 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/ProjectHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.intellij.openapi.module.Module; 21 | import com.intellij.openapi.module.ModuleManager; 22 | import com.intellij.openapi.project.Project; 23 | import com.intellij.openapi.roots.ModuleRootManager; 24 | import com.intellij.openapi.roots.libraries.Library; 25 | import com.intellij.util.Processor; 26 | 27 | import java.util.ArrayList; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | /** 33 | * Project utilities 34 | */ 35 | public class ProjectHelper { 36 | 37 | private static final String MAGNET_LIB_PREFIX = "magnet-sdk-android"; 38 | 39 | public static boolean isContainsSDK(Project project) { 40 | boolean result = false; 41 | 42 | List libraryNames = getLibrariesName(project); 43 | for (String s : libraryNames) { 44 | if (s.contains(MAGNET_LIB_PREFIX)) { 45 | result = true; 46 | break; 47 | } 48 | } 49 | 50 | return result; 51 | } 52 | 53 | public static String getMagnetLibName(Project project) { 54 | String result = null; 55 | 56 | List libraryNames = getLibrariesName(project); 57 | for (String s : libraryNames) { 58 | if (s.contains(MAGNET_LIB_PREFIX)) { 59 | result = s; 60 | break; 61 | } 62 | } 63 | 64 | return result; 65 | } 66 | 67 | public static Module getMainModule(Project project) { 68 | Module result = null; 69 | Module[] modules = ModuleManager.getInstance(project).getModules(); 70 | final Map moduleMap = getModulesMap(modules); 71 | if (moduleMap.size() > 1) { 72 | moduleMap.remove(project.getName()); 73 | for (Module module : modules) { 74 | ModuleRootManager.getInstance(module).orderEntries().forEachModule(new Processor() { 75 | @Override 76 | public boolean process(Module module) { 77 | moduleMap.remove(module.getName()); 78 | return true; 79 | } 80 | }); 81 | } 82 | } 83 | List list = new ArrayList(moduleMap.values()); 84 | if (list.size() > 0) { 85 | result = list.get(0); 86 | } 87 | 88 | return result; 89 | } 90 | 91 | public static String getModulePath(Module module, Project project) { 92 | String result = null; 93 | if ((module != null) && (project != null)) { 94 | result = project.getBasePath(); 95 | } 96 | return result; 97 | } 98 | 99 | private static Map getModulesMap(Module[] modules) { 100 | final Map moduleMap = new HashMap(); 101 | for (Module module : modules) { 102 | moduleMap.put(module.getName(), module); 103 | } 104 | return moduleMap; 105 | } 106 | 107 | private static List getLibrariesName(Project project) { 108 | Module[] modules = ModuleManager.getInstance(project).getModules(); 109 | final List libraryNames = new ArrayList(); 110 | 111 | 112 | for (Module module : modules) { 113 | ModuleRootManager.getInstance(module).orderEntries().forEachLibrary(new Processor() { 114 | @Override 115 | public boolean process(Library library) { 116 | libraryNames.add(library.getName()); 117 | return true; 118 | } 119 | }); 120 | } 121 | return libraryNames; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/R2MConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | /** 21 | * Constants 22 | */ 23 | public interface R2MConstants { 24 | /** 25 | * Public name fo the plugin 26 | */ 27 | String PUBLIC_TOOL_NAME = "rest2mobile"; 28 | /** 29 | * Developer landing page URL 30 | */ 31 | String MAGNET_DEVELOPER_URL = "developer.magnet.com"; 32 | /** 33 | * Public package for this plugin used to identify the plugin 34 | */ 35 | String PUBLIC_TOOL_PACKAGE = "com.magnet.r2m"; 36 | /** 37 | * Where to find the version information 38 | */ 39 | String PUBLIC_VERSION_URL = "https://raw.githubusercontent.com/magnetsystems/r2m-plugin-android/master/version.properties"; 40 | /** 41 | * connection timeout for http request 42 | */ 43 | int CONNECTION_TIMEOUT = 10000; 44 | 45 | // 46 | // Key used in file pointed to by PUBLIC_VERSION_URL describing the version 47 | // 48 | String LATEST_VERSION_KEY = "version"; 49 | String DOWNLOAD_URL_KEY = "downloadUrl"; 50 | String DESCRIPTION_KEY="description"; 51 | String COMMENTS_KEY="comments"; 52 | 53 | /** 54 | * Default documentation 55 | */ 56 | String DOCUMENTATION_URL = "https://github.com/magnetsystems/rest2mobile/wiki"; 57 | 58 | // 59 | // Path variables 60 | // 61 | String END_TEMPLATE_VARIABLE = "}"; 62 | String START_TEMPLATE_VARIABLE = "{"; 63 | String END_TEMPLATE_VARIABLE_REGEX = "}"; 64 | String START_TEMPLATE_VARIABLE_REGEX = "\\{"; 65 | String TEMPLATE_VARIABLE_REGEX = "\\{(.*?)\\}"; 66 | } 67 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/R2MVerifyHelper.java: -------------------------------------------------------------------------------- 1 | package com.magnet.plugin.r2m.helpers; 2 | 3 | import com.magnet.plugin.common.helpers.VerifyHelper; 4 | import com.magnet.plugin.r2m.messages.R2MMessages; 5 | import org.apache.commons.validator.routines.UrlValidator; 6 | 7 | /** 8 | * R2M specific verification methods. 9 | */ 10 | public class R2MVerifyHelper { 11 | 12 | /** 13 | * The supported schemes when validating the url 14 | */ 15 | private static final String[] SUPPORTED_PROTOCOL_SCHEMES = {"http", "https"}; 16 | 17 | private static final long URL_VALIDATION_OPTIONS = UrlValidator.ALLOW_LOCAL_URLS; 18 | 19 | public static boolean isValidUrl(String url) { 20 | String templateURL = url; 21 | templateURL = templateURL.replaceAll(R2MConstants.START_TEMPLATE_VARIABLE_REGEX, ""); 22 | templateURL = templateURL.replaceAll(R2MConstants.END_TEMPLATE_VARIABLE_REGEX, ""); 23 | UrlValidator urlValidator = new UrlValidator(SUPPORTED_PROTOCOL_SCHEMES, URL_VALIDATION_OPTIONS); 24 | return urlValidator.isValid(templateURL); 25 | } 26 | 27 | public static boolean isValidUrlWithoutPerformance(String url) { 28 | UrlValidator urlValidator = new UrlValidator(); 29 | return urlValidator.isValid(url); 30 | } 31 | 32 | private static String verifyByKeyWords(String text) { 33 | if (VerifyHelper.KEYWORDS.contains(text)) { 34 | UIHelper.showErrorMessage(R2MMessages.getMessage("NAME_CONFLICTS_WITH_JAVA_KEYWORDS")); 35 | text = ""; 36 | } 37 | return text; 38 | } 39 | 40 | public static String verifyClassName(String name) { 41 | return verify(name, "[^A-Za-z0-9_]", true); 42 | } 43 | 44 | public static String verifyMethodName(String name) { 45 | return verify(name, "[^A-Za-z0-9_]", false); 46 | } 47 | 48 | public static String verifyVariableName(String name) { 49 | return verify(name, "[^A-Za-z0-9_]", false); 50 | } 51 | 52 | private static String verify(String name, String regExp, boolean isUpper) { 53 | name = name.replaceAll(regExp, ""); 54 | if (!name.equalsIgnoreCase("")) { 55 | if (isUpper) { 56 | name = name.substring(0, 1).toUpperCase() + name.substring(1); 57 | } else { 58 | name = name.substring(0, 1).toLowerCase() + name.substring(1); 59 | } 60 | } 61 | name = verifyByKeyWords(name); 62 | return name; 63 | } 64 | 65 | 66 | public static String verifyPackageName(String name) { 67 | name = name.replaceAll(">", ""); 68 | return name; 69 | } 70 | 71 | 72 | 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/ResponseHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.magnet.plugin.common.Logger; 21 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 22 | 23 | import java.io.IOException; 24 | import java.util.Arrays; 25 | 26 | /** 27 | * Response helper 28 | */ 29 | public class ResponseHelper { 30 | 31 | public static String processResponse(ApiMethodModel methodModel){ 32 | String entity = ""; 33 | if(null != methodModel.getHttpResponse().getEntity()) { 34 | try { 35 | entity = IOUtils.toString(methodModel.getHttpResponse().getEntity().getContent()); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | Logger.info(ResponseHelper.class, Arrays.asList(methodModel.getRequestHeaders()).toString()); 42 | Logger.info(ResponseHelper.class, methodModel.getHttpResponse().getStatusLine().getReasonPhrase()); 43 | Logger.info(ResponseHelper.class, Arrays.asList(methodModel.getHttpResponse().getAllHeaders()).toString()); 44 | if (entity != null && !entity.isEmpty()) { 45 | Logger.info(ResponseHelper.class, entity); 46 | } 47 | 48 | return entity; 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/RestByExampleKeywords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | /** 21 | * Constants for Rest-By-Example specification 22 | */ 23 | public interface RestByExampleKeywords { 24 | 25 | /** Indicate a HTTP request */ 26 | String REQUEST_TOKEN = "+Request"; 27 | 28 | /** Indicate a HTTP response */ 29 | String RESPONSE_TOKEN = "+Response"; 30 | 31 | /** Indicate a HTTP headers for request or response */ 32 | String HEADERS_TOKEN = "+Headers"; 33 | 34 | /** Indicate a HTTP body for request or response */ 35 | String BODY_TOKEN = "+Body"; 36 | 37 | /** Indicate the method name to generate for the request/response pair */ 38 | String NAME_TOKEN = "+Name"; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/UIHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.intellij.openapi.actionSystem.AnActionEvent; 21 | import com.intellij.openapi.project.Project; 22 | import com.intellij.openapi.ui.Messages; 23 | import com.magnet.plugin.r2m.messages.R2MMessages; 24 | import com.magnet.plugin.r2m.singletons.Application; 25 | 26 | import javax.swing.*; 27 | import java.awt.*; 28 | 29 | /** 30 | * Main UI hub where windows are launched. 31 | */ 32 | public class UIHelper { 33 | 34 | public static final String ERROR_TEST_API = R2MMessages.getMessage("TEST_API_BEFORE_SAVE_METHOD"); 35 | public static final String ERROR_METHOD_NAME = R2MMessages.getMessage("EMPTY_METHOD_NAME"); 36 | public static final String ERROR_REQUEST = R2MMessages.getMessage("ERROR_REQUEST"); 37 | public static final String ERROR_SERVICE_NAME = R2MMessages.getMessage("EMPTY_CLASS_NAME"); 38 | public static final String ERROR_PACKAGE_NAME = R2MMessages.getMessage("EMPTY_PACKAGE_NAME"); 39 | public static final String ERROR_REQUIRED_FIELD = R2MMessages.getMessage("REQUIRED_FIELD"); 40 | public static final String ERROR_FILL_REQUIRED_FIELD = R2MMessages.getMessage("MUST_FILL_ALL_REQUIRED_FIELDS"); 41 | public static final String MESSAGE_GENERATING_SERVICE = R2MMessages.getMessage("SERVICE_WAS_GENERATED"); 42 | 43 | 44 | public static void openAPIDialog(Project project, AnActionEvent anAction) { 45 | Application.getApplication().getCurrentForm(project, anAction, false); 46 | } 47 | 48 | public static void showErrorMessage(String message) { 49 | Messages.showInfoMessage(message, R2MMessages.getMessage("WINDOW_TITLE")); 50 | } 51 | 52 | public static void showErrorMessageEventuallyAndEnable(final String message, final JComponent component) { 53 | SwingUtilities.invokeLater(new Runnable() { 54 | 55 | @Override 56 | public void run() { 57 | Messages.showErrorDialog(message, R2MMessages.getMessage("WINDOW_TITLE")); 58 | component.setEnabled(true); 59 | } 60 | }); 61 | } 62 | 63 | public static Font getFont() { 64 | return new Font("Lucinda Grande", Font.PLAIN, 12); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/helpers/UrlParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.helpers; 19 | 20 | import com.magnet.plugin.common.Logger; 21 | import com.magnet.plugin.r2m.messages.R2MMessages; 22 | import com.magnet.plugin.r2m.models.ParsedUrl; 23 | import com.magnet.plugin.r2m.models.PathPart; 24 | import com.magnet.plugin.r2m.models.Query; 25 | import org.apache.http.NameValuePair; 26 | import org.apache.http.client.utils.URLEncodedUtils; 27 | 28 | import java.net.URL; 29 | import java.nio.charset.Charset; 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | import java.util.regex.Matcher; 33 | import java.util.regex.Pattern; 34 | 35 | public class UrlParser { 36 | private static Pattern PATH_PARAM_PATTERN = Pattern.compile(R2MConstants.TEMPLATE_VARIABLE_REGEX); 37 | 38 | public static ParsedUrl parseUrl(String url) { 39 | List pathParts = new ArrayList(); 40 | List queries = new ArrayList(); 41 | ParsedUrl parsedUrl; 42 | String base; 43 | 44 | try { 45 | URL aURL = new URL(url); 46 | base = aURL.getAuthority(); 47 | String protocol = aURL.getProtocol(); 48 | parsedUrl = new ParsedUrl(); 49 | parsedUrl.setPathWithEndingSlash(aURL.getPath().endsWith("/")); 50 | parsedUrl.setBaseUrl(protocol + "://" + base); 51 | List pairs = URLEncodedUtils.parse(aURL.getQuery(), 52 | Charset.defaultCharset()); 53 | for (NameValuePair pair : pairs) { 54 | Query query = new Query(pair.getName(), pair.getValue()); 55 | queries.add(query); 56 | } 57 | parsedUrl.setQueries(queries); 58 | 59 | String[] pathStrings = aURL.getPath().split("/"); 60 | for (String pathPart : pathStrings) { 61 | Matcher m = PATH_PARAM_PATTERN.matcher(pathPart); 62 | if (m.find()) { 63 | String paramDef = m.group(1); 64 | String[] paramParts = paramDef.split(":"); 65 | if (paramParts.length > 1) { 66 | pathParts.add(new PathPart(paramParts[1].trim(), paramParts[0].trim())); 67 | } else { 68 | pathParts.add(new PathPart(paramParts[0].trim())); 69 | } 70 | } else { 71 | if(!pathPart.isEmpty()) { 72 | pathParts.add(new PathPart(pathPart)); 73 | } 74 | } 75 | } 76 | parsedUrl.setPathParts(pathParts); 77 | } catch (Exception ex) { 78 | Logger.error(UrlParser.class, R2MMessages.getMessage("CANNOT_PARSE_URL", url)); 79 | return null; 80 | } 81 | return parsedUrl; 82 | } 83 | 84 | /** 85 | * @param url url where path param are expanded (removed "{""}") 86 | * @return expanded url 87 | */ 88 | public static String expandUrl(String url) { 89 | Matcher m = PATH_PARAM_PATTERN.matcher(url); 90 | while (m.find()) { 91 | String paramDef = m.group(1); 92 | String[] paramParts = paramDef.split(":"); 93 | if (paramParts.length > 1) { 94 | url = url.replaceAll(R2MConstants.START_TEMPLATE_VARIABLE_REGEX + paramParts[0] + R2MConstants.END_TEMPLATE_VARIABLE_REGEX, paramParts[1]); 95 | } else { 96 | url = url.replaceAll(R2MConstants.START_TEMPLATE_VARIABLE_REGEX + paramParts[0] + R2MConstants.END_TEMPLATE_VARIABLE_REGEX, paramParts[0]); 97 | } 98 | } 99 | 100 | return url; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/ControllerActionCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners; 19 | 20 | public interface ControllerActionCallback { 21 | void isDispose(); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/CreateMethodCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners; 19 | 20 | import com.magnet.plugin.r2m.api.models.ApiMethodModel; 21 | 22 | public interface CreateMethodCallback { 23 | 24 | public void createMethod(ApiMethodModel methodModel); 25 | 26 | public void canGenerate(boolean canGenerate); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/TabRemoveListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners; 19 | 20 | import com.magnet.plugin.r2m.ui.tab.MethodTabPanel; 21 | 22 | public interface TabRemoveListener { 23 | void removeCurrentPanel(MethodTabPanel methodTabPanel); 24 | } 25 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/URLFocusListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners; 19 | 20 | public interface URLFocusListener { 21 | void onFocusChange(String url); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/generator/PostGenerateCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners.generator; 19 | 20 | import java.io.File; 21 | 22 | /** 23 | * Callback invoked upon successful generation 24 | */ 25 | public interface PostGenerateCallback { 26 | void onGenerateFinished(boolean result, File path); 27 | } 28 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/listeners/generator/ProgressGenerateCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.listeners.generator; 19 | 20 | import com.magnet.plugin.r2m.constants.GenerateActions; 21 | 22 | public interface ProgressGenerateCallback { 23 | void onActionSuccess(GenerateActions actions); 24 | void onActionFailure(String error); 25 | } 26 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/messages/MessagesSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.messages; 19 | 20 | import java.text.MessageFormat; 21 | import java.util.ResourceBundle; 22 | 23 | /** 24 | * Base class to retrieve L10N messages 25 | */ 26 | public class MessagesSupport { 27 | 28 | /** 29 | * Build the localized message given a resource bundle name, message key, and message arguments 30 | * @param bundleName bundleName 31 | * @param key the message key in the bundle 32 | * @param args the message arguments to inject in the message at key key 33 | * @return the localized message, if found, otherwise BUNDLE_NOT_FOUND, if bundle is not found, or MESSAGE_NOT_FOUND 34 | * if the message for key key is not found in bundle 35 | */ 36 | static String getMessage(String bundleName, String key, Object... args) { 37 | ResourceBundle resourceBundle = getBundle(bundleName); 38 | if (null == resourceBundle) { 39 | return "BUNDLE_NOT_FOUND(" + bundleName + ")"; 40 | } 41 | String message = null; 42 | try { 43 | message = resourceBundle.getString(key); 44 | } catch (Exception e) { 45 | // eat it 46 | } 47 | if (null == message) { 48 | return "MESSAGE_NOT_FOUND($bundleName, " + key + ", " + args + ")"; 49 | } 50 | return MessageFormat.format(message, args); 51 | } 52 | 53 | /** 54 | * Utility method to retrieve the resource bundle 55 | * @param bundleName name of the resource bundle 56 | * @return bundle or null if none found 57 | */ 58 | static ResourceBundle getBundle(String bundleName) { 59 | ResourceBundle res = null; 60 | try { 61 | res = ResourceBundle.getBundle(bundleName); 62 | } catch (Exception e) { 63 | // eat it 64 | } 65 | return res; 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/messages/R2MMessages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.messages; 19 | 20 | /** 21 | * Placeholder for retrieving all L10N messages 22 | * 23 | */ 24 | public class R2MMessages { 25 | /** 26 | * @param key constant identifying L10n message 27 | * @param args arguments to be expanded in L10n message 28 | * @return expanded L10n message given its key and arguments 29 | */ 30 | public static String getMessage(String key, Object... args) { 31 | return MessagesSupport.getMessage("r2m/r2m", key, args); 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/ControllerHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.intellij.openapi.project.Project; 21 | import com.magnet.plugin.r2m.project.CacheManager; 22 | 23 | import java.io.File; 24 | import java.io.FileFilter; 25 | import java.util.ArrayList; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Cache holding all controllers used in this project 31 | */ 32 | public class ControllerHistory { 33 | private final Project project; 34 | private List controllerNames; 35 | 36 | public ControllerHistory(Project project) { 37 | this.project = project; 38 | reset(); 39 | } 40 | 41 | public void addController(String name) { 42 | if (controllerNames.contains(name)) { 43 | return; 44 | } 45 | controllerNames.add(name); 46 | } 47 | 48 | public void removeController(String name) { 49 | controllerNames.remove(name); 50 | } 51 | 52 | public void reset() { 53 | this.controllerNames = new ArrayList(); 54 | File[] dirs = CacheManager.getControllerFolders(project); 55 | if (null != dirs) { 56 | for (File d : dirs) { 57 | controllerNames.add(d.getName()); 58 | } 59 | } 60 | } 61 | 62 | public List getControllers() { 63 | return Collections.unmodifiableList(controllerNames); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/ExampleResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | /** 21 | * Model for an example resource from r2m-examples repository 22 | */ 23 | public class ExampleResource { 24 | public static final String EXAMPLES_BASE_URL = "https://raw.githubusercontent.com/magnetsystems/r2m-examples/master/samples/"; 25 | 26 | private final String name; 27 | private final String file; 28 | private final String description; 29 | 30 | public ExampleResource(String name, String file, String description) { 31 | this.name = name; 32 | this.file = file; 33 | this.description = description; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public String getDescription() { 41 | return description; 42 | } 43 | 44 | public String getFile() { 45 | return file; 46 | } 47 | 48 | public String getUrl() { 49 | return EXAMPLES_BASE_URL + getFile(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/ExamplesManifest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.google.gson.stream.JsonReader; 21 | 22 | import java.io.IOException; 23 | import java.io.StringReader; 24 | import java.util.*; 25 | 26 | /** 27 | * Model for example manifest from r2m-examples 28 | */ 29 | public class ExamplesManifest { 30 | public static final String DESCRIPTION_SEPARATOR_KEY = " - "; 31 | 32 | private static final String FILE_KEY = "file"; 33 | private static final String DESCRIPTION_KEY = "description"; 34 | 35 | private final Map examples; 36 | 37 | public ExamplesManifest(String json) throws IOException { 38 | this.examples = new HashMap(); 39 | 40 | JsonReader reader = new JsonReader(new StringReader(json)); 41 | reader.beginObject(); 42 | while (reader.hasNext()) { 43 | String name = reader.nextName(); 44 | 45 | // single example 46 | reader.beginObject(); 47 | String file = null; 48 | String description = null; 49 | while (reader.hasNext()) { 50 | String key = reader.nextName(); 51 | if (key.equals(FILE_KEY)) { 52 | file = reader.nextString(); 53 | } else if (key.equals(DESCRIPTION_KEY)) { 54 | description = reader.nextString(); 55 | } 56 | } 57 | reader.endObject(); 58 | examples.put(name, new ExampleResource(name, file, description)); 59 | } 60 | 61 | } 62 | 63 | public List getExamplesList() { 64 | List list = new ArrayList(examples.keySet()); 65 | Collections.sort(list); 66 | return list; 67 | } 68 | 69 | public ExampleResource getExample(String name) { 70 | return examples.get(name); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/History.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | public class History { 21 | 22 | public History() { 23 | } 24 | 25 | private String[] urls; 26 | 27 | public History(String[] urls) { 28 | this.urls=urls; 29 | } 30 | 31 | public String[] getUrls() { 32 | return urls; 33 | } 34 | 35 | public void setUrls(String[] urls) { 36 | this.urls = urls; 37 | } 38 | } -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/JSONError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.magnet.langpack.builder.rest.parser.validation.DocLocation; 21 | import com.magnet.langpack.builder.rest.parser.validation.ValidationResultEntry; 22 | import com.magnet.plugin.r2m.constants.JSONErrorType; 23 | 24 | public class JSONError { 25 | protected JSONErrorType errorType; 26 | private int startIndex; 27 | private int endIndex; 28 | private ValidationResultEntry validationResultEntry; 29 | 30 | public JSONError(ValidationResultEntry validationResultEntry, int startIndex, int endIndex) { 31 | this.validationResultEntry = validationResultEntry; 32 | this.startIndex = startIndex; 33 | this.endIndex = endIndex; 34 | 35 | this.errorType = convertErrorType(validationResultEntry.getErrorType()); 36 | } 37 | 38 | public JSONErrorType getErrorType() { 39 | return errorType; 40 | } 41 | 42 | public String getErrorTypeAsString() { 43 | return errorType2String(errorType); 44 | } 45 | 46 | 47 | public void setErrorType(JSONErrorType errorType) { 48 | this.errorType = errorType; 49 | } 50 | 51 | public int getStartIndex() { 52 | return startIndex; 53 | } 54 | 55 | public void setStartIndex(int startIndex) { 56 | this.startIndex = startIndex; 57 | } 58 | 59 | public int getEndIndex() { 60 | return endIndex; 61 | } 62 | 63 | public void setEndIndex(int endIndex) { 64 | this.endIndex = endIndex; 65 | } 66 | 67 | public ValidationResultEntry.SEVERITY getSeverity() { 68 | return validationResultEntry.getSeverity(); 69 | } 70 | 71 | public DocLocation getDocLocation() { 72 | return validationResultEntry.getDocLocation(); 73 | } 74 | 75 | public String getPropertyName() { 76 | return validationResultEntry.getPropertyName(); 77 | } 78 | 79 | public String getMessage() { 80 | return validationResultEntry.getMessage(); 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | String error = ""; 86 | if ((endIndex == -1)) { 87 | error = errorType + " (line: " + startIndex + ")\n"; 88 | } else { 89 | error = errorType.toString() + "\n"; 90 | } 91 | return error; 92 | } 93 | 94 | private JSONErrorType convertErrorType(ValidationResultEntry.ErrorType validationErrorType) { 95 | switch (validationErrorType) { 96 | case INVALID_FORMAT: 97 | return JSONErrorType.ERROR_INVALID_FORMAT; 98 | case EMPTY_ARRAY: 99 | return JSONErrorType.ERROR_EMPTY_ARRAY; 100 | case EMPTY_OBJECT: 101 | return JSONErrorType.ERROR_EMPTY_DICTIONARY; 102 | default: //case NULL_PROPERTY: 103 | return JSONErrorType.ERROR_NULL_VALUE; 104 | } 105 | } 106 | 107 | private String errorType2String(JSONErrorType errorType) { 108 | switch (errorType) { 109 | case ERROR_NULL_VALUE : 110 | return "value is null"; 111 | case ERROR_EMPTY_ARRAY : 112 | return "empty array []"; 113 | case ERROR_EMPTY_DICTIONARY : 114 | return "empty object {}"; 115 | case ERROR_INVALID_FORMAT: 116 | return "invalid format"; 117 | default: 118 | return "unknown"; 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/Method.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.intellij.util.net.HTTPMethod; 21 | import com.magnet.plugin.r2m.api.models.RequestHeaderModel; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class Method { 27 | 28 | private String methodName; 29 | private String testUrl; 30 | private String templateUrl; 31 | private List headers = new ArrayList(); 32 | private List pathParts = new ArrayList(); 33 | private List queries = new ArrayList(); 34 | 35 | private String payload; 36 | private HTTPMethod httpMethod; 37 | private String response; 38 | 39 | public String getMethodName() { 40 | return methodName; 41 | } 42 | 43 | public void setMethodName(String methodName) { 44 | this.methodName = methodName; 45 | } 46 | 47 | public String getTestUrl() { 48 | return testUrl; 49 | } 50 | 51 | public void setTestUrl(String testUrl) { 52 | this.testUrl = testUrl; 53 | } 54 | 55 | public String getTemplateUrl() { 56 | return templateUrl; 57 | } 58 | 59 | public void setTemplateUrl(String templateUrl) { 60 | this.templateUrl = templateUrl; 61 | } 62 | 63 | public List getHeaders() { 64 | return headers; 65 | } 66 | 67 | public void setHeaders(List headers) { 68 | this.headers = headers; 69 | } 70 | 71 | public List getPathParts() { 72 | List pathPartList = new ArrayList(); 73 | return pathPartList; 74 | } 75 | 76 | public void setPathParts(List pathParts) { 77 | this.pathParts = pathParts; 78 | } 79 | 80 | public List getQueries() { 81 | return queries; 82 | } 83 | 84 | public void setQueries(List queries) { 85 | this.queries = queries; 86 | } 87 | 88 | public String getPayload() { 89 | return payload; 90 | } 91 | 92 | public void setPayload(String payload) { 93 | this.payload = payload; 94 | } 95 | 96 | public HTTPMethod getHttpMethod() { 97 | return httpMethod; 98 | } 99 | 100 | public void setHttpMethod(HTTPMethod httpMethod) { 101 | this.httpMethod = httpMethod; 102 | } 103 | 104 | public String getResponse() { 105 | return response; 106 | } 107 | 108 | public void setResponse(String response) { 109 | this.response = response; 110 | } 111 | 112 | @Override 113 | public String toString() { 114 | return "Method{\n" + 115 | "methodName='" + methodName + '\'' + 116 | "\n, testUrl='" + testUrl + '\'' + 117 | "\n, headers=" + headers + 118 | "\n, paths=" + pathParts + 119 | "\n, queries=" + queries + 120 | "\n, payload='" + payload + '\'' + 121 | "\n, httpMethod=" + httpMethod + 122 | "\n, response='" + response + '\'' + 123 | "\n}"; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/ParsedUrl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.magnet.plugin.common.Logger; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * Parsed URL 27 | */ 28 | public class ParsedUrl { 29 | 30 | private List pathParts = new ArrayList(); 31 | private List queries = new ArrayList(); 32 | private String baseUrl; 33 | private boolean pathEndsWithSlash; 34 | 35 | public List getPathParts() { 36 | return pathParts; 37 | } 38 | 39 | public void setPathParts(List pathParts) { 40 | this.pathParts = pathParts; 41 | } 42 | 43 | public void removePathParam(int index) { 44 | if (index > -1 && index < pathParts.size()) { 45 | pathParts.remove(index); 46 | } 47 | } 48 | 49 | public void addPathParam(PathPart pathPart) { 50 | pathParts.add(pathPart); 51 | } 52 | 53 | public boolean hasPathParams() { 54 | for (PathPart part : pathParts) { 55 | if (part.isTemplatized()) { 56 | return true; 57 | } 58 | } 59 | return false; 60 | } 61 | 62 | public List getQueries() { 63 | return queries; 64 | } 65 | 66 | public void setQueries(List queries) { 67 | this.queries = queries; 68 | } 69 | 70 | public void removeQueryParam(int index) { 71 | if (index > -1 && index < queries.size()) { 72 | queries.remove(index); 73 | } 74 | } 75 | 76 | public void addQueryParam(Query queryParam) { 77 | queries.add(queryParam); 78 | } 79 | 80 | public String getBaseUrl() { 81 | return baseUrl; 82 | } 83 | 84 | public void setBaseUrl(String baseUrl) { 85 | this.baseUrl = baseUrl; 86 | } 87 | 88 | public String buildUrl(boolean isTemplatized) { 89 | StringBuilder builder = new StringBuilder(baseUrl); 90 | for (PathPart path : pathParts) { 91 | builder.append("/"); 92 | if (isTemplatized) { 93 | builder.append(path.getTemplatizedPath()); 94 | } else { 95 | builder.append(path.getEncodedValue()); 96 | } 97 | } 98 | 99 | if (pathEndsWithSlash) { 100 | builder.append("/"); 101 | } 102 | 103 | if (queries.size() > 0) { 104 | builder.append("?"); 105 | 106 | for (Query query : queries) { 107 | String queryString = query.getEncodedKey() + "=" + query.getEncodedValue() + "&"; 108 | builder.append(queryString); 109 | } 110 | if (queries.size() > 0) { 111 | builder.deleteCharAt(builder.length() - 1); 112 | } 113 | } 114 | 115 | return builder.toString(); 116 | } 117 | 118 | 119 | public void setPathWithEndingSlash(boolean b) { 120 | pathEndsWithSlash = b; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/PathPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import com.magnet.plugin.r2m.helpers.R2MConstants; 21 | 22 | import java.io.UnsupportedEncodingException; 23 | import java.net.URLDecoder; 24 | 25 | public class PathPart { 26 | 27 | /** 28 | * path value (not url encoded) 29 | */ 30 | private String pathValue; 31 | 32 | /** 33 | * variable name attached to this path part (if templatized) 34 | */ 35 | private String variableName; 36 | /** 37 | * Whether the url has path param variables 38 | */ 39 | private boolean templatized; 40 | 41 | public PathPart() { 42 | this(""); 43 | } 44 | 45 | public PathPart(String pathValue) { 46 | this(pathValue, "", false); 47 | } 48 | 49 | public PathPart(String pathValue, String variableName) { 50 | this(pathValue, variableName, true); 51 | } 52 | 53 | private PathPart(String pathValue, String variableName, boolean templatized) { 54 | this.pathValue = pathValue; 55 | this.variableName = variableName; 56 | this.templatized = templatized; 57 | } 58 | 59 | public String getValue() { 60 | return pathValue; 61 | } 62 | 63 | public String getTemplatizedPath() { 64 | if (templatized) { 65 | String s; 66 | if(null != pathValue && !pathValue.isEmpty()) { 67 | s = variableName + ":" + pathValue; 68 | } else { 69 | s = variableName; 70 | } 71 | 72 | return R2MConstants.START_TEMPLATE_VARIABLE + s + R2MConstants.END_TEMPLATE_VARIABLE; 73 | } else { 74 | return pathValue; 75 | } 76 | } 77 | 78 | public void setValue(String pathValue) { 79 | this.pathValue = pathValue; 80 | } 81 | 82 | public String getEncodedValue() { 83 | try { 84 | return java.net.URLEncoder.encode(pathValue, "UTF-8"); 85 | } catch (UnsupportedEncodingException e) { 86 | e.printStackTrace(); 87 | }catch (NullPointerException ex){ 88 | ex.printStackTrace(); 89 | } 90 | return null; 91 | } 92 | 93 | 94 | public void setEncodedValue(String encodedValue) { 95 | try { 96 | this.pathValue = URLDecoder.decode(encodedValue, "UTF-8"); 97 | } catch (UnsupportedEncodingException e) { 98 | e.printStackTrace(); 99 | }catch (NullPointerException ex){ 100 | ex.printStackTrace(); 101 | } 102 | } 103 | 104 | public String getVariableName() { 105 | return variableName; 106 | } 107 | 108 | public void setVariableName(String variableName) { 109 | this.variableName = variableName; 110 | } 111 | 112 | public boolean isTemplatized() { 113 | return templatized; 114 | } 115 | 116 | public void setTemplatized(boolean templatized) { 117 | this.templatized = templatized; 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | return "PathPart{" + 123 | "pathValue='" + pathValue + '\'' + 124 | ", variableName='" + variableName + '\'' + 125 | ", templatized=" + templatized + 126 | '}'; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/models/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.models; 19 | 20 | import java.io.UnsupportedEncodingException; 21 | import java.net.URLDecoder; 22 | 23 | public class Query { 24 | 25 | /** 26 | * query key (not encoded) 27 | */ 28 | private String key = ""; 29 | /** 30 | * query value (not encoded) 31 | */ 32 | private String value = ""; 33 | 34 | public String getKey() { 35 | return key; 36 | } 37 | 38 | public String getEncodedKey() { 39 | try { 40 | return java.net.URLEncoder.encode(key, "UTF-8"); 41 | } catch (UnsupportedEncodingException e) { 42 | e.printStackTrace(); 43 | }catch (NullPointerException ex){ 44 | ex.printStackTrace(); 45 | } 46 | return null; 47 | } 48 | 49 | public void setKey(String key) { 50 | this.key = key; 51 | } 52 | 53 | public String getEncodedValue() { 54 | try { 55 | return java.net.URLEncoder.encode(value, "UTF-8"); 56 | } catch (UnsupportedEncodingException e) { 57 | e.printStackTrace(); 58 | }catch (NullPointerException ex){ 59 | ex.printStackTrace(); 60 | } 61 | return null; 62 | } 63 | 64 | public String getValue() { 65 | return value; 66 | } 67 | 68 | public void setEncodedValue(String encodedValue) { 69 | try { 70 | this.value = URLDecoder.decode(encodedValue, "UTF-8"); 71 | } catch (UnsupportedEncodingException e) { 72 | e.printStackTrace(); 73 | }catch (NullPointerException ex){ 74 | ex.printStackTrace(); 75 | } 76 | } 77 | 78 | public void setEncodedKey(String encodedKey) { 79 | try { 80 | this.key = URLDecoder.decode(encodedKey, "UTF-8"); 81 | } catch (UnsupportedEncodingException e) { 82 | e.printStackTrace(); 83 | }catch (NullPointerException ex){ 84 | ex.printStackTrace(); 85 | } 86 | } 87 | 88 | 89 | public void setValue(String value) { 90 | this.value = value; 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "Query{" + 96 | "key='" + key + '\'' + 97 | ", value='" + value + '\'' + 98 | '}'; 99 | } 100 | 101 | public Query(String key, String value) { 102 | this.key = key; 103 | this.value = value; 104 | } 105 | 106 | public Query() { 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/singletons/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.singletons; 19 | 20 | import com.intellij.openapi.actionSystem.AnActionEvent; 21 | import com.intellij.openapi.project.Project; 22 | import com.magnet.plugin.r2m.listeners.ControllerActionCallback; 23 | import com.magnet.plugin.r2m.ui.AddControllerForm; 24 | 25 | public class Application implements ControllerActionCallback { 26 | private static Application application; 27 | private AddControllerForm currentForm; 28 | 29 | public Application() { 30 | currentForm = null; 31 | } 32 | 33 | public static Application getApplication() { 34 | if (application == null) { 35 | application = new Application(); 36 | } 37 | return application; 38 | } 39 | 40 | public void initializeCurrentForm(Project project, AnActionEvent anAction, boolean canBeParent) { 41 | if (currentForm == null) { 42 | currentForm = new AddControllerForm(project, anAction, canBeParent, this); 43 | currentForm.show(); 44 | } else { 45 | currentForm.getThis().setVisible(true); 46 | } 47 | } 48 | 49 | public AddControllerForm getCurrentForm(Project project, AnActionEvent anAction, boolean canBeParent) { 50 | initializeCurrentForm(project, anAction, canBeParent); 51 | return currentForm; 52 | } 53 | 54 | @Override 55 | public void isDispose() { 56 | currentForm = null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/AbstractDocumentListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.ui; 19 | 20 | import javax.swing.event.DocumentEvent; 21 | import javax.swing.event.DocumentListener; 22 | 23 | public abstract class AbstractDocumentListener implements DocumentListener { 24 | 25 | abstract protected void doUpdate(); 26 | 27 | @Override 28 | public void insertUpdate(DocumentEvent documentEvent) { 29 | doUpdate(); 30 | } 31 | 32 | @Override 33 | public void removeUpdate(DocumentEvent documentEvent) { 34 | doUpdate(); 35 | } 36 | 37 | @Override 38 | public void changedUpdate(DocumentEvent documentEvent) { 39 | doUpdate(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/ControllerNameBoxItemListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.r2m.ui; 18 | 19 | import com.intellij.openapi.project.Project; 20 | import com.magnet.langpack.builder.rest.parser.RestExampleModel; 21 | import com.magnet.plugin.r2m.helpers.ControllerHistoryManager; 22 | import com.magnet.plugin.common.helpers.VerifyHelper; 23 | import com.magnet.plugin.r2m.helpers.R2MVerifyHelper; 24 | import com.magnet.plugin.r2m.project.CacheManager; 25 | 26 | import java.awt.event.ActionEvent; 27 | import java.awt.event.ActionListener; 28 | import java.awt.event.FocusEvent; 29 | import java.awt.event.FocusListener; 30 | import java.util.Arrays; 31 | import java.util.List; 32 | 33 | /** 34 | * item listener for Controller name box 35 | * when an item is selection, the form is populated with cached data, if the controller matches one of the previously 36 | * created controllers 37 | */ 38 | public class ControllerNameBoxItemListener implements ActionListener, FocusListener{ 39 | 40 | private final Project project; 41 | private final AddControllerForm form; 42 | 43 | public ControllerNameBoxItemListener(Project project, AddControllerForm form) { 44 | this.project = project; 45 | this.form = form; 46 | } 47 | 48 | private List getMethodsFromCache(String entry) { 49 | int index = entry.lastIndexOf('.'); 50 | if (index <= 0) { 51 | return null; 52 | } 53 | 54 | if (!isCacheController(entry)) { 55 | return null; 56 | } 57 | 58 | String packageName = entry.substring(0, index); 59 | String controllerName = entry.substring(index + 1); 60 | CacheManager cache = new CacheManager(project, packageName, controllerName); 61 | return cache.getControllerMethodsModel(); 62 | } 63 | 64 | private boolean isCacheController(String entry) { 65 | List cachedControllers = Arrays.asList(ControllerHistoryManager.getCachedControllers(project)); 66 | return cachedControllers.contains(entry); 67 | } 68 | 69 | @Override 70 | public void actionPerformed(ActionEvent e) { 71 | String entry; 72 | String controllerName; 73 | entry = form.getControllerName(); 74 | 75 | if (null == entry || entry.isEmpty()) { 76 | return; 77 | } 78 | 79 | String packageName; 80 | 81 | if (entry.lastIndexOf('.') <= 0) { 82 | controllerName = entry; 83 | form.populateMethods(controllerName, null, null); 84 | } else { 85 | packageName = entry.substring(0, entry.lastIndexOf('.')); 86 | controllerName = getControllerName(); 87 | if (null == controllerName) { 88 | return; 89 | } 90 | form.populateMethods(controllerName, packageName, getMethodsFromCache(entry)); 91 | } 92 | } 93 | 94 | @Override 95 | public void focusGained(FocusEvent focusEvent) { 96 | return; 97 | } 98 | 99 | @Override 100 | public void focusLost(FocusEvent focusEvent) { 101 | String controllerName = getControllerName(); 102 | if (controllerName == null) { 103 | return; 104 | } 105 | form.getControllerNameBox().getChildComponent().getEditor().setItem(controllerName); 106 | 107 | } 108 | 109 | private String getControllerName() { 110 | String entry = form.getControllerName(); 111 | 112 | if (null == entry || entry.isEmpty()) { 113 | return null; 114 | } 115 | 116 | String className = null; 117 | if (entry.lastIndexOf('.') <= 0) { 118 | className = entry; 119 | } else { 120 | className = R2MVerifyHelper.verifyClassName(entry.substring(entry.lastIndexOf('.') + 1)); 121 | } 122 | 123 | if(Character.isUpperCase(className.charAt(0))) { 124 | return className; 125 | } else { 126 | return (new StringBuilder()).append(Character.toUpperCase(className.charAt(0))).append(className.substring(1)).toString(); 127 | } 128 | } 129 | 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/BasePanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.ui.tab; 19 | 20 | import com.magnet.plugin.r2m.helpers.UIHelper; 21 | 22 | import javax.swing.*; 23 | import java.awt.*; 24 | 25 | public class BasePanel extends JPanel { 26 | 27 | protected final Font baseFont = UIHelper.getFont(); 28 | } 29 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/BaseUrlCallBack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.r2m.ui.tab; 18 | 19 | import javax.swing.*; 20 | 21 | /** 22 | * Callback triggered when user update the base url 23 | */ 24 | public interface BaseUrlCallBack { 25 | void updated(JTextField baseUrlField); 26 | } 27 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/ButtonsSection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | package com.magnet.plugin.r2m.ui.tab; 24 | 25 | import com.magnet.plugin.r2m.constants.FormConfig; 26 | import com.magnet.plugin.r2m.messages.R2MMessages; 27 | 28 | import javax.swing.*; 29 | 30 | public class ButtonsSection extends BasePanel { 31 | 32 | private JButton testApiButton; 33 | private JButton deletePanelButton; 34 | 35 | 36 | { 37 | testApiButton = new JButton(R2MMessages.getMessage("TEST_API_TEXT")); 38 | testApiButton.setToolTipText(R2MMessages.getMessage("TEST_API_TOOL_TIP")); 39 | deletePanelButton = new JButton(R2MMessages.getMessage("REMOVE_METHOD_TEXT")); 40 | deletePanelButton.setToolTipText(R2MMessages.getMessage("REMOVE_METHOD_TOOL_TIP")); 41 | deletePanelButton.setEnabled(true); 42 | 43 | testApiButton.setFont(baseFont); 44 | deletePanelButton.setFont(baseFont); 45 | 46 | GroupLayout layout = new GroupLayout(this); 47 | this.setLayout(layout); 48 | layout.setHorizontalGroup(layout.createSequentialGroup() 49 | .addComponent(testApiButton, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_BUTTON_SIZE, Short.MAX_VALUE) 50 | .addComponent(deletePanelButton, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_BUTTON_SIZE, Short.MAX_VALUE) 51 | ); 52 | layout.setVerticalGroup( 53 | layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 54 | .addComponent(testApiButton) 55 | .addComponent(deletePanelButton) 56 | ); 57 | } 58 | 59 | 60 | public JButton getTestApiButton() { 61 | return testApiButton; 62 | } 63 | 64 | public JButton getDeletePanelButton() { 65 | return deletePanelButton; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/ExtendedJPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | 24 | package com.magnet.plugin.r2m.ui.tab; 25 | 26 | import java.util.List; 27 | import java.util.concurrent.CopyOnWriteArrayList; 28 | import javax.swing.JPanel; 29 | 30 | public class ExtendedJPanel extends BasePanel{ 31 | 32 | private List panels = new CopyOnWriteArrayList(); 33 | private JPanel labelPanel; 34 | 35 | public List getPanels() { 36 | return panels; 37 | } 38 | 39 | public void addPanel(JPanel panel) { 40 | this.panels.add(panel); 41 | } 42 | 43 | public void removePanel(JPanel panel) { 44 | this.panels.remove(panel); 45 | } 46 | 47 | public void visibleLabelPanel(){ 48 | labelPanel.setVisible(!panels.isEmpty()); 49 | } 50 | 51 | public JPanel getLabelPanel() { 52 | return labelPanel; 53 | } 54 | 55 | public void setLabelPanel(JPanel labelPanel) { 56 | this.labelPanel = labelPanel; 57 | this.labelPanel.setVisible(false); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/HeaderPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this template, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.magnet.plugin.r2m.ui.tab; 23 | 24 | import com.magnet.plugin.r2m.api.models.RequestHeaderModel; 25 | import com.magnet.plugin.r2m.constants.FormConfig; 26 | import com.magnet.plugin.r2m.messages.R2MMessages; 27 | 28 | import java.awt.event.ActionListener; 29 | import javax.swing.*; 30 | 31 | /** 32 | * Swing component representing the header panel 33 | */ 34 | public class HeaderPanel extends BasePanel { 35 | 36 | private JTextField key; 37 | private JTextField value; 38 | private JButton delete; 39 | 40 | public ExtendedJPanel getParentPanel() { 41 | return parentPanel; 42 | } 43 | 44 | private ExtendedJPanel parentPanel; 45 | 46 | private final RequestHeaderModel header; 47 | 48 | public ActionListener getListener() { 49 | return listener; 50 | } 51 | 52 | public void setListener(ActionListener listener) { 53 | this.listener = listener; 54 | delete.addActionListener(listener); 55 | 56 | } 57 | 58 | private ActionListener listener; 59 | 60 | public HeaderPanel(ExtendedJPanel parentPanel, RequestHeaderModel header) { 61 | this.parentPanel = parentPanel; 62 | this.parentPanel.addPanel(this); 63 | this.header = header; 64 | } 65 | 66 | 67 | { 68 | key = new JTextField(); 69 | value = new JTextField(); 70 | delete = new JButton(R2MMessages.getMessage("SECTION_DELETE")); 71 | 72 | delete.addActionListener(listener); 73 | 74 | key.setFont(baseFont); 75 | value.setFont(baseFont); 76 | delete.setFont(baseFont); 77 | 78 | 79 | GroupLayout jPanel2Layout = new GroupLayout(this); 80 | this.setLayout(jPanel2Layout); 81 | jPanel2Layout.setHorizontalGroup( 82 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 83 | .addGroup(jPanel2Layout.createSequentialGroup() 84 | .addComponent(key, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 85 | .addComponent(value, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 86 | .addComponent(delete))); 87 | jPanel2Layout.setVerticalGroup( 88 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 89 | .addGroup(GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 90 | .addComponent(key) 91 | .addComponent(value) 92 | .addComponent(delete))); 93 | } 94 | 95 | 96 | 97 | public RequestHeaderModel getHeader() { 98 | header.setValue(value.getText()); 99 | header.setName(key.getText()); 100 | return header; 101 | } 102 | 103 | public void setHeader(String key, String value) { 104 | this.value.setText(value); 105 | this.key.setText(key); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/HeaderPanelLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this template, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.magnet.plugin.r2m.ui.tab; 23 | 24 | import com.magnet.plugin.r2m.constants.FormConfig; 25 | 26 | import javax.swing.*; 27 | 28 | public class HeaderPanelLabel extends BasePanel { 29 | 30 | private JLabel key; 31 | private JLabel value; 32 | 33 | { 34 | key = new JLabel(); 35 | value = new JLabel(); 36 | 37 | key.setText("Key"); 38 | value.setText("Value"); 39 | 40 | key.setFont(baseFont); 41 | value.setFont(baseFont); 42 | 43 | GroupLayout jPanel2Layout = new GroupLayout(this); 44 | this.setLayout(jPanel2Layout); 45 | jPanel2Layout.setHorizontalGroup( 46 | jPanel2Layout.createSequentialGroup() 47 | .addComponent(key, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 48 | .addComponent(value, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 49 | .addGap(30)); 50 | jPanel2Layout.setVerticalGroup( 51 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 52 | // .addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 53 | .addComponent(key) 54 | .addComponent(value)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/HeaderSection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | package com.magnet.plugin.r2m.ui.tab; 24 | 25 | import com.magnet.plugin.r2m.api.models.RequestHeaderModel; 26 | import com.magnet.plugin.r2m.constants.FormConfig; 27 | import com.magnet.plugin.r2m.messages.R2MMessages; 28 | 29 | import javax.swing.*; 30 | import java.awt.event.ActionEvent; 31 | import java.awt.event.ActionListener; 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | public class HeaderSection extends ExtendedJPanel { 36 | 37 | public List getHeaders() { 38 | List headerList = new ArrayList(); 39 | for (HeaderPanel panel : headers) { 40 | headerList.add(panel.getHeader()); 41 | } 42 | return headerList; 43 | } 44 | 45 | private List headers = new ArrayList(); 46 | 47 | private GroupLayout.ParallelGroup customGroupHorizontal; 48 | private GroupLayout.SequentialGroup customGroupVertical; 49 | 50 | { 51 | JLabel jLabel4 = new JLabel(); 52 | JSeparator jSeparator1 = new JSeparator(); 53 | jSeparator1.setOpaque(false); 54 | JLabel jLabel5 = new JLabel(); 55 | JButton jButton1 = new JButton(); 56 | 57 | setLabelPanel(new HeaderPanelLabel()); 58 | 59 | jLabel4.setText(R2MMessages.getMessage("HEADER_SECTION_NAME")); 60 | jLabel5.setText(R2MMessages.getMessage("SECTION_ADD_NEW")); 61 | jButton1.setText(R2MMessages.getMessage("SECTION_PLUS")); 62 | 63 | jLabel4.setFont(baseFont); 64 | jLabel5.setFont(baseFont); 65 | jButton1.setFont(baseFont); 66 | 67 | jButton1.addActionListener(new ActionListener() { 68 | 69 | @Override 70 | public void actionPerformed(ActionEvent evt) { 71 | addHeader(evt); 72 | } 73 | }); 74 | 75 | GroupLayout layout = new GroupLayout(this); 76 | this.setLayout(layout); 77 | 78 | customGroupHorizontal = layout.createParallelGroup(GroupLayout.Alignment.LEADING); 79 | customGroupVertical = layout.createSequentialGroup(); 80 | 81 | layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 82 | .addGroup(layout.createSequentialGroup() 83 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 84 | .addGap(FormConfig.CUSTOM_GAP) 85 | .addComponent(jLabel4, GroupLayout.Alignment.TRAILING) 86 | ) 87 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 88 | .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup() 89 | .addComponent(jSeparator1) 90 | .addComponent(jLabel5) 91 | .addComponent(jButton1)) 92 | .addComponent(getLabelPanel(), GroupLayout.Alignment.CENTER) 93 | .addGroup(customGroupHorizontal)))); 94 | 95 | layout.setVerticalGroup(layout.createSequentialGroup() 96 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER) 97 | .addComponent(jLabel4) 98 | .addComponent(jSeparator1, FormConfig.SEPARATOR_CUSTOM_SIZE, FormConfig.SEPARATOR_CUSTOM_SIZE, FormConfig.SEPARATOR_CUSTOM_SIZE) 99 | .addComponent(jLabel5) 100 | .addComponent(jButton1) 101 | ) 102 | .addComponent(getLabelPanel()) 103 | .addGroup(customGroupVertical) 104 | ); 105 | 106 | } 107 | 108 | private void addHeader(ActionEvent evt) { 109 | addHeader(null, null); 110 | } 111 | 112 | public void addHeader(String key, String value) { 113 | RequestHeaderModel header = new RequestHeaderModel(); 114 | HeaderPanel panel = new HeaderPanel(this, header); 115 | headers.add(panel); 116 | if (key != null && !key.isEmpty()) { 117 | panel.setHeader(key, value); 118 | } 119 | 120 | ActionListener listener = new HeaderAction(panel); 121 | panel.setListener(listener); 122 | 123 | customGroupHorizontal.addComponent(panel); 124 | customGroupVertical.addComponent(panel); 125 | 126 | this.visibleLabelPanel(); 127 | this.revalidate(); 128 | this.validate(); 129 | this.repaint(); 130 | } 131 | 132 | private class HeaderAction implements ActionListener { 133 | 134 | private final HeaderPanel panel; 135 | 136 | private HeaderAction(HeaderPanel panel) { 137 | this.panel = panel; 138 | } 139 | 140 | @Override 141 | public void actionPerformed(ActionEvent e) { 142 | headers.remove(panel); 143 | deleteThisPanel(); 144 | } 145 | 146 | private void deleteThisPanel() { 147 | panel.getParentPanel().remove(panel); 148 | panel.getParentPanel().removePanel(panel); 149 | panel.getParentPanel().visibleLabelPanel(); 150 | panel.getParentPanel().revalidate(); 151 | panel.getParentPanel().validate(); 152 | panel.getParentPanel().repaint(); 153 | } 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/PathPartLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this template, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.magnet.plugin.r2m.ui.tab; 23 | 24 | import com.magnet.plugin.r2m.constants.FormConfig; 25 | import com.magnet.plugin.r2m.messages.R2MMessages; 26 | 27 | import javax.swing.*; 28 | 29 | public class PathPartLabel extends BasePanel { 30 | 31 | { 32 | JLabel pathLabel = new JLabel(); 33 | JLabel variableLabel = new JLabel(); 34 | JLabel variableNameLabel = new JLabel(); 35 | 36 | pathLabel.setText(R2MMessages.getMessage("PATH_PART_NAME")); 37 | variableLabel.setText(R2MMessages.getMessage("PATH_VARIABLE_CHECKBOX_NAME")); 38 | variableNameLabel.setText(R2MMessages.getMessage("PATH_VARIABLE_NAME")); 39 | 40 | pathLabel.setFont(baseFont); 41 | variableLabel.setFont(baseFont); 42 | variableNameLabel.setFont(baseFont); 43 | 44 | GroupLayout pathParamLabelsLayout = new GroupLayout(this); 45 | this.setLayout(pathParamLabelsLayout); 46 | pathParamLabelsLayout.setHorizontalGroup( 47 | pathParamLabelsLayout.createSequentialGroup() 48 | .addComponent(pathLabel, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 49 | .addComponent(variableLabel, GroupLayout.DEFAULT_SIZE, FormConfig.PATH_CHECKBOX_PREF_SIZE, FormConfig.PATH_CHECKBOX_MAX_SIZE) 50 | .addComponent(variableNameLabel, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE)); 51 | pathParamLabelsLayout.setVerticalGroup( 52 | pathParamLabelsLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 53 | .addComponent(pathLabel) 54 | .addComponent(variableLabel) 55 | .addComponent(variableNameLabel)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/QueryPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | package com.magnet.plugin.r2m.ui.tab; 19 | 20 | import com.magnet.plugin.common.ui.HintTextField; 21 | import com.magnet.plugin.r2m.messages.R2MMessages; 22 | import com.magnet.plugin.r2m.models.Query; 23 | import com.magnet.plugin.r2m.constants.FormConfig; 24 | import com.magnet.plugin.r2m.ui.AbstractDocumentListener; 25 | 26 | import javax.swing.*; 27 | import java.awt.event.ActionEvent; 28 | import java.awt.event.ActionListener; 29 | 30 | import static com.magnet.plugin.r2m.helpers.UIHelper.ERROR_REQUIRED_FIELD; 31 | 32 | public class QueryPanel extends BasePanel { 33 | 34 | private HintTextField key; 35 | private HintTextField value; 36 | 37 | private QueryParamCallBack callBack; 38 | 39 | private Query query; 40 | 41 | public QueryPanel(QueryParamCallBack callBack, Query query) { 42 | this.callBack = callBack; 43 | this.query = query; 44 | key.setText(query.getKey()); 45 | value.setText(query.getValue()); 46 | } 47 | 48 | { 49 | key = new HintTextField(""); 50 | key.setFont(baseFont); 51 | key.getDocument().addDocumentListener(new AbstractDocumentListener() { 52 | 53 | @Override 54 | protected void doUpdate() { 55 | query.setKey(key.getText()); 56 | callBack.updated(QueryPanel.this); 57 | } 58 | }); 59 | 60 | value = new HintTextField(""); 61 | value.setFont(baseFont); 62 | value.getDocument().addDocumentListener(new AbstractDocumentListener() { 63 | 64 | @Override 65 | protected void doUpdate() { 66 | query.setValue(value.getText()); 67 | callBack.updated(QueryPanel.this); 68 | } 69 | }); 70 | 71 | JButton delete = new JButton(R2MMessages.getMessage("SECTION_DELETE")); 72 | delete.setFont(baseFont); 73 | 74 | key.setHint(ERROR_REQUIRED_FIELD); 75 | value.setHint(ERROR_REQUIRED_FIELD); 76 | 77 | delete.addActionListener(new ActionListener() { 78 | 79 | @Override 80 | public void actionPerformed(ActionEvent evt) { 81 | callBack.deleted(QueryPanel.this); 82 | } 83 | }); 84 | 85 | 86 | GroupLayout jPanel2Layout = new GroupLayout(this); 87 | this.setLayout(jPanel2Layout); 88 | jPanel2Layout.setHorizontalGroup( 89 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 90 | .addGroup(jPanel2Layout.createSequentialGroup() 91 | .addComponent(key, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 92 | .addComponent(value, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 93 | .addComponent(delete))); 94 | jPanel2Layout.setVerticalGroup( 95 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 96 | .addGroup(GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 97 | .addComponent(key) 98 | .addComponent(value) 99 | .addComponent(delete))); 100 | } 101 | 102 | public Query getQuery() { 103 | query.setKey(key.getText()); 104 | query.setValue(value.getText()); 105 | return query; 106 | } 107 | 108 | public boolean checkRequirementField() { 109 | return !key.getText().trim().equalsIgnoreCase("") && !value.getText().trim().equalsIgnoreCase(""); 110 | 111 | } 112 | 113 | /** 114 | * Callback interface to handle events in this panel 115 | */ 116 | public interface QueryParamCallBack { 117 | void deleted(QueryPanel queryPanel); 118 | 119 | void updated(QueryPanel queryPanel); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/QueryPanelLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this template, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.magnet.plugin.r2m.ui.tab; 23 | 24 | import com.magnet.plugin.r2m.constants.FormConfig; 25 | 26 | import javax.swing.*; 27 | 28 | public class QueryPanelLabel extends BasePanel { 29 | 30 | private JLabel key; 31 | private JLabel value; 32 | 33 | { 34 | key = new JLabel(); 35 | value = new JLabel(); 36 | 37 | key.setText("Key"); 38 | value.setText("Value"); 39 | 40 | key.setFont(baseFont); 41 | value.setFont(baseFont); 42 | 43 | GroupLayout jPanel2Layout = new GroupLayout(this); 44 | this.setLayout(jPanel2Layout); 45 | jPanel2Layout.setHorizontalGroup( 46 | jPanel2Layout.createSequentialGroup() 47 | .addComponent(key, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 48 | .addComponent(value, GroupLayout.DEFAULT_SIZE, FormConfig.CUSTOM_PREF_SIZE, Short.MAX_VALUE) 49 | .addGap(30)); 50 | jPanel2Layout.setVerticalGroup( 51 | jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) 52 | .addComponent(key) 53 | .addComponent(value)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/RequestPayloadSection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | package com.magnet.plugin.r2m.ui.tab; 24 | 25 | public class RequestPayloadSection extends PayloadPanel { 26 | private static final String _TYPE = "Request"; 27 | 28 | protected String getType() { 29 | return _TYPE; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/ResponsePayloadSection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | 18 | /* 19 | * To change this license header, choose License Headers in Project Properties. 20 | * To change this template file, choose Tools | Templates 21 | * and open the template in the editor. 22 | */ 23 | package com.magnet.plugin.r2m.ui.tab; 24 | 25 | public class ResponsePayloadSection extends PayloadPanel { 26 | private static final String _TYPE = "Response"; 27 | 28 | protected String getType() { 29 | return _TYPE; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/magnet/plugin/r2m/ui/tab/TabManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Magnet Systems, Inc. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you 6 | * may not use this file except in compliance with the License. You 7 | * may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | * implied. See the License for the specific language governing 15 | * permissions and limitations under the License. 16 | */ 17 | package com.magnet.plugin.r2m.ui.tab; 18 | 19 | import com.beust.jcommander.internal.Lists; 20 | import com.intellij.openapi.project.Project; 21 | import com.magnet.plugin.common.Logger; 22 | import com.magnet.plugin.r2m.listeners.TabRemoveListener; 23 | import com.magnet.plugin.r2m.messages.R2MMessages; 24 | import com.magnet.plugin.r2m.ui.AddControllerForm; 25 | 26 | import javax.swing.*; 27 | import javax.swing.event.ChangeEvent; 28 | import javax.swing.event.ChangeListener; 29 | import java.util.ArrayList; 30 | import java.util.Collections; 31 | import java.util.List; 32 | 33 | /** 34 | * Manage the method tabs in form 35 | */ 36 | public class TabManager { 37 | private final Project project; 38 | private final AddControllerForm form; 39 | 40 | private final JTabbedPane tabPanel; 41 | 42 | private final List tabs; 43 | 44 | public TabManager(Project project, AddControllerForm form, JTabbedPane tabPanel) { 45 | this.project = project; 46 | this.form = form; 47 | this.tabPanel = tabPanel; 48 | this.tabs = new ArrayList(); 49 | 50 | init(); 51 | 52 | } 53 | 54 | /** 55 | * Initialize the tabs 56 | */ 57 | private void init() { 58 | MethodTabPanel customTab = new MethodTabPanel(project, form, tabPanel); 59 | customTab.setTabRemoveListener(tabRemoveListener); 60 | customTab.setIndex(0); 61 | tabs.add(customTab); 62 | tabPanel.addTab(R2MMessages.getMessage("METHOD_N", 1), customTab); 63 | tabPanel.addTab(R2MMessages.getMessage("PLUS_TAB"), new JLabel("")); 64 | tabPanel.addChangeListener(tabListener); 65 | } 66 | 67 | public MethodTabPanel addNewTab(int index) { 68 | MethodTabPanel customTab = new MethodTabPanel(project, form, tabPanel); 69 | customTab.setTabRemoveListener(tabRemoveListener); 70 | customTab.setIndex(index); 71 | 72 | tabs.add(customTab); 73 | 74 | // now add new tab in panel 75 | // clean up first 76 | // remove change listener 77 | tabPanel.removeChangeListener(tabListener); 78 | 79 | // remove "+" tab 80 | tabPanel.remove(index); 81 | // add "method N" tab 82 | tabPanel.addTab(R2MMessages.getMessage("METHOD_N", index + 1), customTab); 83 | // add "+" tab 84 | tabPanel.addTab(R2MMessages.getMessage("PLUS_TAB"), new JLabel("")); 85 | // set selected index 86 | tabPanel.setSelectedIndex(index); 87 | 88 | // add listener back 89 | tabPanel.addChangeListener(tabListener); 90 | updateRemoveButtons(); 91 | return customTab; 92 | } 93 | 94 | public void removeAllTabs() { 95 | tabPanel.removeChangeListener(tabListener); 96 | for (MethodTabPanel tab : getTabs() /* use a copy */) { 97 | removeTab(tab); 98 | } 99 | tabPanel.addChangeListener(tabListener); 100 | } 101 | 102 | public void removeTab(MethodTabPanel methodTabPanel) { 103 | tabs.remove(methodTabPanel); 104 | tabPanel.setSelectedIndex(0); 105 | tabPanel.remove(methodTabPanel); 106 | tabPanel.invalidate(); 107 | } 108 | 109 | public void selectTab(int index) { 110 | if(index >= 0 && index < tabs.size()) { 111 | tabPanel.setSelectedIndex(index); 112 | } 113 | } 114 | 115 | private ChangeListener tabListener = new ChangeListener() { 116 | @Override 117 | public void stateChanged(ChangeEvent e) { 118 | int lastSelected = tabPanel.getSelectedIndex(); 119 | Logger.info(getClass(), "" + lastSelected); 120 | if (lastSelected == tabPanel.getTabCount() - 1) { // the last index i.e. "+" button 121 | addNewTab(lastSelected); 122 | updateRemoveButtons(); 123 | tabPanel.revalidate(); 124 | 125 | } 126 | } 127 | }; 128 | 129 | private TabRemoveListener tabRemoveListener = new TabRemoveListener() { 130 | @Override 131 | public void removeCurrentPanel(MethodTabPanel methodTabPanel) { 132 | if (tabPanel.getTabCount() > 1) { 133 | removeTab(methodTabPanel); 134 | // do not delete the method example file. 135 | // Users will be asked whether they want to keep it on or not at generation time. 136 | updateRemoveButtons(); 137 | } 138 | } 139 | }; 140 | 141 | 142 | public void updateRemoveButtons() { 143 | for (int i = 0; i < tabs.size(); i++) { 144 | tabs.get(i).setIndex(i); 145 | } 146 | for (MethodTabPanel panel : tabs) { 147 | panel.enableRemoveButton(tabs.size() > 0); 148 | } 149 | } 150 | 151 | /** 152 | * @return an immutable copy of the tabs list 153 | */ 154 | public List getTabs() { 155 | return Collections.unmodifiableList(Lists.newArrayList(tabs)); 156 | } 157 | 158 | public JTabbedPane getTabPanel() { 159 | return tabPanel; 160 | } 161 | 162 | 163 | 164 | } 165 | -------------------------------------------------------------------------------- /version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014 Magnet Systems, Inc. 3 | # All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you 6 | # may not use this file except in compliance with the License. You 7 | # may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | # implied. See the License for the specific language governing 15 | # permissions and limitations under the License. 16 | # 17 | 18 | version=1.1.12 19 | downloadUrl=https://github.com/magnetsystems/r2m-plugin-android/releases/download/1.1.12/r2m-plugin-android-1.1.12.zip 20 | sha1=03ff0c86419f2ab7297b350277dcab5de803a2f6 21 | description=Android Studio and IntelliJ IDEA plugin 1.1.12 22 | comments=(Release 1.1.12) Changes from release 1.1.0:\n \ 23 | - automatically show generated controller class after generation\n \ 24 | - show gradle snippet explaining how to include R2M dependencies\n \ 25 | - fix URLSection NPE 26 | - fix issue with URL encoding\n \ 27 | - fix for 'REST API requiring an ending slash can't be invoked' (issue #19)\n \ 28 | 29 | 30 | --------------------------------------------------------------------------------