Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add desktop demo for function mapper #30

Merged
merged 6 commits into from Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions cloudlink-function-mapper-desktop/.gitignore
@@ -0,0 +1,9 @@
# Maven
target/

# IntelliJ IDEA
cloudlinkdemo.iml
.idea/

# Gluon
gluoncloudlink_config.json
24 changes: 24 additions & 0 deletions cloudlink-function-mapper-desktop/LICENSE
@@ -0,0 +1,24 @@
Copyright (c) 2019, Gluon
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Gluon, any associated website, nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 changes: 29 additions & 0 deletions cloudlink-function-mapper-desktop/README.md
@@ -0,0 +1,29 @@

CloudLink-Function-Mapper-Desktop
===========

Learn how you can retrieve external data in your JavaFX desktop application by configuring Remote Functions in Gluon CloudLink.
The Java code calls a function with parameters, and this function makes a request to Gluon CloudLink.
The Function Mapper in Gluon CloudLink will then call the corresponding external endpoint, providing the required parameters.

Prerequisites
-------------

* JDK 11
* `JAVA_HOME` environment variable pointing to JDK 11.
* You need a valid subscription to Gluon CloudLink. You can get it [here](http://gluonhq.com/products/cloudlink/buy/), and there is a 30-day free trial. Sign up and get a valid account on Gluon CloudLink to sign in on [Gluon Dashboard](https://gluon.io).
* Create the remote functions used by this sample in the Dashboard's API Management view, as explained in the documentation linked below.

Instructions
------------

To execute the sample, do as follows:

```
mvn javafx:run
```

Documentation
-------------

Read how to create this sample step by step [here](http://docs.gluonhq.com/samples/functionmapperdesktop/)
84 changes: 84 additions & 0 deletions cloudlink-function-mapper-desktop/pom.xml
@@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gluonhq</groupId>
<artifactId>cloudlink-function-mapper-desktop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>gluon-private-snapshot</id>
<url>https://nexus.gluonhq.com/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>Gluon-Public-Snapshot</id>
<url>https://nexus.gluonhq.com/nexus/content/repositories/public-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>com.gluonhq</groupId>
<artifactId>charm-cloudlink-client</artifactId>
tiainen marked this conversation as resolved.
Show resolved Hide resolved
<version>6.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>cache</artifactId>
<version>4.0.0-SNAPSHOT</version>
<classifier>desktop</classifier>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>storage</artifactId>
<version>4.0.0-SNAPSHOT</version>
<classifier>desktop</classifier>
</dependency>

<!-- Cloudlink client should expose these dependencies -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>1.1.5</version>
<classifier>module</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>com.gluonhq.functionmapper.FunctionMapper</mainClass>
<options>
<option>--add-modules</option>
<option>com.gluonhq.cloudlink.client</option>
</options>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2019, Gluon
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Gluon, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.gluonhq.functionmapper;

import com.gluonhq.functionmapper.service.RemoteService;
import com.gluonhq.functionmapper.views.AbstractController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class FunctionMapper extends Application {

private static Scene scene;
private RemoteService remoteService;
private static Map<String, FXMLLoader> viewCache = new HashMap<>();

@Override
public void start(Stage stage) {
scene = new Scene(getController("main").getRoot(), 800, 600);
scene.getStylesheets().add(FunctionMapper.class.getResource("functionmapper.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Stackoverflow Question & Answers");
stage.show();
}

public void setRoot(Parent parent) {
scene.setRoot(parent);
}

public AbstractController getController(String fxml) {
FXMLLoader fxmlLoader = loadFXML(fxml);
AbstractController controller = fxmlLoader.getController();
controller.setApp(this);
return controller;
}

public RemoteService service() {
if (remoteService == null) {
remoteService = new RemoteService();
}
return remoteService;
}

private static FXMLLoader loadFXML(String fxml) {
return viewCache.computeIfAbsent(fxml, name -> {
FXMLLoader fxmlLoader = new FXMLLoader(FunctionMapper.class.getResource("views/" + name + ".fxml"));
try {
fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
return fxmlLoader;
});
}
}
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2019, Gluon
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Gluon, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.gluonhq.functionmapper.model;

public class StackEntry {

private int answer_count;
private long creation_date;
private boolean is_accepted;
private String link;
private StackOwner owner;
private long question_id;
private int score;
private String title;

public int getAnswer_count() {
return answer_count;
}

public void setAnswer_count(int answer_count) {
this.answer_count = answer_count;
}

public long getCreation_date() {
return creation_date;
}

public void setCreation_date(long creation_date) {
this.creation_date = creation_date;
}

public boolean isIs_accepted() {
return is_accepted;
}

public void setIs_accepted(boolean is_accepted) {
this.is_accepted = is_accepted;
}

public String getLink() {
return link;
}

public void setLink(String link) {
this.link = link;
}

public StackOwner getOwner() {
return owner;
}

public void setOwner(StackOwner owner) {
this.owner = owner;
}

public long getQuestion_id() {
return question_id;
}

public void setQuestion_id(long question_id) {
this.question_id = question_id;
}

public int getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

@Override
public String toString() {
return "StackEntry{" + "answer_count=" + answer_count + ", creation_date=" + creation_date + ", is_accepted=" + is_accepted + ", link=" + link + ", owner=" + owner + ", question_id=" + question_id + ", score=" + score + ", title=" + title + '}';
}

}