List of usage examples for com.vaadin.ui VerticalLayout removeComponent
@Override public void removeComponent(Component c)
From source file:at.peppol.webgui.app.components.PartyDetailForm.java
License:Mozilla Public License
private void initElements() { setCaption(party + " Party"); //setStyleName("light"); final VerticalLayout outerLayout = new VerticalLayout(); outerLayout.setSpacing(true);// ww w . j a va 2 s . co m outerLayout.setMargin(true); hiddenContent = new VerticalLayout(); hiddenContent.setSpacing(true); hiddenContent.setMargin(true); PropertysetItem partyItemSet = new PropertysetItem(); PartyIdentificationType supplierPartyID; if (partyBean.getPartyIdentification().size() == 0) { supplierPartyID = new PartyIdentificationType(); supplierPartyID.setID(new IDType()); partyBean.getPartyIdentification().add(supplierPartyID); } else { supplierPartyID = partyBean.getPartyIdentification().get(0); } partyItemSet.addItemProperty("Party ID", new NestedMethodProperty(supplierPartyID, "ID.value")); EndpointIDType endPointID; if (partyBean.getEndpointID() == null) { endPointID = new EndpointIDType(); partyBean.setEndpointID(endPointID); } else { endPointID = partyBean.getEndpointID(); } partyItemSet.addItemProperty("Endpoint ID", new NestedMethodProperty(endPointID, "SchemeAgencyID")); PartyNameType partyName; if (partyBean.getPartyName().size() == 0) { partyName = new PartyNameType(); partyName.setName(new NameType()); partyBean.getPartyName().add(partyName); } else { partyName = partyBean.getPartyName().get(0); } partyItemSet.addItemProperty("Party Name", new NestedMethodProperty(partyName, "name.value")); /* partyItemSet.addItemProperty("Agency Name", new NestedMethodProperty(supplierPartyID, "ID.SchemeAgencyID") ); */ /* final AddressType partyrAddress = new AddressType(); partyBean.setPostalAddress(partyrAddress); partyrAddress.setStreetName(new StreetNameType()); partyrAddress.setCityName(new CityNameType()); partyrAddress.setPostalZone(new PostalZoneType()); partyrAddress.setCountry(new CountryType()); partyrAddress.getCountry().setIdentificationCode(new IdentificationCodeType()); partyItemSet.addItemProperty("Street Name", new NestedMethodProperty(partyrAddress, "streetName.value")); partyItemSet.addItemProperty("City", new NestedMethodProperty(partyrAddress, "cityName.value")); partyItemSet.addItemProperty("Postal Zone", new NestedMethodProperty(partyrAddress, "postalZone.value")); partyItemSet.addItemProperty("Country", new NestedMethodProperty(partyrAddress, "country.identificationCode.value")); */ AddressDetailForm partyAddressForm; AddressType address; if (partyBean.getPostalAddress() == null) { address = new AddressType(); } else { address = partyBean.getPostalAddress(); } partyAddressForm = new AddressDetailForm(party, address); partyBean.setPostalAddress(address); PartyTaxSchemeType taxScheme; if (partyBean.getPartyTaxScheme().size() == 0) { taxScheme = new PartyTaxSchemeType(); taxScheme.setCompanyID(new CompanyIDType()); //partyItemSet.addItemProperty(taxSchemeCompanyID, // new NestedMethodProperty(taxScheme.getCompanyID(),"value")); // TODO: Hardcoded ShemeID etc for TaxScheme. Should be from a codelist? taxScheme.setTaxScheme(new TaxSchemeType()); taxScheme.getTaxScheme().setID(new IDType()); taxScheme.getTaxScheme().getID().setValue("VAT"); taxScheme.getTaxScheme().getID().setSchemeID("UN/ECE 5153"); taxScheme.getTaxScheme().getID().setSchemeAgencyID("6"); partyBean.getPartyTaxScheme().add(taxScheme); } else { taxScheme = partyBean.getPartyTaxScheme().get(0); } partyItemSet.addItemProperty(taxSchemeCompanyID, new NestedMethodProperty(taxScheme.getCompanyID(), "value")); partyItemSet.addItemProperty(taxSchemeID, new NestedMethodProperty(taxScheme.getTaxScheme().getID(), "value")); final Form partyForm = new Form(); partyForm.setFormFieldFactory(new PartyFieldFactory()); partyForm.setItemDataSource(partyItemSet); partyForm.setImmediate(true); final Button addLegalEntityBtn = new Button("Add Legal Entity"); final Button removeLegalEntityBtn = new Button("Remove Legal Entity"); //removeLegalEntityBtn.setVisible(false); addLegalEntityBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { //add the legal entity component Panel panel = createLegalEntityPanel(removeLegalEntityBtn); outerLayout.addComponent(panel); panel.setWidth("90%"); addLegalEntityBtn.setVisible(false); //removeLegalEntityBtn.setVisible(true); //outerLayout.replaceComponent(removeLegalEntityBtn, panel); } }); removeLegalEntityBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { //remove the legal entity component for (int i = 0; i < outerLayout.getComponentCount(); i++) { Component c = outerLayout.getComponent(i); if (c instanceof Panel) { if (c.getCaption().equals("Legal Entity")) { outerLayout.removeComponent(c); if (partyBean.getPartyLegalEntity().size() > 0) { partyBean.getPartyLegalEntity().clear(); ValidatorsList.removeListeners(Utils.getFieldListeners(legalEntityForm)); } } } } //removeLegalEntityBtn.setVisible(false); addLegalEntityBtn.setVisible(true); } }); outerLayout.addComponent(partyForm); partyForm.setWidth("90%"); outerLayout.addComponent(partyAddressForm); partyAddressForm.setWidth("90%"); outerLayout.addComponent(addLegalEntityBtn); if (partyBean.getPartyLegalEntity().size() > 0) addLegalEntityBtn.click(); //outerLayout.addComponent(removeLegalEntityBtn); //outerLayout.addComponent(createLegalEntityPanel()); setContent(outerLayout); }
From source file:com.haulmont.cuba.web.WebWindowManager.java
License:Apache License
protected void closeWindow(Window window, WindowOpenInfo openInfo) { if (!disableSavingScreenHistory) { screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode()); }// w w w . j ava 2 s.co m WebWindow webWindow = (WebWindow) window; webWindow.stopTimers(); switch (openInfo.getOpenMode()) { case DIALOG: { final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData(); cubaDialogWindow.forceClose(); fireListeners(window, tabs.size() != 0); break; } case NEW_WINDOW: case NEW_TAB: { final Layout layout = (Layout) openInfo.getData(); layout.removeComponent(WebComponentsHelper.getComposition(window)); WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window)); if (workArea.getMode() == Mode.TABBED) { TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour(); tabSheet.silentCloseTabAndSelectPrevious(layout); tabSheet.removeComponent(layout); } else { VerticalLayout singleLayout = workArea.getSingleWindowContainer(); singleLayout.removeComponent(layout); } WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout); if (windowBreadCrumbs != null) { windowBreadCrumbs.clearListeners(); windowBreadCrumbs.removeWindow(); } tabs.remove(layout); stacks.remove(windowBreadCrumbs); fireListeners(window, !tabs.isEmpty()); if (tabs.isEmpty() && app.getConnection().isConnected()) { workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT); } break; } case THIS_TAB: { final Layout layout = (Layout) openInfo.getData(); final WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) { throw new IllegalStateException("Unable to close screen: breadCrumbs not found"); } breadCrumbs.removeWindow(); Window currentWindow = breadCrumbs.getCurrentWindow(); if (!getStack(breadCrumbs).empty()) { Pair<Window, Integer> entry = getStack(breadCrumbs).pop(); putToWindowMap(entry.getFirst(), entry.getSecond()); } Component component = WebComponentsHelper.getComposition(currentWindow); component.setSizeFull(); WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window)); layout.removeComponent(WebComponentsHelper.getComposition(window)); if (app.getConnection().isConnected()) { layout.addComponent(component); if (workArea.getMode() == Mode.TABBED) { TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour(); String tabId = tabSheet.getTab(layout); String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription()); tabSheet.setTabCaption(tabId, formattedCaption); String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription()); if (!Objects.equals(formattedCaption, formattedDescription)) { tabSheet.setTabDescription(tabId, formattedDescription); } else { tabSheet.setTabDescription(tabId, null); } tabSheet.setTabIcon(tabId, WebComponentsHelper.getIcon(currentWindow.getIcon())); ContentSwitchMode contentSwitchMode = ContentSwitchMode .valueOf(currentWindow.getContentSwitchMode().name()); tabSheet.setContentSwitchMode(tabId, contentSwitchMode); } } fireListeners(window, !tabs.isEmpty()); if (tabs.isEmpty() && app.getConnection().isConnected()) { workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT); } break; } default: { throw new UnsupportedOperationException(); } } }
From source file:com.hris.employee.EmployeeUI.java
private VerticalLayout firstComponent() { employeeGridUI = new EmployeeGridUI(new EmployeeDataContainer()); VerticalLayout v = new VerticalLayout(); v.setWidth("100%"); v.setHeight("100%"); employeeStatus = employeeStatusComboBox(); employeeStatus.addValueChangeListener((Property.ValueChangeEvent event) -> { v.removeComponent(employeeGridUI); if (employeeStatus.getValue() == null) { if (getBranchId() == 0) { employeeGridUI = new EmployeeGridUI(new EmployeeDataContainer()); } else { employeeGridUI = new EmployeeGridUI( new EmployeeDataContainer(getBranchId(), (int) employeeStatus.getValue())); }// w w w . ja v a 2 s . com } else { employeeGridUI = new EmployeeGridUI( new EmployeeDataContainer(getBranchId(), (int) employeeStatus.getValue())); } v.addComponent(employeeGridUI); v.setExpandRatio(employeeGridUI, 2); }); v.addComponent(employeeStatus); v.addComponent(employeeGridUI); v.setExpandRatio(employeeGridUI, 2); return v; }
From source file:com.hris.employee.EmployeeUI.java
private VerticalLayout firstComponent(int branchId) { employeeGridUI = new EmployeeGridUI(new EmployeeDataContainer(branchId)); VerticalLayout v = new VerticalLayout(); v.setWidth("100%"); v.setHeight("100%"); employeeStatus = employeeStatusComboBox(); employeeStatus.addValueChangeListener((Property.ValueChangeEvent event) -> { v.removeComponent(employeeGridUI); if (employeeStatus.getValue() == null) { employeeGridUI = new EmployeeGridUI(new EmployeeDataContainer(getBranchId())); } else {/* w ww .j a v a 2 s . co m*/ employeeGridUI = new EmployeeGridUI( new EmployeeDataContainer(getBranchId(), (int) employeeStatus.getValue())); } v.addComponent(employeeGridUI); v.setExpandRatio(employeeGridUI, 2); }); v.addComponent(employeeStatus); v.addComponent(employeeGridUI); v.setExpandRatio(employeeGridUI, 2); return v; }
From source file:com.jain.common.header.Header.java
License:Apache License
public void buttonClick(ClickEvent event) { Button selected = event.getButton(); if (selected != current) { current.removeStyleName(ApplicationTheme.SELECTED); current = event.getButton();/* w ww. j a v a2 s . c o m*/ current.addStyleName(ApplicationTheme.SELECTED); VerticalLayout layout = (VerticalLayout) getUI().getContent(); if (currentComponent != null) layout.removeComponent(currentComponent); findNCreateCurrentComponent(); if (currentComponent != null) { layout.setSpacing(false); layout.setMargin(false); layout.addComponent(currentComponent); layout.setExpandRatio(currentComponent, 3); } } }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public Component getSources(InterestProfile profile) { VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setWidth("100%"); VerticalLayout sourcesLayout = new VerticalLayout(); sourcesLayout.setWidth("100%"); Panel sourcesPanel = new Panel(sourcesLayout); List<CheckBox> checkBoxes = new ArrayList<>(); HashMap<String, GridLayout> sourceLayouts = new HashMap<>(); profile.getSources().entrySet().stream() .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> { Source source = e.getKey(); boolean enabled = e.getValue(); GridLayout sourceLayout = new GridLayout(5, 1); sourceLayout.setSizeFull(); CheckBox sourceSelected = new CheckBox(); sourceSelected.setValue(enabled); sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE); sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue())); checkBoxes.add(sourceSelected); Image sourceLogo = new Image(); sourceLogo.addStyleName("logosmall"); sourceLogo.setSource(new ExternalResource(source.getLogo())); sourceLogo.addClickListener(c -> { sourceSelected.setValue(!sourceSelected.getValue()); profile.getSources().replace(source, sourceSelected.getValue()); });// w w w. j ava 2s. c o m VerticalLayout layoutLogo = new VerticalLayout(sourceLogo); layoutLogo.setWidth("150px"); layoutLogo.setHeight("50px"); layoutLogo.setMargin(false); layoutLogo.setSpacing(false); layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT); Label labelHeadLine = new Label( source.getCategory().getIcon().getHtml() + " " + source.getName(), ContentMode.HTML); labelHeadLine.addStyleName(ValoTheme.LABEL_H3); Label labelDescription = new Label(source.getDescription(), ContentMode.HTML); labelDescription.setWidth("300px"); PopupView popup = new PopupView(null, labelDescription); Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O); buttonDescription.addClickListener(ce -> { popup.setPopupVisible(true); }); sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription); sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER); sourceLayout.setColumnExpandRatio(2, 5); sourceLayout.setSpacing(true); sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "") .replaceAll("_", ""), sourceLayout); sourcesLayout.addComponent(sourceLayout); }); sourcesPanel.setContent(sourcesLayout); sourcesPanel.setHeight("100%"); sourcesPanel.setCaption(Language.get(Word.SOURCES)); Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s)); windowLayout.addComponent(sourcesPanel); windowLayout.setExpandRatio(sourcesPanel, 1); windowLayout.setSpacing(false); windowLayout.setMargin(false); CheckBox checkBoxSelectAll = new CheckBox(); Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s)); checkBoxSelectAll.setWidth("100%"); checkBoxSelectAll.addValueChangeListener(e -> { profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue()); checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue())); }); TextField textFieldSearch = new TextField(); Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s)); textFieldSearch.setWidth("100%"); textFieldSearch.setMaxLength(255); textFieldSearch.setPlaceholder(Language.get(Word.SEARCH)); textFieldSearch.addValueChangeListener(searchValue -> { sourceLayouts.forEach((sourceName, sourceLayout) -> { if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "") .replaceAll("-", "").replaceAll("_", ""))) { sourcesLayout.removeComponent(sourceLayout); } else { sourcesLayout.addComponent(sourceLayout); } }); }); Label placeholder = new Label(); placeholder.setWidth("100%"); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.setMargin(new MarginInfo(true, false, false, false)); footer.addStyleName("menubar"); footer.setWidth("100%"); footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder); footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT); footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER); windowLayout.addComponent(footer); windowLayout.setHeight("350px"); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java
public Component getSources(GroupInterestProfile profile, boolean isAdmin) { VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setWidth("100%"); VerticalLayout sourcesLayout = new VerticalLayout(); sourcesLayout.setWidth("100%"); Panel sourcesPanel = new Panel(sourcesLayout); List<CheckBox> checkBoxes = new ArrayList<>(); HashMap<String, GridLayout> sourceLayouts = new HashMap<>(); profile.getSources().entrySet().stream() .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> { Source source = e.getKey(); boolean enabled = e.getValue(); GridLayout sourceLayout = new GridLayout(5, 1); sourceLayout.setSizeFull(); CheckBox sourceSelected = new CheckBox(); sourceSelected.setValue(enabled); sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE); sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue())); sourceSelected.setEnabled(isAdmin); checkBoxes.add(sourceSelected); Image sourceLogo = new Image(); sourceLogo.addStyleName("logosmall"); sourceLogo.setSource(new ExternalResource(source.getLogo())); if (isAdmin) { sourceLogo.addClickListener(c -> { sourceSelected.setValue(!sourceSelected.getValue()); profile.getSources().replace(source, sourceSelected.getValue()); });/* www .j a va2s.c o m*/ } VerticalLayout layoutLogo = new VerticalLayout(sourceLogo); layoutLogo.setWidth("150px"); layoutLogo.setHeight("50px"); layoutLogo.setMargin(false); layoutLogo.setSpacing(false); layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT); Label labelHeadLine = new Label( source.getCategory().getIcon().getHtml() + " " + source.getName(), ContentMode.HTML); labelHeadLine.addStyleName(ValoTheme.LABEL_H3); Label labelDescription = new Label(source.getDescription(), ContentMode.HTML); labelDescription.setWidth("300px"); PopupView popup = new PopupView(null, labelDescription); Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O); buttonDescription.addClickListener(ce -> { popup.setPopupVisible(true); }); sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription); sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER); sourceLayout.setColumnExpandRatio(2, 5); sourceLayout.setSpacing(true); sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "") .replaceAll("_", ""), sourceLayout); sourcesLayout.addComponent(sourceLayout); }); sourcesPanel.setContent(sourcesLayout); sourcesPanel.setHeight("100%"); sourcesPanel.setCaption(Language.get(Word.SOURCES)); Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s)); windowLayout.addComponent(sourcesPanel); windowLayout.setExpandRatio(sourcesPanel, 1); windowLayout.setSpacing(false); windowLayout.setMargin(false); CheckBox checkBoxSelectAll = new CheckBox(); Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s)); checkBoxSelectAll.setWidth("100%"); checkBoxSelectAll.addValueChangeListener(e -> { profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue()); checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue())); }); checkBoxSelectAll.setEnabled(isAdmin); TextField textFieldSearch = new TextField(); Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s)); textFieldSearch.setWidth("100%"); textFieldSearch.setMaxLength(255); textFieldSearch.setPlaceholder(Language.get(Word.SEARCH)); textFieldSearch.addValueChangeListener(searchValue -> { sourceLayouts.forEach((sourceName, sourceLayout) -> { if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "") .replaceAll("-", "").replaceAll("_", ""))) { sourcesLayout.removeComponent(sourceLayout); } else { sourcesLayout.addComponent(sourceLayout); } }); }); Label placeholder = new Label(); placeholder.setWidth("100%"); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.setMargin(new MarginInfo(true, false, false, false)); footer.addStyleName("menubar"); footer.setWidth("100%"); footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder); footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT); footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER); windowLayout.addComponent(footer); windowLayout.setHeight("350px"); return windowLayout; }
From source file:edu.nps.moves.mmowgli.modules.cards.CardChainPage.java
License:Open Source License
private void listFollowers_oob(Session sess, Object badboyId) { Card badboy = Card.get(badboyId, sess); Set<Card> children = badboy.getFollowOns(); Vector<CardSummary> vec = new Vector<CardSummary>(); User me = User.get(Mmowgli2UI.getGlobals().getUserID(), sess); int col = -1; for (CardType ct : followOnTypes) { col++;/*from ww w.jav a 2 s . c o m*/ VerticalLayout columnV = columnVLs.get(col); int numcards = columnV.getComponentCount(); // including header, which we // don't touch for (int i = numcards - 1; i > 0; i--) columnV.removeComponent(columnV.getComponent(i)); if (children != null) { vec.clear(); // need to sort below // todo, enforce this in db for (Card c : children) { if (!isGameMaster && CardMarkingManager.isHidden(c)) continue; if (!Card.canSeeCard_oob(c, me, sess)) continue; if (c.getCardType().getId() == ct.getId()) { CardSummary summ = CardSummary.newCardSummary(c.getId(), sess, me); vec.add(summ); } } for (CardSummary cs : vec) { columnV.addComponent(cs); cs.initGui(sess); } } } }
From source file:info.magnolia.security.app.dialog.field.WebAccessFieldFactory.java
License:Open Source License
@Override protected Field<Object> createFieldComponent() { final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);// w ww . j a v a2 s . co m try { final JcrNodeAdapter roleItem = (JcrNodeAdapter) item; final VerticalLayout aclLayout = new VerticalLayout(); final Label emptyLabel = new Label(i18n.translate("security.web.field.noAccess")); // Since JcrNewNodeAdapter.getJcrItem() returns the parent node we need to skip this step because we don't want to inspect the parent node if (!(roleItem instanceof JcrNewNodeAdapter)) { Node roleNode = roleItem.getJcrItem(); if (roleNode.hasNode(ACL_NODE_NAME)) { final Node aclNode = roleNode.getNode(ACL_NODE_NAME); AbstractJcrNodeAdapter aclItem = new JcrNodeAdapter(aclNode); roleItem.addChild(aclItem); for (Node entryNode : NodeUtil.getNodes(aclNode)) { AbstractJcrNodeAdapter entryItem = new JcrNodeAdapter(entryNode); aclItem.addChild(entryItem); Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel); aclLayout.addComponent(ruleRow); } } } if (aclLayout.getComponentCount() == 0) { aclLayout.addComponent(emptyLabel); } final HorizontalLayout buttons = new HorizontalLayout(); final Button addButton = new Button(i18n.translate("security.web.field.addNew")); addButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { AbstractJcrNodeAdapter aclItem = getOrAddAclItem(roleItem, ACL_NODE_NAME); JcrNewNodeAdapter newItem = addAclEntryItem(aclItem); Component ruleRow = createRuleRow(aclLayout, newItem, emptyLabel); aclLayout.removeComponent(emptyLabel); aclLayout.addComponent(ruleRow, aclLayout.getComponentCount() - 1); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } } }); buttons.addComponent(addButton); aclLayout.addComponent(buttons); layout.addComponent(aclLayout); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } return new CustomField<Object>() { @Override protected Component initContent() { return layout; } @Override public Class<?> getType() { return Object.class; } }; }
From source file:info.magnolia.security.app.dialog.field.WorkspaceAccessFieldFactory.java
License:Open Source License
@Override protected Field<Object> createFieldComponent() { final String aclName = "acl_" + getFieldDefinition().getWorkspace(); final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);/* w ww. j a v a 2 s. c om*/ try { final JcrNodeAdapter roleItem = (JcrNodeAdapter) item; final VerticalLayout aclLayout = new VerticalLayout(); final Label emptyLabel = new Label(i18n.translate("security.workspace.field.noAccess")); // Since JcrNewNodeAdapter.getJcrItem() returns the parent node we need to skip this step because we don't want to inspect the parent node if (!(roleItem instanceof JcrNewNodeAdapter)) { Node roleNode = roleItem.getJcrItem(); if (roleNode.hasNode(aclName)) { final Node aclNode = roleNode.getNode(aclName); AccessControlList acl = new AccessControlList(); acl.readEntries(aclNode); AbstractJcrNodeAdapter aclItem = new JcrNodeAdapter(aclNode); roleItem.addChild(aclItem); aclItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME, new DefaultProperty<String>(String.class, "true")); final Set<AccessControlList.Entry> uniqueEntries = new HashSet<AccessControlList.Entry>(); for (final Node aclEntryNode : NodeUtil.getNodes(aclNode)) { AccessControlList.Entry entry = acl.getEntryByNode(aclEntryNode); if (uniqueEntries.contains(entry)) { continue; } uniqueEntries.add(entry); long permissions = entry.getPermissions(); long accessType = entry.getAccessType(); String path = entry.getPath(); JcrNodeAdapter entryItem = new JcrNodeAdapter(aclEntryNode); entryItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME, new DefaultProperty<String>(String.class, "true")); final Property<Long> permissionsProperty = DefaultPropertyUtil .newDefaultProperty(Long.class, null); entryItem.addItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME, permissionsProperty); final Property<Long> accessProperty = DefaultPropertyUtil.newDefaultProperty(Long.class, null); entryItem.addItemProperty(ACCESS_TYPE_PROPERTY_NAME, accessProperty); final Property<String> pathProperty = DefaultPropertyUtil.newDefaultProperty(String.class, null); entryItem.addItemProperty(AccessControlList.PATH_PROPERTY_NAME, pathProperty); permissionsProperty.setValue(permissions); accessProperty.setValue(accessType); pathProperty.setValue(path); aclItem.addChild(entryItem); Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel); aclLayout.addComponent(ruleRow); } } } if (aclLayout.getComponentCount() == 0) { aclLayout.addComponent(emptyLabel); } final HorizontalLayout buttons = new HorizontalLayout(); final Button addButton = new Button(i18n.translate("security.workspace.field.addButton")); addButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { AbstractJcrNodeAdapter aclItem = getOrAddAclItem(roleItem, aclName); if (aclItem.getItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME) == null) { aclItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME, new DefaultProperty<String>(String.class, "true")); } JcrNodeAdapter entryItem = addAclEntryItem(aclItem); entryItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME, new DefaultProperty<String>(String.class, "true")); entryItem.addItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME, new DefaultProperty<Long>(Long.class, Permission.ALL)); entryItem.addItemProperty(ACCESS_TYPE_PROPERTY_NAME, new DefaultProperty<Long>(Long.class, AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN)); entryItem.addItemProperty(AccessControlList.PATH_PROPERTY_NAME, new DefaultProperty<String>(String.class, "")); Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel); aclLayout.removeComponent(emptyLabel); aclLayout.addComponent(ruleRow, aclLayout.getComponentCount() - 1); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } } }); buttons.addComponent(addButton); aclLayout.addComponent(buttons); layout.addComponent(aclLayout); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } return new CustomField<Object>() { @Override protected Component initContent() { return layout; } @Override public Class<?> getType() { return Object.class; } }; }