Example usage for com.google.gwt.user.client Timer scheduleRepeating

List of usage examples for com.google.gwt.user.client Timer scheduleRepeating

Introduction

In this page you can find the example usage for com.google.gwt.user.client Timer scheduleRepeating.

Prototype

public synchronized void scheduleRepeating(final int periodMs) 

Source Link

Document

Schedules a timer that elapses repeatedly.

Usage

From source file:org.pentaho.support.di.client.DISupportUtility.java

License:Open Source License

/**
 * loads the module on UI call/*from   w  w w .ja v a  2 s  .  c  o  m*/
 */
@Override
public void onModuleLoad() {
    selectObj.setInstallType("Installer");
    ((ServiceDefTarget) disupportService).setServiceEntryPoint(getBaseUrl());
    RootPanel panel = RootPanel.get("maincontainer");
    mainPanel = new AbsolutePanel();
    mainPanel.setStyleName("mainPanel");
    panel.add(mainPanel, 0, 0);
    mainPanel.setSize("809px", "565px");

    bck_img = new Image("Images/login-crystal-bg.jpg");
    mainPanel.add(bck_img, 0, 0);
    bck_img.setSize("809px", "565px");

    logo_img = new Image("Images/puc-login-logo.png");
    mainPanel.add(logo_img, 10, 33);
    logo_img.setSize("360px", "93px");

    Label pentahoCustomerSupport = new Label("Pentaho Customer Support Wizard");
    mainPanel.add(pentahoCustomerSupport, 255, 132);
    pentahoCustomerSupport.setStyleName("pentaho-label");

    Label lblSelectInstallationType = new Label("Select Installation Type :");
    lblSelectInstallationType.setStyleName("gwt-Label-header");
    mainPanel.add(lblSelectInstallationType, 47, 184);

    rdbtnInstaller = new RadioButton("type", "Installer");
    rdbtnInstaller.setValue(true);
    rdbtnInstaller.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            selectObj.setInstallType("Installer");
        }
    });
    mainPanel.add(rdbtnInstaller, 196, 225);

    rdbtnArchive = new RadioButton("type", "Archive");
    rdbtnArchive.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            selectObj.setInstallType("Archive");
        }
    });
    mainPanel.add(rdbtnArchive, 353, 225);

    rdbtnManual = new RadioButton("type", "Manual");
    rdbtnManual.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            selectObj.setInstallType("Manual");
        }
    });
    mainPanel.add(rdbtnManual, 504, 225);

    AbsolutePanel absolutePanel = new AbsolutePanel();
    mainPanel.add(absolutePanel, 102, 254);
    absolutePanel.setSize("611px", "201px");

    selectDselect = new CheckBox("Select/De-Select");
    selectDselect.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            onSelectDselect();
        }
    });
    absolutePanel.add(selectDselect, 10, 10);

    VerticalPanel absolutePanel_left = new VerticalPanel();
    absolutePanel.add(absolutePanel_left, 68, 36);
    absolutePanel_left.setSize("200px", "160px");

    license = new CheckBox("License File");
    license.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    secure = new CheckBox("Secure Files");
    secure.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    md5 = new CheckBox("MD5 Hash Value");
    md5.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });
    running = new CheckBox("Running Process");
    running.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    environment = new CheckBox("Environment");
    environment.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    datasource = new CheckBox("Datasource Details");
    datasource.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    absolutePanel_left.add(license);
    absolutePanel_left.add(secure);
    absolutePanel_left.add(md5);
    absolutePanel_left.add(running);
    absolutePanel_left.add(environment);
    absolutePanel_left.add(datasource);

    VerticalPanel absolutePanel_right = new VerticalPanel();
    absolutePanel.add(absolutePanel_right, 362, 36);
    absolutePanel_right.setSize("200px", "160px");

    logs = new CheckBox("Logs");
    logs.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    structure = new CheckBox("Structure Details");
    structure.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    serverXml = new CheckBox("XML files from Server");
    serverXml.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    tomcatXml = new CheckBox("XML files from Tomcat");
    tomcatXml.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    serverbat = new CheckBox("Start up files from server");
    serverbat.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    serverProp = new CheckBox("Properites files from server");
    serverProp.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            checkList();
        }
    });

    absolutePanel_right.add(logs);
    absolutePanel_right.add(structure);
    absolutePanel_right.add(serverXml);
    absolutePanel_right.add(tomcatXml);
    absolutePanel_right.add(serverbat);
    absolutePanel_right.add(serverProp);

    Label information = new Label("Browser Information :");
    mainPanel.add(information, 74, 461);
    information.setSize("179px", "20px");
    information.setStyleName("label-browser");

    browserText = new TextBox();
    mainPanel.add(browserText, 255, 464);
    browserText.setSize("417px", "27px");

    button = new Button("Package");
    button.addClickHandler(new ClickHandler() {
        // sets the server name and checks for selected options
        public void onClick(ClickEvent event) {

            boolean result = false;
            selectObj.setServerName("diserver");

            if (selectDselect.getValue()) {

                selectObj.setBidiXml(true);
                selectObj.setBidiBatFile(true);
                selectObj.setBidiProrperties(true);
                selectObj.setTomcatXml(true);

                selectedItem = new ArrayList<String>();
                for (String item : DIConstant.SELECTEDITEM) {

                    selectedItem.add(item);
                }
                if (!browserText.getText().isEmpty()) {
                    selectObj.setBrowserInfo(browserText.getText());
                    selectedItem.add(DIConstant.BROWSER_INFO);
                }

                result = true;
            } else if (checkSelected()) {
                result = true;
            } else {
                message = null;
                message = new MessageDialogBox("Message", "Please select options to proceed", false, true,
                        true);
                showDialog();
            }

            if (result) {

                disableAll();

                final ProgressBar progressBar = new ProgressBar(0);
                DOM.setElementAttribute(progressBar.getElement(), "id", "progressBar");
                mainPanel.add(progressBar, 58, 508);

                Timer timer = new Timer() {
                    public void run() {
                        double progress = progressBar.getProgress() + 1;
                        if (progress > 100) {
                            cancel();
                        }
                        progressBar.setProgress(progress);
                    }
                };
                timer.scheduleRepeating(1500);

                disupportService.readandsaveSelectedConfiguration(selectedItem, selectObj,
                        new AsyncCallback<Boolean>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                message = new MessageDialogBox("Error", caught.getMessage(), false, true, true);
                                showDialog();
                            }

                            @Override
                            public void onSuccess(Boolean result) {
                                progressBar.removeFromParent();
                                button.setVisible(true);
                                selectedItem.clear();
                                enableAll();
                            }

                        });

            }
        }
    });
    mainPanel.add(button, 58, 508);
    button.setSize("661px", "30px");

}

