Search in sources :

Example 1 with TreeItem

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

the class PreviewViewImpl method setTreeOfChanges.

/** {@inheritDoc} */
@Override
public void setTreeOfChanges(final RefactoringPreview changes) {
    showDiffPanel(false);
    final SelectionModel<RefactoringPreview> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            RefactoringPreview selectedNode = (RefactoringPreview) ((SingleSelectionModel) selectionModel).getSelectedObject();
            delegate.onSelectionChanged(selectedNode);
        }
    });
    Tree tree = new Tree();
    tree.getElement().setId("tree-of-changes");
    for (RefactoringPreview parentChange : changes.getChildrens()) {
        TreeItem treeItem = new TreeItem();
        containerChanges.put(treeItem, parentChange);
        createTreeElement(treeItem, parentChange.getText(), parentChange.getChildrens());
        tree.addItem(treeItem);
    }
    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {

        @Override
        public void onSelection(SelectionEvent<TreeItem> event) {
            if (selectedElement != null) {
                selectedElement.getStyle().setProperty("background", "transparent");
            }
            selectedElement = event.getSelectedItem().getWidget().getElement();
            selectedElement.getStyle().setProperty("background", getEditorSelectionColor());
        }
    });
    treePanel.add(tree);
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) TreeItem(com.google.gwt.user.client.ui.TreeItem) Tree(com.google.gwt.user.client.ui.Tree) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 2 with TreeItem

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

the class DocumentOutlineWidget method rebuildScopeTree.

private void rebuildScopeTree(JsArray<Scope> scopeTree, Scope currentScope) {
    scopeTree_ = scopeTree;
    currentScope_ = currentScope;
    currentVisibleScope_ = getCurrentVisibleScope(currentScope_);
    if (scopeTree_.length() == 0) {
        setActiveWidget(emptyPlaceholder_);
        return;
    }
    setActiveWidget(tree_);
    int h1Count = 0;
    for (int i = 0; i < scopeTree_.length(); i++) {
        Scope node = scopeTree_.get(i);
        if (node.isMarkdownHeader()) {
            if (node.getDepth() == 1)
                h1Count++;
        }
    }
    int initialDepth = h1Count == 1 ? -1 : 0;
    Counter counter = new Counter(-1);
    for (int i = 0; i < scopeTree_.length(); i++) buildScopeTreeImpl(scopeTree_.get(i), initialDepth, counter);
    // Clean up leftovers in the tree. 
    int oldTreeSize = tree_.getItemCount();
    int newTreeSize = counter.increment();
    for (int i = oldTreeSize - 1; i >= newTreeSize; i--) {
        TreeItem item = tree_.getItem(i);
        if (item != null)
            item.remove();
    }
}
Also used : Counter(org.rstudio.core.client.Counter) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) TreeItem(com.google.gwt.user.client.ui.TreeItem)

Example 3 with TreeItem

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

the class ScopeTreeWidget method addItem.

private void addItem(Scope node) {
    TreeItem item = new TreeItem();
    item.setText(node.getLabel());
    tree_.addItem(item);
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem)

Example 4 with TreeItem

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

the class PreviewViewImpl method checkChildrenState.

private void checkChildrenState(TreeItem treeItem, Boolean value) {
    int childCount = treeItem.getChildCount();
    if (childCount == 0) {
        return;
    }
    for (int i = 0; i < childCount; i++) {
        TreeItem childItem = treeItem.getChild(i);
        if (!(childItem.getWidget() instanceof FlowPanel)) {
            return;
        }
        FlowPanel childItemContainer = (FlowPanel) childItem.getWidget();
        if (!(childItemContainer.getWidget(0) instanceof CheckBox)) {
            return;
        }
        CheckBox childCheckBox = (CheckBox) childItemContainer.getWidget(0);
        childCheckBox.setValue(value);
        checkChildrenState(childItem, value);
    }
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) CheckBox(com.google.gwt.user.client.ui.CheckBox) FlowPanel(com.google.gwt.user.client.ui.FlowPanel)

Example 5 with TreeItem

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

the class PreviewViewImpl method checkParentState.

private void checkParentState(TreeItem treeItem, Boolean value) {
    TreeItem parentItem = treeItem.getParentItem();
    if (parentItem == null) {
        return;
    }
    if (!(parentItem.getWidget() instanceof FlowPanel)) {
        return;
    }
    FlowPanel parentChangeContainer = (FlowPanel) parentItem.getWidget();
    if (!(parentChangeContainer.getWidget(0) instanceof CheckBox)) {
        return;
    }
    CheckBox parentCheckBox = (CheckBox) parentChangeContainer.getWidget(0);
    if (value && !parentCheckBox.getValue()) {
        parentCheckBox.setValue(true);
        checkParentState(parentItem, true);
    }
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) CheckBox(com.google.gwt.user.client.ui.CheckBox) FlowPanel(com.google.gwt.user.client.ui.FlowPanel)

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