Example usage for com.google.gwt.view.client SingleSelectionModel SingleSelectionModel

List of usage examples for com.google.gwt.view.client SingleSelectionModel SingleSelectionModel

Introduction

In this page you can find the example usage for com.google.gwt.view.client SingleSelectionModel SingleSelectionModel.

Prototype

public SingleSelectionModel() 

Source Link

Document

Constructs a SingleSelectionModel without a key provider.

Usage

From source file:parceirosDaEstrada.web.client.paineis.PainelLocalizarCaronas.java

License:Open Source License

/**
 * @wbp.parser.entryPoint/*  w  w  w.j  a  v  a2 s  .c  om*/
 */
public LayoutPanel carregaPainel() {

    List<Carona> Caronas = new ArrayList<Carona>();
    try {
        Caronas = SistemaWebMain.getSistema().localizarCarona("", "");
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    DateCell dateCell = new DateCell();
    layoutLocalizarCaronas = new LayoutPanel();

    final SingleSelectionModel<Carona> selectionModel = new SingleSelectionModel<Carona>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            Carona selected = selectionModel.getSelectedObject();
            if (selected != null) {
                PainelOpcoesDeCarona painel = new PainelOpcoesDeCarona(selected, idUsuarioLogado,
                        PainelLocalizarCaronas.this);
                layoutLocalizarCaronas.clear();
                layoutLocalizarCaronas.add(painel.carregaPainelDadosDaCarona());
                painel.onModuleLoad();

            }
        }
    });

    ScrollPanel scrollPanel = new ScrollPanel();
    layoutLocalizarCaronas.add(scrollPanel);
    layoutLocalizarCaronas.setWidgetLeftWidth(scrollPanel, 45.0, Unit.PX, 679.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(scrollPanel, 110.0, Unit.PX, 410.0, Unit.PX);
    scrollPanel.setSize("675px", "410px");

    // Cria a CellTable que mostra a lista de caronas ao usuario
    final CellTable<Carona> table = new CellTable<Carona>();
    scrollPanel.setWidget(table);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    TextColumn<Carona> origemColumn = new TextColumn<Carona>() {
        @Override
        public String getValue(Carona object) {
            return object.getOrigem();
        }
    };

    // Coluna origem
    table.addColumn(origemColumn, "Origem");

    // Coluna data
    Column<Carona, Date> dateColumn = new Column<Carona, Date>(dateCell) {
        @SuppressWarnings("deprecation")
        @Override
        public Date getValue(Carona object) {
            String[] data = object.getData().split("/");
            return new Date(Integer.parseInt(data[2]) - 1900, Integer.parseInt(data[1]) - 1,
                    Integer.parseInt(data[0]));
        }
    };
    table.addColumn(dateColumn, "Data");

    // Coluna destino
    TextColumn<Carona> destinoColumn = new TextColumn<Carona>() {
        @Override
        public String getValue(Carona object) {
            return object.getDestino();
        }
    };
    table.addColumn(destinoColumn, "Destino");

    // Coluna vagas
    TextColumn<Carona> vagasColumn = new TextColumn<Carona>() {
        @Override
        public String getValue(Carona object) {
            return object.getVagas();
        }
    };
    table.addColumn(vagasColumn, "Vagas");

    table.setSelectionModel(selectionModel);
    table.setRowCount(Caronas.size(), true);

    // Push the data into the widget.
    table.setRowData(Caronas);
    table.setSize("688px", "420px");
    campoOrigem = new TextBox();
    // tabPanel.add(campoOrigem);
    layoutLocalizarCaronas.add(campoOrigem);
    layoutLocalizarCaronas.setWidgetLeftWidth(campoOrigem, 101.0, Unit.PX, 253.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(campoOrigem, 17.0, Unit.PX, 32.0, Unit.PX);

    campoDestino = new TextBox();
    layoutLocalizarCaronas.add(campoDestino);
    layoutLocalizarCaronas.setWidgetLeftWidth(campoDestino, 439.0, Unit.PX, 253.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(campoDestino, 17.0, Unit.PX, 32.0, Unit.PX);

    Label origemText = new Label("Origem:");
    layoutLocalizarCaronas.add(origemText);
    origemText.setSize("60px", "21px");
    layoutLocalizarCaronas.setWidgetLeftWidth(origemText, 35.0, Unit.PX, 60.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(origemText, 28.0, Unit.PX, 21.0, Unit.PX);

    Label destinoText = new Label("Destino:");
    layoutLocalizarCaronas.add(destinoText);
    destinoText.setSize("60px", "21px");
    layoutLocalizarCaronas.setWidgetLeftWidth(destinoText, 377.0, Unit.PX, 60.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(destinoText, 28.0, Unit.PX, 21.0, Unit.PX);

    Button buscarCaronaButton = new Button("New button");
    buscarCaronaButton.setText("Buscar Carona");
    layoutLocalizarCaronas.add(buscarCaronaButton);
    layoutLocalizarCaronas.setWidgetLeftWidth(buscarCaronaButton, 574.0, Unit.PX, 118.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(buscarCaronaButton, 65.0, Unit.PX, 24.0, Unit.PX);

    // determina acao ao clicar o botato de buscar carona
    buscarCaronaButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            try {
                List<Carona> Caronas = SistemaWebMain.getSistema().localizarCarona(campoOrigem.getText(),
                        campoDestino.getText());

                table.setRowData(Caronas);
            } catch (Exception e) {
                Window.alert(e.getMessage() + "!");
            }
        }
    });

    // Push the data into the widget.
    table.setRowData(Caronas);
    Label infoMsg = new Label("Clique na carona desejada para ver mais detalhes e solicitar uma vaga.");
    layoutLocalizarCaronas.add(infoMsg);
    infoMsg.setSize("460px", "21px");
    layoutLocalizarCaronas.setWidgetLeftRight(infoMsg, 47.0, Unit.PX, 267.0, Unit.PX);
    layoutLocalizarCaronas.setWidgetTopHeight(infoMsg, 77.0, Unit.PX, 21.0, Unit.PX);
    layoutLocalizarCaronas.setSize("759px", "542px");
    return layoutLocalizarCaronas;
}

From source file:parceirosDaEstrada.web.client.ParceirosDaEstrada.java

License:Open Source License

public LayoutPanel carregaPainelCaronas() throws Exception {
    LayoutPanel painelDeCaronas = new LayoutPanel();
    painelDeCaronas.setSize("590px", "490px");
    final List<Carona> CONTACTS = SistemaWebMain.getSistema().localizarCarona("", "");

    DateCell dateCell = new DateCell();

    TabPanel tabPanel = new TabPanel();
    tabPanel.setSize("586px", "485px");
    CellTable<Carona> table = new CellTable<Carona>();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    final SingleSelectionModel<Carona> selectionModel = new SingleSelectionModel<Carona>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            Carona selected = selectionModel.getSelectedObject();
            if (selected != null) {
                Window.alert(selected.toString() + "\n  Cadastre agora mesmo e solicite uma vaga!");
            }/*from w w w. j a v  a  2s.  c om*/
        }
    });
    TextColumn<Carona> nameColumn = new TextColumn<Carona>() {
        @Override
        public String getValue(Carona object) {
            return object.getOrigem();
        }
    };
    table.addColumn(nameColumn, "Origem");
    Column<Carona, Date> dateColumn = new Column<Carona, Date>(dateCell) {
        @SuppressWarnings("deprecation")
        @Override
        public Date getValue(Carona object) {
            String[] data = object.getData().split("/");
            return new Date(Integer.parseInt(data[2]) - 1900, Integer.parseInt(data[1]) - 1,
                    Integer.parseInt(data[0]));

        }
    };
    table.addColumn(dateColumn, "Data");

    TextColumn<Carona> addressColumn = new TextColumn<Carona>() {
        @Override
        public String getValue(Carona object) {
            return object.getDestino();
        }
    };
    table.addColumn(addressColumn, "Destino");
    table.setSelectionModel(selectionModel);

    tabPanel.add(table, "Proximas Caronas", false);
    table.setRowCount(CONTACTS.size(), true);
    table.setRowData(0, CONTACTS);
    table.setSize("572px", "446px");

    tabPanel.add((new PainelOProjeto()).carregaPainel(), "O Projeto", false);
    tabPanel.selectTab(0);
    painelDeCaronas.add(tabPanel);
    return painelDeCaronas;
}

