Example usage for com.vaadin.ui Window setResizable

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

Introduction

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

Prototype

public void setResizable(boolean resizable) 

Source Link

Document

Sets window resizable.

Usage

From source file:org.investovator.ui.main.AdminGameConfigLayout.java

License:Open Source License

private void startDailySummaryAddGameWizard() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Create New Game");
    VerticalLayout subContent = new VerticalLayout();
    subContent.setMargin(true);//from   w w w  .java 2s  . co m
    subWindow.setContent(subContent);

    // Put some components in it
    subContent.addComponent(new NewDataPlaybackGameWizard(subWindow));

    // set window characteristics
    subWindow.center();
    subWindow.setClosable(false);
    subWindow.setDraggable(false);
    subWindow.setResizable(false);
    subWindow.setModal(true);

    subWindow.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent closeEvent) {
            //getUI().getNavigator().navigateTo(UIConstants.MAINVIEW);
            getUI().getPage().reload();
        }
    });

    // Add it to the root component
    UI.getCurrent().addWindow(subWindow);
}

From source file:org.investovator.ui.main.components.AdminGameCreateView.java

License:Open Source License

private void startDailySummaryAddGameWizard() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Create New Game");
    VerticalLayout subContent = new VerticalLayout();
    subContent.setMargin(true);//from ww  w .j  a  v a2  s.c o m
    subWindow.setContent(subContent);

    // Put some components in it
    subContent.addComponent(new NewDataPlaybackGameWizard(subWindow));

    // set window characteristics
    subWindow.center();
    subWindow.setClosable(false);
    subWindow.setDraggable(false);
    subWindow.setResizable(false);
    subWindow.setModal(true);

    subWindow.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent closeEvent) {
            getUI().getNavigator().navigateTo(UIConstants.MAINVIEW);
            //                getUI().getPage().reload();
        }
    });

    // Add it to the root component
    UI.getCurrent().addWindow(subWindow);
}

From source file:org.opencms.ui.actions.CmsUserInfoDialogAction.java

License:Open Source License

/**
 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext)
 *//*from   w w  w . j  a v  a2  s .c  o m*/
public void executeAction(final I_CmsDialogContext context) {

    CmsUserInfo dialog = new CmsUserInfo(new I_UploadListener() {

        public void onUploadFinished(List<String> uploadedFiles) {

            handleUpload(uploadedFiles, context);
        }
    }, context);
    Multimap<String, String> params = A_CmsUI.get().getParameters();
    int top = 55;
    int left = 0;
    if (params.containsKey("left")) {
        String buttonLeft = params.get("left").iterator().next();
        left = Integer.parseInt(buttonLeft) - 290;
    }
    final Window window = new Window();
    window.setModal(false);
    window.setClosable(true);
    window.setResizable(false);
    window.setContent(dialog);
    context.setWindow(window);
    window.addStyleName(OpenCmsTheme.DROPDOWN);
    UI.getCurrent().addWindow(window);
    window.setPosition(left, top);
}

From source file:org.opencms.ui.CmsVaadinUtils.java

License:Open Source License

/**
 * Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.<p>
 *
 * @param title the title//from ww  w  . j  a v  a2  s  . c o m
 * @param message the message
 *
 * @param callback the callback to execute after clicking OK
 */
public static void showAlert(String title, String message, final Runnable callback) {

    final Window window = new Window();
    window.setModal(true);
    Panel panel = new Panel();
    panel.setCaption(title);
    panel.setWidth("500px");
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    panel.setContent(layout);
    layout.addComponent(new Label(message));
    Button okButton = new Button();
    okButton.addClickListener(new ClickListener() {

        /** The serial version id. */
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            window.close();
            if (callback != null) {
                callback.run();
            }
        }
    });
    layout.addComponent(okButton);
    layout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
    okButton.setCaption(org.opencms.workplace.Messages.get().getBundle(A_CmsUI.get().getLocale())
            .key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_OK_0));
    window.setContent(panel);
    window.setClosable(false);
    window.setResizable(false);
    A_CmsUI.get().addWindow(window);

}

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/*from   ww  w  . jav a  2  s.  c om*/
 *
 * @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.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  w  w.  j  a  va2s  .co m
    }

    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 ww  w  .j  a v  a2 s  .  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);
    }//from  w ww . 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 www .j  a  v  a2s . c  om*/
    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 {//  w ww .  ja v a2  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());
}