Example usage for com.google.gwt.event.logical.shared SelectionEvent getSelectedItem

List of usage examples for com.google.gwt.event.logical.shared SelectionEvent getSelectedItem

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared SelectionEvent getSelectedItem.

Prototype

public T getSelectedItem() 

Source Link

Document

Gets the selected item.

Usage

From source file:org.rebioma.client.MapView.java

License:Apache License

public void onSelection(SelectionEvent<Widget> event) {
    Object source = event.getSource();
    if (source == leftTab) {
        if (!event.getSelectedItem().equals(currentTab)) {
            currentTab = (Widget) event.getSelectedItem();
            addHistoryItem(false);/*from  w w  w.j  a  v a2s .c o m*/
            if (currentTab.equals(modelSearch.getParent())) {
                modelSearch.setPage(1);
                String modelSearchTerm = historyState.getHistoryParameters(UrlParam.M_SEARCH).toString();
                modelSearch.search(modelSearchTerm);
            } else if (currentTab.equals(markerList.getParent())) {
                //Exception ?
                try {
                    modelSearch.clearOverLay();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ;
            }
        }
    }

}

From source file:org.roda.wui.client.browse.BrowseAIP.java

private void updateSectionDescriptiveMetadata(BrowseAIPBundle bundle) {
    final List<Pair<String, HTML>> descriptiveMetadataContainers = new ArrayList<>();
    final Map<String, DescriptiveMetadataViewBundle> bundles = new HashMap<>();

    List<DescriptiveMetadataViewBundle> descMetadata = bundle.getDescriptiveMetadata();
    if (descMetadata != null) {
        for (DescriptiveMetadataViewBundle descMetadatum : descMetadata) {
            String title = descMetadatum.getLabel() != null ? descMetadatum.getLabel() : descMetadatum.getId();
            HTML container = new HTML();
            container.addStyleName("metadataContent");
            descriptiveMetadata.add(container, title);
            descriptiveMetadataContainers.add(Pair.of(descMetadatum.getId(), container));
            bundles.put(descMetadatum.getId(), descMetadatum);
        }//from www  .j  a  v a2 s.  c om
    }

    HandlerRegistration tabHandler = descriptiveMetadata.addSelectionHandler(new SelectionHandler<Integer>() {

        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() < descriptiveMetadataContainers.size()) {
                Pair<String, HTML> pair = descriptiveMetadataContainers.get(event.getSelectedItem());
                String descId = pair.getFirst();
                final HTML html = pair.getSecond();
                final DescriptiveMetadataViewBundle descBundle = bundles.get(descId);
                if (html.getText().length() == 0) {
                    getDescriptiveMetadataHTML(aipId, descId, descBundle, new AsyncCallback<SafeHtml>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            if (!AsyncCallbackUtils.treatCommonFailures(caught)) {
                                Toast.showError(messages.errorLoadingDescriptiveMetadata(caught.getMessage()));
                            }
                        }

                        @Override
                        public void onSuccess(SafeHtml result) {
                            html.setHTML(result);
                        }
                    });
                }
            }
        }
    });

    final int addTabIndex = descriptiveMetadata.getWidgetCount();
    FlowPanel addTab = new FlowPanel();
    addTab.add(new HTML(SafeHtmlUtils.fromSafeConstant("<i class=\"fa fa-plus-circle\"></i>")));
    descriptiveMetadata.add(new Label(), addTab);
    HandlerRegistration addTabHandler = descriptiveMetadata
            .addSelectionHandler(new SelectionHandler<Integer>() {
                @Override
                public void onSelection(SelectionEvent<Integer> event) {
                    if (event.getSelectedItem() == addTabIndex) {
                        newDescriptiveMetadataRedirect();
                    }
                }
            });
    addTab.addStyleName("addTab");
    addTab.getParent().addStyleName("addTabWrapper");

    handlers.add(tabHandler);
    handlers.add(addTabHandler);

    if (descMetadata != null && !descMetadata.isEmpty()) {
        descriptiveMetadata.setVisible(true);
        descriptiveMetadata.selectTab(0);
    } else {
        newDescriptiveMetadata.setVisible(true);
    }

    WCAGUtilities.getInstance().makeAccessible(descriptiveMetadata.getElement());
}

