List of usage examples for com.vaadin.ui Window setModal
public void setModal(boolean modal)
From source file:org.opennms.features.vaadin.dashboard.config.ui.HelpClickListener.java
License:Open Source License
@Override public void buttonClick(Button.ClickEvent clickEvent) { final Window window = new Window("Help"); window.setModal(true); window.setClosable(false);/*w w w.j av a 2 s . c o m*/ window.setResizable(false); window.setWidth("55%"); window.setHeight("80%"); m_component.getUI().addWindow(window); window.setContent(new VerticalLayout() { { setMargin(true); setSpacing(true); setSizeFull(); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setSizeFull(); horizontalLayout.setSpacing(true); Tree tree = new Tree(); tree.setNullSelectionAllowed(false); tree.setMultiSelect(false); tree.setImmediate(true); tree.addItem("Overview"); tree.setChildrenAllowed("Overview", false); tree.addItem("Installed Dashlets"); tree.setChildrenAllowed("Installed Dashlets", true); final List<DashletFactory> factories = m_dashletSelector.getDashletFactoryList(); for (DashletFactory dashletFactory : factories) { tree.addItem(dashletFactory.getName()); tree.setParent(dashletFactory.getName(), "Installed Dashlets"); tree.setChildrenAllowed(dashletFactory.getName(), false); } horizontalLayout.addComponent(tree); for (final Object id : tree.rootItemIds()) { tree.expandItemsRecursively(id); } final Panel panel = new Panel(); panel.setSizeFull(); horizontalLayout.addComponent(panel); horizontalLayout.setExpandRatio(panel, 1.0f); addComponent(horizontalLayout); setExpandRatio(horizontalLayout, 1.0f); tree.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String itemId = String.valueOf(valueChangeEvent.getProperty().getValue()); if ("Installed Dashlets".equals(itemId)) { return; } if ("Overview".equals(itemId)) { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); verticalLayout.addComponent(new Label(getOverviewHelpHTML(), ContentMode.HTML)); panel.setContent(verticalLayout); } else { DashletFactory dashletFactory = m_dashletSelector.getDashletFactoryForName(itemId); if (dashletFactory != null) { if (dashletFactory.providesHelpComponent()) { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); Label helpTitle = new Label( "Help for Dashlet '" + dashletFactory.getName() + "'"); helpTitle.addStyleName("help-title"); verticalLayout.addComponent(helpTitle); verticalLayout.addComponent(dashletFactory.getHelpComponent()); panel.setContent(verticalLayout); } } } } }); tree.select("Overview"); addComponent(new HorizontalLayout() { { setMargin(true); setSpacing(true); setWidth("100%"); Button closeButton = new Button("Close"); addComponent(closeButton); setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT); closeButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { window.close(); } }); } }); } }); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.PreviewClickListener.java
License:Open Source License
@Override public void buttonClick(Button.ClickEvent clickEvent) { final Window window = new Window("Preview"); window.setModal(true); window.setClosable(false);/* ww w .java 2 s.c o m*/ window.setResizable(false); window.setWidth("80%"); window.setHeight("90%"); m_component.getUI().addWindow(window); final WallboardBody wallboardBody = new WallboardBody(); window.setContent(new VerticalLayout() { { setMargin(true); setSpacing(true); setSizeFull(); addComponent(wallboardBody); setExpandRatio(wallboardBody, 1.0f); addComponent(new HorizontalLayout() { { setMargin(true); setSpacing(true); setWidth("100%"); Button closeButton = new Button("Close"); addComponent(closeButton); setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT); closeButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { window.close(); } }); } }); } }); wallboardBody.setDashletSpecs(m_wallboard.getDashletSpecs()); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardConfigView.java
License:Open Source License
/** * This method is used to add a new {@link TabSheet.Tab} component. It creates a new window querying the user for the name of the new {@link Wallboard}. */// w w w .j av a 2s.com protected void addNewTabComponent() { final Window window = new Window("New Ops Board"); window.setModal(true); window.setClosable(false); window.setResizable(false); window.addCloseListener(new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { m_dashboardOverview.refreshTable(); } }); getUI().addWindow(window); window.setContent(new VerticalLayout() { TextField name = new TextField("Ops Board Name"); { addComponent(new FormLayout() { { setSizeUndefined(); setMargin(true); String newName = "Untitled"; int i = 1; if (WallboardProvider.getInstance().containsWallboard(newName)) { do { i++; newName = "Untitled #" + i; } while (WallboardProvider.getInstance().containsWallboard(newName)); } name.setValue(newName); addComponent(name); name.focus(); name.selectAll(); name.addValidator(new AbstractStringValidator("Title must be unique") { @Override protected boolean isValidValue(String s) { return (!WallboardProvider.getInstance().containsWallboard(s) && !"".equals(s)); } }); } }); addComponent(new HorizontalLayout() { { setMargin(true); setSpacing(true); setWidth("100%"); Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { // NMS-7560: Toggle the tab in order to allow us to click it again m_tabSheet.togglePlusTab(); window.close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); addComponent(cancel); setExpandRatio(cancel, 1); setComponentAlignment(cancel, Alignment.TOP_RIGHT); Button ok = new Button("Save"); ok.setDescription("Save configuration"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (name.isValid()) { Wallboard wallboard = new Wallboard(); wallboard.setTitle(name.getValue()); WallboardProvider.getInstance().addWallboard(wallboard); WallboardProvider.getInstance().save(); WallboardEditor wallboardEditor = new WallboardEditor(m_dashletSelector, wallboard); TabSheet.Tab tab = m_tabSheet.addTab(wallboardEditor, wallboard.getTitle()); wallboardEditor.setTab(tab); m_wallboardEditorMap.put(wallboard, tab); tab.setClosable(true); m_tabSheet.setSelectedTab(tab); window.close(); } } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); addComponent(ok); } }); } }); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.PreviewClickListener.java
License:Open Source License
/** * {@inheritDoc}//from ww w . j ava 2 s. c o m */ @Override public void buttonClick(Button.ClickEvent clickEvent) { final Window window = new Window("Preview"); window.setModal(true); window.setClosable(true); window.setResizable(false); window.setWidth("80%"); window.setHeight("90%"); m_component.getUI().addWindow(window); window.setContent(new VerticalLayout() { { addComponent(new VerticalLayout() { { setMargin(true); setSpacing(true); setSizeFull(); addComponent(new SurveillanceView(m_view, m_surveillanceViewService, false, false)); } }); } }); }
From source file:org.processbase.ui.servlet.MainWindow.java
License:Open Source License
void openLogoutWindow() { Window logout = new Window(((PbApplication) getApplication()).getPbMessages().getString("btnLogout")); logout.setModal(true); // logout.setStyleName(Reindeer.WINDOW_BLACK); logout.setWidth("260px"); logout.setResizable(false);/* w w w. j av a 2 s .c o m*/ logout.setClosable(false); logout.setDraggable(false); logout.setCloseShortcut(KeyCode.ESCAPE, null); Label helpText = new Label("Are you sure you want to log out?", Label.CONTENT_XHTML); logout.addComponent(helpText); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button yes = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"), new Button.ClickListener() { public void buttonClick(ClickEvent event) { WebApplicationContext applicationContext = (WebApplicationContext) getApplication() .getContext(); getApplication().close(); applicationContext.getHttpSession().invalidate(); } }); yes.setStyleName(Reindeer.BUTTON_DEFAULT); yes.focus(); buttons.addComponent(yes); Button no = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnCancel"), new Button.ClickListener() { public void buttonClick(ClickEvent event) { removeWindow(event.getButton().getWindow()); } }); buttons.addComponent(no); logout.addComponent(buttons); ((VerticalLayout) logout.getContent()).setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); ((VerticalLayout) logout.getContent()).setSpacing(true); addWindow(logout); }
From source file:org.vaadin.addon.ewopener.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true); Button button1 = new Button("Click me"); button1.addClickListener(e -> {//w ww . j ava2 s.c o m opener1.open(generateResource()); }); opener1.extend(button1); EnhancedBrowserWindowOpener opener4 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true); Button button4 = new Button("Nothing to open here"); button4.addClickListener(e -> { opener4.open((Resource) null); }); opener4.extend(button4); Button button2 = new Button("Click me"); button2.addClickListener(e -> { EnhancedBrowserWindowOpener.extendOnce(button2).open(generateResource()); }); Button button3 = new Button("Click me"); EnhancedBrowserWindowOpener opener3 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true) .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(button3); button3.addClickListener(opener3::open); Link link = new Link("Click me", null); new EnhancedBrowserWindowOpener().clientSide(true) .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(link); Link link2 = new Link("Click me", null); new EnhancedBrowserWindowOpener().clientSide(true) .withGeneratedContent("myFileName.txt", this::generateContent, resource -> { resource.setCacheTime(0); resource.setFilename("runtimeFileName-" + Instant.now().getEpochSecond() + ".txt"); }).doExtend(link2); EnhancedBrowserWindowOpener opener5 = new EnhancedBrowserWindowOpener( new ClassResource(DemoUI.class, "static.txt")); CssLayout hiddenComponent = new MCssLayout().withWidth("0").withHeight("0"); opener5.extend(hiddenComponent); CompletableFuture.runAsync(this::doSomeLongProcessing).thenRun(() -> getUI().access(opener5::open)); table = new Table("Select items to download", new BeanItemContainer<>(DummyService.Person.class, DummyService.data())); table.setImmediate(true); table.setVisibleColumns("name", "age"); table.setColumnHeaders("Name", "Age"); table.setWidth("100%"); table.setPageLength(20); table.setMultiSelectMode(MultiSelectMode.DEFAULT); table.setMultiSelect(true); table.setSelectable(true); final MyPopupContent popupContent = new MyPopupContent(); Button popupButton = new Button("Open modal", event -> { Window window = new Window("Test", popupContent); window.setWidth(40, Sizeable.Unit.PERCENTAGE); window.setHeight(200, Sizeable.Unit.PIXELS); window.setModal(true); window.setDraggable(false); window.setResizable(false); window.center(); getUI().addWindow(window); }); MenuBar.Command cmd = selectedItem -> Notification.show("Item clicked", "Item is " + selectedItem.getDescription(), Notification.Type.TRAY_NOTIFICATION); MenuBar menuBar = new MenuBar(); menuBar.setSizeFull(); EnhancedBrowserWindowOpener opener6 = new EnhancedBrowserWindowOpener() .withGeneratedContent("menu-item-serverside.txt", this::generateContent) .popupBlockerWorkaround(true); EnhancedBrowserWindowOpener opener7 = new EnhancedBrowserWindowOpener() .withGeneratedContent("menu-item-clientside-1.txt", this::generateContent).clientSide(true); EnhancedBrowserWindowOpener opener8 = new EnhancedBrowserWindowOpener() .withGeneratedContent("menu-item-clientside-2.txt", this::generateContent).clientSide(true); MenuBar.MenuItem menuItem = menuBar.addItem("Download from Menu (Client side)", selectedItem -> { System.out.println("OK, Invoked"); }); MenuBar.MenuItem subMenu = menuBar.addItem("Sub menu", null); subMenu.addItem("Item 1", cmd); subMenu.addItem("Item 2", cmd); MenuBar.MenuItem subItem = subMenu.addItem("Download (client side)", cmd); MenuBar.MenuItem subItem2 = subMenu.addItem("Download (server side)", selectedItem -> opener6.open()); opener7.doExtend(menuBar, menuItem); opener6.doExtend(menuBar, subItem2); opener8.doExtend(menuBar, subItem); // Show it in the middle of the screen final Layout layout = new MVerticalLayout( new MLabel("Enhanced Window Opener Demo").withStyleName(ValoTheme.LABEL_COLORED, ValoTheme.LABEL_H1), new MHorizontalLayout().add(table, 1) .add(new MCssLayout(menuBar, readMarkdown("code_menu.md").withFullWidth(), new MVerticalLayout(readMarkdown("code1.md"), button1) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code2.md"), button2) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code7.md"), button3) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code5.md"), link) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code6.md"), link2) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code3.md"), button4) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code8.md"), popupButton) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code4.md"), hiddenComponent) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false)) .withFullWidth().withStyleName("demo-samples"), 5) .withFullWidth()).withFullWidth().withMargin(true); setContent(layout); }
From source file:org.vaadin.addons.forms.LocationApplication.java
License:Apache License
public void init() { Window mainWindow = new Window("Location Form Sample"); Button button = new Button("Open Location Form"); button.setWidth("150px"); button.setHeight("30px"); button.addListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { Window window = new Window("Update Location"); window.addComponent(new LocationForm()); window.setModal(true); window.setResizable(false);//from ww w . j a v a2s .co m window.setWidth("510px"); window.setHeight("370px"); getMainWindow().addWindow(window); window.center(); } }); mainWindow.addComponent(button); setMainWindow(mainWindow); }
From source file:org.vaadin.addons.serverpush.samples.chat.ManualPushChatApplication.java
License:Apache License
private void fireLoginWindow() { final Window window = new Window("Login"); window.setModal(true); window.setWidth("640px"); window.setHeight("480px"); LoginForm loginForm = new LoginForm(); loginForm.setSizeFull();//w w w. jav a2 s . c o m loginForm.addListener(new LoginForm.LoginListener() { public void onLogin(LoginForm.LoginEvent event) { doLogin(event); getMainWindow().removeWindow(window); } }); window.setContent(loginForm); getMainWindow().addWindow(window); window.bringToFront(); }
From source file:org.vaadin.alump.ckeditor.demo.VaadinCKEditorUI.java
License:LGPL
@Override public void init(VaadinRequest request) { //Enable to test effects of other UIDL calls to cursor position //setPollInterval(5000); getPage().setTitle("Vaadin CKEditor UI"); VerticalLayout mainView = new VerticalLayout(); setContent(mainView);//www . ja va2 s . c o m /* enablePushEvents = new CheckBox("Enable push events"); enablePushEvents.addValueChangeListener(this::enablePushEvents); mainView.addComponents(new HorizontalLayout(enablePushEvents, pushUpdateLabel)); */ /* See http://ckeditor.com/latest/samples/plugins/toolbar/toolbar.html for the official info. * This is the full list as we know it in CKEditor 4.x [ { name: 'document', items : [ 'Source','-','NewPage','Preview','Print','-','Templates' ] }, { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, '/', { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/', { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, { name: 'colors', items : [ 'TextColor','BGColor' ] }, { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ] */ final String editor1InitialValue = "<p>Thanks TinyMCEEditor for getting us started on the CKEditor integration.</p>\n\n<h1>Like TinyMCEEditor said, "Vaadin rocks!"</h1>\n\n<h1>And CKEditor is no slouch either.</h1>\n"; CKEditorConfig config1 = new CKEditorConfig(); config1.useCompactTags(); config1.disableElementsPath(); config1.setResizeDir(CKEditorConfig.RESIZE_DIR.HORIZONTAL); config1.disableSpellChecker(); config1.setHeight("300px"); config1.addToExtraPlugins("exampleplugin"); //final CKEditorTextField ckEditorTextField1 = new CKEditorTextField(config1); final AbstractCKEditorTextField ckEditorTextField1 = new CKEditorPluginExample(config1); ckEditorTextField1.setImmediate(true); ckEditorTextField1.setHeight("440px"); // account for 300px editor plus toolbars mainView.addComponent(ckEditorTextField1); ckEditorTextField1.setValue(editor1InitialValue); ckEditorTextField1.addValueChangeListener(e -> { System.out.println("CKEditor v" + ckEditorTextField1.getVersion() + "/" + getVersion() + " - #1 contents: " + e.getValue()); }); Button resetTextButton1 = new Button("Reset editor #1"); resetTextButton1.addClickListener(event -> { if (!ckEditorTextField1.isReadOnly()) { ckEditorTextField1.setValue(editor1InitialValue); } }); Button toggleReadOnlyButton1 = new Button("Toggle read-only editor #1"); toggleReadOnlyButton1.addClickListener(event -> { ckEditorTextField1.setReadOnly(!ckEditorTextField1.isReadOnly()); }); Button toggleViewWithoutEditorButton1 = new Button("Toggle view-without-editor #1"); toggleViewWithoutEditorButton1.addClickListener(event -> { ckEditorTextField1.setViewWithoutEditor(!ckEditorTextField1.isViewWithoutEditor()); }); Button toggleVisibleButton1 = new Button("Toggle visible editor #1"); toggleVisibleButton1.addClickListener(event -> { ckEditorTextField1.setVisible(!ckEditorTextField1.isVisible()); }); HorizontalLayout buttonsLayout = new HorizontalLayout(resetTextButton1, toggleReadOnlyButton1, toggleViewWithoutEditorButton1, toggleVisibleButton1); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); mainView.addComponent(createSeparator()); // Now add in a second editor.... final String editor2InitialValue = "<p>Here is editor #2.</p>\n\n<p>Hope you find this useful in your Vaadin projects.</p>\n"; //final CKEditorTextField ckEditorTextField2 = new CKEditorTextField(); final AbstractCKEditorTextField ckEditorTextField2 = new CKEditorTextField(); ckEditorTextField2.setWidth("600px"); mainView.addComponent(ckEditorTextField2); CKEditorConfig config2 = new CKEditorConfig(); config2.addCustomToolbarLine( "{ items : ['Source','Styles','Bold','VaadinSave','-','Undo','Redo','-','NumberedList','BulletedList'] }"); config2.enableCtrlSWithVaadinSavePlugin(); config2.addToRemovePlugins("scayt"); ckEditorTextField2.setConfig(config2); ckEditorTextField2.setValue(editor2InitialValue); ckEditorTextField2.addValueChangeListener(event -> { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - #2 contents: " + event.getValue()); }); ckEditorTextField2.addVaadinSaveListener(editor -> { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - #2 VaadinSave button pressed."); }); Button resetTextButton2 = new Button("Reset editor #2"); resetTextButton2.addClickListener(event -> { if (!ckEditorTextField2.isReadOnly()) { ckEditorTextField2.setValue(editor2InitialValue); } }); Button toggleReadOnlyButton2 = new Button("Toggle read-only editor #2"); toggleReadOnlyButton2.addClickListener(event -> { ckEditorTextField2.setReadOnly(!ckEditorTextField2.isReadOnly()); }); Button toggleViewWithoutEditorButton2 = new Button("Toggle view-without-editor #2"); toggleViewWithoutEditorButton2.addClickListener(event -> { ckEditorTextField2.setViewWithoutEditor(!ckEditorTextField2.isViewWithoutEditor()); }); Button toggleVisibleButton2 = new Button("Toggle visible editor #2"); toggleVisibleButton2.addClickListener(event -> { ckEditorTextField2.setVisible(!ckEditorTextField2.isVisible()); }); buttonsLayout = new HorizontalLayout(resetTextButton2, toggleReadOnlyButton2, toggleViewWithoutEditorButton2, toggleVisibleButton2); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); buttonsLayout = new HorizontalLayout(); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); buttonsLayout.addComponent(new Button("Open Modal Subwindow", event -> { Window sub = new Window("Subwindow modal"); VerticalLayout subLayout = new VerticalLayout(); sub.setContent(subLayout); CKEditorConfig config = new CKEditorConfig(); config.useCompactTags(); config.disableElementsPath(); config.disableSpellChecker(); config.enableVaadinSavePlugin(); // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening // in a window that's on top of the main two editors of this demo app config.setBaseFloatZIndex(11000); config.setHeight("150px"); final CKEditorTextField ckEditorTextField = new CKEditorTextField(config); ckEditorTextField.addValueChangeListener(event2 -> { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - POPUP MODAL contents: " + event2.getValue()); }); ckEditorTextField.focus(); subLayout.addComponent(ckEditorTextField); sub.setWidth("80%"); sub.setModal(true); sub.center(); event.getButton().getUI().addWindow(sub); })); buttonsLayout.addComponent(new Button("Open Non-Modal Subwindow with 100% Height", event -> { Window sub = new Window("Subwindow non-modal 100% height"); VerticalLayout subLayout = new VerticalLayout(); sub.setContent(subLayout); sub.setWidth("80%"); sub.setHeight("500px"); subLayout.setSizeFull(); CKEditorConfig config = new CKEditorConfig(); config.useCompactTags(); config.disableElementsPath(); config.disableSpellChecker(); config.enableVaadinSavePlugin(); // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening // in a window that's on top of the main two editors of this demo app config.setBaseFloatZIndex(11000); config.setStartupFocus(true); config.setReadOnly(true); final CKEditorTextField ckEditorTextField = new CKEditorTextField(config); ckEditorTextField.setHeight("100%"); ckEditorTextField.addValueChangeListener(event2 -> { Notification.show("CKEditor v" + ckEditorTextField.getVersion() + "/" + getVersion() + " - POPUP NON-MODAL 100% HEIGHT contents: " + event2.getValue()); }); subLayout.addComponent(ckEditorTextField); subLayout.setExpandRatio(ckEditorTextField, 10); final TextField textField = new TextField("TextField"); textField.addValueChangeListener(event2 -> { Notification.show("TextField - POPUP NON-MODAL 100% HEIGHT contents: " + event2.getValue()); }); subLayout.addComponent(textField); sub.center(); event.getButton().getUI().addWindow(sub); })); }
From source file:org.vaadin.openesignforms.ckeditor.VaadinCKEditorUI.java
License:Open Source License
@Override public void init(VaadinRequest request) { getPage().setTitle("Vaadin7 CKEditor UI"); VerticalLayout mainView = new VerticalLayout(); setContent(mainView);/*from w ww. j a va 2 s .com*/ mainView.addComponent(new Button("Hit server")); Label separator = new Label(" "); separator.setContentMode(ContentMode.HTML); mainView.addComponent(separator); /* See http://ckeditor.com/latest/samples/plugins/toolbar/toolbar.html for the official info. * This is the full list as we know it in CKEditor 4.x [ { name: 'document', items : [ 'Source','-','NewPage','Preview','Print','-','Templates' ] }, { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, '/', { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/', { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, { name: 'colors', items : [ 'TextColor','BGColor' ] }, { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ] */ final String editor1InitialValue = "<p>Thanks TinyMCEEditor for getting us started on the CKEditor integration.</p>\n\n<h1>Like TinyMCEEditor said, "Vaadin rocks!"</h1>\n\n<h1>And CKEditor is no slouch either.</h1>\n"; CKEditorConfig config1 = new CKEditorConfig(); config1.useCompactTags(); config1.disableElementsPath(); config1.setResizeDir(CKEditorConfig.RESIZE_DIR.HORIZONTAL); config1.disableSpellChecker(); config1.setHeight("300px"); final CKEditorTextField ckEditorTextField1 = new CKEditorTextField(config1); ckEditorTextField1.setHeight("440px"); // account for 300px editor plus toolbars mainView.addComponent(ckEditorTextField1); ckEditorTextField1.setValue(editor1InitialValue); ckEditorTextField1.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -761434593559159149L; public void valueChange(ValueChangeEvent event) { Notification.show("CKEditor v" + ckEditorTextField1.getVersion() + "/" + getVersion() + " - #1 contents: " + event.getProperty().getValue().toString()); } }); // This selection change listener is commented out for general use, but it does appear to work in preliminary testing as of // version 7.10.2 (15 July 2015) if you need it. /* ckEditorTextField1.addSelectionChangeListener(new SelectionChangeListener() { private static final long serialVersionUID = 1270295222444271706L; public void selectionChange(SelectionChangeEvent event) { if ( event.hasSelectedHtml() ) { Notification.show("CKEditor selected HTML: " + event.getSelectedHtml(), Type.ERROR_MESSAGE); ckEditorTextField1.focus(); } else { Notification.show("CKEditor un-select reported", Type.ERROR_MESSAGE); } } }); */ Button resetTextButton1 = new Button("Reset editor #1"); resetTextButton1.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 2872667648717255301L; @Override public void buttonClick(ClickEvent event) { if (!ckEditorTextField1.isReadOnly()) { ckEditorTextField1.setValue(editor1InitialValue); } } }); Button toggleReadOnlyButton1 = new Button("Toggle read-only editor #1"); toggleReadOnlyButton1.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 8462908141468254844L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField1.setReadOnly(!ckEditorTextField1.isReadOnly()); } }); Button toggleViewWithoutEditorButton1 = new Button("Toggle view-without-editor #1"); toggleViewWithoutEditorButton1.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 8122286299515325693L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField1.setViewWithoutEditor(!ckEditorTextField1.isViewWithoutEditor()); } }); Button toggleVisibleButton1 = new Button("Toggle visible editor #1"); toggleVisibleButton1.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -6715135605688427318L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField1.setVisible(!ckEditorTextField1.isVisible()); } }); HorizontalLayout buttonsLayout = new HorizontalLayout(resetTextButton1, toggleReadOnlyButton1, toggleViewWithoutEditorButton1, toggleVisibleButton1); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); separator = new Label(" "); separator.setContentMode(ContentMode.HTML); mainView.addComponent(separator); // Now add in a second editor.... final String editor2InitialValue = "<p>Here is editor #2.</p>\n\n<p>Hope you find this useful in your Vaadin projects.</p>\n"; final CKEditorTextField ckEditorTextField2 = new CKEditorTextField(); ckEditorTextField2.setWidth("600px"); mainView.addComponent(ckEditorTextField2); CKEditorConfig config2 = new CKEditorConfig(); config2.addCustomToolbarLine( "{ items : ['Source','Styles','Bold','VaadinSave','-','Undo','Redo','-','NumberedList','BulletedList'] }"); config2.enableCtrlSWithVaadinSavePlugin(); config2.addToRemovePlugins("scayt"); ckEditorTextField2.setConfig(config2); ckEditorTextField2.setValue(editor2InitialValue); ckEditorTextField2.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 1522230917891035997L; public void valueChange(ValueChangeEvent event) { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - #2 contents: " + event.getProperty().getValue().toString()); } }); ckEditorTextField2.addVaadinSaveListener(new CKEditorTextField.VaadinSaveListener() { private static final long serialVersionUID = 3763779235559050613L; @Override public void vaadinSave(CKEditorTextField editor) { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - #2 VaadinSave button pressed."); } }); Button resetTextButton2 = new Button("Reset editor #2"); resetTextButton2.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 4877506990872691752L; @Override public void buttonClick(ClickEvent event) { if (!ckEditorTextField2.isReadOnly()) { ckEditorTextField2.setValue(editor2InitialValue); } } }); Button toggleReadOnlyButton2 = new Button("Toggle read-only editor #2"); toggleReadOnlyButton2.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 7388801260896778551L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField2.setReadOnly(!ckEditorTextField2.isReadOnly()); } }); Button toggleViewWithoutEditorButton2 = new Button("Toggle view-without-editor #2"); toggleViewWithoutEditorButton2.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 6042124118599379679L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField2.setViewWithoutEditor(!ckEditorTextField2.isViewWithoutEditor()); } }); Button toggleVisibleButton2 = new Button("Toggle visible editor #2"); toggleVisibleButton2.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -3804977370320346348L; @Override public void buttonClick(ClickEvent event) { ckEditorTextField2.setVisible(!ckEditorTextField2.isVisible()); } }); buttonsLayout = new HorizontalLayout(resetTextButton2, toggleReadOnlyButton2, toggleViewWithoutEditorButton2, toggleVisibleButton2); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); separator = new Label(" "); separator.setContentMode(ContentMode.HTML); mainView.addComponent(separator); buttonsLayout = new HorizontalLayout(); buttonsLayout.setSpacing(true); mainView.addComponent(buttonsLayout); buttonsLayout.addComponent(new Button("Open Modal Subwindow", new ClickListener() { private static final long serialVersionUID = 7661931879334525618L; @Override public void buttonClick(ClickEvent event) { Window sub = new Window("Subwindow modal"); VerticalLayout subLayout = new VerticalLayout(); sub.setContent(subLayout); CKEditorConfig config = new CKEditorConfig(); config.useCompactTags(); config.disableElementsPath(); config.disableSpellChecker(); config.enableVaadinSavePlugin(); // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening // in a window that's on top of the main two editors of this demo app config.setBaseFloatZIndex(11000); config.setHeight("150px"); final CKEditorTextField ckEditorTextField = new CKEditorTextField(config); ckEditorTextField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -1308863170484877239L; public void valueChange(ValueChangeEvent event) { Notification.show("CKEditor v" + ckEditorTextField2.getVersion() + "/" + getVersion() + " - POPUP MODAL contents: " + event.getProperty().getValue().toString()); } }); ckEditorTextField.focus(); subLayout.addComponent(ckEditorTextField); sub.setWidth("80%"); sub.setModal(true); sub.center(); event.getButton().getUI().addWindow(sub); } })); buttonsLayout.addComponent(new Button("Open Non-Modal Subwindow with 100% Height", new ClickListener() { private static final long serialVersionUID = 8895747367120494167L; @Override public void buttonClick(ClickEvent event) { Window sub = new Window("Subwindow non-modal 100% height"); VerticalLayout subLayout = new VerticalLayout(); sub.setContent(subLayout); sub.setWidth("80%"); sub.setHeight("500px"); subLayout.setSizeFull(); CKEditorConfig config = new CKEditorConfig(); config.useCompactTags(); config.disableElementsPath(); config.disableSpellChecker(); config.enableVaadinSavePlugin(); // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening // in a window that's on top of the main two editors of this demo app config.setBaseFloatZIndex(11000); config.setStartupFocus(true); config.setReadOnly(true); final CKEditorTextField ckEditorTextField = new CKEditorTextField(config); ckEditorTextField.setHeight("100%"); ckEditorTextField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 5592423527258867304L; public void valueChange(ValueChangeEvent event) { Notification.show("CKEditor v" + ckEditorTextField.getVersion() + "/" + getVersion() + " - POPUP NON-MODAL 100% HEIGHT contents: " + event.getProperty().getValue().toString()); } }); subLayout.addComponent(ckEditorTextField); subLayout.setExpandRatio(ckEditorTextField, 10); final TextField textField = new TextField("TextField"); textField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 6686202497483757206L; public void valueChange(ValueChangeEvent event) { Notification.show("TextField - POPUP NON-MODAL 100% HEIGHT contents: " + event.getProperty().getValue().toString()); } }); subLayout.addComponent(textField); sub.center(); event.getButton().getUI().addWindow(sub); } })); }