Example usage for com.google.gwt.user.client.ui TreeItem getText

List of usage examples for com.google.gwt.user.client.ui TreeItem getText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TreeItem getText.

Prototype

public String getText() 

Source Link

Usage

From source file:org.drools.guvnor.client.explorer.navigation.browse.BrowseTreeViewImpl.java

License:Apache License

private void addSelectionHandler() {
    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
        public void onSelection(SelectionEvent<TreeItem> treeItemSelectionEvent) {
            TreeItem selectedItem = treeItemSelectionEvent.getSelectedItem();
            presenter.onTreeItemSelection(selectedItem, selectedItem.getText());
        }/*  w w  w .  j a  v a  2s  .  co  m*/
    });
}

From source file:org.drools.guvnor.client.explorer.PackagesTree.java

License:Apache License

public void onSelection(SelectionEvent<TreeItem> event) {
    TreeItem node = event.getSelectedItem();
    Object userObject = node.getUserObject();

    TabOpener opener = TabOpener.getInstance();

    if (userObject != null) {
        if (userObject instanceof PackageConfigData && !((PackageConfigData) userObject).isGlobal()) {
            PackageConfigData pc = (PackageConfigData) userObject;
            RulePackageSelector.currentlySelectedPackage = pc.name;

            String uuid = pc.uuid;
            opener.openPackageEditor(uuid, new Command() {
                public void execute() {
                    // refresh the package tree.
                    refreshTree();// ww  w .  java2s  .co  m
                }
            });
        } else if (userObject instanceof String[]) {
            final String[] formats = (String[]) userObject;
            final PackageConfigData packageConfigData = (PackageConfigData) node.getParentItem()
                    .getUserObject();
            RulePackageSelector.currentlySelectedPackage = packageConfigData.name;
            String key = key(formats, packageConfigData);
            opener.openPackageViewAssets(packageConfigData.uuid, packageConfigData.name, key,
                    formats.length == 0 ? null : Arrays.asList(formats),
                    formats.length == 0 ? Boolean.TRUE : null, node.getText());
        } else if (userObject instanceof String) {
            // Ignore, there is no click event for this.
        } else {
            throw new IllegalArgumentException("The userObject (" + userObject + ") is not supported.");
        }
    }
}

From source file:org.ebayopensource.turmeric.monitoring.client.presenter.ConsumerPresenter.java

License:Open Source License

/**
 * Bind./*from ww  w  . java2  s .c o  m*/
 */
