Added ErrorLayer over ResponseArea and made minor UI tweaks

This commit is contained in:
Rohit Awate 2018-02-02 16:42:37 +05:30
parent 21599557d6
commit 74aa666208
7 changed files with 68 additions and 12 deletions

View file

@ -35,9 +35,12 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -50,13 +53,13 @@ public class DashboardController implements Initializable {
@FXML @FXML
private ComboBox<String> httpMethodBox; private ComboBox<String> httpMethodBox;
@FXML @FXML
private VBox responseBox, loadingLayer, promptLayer, paramsBox; private VBox responseBox, loadingLayer, promptLayer, errorLayer, paramsBox;
@FXML @FXML
private HBox responseDetails; private HBox responseDetails;
@FXML @FXML
private TextArea responseArea; private TextArea responseArea;
@FXML @FXML
private Label statusCode, statusCodeDescription, responseTime, responseSize; private Label statusCode, statusCodeDescription, responseTime, responseSize, errorTitle, errorDetails;
@FXML @FXML
private JFXButton cancelButton; private JFXButton cancelButton;
@FXML @FXML
@ -92,11 +95,13 @@ public class DashboardController implements Initializable {
IOE.printStackTrace(); IOE.printStackTrace();
} }
addressField.setText("http://localhost:8080/api/members/file"); addressField.setText("https://anapioficeandfire.com/api/characters/583");
responseBox.getChildren().remove(0); responseBox.getChildren().remove(0);
promptLayer.setVisible(true); promptLayer.setVisible(true);
httpMethodBox.getItems().addAll(httpMethods); httpMethodBox.getItems().addAll(httpMethods);
httpMethodBox.getSelectionModel().select(1);
// Selects GET by default
httpMethodBox.getSelectionModel().select(0);
paramsControllers = new ArrayList<>(); paramsControllers = new ArrayList<>();
appendedParams = new ArrayList<>(); appendedParams = new ArrayList<>();
@ -139,10 +144,12 @@ public class DashboardController implements Initializable {
cancelButton.setOnAction(e -> requestManager.cancel()); cancelButton.setOnAction(e -> requestManager.cancel());
requestManager.setOnRunning(e -> { requestManager.setOnRunning(e -> {
responseArea.clear(); responseArea.clear();
errorLayer.setVisible(false);
loadingLayer.setVisible(true); loadingLayer.setVisible(true);
}); });
requestManager.setOnSucceeded(e -> { requestManager.setOnSucceeded(e -> {
updateDashboard(requestManager.getValue()); updateDashboard(requestManager.getValue());
errorLayer.setVisible(false);
loadingLayer.setVisible(false); loadingLayer.setVisible(false);
requestManager.reset(); requestManager.reset();
}); });
@ -154,8 +161,13 @@ public class DashboardController implements Initializable {
}); });
requestManager.setOnFailed(e -> { requestManager.setOnFailed(e -> {
loadingLayer.setVisible(false); loadingLayer.setVisible(false);
promptLayer.setVisible(true); errorLayer.setVisible(true);
snackBar.show("Request timed out. Server is unavailable or didn't respond.", 10000); Throwable exception = requestManager.getException().getCause();
if (exception.getClass() == UnknownHostException.class) {
errorTitle.setText("No Internet Connection");
errorDetails.setText("Could not connect to the server. Please check your connection.");
}
requestManager.reset(); requestManager.reset();
}); });
requestManager.start(); requestManager.start();
@ -176,10 +188,12 @@ public class DashboardController implements Initializable {
cancelButton.setOnAction(e -> requestManager.cancel()); cancelButton.setOnAction(e -> requestManager.cancel());
requestManager.setOnRunning(e -> { requestManager.setOnRunning(e -> {
responseArea.clear(); responseArea.clear();
errorLayer.setVisible(false);
loadingLayer.setVisible(true); loadingLayer.setVisible(true);
}); });
requestManager.setOnSucceeded(e -> { requestManager.setOnSucceeded(e -> {
updateDashboard(requestManager.getValue()); updateDashboard(requestManager.getValue());
errorLayer.setVisible(false);
loadingLayer.setVisible(false); loadingLayer.setVisible(false);
requestManager.reset(); requestManager.reset();
}); });
@ -189,7 +203,15 @@ public class DashboardController implements Initializable {
snackBar.show("Request canceled.", 2000); snackBar.show("Request canceled.", 2000);
requestManager.reset(); requestManager.reset();
}); });
requestManager.setOnFailed(e -> requestManager.getException().printStackTrace()); requestManager.setOnFailed(e -> {
loadingLayer.setVisible(false);
promptLayer.setVisible(true);
if (requestManager.getException().getClass() == ConnectException.class)
snackBar.show("Request timed out. Server is unavailable or didn't respond.", 10000);
else if (requestManager.getException().getClass() == FileNotFoundException.class)
snackBar.show("File could not be found.", 5000);
requestManager.reset();
});
requestManager.start(); requestManager.start();
break; break;
default: default:
@ -198,7 +220,9 @@ public class DashboardController implements Initializable {
} catch (MalformedURLException MURLE) { } catch (MalformedURLException MURLE) {
snackBar.show("Invalid address. Please verify and try again.", 3000); snackBar.show("Invalid address. Please verify and try again.", 3000);
} catch (Exception E) { } catch (Exception E) {
snackBar.show("Something went wrong. Couldn't process request.", 5000); errorLayer.setVisible(true);
errorTitle.setText("Oops... That's embarrassing!");
errorDetails.setText("Something went wrong. Try to make another request.\nRestart RESTaurant if that doesn't work.");
} }
} }

