Example usage for com.vaadin.ui Button.ClickListener Button.ClickListener

List of usage examples for com.vaadin.ui Button.ClickListener Button.ClickListener

Introduction

In this page you can find the example usage for com.vaadin.ui Button.ClickListener Button.ClickListener.

Prototype

Button.ClickListener

Source Link

Usage

From source file:org.investovator.ui.dataplayback.user.dashboard.realtime.RealTimeMainView.java

License:Open Source License

@Override
public HorizontalLayout getBuySellForumButtons(final ComboBox stocksList, final TextField quantity,
        final NativeSelect orderSide) {
    HorizontalLayout buttonsBar = new HorizontalLayout();
    final Button buySellButton = new Button("Buy");
    buySellButton.addClickListener(new Button.ClickListener() {
        @Override//from w  w w  . jav a  2 s  .  c o  m
        public void buttonClick(Button.ClickEvent clickEvent) {
            //check for invalid orders
            boolean invalidOrder = false;
            String numericRegex = "^[0-9]+$";
            //conditions to check
            if (stocksList.getValue() == null || quantity.getValue() == null
                    || !quantity.getValue().toString().matches(numericRegex)) {
                invalidOrder = true;

            }
            //if this is a sell order
            else if (((OrderType) orderSide.getValue()) == OrderType.SELL) {
                //check if te user has this stock
                BeanContainer<String, PortfolioBean> beans = (BeanContainer<String, PortfolioBean>) portfolioTable
                        .getContainerDataSource();

                if (!beans.containsId(stocksList.getValue().toString())) {
                    invalidOrder = true;
                }
            }

            if (invalidOrder) {
                Notification.show("Invalid Order");
                return;
            }

            try {
                Boolean status = player.executeOrder(stocksList.getValue().toString(),
                        Integer.parseInt(quantity.getValue().toString()), ((OrderType) orderSide.getValue()),
                        userName);
                //if the transaction was a success
                if (status) {
                    updatePortfolioTable(stocksList.getValue().toString());
                    //update account info
                    updateAccountBalance();
                    Notification.show("Order executed successfully", Notification.Type.TRAY_NOTIFICATION);
                } else {

                    Notification.show(status.toString());
                }
            } catch (InvalidOrderException e) {
                Notification.show(e.getMessage());
            } catch (UserJoinException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }
    });

    orderSide.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (valueChangeEvent.getProperty().getValue() == OrderType.BUY) {
                buySellButton.setCaption("Buy");
            } else if (valueChangeEvent.getProperty().getValue() == OrderType.SELL) {
                buySellButton.setCaption("Sell");
            }
        }
    });

    buttonsBar.addComponent(buySellButton);

    return buttonsBar;
}

From source file:org.investovator.ui.main.AdminGameConfigLayout.java

License:Open Source License

