Example usage for com.vaadin.ui Window setModal

List of usage examples for com.vaadin.ui Window setModal

Introduction

In this page you can find the example usage for com.vaadin.ui Window setModal.

Prototype

public void setModal(boolean modal) 

Source Link

Document

Sets window modality.

Usage

From source file:org.opencms.workplace.tools.git.ui.CmsGitToolOptionsPanel.java

License:Open Source License

/**
 * Opens a modal window with the given component as content.<p>
 *
 * @param component the window content/*  w  w  w .j  a v a2  s .  co m*/
 *
 * @return the window which is opened
 */
public Window addAsWindow(Component component) {

    // Have to use an array because Vaadin declarative tries to bind the field otherwise
    if (m_currentWindow[0] != null) {
        m_currentWindow[0].close();
        m_currentWindow[0] = null;
    }

    Window window = new Window();
    window.setContent(component);
    window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_GIT_SCRIPT_RESULTS_0));
    window.setWidth("1000px");
    window.setModal(true);
    window.setResizable(false);
    A_CmsUI.get().addWindow(window);

    m_currentWindow[0] = window;
    return window;
}

From source file:org.openeos.services.ui.vaadin.internal.UIApplicationImpl.java

License:Apache License

@Override
public <U> UIDialog showGenericFormDialog(BForm<U> form, U bean) {
    Map<String, Object> extraObjects = new HashMap<String, Object>();
    extraObjects.put(UIVaadinFormToolkit.EXTRA_OBJECT_APPLICATION, this);
    VaadinBindingFormInstance formInstance = vaadinToolkit.buildForm(form, commonBindingToolkit, extraObjects,
            false);//from   w w  w .j av a 2 s  . co  m

    Window window = new Window(form.getName());
    window.setModal(true);
    window.addComponent((ComponentContainer) formInstance.getImplementation());
    formInstance.setValue(bean);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth(100, HorizontalLayout.UNITS_PERCENTAGE);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button buttonOk = new Button("Ok");
    buttons.addComponent(buttonOk);
    Button buttonCancel = new Button("Cancel");
    buttons.addComponent(buttonCancel);

    footer.addComponent(buttons);
    footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT);
    window.addComponent(footer);
    ((VerticalLayout) window.getContent()).setComponentAlignment(footer, Alignment.BOTTOM_CENTER);
    window.getContent().setSizeFull();
    vaadinApplication.getMainWindow().addWindow(window);

    return new UIDialogImpl(window, buttonOk, buttonCancel, formInstance);

}

From source file:org.openeos.services.ui.vaadin.internal.UIApplicationImpl.java

License:Apache License

private <T> UIDialog showFormDialog(Class<T> modelClass, UIBean model, BindingFormCapability capability) {
    AbstractFormBindingForm<T> form = formRegistryService.getDefaultForm(modelClass,
            AbstractFormBindingForm.class, capability);
    Map<String, Object> extraObjects = new HashMap<String, Object>();
    extraObjects.put(UIVaadinFormToolkit.EXTRA_OBJECT_APPLICATION, this);
    VaadinBindingFormInstance formInstance = vaadinToolkit.buildForm(form.getAbstractBForm(),
            uiBeanBindingToolkit, extraObjects, false);

    Window window = new Window(form.getAbstractBForm().getName());
    window.setModal(true);
    window.addComponent((ComponentContainer) formInstance.getImplementation());
    formInstance.setValue(model);/*from www .j a v a  2  s  .co m*/

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth(100, HorizontalLayout.UNITS_PERCENTAGE);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button buttonOk = new Button("Ok");
    buttons.addComponent(buttonOk);
    Button buttonCancel = new Button("Cancel");
    buttons.addComponent(buttonCancel);

    footer.addComponent(buttons);
    footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT);
    window.addComponent(footer);
    ((VerticalLayout) window.getContent()).setComponentAlignment(footer, Alignment.BOTTOM_CENTER);
    window.getContent().setSizeFull();
    vaadinApplication.getMainWindow().addWindow(window);

    return new UIDialogImpl(window, buttonOk, buttonCancel, formInstance);
}