public void bind() {
    // listen for any uploads of the services/operations list by other tabs
    this.eventBus.addHandler(GetServicesEvent.TYPE, new GetServicesEventHandler() {

        public void onData(GetServicesEvent event) {
            // only fetch once?
            if (ConsumerPresenter.this.servicesList == null) {
                ConsumerPresenter.this.servicesList = event.getData();
                ConsumerPresenter.this.view.setServicesMap(event.getData());
            }
        }

    });

    // listen for any changes from other tabs to the currently selected
    // service or operation
    this.eventBus.addHandler(ObjectSelectionEvent.TYPE, new ObjectSelectionEventHandler() {

        public void onSelection(ObjectSelectionEvent event) {
            selectionContext = new SelectionContext();
            if (event.getSelection(ObjectType.ServiceName) != null)
                selectionContext.select(ObjectType.ServiceName, event.getSelection(ObjectType.ServiceName));
            if (event.getSelection(ObjectType.OperationName) != null)
                selectionContext.select(ObjectType.OperationName, event.getSelection(ObjectType.OperationName));
        }
    });

    // listen for any changes from other tabs to the currently selected
    // dates
    this.eventBus.addHandler(DateFilterSelectionEvent.TYPE, new DateFilterSelectionHandler() {

        public void onSelection(DateFilterSelectionEvent event) {
            selectedDate1 = event.getDate1();
            selectedDate2 = event.getDate2();
            selectedDuration = event.getDuration();
            view.getFilter().setHours1(Util.getAvailableHours(selectedDate1));
            view.getFilter().setHour1(new Date(selectedDate1).getHours());
            view.getFilter().setDate1(new Date(selectedDate1));

            view.getFilter().setDate2(new Date(selectedDate2));
            view.getFilter().setDuration(selectedDuration);
        }
    });

    // listen for user selection of date1
    this.view.addValueChangeHandlerForDate1(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            int[] hrs = Util.getAvailableHours(date);
            ConsumerPresenter.this.view.getFilter().setHours1(hrs);
        }
    });

    // handle user selection of some new dates and intervals to see metrics
    // for

    this.view.addFilterOptionsApplyClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // Get the date component
            long oldDate1 = selectedDate1;
            long oldDate2 = selectedDate2;
            selectedDate1 = ConsumerPresenter.this.view.getFilter().getDate1().getValue().getTime();
            selectedDate2 = ConsumerPresenter.this.view.getFilter().getDate2().getValue().getTime();

            // Get the hour component
            int hour1 = ConsumerPresenter.this.view.getFilter().getHour1();
            int hour2 = ConsumerPresenter.this.view.getFilter().getHour1();
            selectedDate1 += (Util.HRS_1_MS * hour1);
            selectedDate2 += (Util.HRS_1_MS * hour2);

            // Get the selected interval
            int oldDuration = selectedDuration;
            selectedDuration = ConsumerPresenter.this.view.getFilter().getDuration();

            view.setFilterLabel(makeFilterLabel(selectedDate1, selectedDate2, selectedDuration));

            // tell other interested tabs that the selected dates have
            // changed
            if ((oldDate1 != selectedDate1) || (oldDate2 != selectedDate2)
                    || (oldDuration != selectedDuration)) {
                eventBus.fireEvent(
                        new DateFilterSelectionEvent(selectedDate1, selectedDate2, selectedDuration));
            }

            // Get which metrics are required
            selectedMetrics = Util.convertToEnumFromCamelCase(
                    ConsumerPresenter.this.view.getFilter().getSelectedMetricNames(), ConsumerMetric.class);

            // Clean up from previous selections
            ConsumerPresenter.this.view.reset();

            // Make a history event so the back/forward buttons work but
            // don't fire it as we don't
            // want to change pages
            fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2, selectedDuration);
            insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDuration, selectedMetrics,
                    false);
        }
    });

    // handle selection of service or operation from list
    this.view.addTreeElementSelectionHandler(new SelectionHandler<TreeItem>() {

        public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem selection = event.getSelectedItem();
            // get service and or operation name corresponding to
            // this selection
            selectionContext.unselect(ObjectType.ServiceName);
            selectionContext.unselect(ObjectType.OperationName);
            // If its the root, ignore it
            if (selection.getParentItem() != null) {
                // If its a leaf, its an operation
                if (selection.getChildCount() == 0) {
                    selectionContext.select(ObjectType.OperationName, selection.getText());
                    selectionContext.select(ObjectType.ServiceName, selection.getParentItem().getText());

                } else {
                    // Its a service
                    selectionContext.select(ObjectType.ServiceName, selection.getText());
                }
            }
            view.setSelection(selectionContext.getSelections());

            eventBus.fireEvent(new ObjectSelectionEvent(selectionContext.getSelections()));

            // Get the date component
            selectedDate1 = ConsumerPresenter.this.view.getFilter().getDate1().getValue().getTime();
            selectedDate2 = ConsumerPresenter.this.view.getFilter().getDate2().getValue().getTime();

            // Get the hour component
            int hour1 = ConsumerPresenter.this.view.getFilter().getHour1();
            int hour2 = ConsumerPresenter.this.view.getFilter().getHour1();
            selectedDate1 += (Util.HRS_1_MS * hour1);
            selectedDate2 += (Util.HRS_1_MS * hour2);

            // Get the interval
            selectedDuration = ConsumerPresenter.this.view.getFilter().getDuration();

            // Get the metrics requested
            selectedMetrics = Util.convertToEnumFromCamelCase(
                    ConsumerPresenter.this.view.getFilter().getSelectedMetricNames(), ConsumerMetric.class);
            view.reset();
            // Fetch set of metrics for the selected
            // service/operation for the currently selected dates
            fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2, selectedDuration);

            // Make a history event so the back/forward buttons work
            // but don't fire it as we don't
            // want to change pages
            insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDuration, selectedMetrics,
                    false);
        }
    });
}