From source file:org.roda.wui.client.browse.BrowseRepresentation.java

public BrowseRepresentation(BrowseRepresentationBundle bundle) {
    this.representation = bundle.getRepresentation();

    this.aipId = representation.getAipId();
    this.repId = representation.getId();
    this.repUUID = representation.getUUID();

    handlers = new ArrayList<>();
    String summary = messages.representationListOfFiles();

    AIPState state = bundle.getAip().getState();
    boolean justActive = AIPState.ACTIVE.equals(state);
    boolean selectable = true;
    boolean showFilesPath = false;

    // FILES/*w  ww  .  j  av  a2s . c om*/

    Filter filter = new Filter(new SimpleFilterParameter(RodaConstants.FILE_REPRESENTATION_UUID, repUUID),
            new EmptyKeyFilterParameter(RodaConstants.FILE_PARENT_UUID));

    filesList = new SearchFileList(filter, justActive, Facets.NONE, summary, selectable, showFilesPath);
    LastSelectedItemsSingleton.getInstance().setSelectedJustActive(justActive);
    filesList.setActionable(FileActions.get(aipId, repId));

    ListSelectionUtils.bindBrowseOpener(filesList);

    filesSearch = new SearchPanel(filter, ALL_FILTER, true, messages.searchPlaceHolder(), false, false, true);
    filesSearch.setList(filesList);

    // DISSEMINATIONS
    disseminationsList = new DIPList(Filter.NULL, Facets.NONE, messages.listOfDisseminations(), true);
    disseminationsList.setActionable(DisseminationActions.get());
    ListSelectionUtils.bindBrowseOpener(disseminationsList);

    disseminationsSearch = new SearchPanel(Filter.NULL, RodaConstants.DIP_SEARCH, true,
            messages.searchPlaceHolder(), false, false, true);
    disseminationsSearch.setList(disseminationsList);

    // INIT
    initWidget(uiBinder.createAndBindUi(this));

    // STATUS
    aipState.setHTML(HtmlSnippetUtils.getAIPStateHTML(state));
    aipState.setVisible(!justActive);

    // IDENTIFICATION

    HTMLPanel representationIconHtmlPanel = new HTMLPanel(
            DescriptionLevelUtils.getRepresentationTypeIcon(representation.getType(), false));
    representationIconHtmlPanel.addStyleName("browseItemIcon-other");
    representationIcon.setWidget(representationIconHtmlPanel);

    String type = representation.getType() != null ? representation.getType() : representation.getId();
    representationType.setHTML(HtmlSnippetUtils.getRepresentationTypeHTML(type, representation.isOriginal()));
    representationId.setText(representation.getId());

    breadcrumb.updatePath(BreadcrumbUtils.getRepresentationBreadcrumbs(bundle));
    breadcrumb.setVisible(true);

    // DESCRIPTIVE METADATA

    final List<Pair<String, HTML>> descriptiveMetadataContainers = new ArrayList<>();
    final Map<String, DescriptiveMetadataViewBundle> bundles = new HashMap<>();
    for (DescriptiveMetadataViewBundle descMetadataBundle : bundle.getRepresentationDescriptiveMetadata()) {
        String title = descMetadataBundle.getLabel() != null ? descMetadataBundle.getLabel()
                : descMetadataBundle.getId();
        HTML container = new HTML();
        container.addStyleName("metadataContent");
        itemMetadata.add(container, title);
        descriptiveMetadataContainers.add(Pair.of(descMetadataBundle.getId(), container));
        bundles.put(descMetadataBundle.getId(), descMetadataBundle);
    }

    HandlerRegistration tabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {

        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() < descriptiveMetadataContainers.size()) {
                Pair<String, HTML> pair = descriptiveMetadataContainers.get(event.getSelectedItem());
                String descId = pair.getFirst();
                final HTML html = pair.getSecond();
                final DescriptiveMetadataViewBundle bundle = bundles.get(descId);
                if (html.getText().length() == 0) {
                    getDescriptiveMetadataHTML(descId, bundle, new AsyncCallback<SafeHtml>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            if (!AsyncCallbackUtils.treatCommonFailures(caught)) {
                                Toast.showError(messages.errorLoadingDescriptiveMetadata(caught.getMessage()));
                            }
                        }

                        @Override
                        public void onSuccess(SafeHtml result) {
                            html.setHTML(result);
                        }
                    });
                }
            }
        }
    });

    final int addTabIndex = itemMetadata.getWidgetCount();
    FlowPanel addTab = new FlowPanel();
    addTab.add(new HTML(SafeHtmlUtils.fromSafeConstant("<i class=\"fa fa-plus-circle\"></i>")));
    itemMetadata.add(new Label(), addTab);
    HandlerRegistration addTabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() == addTabIndex) {
                newRepresentationDescriptiveMetadata();
            }
        }
    });
    addTab.addStyleName("addTab");
    addTab.getParent().addStyleName("addTabWrapper");

    handlers.add(tabHandler);
    handlers.add(addTabHandler);

    if (!bundle.getRepresentationDescriptiveMetadata().isEmpty()) {
        newDescriptiveMetadata.setVisible(false);
        itemMetadata.setVisible(true);
        itemMetadata.selectTab(0);
    } else {
        newDescriptiveMetadata.setVisible(true);
        itemMetadata.setVisible(false);
    }

    // DISSEMINATIONS (POST-INIT)
    if (bundle.getDipCount() > 0) {
        Filter disseminationsFilter = new Filter(
                new SimpleFilterParameter(RodaConstants.DIP_REPRESENTATION_UUIDS, repUUID));
        disseminationsList.set(disseminationsFilter, state.equals(AIPState.ACTIVE), Facets.NONE);
        disseminationsSearch.setDefaultFilter(disseminationsFilter, true);
        disseminationsSearch.clearSearchInputBox();
    }
    disseminationsList.getParent().setVisible(bundle.getDipCount() > 0);

    // SIDEBAR
    actionsSidebar.setWidget(RepresentationActions.get(aipId).createActionsLayout(representation,
            new AsyncCallback<Actionable.ActionImpact>() {

                @Override
                public void onFailure(Throwable caught) {
                    AsyncCallbackUtils.defaultFailureTreatment(caught);
                }

                @Override
                public void onSuccess(Actionable.ActionImpact impact) {
                    if (Actionable.ActionImpact.UPDATED.equals(impact)) {
                        BrowserService.Util.getInstance().retrieve(IndexedRepresentation.class.getName(),
                                representation.getUUID(), representationFields,
                                new AsyncCallback<IndexedRepresentation>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        AsyncCallbackUtils.defaultFailureTreatment(caught);
                                    }

                                    @Override
                                    public void onSuccess(IndexedRepresentation rep) {
                                        representation = rep;
                                        representationType.setText(rep.getType());
                                    }
                                });
                    }
                }
            }));

    ListSelectionUtils.bindLayout(representation, searchPrevious, searchNext, keyboardFocus, true, false, false,
            searchSection);

    // CSS
    this.addStyleName("browse");
    this.addStyleName("browse-representation");
    this.addStyleName(state.toString().toLowerCase());

    Element firstElement = this.getElement().getFirstChildElement();
    if ("input".equalsIgnoreCase(firstElement.getTagName())) {
        firstElement.setAttribute("title", "browse input");
    }

    WCAGUtilities.getInstance().makeAccessible(itemMetadata.getElement());
}