From source file:org.pepstock.jem.gwt.client.security.CurrentUser.java

License:Open Source License

private CurrentUser() {
    Timer preferencesStoreTimer = new Timer() {

        @Override/*  ww  w .  j  a  va  2 s  .c  om*/
        public void run() {
            if (user != null) {
                storePreferences();
            }
        }
    };
    preferencesStoreTimer.run();
    preferencesStoreTimer.scheduleRepeating(PREFERENCES_STORE_INTERVAL);
}

From source file:org.primordion.xholon.base.XholonTime.java

License:Open Source License

public XholonTimerTask timeoutRepeat(IXholon clientNode, long delay, long period) {
    final XholonTimerTask xhTask = new XholonTimerTask(clientNode, null, TIMERTYPE_REPEAT, this);

    // GWT/*from  ww w.ja  va  2 s .c  o  m*/
    //timer.schedule(xhTask, delay, period);
    Timer timer = new Timer() {
        @Override
        public void run() {
            xhTask.run();
        }
    };
    timer.scheduleRepeating((int) period);

    return xhTask;
}

From source file:org.primordion.xholon.base.XholonTime.java

License:Open Source License

public XholonTimerTask timeoutRepeat(IXholon clientNode, Object data, long delay, long period) {
    final XholonTimerTask xhTask = new XholonTimerTask(clientNode, data, TIMERTYPE_REPEAT, this);

    // GWT/*w  w  w .  ja v  a  2 s  .co m*/
    //timer.schedule(xhTask, delay, period);
    Timer timer = new Timer() {
        @Override
        public void run() {
            xhTask.run();
        }
    };
    timer.scheduleRepeating((int) period);

    return xhTask;
}

