@Override public void actionPerform(Component component) { tableImpl.hidePresentationsPopup(); Presentations presentations = table.getPresentations(); Presentation current = presentations.getCurrent(); Element e = presentations.getSettings(current); table.saveSettings(e); presentations.setSettings(current, e); presentations.commit(); } }
protected void fillPresentations(Presentations presentations) { presentation.removeAllItems(); Collection<Object> availablePresentationIds = presentations.getPresentationIds(); for (Object pId : availablePresentationIds) { Presentation p = presentations.getPresentation(pId); presentation.addItem(p); presentation.setItemCaption(p, presentations.getCaption(pId)); } }
@Override public Object getDefaultPresentationId() { if (presentations == null) { return null; } Presentation def = presentations.getDefault(); return def == null ? null : def.getId(); }
protected boolean handleSpecificVariables(Map<String, Object> variables) { boolean needReload = false; if (isUsePresentations() && presentations != null) { Presentations p = getPresentations(); if (p.getCurrent() != null && p.isAutoSave(p.getCurrent()) && needUpdatePresentation(variables)) { Element e = p.getSettings(p.getCurrent()); saveSettings(e); p.setSettings(p.getCurrent(), e); } } //noinspection ConstantConditions return needReload; }
@Override public void actionPerform(Component component) { tableImpl.hidePresentationsPopup(); Presentations presentations = table.getPresentations(); Presentation current = presentations.getCurrent(); presentations.remove(current); presentations.commit(); } }
protected void buildPresentationsList() { menuBar.removeItems(); presentationsMenuMap = new HashMap<>(); Presentations p = table.getPresentations(); for (Object presId : p.getPresentationIds()) { MenuBar.MenuItem item = menuBar.addItem( defaultString(p.getCaption(presId)), selectedItem -> table.applyPresentation(presId) ); Presentation current = p.getCurrent(); if (current != null && presId.equals(current.getId())) { setCurrentItemStyle(item); } Presentation defaultPresentation = p.getDefault(); if (defaultPresentation != null && presId.equals(defaultPresentation.getId())) { setDefaultItemStyle(item); } presentationsMenuMap.put(presId, item); } }
protected void commit() { Presentations presentations = component.getPresentations(); Document doc = DocumentHelper.createDocument(); doc.setRootElement(doc.addElement("presentation")); component.saveSettings(doc.getRootElement()); String xml = Dom4j.writeDocument(doc, false); presentation.setXml(xml); presentation.setName(nameField.getValue()); presentation.setAutoSave(autoSaveField.getValue()); presentation.setDefault(defaultField.getValue()); User user = sessionSource.getUserSession().getCurrentOrSubstitutedUser(); boolean userOnly = !allowGlobalPresentations || !BooleanUtils.isTrue(globalField.getValue()); presentation.setUser(userOnly ? user : null); if (log.isTraceEnabled()) { log.trace(String.format("XML: %s", Dom4j.writeDocument(doc, true))); } if (isNew) { presentations.add(presentation); } else { presentations.modify(presentation); } presentations.commit(); addCloseListener(e -> { if (isNew) { component.applyPresentation(presentation.getId()); } }); }
@Override public void currentPresentationChanged(Presentations presentations, Object oldPresentationId) { table.getPresentations().commit(); if (presentationsMenuMap != null) { // simple change current item if (oldPresentationId != null) { if (oldPresentationId instanceof Presentation) oldPresentationId = ((Presentation) oldPresentationId).getId(); com.vaadin.ui.MenuBar.MenuItem lastMenuItem = presentationsMenuMap.get(oldPresentationId); if (lastMenuItem != null) removeCurrentItemStyle(lastMenuItem); } Presentation current = presentations.getCurrent(); if (current != null) { com.vaadin.ui.MenuBar.MenuItem menuItem = presentationsMenuMap.get(current.getId()); if (menuItem != null) setCurrentItemStyle(menuItem); } buildActions(); } }
@Override public void applyPresentationAsDefault(Object id) { if (isUsePresentations() && presentations != null) { Presentation p = presentations.getPresentation(id); if (p != null) { presentations.setDefault(p); applyPresentation(p); } } else { throw new UnsupportedOperationException("Component doesn't use presentations"); } }
protected void applyPresentation(Presentation p) { if (presentations != null) { Element settingsElement = presentations.getSettings(p); applySettings(settingsElement); presentations.setCurrent(p); component.markAsDirty(); } }
protected boolean isGlobalPresentation() { Presentations presentations = table.getPresentations(); Presentation presentation = presentations.getCurrent(); return presentation != null && (!presentations.isGlobal(presentation) || userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.presentations.global")); } }
Presentations presentations = ((HasPresentations) component).getPresentations(); if (presentations != null) { presentations.commit();
@Override public void applyPresentation(Object id) { if (isUsePresentations() && presentations != null) { Presentation p = presentations.getPresentation(id); applyPresentation(p); } else { throw new UnsupportedOperationException("Component doesn't use presentations"); } }
@Override public void actionPerform(Component component) { tableImpl.hidePresentationsPopup(); Presentations presentations = table.getPresentations(); Presentation current = presentations.getCurrent(); openEditor(current); } }
protected boolean validate() { Presentations presentations = component.getPresentations(); //check that name is empty if (StringUtils.isEmpty(nameField.getValue())) { App.getInstance().getWindowManager().showNotification( messages.getMainMessage("PresentationsEditor.error"), messages.getMainMessage("PresentationsEditor.error.nameRequired"), Frame.NotificationType.HUMANIZED); return false; } //check that name is unique final Presentation pres = presentations.getPresentationByName(nameField.getValue()); if (pres != null && !pres.equals(presentation)) { App.getInstance().getWindowManager().showNotification( messages.getMainMessage("PresentationsEditor.error"), messages.getMainMessage("PresentationsEditor.error.nameAlreadyExists"), Frame.NotificationType.HUMANIZED); return false; } return true; }
table.getPresentations().addListener(new PresentationsChangeListener() { @Override public void currentPresentationChanged(Presentations presentations, Object oldPresentationId) {
@Override public void defaultPresentationChanged(Presentations presentations, Object oldPresentationId) { if (presentationsMenuMap != null) { if (oldPresentationId != null) { if (oldPresentationId instanceof Presentation) oldPresentationId = ((Presentation) oldPresentationId).getId(); com.vaadin.ui.MenuBar.MenuItem lastMenuItem = presentationsMenuMap.get(oldPresentationId); if (lastMenuItem != null) removeDefaultItemStyle(lastMenuItem); } Presentation defaultPresentation = presentations.getDefault(); if (defaultPresentation != null) { com.vaadin.ui.MenuBar.MenuItem menuItem = presentationsMenuMap.get(defaultPresentation.getId()); if (menuItem != null) setDefaultItemStyle(menuItem); } } } });