From source file:org.rstudio.core.client.files.filedialog.ChooseFolderDialog.java

License:Open Source License

@Override
public void onSelection(SelectionEvent<FileSystemItem> event) {
    super.onSelection(event);
    FileSystemItem item = event.getSelectedItem();
    if (item != null && item.isDirectory())
        filename_.setText(item.getName());
}

From source file:org.rstudio.core.client.files.filedialog.ChooseFolderDialog2.java

License:Open Source License

@Override
public void onSelection(SelectionEvent<FileSystemItem> event) {
    super.onSelection(event);
    FileSystemItem item = event.getSelectedItem();
    if (item != null)
        filename_.setText(item.getPath());
    else/*from  ww w .  j a va  2 s .co m*/
        filename_.setText("");
}

From source file:org.rstudio.core.client.files.filedialog.FileDialog.java

License:Open Source License

@Override
public void onSelection(SelectionEvent<FileSystemItem> event) {
    super.onSelection(event);

    FileSystemItem item = event.getSelectedItem();
    if (item != null && !item.isDirectory())
        filename_.setText(item.getName());
}

From source file:org.rstudio.core.client.files.filedialog.OpenFileDialog.java

License:Open Source License

@Override
public void onSelection(SelectionEvent<FileSystemItem> event) {
    super.onSelection(event);

    // clear the active filename whenever a directory
    // is selected -- this allows us to disambiguate
    // 'fresh' from 'stale' user input; ie, tell whether
    // the user is navigating in the widget or typing in
    // the file name textbox
    if (event.getSelectedItem().isDirectory())
        browser_.setFilename("");
}