From source file:thothbot.parallax.demo.client.Demo.java

License:Open Source License

public void onModuleLoad() {
    GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
        public void onUncaughtException(Throwable throwable) {
            Log.error("Uncaught exception", throwable);
            if (!GWT.isScript()) {
                String text = "Uncaught exception: ";
                while (throwable != null) {
                    StackTraceElement[] stackTraceElements = throwable.getStackTrace();
                    text += throwable.toString() + "\n";

                    for (int i = 0; i < stackTraceElements.length; i++)
                        text += "    at " + stackTraceElements[i] + "\n";

                    throwable = throwable.getCause();
                    if (throwable != null)
                        text += "Caused by: ";
                }/*from   w w  w  . j  ava2  s  .  com*/

                DialogBox dialogBox = new DialogBox(true);
                DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
                text = text.replaceAll(" ", "&nbsp;");
                dialogBox.setHTML("<pre>" + text + "</pre>");
                dialogBox.center();
            }
        }
    });

    // Generate the source code for examples
    GWT.create(GenerateSourceSignal.class);

    // Generate the demo file
    GWT.create(GenerateFacebookSignal.class);

    resources.css().ensureInjected();

    // Create the application shell.
    final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>();
    final DataModel treeModel = new DataModel(selectionModel);
    Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets();

    index = new Index();
    // Hide loading panel
    RootPanel.get("loading").getElement().getStyle().setVisibility(Visibility.HIDDEN);
    // Attach index panel
    RootLayoutPanel.get().add(index);

    index.getTabIndex().addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            displayIndex();
        }
    });

    indexWidget = new IndexWidget(treeModel);
    shell = new DemoShell(treeModel, index);

    // Prefetch examples when opening the Category tree nodes.
    final List<Category> prefetched = new ArrayList<Category>();
    final CellTree mainMenu = shell.getMainMenu();

    mainMenu.addOpenHandler(new OpenHandler<TreeNode>() {
        public void onOpen(OpenEvent<TreeNode> event) {
            Object value = event.getTarget().getValue();
            if (!(value instanceof Category))
                return;

            Category category = (Category) value;
            if (!prefetched.contains(category)) {
                prefetched.add(category);
                Prefetcher.prefetch(category.getSplitPoints());
            }
        }
    });

    // Always prefetch.
    Prefetcher.start();

    // Change the history token when a main menu item is selected.
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            ContentWidget selected = selectionModel.getSelectedObject();
            if (selected != null) {
                index.setContentWidget(shell);
                History.newItem("!" + selected.getContentWidgetToken(), true);
            }
        }
    });

    // Setup a history handler to reselect the associate menu item.
    final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            // Get the content widget associated with the history token.
            ContentWidget contentWidget = treeModel
                    .getContentWidgetForToken(event.getValue().replaceFirst("!", ""));

            if (contentWidget == null)
                return;

            // Expand the tree node associated with the content.
            Category category = treeModel.getCategoryForContentWidget(contentWidget);
            TreeNode node = mainMenu.getRootTreeNode();
            int childCount = node.getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (node.getChildValue(i) == category) {
                    node.setChildOpen(i, true, true);
                    break;
                }
            }

            // Display the content widget.
            displayContentWidget(contentWidget);

            //Add GA statistics
            trackPageview(Window.Location.getHref());

            // Select the node in the tree.
            selectionModel.setSelected(contentWidget, true);
        }
    };

    History.addValueChangeHandler(historyHandler);

    // Show the initial example.
    if (History.getToken().length() > 0)
        History.fireCurrentHistoryState();

    // Use the first token available.
    else
        displayIndex();

    // Generate a site map.
    createSiteMap(contentWidgets);
}