Search in sources :

Example 86 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class WebComponentsHelper method focusProblemComponent.

public static void focusProblemComponent(ValidationErrors errors) {
    com.haulmont.cuba.gui.components.Component component = null;
    if (!errors.getAll().isEmpty()) {
        component = errors.getAll().get(0).component;
    }
    if (component != null) {
        try {
            com.vaadin.ui.Component vComponent = WebComponentsHelper.unwrap(component);
            com.vaadin.ui.Component c = vComponent;
            com.vaadin.ui.Component prevC = null;
            while (c != null) {
                if (c instanceof com.vaadin.ui.TabSheet && !((com.vaadin.ui.TabSheet) c).getSelectedTab().equals(prevC)) {
                    ((com.vaadin.ui.TabSheet) c).setSelectedTab(prevC);
                    break;
                }
                if (c instanceof CubaGroupBox && !((CubaGroupBox) c).isExpanded()) {
                    ((CubaGroupBox) c).setExpanded(true);
                    break;
                }
                prevC = c;
                c = c.getParent();
            }
            // focus first up component
            c = vComponent;
            while (c != null) {
                if (c instanceof com.vaadin.ui.Component.Focusable) {
                    ((com.vaadin.ui.Component.Focusable) c).focus();
                    break;
                }
                c = c.getParent();
            }
        } catch (Exception e) {
            LoggerFactory.getLogger(WebComponentsHelper.class).warn("Error while validation handling ", e);
        }
    }
}
Also used : com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) com.vaadin.ui(com.vaadin.ui) TabSheet(com.vaadin.ui.TabSheet) TabSheet(com.vaadin.ui.TabSheet) Component(com.vaadin.ui.Component)

Example 87 with Component

use of com.vaadin.ui.Component in project vaadin-app-layout by appreciated.

the class MaterialNotificationWindow method getNotificationLayout.

VerticalLayout getNotificationLayout(NotificationHolder notifications) {
    List<Component> components = notifications.getNotifications(isShowAll());
    notificationsView = new VerticalLayout(components.toArray(new Component[] {}));
    notificationsView.addStyleName(Styles.APP_BAR_NOTIFICATION_WINDOW);
    notificationsView.addStyleName(Styles.APP_BAR_NOTIFICATION_LIST);
    notificationsView.setMargin(false);
    notificationsView.setSpacing(true);
    return notificationsView;
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) Component(com.vaadin.ui.Component)

Example 88 with Component

use of com.vaadin.ui.Component in project vaadin-app-layout by appreciated.

the class NotificationHolder method getComponent.

public Component getComponent(T message) {
    Component component = componentProvider.getComponent(this, message);
    component.addStyleName(APP_BAR_NOTIFICATION);
    return component;
}
Also used : Component(com.vaadin.ui.Component)

Example 89 with Component

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

the class ShowNCSPathOperation method execute.