From source file:org.rebioma.client.maps.TileLayerSelector.java

License:Apache License

/**
 * The timer is needed when a page is reloaded since it takes time for the
 * layers to return from the server./*from   ww  w. java 2  s  .  c o m*/
 * 
 * @param selectionIndex
 * @return
 */
public LayerInfo selectLayer(final int selectionIndex) {
    if (selectionIndices.isEmpty()) {
        Timer t = new Timer() {
            @Override
            public void run() {
                if (!selectionIndices.isEmpty()) {
                    selectLayer(selectionIndices.get(selectionIndex));
                    cancel();
                }
            }
        };
        t.scheduleRepeating(500);
    }
    return selectLayer(selectionIndices.get(selectionIndex));
}

From source file:org.rebioma.client.maps.TileLayerSelector.java

License:Apache License

public LayerInfo selectLayer(final String layerSelected, final TileLayerCallback callback) {
    if (layerSelected == null) {
        return null;
    }//from  w  w w  .j  a  v  a2  s .c  o m
    if (layerSelected.equals(LOADING)) {
        Timer t = new Timer() {
            @Override
            public void run() {
                if (!getItemText(0).equals(LOADING)) {
                    cancel();
                    selectLayer(layerSelected, callback);
                }
            }
        };
        t.scheduleRepeating(500);
        return null;
    }
    LayerInfo layerInfo = null;
    if (selectedLayer != null) {
        map.getOverlayMapTypes().removeAt(selectedLayer.getMapIndex());
    }
    if (layerLegend != null) {
        layerLegend.removeFromParent();
    }
    if (layerSelected.equals(SELECT) || layerSelected.equals(CLEAR)) {
        setSelectedIndex(selectionNames.get(SELECT));
        selectedLayer = null;
        layerLegend = null;
        callback.onLayerCleared(layerInfos.get(selectedLayer));
    } else {
        setSelectedIndex(selectionNames.get(layerSelected));
        layerInfo = layerInfos.get(layerSelected);
        selectedLayer = layerInfo.getInstance();
        ImageMapType overlay = selectedLayer.asOverlay();
        map.getOverlayMapTypes().push(overlay);
        selectedLayer.setMapIndex(map.getOverlayMapTypes().getLength() - 1);
        layerLegend = layerInfos.get(layerSelected).getInstance().getLegend();
        if (layerLegend != null) {
            map.setControls(ControlPosition.RIGHT_BOTTOM, layerLegend);
        }
        callback.onLayerSelected(layerInfo);
    }
    return layerInfo;
}

From source file:org.rebioma.client.OccurrenceView.java

License:Apache License