From source file:org.opennms.features.topology.app.internal.operations.HistoryOperation.java

License:Open Source License

@Override
public Undoer execute(List<VertexRef> targets, OperationContext operationContext) {
    UI mainWindow = operationContext.getMainWindow();
    CommandManager commandManager = m_commandManager;

    Window window = new Window();
    window.setModal(true);

    VerticalLayout layout = new VerticalLayout();
    for (Command command : commandManager.getHistoryList()) {
        layout.addComponent(new Label(command.toString()));
    }//from   w ww.jav  a  2s  . com
    window.setContent(layout);

    mainWindow.addWindow(window);
    return null;
}

From source file:org.opennms.features.topology.app.internal.operations.RemoveVertexFromGroupOperation.java

License:Open Source License

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    if (targets == null || targets.isEmpty() || targets.size() != 1) {
        return;/*from w ww .  j av a  2  s . c om*/
    }

    final Logger log = LoggerFactory.getLogger(this.getClass());

    final GraphContainer graphContainer = operationContext.getGraphContainer();

    final VertexRef currentGroup = targets.get(0);
    final Collection<? extends Vertex> children = graphContainer.getBaseTopology().getChildren(currentGroup);
    for (Vertex child : children) {
        log.debug("Child ID: {}", child.getId());
    }

    final UI window = operationContext.getMainWindow();

    final Window groupNamePrompt = new Window("Remove item from this Group");
    groupNamePrompt.setModal(true);
    groupNamePrompt.setResizable(false);
    groupNamePrompt.setHeight("180px");
    groupNamePrompt.setWidth("300px");

    // Define the fields for the form
    final PropertysetItem item = new PropertysetItem();
    item.addItemProperty("Item", new ObjectProperty<String>(null, String.class));

    FormFieldFactory fieldFactory = new FormFieldFactory() {
        private static final long serialVersionUID = 243277720538924081L;

        @Override
        public Field<?> createField(Item item, Object propertyId, Component uiContext) {
            // Identify the fields by their Property ID.
            String pid = (String) propertyId;
            if ("Item".equals(pid)) {
                ComboBox select = new ComboBox("Item");
                for (Vertex child : children) {
                    log.debug("Adding child: {}, {}", child.getId(), child.getLabel());
                    select.addItem(child.getId());
                    select.setItemCaption(child.getId(), child.getLabel());
                }
                select.setNewItemsAllowed(false);
                select.setNullSelectionAllowed(false);
                return select;
            }

            return null; // Invalid field (property) name.
        }
    };

    // TODO Add validator for name value

    final Form promptForm = new Form() {

        private static final long serialVersionUID = 2067414790743946906L;

        @Override
        public void commit() {
            super.commit();

            String childId = (String) getField("Item").getValue();
            log.debug("Field value: {}", childId);

            LoggerFactory.getLogger(this.getClass()).debug("Removing item from group: {}", childId);

            Vertex grandParent = graphContainer.getBaseTopology().getParent(currentGroup);

            GraphProvider topologyProvider = graphContainer.getBaseTopology();

            // Relink the child to the grandparent group (or null if it is null)
            topologyProvider.setParent(graphContainer.getBaseTopology()
                    .getVertex(graphContainer.getBaseTopology().getVertexNamespace(), childId), grandParent);

            // Save the topology
            topologyProvider.save();

            graphContainer.redoLayout();
        }
    };
    // Buffer changes to the datasource
    promptForm.setBuffered(true);
    // You must set the FormFieldFactory before you set the data source
    promptForm.setFormFieldFactory(fieldFactory);
    promptForm.setItemDataSource(item);

    Button ok = new Button("OK");
    ok.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 7388841001913090428L;

        @Override
        public void buttonClick(ClickEvent event) {
            promptForm.commit();
            // Close the prompt window
            window.removeWindow(groupNamePrompt);
        }
    });
    promptForm.getFooter().addComponent(ok);

    Button cancel = new Button("Cancel");
    cancel.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 8780989646038333243L;

        @Override
        public void buttonClick(ClickEvent event) {
            // Close the prompt window
            window.removeWindow(groupNamePrompt);
        }
    });
    promptForm.getFooter().addComponent(cancel);

    groupNamePrompt.setContent(promptForm);

    window.addWindow(groupNamePrompt);
}