@Override
public void execute(List<VertexRef> targets, final OperationContext operationContext) {
    // Get the current NCS criteria from here you can get the foreignIds foreignSource and deviceA and Z
    for (Criteria criterium : operationContext.getGraphContainer().getCriteria()) {
        try {
            NCSServiceCriteria ncsCriterium = (NCSServiceCriteria) criterium;
            if (ncsCriterium.getServiceCount() > 0) {
                m_storedCriteria = ncsCriterium;
                break;
            }
        } catch (ClassCastException e) {
        }
    }
    final VertexRef defaultVertRef = targets.get(0);
    final SelectionManager selectionManager = operationContext.getGraphContainer().getSelectionManager();
    // selectionManager.getSelectedVertexRefs();
    final Collection<VertexRef> vertexRefs = getVertexRefsForNCSService(m_storedCriteria);
    final UI mainWindow = operationContext.getMainWindow();
    final Window ncsPathPrompt = new Window("Show NCS Path");
    ncsPathPrompt.setModal(true);
    ncsPathPrompt.setResizable(false);
    ncsPathPrompt.setWidth("300px");
    ncsPathPrompt.setHeight("220px");
    // Items used in form field
    final PropertysetItem item = new PropertysetItem();
    item.addItemProperty("Device A", new ObjectProperty<String>("", String.class));
    item.addItemProperty("Device Z", new ObjectProperty<String>("", String.class));
    FormFieldFactory fieldFactory = new FormFieldFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public Field<?> createField(Item item, Object propertyId, Component uiContext) {
            String pid = (String) propertyId;
            ComboBox select = new ComboBox();
            for (VertexRef vertRef : vertexRefs) {
                select.addItem(vertRef.getId());
                select.setItemCaption(vertRef.getId(), vertRef.getLabel());
            }
            select.setNewItemsAllowed(false);
            select.setNullSelectionAllowed(false);
            select.setImmediate(true);
            select.setScrollToSelectedItem(true);
            if ("Device A".equals(pid)) {
                select.setCaption("Device A");
            } else {
                select.setCaption("Device Z");
            }
            return select;
        }
    };
    final Form promptForm = new Form() {

        @Override
        public void commit() {
            String deviceA = (String) getField("Device A").getValue();
            String deviceZ = (String) getField("Device Z").getValue();
            if (deviceA.equals(deviceZ)) {
                Notification.show("Device A and Device Z cannot be the same", Notification.Type.WARNING_MESSAGE);
                throw new Validator.InvalidValueException("Device A and Device Z cannot be the same");
            }
            OnmsNode nodeA = m_nodeDao.get(Integer.valueOf(deviceA));
            String deviceANodeForeignId = nodeA.getForeignId();
            // Use nodeA's foreignSource, deviceZ should have the same foreignSource. It's an assumption
            // which might need to changed in the future. Didn't want to hard code it it "space" if they
            // change it in the future
            String nodeForeignSource = nodeA.getForeignSource();
            String deviceZNodeForeignId = m_nodeDao.get(Integer.valueOf(deviceZ)).getForeignId();
            NCSComponent ncsComponent = m_dao.get(m_storedCriteria.getServiceIds().get(0));
            String foreignSource = ncsComponent.getForeignSource();
            String foreignId = ncsComponent.getForeignId();
            String serviceName = ncsComponent.getName();
            try {
                NCSServicePath path = getNcsPathProvider().getPath(foreignId, foreignSource, deviceANodeForeignId, deviceZNodeForeignId, nodeForeignSource, serviceName);
                if (path.getStatusCode() == 200) {
                    NCSServicePathCriteria criteria = new NCSServicePathCriteria(path.getEdges());
                    m_serviceManager.registerCriteria(criteria, operationContext.getGraphContainer().getSessionId());
                    // Select only the vertices in the path
                    selectionManager.setSelectedVertexRefs(path.getVertices());
                } else {
                    LoggerFactory.getLogger(this.getClass()).warn("An error occured while retrieving the NCS Path, Juniper NetworkAppsApi send error code: " + path.getStatusCode());
                    mainWindow.showNotification("An error occurred while retrieving the NCS Path\nStatus Code: " + path.getStatusCode(), Notification.TYPE_ERROR_MESSAGE);
                }
            } catch (Exception e) {
                if (e.getCause() instanceof ConnectException) {
                    LoggerFactory.getLogger(this.getClass()).warn("Connection Exception Occurred while retreiving path {}", e);
                    Notification.show("Connection Refused when attempting to reach the NetworkAppsApi", Notification.Type.TRAY_NOTIFICATION);
                } else if (e.getCause() instanceof HttpOperationFailedException) {
                    HttpOperationFailedException httpException = (HttpOperationFailedException) e.getCause();
                    if (httpException.getStatusCode() == 401) {
                        LoggerFactory.getLogger(this.getClass()).warn("Authentication error when connecting to NetworkAppsApi {}", httpException);
                        Notification.show("Authentication error when connecting to NetworkAppsApi, please check the username and password", Notification.Type.TRAY_NOTIFICATION);
                    } else {
                        LoggerFactory.getLogger(this.getClass()).warn("An error occured while retrieving the NCS Path {}", httpException);
                        Notification.show("An error occurred while retrieving the NCS Path\n" + httpException.getMessage(), Notification.Type.TRAY_NOTIFICATION);
                    }
                } else if (e.getCause() instanceof Validator.InvalidValueException) {
                    Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
                } else {
                    LoggerFactory.getLogger(this.getClass()).warn("Exception Occurred while retreiving path {}", e);
                    Notification.show("An error occurred while calculating the path please check the karaf.log file for the exception: \n" + e.getMessage(), Notification.Type.TRAY_NOTIFICATION);
                }
            }
        }
    };
    promptForm.setBuffered(true);
    promptForm.setFormFieldFactory(fieldFactory);
    promptForm.setItemDataSource(item);
    Button ok = new Button("OK");
    ok.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -2742886456007926688L;

        @Override
        public void buttonClick(ClickEvent event) {
            promptForm.commit();
            mainWindow.removeWindow(ncsPathPrompt);
        }
    });
    promptForm.getFooter().addComponent(ok);
    Button cancel = new Button("Cancel");
    cancel.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -9026067481179449095L;

        @Override
        public void buttonClick(ClickEvent event) {
            mainWindow.removeWindow(ncsPathPrompt);
        }
    });
    promptForm.getFooter().addComponent(cancel);
    ncsPathPrompt.setContent(promptForm);
    mainWindow.addWindow(ncsPathPrompt);
    promptForm.getField("Device A").setValue(defaultVertRef.getId());
}
Also used : Form(com.vaadin.ui.Form) ClickEvent(com.vaadin.ui.Button.ClickEvent) PropertysetItem(com.vaadin.data.util.PropertysetItem) NCSServiceCriteria(org.opennms.features.topology.plugins.ncs.NCSEdgeProvider.NCSServiceCriteria) NCSServicePathCriteria(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSServicePathCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) NCSServicePathCriteria(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSServicePathCriteria) FormFieldFactory(com.vaadin.ui.FormFieldFactory) PropertysetItem(com.vaadin.data.util.PropertysetItem) Item(com.vaadin.data.Item) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) UI(com.vaadin.ui.UI) Button(com.vaadin.ui.Button) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) Component(com.vaadin.ui.Component) ClickListener(com.vaadin.ui.Button.ClickListener) ConnectException(java.net.ConnectException) Window(com.vaadin.ui.Window) SelectionManager(org.opennms.features.topology.api.SelectionManager) OnmsNode(org.opennms.netmgt.model.OnmsNode) ComboBox(com.vaadin.ui.ComboBox) NCSServiceCriteria(org.opennms.features.topology.plugins.ncs.NCSEdgeProvider.NCSServiceCriteria) HttpOperationFailedException(org.apache.camel.component.http.HttpOperationFailedException) ConnectException(java.net.ConnectException) HttpOperationFailedException(org.apache.camel.component.http.HttpOperationFailedException) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Validator(com.vaadin.data.Validator)

