List of usage examples for com.vaadin.ui Notification show
public static Notification show(String caption, Type type)
From source file:com.save.serviceprovider.PromoDealServiceImpl.java
@Override public boolean create(PromoDeals p) { Connection conn = DBConnection.connect(); PreparedStatement pstmt = null; boolean result = false; try {//from w w w.jav a2 s .c om pstmt = conn.prepareStatement( "INSERT INTO promo_deals " + "SET ClientID = ?, " + "PromoItem = ?, " + "PromoAmount = ?, " + "Quantity = ?, " + "ProductID = ?, " + "EntryDate = ?, " + "StartDate = ?, " + "EndDate = ?, " + "Remarks = ?, " + "SalesRepID = ?, " + "AreaSalesID = ?"); pstmt.setInt(1, p.getClientId()); pstmt.setString(2, p.getPromoItem()); pstmt.setDouble(3, p.getPromoAmount()); pstmt.setDouble(4, p.getQuantity()); pstmt.setInt(5, p.getProductId()); pstmt.setString(6, CommonUtilities.convertDateFormat(p.getEntryDate().toString())); pstmt.setString(7, CommonUtilities.convertDateFormat(p.getStartDate().toString())); pstmt.setString(8, CommonUtilities.convertDateFormat(p.getEndDate().toString())); pstmt.setString(9, p.getRemarks()); pstmt.setInt(10, p.getSalesRepId()); pstmt.setInt(11, p.getAreaSalesId()); pstmt.executeUpdate(); result = true; Notification.show("Added New Promo", Notification.Type.TRAY_NOTIFICATION); } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } finally { try { if (conn != null || !conn.isClosed()) { pstmt.close(); conn.close(); } } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.save.serviceprovider.PromoDealServiceImpl.java
@Override public boolean delete(int promoId, String remarks) { Connection conn = DBConnection.connect(); PreparedStatement pstmt = null; boolean result = false; try {//from w ww . j a v a2 s . c o m pstmt = conn.prepareStatement("UPDATE promo_deals " + "SET Status = ? " + "WHERE PromoDealID = ? "); pstmt.setInt(1, 1); pstmt.setInt(2, promoId); pstmt.executeUpdate(); result = true; Notification.show("Promo Deleted!", Notification.Type.TRAY_NOTIFICATION); } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } finally { try { if (conn != null || !conn.isClosed()) { pstmt.close(); conn.close(); } } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.save.serviceprovider.PromoDealServiceImpl.java
@Override public boolean update(PromoDeals p) { Connection conn = DBConnection.connect(); PreparedStatement pstmt = null; boolean result = false; try {/* w w w.j a v a 2 s . c om*/ pstmt = conn.prepareStatement("UPDATE promo_deals " + "SET PromoItem = ?, " + "PromoAmount = ?, " + "Quantity = ?, " + "ProductID = ?, " + "EntryDate = ?, " + "StartDate = ?, " + "EndDate = ?, " + "Remarks = ?, " + "SalesRepID = ?, " + "AreaSalesID = ? " + "WHERE PromoDealID = ? "); pstmt.setString(1, p.getPromoItem()); pstmt.setDouble(2, p.getPromoAmount()); pstmt.setDouble(3, p.getQuantity()); pstmt.setInt(4, p.getProductId()); pstmt.setString(5, CommonUtilities.convertDateFormat(p.getEntryDate().toString())); pstmt.setString(6, CommonUtilities.convertDateFormat(p.getStartDate().toString())); pstmt.setString(7, CommonUtilities.convertDateFormat(p.getEndDate().toString())); pstmt.setString(8, p.getRemarks()); pstmt.setInt(9, p.getSalesRepId()); pstmt.setInt(10, p.getAreaSalesId()); pstmt.setInt(11, p.getPromoId()); pstmt.executeUpdate(); result = true; Notification.show("Promo Updated!", Notification.Type.TRAY_NOTIFICATION); } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } finally { try { if (conn != null || !conn.isClosed()) { pstmt.close(); conn.close(); } } catch (SQLException ex) { ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName()); Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.java
License:Apache License
/** * /*from w w w.jav a 2s . co m*/ */ @Override public void doEnter(ViewChangeEvent event) { try { loadFrontEndInformation(true); loadClusterInformation(discoveryClient.getInstances("butterflyeffect-frontend"), frontendLayout, false); loadClusterInformation(discoveryClient.getInstances("butterflyeffect-backend"), backendLayout, false); } catch (Exception e) { e.printStackTrace(); Notification.show("The requested function was not executed correctly - " + e.getMessage() + "\n the informaiton displayed is incomplete.", Type.TRAY_NOTIFICATION); } }
From source file:com.skysql.manager.api.APIrestful.java
License:Open Source License
private boolean call(String uri, CallType type, String value, String lastModified) { HttpURLConnection httpConnection = null; URL url = null;//ww w . ja v a 2s . co m long startTime = System.nanoTime(); try { url = new URL(apiURI + "/" + uri + ((type == CallType.GET && value != null) ? value : "")); lastCall = type + " " + url.toString() + (type != CallType.GET && value != null ? " parameters: " + value : ""); ManagerUI.log("API " + lastCall); URLConnection sc = url.openConnection(); httpConnection = (HttpURLConnection) sc; String date = sdf.format(new Date()); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] mdbytes = md.digest((uri + keyCode + date).getBytes("UTF-8")); StringBuffer sb = new StringBuffer(); for (int i = 0; i < mdbytes.length; i++) { sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); } sc.setRequestProperty("Authorization", "api-auth-" + keyID + "-" + sb.toString()); sc.setRequestProperty("Date", date); sc.setRequestProperty("Accept", "application/json"); sc.setRequestProperty("X-SkySQL-API-Version", apiVERSION); OutputStreamWriter out; switch (type) { case GET: //httpConnection.setRequestProperty("Accept-Encoding", "gzip"); if (lastModified != null && !lastModified.isEmpty()) { httpConnection.setRequestProperty("If-Modified-Since", lastModified); } break; case PUT: httpConnection.setDoOutput(true); httpConnection.setRequestProperty("Content-Type", "application/json"); httpConnection.setRequestProperty("charset", "utf-8"); String length = Integer.toString(value.getBytes().length); httpConnection.setRequestProperty("Content-Length", "" + length); httpConnection.setUseCaches(false); httpConnection.setRequestMethod(type.toString()); out = new OutputStreamWriter(httpConnection.getOutputStream(), "UTF-8"); out.write(value); out.close(); break; case POST: httpConnection.setDoOutput(true); httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpConnection.setRequestProperty("charset", "utf-8"); httpConnection.setRequestProperty("Content-Length", "" + Integer.toString(value.getBytes().length)); httpConnection.setUseCaches(false); httpConnection.setRequestMethod(type.toString()); out = new OutputStreamWriter(httpConnection.getOutputStream()); out.write(value); out.close(); break; case DELETE: httpConnection.setRequestMethod(type.toString()); break; } if (api.version == null) { Map<String, List<String>> headers = httpConnection.getHeaderFields(); List<String> version = headers.get("X-SkySQL-API-Version"); api.version = version.get(0); } responseCode = httpConnection.getResponseCode(); long estimatedTime = (System.nanoTime() - startTime) / 1000000; if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) { BufferedReader in = new BufferedReader(new InputStreamReader(sc.getInputStream())); result = in.readLine(); in.close(); ManagerUI.log("Response Time: " + estimatedTime + "ms, inputStream: " + result); APIrestful api = getGson().fromJson(result, APIrestful.class); return api.success; } else if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) { ManagerUI.log("If-Modified-Since worked!"); APIrestful api = getGson().fromJson("", APIrestful.class); return true; } else { BufferedReader in = new BufferedReader(new InputStreamReader(httpConnection.getErrorStream())); errors = in.readLine(); in.close(); String msg = "Response Time: " + estimatedTime + "ms, responseCode: " + responseCode + ", errorStream: " + errors; if (Debug.ON) { ManagerUI.log(msg); } else { ManagerUI.error("API " + lastCall); ManagerUI.error(msg); } APIrestful api = getGson().fromJson(errors, APIrestful.class); errors = "API error: HTTP " + responseCode + " - " + api.getErrors(); switch (responseCode) { case HttpURLConnection.HTTP_INTERNAL_ERROR: case HttpURLConnection.HTTP_UNAUTHORIZED: Notification.show(errors, Notification.Type.ERROR_MESSAGE); throw new RuntimeException("API error"); case HttpURLConnection.HTTP_BAD_REQUEST: case HttpURLConnection.HTTP_NOT_FOUND: case HttpURLConnection.HTTP_CONFLICT: Notification.show(errors, Notification.Type.ERROR_MESSAGE); return false; default: Notification.show(errors, Notification.Type.ERROR_MESSAGE); return false; } } } catch (NoSuchAlgorithmException e) { new ErrorDialog(e, "Could not use MD5 to encode HTTP request header"); throw new RuntimeException(); } catch (MalformedURLException e) { new ErrorDialog(e, "Bad URL: " + url.toString()); throw new RuntimeException(); } catch (ConnectException e) { new ErrorDialog(e, "API not responding at: " + getURI()); throw new RuntimeException("API not responding"); } catch (MalformedJsonException e) { new ErrorDialog(e, "API did not return JSON for: " + api.errorString()); throw new RuntimeException("MalformedJson inputStream"); } catch (IOException e) { new ErrorDialog(e, "IOException while calling the API" + errorString()); throw new RuntimeException("IOException"); } catch (JsonSyntaxException e) { new ErrorDialog(e, "API did not return valid JSON for:" + api.errorString()); throw new RuntimeException("JsonSyntax inputStream"); } catch (Exception e) { new ErrorDialog(e, "API call: " + url.toString()); throw new RuntimeException("API error"); } }
From source file:com.skysql.manager.ui.ErrorView.java
License:Open Source License
/** * Instantiates a new error view./*from ww w . ja v a 2 s. co m*/ * * @param type the notification type * @param errorMsg the error msg */ public ErrorView(Type type, String errorMsg) { addStyleName("loginView"); setSizeFull(); setMargin(true); setSpacing(true); if (errorMsg != null) { Notification.show(errorMsg, type); } Embedded logo = new Embedded(null, new ThemeResource("img/productlogo.png")); addComponent(logo); setComponentAlignment(logo, Alignment.TOP_CENTER); if (type == Notification.Type.ERROR_MESSAGE) { Label refreshLabel = new Label("To try again, please refresh/reload the current page."); refreshLabel.setSizeUndefined(); refreshLabel.addStyleName("instructions"); addComponent(refreshLabel); setComponentAlignment(refreshLabel, Alignment.TOP_CENTER); } }
From source file:com.snowy.Game.java
public Game(int id, data d) { Notification.show("Game/Chat Created", Notification.Type.TRAY_NOTIFICATION); this.d = d;/*from www . java 2s. com*/ gameId = id; CheckForUpdate(); selfGame = p1 == p2; this.setId("GameForMe"); js.addFunction("sendMove", (e) -> { int clickPos = (int) e.getNumber(0); for (int i = 0; i < e.getArray(1).length(); i++) { int circle = (int) e.getArray(1).getArray(i).getNumber(0); int center = (int) e.getArray(1).getArray(i).getNumber(1); if (clickPos <= (center + 30) && clickPos >= (center - 30)) { //Logger.getLogger(Game.class.getName()).info("Played "+circle); boolean win = d.move(circle, (currentTurn == p1 ? p2 : p1), this.gameId); if (win == true) { /*Notification nn = new Notification("Game Over You Win","",Notification.Type.WARNING_MESSAGE); nn.setDelayMsec(5000); nn.show(Page.getCurrent());*/ js.execute("if(document.getElementById('GameForMe')!=null && " + "document.getElementById('GameForMe').hasChildNodes() &&" + "document.getElementById('GameForMe').lastChild.hasChildNodes()){" + "var bb = document.getElementsByTagName('svg')[0];" + "bb.parentNode.removeChild(bb);" + "}"); VerticalLayout winLayout = new VerticalLayout(); Label winMessage = new Label("<h1>Congratulations You Win!</h1>", ContentMode.HTML); Label winCloseMessage = new Label( "<h3>Game and Chat Tabs will stay open till next Login</h3>", ContentMode.HTML); Notification.show("Game Won", Notification.Type.TRAY_NOTIFICATION); winLayout.addComponent(winMessage); winLayout.addComponent(winCloseMessage); winLayout.setSizeFull(); winLayout.setMargin(true); winLayout.setSpacing(false); winLayout.setComponentAlignment(winMessage, Alignment.MIDDLE_CENTER); winLayout.setComponentAlignment(winCloseMessage, Alignment.MIDDLE_CENTER); this.addComponent(winLayout); this.setComponentAlignment(winLayout, Alignment.MIDDLE_CENTER); notDisp = true; //Logger.getLogger(Game.class.getName()).info("go win"); } currentTurn = currentTurn == p1 ? p2 : p1; rendered = false; break; } } }); /*this.addComponent(new Button("c",e->{ create(); //js.execute("hello();"); }));*/ this.setSizeFull(); }
From source file:com.snowy.Game.java
public void CheckForUpdate() { if (d.isGameActive(gameId) == 0) { ArrayList<ArrayList<Integer>> tempGameBoard = d.getGameBoard(gameId); if (!tempGameBoard.equals(gameBoard)) { hasUpdate = true;/*w w w . j a v a2 s.c o m*/ gameBoard = tempGameBoard; p1 = d.getPlayerOne(gameId); p2 = d.getPlayerTwo(gameId); currentTurn = d.getLastTurn(gameId) == 0 ? p1 : d.getLastTurn(gameId); } //Logger.getLogger(Game.class.getName()).info(hasUpdate+"|"+this.isConnectorEnabled()+"|"+rendered+"|"+jj++); if (this.isConnectorEnabled() && hasUpdate) {//&& !rendered){ Update(); hasUpdate = false; //Logger.getLogger(Game.class.getName()).info("has update"); rendered = true; } else if (this.isConnectorEnabled() && !rendered) { Update(); //Logger.getLogger(Game.class.getName()).info("rendering"); this.rendered = true; } else if (!this.isConnectorEnabled() && rendered) { rendered = false; //Logger.getLogger(Game.class.getName()).info("mark as need to render"); } } else { //Logger.getLogger(Game.class.getName()).info("go lose"); if (this.isConnectorEnabled() && notDisp == false) { //Logger.getLogger(Game.class.getName()).info("go lose " +((d.getLastTurn(gameId)==p1?p2:p1))+" | "+d.getUserIdFromToken()); if ((d.getLastTurn(gameId) == p1 ? p2 : p1) != d.getUserIdFromToken()) { /*Notification nn = new Notification("Game Over You Lose","",Notification.Type.WARNING_MESSAGE); nn.setDelayMsec(5000); nn.show(Page.getCurrent());*/ js.execute("if(document.getElementById('GameForMe')!=null && " + "document.getElementById('GameForMe').hasChildNodes() &&" + "document.getElementById('GameForMe').lastChild.hasChildNodes()){" + "var bb = document.getElementsByTagName('svg')[0];" + "bb.parentNode.removeChild(bb);" + "}"); VerticalLayout loseLayout = new VerticalLayout(); Label loseMessage = new Label("<h1>Unfortunately You Have Lost</h1>", ContentMode.HTML); Label loseCloseMessage = new Label("<h3>Game and Chat Tabs will stay open till next Login</h3>", ContentMode.HTML); loseLayout.addComponent(loseMessage); loseLayout.addComponent(loseCloseMessage); loseLayout.setSizeFull(); loseLayout.setComponentAlignment(loseMessage, Alignment.MIDDLE_CENTER); Notification.show("Game Lost", Notification.Type.TRAY_NOTIFICATION); loseLayout.setComponentAlignment(loseCloseMessage, Alignment.MIDDLE_CENTER); loseLayout.setMargin(true); loseLayout.setSpacing(false); this.addComponent(loseLayout); this.setComponentAlignment(loseLayout, Alignment.MIDDLE_CENTER); //Logger.getLogger(Game.class.getName()).info("go lose"); notDisp = true; } } //n. } }
From source file:com.snowy.Requests.java
public void updateRequests() { if (this.getComponentCount() > 0) { x = Integer.parseInt(this.getSelectedTab().getId().substring(3)); //Logger.getLogger(Requests.class.getName()).info(this.getSelectedTab().getId()); }//from ww w . j av a 2 s .co m if (this.getComponentCount() < d.retriveChallenges().size()) { Notification.show("New Game Request", Notification.Type.TRAY_NOTIFICATION); } this.removeAllComponents(); ArrayList<ArrayList<String>> al = d.retriveChallenges(); int i = 0; for (ArrayList<String> ss : al) { VerticalLayout vl = new VerticalLayout(); HorizontalLayout hl = new HorizontalLayout(); if ((!d.getUsernameFromToken().equals(ss.get(0)) || (d.getUsernameFromToken().equals(ss.get(0)) && d.getUsernameFromToken().equals(ss.get(1)))) && Integer.parseInt(ss.get(3)) == 0) { vl.addComponent(new Label("You have been challenged by " + ss.get(0) + " on " + new java.sql.Timestamp(Long.parseLong(ss.get(2))).toString())); //Notification.show("New Game Reqest from "+ss.get(0), Notification.Type.TRAY_NOTIFICATION); hl.addComponent(new Button("Accept", ee -> { d.acceptRefuse(Integer.parseInt(ss.get(4)), true); })); hl.addComponent(new Button("Refuse", rr -> { d.acceptRefuse(Integer.parseInt(ss.get(4)), false); })); vl.addComponent(hl); } else { vl.addComponent(new Label("You challenged " + ss.get(1) + " on " + new java.sql.Timestamp(Long.parseLong(ss.get(2))).toString())); switch (Integer.parseInt(ss.get(3))) { case 0: vl.addComponent(new Label("Status: Awaiting Response")); break; case 1: PostLoginView plv = ((PostLoginView) this.getUI().getContent()); vl.addComponent(new Label("Status: Accepted")); plv.getGameWindow().initGame(ss.get(0), ss.get(1), Integer.parseInt(ss.get(4))); //Logger.getLogger(Requests.class.getName()).info(ss.get(4)); int gameId = d.getGameIdfromRequest(Integer.parseInt(ss.get(4))); if (plv.getGameWindow().gameIds().contains(gameId) != true && plv.getChatWindow().getChatIds().contains(gameId) != true) { plv.getChatWindow().addChat(gameId); //add game } //Logger.getLogger(Requests.class.getName()).info(plv.getGameWindow().gameIds().get(0)+" | "+ss.get(4)); break; case 2: vl.addComponent(new Label("Status: Refused")); break; } } vl.setSpacing(true); hl.setSpacing(true); vl.setMargin(true); vl.setId("set" + al.indexOf(ss)); this.addTab(vl, ss.get(0) + "\t" + new java.sql.Timestamp(Long.parseLong(ss.get(2))).toString()); //this.getTab(vl).setId("set"+i); i++; } this.setSelectedTab(x); }
From source file:com.squadd.views.LoginView.java
@PostConstruct private void configureComponents() { login = new Button("Sign in"); register = new Button("Register"); loginUI = new LoginUI(login, register, false); addComponents(loginUI);//from ww w . j a va 2 s.co m Button.ClickListener log = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (loginUI.getUsername().getValue().isEmpty()) { loginUI.getUsername().setComponentError(new UserError("Login field must not be empty")); } else if (loginUI.getPassword().getValue().isEmpty()) { loginUI.getPassword().setComponentError(new UserError("Password field must not be empty")); } else { if (Authorizator.successAuthorization(loginUI, contact)) { Notification.show("Welcome to the squadd!", Notification.Type.HUMANIZED_MESSAGE); getUI().getNavigator().navigateTo(UserPageView.NAME); } else { Notification.show("Wrong login/password", Notification.Type.ERROR_MESSAGE); } } } }; Button.ClickListener reg = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { getUI().getNavigator().navigateTo(RegisterView.name); } catch (Exception e) { System.out.println(e.getMessage()); } } }; login.addClickListener(log); register.addClickListener(reg); }