From source file:org.ebayopensource.turmeric.monitoring.client.presenter.ErrorPresenter.java

License:Open Source License

/**
 * Bind.//from   w  ww.java  2 s . co m
 */
public void bind() {

    //listen for any uploads of the services/operations list by other tabs
    this.eventBus.addHandler(GetServicesEvent.TYPE, new GetServicesEventHandler() {

        public void onData(GetServicesEvent event) {
            //only fetch once?
            if (servicesList == null) {
                servicesList = event.getData();
                view.setServicesMap(event.getData());
            }
        }

    });

    //listen for any changes from other tabs to the currently selected service or operation
    this.eventBus.addHandler(ObjectSelectionEvent.TYPE, new ObjectSelectionEventHandler() {

        public void onSelection(ObjectSelectionEvent event) {
            selectionContext = new SelectionContext();

            Map<ObjectType, String> selections = event.getSelections();
            if (selections != null) {
                for (Map.Entry<ObjectType, String> entry : selections.entrySet()) {
                    if (entry.getValue() != null)
                        selectionContext.select(entry.getKey(), entry.getValue());
                }
            }
        }
    });

    //listen for any changes from other tabs to the currently selected dates
    this.eventBus.addHandler(DateFilterSelectionEvent.TYPE, new DateFilterSelectionHandler() {

        public void onSelection(DateFilterSelectionEvent event) {
            selectedDate1 = event.getDate1();
            selectedDate2 = event.getDate2();
            selectedDurationHrs = event.getDuration();
            view.getFilter().setHours1(Util.getAvailableHours(selectedDate1));
            view.getFilter().setHour1(new Date(selectedDate1).getHours());
            view.getFilter().setDate1(new Date(selectedDate1));

            view.getFilter().setDate2(new Date(selectedDate2));
            view.getFilter().setDuration(selectedDurationHrs);
        }
    });

    //listen for user selection of date1
    this.view.addValueChangeHandlerForDate1(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            int[] hrs = Util.getAvailableHours(date);
            view.getFilter().setHours1(hrs);
        }
    });

    //handle user selection of some new dates and intervals to see metrics for

    this.view.addFilterOptionsApplyClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            //Get the date component
            long oldDate1 = selectedDate1;
            long oldDate2 = selectedDate2;
            selectedDate1 = view.getFilter().getDate1().getValue().getTime();
            selectedDate2 = view.getFilter().getDate2().getValue().getTime();

            //Get the hour component
            int hour1 = view.getFilter().getHour1();
            int hour2 = view.getFilter().getHour1();
            selectedDate1 += (Util.HRS_1_MS * hour1);
            selectedDate2 += (Util.HRS_1_MS * hour2);

            //Get the selected interval
            int oldDuration = selectedDurationHrs;
            selectedDurationHrs = view.getFilter().getDuration();

            view.setFilterLabel(makeFilterLabel(selectedDate1, selectedDate2, selectedDurationHrs));

            //tell other interested tabs that the selected dates have changed
            if ((oldDate1 != selectedDate1) || (oldDate2 != selectedDate2)
                    || (oldDuration != selectedDurationHrs)) {
                eventBus.fireEvent(
                        new DateFilterSelectionEvent(selectedDate1, selectedDate2, selectedDurationHrs));
            }

            view.setFilterLabel(makeFilterLabel(selectedDate1, selectedDate2, selectedDurationHrs));

            List<String> metrics = ((Filterable.ErrorFilterable) view.getFilter())
                    .getSelectedCategoryViewNames();
            if (metrics.isEmpty())
                metrics = ((Filterable.ErrorFilterable) view.getFilter()).getSelectedSeverityViewNames();

            //Get which metrics are required
            selectedMetrics = Util.convertToEnumFromCamelCase(metrics, ErrorMetric.class);

            //Clean up from previous selections
            view.reset();

            fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2, selectedDurationHrs);
            //Make a history event so the back/forward buttons work but don't fire it as we don't
            //want to change pages
            insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDurationHrs, selectedMetrics,
                    false);
        }
    });

    //handle selection of service or operation from list
    this.view.addTreeElementSelectionHandler(new SelectionHandler<TreeItem>() {

        public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem selection = event.getSelectedItem();
            //get service and or operation name corresponding to this selection
            selectionContext.unselect(ObjectType.ServiceName);
            selectionContext.unselect(ObjectType.OperationName);
            selectionContext.unselect(ObjectType.ErrorId);
            selectionContext.unselect(ObjectType.ErrorName);

            if (selection.getParentItem() != null) {
                selectionContext = new SelectionContext();
                //If its a leaf, its an operation
                if (selection.getChildCount() == 0) {
                    selectionContext.select(ObjectType.OperationName, selection.getText());
                    selectionContext.select(ObjectType.ServiceName, selection.getParentItem().getText());

                } else {
                    //Its a service
                    selectionContext.select(ObjectType.ServiceName, selection.getText());

                }
            }
            view.setSelection(selectionContext.getSelections());

            eventBus.fireEvent(new ObjectSelectionEvent(selectionContext.getSelections()));

            //Get the date component
            selectedDate1 = view.getFilter().getDate1().getValue().getTime();
            selectedDate2 = view.getFilter().getDate2().getValue().getTime();

            //Get the hour component
            int hour1 = view.getFilter().getHour1();
            int hour2 = view.getFilter().getHour1();
            selectedDate1 += (Util.HRS_1_MS * hour1);
            selectedDate2 += (Util.HRS_1_MS * hour2);

            //Get the interval
            selectedDurationHrs = view.getFilter().getDuration();

            //Get the metrics requested
            List<String> metrics = ((Filterable.ErrorFilterable) view.getFilter())
                    .getSelectedCategoryViewNames();
            if (metrics.isEmpty())
                metrics = ((Filterable.ErrorFilterable) view.getFilter()).getSelectedSeverityViewNames();

            //Get which metrics are required
            selectedMetrics = Util.convertToEnumFromCamelCase(metrics, ErrorMetric.class);

            view.reset();
            //Fetch set of metrics for the selected service/operation for the currently selected dates
            fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2, selectedDurationHrs);

            //Make a history event so the back/forward buttons work but don't fire it as we don't
            //want to change pages
            insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDurationHrs, selectedMetrics,
                    false);
        }
    });
}