From source file:org.opennms.features.topology.app.internal.operations.RenameGroupOperation.java

License:Open Source License

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    if (targets == null || targets.isEmpty() || targets.size() != 1) {
        return;//from w w w . j a v a 2s  .c  om
    }

    final GraphContainer graphContainer = operationContext.getGraphContainer();

    final UI window = operationContext.getMainWindow();

    final Window groupNamePrompt = new Window("Rename Group");
    groupNamePrompt.setModal(true);
    groupNamePrompt.setResizable(false);
    groupNamePrompt.setHeight("220px");
    groupNamePrompt.setWidth("300px");

    // Define the fields for the form
    final PropertysetItem item = new PropertysetItem();
    item.addItemProperty("Group Label", new ObjectProperty<String>("", String.class));

    final Form promptForm = new Form() {

        private static final long serialVersionUID = 9202531175744361407L;

        @Override
        public void commit() {
            // Trim the form value
            Property<String> field = getField("Group Label");
            String groupLabel = field.getValue();
            if (groupLabel == null) {
                throw new InvalidValueException("Group label cannot be null.");
            }
            field.setValue(groupLabel.trim());
            super.commit();
            groupLabel = field.getValue();

            //Object parentKey = targets.get(0);
            //Object parentId = graphContainer.getVertexItemIdForVertexKey(parentKey);
            VertexRef parentId = targets.get(0);
            Vertex parentVertex = parentId == null ? null
                    : graphContainer.getBaseTopology().getVertex(parentId, graphContainer.getCriteria());
            Item parentItem = parentVertex == null ? null : parentVertex.getItem();

            if (parentItem != null) {

                Property<String> property = parentItem.getItemProperty("label");
                if (property != null && !property.isReadOnly()) {
                    property.setValue(groupLabel);

                    // Save the topology
                    graphContainer.getBaseTopology().save();

                    graphContainer.redoLayout();
                }
            }
        }
    };
    // Buffer changes to the datasource
    promptForm.setBuffered(true);
    // Bind the item to create all of the fields
    promptForm.setItemDataSource(item);
    // Add validators to the fields
    promptForm.getField("Group Label").setRequired(true);
    promptForm.getField("Group Label").setRequiredError("Group label cannot be blank.");
    promptForm.getField("Group Label").addValidator(
            new StringLengthValidator("Label must be at least one character long.", 1, -1, false));
    promptForm.getField("Group Label")
            .addValidator(new AbstractValidator<String>("A group with label \"{0}\" already exists.") {

                private static final long serialVersionUID = 79618011585921224L;

                @Override
                protected boolean isValidValue(String value) {
                    try {
                        final Collection<? extends Vertex> vertexIds = graphContainer.getBaseTopology()
                                .getVertices();
                        final Collection<String> groupLabels = new ArrayList<String>();
                        for (Vertex vertexId : vertexIds) {
                            if (vertexId.isGroup()) {
                                groupLabels.add(vertexId.getLabel());
                            }
                        }

                        for (String label : groupLabels) {
                            LoggerFactory.getLogger(this.getClass()).debug("Comparing {} to {}", value, label);
                            if (label.equals(value)) {
                                return false;
                            }
                        }
                        return true;
                    } catch (Throwable e) {
                        LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e);
                        return false;
                    }
                }

                @Override
                public Class<String> getType() {
                    return String.class;
                }
            });

    Button ok = new Button("OK");
    ok.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 7388841001913090428L;

        @Override
        public void buttonClick(ClickEvent event) {
            promptForm.commit();
            // Close the prompt window
            window.removeWindow(groupNamePrompt);
        }
    });
    promptForm.getFooter().addComponent(ok);

    Button cancel = new Button("Cancel");
    cancel.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 8780989646038333243L;

        @Override
        public void buttonClick(ClickEvent event) {
            // Close the prompt window
            window.removeWindow(groupNamePrompt);
        }
    });
    promptForm.getFooter().addComponent(cancel);

    groupNamePrompt.setContent(promptForm);

    window.addWindow(groupNamePrompt);
}

