List of usage examples for com.google.gwt.user.client Cookies getCookie
public static String getCookie(String name)
From source file:org.opennms.features.node.list.gwt.client.PageableNodeList.java
License:Open Source License
public void showErrorDialogBox(String errorMsg) { if (m_errorDialog == null) { m_errorDialog = new ErrorDialogBox(); }/* ww w .j a v a 2s. co m*/ if (!Boolean.parseBoolean(Cookies.getCookie(COOKIE))) { m_errorDialog.setPopupPosition(getAbsoluteLeft(), getAbsoluteTop()); m_errorDialog.setWidth("" + (getOffsetWidth() - 12) + "px"); m_errorDialog.setErrorMessageAndShow(errorMsg); } }
From source file:org.opennms.gwt.web.ui.asset.client.tools.DisclosurePanelCookie.java
License:Open Source License
@UiConstructor public DisclosurePanelCookie(final String cookieName) { panel.setStyleName("DisclosurePanelCookie"); panel.setAnimationEnabled(true);// w w w . j av a 2s . c o m if (Cookies.isCookieEnabled()) { // prepare Cookie if not already set if (Cookies.getCookie(cookieName + "Open") == null) { Cookies.setCookie(cookieName + "Open", "true"); } // check cookie and set open/close by cookie-value if (Cookies.getCookie(cookieName + "Open").equals("true")) { panel.setOpen(true); } else { panel.setOpen(false); } // add openhandler that sets open/true to cookie panel.addOpenHandler(new OpenHandler<DisclosurePanel>() { @Override public void onOpen(OpenEvent<DisclosurePanel> event) { Cookies.setCookie(cookieName + "Open", "true"); } }); // add closehandler that sets close/flase to cookie panel.addCloseHandler(new CloseHandler<DisclosurePanel>() { @Override public void onClose(CloseEvent<DisclosurePanel> event) { Cookies.setCookie(cookieName + "Open", "false"); } }); } initWidget(panel); }
From source file:org.openremote.modeler.client.view.ApplicationView.java
License:Open Source License
private ToggleButton createBMButton() { final ToggleButton bmButton = new ToggleButton(); bmButton.setToolTip("Building Modeler"); bmButton.setIcon(icons.bmIcon());/*from www . j a va 2 s. c o m*/ bmButton.addSelectionListener(new SelectionListener<ButtonEvent>() { public void componentSelected(ButtonEvent ce) { if (!bmButton.isPressed()) { bmButton.toggle(true); } else { modelerContainer.remove(uiDesignerView); modelerContainer.add(buildingModelerView); Cookies.setCookie(Constants.CURRETN_ROLE, Role.ROLE_MODELER); modelerContainer.layout(); } } }); bmButton.setToggleGroup("modeler-switch"); if (Cookies.getCookie(Constants.CURRETN_ROLE) == null || Role.ROLE_MODELER.equals(Cookies.getCookie(Constants.CURRETN_ROLE))) { bmButton.toggle(true); } return bmButton; }
From source file:org.openremote.modeler.client.view.ApplicationView.java
License:Open Source License
private ToggleButton createUDButton() { final ToggleButton udButton = new ToggleButton(); udButton.setToolTip("UI Designer"); udButton.setIcon(icons.udIcon());/*from w ww.j a v a 2 s. c o m*/ udButton.addSelectionListener(new SelectionListener<ButtonEvent>() { public void componentSelected(ButtonEvent ce) { if (!udButton.isPressed()) { udButton.toggle(true); } else { modelerContainer.remove(buildingModelerView); modelerContainer.add(uiDesignerView); Cookies.setCookie(Constants.CURRETN_ROLE, Role.ROLE_DESIGNER); modelerContainer.layout(); } } }); udButton.setToggleGroup("modeler-switch"); if (Role.ROLE_DESIGNER.equals(Cookies.getCookie(Constants.CURRETN_ROLE))) { udButton.toggle(true); } return udButton; }
From source file:org.openremote.modeler.client.view.ApplicationView.java
License:Open Source License
/** * Creates the center.// w w w .ja v a 2 s . c om * * @param authority * the authority */ private void createCenter(Authority authority) { List<String> roles = authority.getRoles(); modelerContainer = new LayoutContainer(); modelerContainer.setLayout(new FitLayout()); if (roles.contains(Role.ROLE_ADMIN) || (roles.contains(Role.ROLE_DESIGNER) && roles.contains(Role.ROLE_MODELER))) { this.buildingModelerView = new BuildingModelerView(); this.uiDesignerView = new UIDesignerView(); if (Role.ROLE_DESIGNER.equals(Cookies.getCookie(Constants.CURRETN_ROLE))) { modelerContainer.add(uiDesignerView); } else { modelerContainer.add(buildingModelerView); } } else if (roles.contains(Role.ROLE_MODELER) && !roles.contains(Role.ROLE_DESIGNER)) { this.buildingModelerView = new BuildingModelerView(); modelerContainer.add(buildingModelerView); } else if (roles.contains(Role.ROLE_DESIGNER) && !roles.contains(Role.ROLE_MODELER)) { this.uiDesignerView = new UIDesignerView(); modelerContainer.add(uiDesignerView); } BorderLayoutData data = new BorderLayoutData(Style.LayoutRegion.CENTER); data.setMargins(new Margins(0, 5, 0, 5)); viewport.add(modelerContainer, data); }
From source file:org.openremote.modeler.client.widget.component.ScreenImage.java
License:Open Source License
public void onStateChange() { Sensor sensor = uiImage.getSensor(); if (sensor != null && states.isEmpty()) { String resourcePath = Cookies.getCookie(Constants.CURRETN_RESOURCE_PATH); if (resourcePath != null) { if (sensor.getType() == SensorType.SWITCH) { if (!"".equals(uiImage.getSensorLink().getStateValueByStateName("on"))) { states.add(resourcePath + uiImage.getSensorLink().getStateValueByStateName("on")); }/* ww w . j av a2 s . c o m*/ if (!"".equals(uiImage.getSensorLink().getStateValueByStateName("off"))) { states.add(resourcePath + uiImage.getSensorLink().getStateValueByStateName("off")); } } else if (sensor.getType() == SensorType.CUSTOM) { SensorLink sensorLink = uiImage.getSensorLink(); for (State state : ((CustomSensor) sensor).getStates()) { if (!"".equals(uiImage.getSensorLink().getStateValueByStateName(state.getName()))) { states.add(resourcePath + sensorLink.getStateValueByStateName(state.getName())); } } } } } if (!states.isEmpty()) { if (stateIndex < states.size() - 1) { stateIndex = stateIndex + 1; } else if (stateIndex == states.size() - 1) { stateIndex = 0; } image.setUrl(states.get(stateIndex)); } }
From source file:org.openremote.web.console.service.LocalDataServiceImpl.java
License:Open Source License
private String getData(String dataName) { if (dataName == null || dataName.equals("")) return ""; dataName = buildPathString(dataName); String data = null;// ww w . j a v a 2s .c o m try { if (dataStore != null) { data = dataStore.getItem(dataName); } else { data = Cookies.getCookie(dataName); } } catch (Exception e) { } if (data == null || data.equals("null")) { data = ""; } return data; }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.RMController.java
License:Open Source License
/** * Start the timer that will fetch new node states periodically *///from w w w . java2s . c o m private void startTimer() { if (this.updater != null) throw new IllegalStateException("Updated is running"); this.updater = new Timer() { @Override public void run() { if (!localSessionNum.equals(Cookies.getCookie(LOCAL_SESSION_COOKIE))) { teardown("Duplicate session detected!<br>" + "Another tab or window in this browser is accessing this page."); } fetchRMMonitoring(); } }; this.updater.scheduleRepeating(RMConfig.get().getClientRefreshTime()); this.statsUpdater = new Timer() { @Override public void run() { fetchStatHistory(); } }; this.statsUpdater.scheduleRepeating(RMConfig.get().getStatisticsRefreshTime()); }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerController.java
License:Open Source License
/** * Starts the Timer that will periodically fetch the current scheduler state * from the server end and update the local view */// w w w. java 2 s. c o m private void startTimer() { if (this.schedulerTimerUpdate != null) throw new IllegalStateException("There's already a Timer"); this.schedulerTimerUpdate = new Timer() { @Override public void run() { if (!localSessionNum.equals(Cookies.getCookie(LOCAL_SESSION_COOKIE))) { teardown("Duplicate session detected!<br>" + "Another tab or window in this browser is accessing this page."); } SchedulerController.this.updateSchedulerStatus(); executionController.executionStateRevision(false); if (timerUpdate % userFetchTick == 0) { final long t1 = System.currentTimeMillis(); scheduler.getSchedulerUsers(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onSuccess(String result) { List<SchedulerUser> users; JSONValue val = parseJSON(result); JSONArray arr = val.isArray(); if (arr == null) { error("Expected JSON Array: " + val.toString()); } users = getUsersFromJson(arr); model.setSchedulerUsers(users); long t = (System.currentTimeMillis() - t1); LogModel.getInstance().logMessage("<span style='color:gray;'>Fetched " + users.size() + " users in " + t + " ms</span>"); } public void onFailure(Throwable caught) { if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch scheduler users:<br>" + JSONUtils.getJsonErrorMessage(caught)); } }); } if (timerUpdate % statsFetchTick == 0) { final long t1 = System.currentTimeMillis(); scheduler.getStatistics(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { String msg = JSONUtils.getJsonErrorMessage(caught); if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch scheduler stats:<br>" + msg); } public void onSuccess(String result) { HashMap<String, String> stats = new HashMap<String, String>(); JSONObject json = parseJSON(result).isObject(); if (json == null) error("Expected JSON Object: " + result); stats.put("JobSubmittingPeriod", json.get("JobSubmittingPeriod").isString().stringValue()); stats.put("FormattedJobSubmittingPeriod", json.get("FormattedJobSubmittingPeriod").isString().stringValue()); stats.put("MeanJobPendingTime", json.get("MeanJobPendingTime").isString().stringValue()); stats.put("ConnectedUsersCount", json.get("ConnectedUsersCount").isString().stringValue()); stats.put("FinishedTasksCount", json.get("FinishedTasksCount").isString().stringValue()); stats.put("RunningJobsCount", json.get("RunningJobsCount").isString().stringValue()); stats.put("RunningTasksCount", json.get("RunningTasksCount").isString().stringValue()); stats.put("FormattedMeanJobPendingTime", json.get("FormattedMeanJobPendingTime").isString().stringValue()); stats.put("MeanJobExecutionTime", json.get("MeanJobExecutionTime").isString().stringValue()); stats.put("PendingTasksCount", json.get("PendingTasksCount").isString().stringValue()); stats.put("FinishedJobsCount", json.get("FinishedJobsCount").isString().stringValue()); stats.put("TotalTasksCount", json.get("TotalTasksCount").isString().stringValue()); stats.put("FormattedMeanJobExecutionTime", json.get("FormattedMeanJobExecutionTime").isString().stringValue()); stats.put("TotalJobsCount", json.get("TotalJobsCount").isString().stringValue()); stats.put("PendingJobsCount", json.get("PendingJobsCount").isString().stringValue()); model.setSchedulerStatistics(stats); long t = (System.currentTimeMillis() - t1); LogModel.getInstance().logMessage("<span style='color:gray;'>Fetched sched stats: " + result.length() + " chars in " + t + " ms</span>"); } }); final long t2 = System.currentTimeMillis(); scheduler.getStatisticsOnMyAccount(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch account stats:<br>" + JSONUtils.getJsonErrorMessage(caught)); } public void onSuccess(String result) { HashMap<String, String> stats = new HashMap<String, String>(); JSONObject json = parseJSON(result).isObject(); if (json == null) error("Expected JSON Object: " + result); stats.put("TotalTaskCount", json.get("TotalTaskCount").isString().stringValue()); stats.put("TotalJobDuration", json.get("TotalJobDuration").isString().stringValue()); stats.put("TotalJobCount", json.get("TotalJobCount").isString().stringValue()); stats.put("TotalTaskDuration", json.get("TotalTaskDuration").isString().stringValue()); model.setAccountStatistics(stats); long t = (System.currentTimeMillis() - t2); LogModel.getInstance() .logMessage("<span style='color:gray;'>Fetched account stats: " + result.length() + " chars in " + t + " ms</span>"); } }); } timerUpdate++; } }; this.schedulerTimerUpdate.scheduleRepeating(SchedulerConfig.get().getClientRefreshTime()); }
From source file:org.palaso.languageforge.client.lex.jsonrpc.JsonRpc.java
License:Apache License
/** * Executes a json-rpc request.//from www . j a v a 2s. c o m * * @param <R> * * @param <R> * * @param url * The location of the service * @param username * The username for basic authentification * @param password * The password for basic authentification * @param method * The method name * @param params * An array of objects containing the parameters * @param callback * A callbackhandler like in gwt's rpc. */ // NOTE We will use the Action to 3encode our request and decode the // response // of *the object* (DTO) // NOTE This class will add the rpc elements which wrap the request and // repsonse. public <A extends Action<R>, R> void execute(final A action, final AsyncCallback<R> callback) { RequestCallback handler = new RequestCallback() { public void onResponseReceived(Request request, Response response) { try { if (response.getStatusCode() != 200) { String errMsg = ""; if (response.getStatusCode() == 0) { errMsg = "Error: Can not connect to server, this may be a problem of network or server down."; } else { errMsg = "Error: Unexpected server or network error [" + String.valueOf(response.getStatusCode()) + "]: " + response.getStatusText(); } RuntimeException runtimeException = new RuntimeException(errMsg); callback.onFailure(runtimeException); return; } String resp = response.getText(); if (resp.equals("")) { RuntimeException runtimeException = new RuntimeException( "Error: Received empty result from server, this could be a server fail."); callback.onFailure(runtimeException); } JsonRpcResponse<R> reply = action.decodeResponse(resp); if (reply == null) { // This implies a decode error. Perhaps // it would be better if the action // doing the decode threw a more // precise exception RuntimeException runtimeException = new RuntimeException( "Error: Received data can not decoded, data: " + response.getText()); callback.onFailure(runtimeException); } if (reply.getResponseModel().isErrorResponse()) { RuntimeException runtimeException = new RuntimeException( "Error: Server failed with message: " + reply.getResponseModel().getError()); callback.onFailure(runtimeException); } else if (reply.getResponseModel().isSuccessfulResponse()) { R result = (R) reply.getResponseModel().getResult(); callback.onSuccess(result); } else { RuntimeException runtimeException = new RuntimeException( "Error: Received data has syntax error: " + response.getText()); callback.onFailure(runtimeException); } } catch (RuntimeException e) { callback.onFailure(e); } finally { decreaseRequestCounter(action.isBackgroundRequest()); } } public void onError(Request request, Throwable exception) { try { if (exception instanceof RequestTimeoutException) { RuntimeException runtimeException = new RuntimeException( "Error: Connection timeout, server didn't respose."); callback.onFailure(runtimeException); } else { RuntimeException runtimeException = new RuntimeException( "Error: A unknown error happened when try to send request to server"); callback.onFailure(runtimeException); } } catch (RuntimeException e) { callback.onFailure(e); } finally { decreaseRequestCounter(action.isBackgroundRequest()); } } }; increaseRequestCounter(action.isBackgroundRequest()); // The request builder. Currently we only attempt a request once. RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, action.getFullServiceUrl()); if (requestTimeout > 0) builder.setTimeoutMillis(requestTimeout); builder.setHeader("Content-Type", "application/json; charset=UTF-8"); String body = action.getRequestModelAsJsonString(requestSerial++); if (body == null) builder.setHeader("Content-Length", "0"); // builder.setHeader("Content-Length", Integer.toString(body.length())); if (requestCookie != null) if (Cookies.getCookie(requestCookie) != null) builder.setHeader("X-Cookie", Cookies.getCookie(requestCookie)); try { builder.sendRequest(body, handler); } catch (RequestException exception) { handler.onError(null, exception); } }