From source file:org.ebayopensource.turmeric.monitoring.client.presenter.ServicePresenter.java

License:Open Source License

/**
 * Bind./*  w w  w .j  av  a  2 s  .c o m*/
 */
public void bind() {
    // listen for any changes from other tabs to the currently selected
    // service or operation
    this.eventBus.addHandler(ObjectSelectionEvent.TYPE, new ObjectSelectionEventHandler() {

        public void onSelection(ObjectSelectionEvent event) {
            selectionContext = new SelectionContext();
            if (event.getSelection(ObjectType.ServiceName) != null)
                selectionContext.select(ObjectType.ServiceName, event.getSelection(ObjectType.ServiceName));
            if (event.getSelection(ObjectType.OperationName) != null)
                selectionContext.select(ObjectType.OperationName, event.getSelection(ObjectType.OperationName));
        }
    });
    // listen for changes to date1 from other tabs
    this.view.addValueChangeHandlerForDate1(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            int[] hrs = Util.getAvailableHours(date);
            ServicePresenter.this.view.getFilter().setHours1(hrs);
        }
    });

    // handle user selection of some new dates and intervals to see metrics
    // for
    this.view.addFilterOptionsApplyClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            if (selectionContext.getSelection(ObjectType.ServiceName) == null) {
                view.error(ConsoleUtil.messages.selectServer());
            } else {
                // Get the date component
                selectedDate1 = ServicePresenter.this.view.getFilter().getDate1().getValue().getTime();
                selectedDate2 = ServicePresenter.this.view.getFilter().getDate2().getValue().getTime();

                // Get the hour component
                int hour1 = ServicePresenter.this.view.getFilter().getHour1();
                int hour2 = ServicePresenter.this.view.getFilter().getHour1();
                selectedDate1 += (Util.HRS_1_MS * hour1);
                selectedDate2 += (Util.HRS_1_MS * hour2);

                // Get the selected interval
                selectedDurationHrs = ServicePresenter.this.view.getFilter().getDuration();

                view.setFilterLabel(makeFilterLabel(selectedDate1, selectedDate2, selectedDurationHrs));

                // Inform of changes to dates and durations
                eventBus.fireEvent(
                        new DateFilterSelectionEvent(selectedDate1, selectedDate2, selectedDurationHrs));

                // Get which metrics are required
                selectedMetrics = Util.convertToEnumFromCamelCase(
                        ServicePresenter.this.view.getFilter().getSelectedMetricNames(), ServiceMetric.class);

                view.reset();
                // Window.alert("getApplyButton().addClickHandler. Before fetchMetrics");
                // Make a history event so the back/forward buttons work but
                // don't fire it as we don't
                // want to change pages
                fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2,
                        selectedDurationHrs);
                insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDurationHrs,
                        selectedMetrics, false);
            }
        }
    });

    // handle selection of service or operation from list
    this.view.addTreeElementSelectionHandler(new SelectionHandler<TreeItem>() {

        public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem selection = event.getSelectedItem();
            // get service and or operation name corresponding to
            // this selection
            selectionContext = new SelectionContext();

            // If its the root, then no service is selected
            if (selection.getParentItem() == null) {
                selectionContext.unselect(ObjectType.ServiceName);
                selectionContext.unselect(ObjectType.OperationName);
            } else {

                // If its a leaf, its an operation
                if (selection.getChildCount() == 0) {
                    selectionContext.select(ObjectType.ServiceName, selection.getParentItem().getText());
                    selectionContext.select(ObjectType.OperationName, selection.getText());
                } else {
                    // Its a service
                    selectionContext.select(ObjectType.ServiceName, selection.getText());
                }
            }

            view.setSelection(selectionContext.getSelections());
            // tell any interested parties the user has selected a
            // service or operation
            fireObjectSelectionEvent(selectionContext);

            // Get the date component
            selectedDate1 = ServicePresenter.this.view.getFilter().getDate1().getValue().getTime();
            selectedDate2 = ServicePresenter.this.view.getFilter().getDate2().getValue().getTime();

            // Get the hour component
            int hour1 = ServicePresenter.this.view.getFilter().getHour1();
            int hour2 = ServicePresenter.this.view.getFilter().getHour1();
            selectedDate1 += (Util.HRS_1_MS * hour1);
            selectedDate2 += (Util.HRS_1_MS * hour2);

            // Get the interval
            selectedDurationHrs = ServicePresenter.this.view.getFilter().getDuration();

            // Inform of the selection of dates and duration
            eventBus.fireEvent(new DateFilterSelectionEvent(selectedDate1, selectedDate2, selectedDurationHrs));

            // Get the metrics requested
            selectedMetrics = Util.convertToEnumFromCamelCase(
                    ServicePresenter.this.view.getFilter().getSelectedMetricNames(), ServiceMetric.class);

            view.reset();

            // If at least a service was selected, get the metrics
            // for the currently selected date
            if (selectionContext.isSelected(ObjectType.ServiceName))
                fetchMetrics(selectedMetrics, selectionContext, selectedDate1, selectedDate2,
                        selectedDurationHrs);

            // Make a history event so the back/forward buttons work
            // but don't fire it as we don't
            // want to change pages
            insertHistory(selectionContext, selectedDate1, selectedDate2, selectedDurationHrs, selectedMetrics,
                    false);
        }
    });
}

