List of usage examples for com.google.gwt.user.client Timer schedule
public synchronized void schedule(int delayMs)
From source file:org.jboss.bpm.console.client.report.RenderReportAction.java
License:Open Source License
public void execute(final Controller controller, Object object) { final RenderDispatchEvent event = (RenderDispatchEvent) object; final String url = event.getDispatchUrl(); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); ConsoleLog.debug(RequestBuilder.POST + ": " + url); final ReportLaunchPadView view = (ReportLaunchPadView) controller.getView(ReportLaunchPadView.ID); view.reset();/*ww w .jav a 2 s . c o m*/ view.setLoading(true); try { controller.handleEvent(LoadingStatusAction.ON); //view.setLoading(true); String parameters = event.getParameters(); final Request request = builder.sendRequest(parameters, new RequestCallback() { public void onError(Request request, Throwable exception) { // Couldn't connect to server (could be timeout, SOP violation, etc.) handleError(controller, url, exception); controller.handleEvent(LoadingStatusAction.OFF); } public void onResponseReceived(Request request, Response response) { try { if (response.getText().indexOf("HTTP 401") != -1) // HACK { appContext.getAuthentication().handleSessionTimeout(); } else if (200 == response.getStatusCode()) { // update view view.displayReport(event.getTitle(), event.getDispatchUrl()); } else { final String msg = response.getText().equals("") ? "Unknown error" : response.getText(); handleError(controller, url, new RequestException("HTTP " + response.getStatusCode() + ": " + msg)); } } finally { controller.handleEvent(LoadingStatusAction.OFF); view.setLoading(false); } } }); // Timer to handle pending request Timer t = new Timer() { public void run() { if (request.isPending()) { request.cancel(); handleError(controller, url, new IOException("Request timeout")); } } }; t.schedule(20000); } catch (Throwable e) { // Couldn't connect to server controller.handleEvent(LoadingStatusAction.OFF); handleError(controller, url, e); view.setLoading(false); } }
From source file:org.jboss.bpm.console.client.report.ReportView.java
License:Open Source License
public Widget asWidget() { panel = new SimplePanel(); initialize();//from ww w. j av a 2 s. c om controller.addView(ReportView.ID, this); controller.addAction(UpdateReportConfigAction.ID, new UpdateReportConfigAction(clientFactory.getApplicationContext())); // ---- Timer t = new Timer() { @Override public void run() { controller.handleEvent(new Event(UpdateReportConfigAction.ID, null)); } }; t.schedule(500); return panel; }
From source file:org.jboss.bpm.console.client.task.AssignedTasksView.java
License:Open Source License
public void initialize() { if (!isInitialized) { // workaround OpenTasksView.registerCommonActions(appContext, controller); taskList = new VerticalPanel(); listBox = new CustomizableListBox<TaskRef>(new CustomizableListBox.ItemFormatter<TaskRef>() { public String format(TaskRef taskRef) { String result = ""; result += String.valueOf(taskRef.getPriority()); result += " "; result += taskRef.getProcessId(); result += " "; result += taskRef.getName(); result += " "; result += taskRef.getDueDate() != null ? dateFormat.format(taskRef.getDueDate()) : ""; return result; }//from www . j a va 2 s . c o m }); listBox.setFirstLine("Priority, Process, Task Name, Due Date"); listBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { TaskRef task = getSelection(); // first call always null? if (task != null) { controller.handleEvent( new Event(UpdateDetailsAction.ID, new DetailViewEvent("AssignedDetailView", task))); } } }); // toolbar final VerticalPanel toolBox = new VerticalPanel(); toolBox.setSpacing(5); final MenuBar toolBar = new MenuBar(); toolBar.addItem("Refresh", new Command() { public void execute() { reload(); } }); MenuItem viewBtn = new MenuItem("View", new Command() { public void execute() { TaskRef selection = getSelection(); if (selection != null) { if (selection.getUrl() != null && !selection.getUrl().equals("")) { iframeWindow = new IFrameWindowPanel(selection.getUrl(), "Task Form: " + selection.getName()); iframeWindow.setCallback(new IFrameWindowCallback() { public void onWindowClosed() { reload(); } }); iframeWindow.show(); } else { Window.alert("Invalid operation. The task doesn't provide a UI"); } } else { Window.alert("Missing selection. Please select a task"); } } }); toolBar.addItem(viewBtn); toolBar.addItem("Release", new Command() { public void execute() { TaskRef selection = getSelection(); if (selection != null) { TaskIdentityEvent payload = new TaskIdentityEvent(null, selection); controller.handleEvent(new Event(ReleaseTaskAction.ID, payload)); } else { Window.alert("Missing selection. Please select a task"); } } }); toolBox.add(toolBar); this.taskList.add(toolBox); this.taskList.add(listBox); pagingPanel = new PagingPanel(new PagingCallback() { public void rev() { renderUpdate(); } public void ffw() { renderUpdate(); } }); this.taskList.add(pagingPanel); detailsView = new TaskDetailView(false); controller.addView("AssignedDetailView", detailsView); detailsView.initialize(); // plugin availability this.hasDispatcherPlugin = ServerPlugins .has("org.jboss.bpm.console.server.plugin.FormDispatcherPlugin"); viewBtn.setEnabled(hasDispatcherPlugin); // deployments model listener ErraiBus.get().subscribe(Model.SUBJECT, new MessageCallback() { public void callback(Message message) { switch (ModelCommands.valueOf(message.getCommandType())) { case HAS_BEEN_UPDATED: if (message.get(String.class, ModelParts.CLASS).equals(Model.PROCESS_MODEL)) { reload(); } break; } } }); Timer t = new Timer() { @Override public void run() { // force loading reload(); } }; t.schedule(500); isInitialized = true; } }
From source file:org.jboss.bpm.console.client.task.OpenTasksView.java
License:Open Source License
public void initialize() { if (!isInitialized) { taskList = new VerticalPanel(); listBox = new CustomizableListBox<TaskRef>(new CustomizableListBox.ItemFormatter<TaskRef>() { public String format(TaskRef taskRef) { String result = ""; result += String.valueOf(taskRef.getPriority()); result += " "; result += taskRef.getProcessId(); result += " "; result += taskRef.getName(); result += " "; result += String.valueOf(taskRef.getCurrentState()); result += " "; result += taskRef.getDueDate() != null ? dateFormat.format(taskRef.getDueDate()) : ""; return result; }/*from w w w .j a v a 2 s. co m*/ }); listBox.setFirstLine("Priority, Process, Task Name, Status, Due Date"); listBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { TaskRef task = getSelection(); // first call always null? if (task != null) { controller.handleEvent( new Event(UpdateDetailsAction.ID, new DetailViewEvent("OpenDetailView", task))); } } }); // toolbar final VerticalPanel toolBox = new VerticalPanel(); toolBox.setSpacing(5); final MenuBar toolBar = new MenuBar(); toolBar.addItem("Refresh", new Command() { public void execute() { reload(); } }); toolBar.addItem("Claim", new Command() { public void execute() { TaskRef selection = getSelection(); if (selection != null) { controller.handleEvent(new Event(ClaimTaskAction.ID, new TaskIdentityEvent(appContext.getAuthentication().getUsername(), selection))); } else { Window.alert("Missing selection. Please select a task"); } } }); toolBox.add(toolBar); this.taskList.add(toolBox); this.taskList.add(listBox); pagingPanel = new PagingPanel(new PagingCallback() { public void rev() { renderUpdate(); } public void ffw() { renderUpdate(); } }); this.taskList.add(pagingPanel); // ---- // create and register views detailsView = new TaskDetailView(true); controller.addView("OpenDetailView", detailsView); detailsView.initialize(); // deployments model listener ErraiBus.get().subscribe(Model.SUBJECT, new MessageCallback() { public void callback(Message message) { switch (ModelCommands.valueOf(message.getCommandType())) { case HAS_BEEN_UPDATED: if (message.get(String.class, ModelParts.CLASS).equals(Model.PROCESS_MODEL)) { reload(); } break; } } }); Timer t = new Timer() { @Override public void run() { // force loading reload(); } }; t.schedule(500); isInitialized = true; } }
From source file:org.jboss.errai.bus.client.api.base.ClientTaskManager.java
License:Apache License
public AsyncTask schedule(TimeUnit unit, int interval, final Runnable task) { final Timer timer = new Timer() { @Override//w ww. j a va2 s .c om public void run() { task.run(); } }; AsyncTask asyncTask = createAsyncTask(task, timer); timer.schedule((int) unit.convert(interval, TimeUnit.MILLISECONDS)); return asyncTask; }
From source file:org.jboss.errai.tools.source.client.ViewSource.java
License:Apache License
public static void on(final LayoutPanel widget, final String[] sourceNames) { Timer t = new Timer() { @Override//from w w w . j a v a 2 s .c o m public void run() { final int left = widget.getAbsoluteLeft(); final int top = widget.getAbsoluteTop(); final int width = widget.getOffsetWidth(); final int height = widget.getOffsetHeight(); final LayoutPopupPanel p = new LayoutPopupPanel(false); HTML html = new HTML("View Source"); html.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) { LayoutPopupPanel p2 = new LayoutPopupPanel(true); p2.setModal(true); //p2.setAnimationEnabled(true); SourceViewWidget viewWidget = new SourceViewWidget(sourceNames); p2.setWidget(viewWidget); //p2.setPopupPosition(10, 10); int w2 = RootPanel.get().getOffsetWidth() - 100; int h2 = RootPanel.get().getOffsetHeight() - 100; p2.setSize(w2 + "px", h2 + "px"); p2.center(); } }); p.setWidget(html); p.setPopupPosition(left + width - 120, top + 10); p.pack(); p.show(); } }; t.schedule(1000); }
From source file:org.jboss.errai.widgets.client.WSGrid.java
License:Apache License
public WSGrid(boolean scrollable, boolean editable) { innerPanel = new VerticalPanel(); innerPanel.setSpacing(0);/*from w ww .j a v a 2 s . c o m*/ focusPanel = new FocusPanel(innerPanel); initWidget(focusPanel); titleBar = new WSAbstractGrid(false, GridType.TITLEBAR); innerPanel.add(titleBar); innerPanel.setCellVerticalAlignment(titleBar, HasVerticalAlignment.ALIGN_BOTTOM); titleBar.setStylePrimaryName("WSGrid-header"); if (editable) dataGrid = new WSAbstractGrid(scrollable, GridType.EDITABLE_GRID); else dataGrid = new WSAbstractGrid(scrollable, GridType.NONEDITABLE_GRID); innerPanel.add(dataGrid); innerPanel.setCellVerticalAlignment(dataGrid, HasVerticalAlignment.ALIGN_TOP); dataGrid.setStylePrimaryName("WSGrid-datagrid"); resizeLine.setWidth("5px"); resizeLine.setHeight("800px"); resizeLine.setStyleName("WSGrid-resize-line"); resizeLine.sinkEvents(Event.MOUSEEVENTS); dataGrid.getScrollPanel().addScrollHandler(new ScrollHandler() { public void onScroll(ScrollEvent event) { titleBar.getScrollPanel() .setHorizontalScrollPosition(dataGrid.getScrollPanel().getHorizontalScrollPosition()); } }); /** * This is the handler that is responsible for resizing columns. */ focusPanel.addMouseDownHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { if (!selectionList.isEmpty() && selectionList.lastElement().isEdit()) { return; } if (_resizeArmed) { if (!_resizing) { _resizing = true; disableTextSelection(getBodyElement(), true); _startpos = event.getClientX(); resizeLine.show(); resizeLine.setPopupPosition(event.getClientX(), 0); } } } }); /** * This handler traces the mouse movement, drawing the vertical resizing * indicator. */ focusPanel.addMouseMoveHandler(new MouseMoveHandler() { public void onMouseMove(MouseMoveEvent event) { if (_resizing) { setStyleAttribute(resizeLine.getElement(), "left", (event.getClientX()) + "px"); } } }); /** * This is the mouse release handler that resizes a column once the left * mouse button is released in a resizing operation. */ focusPanel.addMouseUpHandler(new MouseUpHandler() { public void onMouseUp(MouseUpEvent event) { if (_resizing) { cancelResize(); WSCell currentFocus = selectionList.isEmpty() ? null : selectionList.lastElement(); if (currentFocus == null) return; int selCol = (_leftGrow ? currentFocus.col - 1 : currentFocus.col); if (selCol == -1) return; int width = colSizes.get(selCol); int offset = event.getClientX(); /** * If we didn't move at all, don't calculate a new size. */ if (offset - _startpos == 0) return; width -= (_startpos -= event.getClientX()); setColumnWidth(selCol, width); } _rangeSelect = false; } }); /** * This handler is responsible for all the keyboard input handlers for * the grid. */ focusPanel.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { final WSCell currentFocus; int offsetX; int offsetY; /** * Is there currently anything selected? */ if (selectionList.isEmpty()) { /** * No. */ return; } else { /** * Set currentFocus to the last element in the * selectionList. */ currentFocus = selectionList.lastElement(); /** * Yes. Let's check to see if this cell spans. If so, we * will set the offsetX value to the colspan value so * navigation behaves. */ offsetX = currentFocus.isColSpan() ? currentFocus.getColspan() : 1; offsetY = currentFocus.isRowSpan() ? currentFocus.getRowspan() : 1; } /** * If we're currently editing a cell, then we ignore these * operations. */ if (currentFocus.edit) { return; } event.preventDefault(); switch (event.getNativeKeyCode()) { /** * If tab is pressed, we want to advance to the next cell. If we * are at the end of the line, go to the first cell of the next * line. If shift is depressed, then perform the inverse. */ case KeyCodes.KEY_TAB: blurAll(); if (event.getNativeEvent().getShiftKey()) { if (currentFocus.getCol() == 0 && currentFocus.getRow() > 0) { dataGrid.tableIndex.get(currentFocus.getRow() - offsetX).get(cols - offsetX).focus(); } else { dataGrid.tableIndex.get(currentFocus.getRow()) .get(currentFocus.getCol() - (currentFocus.isColSpan() ? currentFocus.getLeftwareColspan() : 1)) .focus(); } } else { if (currentFocus.getCol() == cols - offsetX && currentFocus.getRow() < dataGrid.tableIndex.size()) { dataGrid.tableIndex.get(currentFocus.getRow() + offsetX).get(0).focus(); } else { dataGrid.tableIndex.get(currentFocus.getRow()).get(currentFocus.getCol() + offsetX) .focus(); } } break; /** * If the up key is pressed, we should advance to the cell * directly above the currently selected cell. If we are at the * top of the grid, then nothing should happen. */ case 63232: case KeyCodes.KEY_UP: if (currentFocus.getRow() > 0) { if (!event.getNativeEvent().getShiftKey()) { blurAll(); } if (fm.isInitialised()) { fm.moveUpwards(); } else { dataGrid.tableIndex .get(currentFocus.getRow() - (currentFocus.isRowSpan() ? currentFocus.getUpwardRowspan() : 1)) .get(currentFocus.getCol()).focus(); } } break; /** * If the right key is pressed, we should advance to the cell * directly to the right of the currently selected cell. If we * are at the rightmost part of the grid, then nothing should * happen. */ case 63235: case KeyCodes.KEY_RIGHT: if (currentFocus.getCol() < cols - offsetX) { /** * Blur all columns if shift is not being depressed. */ if (!event.getNativeEvent().getShiftKey()) { blurAll(); } if (currentFocusColumn) { titleBar.tableIndex.get(currentFocus.getRow()).get(currentFocus.getCol() + offsetX) .focus(); } else { if (fm.isInitialised()) { fm.moveRight(); } else { dataGrid.tableIndex.get(currentFocus.getRow()).get(currentFocus.getCol() + offsetX) .focus(); } } } break; /** * If either "Enter" or the down key is pressed we should * advance to the cell directly below the current cell. If we * are at the bottom of the grid, depending on the mode of the * grid, either nothing should happen, or a new line should be * added. */ case 63233: case KeyCodes.KEY_ENTER: case KeyCodes.KEY_DOWN: if (currentFocus.getRow() < dataGrid.tableIndex.size() - offsetX) { if (!event.getNativeEvent().getShiftKey()) { blurAll(); } if (fm.isInitialised()) { fm.moveDownwards(); } else { dataGrid.tableIndex.get(currentFocus.getRow() + offsetY).get(currentFocus.getCol()) .focus(); } } break; /** * If the left key is pressed we should advance to the cell * directly to the left of the currently selected cell. If we * are at the leftmost part of the grid, nothing should happen. */ case 63234: case KeyCodes.KEY_LEFT: if (currentFocus.getCol() > 0) { if (!event.getNativeEvent().getShiftKey()) { blurAll(); } if (currentFocusColumn) { titleBar.tableIndex.get(currentFocus.getRow()).get(currentFocus.getCol() - offsetX) .focus(); } else { if (fm.isInitialised()) { fm.moveLeft(); } else { int delta = currentFocus.getCol() - (currentFocus.isColSpan() ? currentFocus.getLeftwareColspan() : 1); if (delta < 0) { currentFocus.focus(); } else { dataGrid.tableIndex.get(currentFocus.getRow()).get(delta).focus(); } } } } break; case KeyCodes.KEY_CTRL: case 16: case 91: break; case KeyCodes.KEY_BACKSPACE: case 63272: case KeyCodes.KEY_DELETE: if (currentFocus.grid.type != GridType.TITLEBAR) { for (WSCell c : selectionList) { c.setValue(""); } } else { /** * Wipe the whole column. */ for (int i = 0; i < dataGrid.tableIndex.size(); i++) { dataGrid.tableIndex.get(i).get(currentFocus.getCol()).setValue(""); } } break; case 32: // spacebar Timer t = new Timer() { public void run() { currentFocus.edit(); } }; t.schedule(15); break; default: currentFocus.setValue(""); currentFocus.edit(); } } }); focusPanel.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent mouseOutEvent) { _rangeSelect = false; } }); }
From source file:org.jboss.errai.workspaces.client.layout.WorkspaceLayout.java
License:Apache License
private void _openTab(final String DOMID, final String initSubject, final String componentId, final String name, final String instanceId, final Image icon) { final MessageBus bus = ErraiBus.get(); bus.conversationWith(createMessage().getMessage().set(LayoutParts.DOMID, DOMID).toSubject(initSubject), new MessageCallback() { public void callback(Message message) { final ExtSimplePanel panel = new ExtSimplePanel(); panel.getElement().getStyle().setProperty("overflow", "hidden"); Effects.setOpacity(panel.getElement(), 0); WSElementWrapper toolWidget = new WSElementWrapper(getElementById(DOMID)); toolWidget.setVisible(true); panel.setWidget(toolWidget); Image app = new Image(erraiImageBundle.application()); final Image newIcon = new Image( icon != null || "".equals(icon) ? icon.getUrl() : app.getUrl()); newIcon.setSize("16px", "16px"); final WSTab newWSTab = new WSTab(name, panel, newIcon); tabPanel.add(panel, newWSTab); newWSTab.activate(); newWSTab.clearTabCloseHandlers(); newWSTab.addTabCloseHandler(new TabCloseHandler(instanceId)); tabDragController.makeDraggable(newWSTab, newWSTab.getLabel()); tabDragController.makeDraggable(newWSTab, newWSTab.getIcon()); newWSTab.getLabel().addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { newWSTab.getLabel().getElement().getStyle().setProperty("cursor", "default"); }// w w w . ja va 2 s. c o m }); newWSTab.getLabel().addMouseDownHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { newWSTab.activate(); } }); tabDragController.setBehaviorDragProxy(true); tabDragController.registerDropController(newWSTab.getTabDropController()); newWSTab.reset(); activateTool(componentId); Map<String, Object> tabProperties = new HashMap<String, Object>(); tabProperties.put(LayoutParts.Name.name(), name); tabProperties.put(LayoutParts.IconURI.name(), newIcon.getUrl()); tabProperties.put(LayoutParts.ComponentID.name(), componentId); tabProperties.put(LayoutParts.Subject.name(), getInstanceSubject(instanceId)); tabInstances.put(instanceId, JSONUtilCli.encodeMap(tabProperties)); bus.subscribe(getInstanceSubject(instanceId), new MessageCallback() { private Map<String, List<Object>> toUnregister = ((ClientMessageBus) bus) .getCapturedRegistrations(); public void callback(Message message) { switch (LayoutCommands.valueOf(message.getCommandType())) { case CloseTab: tabDragController.unregisterDropController(newWSTab.getTabDropController()); ((ClientMessageBus) bus).unregisterAll(toUnregister); deactivateTool(componentId); int idx = newWSTab.remove(); if (idx > 0) idx--; else if (tabPanel.getWidgetCount() == 0) return; tabPanel.selectTab(idx); break; case ActivateTool: newWSTab.activate(); break; } } }); ((ClientMessageBus) bus).endCapture(); Timer t = new Timer() { public void run() { pack(); } }; t.schedule(25); Effects.fade(panel.getElement(), 1, 0, 100); } }); }
From source file:org.jboss.errai.workspaces.client.modules.auth.AuthenticationDisplay.java
License:Apache License
public void showWelcomeMessage(final String messageText) { Timer t = new Timer() { public void run() { MessageBox.info("Welcome", messageText); }// www. j av a2s. com }; t.schedule(500); }
From source file:org.jboss.errai.workspaces.client.Viewport.java
License:Apache License
public void onResize(ResizeEvent event) { super.onResize(event); DeferredCommand.addCommand(new Command() { public void execute() { /**/* www . j a v a 2 s . co m*/ * Mosaic seems to be doing something weird in it's layout calculations right now that I can't trace down, * so my only solution is to create a timer-based delay... * * This is really sloppy... and contributes to what is already a very slow resizing experience with the * Mosaic layouts... */ Timer layoutHintDelay = new Timer() { public void run() { LayoutUtil.layoutHints(getLayoutPanel()); } }; layoutHintDelay.schedule(500); } }); }