From source file:org.rstudio.core.client.prefs.PreferencesDialogBase.java

License:Open Source License

protected PreferencesDialogBase(String caption, String panelContainerStyle, boolean showApplyButton,
        PreferencesDialogPaneBase<T>[] panes) {
    super();//from w w  w  .  ja v a2 s.  c om
    setText(caption);
    panes_ = panes;

    PreferencesDialogBaseResources res = PreferencesDialogBaseResources.INSTANCE;

    sectionChooser_ = new SectionChooser();

    ThemedButton okButton = new ThemedButton("OK", new ClickHandler() {
        public void onClick(ClickEvent event) {
            attemptSaveChanges(new Operation() {
                @Override
                public void execute() {
                    closeDialog();
                }
            });
        }
    });
    addOkButton(okButton);
    addCancelButton();

    if (showApplyButton) {
        addButton(new ThemedButton("Apply", new ClickHandler() {
            public void onClick(ClickEvent event) {
                attemptSaveChanges();
            }
        }));
    }

    progressIndicator_ = addProgressIndicator(false);
    panel_ = new DockLayoutPanel(Unit.PX);
    panel_.setStyleName(panelContainerStyle);
    container_ = new FlowPanel();
    container_.getElement().getStyle().setPaddingLeft(10, Unit.PX);

    addStyleName(res.styles().preferencesDialog());

    for (final PreferencesDialogPaneBase<T> pane : panes_) {
        sectionChooser_.addSection(pane.getIcon(), pane.getName());
        pane.setWidth("100%");
        pane.setDialog(this);
        pane.setProgressIndicator(progressIndicator_);
        container_.add(pane);
        setPaneVisibility(pane, false);
        pane.addEnsureVisibleHandler(new EnsureVisibleHandler() {
            public void onEnsureVisible(EnsureVisibleEvent event) {
                sectionChooser_.select(container_.getWidgetIndex(pane));
            }
        });
    }

    panel_.addWest(sectionChooser_, sectionChooser_.getDesiredWidth());
    panel_.add(container_);

    sectionChooser_.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> e) {
            Integer index = e.getSelectedItem();

            if (currentIndex_ != null)
                setPaneVisibility(panes_[currentIndex_], false);

            currentIndex_ = index;

            if (currentIndex_ != null)
                setPaneVisibility(panes_[currentIndex_], true);
        }
    });

    sectionChooser_.select(0);
}

