Skip to content

Commit

Permalink
Update Ui and switch tab command (#165)
Browse files Browse the repository at this point in the history
Updates to Ui and completes tab command

- Tab command takes in user input following the syntax in UG. 
- The Tab name supplied must match tabs that exist as given by
`TabEnum`. To switch tabs, its `Index` is used, which is parsed by
`ParserUtil`.
- Ui refactored such that `MainWindow` has `TabPanel` instead of
individual `*ListPanels`
- `TabPanel` now contains all tabs.
- UI also now features placeholder FinancialCards in `HomeView` and
MenuItem.
  • Loading branch information
LiuMC-SG authored Mar 23, 2023
2 parents 9f53302 + 0513a68 commit f745ec8
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 56 deletions.
6 changes: 3 additions & 3 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ Examples:

Switch to another tab.

Syntax: `tab TAB`
Syntax: `tab t/TAB`

* The available tabs are: `Home`, `Orders`, `Suppliers`
* The available tabs are: `Home`, `Orders`, `Contacts`

Examples:
* `tab t/Home` switches the tab to the `Home` tab
* `tab t/HOME` switches the tab to the `Home` tab

### Exiting the program : `exit`

Expand Down
38 changes: 38 additions & 0 deletions src/main/java/trackr/logic/commands/TabCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package trackr.logic.commands;

import static java.util.Objects.requireNonNull;
import static trackr.logic.parser.CliSyntax.PREFIX_TAB;
import static trackr.ui.TabPanel.switchToTab;

import trackr.commons.core.index.Index;
import trackr.logic.commands.exceptions.CommandException;
import trackr.model.Model;

/**
* Switches to a tab specified by the user
*/
public class TabCommand extends Command {
public static final String MESSAGE_SUCCESS = "Switched tab.";
public static final String COMMAND_WORD = "tab";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Switches to specified tab. "
+ "Parameters: "
+ PREFIX_TAB + "TAB NAME\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_TAB + "HOME";

private final Index targetTab;

/**
* Creates a SwitchTabCommand to switch to specified tab {@code index}
*/
public TabCommand(Index targetTab) {
requireNonNull(targetTab);
this.targetTab = targetTab;
}

@Override
public CommandResult execute(Model unused) throws CommandException {
switchToTab(targetTab);
return new CommandResult(String.format(MESSAGE_SUCCESS));
}
}
2 changes: 2 additions & 0 deletions src/main/java/trackr/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class CliSyntax {
public static final Prefix PREFIX_ORDERNAME = new Prefix("on/");
public static final Prefix PREFIX_ORDERQUANTITY = new Prefix("q/");

public static final Prefix PREFIX_TAB = new Prefix("t/");

}
21 changes: 20 additions & 1 deletion src/main/java/trackr/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import trackr.logic.parser.exceptions.ParseException;
import trackr.model.commons.Deadline;
import trackr.model.commons.Name;
import trackr.model.commons.TabEnum;
import trackr.model.commons.Tag;
import trackr.model.order.OrderDeadline;
import trackr.model.order.OrderName;
Expand All @@ -34,7 +35,7 @@
public class ParserUtil {

public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer.";

public static final String MESSAGE_INVALID_TAB = "No such tab.";
/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
Expand Down Expand Up @@ -298,4 +299,22 @@ public static CustomerAddress parseCustomerAddress(String customerAddress) throw
return new CustomerAddress(trimmedCustomerAddress);
}

//========================Parse those related to tab==================================
/**
* Parses {@code targetTabName} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
*
* @throws ParseException if the specified TabName is invalid (not a recognised Tab).
*/
public static Index parseTab(String targetTabName) throws ParseException {
String trimmedTab = targetTabName.trim();
int tabIndex;
try {
tabIndex = TabEnum.getTabIndex(trimmedTab);
} catch (IllegalArgumentException e) {
throw new ParseException(MESSAGE_INVALID_TAB);
}
return Index.fromZeroBased(tabIndex);
}

}
35 changes: 35 additions & 0 deletions src/main/java/trackr/logic/parser/TabCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package trackr.logic.parser;

import static trackr.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static trackr.logic.parser.CliSyntax.PREFIX_TAB;

import trackr.commons.core.index.Index;
import trackr.logic.commands.TabCommand;
import trackr.logic.parser.exceptions.ParseException;

/**
* Parser for TabCommand
*/
public class TabCommandParser implements Parser<TabCommand> {
/**
* Parses the given {@code String} of arguments in the context of TabCommand
* and returns a TabCommand object for execution.
*
* @throws ParseException if the user input does not conform to the expected format
*/
public TabCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TAB);

