Search in sources :

Example 1 with UI

use of com.vaadin.ui.UI in project opennms by OpenNMS.

the class SSHWindowTest method setup.

@SuppressWarnings("serial")
@Before
public void setup() {
    app = new UI() {

        @Override
        public void init(VaadinRequest request) {
        }
    };
    sshWindow = new SSHWindow(null, 200, 200);
    client = SshClient.setUpDefaultClient();
    client.start();
    try {
        session = client.connect(testHost, testPort).await().getSession();
    } catch (Exception e) {
        fail("Could not connect to host");
    }
    sshWindow2 = new SSHWindow(session, 200, 200);
    app.addWindow(sshWindow);
    app.addWindow(sshWindow2);
}
Also used : UI(com.vaadin.ui.UI) VaadinRequest(com.vaadin.server.VaadinRequest) Before(org.junit.Before)

Example 2 with UI

use of com.vaadin.ui.UI in project opennms by OpenNMS.

the class SSHTerminalTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
    app = new UI() {

        @Override
        public void init(VaadinRequest request) {
        }
    };
    mainWindow = new VerticalLayout();
    app.setContent(mainWindow);
    SSHWindow sshWindow = new SSHWindow(null, 200, 200);
    app.addWindow(sshWindow);
    SshClient client = SshClient.setUpDefaultClient();
    client.start();
    ClientSession session = null;
    try {
        session = client.connect(testHost, testPort).await().getSession();
    } catch (Exception e) {
        fail("Could not connect to host");
    }
    sshTerm = new SSHTerminal(sshWindow, session, 200, 200);
    sshWindow.setContent(sshTerm);
    UI.setCurrent(app);
}
Also used : UI(com.vaadin.ui.UI) SshClient(org.apache.sshd.SshClient) ClientSession(org.apache.sshd.ClientSession) VerticalLayout(com.vaadin.ui.VerticalLayout) VaadinRequest(com.vaadin.server.VaadinRequest) Before(org.junit.Before)

Example 3 with UI

use of com.vaadin.ui.UI in project VaadinUtils by rlsutton1.

the class BaseCrudView method initButtons.

private void initButtons() {
    actionNewButton.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            if (isDirty()) {
                Notification.show("You must Save or Discard your changes first", Type.ERROR_MESSAGE);
                return;
            }
            newClicked();
        }
    });
    actionApplyButton.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            final Object entityId = entityTable.getValue();
            if (entityId != null) {
                @SuppressWarnings("unchecked") CrudAction<E> action = (CrudAction<E>) actionCombo.getValue();
                if (action != null) {
                    if (action.showPreparingDialog()) {
                        performActionWithWaitDialog(entityId, action);
                    } else {
                        performAction(entityId, action);
                    }
                } else {
                    Notification.show("Please select an Action first.");
                }
            } else {
                Notification.show("Please select record first.");
            }
        }

        private void performAction(final Object entityId, final CrudAction<E> action) {
            EntityItem<E> entity = container.getItem(entityId);
            if (interceptAction(action, entity)) {
                action.exec(BaseCrudView.this, entity);
            }
            container.commit();
            container.refreshItem(entity.getItemId());
        // actionCombo.select(actionCombo.getNullSelectionItemId());
        }

        private void performActionWithWaitDialog(final Object entityId, final CrudAction<E> action) {
            final ConfirmDialog pleaseWaitMessage = createPleaseWaitDialog();
            if (action != null) {
                // we have to delay, because if we try to close the window
                // before it's created - that won't work.
                final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
                final EntityManagerRunnable runner = invokeAction(entityId, pleaseWaitMessage, action);
                exec.schedule(runner, 1, TimeUnit.SECONDS);
                exec.shutdown();
                UI.getCurrent().setPollInterval(500);
            }
        }

        private EntityManagerRunnable invokeAction(final Object entityId, final ConfirmDialog pleaseWaitMessage, final CrudAction<E> action) {
            final EntityManagerRunnable runner = new EntityManagerRunnable(new RunnableUI(UI.getCurrent()) {

                @Override
                protected void run(final UI ui) {
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                EntityItem<E> entity = container.getItem(entityId);
                                if (interceptAction(action, entity)) {
                                    action.exec(BaseCrudView.this, entity);
                                }
                                container.commit();
                                container.refreshItem(entity.getItemId());
                            // actionCombo.select(actionCombo.getNullSelectionItemId());
                            } finally {
                                pleaseWaitMessage.close();
                                ui.setPollInterval(-1);
                            }
                        }
                    });
                }
            });
            return runner;
        }

        private ConfirmDialog createPleaseWaitDialog() {
            final ConfirmDialog pleaseWaitMessage = ConfirmDialog.show(UI.getCurrent(), "Please wait...", new ConfirmDialog.Listener() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClose(ConfirmDialog dialog) {
                }
            });
            pleaseWaitMessage.setClosable(false);
            pleaseWaitMessage.getCancelButton().setVisible(false);
            pleaseWaitMessage.getOkButton().setVisible(false);
            pleaseWaitMessage.setModal(true);
            pleaseWaitMessage.setCaption("Preparing Action");
            return pleaseWaitMessage;
        }
    });
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ClickListener(com.vaadin.ui.Button.ClickListener) ItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) TextChangeListener(com.vaadin.event.FieldEvents.TextChangeListener) ClickEventLogged(au.com.vaadinutils.listener.ClickEventLogged) ClickEvent(com.vaadin.ui.Button.ClickEvent) RunnableUI(au.com.vaadinutils.dao.RunnableUI) UI(com.vaadin.ui.UI) RunnableUI(au.com.vaadinutils.dao.RunnableUI) EntityManagerRunnable(au.com.vaadinutils.dao.EntityManagerRunnable) EntityManagerRunnable(au.com.vaadinutils.dao.EntityManagerRunnable) EntityItem(com.vaadin.addon.jpacontainer.EntityItem) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 4 with UI