public void onClick(ClickEvent event) {
    Object sender = event.getSource();
    if (sender == mapLink) {
        switchView(MAP, false);//from   w w  w. j ava2s  .  c o m
        addHistoryItem(false);
        searchForm.restoreStatesFromHistory(History.getToken());
    } else if (sender == listLink) {
        switchView(LIST, false);
        addHistoryItem(false);
        searchForm.restoreStatesFromHistory(History.getToken());
    } else if (sender == uploadLink) {
        switchView(UPLOAD, false);
        activeViewInfo.getView().resetToDefaultState();
        addHistoryItem(false);
    } else if (sender == searchForm.advanceLink) {
        switchView(ADVANCE, false);
        helpLink.setStyleName("helplink");
        switchViewPanel.add(helpLink);
        addHistoryItem(false);
    } else if (sender == searchForm.shapeDialogLink) {
        ShapeFileWindow window = new ShapeFileWindow(constants);
        window.setWidth(400);
        window.setHeight(300);
        window.show();
        window.addTreeSelectHandler(this);
    } else if (sender == revalidateLink) {
        addHistoryItem(false);
        String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME);
        if (revalidateLink.getText().equals(constants.Revalidating())) {
            /*RevalidationService.Proxy.get().cancelRevalidation(sessionId, new AsyncCallback<Void>() {
                    
               @Override
               public void onFailure(Throwable caught) {
                  revalidateLink.setHTML(constants.Revalidate());
                          
               }
                    
               @Override
               public void onSuccess(Void result) {
                  revalidateLink.setHTML(constants.Revalidate());
                          
               }
            });*/
        } else {

            revalidateLink.setStyleName("revalidating", true);//add loading image
            final ServerPingServiceAsync pingService = ServerPingService.Proxy.get();
            final Timer sessionAliveTimer = new Timer() {
                public void run() {
                    pingService.ping(new AsyncCallback<Void>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            GWT.log("Error while pinging the server", caught);
                        }

                        @Override
                        public void onSuccess(Void result) {
                            GWT.log("Ping success");
                        }
                    });
                }
            };
            sessionAliveTimer.scheduleRepeating(REVALIDATION_SERVER_PING_INTERVAL);

            RevalidationService.Proxy.get().revalidate(sessionId, new AsyncCallback<RevalidationResult>() {

                @Override
                public void onSuccess(RevalidationResult result) {
                    GWT.log("Revalidation success");
                    revalidateLink.setHTML(constants.Revalidate());
                    new RevalidationResultPopup(result).show();
                    revalidateLink.setStyleName("revalidatelink");
                    revalidateLink.setStyleName("revalidatelink_success", true);
                    //Window.alert(constants.RevalidationSuccess());
                    sessionAliveTimer.cancel();

                }

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log("Error while revalidating", caught);
                    revalidateLink.setHTML(constants.Revalidate());
                    revalidateLink.setStyleName("revalidatelink");
                    revalidateLink.setStyleName("revalidatelink_error", true);
                    Window.alert(caught.getLocalizedMessage());
                    sessionAliveTimer.cancel();
                }
            });
            revalidateLink.setHTML(constants.Revalidating());
        }

    } else if (sender == ativityLink) {
        new ActivityLogDialog(constants).show();
    }
}

From source file:org.rhq.coregui.client.admin.roles.RoleLdapGroupSelector.java

License:Open Source License

/** Define search for case insensitive filtering on ldap name.
 *//* w ww  . j a  v  a  2  s. c  om*/