if (!isPrefixPresent(argMultimap, PREFIX_TAB)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TabCommand.MESSAGE_USAGE));
}
Index targetTab = ParserUtil.parseTab(argMultimap.getValue(PREFIX_TAB).get());
return new TabCommand(targetTab);
}

private static boolean isPrefixPresent(ArgumentMultimap argumentMultimap, Prefix prefix) {
return argumentMultimap.getValue(prefix).isPresent();
}
}
3 changes: 3 additions & 0 deletions src/main/java/trackr/logic/parser/TrackrParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import trackr.logic.commands.Command;
import trackr.logic.commands.ExitCommand;
import trackr.logic.commands.HelpCommand;
import trackr.logic.commands.TabCommand;
import trackr.logic.commands.order.AddOrderCommand;
import trackr.logic.commands.order.ClearOrderCommand;
import trackr.logic.commands.order.DeleteOrderCommand;
Expand Down Expand Up @@ -140,6 +141,8 @@ public Command parseCommand(String userInput) throws ParseException {
case ListTaskCommand.COMMAND_WORD_SHORTCUT:
return new ListTaskCommand();

case TabCommand.COMMAND_WORD:
return new TabCommandParser().parse(arguments);
case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/trackr/model/commons/TabEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package trackr.model.commons;

/**
* Enum representing all tabs.
*/
public enum TabEnum {
HOME,
ORDERS,
TASKS,
CONTACTS,
MENU;

public static int getTabIndex(String targetStr) {
return TabEnum.valueOf(targetStr).ordinal();
}
}
32 changes: 32 additions & 0 deletions src/main/java/trackr/ui/HomeView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package trackr.ui;

import javafx.fxml.FXML;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import trackr.logic.Logic;

/**
* The UI component that is resposnible for displaying Home tab.
*/
public class HomeView extends UiPart<Region> {
private static final String FXML = "HomeView.fxml";
private Logic logic;
private TaskListPanel taskListPanel;

@FXML
private StackPane homeList;

/**
* Creates an empty TabPane
*/
public HomeView(Logic logic) {
super(FXML);
this.logic = logic;
fillParts();
}

private void fillParts() {
taskListPanel = new TaskListPanel(logic.getFilteredTaskList());
homeList.getChildren().add(taskListPanel.getRoot());
}
}
39 changes: 7 additions & 32 deletions src/main/java/trackr/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import trackr.commons.core.GuiSettings;
import trackr.commons.core.LogsCenter;
Expand All @@ -31,26 +32,18 @@ public class MainWindow extends UiPart<Stage> {
private Logic logic;

// Independent Ui parts residing in this Ui container
private SupplierListPanel supplierListPanel;
private TaskListPanel taskListPanel;
private OrderListPanel orderListPanel;
private TabPanel tabPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

@FXML
private StackPane commandBoxPlaceholder;

@FXML
private MenuItem helpMenuItem;
private VBox tabPanelPlaceholder;

@FXML
private StackPane supplierListPanelPlaceholder;

@FXML
private StackPane taskListPanelPlaceholder;
private StackPane commandBoxPlaceholder;

@FXML
private StackPane orderListPanelPlaceholder;
private MenuItem helpMenuItem;

@FXML
private StackPane resultDisplayPlaceholder;
Expand Down Expand Up @@ -118,14 +111,8 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
supplierListPanel = new SupplierListPanel(logic.getFilteredSupplierList());
supplierListPanelPlaceholder.getChildren().add(supplierListPanel.getRoot());

taskListPanel = new TaskListPanel(logic.getFilteredTaskList());
taskListPanelPlaceholder.getChildren().add(taskListPanel.getRoot());

orderListPanel = new OrderListPanel(logic.getFilteredOrderList());
orderListPanelPlaceholder.getChildren().add(orderListPanel.getRoot());
tabPanel = new TabPanel(logic);
tabPanelPlaceholder.getChildren().add(tabPanel.getRoot());

resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());
Expand Down Expand Up @@ -177,18 +164,6 @@ private void handleExit() {
primaryStage.hide();
}

public SupplierListPanel getSupplierListPanel() {
return supplierListPanel;
}

public TaskListPanel getTaskListPanel() {
return taskListPanel;
}

public OrderListPanel getOrderListPanel() {
return orderListPanel;
}

/**
* Executes the command and returns the result.
*
Expand Down
Loading

0 comments on commit f745ec8

Please sign in to comment.