private void init() {

    //final GameModes gameMode= GameControllerFacade.getInstance().getCurrentGameMode();
    //final GameStates gameState=GameControllerFacade.getInstance().getCurrentGameState();

    Button agentGames = new Button("Agent Gaming Engine", new Button.ClickListener() {
        @Override/*from  ww  w  .  j  av a2s  . c o m*/
        public void buttonClick(Button.ClickEvent event) {
            if (authenticator.isLoggedIn()) {
                startAgentCreateWizard();
            } else {
                getUI().getNavigator().navigateTo(UIConstants.LOGIN_VIEW);
            }
        }
    });

    Button dataPlayback = new Button("Data Playback Engine", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {

            startDailySummaryAddGameWizard();

            /*//if there is no game running
            if(gameState==GameStates.NEW){
            startDailySummaryAddGameWizard();
                    
            }
            //if there is a game running
            else if(gameState==GameStates.RUNNING && gameMode==GameModes.PAYBACK_ENG){
            if(DataPlaybackEngineStates.gameConfig.getPlayerType()== PlayerTypes.REAL_TIME_DATA_PLAYER){
                try {
                    //if the game is multi player
                    //todo - modify to data player parentnew  (no need to even check the follwoing if conditions it seems)
                    if(DataPlayerFacade.getInstance().getRealTimeDataPlayer().isMultiplayer()){
                        getUI().getNavigator().navigateTo(UIConstants.DATA_PLAYBACK_ADMIN_DASH);
                    
                    }
                    else{
                        //loads single player real time data playback view
                        getUI().getNavigator().navigateTo(UIConstants.DATAPLAY_USR_DASH);
                    }
                } catch (PlayerStateException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                    
            }
            else if(DataPlaybackEngineStates.gameConfig.getPlayerType()==PlayerTypes.DAILY_SUMMARY_PLAYER){
            //                        try {
                    //if this is a multiplayer game
            //                            if (DataPlayerFacade.getInstance().getCurrentPlayer().isMultiplayer()){
                        if (DataPlaybackEngineStates.isMultiplayer){
                    
                            getUI().getNavigator().navigateTo(UIConstants.DATA_PLAYBACK_ADMIN_DASH);
                    }
                    else{
                        //loads single player daily summary data playback view
                        getUI().getNavigator().navigateTo(UIConstants.DATAPLAY_USR_DASH);
                    }
            //                        } catch (PlayerStateException e) {
            //                            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            //                        }
            }
                    
            }*/

        }
    });

    Button nnGames = new Button("NN Gaming Engine", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (authenticator.isLoggedIn()) {
                startNNCreateWizard();
            } else {
                getUI().getNavigator().navigateTo(UIConstants.LOGIN_VIEW);
            }
        }
    });
    Label agentGamesLabel = new Label("Agent based game");
    Label agentGamesStatusLabel = new Label("Not Running");
    Label dataPlaybackGamesStatusLabel = new Label("Not Running");
    Label annGamesStatusLabel = new Label("Not Running");
    /*if(gameMode==GameModes.AGENT_GAME && gameState==GameStates.RUNNING){
    agentGamesStatusLabel.setValue("<b> <p style=\"color:red\">Running<b>");
    agentGamesStatusLabel.setContentMode(ContentMode.HTML);
    dataPlaybackGamesStatusLabel.setValue("Not Running");
    annGamesStatusLabel.setValue("Not Running");
            
            
            
    }*/

    Label dataPlaybackGamesLabel = new Label("Data Playback based game");
    /*if(gameMode==GameModes.PAYBACK_ENG && gameState==GameStates.RUNNING){
    dataPlaybackGamesStatusLabel.setValue("<b> <p style=\"color:red\">Running<b>");
    dataPlaybackGamesStatusLabel.setContentMode(ContentMode.HTML);
    annGamesStatusLabel.setValue("Not Running");
    agentGamesStatusLabel.setValue("Not Running");
            
            
    }*/

    Label annGamesLabel = new Label("ANN based game");
    /* if(gameMode==GameModes.NN_GAME && gameState==GameStates.RUNNING){
    annGamesStatusLabel.setValue("<b> <p style=\"color:red\">Running<b>");
    annGamesStatusLabel.setContentMode(ContentMode.HTML);
    dataPlaybackGamesStatusLabel.setValue("Not Running");
    agentGamesStatusLabel.setValue("Not Running");
            
            
            
     }*/

    //add a stop button for DPE
    Button stopDpeButton = new Button("Stop DPE", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            /* if(gameState==GameStates.RUNNING && gameMode==GameModes.PAYBACK_ENG){
            if(DataPlaybackEngineStates.gameConfig.getPlayerType()== PlayerTypes.REAL_TIME_DATA_PLAYER){
                try {
                    DataPlaybackGameFacade.getDataPlayerFacade().getRealTimeDataPlayer().stopGame();
                    GameControllerFacade.getInstance().stopGame(GameModes.PAYBACK_ENG);
                } catch (PlayerStateException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                    
            }
            else if(DataPlaybackEngineStates.gameConfig.getPlayerType()==PlayerTypes.DAILY_SUMMARY_PLAYER){
                try {
                    DataPlaybackGameFacade.getDataPlayerFacade().getDailySummaryDataPLayer().stopGame();
                    GameControllerFacade.getInstance().stopGame(GameModes.PAYBACK_ENG);
                } catch (PlayerStateException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
                    
             }*/

        }
    });

    HorizontalLayout agentLayout = new HorizontalLayout(agentGamesLabel, agentGames, agentGamesStatusLabel);
    agentLayout.setSizeFull();
    HorizontalLayout dataPlaybackLayout;
    //if(GameControllerFacade.getInstance().getCurrentGameState()==GameStates.RUNNING){
    //    dataPlaybackLayout=new HorizontalLayout(dataPlaybackGamesLabel,
    //            dataPlayback,stopDpeButton,dataPlaybackGamesStatusLabel);
    //}
    //else{
    dataPlaybackLayout = new HorizontalLayout(dataPlaybackGamesLabel, dataPlayback,
            dataPlaybackGamesStatusLabel);
    // }

    dataPlaybackLayout.setSizeFull();
    HorizontalLayout annLayout = new HorizontalLayout(annGamesLabel, nnGames, annGamesStatusLabel);
    annLayout.setSizeFull();

    this.addComponent(agentLayout);
    this.addComponent(dataPlaybackLayout);
    this.addComponent(annLayout);

}