@Override
protected DynamicForm getAvailableFilterForm() {
    DynamicForm availableFilterForm = new DynamicForm();
    {
        availableFilterForm.setWidth100();
        availableFilterForm.setNumCols(2);
    }
    int groupPanelWidth = 375;
    int groupPanelHeight = 150;

    // Structure the display area into two separate display regions
    // Available Groups region
    final DynamicForm availableGroupDetails = new DynamicForm();
    {
        availableGroupDetails.setWidth(groupPanelWidth);
        availableGroupDetails.setHeight(groupPanelHeight);
        availableGroupDetails.setGroupTitle(MSG.common_title_ldapGroupsAvailable());
        availableGroupDetails.setIsGroup(true);
        availableGroupDetails.setWrapItemTitles(false);
        //add itemChanged handler to listen for changes to SearchItem
        availableGroupDetails.addItemChangedHandler(new ItemChangedHandler() {
            public void onItemChanged(ItemChangedEvent itemChangedEvent) {

                latestCriteria = getLatestCriteria(null);

                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        if (latestCriteria != null) {
                            Criteria criteria = latestCriteria;
                            latestCriteria = null;
                            populateAvailableGrid(criteria);
                        }
                    }
                };
                timer.schedule(500);
            }
        });
    }
    final TextItem resultCountItem = new TextItem("resultCount", MSG.common_title_groupsFound());
    {
        resultCountItem.setCanEdit(false);
        resultCountItem.setWidth("100%");
    }
    final TextItem pageCountItem = new TextItem("pageCount", MSG.common_title_queryPagesParsed());
    {
        pageCountItem.setCanEdit(false);
        pageCountItem.setWidth("100%");
    }
    final TextAreaItem adviceItem = new TextAreaItem("advice", MSG.common_title_suggest());
    {
        adviceItem.setWidth("100%");
        adviceItem.setHeight(20);
        String feedback = MSG.common_val_none();
        adviceItem.setValue(feedback);
        adviceItem.setTooltip(feedback);
        adviceItem.setDisabled(true);
        adviceItem.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                event.cancel();
                cursorPosition = adviceItem.getSelectionRange()[0];
            }
        });
        adviceItem.addChangedHandler(new ChangedHandler() {

            @Override
            public void onChanged(ChangedEvent event) {
                adviceItem.setSelectionRange(cursorPosition, cursorPosition);
            }
        });
    }
    //Customize Search component
    {
        searchTextItem.setName(MSG.common_title_search());
        searchTextItem.setTitle(MSG.view_admin_roles_filterResultsBelow());
        searchTextItem.setWidth("100%");
        searchTextItem.setTooltip(MSG.common_msg_typeToFilterResults());
    }
    final FormItemIcon loadingIcon = new FormItemIcon();
    final FormItemIcon successIcon = new FormItemIcon();
    final FormItemIcon failIcon = new FormItemIcon();
    final FormItemIcon attentionIcon = new FormItemIcon();
    String successIconPath = "[SKIN]/actions/ok.png";
    String failedIconPath = "[SKIN]/actions/exclamation.png";
    String loadingIconPath = "[SKIN]/loading.gif";
    String attentionIconPath = "[SKIN]/Dialog/warn.png";
    loadingIcon.setSrc(loadingIconPath);
    successIcon.setSrc(successIconPath);
    failIcon.setSrc(failedIconPath);
    attentionIcon.setSrc(attentionIconPath);

    final StaticTextItem groupQueryStatus = new StaticTextItem();
    {
        groupQueryStatus.setName("groupQueryStatus");
        groupQueryStatus.setTitle(MSG.common_title_queryProgress());
        groupQueryStatus.setDefaultValue(MSG.common_msg_loading());
        groupQueryStatus.setIcons(loadingIcon);
    }
    availableGroupDetails.setItems(resultCountItem, pageCountItem, groupQueryStatus, adviceItem,
            searchTextItem);

    // Ldap Group Settings region
    final DynamicForm ldapGroupSettings = new DynamicForm();
    {
        ldapGroupSettings.setWidth(groupPanelWidth);
        ldapGroupSettings.setHeight(groupPanelHeight);
        ldapGroupSettings.setGroupTitle(MSG.view_adminRoles_ldapGroupsSettingsReadOnly());
        ldapGroupSettings.setIsGroup(true);
        ldapGroupSettings.setWrapItemTitles(false);
    }
    final TextItem groupSearch = new TextItem("groupSearch", MSG.view_admin_systemSettings_LDAPFilter_name());
    {
        groupSearch.setCanEdit(false);
        groupSearch.setWidth("100%");
    }
    final TextItem groupMember = new TextItem("groupMember",
            MSG.view_admin_systemSettings_LDAPGroupMember_name());
    {
        groupMember.setCanEdit(false);
        groupMember.setWidth("100%");
    }
    final CheckboxItem groupQueryPagingItem = new CheckboxItem("groupQueryEnable",
            MSG.view_admin_systemSettings_LDAPGroupUsePaging_name());
    {
        groupQueryPagingItem.setCanEdit(false);
        groupQueryPagingItem.setValue(false);
        groupQueryPagingItem.setShowLabel(false);
        groupQueryPagingItem.setShowTitle(true);
        groupQueryPagingItem.setTitleOrientation(TitleOrientation.LEFT);
        //You have to set this attribute
        groupQueryPagingItem.setAttribute("labelAsTitle", true);
    }
    final TextItem groupQueryPagingCountItem = new TextItem("groupQueryCount",
            MSG.view_adminRoles_ldapQueryPageSize());
    {
        groupQueryPagingCountItem.setCanEdit(false);
        groupQueryPagingCountItem.setWidth("100%");
    }
    final CheckboxItem groupUsePosixGroupsItem = new CheckboxItem("groupUsePosixGroups",
            MSG.view_admin_systemSettings_LDAPGroupUsePosixGroup_name());
    {
        groupUsePosixGroupsItem.setCanEdit(false);
        groupUsePosixGroupsItem.setValue(false);
        groupUsePosixGroupsItem.setShowLabel(false);
        groupUsePosixGroupsItem.setShowTitle(true);
        groupUsePosixGroupsItem.setTitleOrientation(TitleOrientation.LEFT);
        //You have to set this attribute
        groupUsePosixGroupsItem.setAttribute("labelAsTitle", true);
    }
    ldapGroupSettings.setItems(groupSearch, groupMember, groupQueryPagingItem, groupQueryPagingCountItem,
            groupUsePosixGroupsItem);

    // orient both panels next to each other
    HLayout panel = new HLayout();
    {
        panel.addMember(availableGroupDetails);
        DynamicForm spacerWrapper = new DynamicForm();
        spacerWrapper.setItems(new SpacerItem());
        panel.addMember(spacerWrapper);
        panel.addMember(ldapGroupSettings);
    }
    availableFilterForm.addChild(panel);

    final long ldapGroupSelectorRequestId = System.currentTimeMillis();

    //launch operations to populate/refresh LDAP Group Query contents.
    final Timer ldapPropertiesTimer = new Timer() {
        public void run() {
            //if system properties not set, launch request/update
            String ldapGroupQuery = groupSearch.getValueAsString();
            if ((ldapGroupQuery == null) || (ldapGroupQuery.trim().isEmpty())) {
                GWTServiceLookup.getSystemService().getSystemSettings(new AsyncCallback<SystemSettings>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        groupQueryStatus.setIcons(failIcon);
                        groupQueryStatus.setDefaultValue(MSG.view_adminRoles_failLdapGroupsSettings());
                        CoreGUI.getErrorHandler().handleError(MSG.view_adminRoles_failLdapGroupsSettings(),
                                caught);
                        Log.debug(MSG.view_adminRoles_failLdapGroupsSettings());
                    }

                    @Override
                    public void onSuccess(SystemSettings settings) {
                        //retrieve relevant information once and update ui
                        String ldapGroupFilter = settings.get(SystemSetting.LDAP_GROUP_FILTER);
                        String ldapGroupMember = settings.get(SystemSetting.LDAP_GROUP_MEMBER);
                        String ldapGroupPagingEnabled = settings.get(SystemSetting.LDAP_GROUP_PAGING);
                        String ldapGroupPagingValue = settings.get(SystemSetting.LDAP_GROUP_QUERY_PAGE_SIZE);
                        String ldapGroupIsPosix = settings.get(SystemSetting.LDAP_GROUP_USE_POSIX);
                        groupSearch.setValue(ldapGroupFilter);
                        groupMember.setValue(ldapGroupMember);
                        groupQueryPagingItem.setValue(Boolean.valueOf(ldapGroupPagingEnabled));
                        groupQueryPagingCountItem.setValue(ldapGroupPagingValue);
                        groupUsePosixGroupsItem.setValue(Boolean.valueOf(ldapGroupIsPosix));
                        ldapGroupSettings.markForRedraw();
                    }
                });
            }
        }
    };
    ldapPropertiesTimer.schedule(2000); // repeat interval in milliseconds, e.g. 30000 = 30seconds

    //launch operations to populate/refresh LDAP Group Query contents.
    final Timer availableGroupsTimer = new Timer() {
        public void run() {
            final String attention = MSG.common_status_attention();
            final String success = MSG.common_status_success();
            final String none = MSG.common_val_none();
            final String failed = MSG.common_status_failed();
            //make request to RHQ about state of latest LDAP GWT request
            GWTServiceLookup.getLdapService()
                    .findAvailableGroupsStatus(new AsyncCallback<Set<Map<String, String>>>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            groupQueryStatus.setIcons(failIcon);
                            groupQueryStatus.setDefaultValue(failed);
                            String adviceValue = MSG.view_adminRoles_failLdapAvailableGroups();
                            adviceItem.setValue(adviceValue);
                            adviceItem.setTooltip(adviceValue);
                            CoreGUI.getErrorHandler().handleError(MSG.view_adminRoles_failLdapAvailableGroups(),
                                    caught);
                            retryAttempt++;
                            if (retryAttempt > 3) {
                                cancel();//kill thread
                                Log.debug(MSG.view_adminRoles_failLdapRetry());
                                retryAttempt = 0;
                            }
                        }

                        @Override
                        public void onSuccess(Set<Map<String, String>> results) {
                            long start = -1, current = -1;
                            int pageCount = 0;
                            int resultCountValue = 0;
                            boolean queryCompleted = false;
                            for (Map<String, String> map : results) {
                                String key = map.keySet().toArray()[0] + "";
                                if (key.equals("query.results.parsed")) {
                                    String value = map.get(key);
                                    resultCountItem.setValue(value);
                                    resultCountValue = Integer.valueOf(value);
                                } else if (key.equals("query.complete")) {
                                    String value = map.get(key);
                                    queryCompleted = Boolean.valueOf(value);
                                } else if (key.equals("query.start.time")) {
                                    String value = map.get(key);
                                    start = Long.valueOf(value);
                                } else if (key.equals("query.current.time")) {
                                    String value = map.get(key);
                                    current = Long.valueOf(value);
                                } else if (key.equals("query.page.count")) {
                                    String value = map.get(key);
                                    pageCountItem.setValue(value);
                                    pageCount = Integer.valueOf(value);
                                }
                            }

                            if (resultCountValue == 0) {
                                noProgressAttempts++;
                            }
                            //Update status information
                            String warnTooManyResults = MSG.view_adminRoles_ldapWarnTooManyResults();
                            String warnQueryTakingLongResults = MSG
                                    .view_adminRoles_ldapWarnQueryTakingLongResults();
                            String warnParsingManyPagesResults = MSG
                                    .view_adminRoles_ldapWarnParsingManyPagesResults();

                            boolean resultCountWarning = false;
                            boolean pageCountWarning = false;
                            boolean timePassingWarning = false;
                            if ((resultCountWarning = (resultCountValue > 5000))
                                    || (pageCountWarning = (pageCount > 5))
                                    || (timePassingWarning = (current - start) > 5 * 1000)) {
                                adviceItem.setDisabled(false);
                                groupQueryStatus.setIcons(attentionIcon);
                                if (resultCountWarning) {
                                    adviceItem.setValue(warnTooManyResults);
                                    adviceItem.setTooltip(warnTooManyResults);
                                } else if (pageCountWarning) {
                                    adviceItem.setValue(warnParsingManyPagesResults);
                                    adviceItem.setTooltip(warnParsingManyPagesResults);
                                } else if (timePassingWarning) {
                                    adviceItem.setValue(warnQueryTakingLongResults);
                                    adviceItem.setTooltip(warnQueryTakingLongResults);
                                }
                            }

                            //act on status details to add extra perf suggestions. Kill threads older than 30 mins
                            long parseTime = System.currentTimeMillis() - ldapGroupSelectorRequestId;
                            if ((queryCompleted) || (parseTime) > 30 * 60 * 1000) {
                                String tooManyResults = MSG.view_adminRoles_ldapTooManyResults();
                                String queryTookLongResults = MSG
                                        .view_adminRoles_ldapTookLongResults(parseTime + "");
                                String queryTookManyPagesResults = MSG
                                        .view_adminRoles_ldapTookManyPagesResults(pageCount + "");

                                adviceItem.setDisabled(false);
                                groupQueryStatus.setIcons(attentionIcon);
                                groupQueryStatus.setDefaultValue(attention);
                                if (resultCountValue > 20000) {//results throttled
                                    adviceItem.setValue(tooManyResults);
                                    adviceItem.setTooltip(tooManyResults);
                                    Log.debug(tooManyResults);//log error to client.
                                } else if ((current - start) >= 10 * 1000) {// took longer than 10s
                                    adviceItem.setValue(queryTookLongResults);
                                    adviceItem.setTooltip(queryTookLongResults);
                                    Log.debug(queryTookLongResults);//log error to client.
                                } else if (pageCount >= 20) {// required more than 20 pages of results
                                    adviceItem.setValue(queryTookManyPagesResults);
                                    adviceItem.setTooltip(queryTookManyPagesResults);
                                    Log.debug(queryTookManyPagesResults);//log error to client.
                                } else {//simple success.
                                    groupQueryStatus.setDefaultValue(success);
                                    groupQueryStatus.setIcons(successIcon);
                                    adviceItem.setValue(none);
                                    adviceItem.setTooltip(none);
                                    adviceItem.setDisabled(true);
                                }
                                noProgressAttempts = 0;
                                //now cancel the timer
                                cancel();
                            } else if (noProgressAttempts >= 10) {//availGroups query stuck on server side
                                //cancel the timer.
                                cancel();
                                String clientSideQuitting = MSG.view_adminRoles_failLdapCancelling();//catch all
                                adviceItem.setDisabled(false);
                                groupQueryStatus.setIcons(attentionIcon);
                                adviceItem.setValue(clientSideQuitting);
                                adviceItem.setTooltip(clientSideQuitting);
                                noProgressAttempts = 0;
                                Log.debug(clientSideQuitting);//log error to client.
                            }
                            availableGroupDetails.markForRedraw();
                        }
                    });
        }
    };
    availableGroupsTimer.scheduleRepeating(3000); // repeat interval in milliseconds, e.g. 30000 = 30seconds

    return availableFilterForm;
}