From source file:org.ebayopensource.turmeric.monitoring.client.view.ServiceListWidget.java

License:Open Source License

/**
 * Sets the selection./* w  w w .j  av  a 2  s .  c o m*/
 * 
 * @param service
 *            the service
 * @param operation
 *            the operation
 */
public void setSelection(String service, String operation) {
    selectedService = service;
    selectedOperation = operation;

    if (serviceTree != null) {
        TreeItem selectedItem = null;
        if (service == null)
            selectedItem = root;
        else {
            Iterator<TreeItem> itor = serviceTree.treeItemIterator();
            while (selectedItem == null && itor.hasNext()) {
                TreeItem item = itor.next();
                if (item.getChildCount() > 0) {
                    // we're looking at a service, check if it matches
                    if (selectedService != null && selectedService.equals(item.getText())
                            && selectedOperation == null) {
                        selectedItem = item;
                    }
                } else {
                    // we're looking at an operation, check if service and
                    // operation match
                    if (selectedService != null && selectedService.equals(item.getParentItem().getText())
                            && selectedOperation != null && selectedOperation.equals(item.getText())) {
                        selectedItem = item;
                    }
                }
            }
        }
        if (selectedItem != null) {
            serviceTree.setSelectedItem(selectedItem, false);
        }
        serviceTree.ensureSelectedItemVisible();
    }
}