use of com.vaadin.ui.UI in project VaadinUtils by rlsutton1.

the class SendEmailTask method sendMessages.

private void sendMessages(final List<JasperTransmission> targets, final JasperProxy proxy) {
    new EntityManagerThread<Void>(new CallableUI<Void>(UI.getCurrent()) {

        @Override
        protected Void call(UI ui) throws Exception {
            int sent = 0;
            try {
                for (JasperTransmission transmission : targets) {
                    if (cancel == true)
                        break;
                    try {
                        JasperManager manager = proxy.getManager();
                        RenderedReport renderedHtml = manager.export(OutputFormat.HTML, null);
                        RenderedReport renderedPDF = manager.export(OutputFormat.PDF, null);
                        JasperEmailBuilder builder = new JasperEmailBuilder(proxy.getEmailSettings());
                        builder.setFrom(proxy.getSenderEmailAddress()).setSubject(proxy.getSubject()).setHtmlBody(renderedHtml).addTo(transmission.getRecipientEmailAddress()).addAttachement(renderedPDF.getBodyAsDataSource("report.pdf", AttachmentType.PDF));
                        builder.send(false);
                    } catch (EmailException e) {
                        logger.error(e, e);
                        transmission.setException(e);
                        SendEmailTask.super.taskItemError(transmission);
                        VUNotification.show(e, Type.ERROR_MESSAGE);
                    }
                }
            } catch (Exception e) {
                VUNotification.show(e, Type.ERROR_MESSAGE);
                throw e;
            } finally {
                SendEmailTask.super.taskComplete(sent);
            }
            return null;
        }
    });
}
Also used : EntityManagerThread(au.com.vaadinutils.dao.EntityManagerThread) UI(com.vaadin.ui.UI) CallableUI(au.com.vaadinutils.dao.CallableUI) JasperManager(au.com.vaadinutils.jasper.JasperManager) RenderedReport(au.com.vaadinutils.jasper.RenderedReport) EmailException(org.apache.commons.mail.EmailException) JasperEmailBuilder(au.com.vaadinutils.jasper.JasperEmailBuilder) EmailException(org.apache.commons.mail.EmailException)

Example 5 with UI

use of com.vaadin.ui.UI in project VaadinUtils by rlsutton1.

the class ReportParameterTable method addSelectionListener.

@Override
public void addSelectionListener(final ValueChangeListener listener) {
    UI ui = UI.getCurrent();
    if (ui != null) {
        Runnable runner = new Runnable() {

            @Override
            public void run() {
                grid.addSelectionListener(new SelectionListener() {

                    /**
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void select(SelectionEvent event) {
                        listener.valueChange(new ValueChangeEvent() {

                            /**
                             */
                            private static final long serialVersionUID = 1L;

                            @Override
                            public Property<Collection<Long>> getProperty() {
                                return new Property<Collection<Long>>() {

                                    /**
                                     */
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    public Collection<Long> getValue() {
                                        return getSelectedIds();
                                    }

                                    @Override
                                    public void setValue(Collection<Long> newValue) throws com.vaadin.data.Property.ReadOnlyException {
                                    }

                                    @Override
                                    public Class<? extends Collection<Long>> getType() {
                                        return null;
                                    }

                                    @Override
                                    public boolean isReadOnly() {
                                        return false;
                                    }

                                    @Override
                                    public void setReadOnly(boolean newStatus) {
                                    }
                                };
                            }
                        });
                    }
                });
            }
        };
        UI.getCurrent().accessSynchronously(runner);
    } else {
        logger.warn("No vaadin session available, not setting up UI");
    }
}
Also used : ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) UI(com.vaadin.ui.UI) SelectionEvent(com.vaadin.event.SelectionEvent) Collection(java.util.Collection) Property(com.vaadin.data.Property) SelectionListener(com.vaadin.event.SelectionEvent.SelectionListener)

Aggregations

UI (com.vaadin.ui.UI)33 AnnisBaseUI (annis.libgui.AnnisBaseUI)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 WebResource (com.sun.jersey.api.client.WebResource)3 VaadinRequest (com.vaadin.server.VaadinRequest)3 Label (com.vaadin.ui.Label)3 IOException (java.io.IOException)3 VertexRef (org.opennms.features.topology.api.topo.VertexRef)3 AnnisUI (annis.gui.AnnisUI)2 Property (com.vaadin.data.Property)2 TextChangeListener (com.vaadin.event.FieldEvents.TextChangeListener)2 SelectionEvent (com.vaadin.event.SelectionEvent)2 SelectionListener (com.vaadin.event.SelectionEvent.SelectionListener)2 Component (com.vaadin.ui.Component)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2