From source file:org.rstudio.studio.client.workbench.codesearch.CodeSearch.java

License:Open Source License

@Inject
public CodeSearch(Display display, final FileTypeRegistry fileTypeRegistry, final EventBus eventBus) {
    display_ = display;//from  w w w.j a  v  a2 s . c om

    final SearchDisplay searchDisplay = display_.getSearchDisplay();
    searchDisplay.setAutoSelectEnabled(true);

    searchDisplay.addSelectionHandler(new SelectionHandler<Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            CodeNavigationTarget target = display_.getSearchOracle()
                    .navigationTarget(searchDisplay.getLastValue(), event.getSelectedItem());

            // create full file path and position
            String srcFile = target.getFile();
            final FileSystemItem srcItem = FileSystemItem.createFile(srcFile);
            final FilePosition pos = target.getPosition();

            // fire editing event (delayed so the Enter keystroke 
            // doesn't get routed into the source editor)
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    display_.getSearchDisplay().clear();
                    display_.getSearchOracle().clear();

                    if (observer_ != null)
                        observer_.onCompleted();

                    fileTypeRegistry.editFile(srcItem, pos);
                }
            });
        }
    });

    searchDisplay.addCloseHandler(new CloseHandler<SearchDisplay>() {
        @Override
        public void onClose(CloseEvent<SearchDisplay> event) {
            display_.getSearchDisplay().clear();

            if (observer_ != null)
                observer_.onCancel();
        }
    });

    // various conditions invalidate the search oracle's cache

    searchDisplay.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            display_.getSearchOracle().clear();
        }
    });

    searchDisplay.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            display_.getSearchOracle().clear();
        }
    });

    eventBusHandlers_.add(eventBus.addHandler(FileChangeEvent.TYPE, new FileChangeHandler() {
        @Override
        public void onFileChange(FileChangeEvent event) {
            // if this was an R file then invalide the cache
            CodeSearchOracle oracle = display_.getSearchOracle();
            if (oracle.hasCachedResults()) {
                FileSystemItem fsi = event.getFileChange().getFile();
                if (fsi.getExtension().toLowerCase().equals(".r"))
                    oracle.clear();
            }
        }
    }));

    searchDisplay.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            boolean hasSearch = event.getValue().length() != 0;
            if (!hasSearch) {
                display_.getSearchOracle().invalidateSearches();
                display_.getSuggestionDisplay().hideSuggestions();
            }
        }
    });

    searchDisplay.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            // eat key-up if the suggestions are showing (since the 
            // suggestions menu is taking these and if we take it
            // the cursor will go to the beginning of the selection)
            if (display_.getSuggestionDisplay().isSuggestionListShowing()
                    && (event.getNativeKeyCode() == KeyCodes.KEY_UP)) {
                event.preventDefault();
                event.stopPropagation();
            }
        }

    });
}

From source file:org.rstudio.studio.client.workbench.ui.PaneManager.java

License:Open Source License

private Triad<LogicalWindow, WorkbenchTabPanel, MinimizedModuleTabLayoutPanel> createTabSet(
        String persisterName, ArrayList<Tab> tabs) {
    final WindowFrame frame = new WindowFrame();
    final WorkbenchTabPanel tabPanel = new WorkbenchTabPanel(frame);
    MinimizedModuleTabLayoutPanel minimized = new MinimizedModuleTabLayoutPanel();

    populateTabPanel(tabs, tabPanel, minimized);

    frame.setFillWidget(tabPanel);/*from   w w w  .  j  a v  a  2  s.co  m*/

    minimized.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
            int tab = integerSelectionEvent.getSelectedItem();
            tabPanel.selectTab(tab);
        }
    });

    tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
            session_.persistClientState();
        }
    });

    new SelectedTabStateValue(persisterName, tabPanel);

    return new Triad<LogicalWindow, WorkbenchTabPanel, MinimizedModuleTabLayoutPanel>(
            new LogicalWindow(frame, minimized), tabPanel, minimized);
}