Added ErrorLayer over ResponseArea and made minor UI tweaks
This commit is contained in:
parent
21599557d6
commit
74aa666208
7 changed files with 68 additions and 12 deletions
|
@ -35,9 +35,12 @@ import javafx.scene.layout.HBox;
|
|||
import javafx.scene.layout.VBox;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -50,13 +53,13 @@ public class DashboardController implements Initializable {
|
|||
@FXML
|
||||
private ComboBox<String> httpMethodBox;
|
||||
@FXML
|
||||
private VBox responseBox, loadingLayer, promptLayer, paramsBox;
|
||||
private VBox responseBox, loadingLayer, promptLayer, errorLayer, paramsBox;
|
||||
@FXML
|
||||
private HBox responseDetails;
|
||||
@FXML
|
||||
private TextArea responseArea;
|
||||
@FXML
|
||||
private Label statusCode, statusCodeDescription, responseTime, responseSize;
|
||||
private Label statusCode, statusCodeDescription, responseTime, responseSize, errorTitle, errorDetails;
|
||||
@FXML
|
||||
private JFXButton cancelButton;
|
||||
@FXML
|
||||
|
@ -92,11 +95,13 @@ public class DashboardController implements Initializable {
|
|||
IOE.printStackTrace();
|
||||
}
|
||||
|
||||
addressField.setText("http://localhost:8080/api/members/file");
|
||||
addressField.setText("https://anapioficeandfire.com/api/characters/583");
|
||||
responseBox.getChildren().remove(0);
|
||||
promptLayer.setVisible(true);
|
||||
httpMethodBox.getItems().addAll(httpMethods);
|
||||
httpMethodBox.getSelectionModel().select(1);
|
||||
|
||||
// Selects GET by default
|
||||
httpMethodBox.getSelectionModel().select(0);
|
||||
|
||||
paramsControllers = new ArrayList<>();
|
||||
appendedParams = new ArrayList<>();
|
||||
|
@ -139,10 +144,12 @@ public class DashboardController implements Initializable {
|
|||
cancelButton.setOnAction(e -> requestManager.cancel());
|
||||
requestManager.setOnRunning(e -> {
|
||||
responseArea.clear();
|
||||
errorLayer.setVisible(false);
|
||||
loadingLayer.setVisible(true);
|
||||
});
|
||||
requestManager.setOnSucceeded(e -> {
|
||||
updateDashboard(requestManager.getValue());
|
||||
errorLayer.setVisible(false);
|
||||
loadingLayer.setVisible(false);
|
||||
requestManager.reset();
|
||||
});
|
||||
|
@ -154,8 +161,13 @@ public class DashboardController implements Initializable {
|
|||
});
|
||||
requestManager.setOnFailed(e -> {
|
||||
loadingLayer.setVisible(false);
|
||||
promptLayer.setVisible(true);
|
||||
snackBar.show("Request timed out. Server is unavailable or didn't respond.", 10000);
|
||||
errorLayer.setVisible(true);
|
||||
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.start();
|
||||
|
@ -176,10 +188,12 @@ public class DashboardController implements Initializable {
|
|||
cancelButton.setOnAction(e -> requestManager.cancel());
|
||||
requestManager.setOnRunning(e -> {
|
||||
responseArea.clear();
|
||||
errorLayer.setVisible(false);
|
||||
loadingLayer.setVisible(true);
|
||||
});
|
||||
requestManager.setOnSucceeded(e -> {
|
||||
updateDashboard(requestManager.getValue());
|
||||
errorLayer.setVisible(false);
|
||||
loadingLayer.setVisible(false);
|
||||
requestManager.reset();
|
||||
});
|
||||
|
@ -189,7 +203,15 @@ public class DashboardController implements Initializable {
|
|||
snackBar.show("Request canceled.", 2000);
|
||||
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();
|
||||
break;
|
||||
default:
|
||||
|
@ -198,7 +220,9 @@ public class DashboardController implements Initializable {
|
|||
} catch (MalformedURLException MURLE) {
|
||||
snackBar.show("Invalid address. Please verify and try again.", 3000);
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,17 @@ public class POSTRequestManager extends RequestManager {
|
|||
|
||||
String filePath;
|
||||
File file;
|
||||
InputStream stream;
|
||||
pairs = postRequest.getFileTuples();
|
||||
for (Map.Entry entry : pairs.entrySet()) {
|
||||
mapEntry = (Map.Entry) entry;
|
||||
filePath = mapEntry.getValue();
|
||||
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(),
|
||||
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));
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
case MediaType.APPLICATION_FORM_URLENCODED:
|
||||
|
|
BIN
src/main/resources/assets/Explosion.png
Normal file
BIN
src/main/resources/assets/Explosion.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
|
@ -66,6 +66,10 @@
|
|||
-fx-background-color: #273154;
|
||||
}
|
||||
|
||||
#errorLayer {
|
||||
-fx-background-color: #822f2f;
|
||||
}
|
||||
|
||||
#cancelButton {
|
||||
-fx-background-color: black;
|
||||
}
|
||||
|
|
|
@ -264,6 +264,28 @@
|
|||
</Label>
|
||||
</children>
|
||||
</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>
|
||||
</StackPane>
|
||||
</children>
|
||||
|
|
|
@ -46,10 +46,10 @@
|
|||
</JFXButton>
|
||||
</children>
|
||||
<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>
|
||||
</HBox>
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" vbarPolicy="ALWAYS" VBox.vgrow="ALWAYS">
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" VBox.vgrow="ALWAYS">
|
||||
<content>
|
||||
<VBox fx:id="headersBox" alignment="TOP_CENTER"/>
|
||||
</content>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<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">
|
||||
<children>
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS">
|
||||
<HBox alignment="CENTER" VBox.vgrow="NEVER">
|
||||
<VBox.margin>
|
||||
<Insets/>
|
||||
</VBox.margin>
|
||||
|
|
Loading…
Reference in a new issue