From source file:org.rhq.coregui.client.dashboard.AutoRefreshUtil.java

License:Open Source License

private static Timer startRefreshCycle(final AutoRefresh autoRefresh, final Canvas autoRefreshCanvas,
        Timer refreshTimer, int intervalMillis, int minIntervalMillis) {
    //cancel any existing timer
    if (null != refreshTimer) {
        refreshTimer.cancel();//from www.ja va2 s .c om
        refreshTimer = null;
    }

    if (minIntervalMillis <= 0 || intervalMillis >= minIntervalMillis) {

        refreshTimer = new Timer() {
            public void run() {

                // if the autoRefresh component is already refreshing or is not currently on screen then
                // don't bother doing the work. this protects against unnecessary or unwanted db queries
                // being performed in the background. Also, avoid refresh if the session has expired and we're
                // waiting for the user to login and refresh his session.
                if (!autoRefresh.isRefreshing() && autoRefreshCanvas.isDrawn() && autoRefreshCanvas.isVisible()
                        && !autoRefreshCanvas.isDisabled() && !LoginView.isLoginShowing()) {

                    autoRefresh.refresh();
                }
            }
        };

        refreshTimer.scheduleRepeating(intervalMillis);
    }

    return refreshTimer;
}

From source file:org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil.java

License:Open Source License

public static Timer startRefreshCycle(final AutoRefreshPortlet autoRefreshPortlet,
        final Canvas autoRefreshPortletCanvas, Timer refreshTimer) {

    final int refreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval();

    //cancel any existing timer
    if (null != refreshTimer) {
        refreshTimer.cancel();//from  w  ww.  ja v a  2s .  co m
    }

    if (refreshInterval >= MeasurementUtility.MINUTES) {

        refreshTimer = new Timer() {
            public void run() {

                // if the portlet is already refreshing or if the portlet is not currently on screen then
                // don't bother doing the work. this protects against unnecessary or unwanted db queries
                // being performed in the background.
                if (!autoRefreshPortlet.isRefreshing() && autoRefreshPortletCanvas.isVisible()) {
                    autoRefreshPortlet.refresh();
                }
            }
        };

        refreshTimer.scheduleRepeating(refreshInterval);
    }

    return refreshTimer;
}