Search in sources :

Example 6 with TreeItem

use of com.google.gwt.user.client.ui.TreeItem in project che by eclipse.

the class PreviewViewImpl method createTreeElement.

private void createTreeElement(final TreeItem root, String changeName, List<RefactoringPreview> children) {
    FlowPanel element = new FlowPanel();
    element.getElement().getStyle().setFloat(LEFT);
    CheckBox itemCheckBox = new CheckBox();
    itemCheckBox.setValue(true);
    itemCheckBox.getElement().getStyle().setFloat(LEFT);
    itemCheckBox.getElement().getStyle().setMarginTop(3, PX);
    Label name = new Label(changeName);
    name.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            delegate.onSelectionChanged(containerChanges.get(root));
            root.setSelected(true);
        }
    });
    name.getElement().getStyle().setFloat(LEFT);
    element.add(itemCheckBox);
    element.add(name);
    root.setWidget(element);
    element.getElement().getParentElement().getStyle().setMargin(1, PX);
    itemCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            checkChildrenState(root, event.getValue());
            checkParentState(root, event.getValue());
            RefactoringPreview change = containerChanges.get(root);
            change.setEnabled(event.getValue());
            delegate.onEnabledStateChanged(change);
        }
    });
    if (children.isEmpty()) {
        return;
    }
    for (RefactoringPreview child : children) {
        TreeItem treeItem = new TreeItem();
        containerChanges.put(treeItem, child);
        createTreeElement(treeItem, child.getText(), child.getChildrens());
        root.addItem(treeItem);
    }
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) TreeItem(com.google.gwt.user.client.ui.TreeItem) CheckBox(com.google.gwt.user.client.ui.CheckBox) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) Label(com.google.gwt.user.client.ui.Label) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)

Example 7 with TreeItem

use of com.google.gwt.user.client.ui.TreeItem in project gwt-test-utils by gwt-test-utils.

the class TreeTest method selectedOnFocusWidget.

@Test
public void selectedOnFocusWidget() {
    // Given
    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {

        public void onSelection(SelectionEvent<TreeItem> event) {
            clickedTreeItem = event.getSelectedItem();
        }
    });
    // When on item2 which wrap a Checkbox
    tree.setSelectedItem(item2);
    TreeItem selected = tree.getSelectedItem();
    // Then
    assertThat(clickedTreeItem).isEqualTo(item2);
    assertThat(selected).isEqualTo(item2);
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) Test(org.junit.Test)

Example 8 with TreeItem

use of com.google.gwt.user.client.ui.TreeItem in project gwt-test-utils by gwt-test-utils.

the class TreeTest method beforeTreeTest.

@Before
public void beforeTreeTest() {
    // Create a tree with a few items in it.
    parent = new TreeItem(new SafeHtmlBuilder().appendEscaped("parent").toSafeHtml());
    item0 = parent.addItem(new SafeHtmlBuilder().appendEscaped("item0").toSafeHtml());
    item1 = parent.addItem(new SafeHtmlBuilder().appendEscaped("item1").toSafeHtml());
    // Add a CheckBox to the tree
    item2 = new TreeItem(new CheckBox("item2"));
    parent.addItem(item2);
    tree = new Tree();
    tree.addItem(parent);
    // Add it to the root panel.
    RootPanel.get().add(tree);
    assertThat(tree.isVisible()).isTrue();
    clickedTreeItem = null;
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) CheckBox(com.google.gwt.user.client.ui.CheckBox) Tree(com.google.gwt.user.client.ui.Tree) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Before(org.junit.Before)

Example 9 with TreeItem

use of com.google.gwt.user.client.ui.TreeItem in project gwt-test-utils by gwt-test-utils.

the class TreeTest method selected.

@Test
public void selected() {
    // Given
    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {

        public void onSelection(SelectionEvent<TreeItem> event) {
            clickedTreeItem = event.getSelectedItem();
        }
    });
    // When
    tree.setSelectedItem(item1);
    TreeItem selected = tree.getSelectedItem();
    // Then
    assertThat(clickedTreeItem).isEqualTo(item1);
    assertThat(selected).isEqualTo(item1);
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) Test(org.junit.Test)

Aggregations

TreeItem (com.google.gwt.user.client.ui.TreeItem)9 CheckBox (com.google.gwt.user.client.ui.CheckBox)4 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)3 Tree (com.google.gwt.user.client.ui.Tree)2 RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)2 Test (org.junit.Test)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Label (com.google.gwt.user.client.ui.Label)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 Before (org.junit.Before)1 Counter (org.rstudio.core.client.Counter)1 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)1