From source file:org.investovator.ui.main.components.DataUploadWindow.java

License:Open Source License

private void bindListeners() {

    submitButton.addClickListener(new Button.ClickListener() {
        @Override//from  w  w  w. j  a  va 2s .  co m
        public void buttonClick(Button.ClickEvent clickEvent) {

            if (newCompany)
                selectedStock = symbol.getValue();

            dataUpload.submitUpload();

        }
    });

    newCompanyCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            boolean status = newCompanyCheckBox.getValue();
            setNewCompanySettings(status);
        }
    });

    companySelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            selectedStock = (String) companySelect.getValue();
        }
    });

    dataTypeSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String valueString = (String) dataTypeSelect.getValue();
            if (valueString.equals(TICKER_DATA))
                selectedDataType = CompanyStockTransactionsData.DataType.TICKER;
            if (valueString.equals(OHCL_DATA))
                selectedDataType = CompanyStockTransactionsData.DataType.OHLC;

        }
    });

    //File Receivers
    dataUpload.setReceiver(new DataFileReceiver());
    dataUpload.addSucceededListener(this);
    detailUpload.setReceiver(new DetailFileReceiver());

}

From source file:org.investovator.ui.main.DataImportPanel.java

License:Open Source License

private void bindEvents() {

    dataInsertButton.addClickListener(new Button.ClickListener() {
        @Override/* w w w  .  jav  a  2s.c om*/
        public void buttonClick(Button.ClickEvent clickEvent) {
            uploadWindow = new DataUploadWindow();
            uploadWindow.addCloseListener(new Window.CloseListener() {
                @Override
                public void windowClose(Window.CloseEvent closeEvent) {
                    setEntryData();
                }
            });

            getUI().addWindow(uploadWindow);
        }
    });

}

From source file:org.investovator.ui.nngaming.config.ParameterAddView.java

License:Open Source License

private void bindListeners() {
    submit.addClickListener(new Button.ClickListener() {
        @Override// w w w .java2  s.  c  om
        public void buttonClick(Button.ClickEvent clickEvent) {

            if (!newParamField.getValue().isEmpty() && upload.getUploadSize() != 0) {
                newParameter = newParamField.getValue();
                newParamField.setValue("");
                upload.submitUpload();
            } else {
                Notification.show("Please enter a valid input parameter or file",
                        Notification.Type.TRAY_NOTIFICATION);
            }

        }
    });

    //File Receivers
    upload.setReceiver(new DataFileReceiver());
    upload.addSucceededListener(this);

}

From source file:org.investovator.ui.nngaming.StockAnalysisView.java

License:Open Source License

private void createChartUpdateButton() {
    chartUpdate = new Button("Update Charts");

    chartUpdate.addClickListener(new Button.ClickListener() {
        @Override/*from w  w w . ja  v a2  s.  c o  m*/
        public void buttonClick(Button.ClickEvent clickEvent) {

            if (inputParameter.getValue().equals("0") || inputParameter.getValue().isEmpty()
                    || analysisValue < 0) {
                Notification.show("Please insert a valid input value", Notification.Type.TRAY_NOTIFICATION);
            }

            try {
                analysisValue = Double.parseDouble(inputParameter.getValue());

                String stockID = (String) stockSelect.getValue();

                reportLayout.removeAllComponents();
                charts.clear();

                for (int i = 0; i < analysisIDs.size(); i++) {

                    if (analysisIDs.get(i).equals(stockID))
                        continue;

                    graphData = nnGamingFacade.getAnalysisData(startDate, endDate, stockID,
                            GameTypes.ANALYSIS_GAME, analysisValue, analysisIDs.get(i));

                    AnalysisChart analysisChart = new AnalysisChart(stockID);
                    charts.add(analysisChart);
                    analysisChart.addSeries(stockID + " - Actual Stock Price", graphData, ACTUAL_INDEX);
                    analysisChart.addSeries(stockID + " - Stock Price if " + analysisIDs.get(i)
                            + " average price = " + analysisValue, graphData, PREDICTED_INDEX);
                    reportLayout.addComponent(analysisChart);

                }

            } catch (NumberFormatException e) {
                Notification.show("Please insert a valid input value", Notification.Type.TRAY_NOTIFICATION);
            }

        }

    });
}

