mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +01:00
Use instanceof checks on views instead of class equality
This commit is contained in:
parent
979fc8aca8
commit
e887be742d
6 changed files with 30 additions and 43 deletions
|
@ -95,28 +95,28 @@ public class AccountView extends ActivatableView<TabPane, AccountViewModel> {
|
|||
|
||||
private void loadView(Class<? extends View> viewClass) {
|
||||
Tab tab;
|
||||
View view = viewLoader.load(viewClass);
|
||||
|
||||
if (viewClass == AccountSettingsView.class) {
|
||||
if (view instanceof AccountSettingsView) {
|
||||
tab = accountSettingsTab;
|
||||
tab.setText("Account settings");
|
||||
arbitratorSettingsTab.setDisable(false);
|
||||
}
|
||||
else if (viewClass == AccountSetupWizard.class) {
|
||||
else if (view instanceof AccountSetupWizard) {
|
||||
tab = accountSettingsTab;
|
||||
tab.setText("Account setup");
|
||||
arbitratorSettingsTab.setDisable(true);
|
||||
}
|
||||
else if (viewClass == ArbitratorSettingsView.class) {
|
||||
else if (view instanceof ArbitratorSettingsView) {
|
||||
tab = arbitratorSettingsTab;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Loading " + viewClass + " from " + this + " is not supported");
|
||||
throw new IllegalArgumentException("View not supported: " + view);
|
||||
}
|
||||
|
||||
// for IRC demo we deactivate the arbitratorSettingsTab
|
||||
arbitratorSettingsTab.setDisable(true);
|
||||
|
||||
View view = viewLoader.load(viewClass);
|
||||
tab.setContent(view.getRoot());
|
||||
root.getSelectionModel().select(tab);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
|||
return;
|
||||
|
||||
loadView(viewPath.tip());
|
||||
selectMainMenuButton(viewPath.tip());
|
||||
};
|
||||
|
||||
ToggleGroup toggleGroup = new ToggleGroup();
|
||||
|
@ -98,7 +97,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
|||
}
|
||||
else if (viewPath.size() == 4 && viewPath.indexOf(AccountSettingsView.class) == 2) {
|
||||
loadView(viewPath.get(3));
|
||||
selectMainMenuButton(viewPath.get(3));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,15 +110,13 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
|||
content.getChildren().setAll(view.getRoot());
|
||||
if (view instanceof Wizard.Step)
|
||||
((Wizard.Step) view).hideWizardNavigation();
|
||||
}
|
||||
|
||||
private void selectMainMenuButton(Class<? extends View> viewClass) {
|
||||
if (viewClass == SeedWordsView.class) seedWords.setSelected(true);
|
||||
else if (viewClass == ChangePasswordView.class) password.setSelected(true);
|
||||
else if (viewClass == RestrictionsView.class) restrictions.setSelected(true);
|
||||
else if (viewClass == IrcAccountView.class) ircAccount.setSelected(true);
|
||||
else if (viewClass == RegistrationView.class) registration.setSelected(true);
|
||||
else throw new BitsquareException("Selecting main menu button for " + viewClass + " is not supported");
|
||||
if (view instanceof SeedWordsView) seedWords.setSelected(true);
|
||||
else if (view instanceof ChangePasswordView) password.setSelected(true);
|
||||
else if (view instanceof RestrictionsView) restrictions.setSelected(true);
|
||||
else if (view instanceof IrcAccountView) ircAccount.setSelected(true);
|
||||
else if (view instanceof RegistrationView) registration.setSelected(true);
|
||||
else throw new BitsquareException("Selecting main menu button for view " + view + " is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,12 +89,11 @@ public class FundsView extends ActivatableViewAndModel<TabPane, Activatable> {
|
|||
if (currentTab != null)
|
||||
currentTab.setContent(null);
|
||||
|
||||
if (viewClass == WithdrawalView.class)
|
||||
currentTab = withdrawalTab;
|
||||
if (viewClass == TransactionsView.class)
|
||||
currentTab = transactionsTab;
|
||||
|
||||
View view = viewLoader.load(viewClass);
|
||||
|
||||
if (view instanceof WithdrawalView) currentTab = withdrawalTab;
|
||||
else if (view instanceof TransactionsView) currentTab = transactionsTab;
|
||||
|
||||
currentTab.setContent(view.getRoot());
|
||||
root.getSelectionModel().select(currentTab);
|
||||
}
|
||||
|
|
|
@ -96,14 +96,12 @@ public class PortfolioView extends ActivatableViewAndModel<TabPane, Activatable>
|
|||
if (currentTab != null)
|
||||
currentTab.setContent(null);
|
||||
|
||||
if (viewClass == OffersView.class)
|
||||
currentTab = offersTab;
|
||||
if (viewClass == PendingTradesView.class)
|
||||
currentTab = openTradesTab;
|
||||
if (viewClass == ClosedTradesView.class)
|
||||
currentTab = closedTradesTab;
|
||||
|
||||
View view = viewLoader.load(viewClass);
|
||||
|
||||
if (view instanceof OffersView) currentTab = offersTab;
|
||||
else if (view instanceof PendingTradesView) currentTab = openTradesTab;
|
||||
else if (view instanceof ClosedTradesView) currentTab = closedTradesTab;
|
||||
|
||||
currentTab.setContent(view.getRoot());
|
||||
root.getSelectionModel().select(currentTab);
|
||||
}
|
||||
|
|
|
@ -88,15 +88,12 @@ public class SettingsView extends ActivatableViewAndModel<TabPane, Activatable>
|
|||
|
||||
private void loadView(Class<? extends View> viewClass) {
|
||||
final Tab tab;
|
||||
|
||||
if (viewClass == PreferencesView.class)
|
||||
tab = preferencesTab;
|
||||
else if (viewClass == NetworkSettingsView.class)
|
||||
tab = networkSettingsTab;
|
||||
else
|
||||
throw new IllegalArgumentException("Navigation to " + viewClass + " is not supported");
|
||||
|
||||
View view = viewLoader.load(viewClass);
|
||||
|
||||
if (view instanceof PreferencesView) tab = preferencesTab;
|
||||
else if (view instanceof NetworkSettingsView) tab = networkSettingsTab;
|
||||
else throw new IllegalArgumentException("Navigation to " + viewClass + " is not supported");
|
||||
|
||||
tab.setContent(view.getRoot());
|
||||
root.getSelectionModel().select(tab);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ import javafx.collections.ListChangeListener;
|
|||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
|
||||
public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
||||
|
||||
private OfferBookView offerBookView;
|
||||
|
@ -120,9 +119,10 @@ public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
|||
|
||||
private View loadView(Class<? extends View> viewClass) {
|
||||
TabPane tabPane = root;
|
||||
if (viewClass == OfferBookView.class && offerBookView == null) {
|
||||
View view = viewLoader.load(viewClass);
|
||||
|
||||
if (view instanceof OfferBookView && offerBookView == null) {
|
||||
// Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
|
||||
View view = viewLoader.load(viewClass);
|
||||
final Tab tab = new Tab(direction == Direction.BUY ? "Buy Bitcoin" : "Sell Bitcoin");
|
||||
tab.setClosable(false);
|
||||
tab.setContent(view.getRoot());
|
||||
|
@ -134,10 +134,9 @@ public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
|||
|
||||
return offerBookView;
|
||||
}
|
||||
else if (viewClass == CreateOfferView.class && createOfferView == null) {
|
||||
else if (view instanceof CreateOfferView && createOfferView == null) {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
View view = viewLoader.load(viewClass);
|
||||
createOfferView = (CreateOfferView) view;
|
||||
createOfferView.initWithData(direction, amount, price);
|
||||
createOfferRoot = view.getRoot();
|
||||
|
@ -148,11 +147,9 @@ public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
|||
tabPane.getSelectionModel().select(tab);
|
||||
return createOfferView;
|
||||
}
|
||||
else if (viewClass == TakeOfferView.class && takeOfferView == null &&
|
||||
offer != null) {
|
||||
else if (view instanceof TakeOfferView && takeOfferView == null && offer != null) {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
View view = viewLoader.load(TakeOfferView.class);
|
||||
takeOfferView = (TakeOfferView) view;
|
||||
takeOfferView.initWithData(direction, amount, offer);
|
||||
takeOfferRoot = view.getRoot();
|
||||
|
|
Loading…
Add table
Reference in a new issue