From source file:org.ebayopensource.turmeric.policy.adminui.client.view.ServiceListWidget.java

License:Open Source License

/**
* Sets the selection.//ww w .  j av a2s.co m
* 
* @param service
*            the service
* @param operation
*            the operation
*/
public void setSelection(String service, String operation) {
    selectedService = service;
    selectedOperation = operation;

    if (serviceTree != null) {
        TreeItem selectedItem = null;
        if (service == null)
            selectedItem = root;
        else {
            Iterator<TreeItem> itor = serviceTree.treeItemIterator();
            while (selectedItem == null && itor.hasNext()) {
                TreeItem item = itor.next();
                if (item.getChildCount() > 0) {
                    //we're looking at a service, check if it matches
                    if (selectedService != null && selectedService.equals(item.getText())
                            && selectedOperation == null) {
                        selectedItem = item;
                    }
                } else {
                    //we're looking at an operation, check if service and operation match
                    if (selectedService != null && selectedService.equals(item.getParentItem().getText())
                            && selectedOperation != null && selectedOperation.equals(item.getText())) {
                        selectedItem = item;
                    }
                }
            }
        }
        if (selectedItem != null) {
            serviceTree.setSelectedItem(selectedItem, false);
        }
        serviceTree.ensureSelectedItemVisible();
    }
}

From source file:org.gatein.management.gadget.client.Application.java

License:Open Source License

/**
 * @return the openHandler/* w w w  .  j a va2 s. c o  m*/
 */