From source file:org.investovator.ui.utils.dashboard.dataplayback.BasicGameOverWindow.java

License:Open Source License

public void setupUI() {
    VerticalLayout content = new VerticalLayout();

    //create the leaderboard
    Table leaderboard = getLeaderboard();

    Portfolio myPortfolio = this.getMyPortfolio(username);
    if (myPortfolio == null) {
        this.close();
        return;/*from  w  ww.  j a v a  2s  . com*/
    }
    Label rankLabel = new Label(
            "<H2 align=\"center\">Congratulations " + myPortfolio.getUsername() + ". You Won..!</H2>");

    //if this player has not won the game
    if (!leaderboard.isFirstId(username)) {
        rankLabel.setValue("<H2 align=\"center\">Game Over!</H2>");
    }
    rankLabel.setContentMode(ContentMode.HTML);
    content.addComponent(rankLabel);

    content.addComponent(leaderboard);

    //add the exit game button
    Button exitGame = new Button("Exit Game");
    exitGame.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            //if admin
            if (userType == Authenticator.UserType.ADMIN) {
                getUI().getNavigator().navigateTo(UIConstants.MAINVIEW);
            } else {
                getUI().getNavigator().navigateTo(UIConstants.USER_VIEW);
            }
            close();
        }
    });

    content.addComponent(exitGame);

    this.setContent(content);

}

From source file:org.investovator.ui.utils.dashboard.dataplayback.BasicStockDataView.java

License:Open Source License

