Add foundation for single-Dashboard design
This commit is contained in:
parent
f1ca82d61c
commit
5f85f83696
9 changed files with 132 additions and 93 deletions
|
@ -18,7 +18,7 @@ package com.rohitawate.everest.controllers;
|
|||
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea.HighlightMode;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.misc.ThemeManager;
|
||||
|
@ -119,8 +119,8 @@ public class BodyTabController implements Initializable {
|
|||
filePathField.setText(filePath);
|
||||
}
|
||||
|
||||
public DashboardState getState() {
|
||||
DashboardState state = new DashboardState();
|
||||
public ComposerState getState() {
|
||||
ComposerState state = new ComposerState();
|
||||
|
||||
state.rawBodyType = rawInputTypeBox.getValue();
|
||||
state.rawBody = rawInputArea.getText();
|
||||
|
@ -154,7 +154,7 @@ public class BodyTabController implements Initializable {
|
|||
return state;
|
||||
}
|
||||
|
||||
public void setState(DashboardState state) {
|
||||
public void setState(ComposerState state) {
|
||||
// Adding URL tab's tuples
|
||||
if (state.urlStringTuples != null)
|
||||
for (FieldState fieldState : state.urlStringTuples)
|
||||
|
@ -175,7 +175,7 @@ public class BodyTabController implements Initializable {
|
|||
filePathField.setText(state.binaryFilePath);
|
||||
}
|
||||
|
||||
private void setRawTab(DashboardState state) {
|
||||
private void setRawTab(ComposerState state) {
|
||||
HighlightMode mode;
|
||||
|
||||
if (state.rawBodyType != null && state.rawBody != null) {
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.jfoenix.controls.JFXProgressBar;
|
|||
import com.jfoenix.controls.JFXSnackbar;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
|
||||
import com.rohitawate.everest.controllers.codearea.EverestCodeArea.HighlightMode;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.exceptions.RedirectException;
|
||||
import com.rohitawate.everest.exceptions.UnreliableResponseException;
|
||||
|
@ -557,25 +557,25 @@ public class DashboardController implements Initializable {
|
|||
/**
|
||||
* @return Current state of the Dashboard.
|
||||
*/
|
||||
public DashboardState getState() {
|
||||
DashboardState dashboardState;
|
||||
public ComposerState getState() {
|
||||
ComposerState composerState;
|
||||
switch (httpMethodBox.getValue()) {
|
||||
case "POST":
|
||||
case "PUT":
|
||||
case "PATCH":
|
||||
dashboardState = bodyTabController.getState();
|
||||
composerState = bodyTabController.getState();
|
||||
break;
|
||||
default:
|
||||
// For GET, DELETE requests
|
||||
dashboardState = new DashboardState();
|
||||
composerState = new ComposerState();
|
||||
}
|
||||
|
||||
dashboardState.target = addressField.getText();
|
||||
dashboardState.httpMethod = httpMethodBox.getValue();
|
||||
dashboardState.headers = headerTabController.getFieldStates();
|
||||
dashboardState.params = getParamFieldStates();
|
||||
composerState.target = addressField.getText();
|
||||
composerState.httpMethod = httpMethodBox.getValue();
|
||||
composerState.headers = headerTabController.getFieldStates();
|
||||
composerState.params = getParamFieldStates();
|
||||
|
||||
return dashboardState;
|
||||
return composerState;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -583,7 +583,7 @@ public class DashboardController implements Initializable {
|
|||
*
|
||||
* @param state - State of the dashboard
|
||||
*/
|
||||
public void setState(DashboardState state) {
|
||||
public void setState(ComposerState state) {
|
||||
/*
|
||||
The only value from a set of constants in the state.json file is the httpMethod
|
||||
which, if manipulated to a non-standard value by the user, would still
|
||||
|
|
|
@ -16,41 +16,39 @@
|
|||
|
||||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import com.rohitawate.everest.controllers.search.Searchable;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
|
||||
public class HistoryItemController implements Initializable, Searchable<DashboardState> {
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class HistoryItemController implements Initializable, Searchable<ComposerState> {
|
||||
@FXML
|
||||
private Label requestType, address;
|
||||
@FXML
|
||||
private Tooltip tooltip;
|
||||
|
||||
private DashboardState state;
|
||||
private ComposerState state;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
tooltip.textProperty().bind(address.textProperty());
|
||||
}
|
||||
|
||||
public DashboardState getState() {
|
||||
public ComposerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(DashboardState state) {
|
||||
public void setState(ComposerState state) {
|
||||
this.state = state;
|
||||
this.requestType.setText(state.httpMethod);
|
||||
this.address.setText(state.target);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.rohitawate.everest.controllers.search.SearchablePaneController;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
|
@ -28,16 +28,16 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class HistoryPaneController extends SearchablePaneController<DashboardState> {
|
||||
public class HistoryPaneController extends SearchablePaneController<ComposerState> {
|
||||
|
||||
private List<Consumer<DashboardState>> stateClickHandler = new LinkedList<>();
|
||||
private List<Consumer<ComposerState>> stateClickHandler = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
protected List<DashboardState> loadInitialEntries() {
|
||||
protected List<ComposerState> loadInitialEntries() {
|
||||
return Services.historyManager.getHistory();
|
||||
}
|
||||
|
||||
protected SearchEntry<DashboardState> createEntryFromState(DashboardState state) throws IOException {
|
||||
protected SearchEntry<ComposerState> createEntryFromState(ComposerState state) throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryItem.fxml"));
|
||||
Parent historyItem = loader.load();
|
||||
|
||||
|
@ -53,13 +53,13 @@ public class HistoryPaneController extends SearchablePaneController<DashboardSta
|
|||
return new SearchEntry<>(historyItem, controller);
|
||||
}
|
||||
|
||||
private void handleClick(DashboardState state) {
|
||||
for (Consumer<DashboardState> consumer : stateClickHandler) {
|
||||
private void handleClick(ComposerState state) {
|
||||
for (Consumer<ComposerState> consumer : stateClickHandler) {
|
||||
consumer.accept(state);
|
||||
}
|
||||
}
|
||||
|
||||
public void addItemClickHandler(Consumer<DashboardState> handler) {
|
||||
public void addItemClickHandler(Consumer<ComposerState> handler) {
|
||||
stateClickHandler.add(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package com.rohitawate.everest.controllers;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.misc.EverestUtilities;
|
||||
import com.rohitawate.everest.misc.KeyMap;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
|
@ -34,6 +34,7 @@ import javafx.scene.control.SplitPane;
|
|||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -54,11 +55,23 @@ public class HomeWindowController implements Initializable {
|
|||
private TabPane homeWindowTabPane;
|
||||
@FXML
|
||||
private HistoryPaneController historyPaneController;
|
||||
@FXML
|
||||
private VBox tabDashboardBox;
|
||||
|
||||
private HashMap<Tab, DashboardController> tabControllerMap;
|
||||
private DashboardController dashboard;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/Dashboard.fxml"));
|
||||
try {
|
||||
Parent dashboardFXML = loader.load();
|
||||
dashboard = loader.getController();
|
||||
tabDashboardBox.getChildren().add(dashboardFXML);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Using LinkedHashMap because they retain order
|
||||
tabControllerMap = new LinkedHashMap<>();
|
||||
recoverState();
|
||||
|
@ -138,15 +151,15 @@ public class HomeWindowController implements Initializable {
|
|||
addTab(null);
|
||||
}
|
||||
|
||||
private void addTab(DashboardState dashboardState) {
|
||||
private void addTab(ComposerState composerState) {
|
||||
try {
|
||||
Tab newTab = new Tab();
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/Dashboard.fxml"));
|
||||
Parent dashboard = loader.load();
|
||||
DashboardController controller = loader.getController();
|
||||
|
||||
if (dashboardState != null)
|
||||
controller.setState(dashboardState);
|
||||
if (composerState != null)
|
||||
controller.setState(composerState);
|
||||
|
||||
newTab.setContent(dashboard);
|
||||
|
||||
|
@ -173,15 +186,15 @@ public class HomeWindowController implements Initializable {
|
|||
}
|
||||
|
||||
private void saveState() {
|
||||
ArrayList<DashboardState> dashboardStates = new ArrayList<>();
|
||||
ArrayList<ComposerState> composerStates = new ArrayList<>();
|
||||
|
||||
// Get the states of all the tabs
|
||||
for (DashboardController controller : tabControllerMap.values())
|
||||
dashboardStates.add(controller.getState());
|
||||
composerStates.add(controller.getState());
|
||||
|
||||
try {
|
||||
File stateFile = new File("Everest/config/state.json");
|
||||
EverestUtilities.jsonMapper.writeValue(stateFile, dashboardStates);
|
||||
EverestUtilities.jsonMapper.writeValue(stateFile, composerStates);
|
||||
Services.loggingService.logInfo("Application state saved.", LocalDateTime.now());
|
||||
} catch (IOException e) {
|
||||
Services.loggingService.logSevere("Failed to save application state.", e, LocalDateTime.now());
|
||||
|
@ -198,15 +211,15 @@ public class HomeWindowController implements Initializable {
|
|||
return;
|
||||
}
|
||||
|
||||
ArrayList<DashboardState> dashboardStates = EverestUtilities.jsonMapper
|
||||
ArrayList<ComposerState> composerStates = EverestUtilities.jsonMapper
|
||||
.reader()
|
||||
.forType(new TypeReference<ArrayList<DashboardState>>() {
|
||||
.forType(new TypeReference<ArrayList<ComposerState>>() {
|
||||
})
|
||||
.readValue(stateFile);
|
||||
|
||||
if (dashboardStates.size() > 0) {
|
||||
for (DashboardState dashboardState : dashboardStates)
|
||||
addTab(dashboardState);
|
||||
if (composerStates.size() > 0) {
|
||||
for (ComposerState composerState : composerStates)
|
||||
addTab(composerState);
|
||||
} else {
|
||||
addTab();
|
||||
}
|
||||
|
@ -217,7 +230,7 @@ public class HomeWindowController implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void addHistoryItem(DashboardState state) {
|
||||
public void addHistoryItem(ComposerState state) {
|
||||
historyPaneController.addHistoryItem(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2018 Rohit Awate.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Convenience class to abstract the state of the application.
|
||||
*/
|
||||
public class ComposerState {
|
||||
public String target;
|
||||
public String httpMethod;
|
||||
public ArrayList<FieldState> params;
|
||||
public ArrayList<FieldState> headers;
|
||||
|
||||
// Determined from the active tab within the Body tab
|
||||
public String contentType;
|
||||
|
||||
// Body and content-type of requests with raw bodies
|
||||
public String rawBody;
|
||||
public String rawBodyType;
|
||||
|
||||
// Tuples of URL-encoded requests
|
||||
public ArrayList<FieldState> urlStringTuples;
|
||||
|
||||
// String and file tuples of multipart-form requests
|
||||
public ArrayList<FieldState> formStringTuples;
|
||||
public ArrayList<FieldState> formFileTuples;
|
||||
|
||||
// File path of application/octet-stream requests
|
||||
public String binaryFilePath;
|
||||
}
|
|
@ -16,31 +16,14 @@
|
|||
|
||||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Convenience class to abstract the state of the application.
|
||||
*/
|
||||
public class DashboardState {
|
||||
public String target;
|
||||
public String httpMethod;
|
||||
public ArrayList<FieldState> params;
|
||||
public ArrayList<FieldState> headers;
|
||||
|
||||
// Determined from the active tab within the Body tab
|
||||
public String contentType;
|
||||
|
||||
// Body and content-type of requests with raw bodies
|
||||
public String rawBody;
|
||||
public String rawBodyType;
|
||||
|
||||
// Tuples of URL-encoded requests
|
||||
public ArrayList<FieldState> urlStringTuples;
|
||||
|
||||
// String and file tuples of multipart-form requests
|
||||
public ArrayList<FieldState> formStringTuples;
|
||||
public ArrayList<FieldState> formFileTuples;
|
||||
|
||||
// File path of application/octet-stream requests
|
||||
public String binaryFilePath;
|
||||
public ComposerState composer;
|
||||
public boolean showResponse;
|
||||
public int statusCode;
|
||||
public String responseType;
|
||||
public int responseTime;
|
||||
public int responseSize;
|
||||
public HashMap<String, String> responseHeaders;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ package com.rohitawate.everest.history;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rohitawate.everest.controllers.state.DashboardState;
|
||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||
import com.rohitawate.everest.controllers.state.FieldState;
|
||||
import com.rohitawate.everest.misc.EverestUtilities;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
|
@ -96,7 +96,7 @@ public class HistoryManager {
|
|||
*
|
||||
* @param state - The state of the Dashboard while making the request.
|
||||
*/
|
||||
public synchronized void saveHistory(DashboardState state) {
|
||||
public synchronized void saveHistory(ComposerState state) {
|
||||
if (isDuplicate(state))
|
||||
return;
|
||||
|
||||
|
@ -110,8 +110,8 @@ public class HistoryManager {
|
|||
/**
|
||||
* Returns a list of all the recent requests.
|
||||
*/
|
||||
public synchronized List<DashboardState> getHistory() {
|
||||
List<DashboardState> history = new ArrayList<>();
|
||||
public synchronized List<ComposerState> getHistory() {
|
||||
List<ComposerState> history = new ArrayList<>();
|
||||
try {
|
||||
// Loads the requests from the last x number of days, x being Settings.showHistoryRange
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("selectRecentRequests").toString()));
|
||||
|
@ -120,9 +120,9 @@ public class HistoryManager {
|
|||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
DashboardState state;
|
||||
ComposerState state;
|
||||
while (resultSet.next()) {
|
||||
state = new DashboardState();
|
||||
state = new ComposerState();
|
||||
|
||||
state.target = resultSet.getString("Target");
|
||||
|
||||
|
@ -241,7 +241,7 @@ public class HistoryManager {
|
|||
* @param newState The new request.
|
||||
* @return true, if request is same as the last one in the database. false, otherwise.
|
||||
*/
|
||||
private boolean isDuplicate(DashboardState newState) {
|
||||
private boolean isDuplicate(ComposerState newState) {
|
||||
try {
|
||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("selectMostRecentRequest").toString()));
|
||||
ResultSet RS = statement.executeQuery();
|
||||
|
@ -346,7 +346,7 @@ public class HistoryManager {
|
|||
}
|
||||
|
||||
private class HistorySaver implements Runnable {
|
||||
private DashboardState state;
|
||||
private ComposerState state;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -19,20 +19,19 @@
|
|||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
|
||||
<StackPane fx:id="homeWindowSP"
|
||||
stylesheets="@../../css/Adreana.css"
|
||||
xmlns="http://javafx.com/javafx/8.0.141"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.rohitawate.everest.controllers.HomeWindowController">
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<StackPane fx:id="homeWindowSP" stylesheets="@../../css/Adreana.css" xmlns="http://javafx.com/javafx/8.0.141"
|
||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.rohitawate.everest.controllers.HomeWindowController">
|
||||
<children>
|
||||
<SplitPane fx:id="splitPane" dividerPositions="0.3">
|
||||
<items>
|
||||
<fx:include fx:id="historyPane" source="HistoryPane.fxml" />
|
||||
<TabPane fx:id="homeWindowTabPane"
|
||||
tabClosingPolicy="ALL_TABS" tabMaxHeight="30.0" tabMaxWidth="200.0"
|
||||
tabMinHeight="30.0" tabMinWidth="200.0"
|
||||
SplitPane.resizableWithParent="false" />
|
||||
<VBox fx:id="tabDashboardBox" SplitPane.resizableWithParent="false">
|
||||
<children>
|
||||
<TabPane fx:id="homeWindowTabPane" tabClosingPolicy="ALL_TABS" tabMaxHeight="30.0"
|
||||
tabMaxWidth="200.0" tabMinHeight="30.0" tabMinWidth="200.0" VBox.vgrow="ALWAYS"/>
|
||||
</children>
|
||||
</VBox>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</children>
|
||||
|
|
Loading…
Reference in a new issue