List of usage examples for com.google.gwt.user.client Timer scheduleRepeating
public synchronized void scheduleRepeating(final int periodMs)
From source file:de.hpfsc.web.anticafe.WidgetRenderingExample.java
License:Open Source License
@Override protected void onRender(Element parent, int index) { super.onRender(parent, index); setHeight(300);/*from w w w . j ava 2 s .c o m*/ final Timer updateClientsTimer = new Timer() { @Override public void run() { clientsServiceAsync.getClients(whoseSession, isAdminSeesAll.getValue(), showAcceptedCheckBox.getValue(), new AsyncCallback<ArrayList<Client>>() { @Override public void onFailure(Throwable throwable) { System.out.println("fail get clients from timer"); } @Override public void onSuccess(ArrayList<Client> clients) { if (clients.isEmpty()) { store.removeAll(); } for (Client client : store.getModels()) { if (!clients.contains(client)) { store.remove(client); } } for (Client client : clients) { Client alreadyPresentModel = store.findModel(client); if (alreadyPresentModel == null && !client.isDeleted()) { store.add(client); } else { updateClientInStore(client, alreadyPresentModel); } long totalSumValue = 0l; for (Client storeClient : store.getModels()) { totalSumValue += storeClient.getTotalSum(); } totalSumLabel.setValue(getPrettyMoney(totalSumValue)); // if (alreadyPresentModel == null) { // if (showAcceptedCheckBox.getValue()) { // store.add(client); // } else { // if (!client.isAccepted()) { // store.add(client); // } // } // } else { // if (isToShowAccepted) { // updateClientInStore(client, alreadyPresentModel); // } else { // if (client.isAccepted()) { // store.remove(client); // } else { // updateClientInStore(client, alreadyPresentModel); // } // } // } } } }); } }; // setLayout(new FlowLayout(10)); GridCellRenderer<Client> ownerCellRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { return new LabelField(model.getWhoseSession().name()); } }; GridCellRenderer<Client> nameCellRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { LabelField labelField = new LabelField(model.getName()); labelField.setWidth(50); return labelField; } }; GridCellRenderer<Client> commentCellRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { LabelField labelField = new LabelField(model.getComment()); labelField.setTitle(model.getComment()); return labelField; } }; GridCellRenderer<Client> buttonRenderer = new GridCellRenderer<Client>() { private boolean init; public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { if (!init) { init = true; grid.addListener(Events.ColumnResize, new Listener<GridEvent<Client>>() { public void handleEvent(GridEvent<Client> be) { for (int i = 0; i < be.getGrid().getStore().getCount(); i++) { if (be.getGrid().getView().getWidget(i, be.getColIndex()) != null && be.getGrid() .getView().getWidget(i, be.getColIndex()) instanceof BoxComponent) { ((BoxComponent) be.getGrid().getView().getWidget(i, be.getColIndex())) .setWidth(be.getWidth() - 10); } } } }); } Button b = new Button((String) model.getName(), new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { Info.display(model.getName(), "<ul><li>" + model.getId() + "</li></ul>"); } }); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click for more information"); return b; } }; GridCellRenderer<Client> playButtonRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, final ListStore<Client> store, final Grid<Client> grid) { final Button b = new Button(""); b.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { // final Client selectedItem = grid.getSelectionModel().getSelectedItem(); b.setEnabled(false); final Client selectedItem = store.getAt(rowIndex); clientsServiceAsync.startSession(selectedItem.getId(), System.currentTimeMillis(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { System.out.println("faile start"); } @Override public void onSuccess(Void aVoid) { Info.display("Started alert", selectedItem.getName() + " is started"); } }); Info.display("", selectedItem.getName()); } }); b.setEnabled(model.getStartTime() == 0); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click for more information"); return b; } }; GridCellRenderer<Client> stopButtonRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { final Client selectedItem = store.getAt(rowIndex); Button b = new Button("Stop", new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { clientsServiceAsync.stopSession(model.getId(), model.getTotalSum(), false, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { System.out.println("fail stop"); } @Override public void onSuccess(Void aVoid) { Info.display("Stop alert", selectedItem.getName() + " is stopped"); } }); } }); b.setEnabled(model.isInProgress()); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click for more information"); return b; } }; GridCellRenderer<Client> timeRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { LabelField timeLabel = new LabelField(); Long stopTime = model.getStopTime(); Long endTime = null; if (!model.isInProgress() && stopTime != 0 && model.getStartTime() != 0 && !model.isExpired()) { endTime = stopTime; timeLabel.setValue(getMinutesString(endTime - model.getStartTime())); } else if (model.isExpired()) { // do nothing here } else if (model.isInProgress()) { endTime = System.currentTimeMillis(); timeLabel.setValue(getMinutesString(endTime - model.getStartTime())); } else { timeLabel.setValue("00:00:00"); } return timeLabel; } }; GridCellRenderer<Client> sumRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<Client> store, Grid<Client> grid) { LabelField sumLabel = new LabelField("00.00"); if (model.getStartTime() != 0) { renderSumLabel(model, sumLabel); } return sumLabel; } }; GridCellRenderer<Client> acceptColumnRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, final ListStore<Client> store, final Grid<Client> grid) { Button b = new Button(" ", new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { model.setAccepted(true); clientsServiceAsync.acceptSession(model, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { System.out.println("fail update from accept"); } @Override public void onSuccess(Void aVoid) { Info.display("", "Model is accepted"); } }); } }); setClientAcceptedButton(b, model.isAccepted(), model.isInProgress()); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click to add to archive"); return b; } private void setClientAcceptedButton(Button b, boolean accepted, boolean inProgress) { if (accepted && !inProgress) { b.setHtml(" "); b.getElement().getStyle().setBackgroundColor("green"); b.setEnabled(false); } } }; GridCellRenderer<Client> editButtonRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, final ListStore<Client> store, Grid<Client> grid) { final Client selectedItem = store.getAt(rowIndex); Button b = new Button("", new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { DialogExample dialogExample = new DialogExample(whoseSession, model, store); dialogExample.show(); } }); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click for more information"); return b; } }; GridCellRenderer<Client> removeButtonRenderer = new GridCellRenderer<Client>() { public Object render(final Client model, String property, ColumnData config, final int rowIndex, final int colIndex, final ListStore<Client> store, final Grid<Client> grid) { final Button b = new Button("", new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { // final Client selectedItem = grid.getSelectionModel().getSelectedItem(); final Client selectedItem = store.getAt(rowIndex); clientsServiceAsync.markSessionAsDeleted(selectedItem.getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { System.out.println("fail deletion start"); } @Override public void onSuccess(Void aVoid) { Info.display("Session ", selectedItem.getName() + " is deleted"); } }); // Info.display("", selectedItem.getName()); } }); if (model.isDeleted()) { b.setEnabled(false); } toggleInprogressButtonStyle(model, b); b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10); b.setToolTip("Click for more information"); return b; } }; final NumberFormat currency = NumberFormat.getCurrencyFormat(); final NumberFormat number = NumberFormat.getFormat("0.00"); // final NumberCellRenderer<Grid<Session>> numberRenderer = new NumberCellRenderer<Grid<Session>>(currency); // GridCellRenderer<Client> change = new GridCellRenderer<Client>() { // public String render(Client model, String property, ColumnData config, int rowIndex, int colIndex, // ListStore<Client> store, Grid<Client> grid) { // double val = (Double) model.get(property); // String style = val < 0 ? "red" : "green"; // return "<span style='color:" + style + "'>" + number.format(val) + "</span>"; // } // }; // GridCellRenderer<Session> gridNumber = new GridCellRenderer<Session>() { // public String render(Session model, String property, ColumnData config, int rowIndex, int colIndex, // ListStore<Session> stor, Grid<Session> grid) { // return numberRenderer.render(null, property, model.get(property)); // } // }; List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); ColumnConfig column = new ColumnConfig(); column.setId("owner"); column.setHeaderHtml(" "); ownerEditor = new SimpleComboBox<>(); ownerEditor.setTriggerAction(ComboBox.TriggerAction.ALL); column.setEditor(new CellEditor(ownerEditor)); column.setRenderer(ownerCellRenderer); column.setWidth(90); configs.add(column); column = new ColumnConfig(); column.setId("name"); column.setHeaderHtml("?"); column.setRenderer(nameCellRenderer); nameEditor = new SimpleComboBox<>(); nameEditor.setTriggerAction(ComboBox.TriggerAction.ALL); column.setEditor(new CellEditor(nameEditor)); column.setWidth(50); configs.add(column); column = new ColumnConfig(); column.setId("comment"); column.setHeaderHtml(""); column.setRenderer(commentCellRenderer); commentEditor = new TextField<>(); column.setEditor(new CellEditor(commentEditor)); column.setWidth(140); configs.add(column); // column = new ColumnConfig(); // column.setId("name"); // column.setHeaderHtml("?"); // column.setWidth(100); // column.setRenderer(buttonRenderer); // configs.add(column); column = new ColumnConfig(); column.setId("play"); column.setResizable(false); column.setHeaderHtml("?"); column.setWidth(50); column.setRenderer(playButtonRenderer); configs.add(column); column = new ColumnConfig(); column.setId("stop"); column.setResizable(false); column.setHeaderHtml(""); column.setWidth(50); column.setRenderer(stopButtonRenderer); configs.add(column); column = new ColumnConfig(); column.setId("time"); column.setResizable(false); column.setHeaderHtml("?"); column.setWidth(60); column.setRenderer(timeRenderer); configs.add(column); column = new ColumnConfig(); column.setId("sum"); column.setResizable(false); column.setHeaderHtml(""); column.setWidth(60); column.setRenderer(sumRenderer); configs.add(column); // column = new ColumnConfig(); // column.setId("accept"); // column.setResizable(false); // column.setHeaderHtml(" "); // column.setWidth(50); // column.setRenderer(acceptButtonRenderer); // configs.add(column); column = new ColumnConfig(); column.setId("edit"); column.setResizable(false); column.setHeaderHtml(""); column.setWidth(100); column.setRenderer(editButtonRenderer); configs.add(column); column = new ColumnConfig(); column.setId("accept"); column.setResizable(false); column.setHeaderHtml("?"); column.setWidth(80); column.setRenderer(acceptColumnRenderer); configs.add(column); // column = new ColumnConfig(); // column.setId("Remove"); // column.setResizable(false); // column.setHeaderHtml(""); // column.setWidth(70); // column.setRenderer(removeButtonRenderer); // configs.add(column); isAdminSeesAll = new CheckBox(); isAdminSeesAll.setValue(WhoseSessionEnum.ADMIN == whoseSession); clientsServiceAsync.getClients(whoseSession, isAdminSeesAll.getValue(), isToShowAccepted, new AsyncCallback<ArrayList<Client>>() { @Override public void onFailure(Throwable throwable) { System.out.println("faile getting clients"); } @Override public void onSuccess(ArrayList<Client> clients) { store.add(clients); updateClientsTimer.scheduleRepeating(3000); } }); // store.add(TestData.getSessions()); ColumnModel cm = new ColumnModel(configs); ContentPanel cp = new ContentPanel(); cp.setBodyBorder(false); // cp.setIcon(Resources.ICONS.table()); // cp.setHeadingHtml("Widget Renderer Grid"); cp.setHeaderVisible(false); cp.setButtonAlign(HorizontalAlignment.CENTER); cp.getElement().getStyle().setTextAlign(Style.TextAlign.CENTER); cp.setLayout(new FitLayout()); cp.setSize(1100, 300); LayoutContainer totalSumContainer = new LayoutContainer(); totalSumContainer.getElement().getStyle().setTextAlign(Style.TextAlign.CENTER); HBoxLayoutData layoutData = new HBoxLayoutData(); layoutData.setMargins(new Margins(3)); totalSumContainer.setLayoutData(layoutData); // totalSumContainer.setSize(60, 30); // totalSumLabel = new LabelField(); LabelField sumLabel = new LabelField(": "); // totalSumContainer.add(sumLabel, layoutData); totalSumLabel.getElement().getStyle().setFontSize(20, Style.Unit.PX); totalSumLabel.getElement().getStyle().setColor("darkblue"); totalSumContainer.add(totalSumLabel, layoutData); ToolBar toolBar = new ToolBar(); toolBar.getAriaSupport().setLabel("Grid Options"); // toolBar.add(new LabelToolItem(" : ")); showAcceptedCheckBox = new CheckBox(); // showAcceptedCheckBox.setFieldLabel(" ?"); showAcceptedCheckBox.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { isToShowAccepted = showAcceptedCheckBox.getValue(); } }); // toolBar.add(showAcceptedCheckBox); // totalSumContainer.add(toolBar); totalSumContainer.setLayout(new CenterLayout()); // borderLayoutExample.getCenter().add(new LabelField(" :")); // HorizontalPanel toShowArchivedPanel = new HorizontalPanel(); // toShowArchivedPanel.getElement().getStyle().setTextAlign(Style.TextAlign.CENTER); // toShowArchivedPanel.addStyleName("align-center"); borderLayoutExample.getCenter().add(new LabelField(" : ")); borderLayoutExample.getCenter().add(showAcceptedCheckBox); // borderLayoutExample.getCenter().add(toShowArchivedPanel); cp.setTopComponent(totalSumContainer); cp.getTopComponent().addStyleName("align-right"); if (WhoseSessionEnum.ADMIN == whoseSession) { borderLayoutExample.getWest().add(new LabelField("? ?: ")); borderLayoutExample.getWest().add(isAdminSeesAll); } borderLayoutExample.getEast().add(totalSumLabel); grid = new Grid<Client>(store, cm); // grid.setWidth("100%"); grid.setStyleAttribute("borderTop", "none"); grid.setAutoExpandColumn("name"); rowEditor = new ScorecardRowEditor() { @Override public void stopEditing(boolean saveChanges) { super.stopEditing(false); } }; rowEditor.addListener(Events.BeforeEdit, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { final Client currentClient = (Client) ((RowEditorEvent) be).getRecord().getModel(); nameEditor.removeAll(); namesServiceAsync.getFreeNames(new AsyncCallback<List<String>>() { @Override public void onFailure(Throwable throwable) { System.out.println("faile obtaining free names"); } @Override public void onSuccess(List<String> strings) { for (String string : strings) { nameEditor.add(string); } String currentClientName = currentClient.getName(); if (currentClientName != null) { if (!isCurrentNameAlreadyPresentInCombo(currentClientName)) { nameEditor.add(currentClientName); } nameEditor.setSimpleValue(currentClientName); } } }); ownerEditor.removeAll(); namesServiceAsync.getAllOwnersNames(new AsyncCallback<List<String>>() { @Override public void onFailure(Throwable throwable) { System.out.println("faile obtaining all owners names"); } @Override public void onSuccess(List<String> strings) { for (String string : strings) { ownerEditor.add(string); } if (currentClient.getId() == null) { ownerEditor.setSimpleValue(whoseSession.name()); } else { ownerEditor.setSimpleValue(currentClient.getWhoseSession().name()); } } }); commentEditor.setOriginalValue(currentClient.getComment()); commentEditor.setValue(currentClient.getComment()); } }); // rowEditor.addListener(Events.AfterEdit, new Listener<BaseEvent>() { // @Override // public void handleEvent(BaseEvent be) { // nameEditor.removeAll(); // for (ClientNamesEnum clientName: ClientNamesEnum.values()) { // if (!isStoreContainsName(clientName.name())) { // nameEditor.add(clientName.name()); // } // } // } // }); rowEditor.setClicksToEdit(EditorGrid.ClicksToEdit.TWO); rowEditor.addListener(Events.AfterEdit, new Listener<RowEditorEvent>() { @Override public void handleEvent(RowEditorEvent ree) { final Record record = ree.getRecord(); final Client newModel = (Client) record.getModel(); newModel.set("name", nameEditor.getSimpleValue()); newModel.set("owner", WhoseSessionEnum.valueOf(ownerEditor.getSimpleValue())); newModel.set("comment", commentEditor.getValue()); newModel.setName(nameEditor.getSimpleValue()); newModel.setWhoseSession(WhoseSessionEnum.valueOf(ownerEditor.getSimpleValue())); newModel.setComment(commentEditor.getValue()); clientsServiceAsync.updateClient(newModel, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { System.out.println("faile update client"); } @Override public void onSuccess(Void aVoid) { System.out.println("success update client from editor"); } }); } }); grid.addPlugin(rowEditor); grid.setBorders(true); cp.add(grid); add(cp); }
From source file:de.schott.gae.football.client.GamePage.java
License:Apache License
private void showGameInternal(final String gameId) { final VerticalPanel panel = new VerticalPanel(); final HorizontalPanel panelComment = new HorizontalPanel(); Panel root = RootPanel.get(FootballEntry.CONTENT_ID); // Set up callbacks. AsyncCallback<TransferObject> gameCallback = new AbstractAsyncCallback<TransferObject>() { public void onSuccess(TransferObject to) { mLblHeader.setText(DF.format((Date) to.get("date")) + " - " + to.get("team1_name") + " vs. " + to.get("team2_name") + " (" + to.get("goal1") + ":" + to.get("goal2") + ")"); }//from www . ja va2 s . c om }; mGameService.getGame(gameId, gameCallback); // Load comments reloadComments(gameId); // Setup timer to refresh list automatically. Timer refreshTimer = new Timer() { @Override public void run() { reloadComments(gameId); } }; refreshTimer.scheduleRepeating(REFRESH_INTERVALL); final AsyncCallback<Void> saveCallback = new AbstractAsyncCallback<Void>() { @Override public void onSuccess(Void result) { reloadComments(gameId); } }; mBtnSave.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { try { int minute = Integer.parseInt(mTxtMinute.getText()); String message = mTxtComment.getText(); if (minute <= 0) { Window.alert("Please enter a correct minute."); } else if (message == null || message.isEmpty()) { Window.alert("Please enter a correct message."); } else { mGameService.saveComment(gameId, minute, message, saveCallback); mTxtComment.setText(""); mTxtMinute.setText(""); } } catch (NumberFormatException e) { Window.alert("Please enter a correct minute."); } } }); panel.add(mLblHeader); panel.add(mTableComments); panelComment.add(mTxtMinute); panelComment.add(mTxtComment); panelComment.add(mBtnSave); panel.add(panelComment); root.clear(); root.add(panel); }
From source file:edu.caltech.ipac.firefly.ui.panels.CollapsiblePanel.java
private void handleCallback() { if (disclosurePanel.isAnimationEnabled()) { if (disclosurePanel.getContent() != null && disclosurePanel.getContent().getParent() != null) { Timer t = new Timer() { int tries = 0; public void run() { tries++;//from w ww. ja va 2 s . com String h = DOM.getStyleAttribute(disclosurePanel.getContent().getParent().getElement(), "height"); if (tries > 20 || h == null || h.equals("auto") || h.equals("")) { postAction(); // GWT.log("#tries: " + tries, null); cancel(); } } }; t.scheduleRepeating(250); return; } } postAction(); }
From source file:edu.caltech.ipac.firefly.ui.panels.SearchSummaryPanel.java
private void layout(final SearchSummaryItem ssi, final int depth) { final int row = table.getRowCount(); final Image loading = new Image(GwtUtil.LOADING_ICON_URL); ssi.checkUpdate();// w w w.ja v a2 s. c om table.setWidget(row, iconColIdx, loading); if (ssi.isLoaded()) { ssi.renderItem(table, row, curGroupByName); GwtUtil.setStyles(loading, "visibility", "hidden"); } else { ssi.checkUpdate(); table.setWidget(row, iconColIdx, loading); Timer timer = new Timer() { public void run() { ssi.checkUpdate(); ssi.renderItem(table, row, curGroupByName); if (ssi.isLoaded()) { cancel(); GwtUtil.setStyles(loading, "visibility", "hidden"); } } }; bgList.add(timer); timer.scheduleRepeating(1000); } if (ssi.getChildren() != null && ssi.getChildren().size() > 0) { for (SearchSummaryItem child : ssi.getChildren()) { layout(child, depth + 1); } } }
From source file:edu.kit.ipd.sonar.client.rpc.RPCHandler.java
License:Open Source License
/** Sets up the event Handlers. */ private void setUpHandlers() { this.handlerManager.addHandler(AttemptAuthenticationEvent.TYPE, new AttemptAuthenticationEventHandler() { public void onAttemptAuthentication(final AttemptAuthenticationEvent e) { if (e.isAdmin()) { service.authenticateAdmin(e.getPassword(), authenticateAdminCallback); } else { service.authenticateUser(e.getUsername(), e.getPassword(), authenticateUserCallback); }// ww w . jav a2s .c om } }); this.handlerManager.addHandler(AttemptLogoutEvent.TYPE, new AttemptLogoutEventHandler() { public void onAttemptLogout(final AttemptLogoutEvent e) { service.logout(logoutCallback); } }); this.handlerManager.addHandler(AvailableCentralitiesRequestEvent.TYPE, new AvailableCentralitiesRequestEventHandler() { public void onAvailableCentralitiesRequest(final AvailableCentralitiesRequestEvent e) { service.getAvailableCentralities(getAvailableCentralitiesCallback); } }); this.handlerManager.addHandler(AvailableTimeBoundaryRequestEvent.TYPE, new AvailableTimeBoundaryRequestEventHandler() { public void onAvailableTimeBoundaryRequest(final AvailableTimeBoundaryRequestEvent e) { service.getTimeBoundary(getTimeBoundaryCallback); } }); this.handlerManager.addHandler(GraphRequestEvent.TYPE, new GraphRequestEventHandler() { public void onGraphRequest(final GraphRequestEvent e) { GraphSpecification spec = e.getGraphSpecification(); ArrayList<Centrality> cents = new ArrayList<Centrality>(spec.getCentralities()); if (spec.getRequestType() == GraphType.GLOBAL_GRAPH) { service.getGlobalGraph(spec.getTimeBoundary(), cents, spec.getCutoff(), new GlobalGraphCallback(spec)); } else if (spec.getRequestType() == GraphType.PEER_GRAPH) { service.getPeerGraph(spec.getUser(), spec.getTimeBoundary(), cents, spec.getCutoff(), new PeerGraphCallback(spec)); } else { throw new IllegalArgumentException("Neither peer nor global graph"); } } }); this.handlerManager.addHandler(UserlistRequestEvent.TYPE, new UserlistRequestEventHandler() { public void onUserlistRequest(final UserlistRequestEvent e) { service.getUserList(getUserListCallback); } }); /* Regularily check for updates. */ Timer t = new Timer() { @Override public void run() { service.getStateHash(getStateHashCallback); } }; t.scheduleRepeating(UPDATE_INTERVAL); }
From source file:eml.studio.client.graph.DiagramBuilder.java
License:Open Source License
/** * Redraw Data flow chart and draft// ww w.j ava 2s . co m */ public void rebuildDAG(final OozieGraph graph, final boolean editable) { // If you are performing a DAG redraw task, do not repeat it if (isloading) return; //Before you start building the map, //the submit button is locked so that it can not be submitted //Until you confirm that the current task has been completed, or begin a new task //And then use unlockSubmit to unlock presenter.lockSubmit(); isloading = true; controller.clear(); // the expected widget number after loading the DAG final int target_widget_size = controller.getWidgetNum() + graph.getNodeNum(); // draw dataset nodes for (OozieDatasetNode node : graph.getDatasetNodes()) setupDatasetWidget(node, controller); // draw program nodes for (OozieProgramNode node : graph.getProgramNodes()) { logger.info("(BEGIN) setup widget " + node.getId()); setupProgramWidget(node, editable, controller); logger.info("(END) setup widget " + node.getId()); } // draw edges Timer timer = new Timer() { @Override public void run() { if (controller.getWidgetNum() >= target_widget_size) { for (OozieEdge e : graph.getEdges()) setupEdge(e); this.cancel(); isloading = false; if (!editable) presenter.afterDAGBuild(); else { presenter.unlockSubmit(); } } } }; timer.scheduleRepeating(2); }
From source file:eolus.client.EolusUI.java
License:EUPL
void setTimeandIp() { /* periodically refresh time */ Timer refreshTimer = new Timer() { @Override/*from www .j a v a 2 s. c o m*/ public void run() { refreshTime(); } }; refreshTimer.scheduleRepeating(1000); refreshTime(); serverCall.getRemoteIp(new AsyncCallback<String>() { public void onFailure(Throwable caught) { RootPanel.get("ip").getElement().setInnerHTML(caught.getMessage()); } public void onSuccess(String reply) { RootPanel.get("ip").getElement().setInnerHTML(reply); } }); }
From source file:erd.client.jung.visualization.control.AnimatedPickingGraphMousePlugin.java
License:Open Source License
/** * If a Vertex was picked in the mousePressed event, start a Thread to * animate the translation of the graph so that the picked Vertex moves to * the center of the view/*from w ww . j a v a 2 s . c o m*/ * * @param e * the event */ @SuppressWarnings("unchecked") public void mouseReleased(MouseUpEvent e) { int buttonModifier = e.getNativeButton(); if (buttonModifier == modifiers) { // if (e.getModifiers() == modifiers) { final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource(); Point2D newCenter = null; if (vertex != null) { // center the picked vertex ERDLayout<V, E> layout = vv.getGraphLayout(); newCenter = layout.apply(vertex); } else { // they did not pick a vertex to center, so // just center the graph newCenter = vv.getCenter(); } Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - newCenter.getX()) / 10; final double dy = (lvc.getY() - newCenter.getY()) / 10; // setup timer final Timer timer = new Timer() { @Override public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy); } } }; timer.scheduleRepeating(refreshRate); // Runnable animator = new Runnable() { // // public void run() { // for (int i = 0; i < 10; i++) { // vv.getRenderContext().getMultiLayerTransformer() // .getTransformer(Layer.LAYOUT).translate(dx, dy); // try { // Thread.sleep(100); // } catch (InterruptedException ex) { // } // } // } // }; // Thread thread = new Thread(animator); // thread.start(); } }
From source file:eu.optimis.ip.gui.client.userwidget.graph.GraphicReportCODiagramPanel.java
License:Open Source License
public GraphicReportCODiagramPanel() { setHeading(Constants.MENU_CO_NAME);// w w w .j a v a2s . co m setLayout(new FitLayout()); ToolBar toolBarInfr = new ToolBar(); LabelToolItem labelInfrastructure = new LabelToolItem("Infrastructure: "); toolBarInfr.add(labelInfrastructure); labelInfrastructure.setVisible(true); setTopComponent(toolBarInfr); LabelToolItem labelInfrastructureTREC = new LabelToolItem("Infrastructure TREC"); labelInfrastructureTREC.setStyleAttribute("color", "blue"); labelInfrastructureTREC.addListener(Events.OnClick, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { ArrayList eventData = new ArrayList(); eventData.add("operation"); eventData.add("infrastructure"); Dispatcher.get().dispatch(MainEvents.TREC, eventData); ContentPanel west = (ContentPanel) Registry.get(MainView.WEST_PANEL); west.collapse(); } }); toolBarInfr.add(labelInfrastructureTREC); labelInfrastructureTREC.setVisible(true); infrastructureStore = new GroupingStore<InfrastructureDataResource>(); ColumnModel cmInfrastructure = new ColumnModel( COInfrastructureOperationData.getInfrastructureTableColumnConfig()); infrastructureGrid = new Grid<InfrastructureDataResource>(infrastructureStore, cmInfrastructure); infrastructureGrid.setBorders(true); infrastructureGrid.setStripeRows(true); infrastructureGrid.setAutoHeight(true); infrastructureGrid.getView().setForceFit(true); add(infrastructureGrid); final int indexColInfrastructure = cmInfrastructure.findColumnIndex("trec"); infrastructureGrid.addListener(Events.CellClick, new Listener<BaseEvent>() { public void handleEvent(BaseEvent be) { GridEvent ge = (GridEvent) be; if (ge.getColIndex() == indexColInfrastructure) { InfrastructureDataResource resource = infrastructureGrid.getSelectionModel().getSelectedItem(); ArrayList eventData = new ArrayList(); if (resource.getTREC().equalsIgnoreCase("Node TREC")) { eventData.add("operation"); eventData.add("node"); eventData.add(resource.getNodeId()); } else { eventData.add("operation"); eventData.add("vm"); eventData.add(resource.getVMId()); } Dispatcher.get().dispatch(MainEvents.TREC, eventData); ContentPanel west = (ContentPanel) Registry.get(MainView.WEST_PANEL); west.collapse(); } } }); ToolBar toolBarService = new ToolBar(); LabelToolItem labelDeployedServices = new LabelToolItem("Deployed Services"); toolBarService.add(labelDeployedServices); labelDeployedServices.setVisible(true); add(toolBarService); serviceStore = new GroupingStore<ServiceDataResource>(); ColumnModel cmService = new ColumnModel(COServiceOperationData.getServiceTableColumnConfig()); serviceGrid = new Grid<ServiceDataResource>(serviceStore, cmService); serviceGrid.setBorders(true); serviceGrid.setStripeRows(true); serviceGrid.setAutoHeight(true); serviceGrid.getView().setForceFit(true); add(serviceGrid); final int indexColService = cmService.findColumnIndex("trec"); serviceGrid.addListener(Events.CellClick, new Listener<BaseEvent>() { public void handleEvent(BaseEvent be) { GridEvent ge = (GridEvent) be; if (ge.getColIndex() == indexColService) { ServiceDataResource resource = serviceGrid.getSelectionModel().getSelectedItem(); ArrayList eventData = new ArrayList(); if (resource.getTREC().equalsIgnoreCase("Service TREC")) { eventData.add("operation"); eventData.add("service"); eventData.add(resource.getServiceId()); } else { eventData.add("operation"); eventData.add("vm"); eventData.add(resource.getVMId()); } Dispatcher.get().dispatch(MainEvents.TREC, eventData); ContentPanel west = (ContentPanel) Registry.get(MainView.WEST_PANEL); west.collapse(); } } }); updateServiceTable(); updateInfrastructureTable(); Timer t = new Timer() { public void run() { if (isUpdateNecessary()) { updateServiceTable(); updateInfrastructureTable(); } } }; // Schedule the timer to run once in 5 seconds. t.scheduleRepeating(5000); }
From source file:fr.aliasource.webmail.client.composer.AttachmentUploadWidget.java
License:GNU General Public License
private void buildUpload(final DockPanel dp) { setEncoding(FormPanel.ENCODING_MULTIPART); setMethod(FormPanel.METHOD_POST);// w ww . j ava2s. co m setAction(GWT.getModuleBaseURL() + "attachements"); Label l = new Label(); dp.add(l, DockPanel.WEST); dp.setCellVerticalAlignment(l, VerticalPanel.ALIGN_MIDDLE); upload = new FileUpload(); upload.setName(attachementId); dp.add(upload, DockPanel.CENTER); droppAttachmentLink = new Anchor(I18N.strings.delete()); droppAttachmentLink.addClickHandler(createDropAttachmentClickListener()); HorizontalPanel eastPanel = new HorizontalPanel(); upSpinner = new Image("minig/images/spinner_moz.gif"); upSpinner.setVisible(false); eastPanel.add(upSpinner); eastPanel.add(droppAttachmentLink); dp.add(eastPanel, DockPanel.EAST); addSubmitHandler(new SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { GWT.log("on submit " + attachementId, null); upSpinner.setVisible(true); droppAttachmentLink.setVisible(false); attachPanel.notifyUploadStarted(attachementId); } }); addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { GWT.log("on submit complete " + attachementId, null); upSpinner.setVisible(false); droppAttachmentLink.setVisible(true); attachPanel.notifyUploadComplete(attachementId); HorizontalPanel hp = new HorizontalPanel(); Label uploadInfo = new Label(); uploadInfo.setText("File '" + attachementId + "' attached."); hp.add(uploadInfo); dp.remove(upload); dp.add(hp, DockPanel.CENTER); updateMetadata(hp); } }); Timer t = new Timer() { public void run() { if (upload.getFilename() != null && upload.getFilename().length() > 0) { GWT.log("filename before upload: " + upload.getFilename(), null); cancel(); submit(); } } }; t.scheduleRepeating(300); }