private OpenHandler<TreeItem> getOpenHandler() {
    OpenHandler<TreeItem> openHandler = new OpenHandler<TreeItem>() {

        public void onOpen(OpenEvent<TreeItem> event) {

            final TreeItem target = event.getTarget();
            final TreeNode tn = (TreeNode) target.getUserObject();
            String text = target.getText();
            target.setText("Loading items");

            if (target.getChildCount() > 0) {
                TreeItem it = target.getChild(0);
                if (it instanceof PendingItem) {
                    target.removeItem(it);
                }
            }

            if (target.getChildCount() == 0) {
                gtnService.updateItem(getPortalContainerName(), tn, new AsyncCallback<TreeNode>() {

                    public void onFailure(Throwable caught) {
                        Window.alert("Fail to update the tree items <br />" + caught);
                        Application.this.details.setHTML("Failed to load sub-tree");
                    }

                    public void onSuccess(TreeNode result) {

                        for (TreeNode tnChild : result.getChildren()) {
                            TreeItem it = Application.this.createItem(tnChild);
                            if (!tnChild.getChildren().isEmpty()) {
                                it.addItem(new PendingItem());
                            }
                            target.addItem(it);
                        }
                    }
                });
            }

            target.setText(text);
        }
    };

    return openHandler;
}

From source file:org.gatein.management.gadget.mop.exportimport.client.Application.java

License:Open Source License

private OpenHandler<TreeItem> createOpenHandler() {
    return new OpenHandler<TreeItem>() {
        @Override//from ww w. j  av a2s . co  m
        public void onOpen(OpenEvent<TreeItem> event) {
            final TreeItem target = event.getTarget();
            final TreeNode tn = (TreeNode) target.getUserObject();
            String text = target.getText();
            target.setText("Loading items");

            if (target.getChildCount() > 0) {
                TreeItem it = target.getChild(0);
                if (it instanceof PendingItem) {
                    target.removeItem(it);
                }
            }

            if (target.getChildCount() == 0) {
                gtnService.updateItem(getPortalContainerName(), tn, new AsyncCallback<TreeNode>() {

                    public void onFailure(Throwable caught) {
                        Window.alert("Failed to update tree items.  See server log for more details.");
                        Application.this.details.setHTML("Failed to load sub-tree");
                    }

                    public void onSuccess(TreeNode result) {

                        for (TreeNode tnChild : result.getChildren()) {
                            TreeItem it = Application.this.createItem(tnChild);
                            if (!tnChild.getChildren().isEmpty()) {
                                it.addItem(new PendingItem());
                            }
                            target.addItem(it);
                        }
                    }
                });
            }

            target.setText(text);
        }
    };
}

From source file:org.gss_project.gss.web.client.Groups.java

License:Open Source License

/**
 * Generate an RPC request to retrieve the users of the specified group for
 * display./*from   w  ww.ja v a 2 s  .  co m*/
 *
 * @param groupItem the TreeItem widget that corresponds to the requested
 *            group
 */
void updateUsers(final TreeItem groupItem) {
    if (groupItem.getUserObject() instanceof GroupResource) {
        GroupResource res = (GroupResource) groupItem.getUserObject();
        MultipleGetCommand<GroupUserResource> gu = new MultipleGetCommand<GroupUserResource>(
                GroupUserResource.class, res.getUserPaths().toArray(new String[] {}), null) {
            @Override
            public void onComplete() {
                List<GroupUserResource> users = getResult();
                groupItem.removeItems();
                for (int i = 0; i < users.size(); i++) {
                    final TreeItem userItem = addImageItem(groupItem,
                            users.get(i).getName() + " &lt;" + users.get(i).getUsername() + "&gt;",
                            images.permUser());
                    userItem.setUserObject(users.get(i));
                }
                if (selectedGroup != null && groupItem.getText().equals(selectedGroup)) {
                    //SelectionEvent.fire(tree, groupItem);;
                    onSelection(groupItem);
                    groupItem.setState(true);
                }
            }

            @Override
            public void onError(Throwable t) {
                GWT.log("", t);
            }

            @Override
            public void onError(String p, Throwable throwable) {
                GWT.log("Path:" + p, throwable);
            }
        };
        DeferredCommand.addCommand(gu);
    }

}