List of usage examples for com.google.gwt.event.dom.client HasClickHandlers addClickHandler
HandlerRegistration addClickHandler(ClickHandler handler);
From source file:asquare.gwt.tk.client.ui.AlertDialog.java
License:Apache License
/** * Adds a widget to button panel. The widget will be added to the focus * cycle if it implements {@link HasFocus} and does not have a tabIndex < 0. * The widget must implement {@link SourcesClickEvents}. When the widget is * clicked, the specified command will be executed. * //www . j ava 2 s .co m * @param widget the widget to add * @param hotKey the keycode of a key which will execute the widget's * associated command when pressed * @param type a constant representing special button behavior * @param closeDialog <code>true</code> to close the dialog when the * button is clicked * @param command a command to execute if the widget is clicked, or * <code>null</code> * @throws ClassCastException if <code>widget</code> does not implement * {@link SourcesClickEvents} */ public void addButton(Widget widget, char hotKey, int type, final boolean closeDialog, final Command command) { HasClickHandlers clickable = (HasClickHandlers) widget; boolean focusable = widget instanceof Focusable; final HideAndExecuteCommand command0 = new HideAndExecuteCommand(AlertDialog.this, closeDialog, command); clickable.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { command0.execute(); } }); m_buttonPanel.add(widget); if (focusable) { getFocusModel().add((Focusable) widget); } if ((type & BUTTON_DEFAULT) != 0) { widget.addStyleName("tk-AlertDialog-defaultButton"); m_defaultButton = widget; if (focusable && getFocusModel().contains((Focusable) widget)) { getFocusModel().setFocusWidget((Focusable) widget); } } if ((type & BUTTON_CANCEL) != 0) { m_keyMap.put((char) KeyEvent.KEYCODE_ESCAPE, command0); } if (hotKey > 0) { m_keyMap.put(Character.toUpperCase(hotKey), command0); } }
From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java
License:Apache License
public static void fireClickOnHandler(final HasClickHandlers source, final ClickHandler handler) { final HandlerRegistration handlerRegistration = source.addClickHandler(handler); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override/* w ww. j a v a 2 s.c om*/ public void execute() { NativeEvent event = createZeroClick(); DomEvent.fireNativeEvent(event, source); handlerRegistration.removeHandler(); } }); }
From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java
License:Apache License
protected void updateItems() { boolean recreateItemHolder = isRecreateItemHolderOnRefresh() && itemHolder.getParent() != null; if (recreateItemHolder) { itemHolder.removeFromParent();/* w w w .j av a 2 s . c om*/ createItemHolder(); } HasWidgets itemHolder = itemHolderAsHasWidgets(); itemHolder.clear(); if (isUseCellList()) { updateItemsCellList("", itemHolder); return; } emptyItems = true; if (hintLabel != null) { itemHolder.add(hintLabel); emptyItems = false; } for (G c : keys) { if (!itemMap.containsKey(c)) { continue; } Label l = new Label(c.toString().toUpperCase()); l.setStyleName("group-heading"); groupCaptions.add(l); addGroupHeading(itemHolder, l); if (c.toString().trim().isEmpty()) { l.getElement().getStyle().setVisibility(Visibility.HIDDEN); } else { emptyItems = false; } int ctr = itemMap.get(c).size(); for (T item : itemMap.get(c)) { emptyItems = false; String sep = (--ctr != 0 && separatorText.length() != 1) ? separatorText : ""; HasClickHandlers hch = createItem(item, false, charWidth, itemsHaveLinefeeds, l, sep); hch.addClickHandler(clickHandler); if (popdown) { hch.addClickHandler(popdownHider); } itemHolder.add((Widget) hch); if (ctr != 0 && sep.length() == 0) { addDefaultSeparator(itemHolder); } } } if (!itemHolder.iterator().hasNext() && emptyItemsText != null) { Label empty = new Label(emptyItemsText); empty.setStyleName("empty-items"); itemHolder.add(empty); } if (recreateItemHolder) { scroller.setWidget(this.itemHolder); } afterUpdateItems(emptyItems); }
From source file:cc.kune.bootstrap.client.actions.ui.BSWidgetMenuGui.java
License:GNU Affero Public License
@Override public AbstractGuiItem create(final GuiActionDescrip descriptor) { final Object value = descriptor.getValue(ParentWidget.PARENT_UI); if (value != null) { // Already created ... so reset ((BSWidgetMenuGui) value).getMenu().clear(); return this; }/*from w ww . j av a2s . c o m*/ this.descriptor = descriptor; final DropDown dropDown = new DropDown(); final Anchor anchor = new Anchor(); anchor.setDataToggle(Toggle.DROPDOWN); dropDown.add(anchor); menu = new DropDownMenu(); widget = (Widget) descriptor.getValue(WidgetMenuDescriptor.WIDGET); popup = new PopupBSMenuGui(menu, widget, descriptor); dropDown.add(menu); HasClickHandlers widgetHasClick; try { widgetHasClick = (HasClickHandlers) widget; } catch (final ClassCastException e) { throw new UIException("Cannot cast to HasClickHandlers descriptor" + descriptor); } widgetHasClick.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { event.stopPropagation(); clickHandlerDefault.onClick(event); show(); } }); descriptor.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { if (event.getPropertyName().equals(MenuDescriptor.MENU_HIDE)) { hide(); } else if (event.getPropertyName().equals(MenuDescriptor.MENU_SHOW)) { show(); } // } else if // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_DOWN)) // { // menu.moveSelectionDown(); // } else if // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_UP)) { // menu.moveSelectionUp(); // } else if // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECT_ITEM)) { // final HasMenuItem item = (HasMenuItem) ((MenuItemDescriptor) // descriptor.getValue(MenuDescriptor.MENU_SELECT_ITEM)).getValue(MenuItemDescriptor.UI); // menu.selectItem((MenuItem) item.getMenuItem()); // } } }); if ((Boolean) descriptor.getValue(MenuDescriptor.MENU_ATRIGHT)) { menu.setPull(Pull.RIGHT); } descriptor.putValue(ParentWidget.PARENT_UI, this); initWidget(dropDown); configureItemFromProperties(); final String id = HTMLPanel.createUniqueId(); menu.getElement().setId(id); return this; }
From source file:com.edgenius.wiki.gwt.client.render.PageRender.java
License:Open Source License
/** * @param spaceUname //from w ww. j a v a2 s .c om * @param panel * @param model * @param pieces: could be pageContent, or side bar content * @param isPreivew: if this render is for preview window */ public void renderContent(final String spaceUname, PageModel page, List<RenderPiece> pieces, boolean isPreivew) { //most stuff only need renderPiece, except PageAuthorPanel at moment widgetRenderContent = new StringBuffer(); widgetCounter.clear(); widgetContainer.clear(); panel.clear(); if (pieces != null) { int size = pieces.size(); for (int idx = 0; idx < size; idx++) { Object piece = pieces.get(idx); if (piece instanceof LinkModel) { LinkModel ln = (LinkModel) piece; if (listeners != null) { fireRenderEvent(ln.getView()); } final String anchorTxt = StringUtil.isBlank(ln.getAnchor()) ? "" : (EscapeUtil.escapeToken(ln.getAnchor().trim())); if (anchorTxt.length() != 0 && StringUtil.isBlank(ln.getLink())) { //[view>#anchor] style: will only redirect to anchor in same page ClickLink link = new ClickLink(ln.getView(), true); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { GwtClientUtils.gotoAnchor(anchorTxt); } }); panel.add(link); } else if (ln.getType() == LinkModel.LINK_TO_CLIENT_CLICK_LINK) { final String[] token = LinkUtil.parseCLinkParamters(ln.getLink()); if (token != null && token.length > 0) { //If it has anchor field, it will be treated as hyper link.Otherwise, ClickLink if (!StringUtil.isEmpty(ln.getAnchor())) { //now it only support user popup - so need to consolidate if want to more functions EventfulHyperLink link = new EventfulHyperLink(ln.getView(), ln.getAnchor()); String method = token[0]; String[] params = null; if (token.length > 1) { params = new String[token.length - 1]; for (int idx1 = 1; idx1 < token.length; idx1++) { params[idx1 - 1] = token[idx1]; } } JavascriptExposer.run(method, params, link); panel.add(link); } else { //click link ClickLink link = new ClickLink(ln.getView(), true); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String method = token[0]; String[] params = null; if (token.length > 1) { params = new String[token.length - 1]; for (int idx = 1; idx < token.length; idx++) { params[idx - 1] = token[idx]; } } JavascriptExposer.run(method, params, (Widget) event.getSource()); } }); panel.add(link); } } else { panel.add(new HTML(ln.getView())); Log.error("Unable pasre link with type 'client click link':" + ln.getLink()); } } else if (ln.getType() == LinkModel.LINK_TO_SERVER_CLICK_LINK) { } else { if (isPreivew) { ClickLink link = new ClickLink(ln.getView(), true); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Window.alert(Msg.consts.preview_disable_link()); } }); panel.add(link); } else { String tokenName = ln.getLink(); String linkSpaceUname = ln.getSpaceUname(); //extspace or current space, if null(failure tolerance) use current spaceUname as value linkSpaceUname = (linkSpaceUname == null || linkSpaceUname.trim().length() == 0) ? spaceUname : linkSpaceUname; if (ln.getType() == LinkModel.LINK_TO_CREATE_FLAG) { //$CREATE ,for link to non-exist page, or for "PAGE_NOT_FOUND" case tokenName = GwtUtils.buildToken(PageMain.TOKEN_CREATE, linkSpaceUname, tokenName); } else if (ln.getType() == LinkModel.LINK_TO_CREATE_HOME_FLAG) { tokenName = GwtUtils.buildToken(PageMain.TOKEN_CREATE_HOME, linkSpaceUname, tokenName); } else if (ln.getType() == LinkModel.LINK_TO_OPEN_NEW_WIN) { //no use so far tokenName = GwtUtils.buildToken(PageMain.TOKEN_OPEN_NEW_WINDOW, linkSpaceUname, tokenName); } else if (ln.getType() == LinkModel.LINK_TO_HYPER_TOKEN) { //keep token unchanged - nothing to do here. } else tokenName = GwtUtils.getSpacePageToken(linkSpaceUname, tokenName); tokenName += (anchorTxt == "" ? "" : "#" + anchorTxt); Hyperlink link = new Hyperlink(ln.getView(), true, tokenName); panel.add(link); } } } else if (piece instanceof MacroModel) { MacroModel rs = (MacroModel) piece; if (rs != null) { if (rs.macroName.equalsIgnoreCase(SharedConstants.MACRO_SPACE_ADMIN)) { SpaceAdminRenderWidget adminPanel = new SpaceAdminRenderWidget(spaceUname); panel.add(adminPanel); widgetContainer.add(adminPanel); adminPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equalsIgnoreCase(SharedConstants.MACRO_NOTIFY_SYSADMIN)) { SendingNotifyRenderWidget adminPanel = new SendingNotifyRenderWidget(); panel.add(adminPanel); widgetContainer.add(adminPanel); adminPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_TAG_CLOUD)) { TagCloudRenderWidget macroPanel = new TagCloudRenderWidget(spaceUname); panel.add(macroPanel); widgetContainer.add(macroPanel); macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_TEMPLATE_LIST)) { TemplateListRenderWidget macroPanel = new TemplateListRenderWidget(spaceUname); panel.add(macroPanel); widgetContainer.add(macroPanel); macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_SEARCH)) { String keyword = (String) rs.values.get(NameConstants.KEYWORD); SearchRenderWidget macroPanel = new SearchRenderWidget(keyword); panel.add(macroPanel); widgetContainer.add(macroPanel); macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_USER_PROFILE)) { String username = rs.values.get(NameConstants.USERNAME); UserProfileRenderWidget macroPanel = new UserProfileRenderWidget(username); panel.add(macroPanel); widgetContainer.add(macroPanel); macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_INCLUDE)) { String src = rs.values.get(NameConstants.SRC); LinkModel link = LinkUtil.parseMarkup(src); if (StringUtil.isBlank(link.getSpaceUname())) { //if @space is blank, treat as current space link.setSpaceUname(spaceUname); } IncludeRenderWidget includePanel = new IncludeRenderWidget(link); panel.add(includePanel); widgetContainer.add(includePanel); includePanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_COMMENT)) { String title = (String) rs.values.get(NameConstants.TITLE); ClickLink comment = new ClickLink(title); comment.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (BaseEntryPoint.I != null && BaseEntryPoint.I instanceof PageMain) { PageMain main = ((PageMain) BaseEntryPoint.I); if (main.getVisiblePanelIndex() == PageMain.VIEW_PANEL) { main.viewPanel.tabPanel.newComment(); return; } } Window.alert(Msg.consts.not_available_mode()); } }); widgetRenderContent.append(title); panel.add(comment); } else if (rs.macroName.equals(SharedConstants.MACRO_PORTAL)) { boolean show = BooleanUtil.toBooleanTrue(rs.values.get(NameConstants.SHOWLOGO)); int column = NumberUtil.toInt(rs.values.get(NameConstants.COLUMNS), -1); if (column == -1) { //this is just for makes this macro can tolerance spell error - colunm or columns column = NumberUtil.toInt(rs.values.get(NameConstants.COLUMN), -1); } if (column == -1) { column = SharedConstants.DEFAULT_PORTAL_COLUMNS; } if (visitor == null) { //default portal visitor - don't use InstancePortalVisitor as it is dangerous to change default dashboard visitor = new HomePortalVisitor(); } Portal portal = new Portal(visitor, column, show); panel.add(portal); widgetContainer.add(portal); portal.onLoad(HTMLPanel.createUniqueId(), currentUser, this); } else if (rs.macroName.equals(SharedConstants.MACRO_FEEDBACK)) { String imgOn = rs.values.get(NameConstants.IMAGE); HasClickHandlers btn; if (StringUtil.isBlank(imgOn)) { //text base link String title = (String) rs.values.get(NameConstants.TITLE); btn = new ClickLink(title); } else { btn = new Image(imgOn); } btn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { FeedbackDialog dialog = new FeedbackDialog(); dialog.showbox(); } }); //for hide welcome message widgetRenderContent.append("feedback");//NON-I18N panel.add((Widget) btn); } else if (rs.macroName.equals(SharedConstants.MACRO_SIGNUP)) { String imgOn = rs.values.get(NameConstants.IMAGE); HasClickHandlers btn; if (StringUtil.isBlank(imgOn)) { //text base link String title = (String) rs.values.get(NameConstants.TITLE); btn = new ClickLink(title); } else { btn = new Image(imgOn); } btn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { LoginDialog dialogue = new LoginDialog(LoginDialog.SINGUP); dialogue.showbox(); } }); //for hide welcome message widgetRenderContent.append("signup");//NON-I18N panel.add((Widget) btn); } } } else if (piece instanceof TextModel) { String text = ((TextModel) piece).toString(); panel.add(text); if (listeners != null) { fireRenderEvent(text); } } } } panel.submit(); if (listeners != null) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { attemptFireRenderEnd(); } }); } }
From source file:com.gafactory.core.client.ui.lists.BaseListPresenter.java
License:Open Source License
public void addActions(List<Action<T>> actions) { if (actions != null) { for (final Action<T> action : actions) { actionList.add(action);//from w w w. j ava 2s .co m final HasClickHandlers actionWidget = getView().addAction(action); if (action.getType().equals(Action.ACTION_TYPE.SCRIPT)) { registerHandler(actionWidget.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (action.isEnabled(getSelectedObject())) { action.perform(getSelectedObject()); } } })); } } } }
From source file:com.google.api.explorer.client.FullView.java
License:Apache License
/** * Display the specified service entries in the container provided, while applying the tags * generated by the tag processor./*from ww w . ja va2s . c o m*/ */ private void populateServiceEntries(Iterable<ServiceDefinition> services, EntryAggregatorView toPopulate, Set<TagProcessor> tagProcessors) { for (final ServiceDefinition service : services) { String iconUrl = service.getIcons().getIcon16Url(); String displayName = NameHelper.generateDisplayTitle(service.getTitle(), service.getName()); Set<DescriptionTag> tags = Sets.newHashSet(); for (TagProcessor processor : tagProcessors) { tags.addAll(processor.process(service)); } HasClickHandlers rowHandle = toPopulate.addEntry( new ServiceEntry(iconUrl, displayName, service.getVersion(), service.getDescription(), tags)); rowHandle.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { presenter.handleClickService(service); } }); } }
From source file:com.google.api.explorer.client.FullView.java
License:Apache License
/** * Display the spcified history items in the aggregator specified. * * @param prefix Prefix that should be prepended to the history item URL when an item is clicked, * changes based on whether this was a search result or the history item list. * @param historyItems Items which to render and display in the aggregator, * @param aggregator Aggregator that will display rendered history items. *///from w w w . ja v a 2 s . c o m private void populateHistoryItems(final String prefix, Iterable<HistoryItem> historyItems, EntryAggregatorView aggregator) { for (final HistoryItem item : historyItems) { ApiRequest request = item.getRequest(); HasClickHandlers rowHandler = aggregator.addEntry(new HistoryEntry(request.getMethod().getId(), request.getHttpMethod().toString() + " " + request.getRequestPath(), item.getEndTime())); rowHandler.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { presenter.handleClickHistoryItem(prefix, item); } }); } }
From source file:com.google.api.explorer.client.FullView.java
License:Apache License
/** * Add an aggregator line for the particular method specified. When clicked, append the prefix * specified and then the method identifier to the current URL. *//* w w w . ja v a 2 s .co m*/ private void populateMethodEntry(final ApiMethod method, @Nullable String serviceTitle, final String prefix, EntryAggregatorView aggregator) { HasClickHandlers rowHandler = aggregator .addEntry(new MethodEntry(method.getId(), serviceTitle, method.getDescription())); rowHandler.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { presenter.handleClickMethod(prefix, method); } }); }
From source file:com.google.livingstories.client.lsp.LspContentItemListWidget.java
License:Apache License
protected void addMoreLinkHandler(HasClickHandlers moreLink) { moreLink.addClickHandler(new ClickHandler() { @Override/*w w w . j a v a 2 s. co m*/ public void onClick(ClickEvent event) { LivingStoryControls.getMoreContentItems(); } }); }