From source file:org.opennms.features.topology.app.internal.TopologyUI.java

License:Open Source License

@Override
public void menuBarUpdated(CommandManager commandManager) {
    if (m_menuBar != null) {
        m_rootLayout.removeComponent(m_menuBar);
    }//ww w  . j ava  2 s  .c o m

    if (m_contextMenu != null) {
        m_contextMenu.detach();
    }

    m_menuBar = commandManager.getMenuBar(m_graphContainer, this);
    m_menuBar.setWidth(100, Unit.PERCENTAGE);
    // Set expand ratio so that extra space is not allocated to this vertical component
    if (m_showHeader) {
        m_rootLayout.addComponent(m_menuBar, 1);
    } else {
        m_rootLayout.addComponent(m_menuBar, 0);
    }

    m_contextMenu = commandManager
            .getContextMenu(new DefaultOperationContext(this, m_graphContainer, DisplayLocation.CONTEXTMENU));
    m_contextMenu.setAsContextMenuOf(this);

    // Add Menu Item to share the View with others
    m_menuBar.addItem("Share", FontAwesome.SHARE, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            // create the share link
            String fragment = getPage().getLocation().getFragment();
            String url = getPage().getLocation().toString().replace("#" + getPage().getLocation().getFragment(),
                    "");
            String shareLink = String.format("%s?%s=%s", url,
                    TopologyUIRequestHandler.PARAMETER_HISTORY_FRAGMENT, fragment);

            // Create the Window
            Window shareWindow = new Window();
            shareWindow.setCaption("Share Link");
            shareWindow.setModal(true);
            shareWindow.setClosable(true);
            shareWindow.setResizable(false);
            shareWindow.setWidth(400, Unit.PIXELS);

            TextArea shareLinkField = new TextArea();
            shareLinkField.setValue(shareLink);
            shareLinkField.setReadOnly(true);
            shareLinkField.setRows(3);
            shareLinkField.setWidth(100, Unit.PERCENTAGE);

            // Close Button
            Button close = new Button("Close");
            close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
            close.addClickListener(event -> shareWindow.close());

            // Layout for Buttons
            HorizontalLayout buttonLayout = new HorizontalLayout();
            buttonLayout.setMargin(true);
            buttonLayout.setSpacing(true);
            buttonLayout.setWidth("100%");
            buttonLayout.addComponent(close);
            buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);

            // Content Layout
            VerticalLayout verticalLayout = new VerticalLayout();
            verticalLayout.setMargin(true);
            verticalLayout.setSpacing(true);
            verticalLayout.addComponent(
                    new Label("Please use the following link to share the current view with others."));
            verticalLayout.addComponent(shareLinkField);
            verticalLayout.addComponent(buttonLayout);

            shareWindow.setContent(verticalLayout);

            getUI().addWindow(shareWindow);
        }
    });

    updateMenuItems();
}

From source file:org.opennms.features.topology.app.internal.ui.ToolbarPanel.java

License:Open Source License