private HorizontalLayout setUpTopBar() {
    HorizontalLayout components = new HorizontalLayout();
    components.setWidth("100%");

    HorizontalLayout addChartComponents = new HorizontalLayout();
    components.addComponent(addChartComponents);

    //create the stocks drop down list
    availableStocksList = new ComboBox();
    addChartComponents.addComponent(availableStocksList);
    availableStocksList.setImmediate(true);

    //        availableStocksList.setCaption("Stock");
    availableStocksList.setNullSelectionAllowed(false);
    for (String stock : DataPlaybackEngineStates.playingSymbols) {
        availableStocksList.addItem(stock);
    }/*from   w  w w.ja v  a  2  s  .  com*/
    availableStocksList.select(availableStocksList.getItemIds().toArray()[0]);

    //available attributes list
    availableDataItems = new NativeSelect();
    addChartComponents.addComponent(availableDataItems);
    //        availableDataItems.setCaption("Data: ");

    for (TradingDataAttribute attr : setSelectableAttributes()) {
        availableDataItems.addItem(attr);
    }
    availableDataItems.setNullSelectionAllowed(false);
    availableDataItems.select(availableDataItems.getItemIds().toArray()[0]);

    availableDataItems.setImmediate(true);

    //add chart button
    Button addChartButton = new Button("Add");
    addChartComponents.addComponent(addChartButton);
    addChartButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            addPlotToChart();
        }
    });

    //Remove charts section
    HorizontalLayout removeChartsComponents = new HorizontalLayout();
    components.addComponent(removeChartsComponents);

    //plotted charts list
    this.plottedItemsList = new ComboBox();
    removeChartsComponents.addComponent(this.plottedItemsList);
    this.plottedItemsList.setImmediate(true);
    //        this.plottedItemsList.setCaption("Drawn Charts");
    this.plottedItemsList.setNullSelectionAllowed(true);

    //remove plot button
    Button removeChartButton = new Button("Remove");
    removeChartsComponents.addComponent(removeChartButton);
    removeChartButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            removePlotFromChart();
        }
    });

    //clear all button
    Button clearAllButton = new Button("Clear All");
    removeChartsComponents.addComponent(clearAllButton);

    clearAllButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            clearTimeline();
        }
    });

    //set the alignments
    components.setComponentAlignment(addChartComponents, Alignment.MIDDLE_CENTER);
    components.setComponentAlignment(removeChartsComponents, Alignment.MIDDLE_CENTER);
    components.setHeight(50, Unit.PIXELS);

    return components;
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.HelpClickListener.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent clickEvent) {
    final Window window = new Window("Help");

    window.setModal(true);//from w  w w.  j  a  v a 2 s  .c  o  m
    window.setClosable(false);
    window.setResizable(false);

    window.setWidth("55%");
    window.setHeight("80%");

    m_component.getUI().addWindow(window);

    window.setContent(new VerticalLayout() {
        {
            setMargin(true);
            setSpacing(true);
            setSizeFull();

            HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setSizeFull();
            horizontalLayout.setSpacing(true);

            Tree tree = new Tree();
            tree.setNullSelectionAllowed(false);
            tree.setMultiSelect(false);
            tree.setImmediate(true);

            tree.addItem("Overview");
            tree.setChildrenAllowed("Overview", false);

            tree.addItem("Installed Dashlets");
            tree.setChildrenAllowed("Installed Dashlets", true);

            final List<DashletFactory> factories = m_dashletSelector.getDashletFactoryList();

            for (DashletFactory dashletFactory : factories) {
                tree.addItem(dashletFactory.getName());
                tree.setParent(dashletFactory.getName(), "Installed Dashlets");
                tree.setChildrenAllowed(dashletFactory.getName(), false);
            }
            horizontalLayout.addComponent(tree);

            for (final Object id : tree.rootItemIds()) {
                tree.expandItemsRecursively(id);
            }

            final Panel panel = new Panel();
            panel.setSizeFull();

            horizontalLayout.addComponent(panel);
            horizontalLayout.setExpandRatio(panel, 1.0f);

            addComponent(horizontalLayout);
            setExpandRatio(horizontalLayout, 1.0f);

            tree.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                    String itemId = String.valueOf(valueChangeEvent.getProperty().getValue());

                    if ("Installed Dashlets".equals(itemId)) {
                        return;
                    }

                    if ("Overview".equals(itemId)) {
                        VerticalLayout verticalLayout = new VerticalLayout();
                        verticalLayout.setSpacing(true);
                        verticalLayout.setMargin(true);

                        verticalLayout.addComponent(new Label(getOverviewHelpHTML(), ContentMode.HTML));

                        panel.setContent(verticalLayout);
                    } else {
                        DashletFactory dashletFactory = m_dashletSelector.getDashletFactoryForName(itemId);

                        if (dashletFactory != null) {
                            if (dashletFactory.providesHelpComponent()) {
                                VerticalLayout verticalLayout = new VerticalLayout();
                                verticalLayout.setSpacing(true);
                                verticalLayout.setMargin(true);

                                Label helpTitle = new Label(
                                        "Help for Dashlet '" + dashletFactory.getName() + "'");
                                helpTitle.addStyleName("help-title");

                                verticalLayout.addComponent(helpTitle);
                                verticalLayout.addComponent(dashletFactory.getHelpComponent());

                                panel.setContent(verticalLayout);
                            }
                        }
                    }
                }
            });

            tree.select("Overview");

            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button closeButton = new Button("Close");

                    addComponent(closeButton);
                    setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT);
                    closeButton.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            window.close();
                        }
                    });
                }
            });
        }
    });
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.PreviewClickListener.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent clickEvent) {
    final Window window = new Window("Preview");

    window.setModal(true);/* ww  w  . j  a  v  a2s .  co  m*/
    window.setClosable(false);
    window.setResizable(false);

    window.setWidth("80%");
    window.setHeight("90%");

    m_component.getUI().addWindow(window);

    final WallboardBody wallboardBody = new WallboardBody();

    window.setContent(new VerticalLayout() {
        {
            setMargin(true);
            setSpacing(true);
            setSizeFull();

            addComponent(wallboardBody);
            setExpandRatio(wallboardBody, 1.0f);
            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button closeButton = new Button("Close");

                    addComponent(closeButton);
                    setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT);
                    closeButton.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            window.close();
                        }
                    });
                }
            });
        }
    });
    wallboardBody.setDashletSpecs(m_wallboard.getDashletSpecs());
}