@Override public void prepareToAdoptChildren() { if (!this.hasChildren()) { // BEFORE the item is prepared to adopt children, it's just like: // <li> // <input type="checkbox" class="expander" disabled> <!-- input.expander DISABLED = no child --> // <span class="expander"></span> // <input type="checkbox" class="selection"> // <!-- the widget --> <!-- if it's a text item: <label>Child Node 1</label> --> // <!-- there's NO child items container --> // </li> // // AFTER the item is prepared to adopt children, it's: // <li> // <input type="checkbox" class="expander"> <!-- input.expander ENABLED = has child --> // <span class="expander"></span> // <input type="checkbox" class="selection"> // <!-- the widget --> <!-- if it's a text item: <label>Child Node 1</label> --> // <ul class='childContainer'> <!-- child items container is present --> // ... here will come the child items // </ul> // </li> // // [1] - Create a child items container UL by cloning the BASE_INTERNAL_ELEM UListElement childContainerULElem = DOM.clone(BASE_CHILD_CONTAINER_ELEM,// an UL true) // deep cloning .cast(); // [2] - set the new UL as a child of the item (the LI) LIElement parentLI = this.getElement().cast(); parentLI.appendChild(childContainerULElem); // [3] - Change the <input type="checkbox" class="expander"> status from DISABLED to ENABLED InputElement expanderINPUT = parentLI.getFirstChild().cast(); // from Node to Element expanderINPUT.setDisabled(false); } else { throw new IllegalStateException(); } }
public final void appendList(ArrayList<String> choices, boolean ordered, String additionalStyle) { if (choices == null || choices.size() == 0) { return; } FlowPanel htmlList = new FlowPanel(ordered? OListElement.TAG : UListElement.TAG); if (additionalStyle != null && additionalStyle.length() > 0) { _promptChar.getElement().setAttribute("style", additionalStyle); } for (String choice : choices) { FlowPanel item = new FlowPanel(LIElement.TAG); item.getElement().setInnerText(choice); htmlList.add(item); } appendAndScrollOrFocusAsAppropriate(htmlList); }
public static LIElement findTreeViewItemLIElement(final Element element) { LIElement outLIElement = null; Element currElement = element; while (currElement != null) { if (LIElement.is(currElement)) { Element parentElement = currElement.getParentElement(); if (UListElement.is(parentElement) && CONTAINER_UL_CSS_CLASS_NAME.equals(parentElement.getClassName())) { outLIElement = currElement.cast(); } else { currElement = parentElement.getParentElement(); } } else { currElement = currElement.getParentElement(); } if (outLIElement != null) break; } return outLIElement; }
private static TreeViewItem _findItemIn(final Collection<TreeViewItem> items, final LIElement element) { TreeViewItem outItem = null; if (items != null && items.size() > 0) { for(TreeViewItem item : items) { if (outItem != null) break; if (item.getElement().cast() == element) { outItem = item; } else if (item.hasChildren()) { outItem = _findItemIn(item.getChildren(),element); } } } return outItem; }
private static LIElement _createBaseTagElement() { // <ul class='tags'> // <li><span><img />Tag1</span></li> // <li><span><img />Tag1</span></li> // ... // </ul> LIElement containerLIEl = DOM.createElement("li").cast(); SpanElement spanEl = DOM.createSpan().cast(); ImageElement imgEl = DOM.createImg().cast(); // assemble the structure spanEl.appendChild(imgEl); spanEl.appendChild(Document.get().createTextNode("")); containerLIEl.appendChild(spanEl); return containerLIEl; }
@Override @SuppressWarnings("fallthrough") public void onBrowserEvent(final Event event) { super.onBrowserEvent(event); int eventType = DOM.eventGetType(event); Element eventTargetEl = DOM.eventGetTarget(event); // GWT.log("_____" + eventTargetEl.getNodeName() + ": " + event.getType()); switch (eventType) { case Event.ONCLICK: { if (ImageElement.is(eventTargetEl)) { LIElement tagLIElement = _findTagLIElementContaining(eventTargetEl); T tag = _tagForElement(tagLIElement); this.removeTag(tag); } break; } } }
/** * Creates an empty tree item. */ TreeViewItem(final CanBePaintedAsWidget viewObjectToWidgetTransformer) { // Create the item element structure LIElement elem = DOM.clone(BASE_ELEM, // a simple LI true) // deep cloning .cast(); elem.setAttribute("id",DOM.createUniqueId()); this.setElement(elem); // Set the ViewObject to Widget transformer _viewObjectToWidgetTransformer = viewObjectToWidgetTransformer; // Create the items container delegate _childItemsContainerDelegate = new TreeViewIsHierarchicalDelegate<TreeViewItem>(_viewObjectToWidgetTransformer, this); // Create other delegates _hideDisplayDelegate = new ViewHideDisplayDelegate(this); _enableDisableDelegate = new ViewEnableDisableDelegate(this); // Create the observable delegate _observableDelegate = new ObservableTreeViewItemDelegate(this); }
@Override public void onLazyLoadingSuccessful(final Collection<ViewObject> children) { // GWT.log("====>" + this.getText() + " > " + (children != null ? children.size() : 0) + " child loaded"); // Remove the loading... label LabelElement loadingLabel = _childLoadingSPANElement(); LIElement parentLI = this.getElement().cast(); parentLI.removeChild(loadingLabel); // if the number of children loaded is 0 (there where no child items), hide the expander // otherwise paint the children if (CollectionUtils.isNullOrEmpty(children)) { _expanderINPUTElement().setDisabled(true); } else { this.paintChildren(children); } }
private void addEntry(String entry, boolean logout) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(entry); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if (Event.ONCLICK == event.getTypeInt()) { if (!logout) { onRoleClicked(entry); } else { onLogoutClicked(); } } }); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); roleList.appendChild((Node) li); }
@Override public void addSourceCodeItem(String name) { AnchorElement anchor = Document.get().createAnchorElement(); String displayName = DisplayerHtmlConstants.INSTANCE.getString("displayer_source_code_" + name); anchor.setInnerText(displayName); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); tabList.appendChild((Node) li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if(Event.ONCLICK == event.getTypeInt()) { presenter.onSourceCodeItemSelected(name); if (selectedItem != null) { selectedItem.setClassName(""); selectedItem.getStyle().setCursor(Style.Cursor.POINTER); } selectedItem = li; selectedItem.setClassName("active"); selectedItem.getStyle().setCursor(Style.Cursor.DEFAULT); previewItem.setClassName(""); } }); }
@Override public void declareVariable(String var, String description) { SpanElement span = Document.get().createSpanElement(); span.setInnerText(var); AnchorElement anchor = Document.get().createAnchorElement(); anchor.setTitle(description); anchor.appendChild(span); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); variablesMenu.appendChild((Node) li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if(Event.ONCLICK == event.getTypeInt()) { presenter.onVariableSelected(var); } }); }
@Override public void addBreadcrumbItem(String navItemName, Command onClicked) { LIElement li = Document.get().createLIElement(); breadcrumb.appendChild((Node) li); if (onClicked != null) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(navItemName); li.appendChild(anchor); li.getStyle().setCursor(Style.Cursor.POINTER); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if (Event.ONCLICK == event.getTypeInt()) { onClicked.execute(); } }); } else { ((Node) li).setTextContent(navItemName); li.setClassName("active"); } }
private void addItem(UnorderedList unorderedList, String name, boolean selected, Command onSelect) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(name); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); li.setClassName(selected ? "selected" : ""); unorderedList.appendChild((Node) li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if(Event.ONCLICK == event.getTypeInt()) { onSelect.execute(); } }); }
@Override public void addCommand(String name, Command command) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(name); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); commandMenu.appendChild((Node) li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if(Event.ONCLICK == event.getTypeInt()) { command.execute(); } }); }
@Override public void addItem(String id, String name, String description, Command onItemSelected) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(name); if (description != null && !description.equals(name)) { anchor.setTitle(description); } LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); navWidget.appendChild((Node) li); itemMap.put(id, li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if (Event.ONCLICK == event.getTypeInt()) { onItemSelected.execute(); } }); }
@Override public void addItem(String name, Command onSelect) { AnchorElement anchor = Document.get().createAnchorElement(); anchor.setInnerText(name); LIElement li = Document.get().createLIElement(); li.getStyle().setCursor(Style.Cursor.POINTER); li.appendChild(anchor); selectorItems.appendChild((Node) li); Event.sinkEvents(anchor, Event.ONCLICK); Event.setEventListener(anchor, event -> { if(Event.ONCLICK == event.getTypeInt()) { onSelect.execute(); } }); }
@Override public void addHitPolicyOption( final GuidedDecisionTable52.HitPolicy hitPolicy ) { final AnchorElement anchor = Document.get() .createAnchorElement(); anchor.setInnerText( HitPolicyInternationalizer.internationalize( hitPolicy ) ); Event.sinkEvents( anchor, Event.ONCLICK ); Event.setEventListener( anchor, event -> { if ( Event.ONCLICK == event.getTypeInt() ) { presenter.onHitPolicySelected( hitPolicy ); } } ); final LIElement li = Document.get() .createLIElement(); li.appendChild( anchor ); listOfAvailableHitModes.appendChild( (Node) li ); }
/** * Finds the TreeView item that contains the provided {@link Element} * (this {@link Element} usually is the {@link EventTarget}) * @param element * @param tree * @return */ public static TreeViewItem findTreeViewItemContaining(final Element element, final TreeView tree) { // Find the eventTarget parent LI and the tree view item associated with it LIElement liElement = TreeViewUtils.findTreeViewItemLIElement(element); TreeViewItem item = _findItemIn(tree.getChildren(), liElement); return item; }
/** * Inserts a tag at a position * @param tag * @param position */ public void insertTagAt(final T tag,final int position) { // Check the index if (position < 0 || position > this.getTagCount()) throw new IndexOutOfBoundsException(); // Check the tag existence if (_elementForTag(tag) != null) return; // Tag already exists // Create the LI element for the tag LIElement liElement = DOM.clone(BASE_TAG_ELEM, // a simple LI true) // deep cloning .cast(); // Set the span text liElement.getChild(0) // span .getChild(1) // span text (child(0) is the image) .setNodeValue(tag.getCaption()); // Physical attach. if (position == this.getTagCount()) { _tagsContainerULElement.appendChild(liElement); } else { LIElement beforeLIElem = _tagsContainerULElement.getChild(position).cast(); _tagsContainerULElement.insertBefore(liElement, beforeLIElem); } // Logical attach. if (_tags == null) _tags = new LinkedHashMap<T,LIElement>(); _insertMapEntryAt(_tags, tag,liElement, position); // Nofify observers _observableDelegate.notifyObserversAboutChildAddition(tag); }
/** * Removes a tag * @param tag */ public void removeTag(final T tag) { LIElement tagLIElem = _elementForTag(tag); if (tagLIElem == null) return; // Physical detach the li from it's parent ul. _tagsContainerULElement.removeChild(tagLIElem); // Logical detach. _tags.remove(tag); // Nofify observers _observableDelegate.notifyObserversAboutChildRemoval(tag); }
private T _tagForElement(final LIElement liElement) { T outTag = null; for (Map.Entry<T,LIElement> tagsMapEntry : _tags.entrySet()) { if (tagsMapEntry.getValue() == liElement) { outTag = tagsMapEntry.getKey(); break; } } return outTag; }
private static LIElement _findTagLIElementContaining(final Element element) { LIElement outLIElement = null; Element currElement = element; while (currElement != null) { if (LIElement.is(currElement)) { outLIElement = currElement.cast(); } else { currElement = currElement.getParentElement(); } if (outLIElement != null) break; } return outLIElement; }
private static LIElement _createBaseElement() { // <li> // [1] --- EXPANDER -- // <input type="checkbox" class="expander" disabled> <!-- input.expander DISABLED = no child --> // <span class="expander"></span> // // [2] --- CHECK // <input type="checkbox" class="selection"> // // [3] --- WIDGET // <!-- the widget --> <!-- if it's a text item: <label>Child Node 1</label> --> // </li> // [1] - Create the expander hidden checkbox and span to fake the expander image over the checkbox TreeViewExpanderDOMElements expanderDOMEls = TreeViewUtils.createExpanderDOMElements(); // [2] - Create the selection checkbox InputElement checkINPUT = DOM.createInputCheck().cast(); checkINPUT.addClassName(TreeViewUtils.CHECKER_CLASS_NAME); // [3] - Create the container LI LIElement containerLI = DOM.createElement("li").cast(); Roles.getTreeitemRole().set(containerLI); // assemble the structure containerLI.appendChild(expanderDOMEls.getInputElement()); containerLI.appendChild(expanderDOMEls.getSpanElement()); containerLI.appendChild(checkINPUT); return containerLI; }
@Override public void allChildrenGone() { UListElement childContainerULElement = _childrenContainerULElement(); assert(childContainerULElement != null && childContainerULElement.getChildCount() == 0); LIElement containerLI = this.getElement().cast(); containerLI.removeChild(childContainerULElement); }
@Override public void onLazyLoadingInProgress() { // [1] - Create a child label element with the "loading..." text LabelElement loadingLabelEl = DOM.clone(BASE_LOADING_ELEM, // a label true) // deep cloning .cast(); // [2] - set the label as a child of the item (the LI) LIElement parentLI = this.getElement().cast(); parentLI.insertAfter(loadingLabelEl, _widget.getElement()); // the loading label is ALLWAYS after the widget }
/** * Builds the element structure: * <pre class='brush:html'> * <ul class='treeview'> * <li> * <input type="checkbox" class="expander" disabled> <!-- input.expander DISABLED = no child --> * <span class="expander"></span> * * <!-- The root node widget --> <!-- usually is a the tree caption --> * * <ul class='childContainer'>..</ul> <!-- the child items container --> * </li> * </ul> * </pre> */ private void _initDOM() { // [1] - Create a main UL UListElement mainULEl = DOM.createElement("ul").cast(); mainULEl.addClassName(TreeViewUtils.TREEVIEW_CSS_CLASS_NAME); // [2] - Create a single LI for the tree label and append it to the UL LIElement mainLIEl = DOM.createElement("li").cast(); mainULEl.appendChild(mainLIEl); // [3] - Create an UL to contain the root nodes and append it to the title's LI _rootNodesContainerElement = DOM.createElement("ul").cast(); _rootNodesContainerElement.addClassName(TreeViewUtils.CONTAINER_UL_CSS_CLASS_NAME); mainLIEl.appendChild(_rootNodesContainerElement); // [4] - set the widget DOM element this.setElement(mainULEl); // Capture events this.sinkEvents(Event.ONMOUSEDOWN | Event.ONCLICK | Event.KEYEVENTS); // = DOM.sinkEvents(this.getElement(),Event.ONMOUSEDOWN | Event.ONCLICK | Event.KEYEVENTS) DOM.sinkEvents(this.getElement(), // main UL Event.FOCUSEVENTS); // Add area role "tree" Roles.getTreeRole() .set(this.getElement()); }
/** * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) */ @Override public void setValue(CallTraceBean value, boolean fireEvents) { if (value != null) { List<TraceNodeBean> tasks = value.getTasks(); for (TraceNodeBean task : tasks) { LIElement li = createTreeNode(task); getElement().appendChild(li); } } }
@Override public void redraw() { this.getElement().removeAllChildren(); for (Error error : this.errors) { LIElement errorElement = Document.get().createLIElement(); errorElement.setInnerText(error.getMessageKey()); this.getElement().appendChild(errorElement); } }