{"id":128978,"date":"2018-05-29T11:14:49","date_gmt":"2018-05-29T09:14:49","guid":{"rendered":"https:\/\/www.justinmind.com\/blog\/how-to-use-justinminds-api\/"},"modified":"2018-05-29T11:14:49","modified_gmt":"2018-05-29T09:14:49","slug":"how-to-use-justinminds-api","status":"publish","type":"post","link":"https:\/\/www.justinmind.com\/de\/hilfe\/wie-verwendet-justinminds-api","title":{"rendered":"Wie man Justinmind Plugins erstellt"},"content":{"rendered":"<p>Starten Sie die Eclipse-App in Ihrem JustinmindSDK-Ordner. W\u00e4hlen Sie dann einen Ordner, in dem Sie Ihren Arbeitsbereich speichern m\u00f6chten und klicken Sie auf &#8222;Dies als Standard verwenden und nicht mehr nachfragen&#8220;. <\/p>\n<h2><a id=\"plugin-setup\"><\/a>Erste Einrichtung<\/h2>\n<p>W\u00e4hlen Sie dann &#8222;Neues Java-Projekt erstellen&#8230;&#8220;.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/welcome-justinmindsdk.png\" alt=\"willkommen-justinmindsdk\"><\/p>\n<p>W\u00e4hlen Sie einen Namen f\u00fcr Ihr Plugin und stellen Sie sicher, dass die ausgew\u00e4hlte Ausf\u00fchrungsumgebung JRE &#8218;JavaSE-11&#8216; ist. Klicken Sie dann auf Weiter.<br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/new-plugin-justinmindsdk.png\" alt=\"newplugin-justinmindsdk\"><\/p>\n<p>Klicken Sie in den Java-Einstellungen auf die Registerkarte Bibliotheken. W\u00e4hlen Sie &#8222;ModulePath&#8220; und f\u00fcgen Sie alle JavaFX-Module hinzu, die Sie im Ordner &#8218;javafx&#8216; innerhalb des Ordners &#8218;JustinmindPluginSDK&#8216; finden, indem Sie die Option Externe JARS hinzuf\u00fcgen verwenden. <\/p>\n<p>F\u00fcr Windows : JustinmindPluginSDK\/javafx\/lib<\/p>\n<p>F\u00fcr MacOS: Anwendungen\/JustinmindPluginSDK\/javafx\/lib<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/setup-modules-justinmindskd.png\" alt=\"module-justinmindsdk\"><\/p>\n<p>W\u00e4hlen Sie &#8222;Klassenpfad&#8220; und f\u00fcgen Sie alle Jars hinzu, die im Ordner &#8218;api_plugins&#8216; enthalten sind, den Sie im Ordner JustinmindSDK finden.<\/p>\n<p>F\u00fcr Windows : JustinmindPluginSDK\/api_plugins\/<\/p>\n<p>F\u00fcr MacOS: \/Programme\/JustinmindPluginSDK\/api_plugins\/<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/setup-classpath-justinmindsdk.png\" alt=\"klassenpfad-justinmindsdk\"><\/p>\n<p>Klicken Sie auf Fertig stellen.<\/p>\n<p>W\u00e4hlen Sie die Option Don&#8217;t create module-info.java, wenn Sie dazu aufgefordert werden.<\/p>\n<p>Jetzt haben wir das Haupt-Java-Projekt erstellt, das den Code unseres Plugins enthalten wird.<\/p>\n<h2><a id=\"write-your-plugin\"><\/a>Schreiben Sie Ihr Plugin<\/h2>\n<p><strong>Struktur<\/strong><\/p>\n<p>Die Struktur eines Justinmind-Plugins ist sehr einfach. Sie ben\u00f6tigen lediglich eine Hauptklassendatei, die den Ausf\u00fchrungscode f\u00fcr die Aktion Ihres Plugins enth\u00e4lt. Diese Klasse muss die Justinmind API-Schnittstelle &#8218;IPlugin&#8216; implementieren.  <\/p>\n<p>IPlugin definiert zwei Methoden:<\/p>\n<p>getName() &#8211; diese Methode definiert den Namen, der in der Justinmind UI angezeigt wird, sobald Ihr Plugin installiert ist.<\/p>\n<p>run() &#8211; was Ihr Plugin macht.<\/p>\n<p>Erstellen Sie die Klassendatei. Klicken Sie mit der rechten Maustaste auf Ihren Plugin-Ordner &#8217;src&#8216; und w\u00e4hlen Sie Neue&gt;Klasse. <\/p>\n<p>Geben Sie Ihrer Hauptklasse einen Namen und w\u00e4hlen Sie die IPlugin-Schnittstelle aus dem Paket com.justinmind.prototyper.api.plugins. Klicken Sie auf Fertigstellen. <\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/create-plugin-class-justinmindsdk.png\" alt=\"createplugin-justinmindsdk\"><\/p>\n<p>Jetzt k\u00f6nnen Sie Ihren Code schreiben.<\/p>\n<h2><a id=\"example-plugin-one\"><\/a>Beispiel: alle Texte in eine CSV-Datei exportieren<\/h2>\n<pre>import java.awt.Desktop;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.util.List;\nimport com.justinmind.pcontrols.ControlUtils;\nimport com.justinmind.prototyper.api.API;\nimport com.justinmind.prototyper.api.IPrototype;\nimport com.justinmind.prototyper.api.plugins.IPlugin;\nimport com.justinmind.prototyper.api.ui.canvas.ICanvas;\nimport com.justinmind.prototyper.api.ui.component.ICanvasComponent;\nimport com.justinmind.prototyper.api.ui.component.IImage;\nimport com.justinmind.prototyper.api.ui.component.IInput;\nimport com.justinmind.prototyper.api.ui.component.IValuedComponent;\nimport javafx.stage.FileChooser;\n\npublic class TestPlugin implements IPlugin { \n\n  @Override\n  public void run() {\n    try {\n      IPrototype prototype = API.getPrototypeLoader().loadPrototype();\n      List canvas = prototype.getApiCanvases();\n      String content = \"Word in prototype\\n\\n\";\n      for (ICanvas current : canvas) {\n        content += \"Screen: \" + current.getApiName() + \"\\n\";\n        List components = current.getApiRoot().getApiChildren();\n        for (ICanvasComponent iComponent : components) {\n          content += addTextsToContent(iComponent);\n        }\n      }\n \n      FileChooser dialog = new FileChooser();\n      FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(\"CSV files (*.csv)\", \"*.csv\");\n      dialog.getExtensionFilters().add(extFilter);\n      File file = dialog.showSaveDialog(ControlUtils.getMainWindow());\n      if (file != null) {\n        Writer output = null;\n        FileWriter fw = null;\n        try {\n          fw = new FileWriter(file);\n          output = new BufferedWriter(fw);\n          output.write(content);\n          output.close();\n          Desktop.getDesktop().open(file);\n        } catch (IOException e) {\n          Alert a = new Alert(AlertType.ERROR);\n          a.setContentText(e.getLocalizedMessage());\n          a.show();\n        }\n      } else {\n        \/\/ show error\n      }\n    } catch (Exception e) {\n      Alert a = new Alert(AlertType.ERROR);\n      a.setContentText(e.getLocalizedMessage());\n      a.show();\n    }\n  } \n\n  private String addTextsToContent(ICanvasComponent iComponent) {\n    String content = \"\";\n    if (iComponent instanceof IValuedComponent &amp;&amp; !(iComponent instanceof IImage) &amp;&amp; !(iComponent instanceof IInput)) {\n      content += ((IValuedComponent) iComponent).getApiValue() + \"\\n\";\n    }\n    List components = iComponent.getApiChildren();\n    for (ICanvasComponent current_child : components) {\n      content += addTextsToContent(current_child);\n    }\n    return content;\n  }\n\n  @Override\n  public String getName() {\n    return \"Test Plugin\";\n  }\n}\n<\/pre>\n<h2><a id=\"deploy-plugin\"><\/a>Einsatz<\/h2>\n<p>Sobald Ihr Code fertig ist, m\u00fcssen Sie ihn als JAR-Datei exportieren, um ein g\u00fcltiges installierbares Plugin in Justinmind zu erstellen.<\/p>\n<p>Klicken Sie mit der rechten Maustaste auf Ihr Plugin-Projekt und w\u00e4hlen Sie Exportieren.<\/p>\n<p>W\u00e4hlen Sie unter Java die JAR-Datei aus und klicken Sie auf Weiter.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/select-jar-justinmindsdk.png\" alt=\"selectjar-justinmindsdk\"><\/p>\n<p>W\u00e4hlen Sie ein Exportziel aus, wobei Sie alle anderen Optionen als Standard belassen, und klicken Sie auf Fertig stellen.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14303\" src=\"https:\/\/www.justinmind.com\/wp-content\/uploads\/2021\/02\/export-plugin-justinmindsdk.png\" alt=\"export-justinmindsdk\"><\/p>\n<h2><a id=\"install-plugin\"><\/a>Installieren und ausf\u00fchren<\/h2>\n<p>Sobald wir unser Plugin in eine JAR-Datei gepackt haben, m\u00fcssen wir es in unserer Justinmind-App installieren, um es ausf\u00fchren zu k\u00f6nnen.<\/p>\n<p>\u00d6ffnen Sie Justinmind und \u00f6ffnen Sie das Men\u00fc Plug-ins.<\/p>\n<p>W\u00e4hlen Sie die Option Ein Plug-in installieren&#8230;<\/p>\n<p>W\u00e4hlen Sie die exportierte JAR-Datei mit Ihrem Plugin und klicken Sie auf \u00d6ffnen.<\/p>\n<p>Danach wird Ihr Plugin installiert und unter dem Men\u00fc Plugins erscheint eine neue Option mit dem Namen, den Sie bei der Implementierung Ihres Plugins gew\u00e4hlt haben. Um es auszuf\u00fchren, klicken Sie einfach darauf. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starten Sie die Eclipse-App in Ihrem JustinmindSDK-Ordner. W\u00e4hlen Sie dann einen Ordner, in dem Sie Ihren Arbeitsbereich speichern m\u00f6chten und klicken Sie auf &#8222;Dies als Standard&#8230;<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[8546,8551],"tags":[],"class_list":["post-128978","post","type-post","status-publish","format-standard","hentry","category-benutzerhandbuch","category-api-und-plugins"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/posts\/128978"}],"collection":[{"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/comments?post=128978"}],"version-history":[{"count":0,"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/posts\/128978\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/media?parent=128978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/categories?post=128978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justinmind.com\/de\/wp-json\/wp\/v2\/tags?post=128978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}