Example 90 with Component

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

the class AlarmDetailsDashlet method getDashboardComponent.

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {

            private AlarmTable m_alarmTable;

            {
                m_alarmTable = new AlarmTable("Alarms", new AlarmDaoContainer(m_alarmDao, m_transactionTemplate), m_alarmRepository);
                m_alarmTable.setSizeFull();
                m_alarmTable.setSortEnabled(false);
                m_alarmTable.addHeaderClickListener(new Table.HeaderClickListener() {

                    @Override
                    public void headerClick(Table.HeaderClickEvent headerClickEvent) {
                        m_alarmTable.setSortContainerPropertyId(headerClickEvent.getPropertyId());
                        m_alarmTable.setSortEnabled(true);
                    }
                });
                final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
                final UI currentUI = UI.getCurrent();
                context.setSessionId(currentUI.getSession().getSession().getId());
                context.setUiId(currentUI.getUIId());
                m_alarmTable.setVaadinApplicationContext(context);
                final EventProxy eventProxy = new EventProxy() {

                    @Override
                    public <T> void fireEvent(final T eventObject) {
                        System.out.println("got event: {}" + eventObject);
                    }

                    @Override
                    public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
                        System.out.println("(ignoring) add consumer: {}" + possibleEventConsumer);
                    }
                };
                m_alarmTable.setEventProxy(eventProxy);
                m_alarmTable.setColumnReorderingAllowed(true);
                m_alarmTable.setColumnCollapsingAllowed(true);
                m_alarmTable.setSortContainerPropertyId("id");
                m_alarmTable.setSortAscending(false);
                m_alarmTable.setCellStyleGenerator(new AlarmTableCellStyleGenerator());
                m_alarmTable.addGeneratedColumn("severity", new SeverityGenerator());
                m_alarmTable.addGeneratedColumn("id", new AlarmIdColumnLinkGenerator(m_alarmDao, "id"));
                m_alarmTable.setVisibleColumns("id", "severity", "nodeLabel", "counter", "lastEventTime", "logMsg");
                m_alarmTable.setColumnHeaders("ID", "Severity", "Node", "Count", "Last Event Time", "Log Message");
                refresh();
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();
                List<Integer> alarmIds = new LinkedList<>();
                if (alarms.size() > 0) {
                    for (OnmsAlarm onmsAlarm : alarms) {
                        alarmIds.add(onmsAlarm.getId());
                    }
                } else {
                    alarmIds.add(0);
                }
                List<Restriction> restrictions = new LinkedList<>();
                restrictions.add(new InRestriction("id", alarmIds));
                ((OnmsVaadinContainer<?, ?>) m_alarmTable.getContainerDataSource()).setRestrictions(restrictions);
                setBoosted(checkBoosted(alarms));
                m_alarmTable.markAsDirtyRecursive();
            }

            @Override
            public Component getComponent() {
                return m_alarmTable;
            }
        };
    }
    return m_dashboardComponent;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) SeverityGenerator(org.opennms.features.topology.plugins.browsers.SeverityGenerator) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) UI(com.vaadin.ui.UI) AlarmTable(org.opennms.features.topology.plugins.browsers.AlarmTable) AlarmTableCellStyleGenerator(org.opennms.features.topology.plugins.browsers.AlarmTableCellStyleGenerator) AlarmIdColumnLinkGenerator(org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator) LinkedList(java.util.LinkedList) List(java.util.List) DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) Component(com.vaadin.ui.Component) EventProxy(org.opennms.osgi.EventProxy) AlarmDaoContainer(org.opennms.features.topology.plugins.browsers.AlarmDaoContainer)

Aggregations

Component (com.vaadin.ui.Component)146 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)23 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)13 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)11 HorizontalLayout (com.vaadin.ui.HorizontalLayout)11 VerticalLayout (com.vaadin.ui.VerticalLayout)11 Button (com.vaadin.ui.Button)9 Window (com.haulmont.cuba.gui.components.Window)8 Label (com.vaadin.ui.Label)8 Test (org.junit.Test)8 WebWindow (com.haulmont.cuba.web.gui.WebWindow)7 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)6 CssLayout (com.vaadin.ui.CssLayout)6 List (java.util.List)6 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)5 CubaUI (com.haulmont.cuba.web.widgets.CubaUI)5 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 Item (com.vaadin.data.Item)5