View file

@ -73,11 +73,17 @@ public class POSTRequestManager extends RequestManager {
String filePath; String filePath;
File file; File file;
InputStream stream;
pairs = postRequest.getFileTuples(); pairs = postRequest.getFileTuples();
for (Map.Entry entry : pairs.entrySet()) { for (Map.Entry entry : pairs.entrySet()) {
mapEntry = (Map.Entry) entry; mapEntry = (Map.Entry) entry;
filePath = mapEntry.getValue(); filePath = mapEntry.getValue();
file = new File(filePath); file = new File(filePath);
/*
Creating a stream only because it throws
FileNotFoundException if file doesn't exist.
*/
stream = new FileInputStream(file);
formData.bodyPart(new FileDataBodyPart(mapEntry.getKey(), formData.bodyPart(new FileDataBodyPart(mapEntry.getKey(),
file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
} }
@ -87,7 +93,7 @@ public class POSTRequestManager extends RequestManager {
invocation = requestBuilder.buildPost(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE)); invocation = requestBuilder.buildPost(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE));
break; break;
case MediaType.APPLICATION_OCTET_STREAM: case MediaType.APPLICATION_OCTET_STREAM:
InputStream stream = new FileInputStream(postRequest.getBody()); stream = new FileInputStream(postRequest.getBody());
invocation = requestBuilder.buildPost(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE)); invocation = requestBuilder.buildPost(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
break; break;
case MediaType.APPLICATION_FORM_URLENCODED: case MediaType.APPLICATION_FORM_URLENCODED:

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -66,6 +66,10 @@
-fx-background-color: #273154; -fx-background-color: #273154;
} }
#errorLayer {
-fx-background-color: #822f2f;
}
#cancelButton { #cancelButton {
-fx-background-color: black; -fx-background-color: black;
} }

View file

@ -264,6 +264,28 @@
</Label> </Label>
</children> </children>
</VBox> </VBox>
<VBox fx:id="errorLayer" alignment="CENTER" layoutX="10.0" layoutY="10.0"
prefHeight="200.0" prefWidth="100.0" visible="false">
<children>
<ImageView fitHeight="100.0" fitWidth="100.0" opacity="0.75"
pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../assets/Explosion.png"/>
</image>
</ImageView>
<Label fx:id="errorTitle" text="Error title" textFill="WHITE">
<font>
<Font name="System Bold" size="32.0"/>
</font>
</Label>
<Label fx:id="errorDetails" text="Error details"
textAlignment="CENTER" textFill="#c3c3c3">
<font>
<Font size="22.0"/>
</font>
</Label>
</children>
</VBox>
</children> </children>
</StackPane> </StackPane>
</children> </children>

View file

@ -46,10 +46,10 @@
</JFXButton> </JFXButton>
</children> </children>
<padding> <padding>
<Insets bottom="10.0" left="25.0" right="10.0" top="15.0"/> <Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
</padding> </padding>
</HBox> </HBox>
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" vbarPolicy="ALWAYS" VBox.vgrow="ALWAYS"> <ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" VBox.vgrow="ALWAYS">
<content> <content>
<VBox fx:id="headersBox" alignment="TOP_CENTER"/> <VBox fx:id="headersBox" alignment="TOP_CENTER"/>
</content> </content>

View file

@ -25,7 +25,7 @@
<VBox stylesheets="@../../css/Default.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" <VBox stylesheets="@../../css/Default.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.rohitawate.restaurant.dashboard.URLTabController"> fx:controller="com.rohitawate.restaurant.dashboard.URLTabController">
<children> <children>
<HBox alignment="CENTER" VBox.vgrow="ALWAYS"> <HBox alignment="CENTER" VBox.vgrow="NEVER">
<VBox.margin> <VBox.margin>
<Insets/> <Insets/>
</VBox.margin> </VBox.margin>