List of usage examples for com.vaadin.ui Window close
public void close()
From source file:facs.components.BookAdmin.java
License:Open Source License
private Component deletedBookingsGrid() { VerticalLayout devicesLayout = new VerticalLayout(); devicesLayout.setCaption("Trash"); // HorizontalLayout buttonLayout = new HorizontalLayout(); // there will now be space around the test component // components added to the test component will now not stick together but have space between // them// www .j a v a2 s . c o m devicesLayout.setMargin(true); devicesLayout.setSpacing(true); // buttonLayout.setMargin(true); // buttonLayout.setSpacing(true); // buttonLayout.addComponent(add); BeanItemContainer<BookingBean> booking = getDeletedBookings(); GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(booking); gpc.addGeneratedProperty("restore", new PropertyValueGenerator<String>() { /** * */ private static final long serialVersionUID = 4082425701384202280L; @Override public String getValue(Item item, Object itemId, Object propertyId) { // return FontAwesome.TRASH_O.getHtml(); // The caption return "Restore"; // The caption } @Override public Class<String> getType() { return String.class; } }); gpc.addGeneratedProperty("delete", new PropertyValueGenerator<String>() { /** * */ private static final long serialVersionUID = 1307493624895857513L; @Override public String getValue(Item item, Object itemId, Object propertyId) { // return FontAwesome.TRASH_O.getHtml(); // The caption return "Purge"; // The caption } @Override public Class<String> getType() { return String.class; } }); devicesGridTrash = new Grid(gpc); // Create a grid devicesGridTrash.setWidth("100%"); devicesGridTrash.setSelectionMode(SelectionMode.SINGLE); devicesGridTrash.getColumn("delete").setRenderer(new HtmlRenderer()); devicesGridTrash.getColumn("restore").setRenderer(new HtmlRenderer()); setRenderers(devicesGridTrash); devicesGridTrash.setColumnOrder("ID", "deviceName", "service", "start", "end", "username", "phone", "price"); // Render a button that deletes the data row (item) /* * devicesGrid.addColumn("delete", FontIcon.class).setWidth(35) .setRenderer(new * FontIconRenderer(new RendererClickListener() { * * @Override public void click(RendererClickEvent e) { Notification.show("Deleted item " + * e.getItemId()); } })); */ devicesGridTrash.getColumn("delete") .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() { /** * */ private static final long serialVersionUID = 302628105070456680L; @Override public void click(RendererClickEvent event) { try { Window cd = new Window("Purge Booking"); cd.setHeight("200px"); cd.setWidth("400px"); cd.setResizable(false); GridLayout dialogLayout = new GridLayout(3, 3); Button okButton = new Button("Yes"); okButton.addStyleName(ValoTheme.BUTTON_DANGER); Button cancelButton = new Button("No, I'm actually not sure!"); cancelButton.addStyleName(ValoTheme.BUTTON_PRIMARY); Label information = new Label("Are you sure you want to purge this item?"); information.addStyleName(ValoTheme.LABEL_NO_MARGIN); okButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 3739260172118651857L; @Override public void buttonClick(ClickEvent okEvent) { purgeBooking((BookingBean) event.getItemId()); cd.close(); Notification("The booking was purged!", "At the end, you are the admin, you have the power.", ""); } }); cancelButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = -3931200823633220160L; @Override public void buttonClick(ClickEvent okEvent) { cd.close(); } }); dialogLayout.addComponent(information, 0, 0, 2, 0); dialogLayout.addComponent(okButton, 0, 1); dialogLayout.addComponent(cancelButton, 1, 1); dialogLayout.setMargin(true); dialogLayout.setSpacing(true); cd.setContent(dialogLayout); cd.center(); UI.getCurrent().addWindow(cd); } catch (Exception e) { e.printStackTrace(); } FieldGroup fieldGroup = devicesGridTrash.getEditorFieldGroup(); fieldGroup.addCommitHandler(new FieldGroup.CommitHandler() { /** * */ private static final long serialVersionUID = 3799806709907688919L; @Override public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { } @Override public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { Notification("Successfully Updated", "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.", "success"); refreshGrid(); } private void refreshGrid() { getDeletedBookings(); } }); } })); devicesGridTrash.getColumn("restore") .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() { /** * */ private static final long serialVersionUID = -9104571186503913834L; @Override public void click(RendererClickEvent event) { restoreBooking((BookingBean) event.getItemId()); } })); // devicesGrid.setEditorEnabled(true); // devicesLayout.addComponent(buttonLayout); devicesLayout.addComponent(devicesGridTrash); // TODO filtering // HeaderRow filterRow = devicesGrid.prependHeaderRow(); return devicesLayout; }
From source file:facs.components.Booking.java
License:Open Source License
private Component myUpcomingBookings() { VerticalLayout devicesLayout = new VerticalLayout(); // devicesLayout.setCaption("My Bookings"); // there will now be space around the test component // components added to the test component will now not stick together but have space between // them/* w w w . j a v a 2 s . c om*/ devicesLayout.setMargin(true); devicesLayout.setSpacing(true); Date serverTime = new WebBrowser().getCurrentDate(); Date nextDayTime = new Date(serverTime.getTime() + (1000 * 60 * 60 * 24)); BeanItemContainer<BookingBean> users = getMyUpcomingBookings(bookingModel.getLDAP(), nextDayTime); // System.out.println(bookingModel.getLDAP()); GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users); gpc.addGeneratedProperty("delete", new PropertyValueGenerator<String>() { /** * */ private static final long serialVersionUID = 1263377339178640406L; @Override public String getValue(Item item, Object itemId, Object propertyId) { // return FontAwesome.TRASH_O.getHtml(); // The caption return "Trash"; // The caption } @Override public Class<String> getType() { return String.class; } }); /* * * try { * * FreeformQuery query = new FreeformQuery( * "SELECT * FROM booking INNER JOIN user ON booking.user_ldap = user.user_ldap WHERE deleted IS NULL AND booking.user_ldap ='" * + bookingModel.getLDAP() + "';", DBManager.getDatabaseInstanceAlternative(), "booking_id"); * SQLContainer container = new SQLContainer(query); * * // System.out.println("Print Container: " + container.size()); * container.setAutoCommit(isEnabled()); * * myBookings = new Grid(container); * * } catch (Exception e) { e.printStackTrace(); } * * myBookings.setColumnOrder("booking_id", "confirmation", "device_name", "service", "start", * "end", "kostenstelle", "price", "project"); * * myBookings.removeColumn("user_ldap"); myBookings.removeColumn("timestamp"); * myBookings.removeColumn("deleted"); myBookings.removeColumn("user_name"); * myBookings.removeColumn("group_id"); myBookings.removeColumn("workgroup_id"); * myBookings.removeColumn("email"); myBookings.removeColumn("phone"); * myBookings.removeColumn("admin_panel"); myBookings.removeColumn("user_id"); * * myBookings.getColumn("booking_id").setHeaderCaption("Booking ID"); */ upcomingBookings = new Grid(gpc); // Create a grid upcomingBookings.setStyleName("my-style"); upcomingBookings.setWidth("100%"); upcomingBookings.setSelectionMode(SelectionMode.SINGLE); upcomingBookings.setEditorEnabled(false); upcomingBookings.setColumnOrder("ID", "confirmation", "deviceName", "service", "start", "end", "username", "phone", "price"); upcomingBookings.getColumn("price").setHeaderCaption("Approx. Price"); // System.out.println(myBookings.getColumns()); setRenderers(upcomingBookings); devicesLayout.addComponent(upcomingBookings); upcomingBookings.getColumn("delete") .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() { /** * */ private static final long serialVersionUID = 302628105070456680L; @Override public void click(RendererClickEvent event) { try { Window cd = new Window("Delete Booking"); cd.setHeight("200px"); cd.setWidth("400px"); cd.setResizable(false); GridLayout dialogLayout = new GridLayout(3, 3); Button okButton = new Button("Yes"); okButton.addStyleName(ValoTheme.BUTTON_DANGER); Button cancelButton = new Button("No, I'm actually not sure!"); cancelButton.addStyleName(ValoTheme.BUTTON_PRIMARY); Label information = new Label("Are you sure you want to trash this item?"); information.addStyleName(ValoTheme.LABEL_NO_MARGIN); okButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1778157399909757369L; @Override public void buttonClick(ClickEvent okEvent) { purgeBooking((BookingBean) event.getItemId()); booking.setSelectedTab(myUpcomingBookings()); cd.close(); showNotification("The booking was deleted!", "You wanted to delete an upcoming booking and it wasn't within the next 24 hours. All good, item purged."); } }); cancelButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = -8957620319158438769L; @Override public void buttonClick(ClickEvent okEvent) { cd.close(); } }); dialogLayout.addComponent(information, 0, 0, 2, 0); dialogLayout.addComponent(okButton, 0, 1); dialogLayout.addComponent(cancelButton, 1, 1); dialogLayout.setMargin(true); dialogLayout.setSpacing(true); cd.setContent(dialogLayout); cd.center(); UI.getCurrent().addWindow(cd); } catch (Exception e) { e.printStackTrace(); } } })); // TODO filtering // HeaderRow filterRow = devicesGrid.prependHeaderRow(); return devicesLayout; }
From source file:facs.components.Settings.java
License:Open Source License
private void addNewDevice() { final Window subWindow = new Window("Add Device"); FormLayout form = new FormLayout(); form.setMargin(true);/*from www. ja v a 2 s . com*/ final TextField name = new TextField(); name.setImmediate(true); name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true)); name.setCaption("Name of new device"); form.addComponent(name); final TextArea description = new TextArea(); description.setImmediate(true); description.addValidator( new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true)); description.setCaption("Description"); form.addComponent(description); final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?"); restricted.addItem("yes"); restricted.setMultiSelect(true); form.addComponent(restricted); HorizontalLayout buttons = new HorizontalLayout(); Button save = new Button("save"); buttons.addComponent(save); Button discard = new Button("discard"); discard.setDescription("discarding will abort the process of adding a new device into the databse."); buttons.addComponent(discard); buttons.setSpacing(true); form.addComponent(buttons); subWindow.setContent(form); form.setMargin(true); form.setSpacing(true); buttons.setMargin(true); buttons.setSpacing(true); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setWidth("50%"); // Open it in the UI UI.getCurrent().addWindow(subWindow); discard.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -5808910314649620731L; @Override public void buttonClick(ClickEvent event) { subWindow.close(); } }); save.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 3748395242651585005L; @Override public void buttonClick(ClickEvent event) { if (name.isValid() && description.isValid()) { Set<String> restr = (Set<String>) restricted.getValue(); int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(), description.getValue(), (restr.size() == 1)); DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(), (restr.size() == 1)); devicesGrid.addRow(bean); } else { Notification.show("Failed to add device to database."); } } }); // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false); // TODO // add to database /* * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); } */ }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre una vista. La colocar en el lado derecho * * @param ui/* www . j a va 2s.c om*/ * @param view */ public static void addView(MyUI ui, AbstractView view) { if (view == null) { System.out.println("abriendo vista null"); ui.getViewDisplay().removeAllComponents(); } else { System.out.println("abriendo vista " + view.getClass().getName() + "::" + view.getViewId()); ViewLayout v = new ViewLayout(view); if (view instanceof AbstractDialog) { AbstractDialog d = (AbstractDialog) view; // Create a sub-window and set the content Window subWindow = new Window(((AbstractDialog) view).getTitle()); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok; if (d instanceof AbstractAddRecordDialog) { ok = new Button("Add record", e -> { List<String> errors = v.getView().getForm().validate(); if (errors.size() > 0) { io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors); } else { //if (d.isCloseOnOk()) subWindow.close(); ((AbstractAddRecordDialog) view).addAndClean(v.getView().getForm().getData()); } }); } else { ok = new Button(d.getOkText(), e -> { List<String> errors = v.getView().getForm().validate(); if (errors.size() > 0) { io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors); } else { if (d.isCloseOnOk()) subWindow.close(); ((AbstractDialog) view).onOk(v.getView().getForm().getData()); } }); } ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); footer.addComponents(footerText); for (AbstractAction a : d.getActions()) { Button b = new Button(a.getName(), e -> { a.run(); }); //b.addStyleName(ValoTheme.BUTTON_); //b.setClickShortcut(ShortcutAction.KeyCode.ENTER); if ("previous".equalsIgnoreCase(a.getName())) { b.setIcon(VaadinIcons.ANGLE_LEFT); } else if ("next".equalsIgnoreCase(a.getName())) { b.setIcon(VaadinIcons.ANGLE_RIGHT); } footer.addComponent(b); } if (d instanceof AbstractListEditorDialog) { AbstractListEditorDialog lv = (AbstractListEditorDialog) d; Property<Integer> pos = new SimpleObjectProperty<>(); pos.setValue(lv.getInitialPos()); Button prev = new Button("Previous", e -> { List<String> errors = v.getView().getForm().validate(); if (errors.size() > 0) { io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors); } else { if (pos.getValue() > 0) { lv.setData(pos.getValue(), view.getForm().getData()); pos.setValue(pos.getValue() - 1); view.getForm().setData(lv.getData(pos.getValue())); } } }); prev.setIcon(VaadinIcons.ANGLE_LEFT); footer.addComponent(prev); Button next = new Button("Next", e -> { List<String> errors = v.getView().getForm().validate(); if (errors.size() > 0) { io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors); } else { if (pos.getValue() < lv.getListSize() - 1) { lv.setData(pos.getValue(), view.getForm().getData()); pos.setValue(pos.getValue() + 1); view.getForm().setData(lv.getData(pos.getValue())); } } }); next.setIcon(VaadinIcons.ANGLE_RIGHT); footer.addComponent(next); pos.addListener(new ChangeListener<Integer>() { @Override public void changed(ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) { if (newValue <= 0) { prev.setEnabled(false); } else { prev.setEnabled(true); } if (newValue < lv.getListSize() - 1) { next.setEnabled(true); } else { next.setEnabled(false); } } }); } footer.addComponents(ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI ui.addWindow(subWindow); } else { System.out.println("aadiendo vista al contenedor de vistas"); ui.getViewDisplay().removeAllComponents(); ui.getViewDisplay().addComponent(v); ui.refreshMenu(v.getArea(), v.getMenu()); } } }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * are el dilogo para autenticarse/*from w ww . j a v a 2 s . c om*/ */ private void openLoginDialog(boolean gohome) { // Create a sub-window and set the content Window subWindow = new Window("Login"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Username")); PasswordField p; f.addComponent(p = new PasswordField("Password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button forgot = new Button("Forgot password", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Asking for email..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("Email sent. Please check your inbox"); } }); } }); //forgot.addStyleName(ValoTheme.BUTTON_); Button ok = new Button("Login", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(), new AsyncCallback<UserData>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(UserData result) { e.setValue("OK!"); getApp().setUserData(result); VaadinSession.getCurrent().setAttribute("usuario", "admin"); subWindow.close(); if (MateuUI.getApp().isFavouritesAvailable()) linkFavoritos.setVisible(true); if (MateuUI.getApp().isLastEditedAvailable()) linkUltimosRegistros.setVisible(true); if (MateuUI.getApp().isFavouritesAvailable()) linkNuevoFavorito.setVisible(true); refreshSettings(); refreshMenu(null, null); System.out.println("STATE:" + navigator.getState()); System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment()); navigator.navigateTo((gohome) ? "" : navigator.getState()); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, forgot, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar el password * *///from ww w . ja v a 2 s . c om private void changePassword() { // Create a sub-window and set the content Window subWindow = new Window("Change password"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); PasswordField l; f.addComponent(l = new PasswordField("Current password")); PasswordField p; f.addComponent(p = new PasswordField("New password")); PasswordField p2; f.addComponent(p2 = new PasswordField("Repeat password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { if (l.getValue() == null || "".equals(l.getValue().trim())) e.setValue("Old password is required"); else if (p.getValue() == null || "".equals(p.getValue().trim())) e.setValue("New password is required"); else if (p2.getValue() == null || "".equals(p2.getValue().trim())) e.setValue("New password repeated is required"); else if (!p.getValue().equals(p2.getValue())) e.setValue("New password and new password repeated must be equal"); else { e.setValue("Changing password..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().changePassword( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); subWindow.close(); } }); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para editar el perfil//from w w w. j a v a 2 s. c om * */ private void editProfile() { // Create a sub-window and set the content Window subWindow = new Window("My profile"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Name")); l.setValue(getApp().getUserData().getName()); TextField p; f.addComponent(p = new TextField("Email")); p.setValue(getApp().getUserData().getEmail()); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Update it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().updateProfile( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), null, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setName(l.getValue()); getApp().getUserData().setEmail(p.getValue()); subWindow.close(); refreshSettings(); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar la foto//from w w w .j av a 2 s . com * * */ private void uploadFoto() { // Create a sub-window and set the content Window subWindow = new Window("My photo"); subWindow.setWidth("475px"); FormLayout f = new FormLayout(); f.setMargin(true); Label e = new Label(); Image image = new Image(); class MyUploader implements Upload.Receiver, Upload.SucceededListener { File file; public File getFile() { return file; } public OutputStream receiveUpload(String fileName, String mimeType) { // Create and return a file output stream System.out.println("receiveUpload(" + fileName + "," + mimeType + ")"); FileOutputStream os = null; if (fileName != null && !"".equals(fileName)) { long id = fileId++; String extension = ".tmp"; if (fileName == null || "".equals(fileName.trim())) fileName = "" + id + extension; if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")); } File temp = null; try { temp = File.createTempFile(fileName, extension); os = new FileOutputStream(file = temp); } catch (IOException e) { e.printStackTrace(); } } return os; } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer image.setSource(new FileResource(file)); System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")"); } public FileLocator getFileLocator() throws IOException { String extension = ".tmp"; String fileName = file.getName(); if (file.getName() == null || "".equals(file.getName().trim())) fileName = "" + getId(); if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_"); } java.io.File temp = (System.getProperty("tmpdir") == null) ? java.io.File.createTempFile(fileName, extension) : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension); System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.out.println("Temp file : " + temp.getAbsolutePath()); if (System.getProperty("tmpdir") == null || !temp.exists()) { System.out.println("writing temp file to " + temp.getAbsolutePath()); Files.copy(file, temp); } else { System.out.println("temp file already exists"); } String baseUrl = System.getProperty("tmpurl"); URL url = null; try { if (baseUrl == null) { url = file.toURI().toURL(); } else url = new URL(baseUrl + "/" + file.getName()); } catch (MalformedURLException e) { e.printStackTrace(); } return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath()); } } ; MyUploader receiver = new MyUploader(); Upload upload = new Upload(null, receiver); //upload.setImmediateMode(false); upload.addSucceededListener(receiver); f.addComponent(image); f.addComponent(upload); f.addComponent(e); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Changing photo..."); try { FileLocator loc = receiver.getFileLocator(); io.mateu.ui.core.client.app.MateuUI.getBaseService() .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setPhoto(loc.getUrl()); foto = (getApp().getUserData().getPhoto() != null) ? new ExternalResource(getApp().getUserData().getPhoto()) : new ClassResource("profile-pic-300px.jpg"); subWindow.close(); refreshSettings(); } }); } catch (IOException e1) { e1.printStackTrace(); io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage()); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); upload.focus(); }
From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.CoordMobileAuthView.java
License:Open Source License
public CoordMobileAuthView(String CoordID) { CtCoordinator ctCoordinator = (CtCoordinator) sys .getCtCoordinator(new DtCoordinatorID(new PtString(CoordID))); ActCoordinator actCoordinator = sys.getActCoordinator(ctCoordinator); actCoordinator.setActorUI(UI.getCurrent()); env.setActCoordinator(actCoordinator.getName(), actCoordinator); IcrashSystem.assCtAuthenticatedActAuthenticated.replace(ctCoordinator, actCoordinator); IcrashSystem.assCtCoordinatorActCoordinator.replace(ctCoordinator, actCoordinator); thisCoordID = CoordID;/*from w w w. j a va 2 s . com*/ setResponsive(true); setWidth("100%"); NavigationBar alertsBar = new NavigationBar(); VerticalComponentGroup alertsContent = new VerticalComponentGroup(); alertsContent.setWidth("100%"); alertsContent.setResponsive(true); HorizontalLayout alertButtons1 = new HorizontalLayout(); HorizontalLayout alertButtons2 = new HorizontalLayout(); //alertButtons.setMargin(true); //alertButtons.setSpacing(true); alertsBar.setCaption("Coordinator " + ctCoordinator.login.toString()); // NavigationButton logoutBtn1 = new NavigationButton("Logout"); Button logoutBtn1 = new Button("Logout"); alertsBar.setRightComponent(logoutBtn1); alertsTable = new Grid(); alertsTable.setContainerDataSource(actCoordinator.getAlertsContainer()); alertsTable.setColumnOrder("ID", "date", "time", "longitude", "latitude", "comment", "status"); alertsTable.setSelectionMode(SelectionMode.SINGLE); alertsTable.setWidth("100%"); alertsTable.setResponsive(true); //alertsTable.setSizeUndefined(); alertsTable.setImmediate(true); Grid inputEventsTable1 = new Grid(); inputEventsTable1.setContainerDataSource(actCoordinator.getMessagesDataSource()); inputEventsTable1.setWidth("100%"); inputEventsTable1.setResponsive(true); alertsContent.addComponents(alertsBar, alertButtons1, alertButtons2, alertsTable, inputEventsTable1); Tab alertsTab = this.addTab(alertsContent); alertsTab.setCaption("Alerts"); alertStatus = new NativeSelect(); alertStatus.setNullSelectionAllowed(false); alertStatus.addItems("Pending", "Valid", "Invalid"); alertStatus.setImmediate(true); alertStatus.select("Pending"); Button validateAlertBtn = new Button("Validate"); Button invalidateAlertBtn = new Button("Invalidate"); Button getAlertsSetBtn = new Button("Get alerts set"); validateAlertBtn.setImmediate(true); invalidateAlertBtn.setImmediate(true); validateAlertBtn.addClickListener(event -> { AlertBean selectedAlertBean = (AlertBean) alertsTable.getSelectedRow(); Integer thisAlertID = new Integer(selectedAlertBean.getID()); PtBoolean res; res = sys.oeValidateAlert(new DtAlertID(new PtString(thisAlertID.toString()))); }); invalidateAlertBtn.addClickListener(event -> { AlertBean selectedAlertBean = (AlertBean) alertsTable.getSelectedRow(); Integer thisAlertID = new Integer(selectedAlertBean.getID()); PtBoolean res; res = sys.oeInvalidateAlert(new DtAlertID(new PtString(thisAlertID.toString()))); }); getAlertsSetBtn.addClickListener(event -> { if (alertStatus.getValue().toString().equals("Pending")) actCoordinator.oeGetAlertsSet(EtAlertStatus.pending); else if (alertStatus.getValue().toString().equals("Valid")) actCoordinator.oeGetAlertsSet(EtAlertStatus.valid); else if (alertStatus.getValue().toString().equals("Invalid")) actCoordinator.oeGetAlertsSet(EtAlertStatus.invalid); }); alertButtons1.addComponents(validateAlertBtn, invalidateAlertBtn); alertButtons2.addComponents(getAlertsSetBtn, alertStatus); ////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// NavigationBar crisesBar = new NavigationBar(); VerticalComponentGroup crisesContent = new VerticalComponentGroup(); crisesContent.setWidth("100%"); crisesContent.setResponsive(true); HorizontalLayout crisesButtons1 = new HorizontalLayout(); HorizontalLayout crisesButtons2 = new HorizontalLayout(); crisesBar.setCaption("Coordinator " + ctCoordinator.login.toString()); //NavigationButton logoutBtn2 = new NavigationButton("Logout"); Button logoutBtn2 = new Button("Logout"); crisesBar.setRightComponent(logoutBtn2); crisesTable = new Grid(); crisesTable.setContainerDataSource(actCoordinator.getCrisesContainer()); crisesTable.setColumnOrder("ID", "date", "time", "type", "longitude", "latitude", "comment", "status"); crisesTable.setSelectionMode(SelectionMode.SINGLE); crisesTable.setWidth("100%"); //crisesTable.setSizeUndefined(); crisesTable.setImmediate(true); crisesTable.setResponsive(true); Grid inputEventsTable2 = new Grid(); inputEventsTable2.setContainerDataSource(actCoordinator.getMessagesDataSource()); inputEventsTable2.setWidth("100%"); inputEventsTable2.setResponsive(true); crisesContent.addComponents(crisesBar, crisesButtons1, crisesButtons2, crisesTable, inputEventsTable2); Tab crisesTab = this.addTab(crisesContent); crisesTab.setCaption("Crises"); Button handleCrisesBtn = new Button("Handle"); Button reportOnCrisisBtn = new Button("Report"); Button changeCrisisStatusBtn = new Button("Status"); Button closeCrisisBtn = new Button("Close"); Button getCrisesSetBtn = new Button("Get crises set"); crisesStatus = new NativeSelect(); handleCrisesBtn.setImmediate(true); reportOnCrisisBtn.setImmediate(true); changeCrisisStatusBtn.setImmediate(true); closeCrisisBtn.setImmediate(true); getCrisesSetBtn.setImmediate(true); crisesStatus.setImmediate(true); crisesStatus.addItems("Pending", "Handled", "Solved", "Closed"); crisesStatus.setNullSelectionAllowed(false); crisesStatus.select("Pending"); crisesButtons1.addComponents(handleCrisesBtn, reportOnCrisisBtn, changeCrisisStatusBtn); crisesButtons2.addComponents(closeCrisisBtn, getCrisesSetBtn, crisesStatus); //////////////////////////////////////// Window reportCrisisSubWindow = new Window(); reportCrisisSubWindow.setClosable(false); reportCrisisSubWindow.setResizable(false); reportCrisisSubWindow.setResponsive(true); VerticalLayout reportLayout = new VerticalLayout(); reportLayout.setMargin(true); reportLayout.setSpacing(true); reportCrisisSubWindow.setContent(reportLayout); TextField crisisID = new TextField(); TextField reportText = new TextField(); HorizontalLayout buttonsLayout = new HorizontalLayout(); Button reportCrisisBtn = new Button("Report"); reportCrisisBtn.setClickShortcut(KeyCode.ENTER); reportCrisisBtn.addStyleName(ValoTheme.BUTTON_PRIMARY); Button cancelBtn = new Button("Cancel"); buttonsLayout.addComponents(reportCrisisBtn, cancelBtn); buttonsLayout.setSpacing(true); reportLayout.addComponents(crisisID, reportText, buttonsLayout); cancelBtn.addClickListener(event -> { reportCrisisSubWindow.close(); reportText.clear(); }); reportCrisisBtn.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); actCoordinator.oeReportOnCrisis(new DtCrisisID(new PtString(thisCrisisID.toString())), new DtComment(new PtString(reportText.getValue()))); reportCrisisSubWindow.close(); reportText.clear(); }); //////////////////////////////////////// Window changeCrisisStatusSubWindow = new Window(); changeCrisisStatusSubWindow.setClosable(false); changeCrisisStatusSubWindow.setResizable(false); changeCrisisStatusSubWindow.setResponsive(true); VerticalLayout statusLayout = new VerticalLayout(); statusLayout.setMargin(true); statusLayout.setSpacing(true); changeCrisisStatusSubWindow.setContent(statusLayout); TextField crisisID1 = new TextField(); NativeSelect crisisStatus = new NativeSelect("crisis status"); crisisStatus.addItems("Pending", "Handled", "Solved", "Closed"); crisisStatus.setNullSelectionAllowed(false); crisisStatus.select("Pending"); HorizontalLayout buttonsLayout1 = new HorizontalLayout(); Button changeCrisisStatusBtn1 = new Button("Change status"); changeCrisisStatusBtn1.setClickShortcut(KeyCode.ENTER); changeCrisisStatusBtn1.addStyleName(ValoTheme.BUTTON_PRIMARY); Button cancelBtn1 = new Button("Cancel"); buttonsLayout1.addComponents(changeCrisisStatusBtn1, cancelBtn1); buttonsLayout1.setSpacing(true); statusLayout.addComponents(crisisID1, crisisStatus, buttonsLayout1); cancelBtn1.addClickListener(event -> changeCrisisStatusSubWindow.close()); changeCrisisStatusBtn1.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); EtCrisisStatus statusToPut = null; if (crisisStatus.getValue().toString().equals("Pending")) statusToPut = EtCrisisStatus.pending; if (crisisStatus.getValue().toString().equals("Handled")) statusToPut = EtCrisisStatus.handled; if (crisisStatus.getValue().toString().equals("Solved")) statusToPut = EtCrisisStatus.solved; if (crisisStatus.getValue().toString().equals("Closed")) statusToPut = EtCrisisStatus.closed; PtBoolean res = actCoordinator.oeSetCrisisStatus(new DtCrisisID(new PtString(thisCrisisID.toString())), statusToPut); changeCrisisStatusSubWindow.close(); }); //////////////////////////////////////// handleCrisesBtn.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); PtBoolean res = actCoordinator .oeSetCrisisHandler(new DtCrisisID(new PtString(thisCrisisID.toString()))); }); reportOnCrisisBtn.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); reportCrisisSubWindow.center(); crisisID.setValue(thisCrisisID.toString()); crisisID.setEnabled(false); reportText.focus(); UI.getCurrent().addWindow(reportCrisisSubWindow); }); changeCrisisStatusBtn.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); changeCrisisStatusSubWindow.center(); crisisID1.setValue(thisCrisisID.toString()); crisisID1.setEnabled(false); crisisStatus.focus(); UI.getCurrent().addWindow(changeCrisisStatusSubWindow); }); closeCrisisBtn.addClickListener(event -> { CrisisBean selectedCrisisBean = (CrisisBean) crisesTable.getSelectedRow(); Integer thisCrisisID = new Integer(selectedCrisisBean.getID()); PtBoolean res = actCoordinator.oeCloseCrisis(new DtCrisisID(new PtString(thisCrisisID.toString()))); }); getCrisesSetBtn.addClickListener(event -> { if (crisesStatus.getValue().toString().equals("Closed")) actCoordinator.oeGetCrisisSet(EtCrisisStatus.closed); if (crisesStatus.getValue().toString().equals("Handled")) actCoordinator.oeGetCrisisSet(EtCrisisStatus.handled); if (crisesStatus.getValue().toString().equals("Solved")) actCoordinator.oeGetCrisisSet(EtCrisisStatus.solved); if (crisesStatus.getValue().toString().equals("Pending")) actCoordinator.oeGetCrisisSet(EtCrisisStatus.pending); }); ClickListener logoutAction = event -> { PtBoolean res; try { res = actCoordinator.oeLogout(); if (res.getValue()) { } } catch (Exception e) { e.printStackTrace(); } Page.getCurrent().reload(); }; logoutBtn1.addClickListener(logoutAction); logoutBtn2.addClickListener(logoutAction); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java
License:Apache License
private void createRequirementSpecNodeMenu(ContextMenu menu) { MenuItem create = menu.addItem(TRANSLATOR.translate("create.requiremnet"), VaadinIcons.PLUS, (MenuItem selectedItem) -> { Requirement r = new Requirement(); r.setRequirementSpecNode((RequirementSpecNode) tree.getValue()); displayRequirement(r, true); });/*from w w w . java 2 s . co m*/ create.setEnabled(checkRight("requirement.modify")); MenuItem edit = menu.addItem(TRANSLATOR.translate("edit.req.spec.node"), EDIT_ICON, (MenuItem selectedItem) -> { displayRequirementSpecNode((RequirementSpecNode) tree.getValue(), true); }); edit.setEnabled(checkRight("requirement.modify")); MenuItem importRequirement = menu.addItem(TRANSLATOR.translate("import.requirement"), IMPORT_ICON, (MenuItem selectedItem) -> {// Create a sub-window and set the content Window subWindow = new VMWindow(TRANSLATOR.translate("import.requirement")); VerticalLayout subContent = new VerticalLayout(); subWindow.setContent(subContent); //Add a checkbox to know if file has headers or not CheckBox cb = new CheckBox(TRANSLATOR.translate("file.has.header")); FileUploader receiver = new FileUploader(); Upload upload = new Upload(TRANSLATOR.translate("upload.excel"), receiver); upload.addSucceededListener((Upload.SucceededEvent event1) -> { try { subWindow.close(); //TODO: Display the excel file (partially), map columns and import //Process the file RequirementImporter importer = new RequirementImporter(receiver.getFile(), (RequirementSpecNode) tree.getValue()); importer.importFile(cb.getValue()); importer.processImport(); buildProjectTree(tree.getValue()); updateScreen(); } catch (RequirementImportException ex) { LOG.log(Level.SEVERE, TRANSLATOR.translate("import.error"), ex); Notification.show(TRANSLATOR.translate("import.unsuccessful"), Notification.Type.ERROR_MESSAGE); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } }); upload.addFailedListener((Upload.FailedEvent event1) -> { LOG.log(Level.SEVERE, "Upload unsuccessful!\n{0}", event1.getReason()); Notification.show(TRANSLATOR.translate("upload.unsuccessful"), Notification.Type.ERROR_MESSAGE); subWindow.close(); }); subContent.addComponent(cb); subContent.addComponent(upload); // Open it in the UI addWindow(subWindow); }); importRequirement.setEnabled(checkRight("requirement.modify")); }