public ToolbarPanel(final ToolbarPanelController controller) {
    addStyleName(Styles.TOOLBAR);//from   w  w  w  .  j  a  v a 2 s  .  c o  m
    this.layoutManager = controller.getLayoutManager();

    final Property<Double> scale = controller.getScaleProperty();
    final Boolean[] eyeClosed = new Boolean[] { false };
    final Button showFocusVerticesBtn = new Button();
    showFocusVerticesBtn.setIcon(FontAwesome.EYE);
    showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes");
    showFocusVerticesBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (eyeClosed[0]) {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE);
            } else {
                showFocusVerticesBtn.setIcon(FontAwesome.EYE_SLASH);
            }
            eyeClosed[0] = !eyeClosed[0]; // toggle
            controller.toggleHighlightFocus();
        }
    });

    final Button magnifyBtn = new Button();
    magnifyBtn.setIcon(FontAwesome.PLUS);
    magnifyBtn.setDescription("Magnify");
    magnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.min(1, scale.getValue() + 0.25)));

    final Button demagnifyBtn = new Button();
    demagnifyBtn.setIcon(FontAwesome.MINUS);
    demagnifyBtn.setDescription("Demagnify");
    demagnifyBtn.addClickListener(
            (Button.ClickListener) event -> scale.setValue(Math.max(0, scale.getValue() - 0.25)));

    m_szlOutBtn = new Button();
    m_szlOutBtn.setId("szlOutBtn");
    m_szlOutBtn.setIcon(FontAwesome.ANGLE_DOWN);
    m_szlOutBtn.setDescription("Decrease Semantic Zoom Level");
    m_szlOutBtn.setEnabled(controller.getSemanticZoomLevel() > 0);
    m_szlOutBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            int szl = controller.getSemanticZoomLevel();
            if (szl > 0) {
                setSemanticZoomLevel(controller, szl - 1);
                controller.saveHistory();
            }
        }
    });

    final Button szlInBtn = new Button();
    szlInBtn.setId("szlInBtn");
    szlInBtn.setIcon(FontAwesome.ANGLE_UP);
    szlInBtn.setDescription("Increase Semantic Zoom Level");
    szlInBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            setSemanticZoomLevel(controller, controller.getSemanticZoomLevel() + 1);
            controller.saveHistory();
        }
    });

    m_zoomLevelLabel.setId("szlInputLabel");

    m_panBtn = new Button();
    m_panBtn.setIcon(FontAwesome.ARROWS);
    m_panBtn.setDescription("Pan Tool");
    m_panBtn.addStyleName(Styles.SELECTED);

    m_selectBtn = new Button();
    m_selectBtn.setIcon(IonicIcons.ANDROID_EXPAND);
    m_selectBtn.setDescription("Selection Tool");
    m_selectBtn.setStyleName("toolbar-button");
    m_selectBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_selectBtn.addStyleName(Styles.SELECTED);
            m_panBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.select);
        }
    });

    m_panBtn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_panBtn.addStyleName(Styles.SELECTED);
            m_selectBtn.removeStyleName(Styles.SELECTED);
            controller.setActiveTool(ActiveTool.pan);
        }
    });

    Button showAllMapBtn = new Button();
    showAllMapBtn.setId("showEntireMapBtn");
    showAllMapBtn.setIcon(FontAwesome.GLOBE);
    showAllMapBtn.setDescription("Show Entire Map");
    showAllMapBtn.addClickListener((Button.ClickListener) event -> controller.showAllMap());

    Button centerSelectionBtn = new Button();
    centerSelectionBtn.setIcon(FontAwesome.LOCATION_ARROW);
    centerSelectionBtn.setDescription("Center On Selection");
    centerSelectionBtn.addClickListener((Button.ClickListener) event -> controller.centerMapOnSelection());

    Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O);
    shareButton.setDescription("Share");
    shareButton.addClickListener((x) -> {
        // Create the share link
        String fragment = getUI().getPage().getLocation().getFragment();
        String url = getUI().getPage().getLocation().toString().replace("#" + fragment, "");
        String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment);

        // Create the Window
        Window shareWindow = new Window();
        shareWindow.setCaption("Share Link");
        shareWindow.setModal(true);
        shareWindow.setClosable(true);
        shareWindow.setResizable(false);
        shareWindow.setWidth(400, Sizeable.Unit.PIXELS);

        TextArea shareLinkField = new TextArea();
        shareLinkField.setValue(shareLink);
        shareLinkField.setReadOnly(true);
        shareLinkField.setRows(3);
        shareLinkField.setWidth(100, Sizeable.Unit.PERCENTAGE);

        // Close Button
        Button close = new Button("Close");
        close.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
        close.addClickListener(event -> shareWindow.close());

        // Layout for Buttons
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setMargin(true);
        buttonLayout.setSpacing(true);
        buttonLayout.setWidth("100%");
        buttonLayout.addComponent(close);
        buttonLayout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);

        // Content Layout
        VerticalLayout verticalLayout = new VerticalLayout();
        verticalLayout.setMargin(true);
        verticalLayout.setSpacing(true);
        verticalLayout.addComponent(
                new Label("Please use the following link to share the current view with others."));
        verticalLayout.addComponent(shareLinkField);
        verticalLayout.addComponent(buttonLayout);

        shareWindow.setContent(verticalLayout);

        getUI().addWindow(shareWindow);
    });

    // Refresh Button
    Button refreshButton = new Button();
    refreshButton.setId("refreshNow");
    refreshButton.setIcon(FontAwesome.REFRESH);
    refreshButton.setDescription("Refresh Now");
    refreshButton.addClickListener((event) -> controller.refreshUI());

    // Layer Layout
    layerLayout = new VerticalLayout();
    layerLayout.setId("layerComponent");
    layerLayout.setSpacing(true);
    layerLayout.setMargin(true);

    // Layer Button
    layerButton = new Button();
    layerButton.setId("layerToggleButton");
    layerButton.setIcon(FontAwesome.BARS);
    layerButton.setDescription("Layers");
    layerButton.addClickListener((event) -> {
        boolean isCollapsed = layerButton.getStyleName().contains(Styles.EXPANDED);
        setLayerLayoutVisible(!isCollapsed);
    });

    // Save button
    layerSaveButton = new Button();
    layerSaveButton.setId("saveLayerButton");
    layerSaveButton.setIcon(FontAwesome.FLOPPY_O);
    layerSaveButton.addClickListener((event) -> controller.saveLayout());

    // Actual Layout for the Toolbar
    CssLayout contentLayout = new CssLayout();
    contentLayout.addStyleName("toolbar-component");
    contentLayout.addComponent(createGroup(szlInBtn, m_zoomLevelLabel, m_szlOutBtn));
    contentLayout.addComponent(
            createGroup(refreshButton, centerSelectionBtn, showAllMapBtn, layerButton, showFocusVerticesBtn));
    contentLayout.addComponent(createGroup(m_panBtn, m_selectBtn));
    contentLayout.addComponent(createGroup(magnifyBtn, demagnifyBtn));
    contentLayout.addComponent(createGroup(shareButton));
    contentLayout.addComponent(createGroup(layerSaveButton));

    // Toolbar
    addComponent(contentLayout);
}

From source file:org.opennms.features.topology.plugins.ncs.ShowNCSPathOperation.java

License:Open Source License

@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 {/* ww  w . jav  a 2  s  . co  m*/
            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();
    final Collection<VertexRef> vertexRefs = getVertexRefsForNCSService(m_storedCriteria); //selectionManager.getSelectedVertexRefs();

    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());
}

From source file:org.opennms.features.vaadin.app.TopologyWidgetTestApplication.java

License:Open Source License

protected void showHistoryList(List<Command> historyList) {

    Window window = new Window();
    window.setModal(true);

    for (Command command : historyList) {
        window.addComponent(new Label(command.toString()));
    }/* w  w  w.  j  a v a2  s  . co  m*/

    getMainWindow().addWindow(window);

}