forked from nus-cs2103-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
Ui
and switch tab command (#165)
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
Showing
13 changed files
with
337 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.