List of usage examples for com.vaadin.ui Window setContent
@Override public void setContent(Component content)
From source file:org.opencms.ui.dialogs.CmsCopyMoveDialog.java
License:Open Source License
/** * Displays the confirm overwrite dialog.<p> * * @param collidingResources the colliding resources *//* w ww .j a v a 2s . co m*/ private void showConfirmOverwrite(List<CmsResource> collidingResources) { final Window window = CmsBasicDialog.prepareWindow(); window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONFIRM_OVERWRITE_TITLE_0)); CmsConfirmationDialog dialog = new CmsConfirmationDialog( CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONFIRM_OVERWRITE_MESSAGE_0), new Runnable() { public void run() { window.close(); submit(true); } }, new Runnable() { public void run() { window.close(); cancel(); } }); dialog.displayResourceInfo(collidingResources); window.setContent(dialog); UI.getCurrent().addWindow(window); }
From source file:org.opencms.ui.dialogs.history.CmsHistoryDialog.java
License:Open Source License
/** * Replaces the contents of the window containing a given component with a basic dialog * consisting of a back button to restore the previous window state and another user provided widget.<p> * * @param currentComponent the component whose parent window's content should be replaced * @param newView the user supplied part of the new window content * @param newCaption the caption for the child dialog *///from w w w . j a va2 s .c om public static void openChildDialog(Component currentComponent, Component newView, String newCaption) { final Window window = CmsVaadinUtils.getWindow(currentComponent); final String oldCaption = window.getCaption(); CmsBasicDialog dialog = new CmsBasicDialog(); VerticalLayout vl = new VerticalLayout(); dialog.setContent(vl); Button backButton = new Button(CmsVaadinUtils.getMessageText(Messages.GUI_CHILD_DIALOG_GO_BACK_0)); HorizontalLayout buttonBar = new HorizontalLayout(); buttonBar.addComponent(backButton); buttonBar.setMargin(true); vl.addComponent(buttonBar); vl.addComponent(newView); final Component oldContent = window.getContent(); if (oldContent instanceof CmsBasicDialog) { List<CmsResource> infoResources = ((CmsBasicDialog) oldContent).getInfoResources(); dialog.displayResourceInfo(infoResources); if (oldContent instanceof CmsHistoryDialog) { dialog.addButton(((CmsHistoryDialog) oldContent).createCloseButton()); } } backButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { window.setContent(oldContent); window.setCaption(oldCaption); window.center(); } }); window.setContent(dialog); window.setCaption(newCaption); window.center(); }
From source file:org.opencms.ui.login.CmsLoginUI.java
License:Open Source License
/** * Shows the password reset dialog.<p> *//*from ww w. j a v a2 s. c o m*/ public void showPasswordResetDialog() { String caption = CmsVaadinUtils.getMessageText(Messages.GUI_PWCHANGE_FORGOT_PASSWORD_0); A_CmsUI r = A_CmsUI.get(); r.setContent(new Label()); Window window = CmsBasicDialog.prepareWindow(DialogWidth.narrow); CmsBasicDialog dialog = new CmsBasicDialog(); VerticalLayout result = new VerticalLayout(); dialog.setContent(result); window.setContent(dialog); window.setCaption(caption); window.setClosable(true); final CmsForgotPasswordDialog forgotPassword = new CmsForgotPasswordDialog(); window.addCloseListener(new CloseListener() { /** Serial version id. */ private static final long serialVersionUID = 1L; public void windowClose(CloseEvent e) { forgotPassword.cancel(); } }); for (Button button : forgotPassword.getButtons()) { dialog.addButton(button); } r.addWindow(window); window.center(); VerticalLayout vl = result; vl.addComponent(forgotPassword); }
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 w w w .j a v a 2 s . c o 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.opennms.features.jmxconfiggenerator.webui.JmxConfigGeneratorApplication.java
License:Open Source License
/** * Creates the main window and adds the header, main and button panels to * it.//from w w w. j av a 2s. c o m */ private void initMainWindow() { Window window = new Window("JmxConfigGenerator GUI Tool"); VerticalLayout layout = new VerticalLayout(); layout.addComponent(headerPanel); layout.addComponent(contentPanel); // content Panel should use most of the space :) layout.setExpandRatio(contentPanel, 1); window.setContent(layout); window.getContent().setSizeFull(); window.setSizeFull(); addWindow(window); }
From source file:org.opennms.features.topology.app.internal.operations.AddVertexToGroupOperation.java
License:Open Source License
@Override public void execute(List<VertexRef> targets, final OperationContext operationContext) { if (targets == null || targets.isEmpty()) { return;//from ww w . j a va2 s. c o m } final Logger log = LoggerFactory.getLogger(this.getClass()); final GraphContainer graphContainer = operationContext.getGraphContainer(); final Collection<VertexRef> vertices = removeChildren(operationContext.getGraphContainer(), determineTargets(targets.get(0), operationContext.getGraphContainer().getSelectionManager())); final Collection<Vertex> vertexIds = graphContainer.getBaseTopology().getRootGroup(); final Collection<Vertex> groupIds = findGroups(graphContainer.getBaseTopology(), vertexIds); final UI window = operationContext.getMainWindow(); final Window groupNamePrompt = new GroupWindow("Add This Item To a Group", "300px", "210px"); // Define the fields for the form final PropertysetItem item = new PropertysetItem(); item.addItemProperty("Group", new ObjectProperty<String>(null, String.class)); // field factory for the form FormFieldFactory fieldFactory = new FormFieldFactory() { private static final long serialVersionUID = 2963683658636386720L; public Field<?> createField(Item item, Object propertyId, Component uiContext) { // Identify the fields by their Property ID. String pid = (String) propertyId; if ("Group".equals(pid)) { final ComboBox select = new ComboBox("Group"); for (Vertex childId : groupIds) { log.debug("Adding child: {}, {}", childId.getId(), childId.getLabel()); select.addItem(childId.getId()); select.setItemCaption(childId.getId(), childId.getLabel()); } select.setNewItemsAllowed(false); select.setNullSelectionAllowed(false); select.setRequired(true); select.setRequiredError("You must select a group"); select.addValidator(new Validator() { private static final long serialVersionUID = -2466240291882827117L; @Override public void validate(Object value) throws InvalidValueException { if (isValid(value)) return; throw new InvalidValueException(String.format("You cannot add group '%s' to itself.", select.getItemCaption(value))); }; /** * Ensures that if only one element is selected that this element cannot be added to itself. * If there are more than one elements selected, we assume as valid. */ private boolean isValid(Object value) { if (vertices.size() > 1) return true; // more than 1 -> assume valid final String groupId = (String) select.getValue(); // only one, check if we want to assign to ourself for (VertexRef eachVertex : vertices) { if (groupId.equals(eachVertex.getId())) { return false; } } return true; } }); return select; } return null; // Invalid field (property) name. } }; // create the form final Form promptForm = new Form() { private static final long serialVersionUID = 8310646938173207767L; @Override public void commit() throws SourceException, InvalidValueException { super.commit(); String groupId = (String) getField("Group").getValue(); Vertex group = graphContainer.getBaseTopology() .getVertex(graphContainer.getBaseTopology().getVertexNamespace(), groupId); log.debug("Field value: {}", group.getId()); for (VertexRef eachChild : vertices) { if (eachChild == group) { log.warn("Ignoring group:(id={},label={}), because otherwise we should add it to itself.", eachChild.getId(), eachChild.getLabel()); continue; } log.debug("Adding item:(id={},label={}) to group:(id={},label={})", eachChild.getId(), eachChild.getLabel(), group.getId(), group.getLabel()); graphContainer.getBaseTopology().setParent(eachChild, group); } graphContainer.getBaseTopology().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); promptForm.setDescription("Please select a group."); // Footer Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = 7388841001913090428L; @Override public void buttonClick(ClickEvent event) { try { promptForm.validate(); promptForm.commit(); window.removeWindow(groupNamePrompt); // Close the prompt window } catch (InvalidValueException exception) { promptForm.setComponentError( new UserError(exception.getMessage(), ContentMode.TEXT, ErrorLevel.WARNING)); } } }); Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 8780989646038333243L; @Override public void buttonClick(ClickEvent event) { window.removeWindow(groupNamePrompt); // Close the prompt window } }); promptForm.setFooter(new HorizontalLayout()); promptForm.getFooter().addComponent(ok); promptForm.getFooter().addComponent(cancel); groupNamePrompt.setContent(promptForm); window.addWindow(groupNamePrompt); }
From source file:org.opennms.features.topology.app.internal.operations.CreateGroupOperation.java
License:Open Source License
@Override public void execute(final List<VertexRef> targets, final OperationContext operationContext) { if (targets == null || targets.isEmpty()) { return;// w w w . j a v a 2s . c o m } final GraphContainer graphContainer = operationContext.getGraphContainer(); final UI window = operationContext.getMainWindow(); final Window groupNamePrompt = new GroupWindow("Create Group", "300px", "200px"); // Define the fields for the form final PropertysetItem item = new PropertysetItem(); item.addItemProperty("Group Label", new ObjectProperty<String>("", String.class) { private static final long serialVersionUID = -7904501088179818863L; @Override public void setValue(String newValue) throws ReadOnlyException, ConversionException { if (newValue == null) { super.setValue(newValue); } else { super.setValue(newValue.trim()); } } @Override public String getValue() { String value = super.getValue(); if (value != null) return value.trim(); return value; } }); final Form promptForm = new Form() { private static final long serialVersionUID = 8938663493202118574L; @Override public void commit() { // Trim the form value Field<String> field = getField("Group Label"); String groupLabel = field.getValue(); if (groupLabel == null) { throw new InvalidValueException("Group label cannot be null."); } getField("Group Label").setValue(groupLabel.trim()); super.commit(); createGroup(graphContainer, (String) getField("Group Label").getValue(), targets); } private void createGroup(final GraphContainer graphContainer, final String groupLabel, final List<VertexRef> targets) { // Add the new group VertexRef groupId = graphContainer.getBaseTopology().addGroup(groupLabel, GROUP_ICON_KEY); // Find a common parent group. If none can be found, then link the group to the // top of the topology Vertex parentGroup = null; for (VertexRef vertexRef : targets) { Vertex parent = graphContainer.getBaseTopology().getParent(vertexRef); if (parentGroup == null) { parentGroup = parent; } else if (!parentGroup.equals(parent)) { // If there are multiple parents present then attach the new group // to the top level of the hierarchy parentGroup = null; break; } } // Link all targets to the newly-created group for (VertexRef vertexRef : targets) { graphContainer.getBaseTopology().setParent(vertexRef, groupId); } // Set the parent of the new group to the selected top-level parent graphContainer.getBaseTopology().setParent(groupId, parentGroup); // Save the topology operationContext.getGraphContainer().getBaseTopology().save(); graphContainer.redoLayout(); } }; // Buffer changes to the datasource promptForm.setBuffered(true); // Bind the item to create all of the fields promptForm.setItemDataSource(item); promptForm.setDescription("Please Enter the Name of the Group"); // Add validators to the fields addValidators(promptForm, graphContainer); // Footer Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = 7388841001913090428L; @Override public void buttonClick(ClickEvent event) { try { promptForm.validate(); promptForm.commit(); window.removeWindow(groupNamePrompt); // Close the prompt window } catch (InvalidValueException exception) { promptForm.setComponentError( new UserError(exception.getMessage(), ContentMode.TEXT, ErrorLevel.WARNING)); } } }); Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 8780989646038333243L; @Override public void buttonClick(ClickEvent event) { window.removeWindow(groupNamePrompt); // Close the prompt window } }); promptForm.setFooter(new HorizontalLayout()); promptForm.getFooter().addComponent(ok); promptForm.getFooter().addComponent(cancel); groupNamePrompt.setContent(promptForm); window.addWindow(groupNamePrompt); }
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);//from ww w . ja v a 2s. co m VerticalLayout layout = new VerticalLayout(); for (Command command : commandManager.getHistoryList()) { layout.addComponent(new Label(command.toString())); } 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;// w ww.j a v a2 s .c o 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 a 2 s. c o m*/ } 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); }