List of usage examples for com.vaadin.ui AbstractOrderedLayout addComponent
public void addComponent(Component c, int index)
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultVerticalLayoutDropHandler.java
License:Apache License
/** * Called when a component changed location within the layout * /* ww w .j a v a 2s .co m*/ * @param event * The drag and drop event */ @Override protected void handleComponentReordering(DragAndDropEvent event) { // Component re-ordering LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails(); AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget(); Component comp = transferable.getComponent(); int idx = details.getOverIndex(); int oldIndex = layout.getComponentIndex(comp); if (idx == oldIndex) { // Index did not change return; } // Detach layout.removeComponent(comp); // Account for detachment if new index is bigger then old index if (idx > oldIndex) { idx--; } // Increase index if component is dropped after or above a previous // component VerticalDropLocation loc = details.getDropLocation(); if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) { idx++; } // Add component if (idx >= 0) { layout.addComponent(comp, idx); } else { layout.addComponent(comp); } // Add component alignment if given if (dropAlignment != null) { layout.setComponentAlignment(comp, dropAlignment); } }
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultVerticalLayoutDropHandler.java
License:Apache License
/** * Handle a drop from another layout/*from w w w . j a v a 2s . com*/ * * @param event * The drag and drop event */ @Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails(); AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget(); Component source = event.getTransferable().getSourceComponent(); int idx = (details).getOverIndex(); Component comp = transferable.getComponent(); // Check that we are not dragging an outer layout into an inner // layout Component parent = layout.getParent(); while (parent != null) { if (parent == comp) { return; } parent = parent.getParent(); } // Detach from old source if (source instanceof ComponentContainer) { ((ComponentContainer) source).removeComponent(comp); } else if (source instanceof SingleComponentContainer) { ((SingleComponentContainer) source).setContent(null); } // Increase index if component is dropped after or above a // previous // component VerticalDropLocation loc = (details).getDropLocation(); if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) { idx++; } // Add component if (idx >= 0) { layout.addComponent(comp, idx); } else { layout.addComponent(comp); } // Add component alignment if given if (dropAlignment != null) { layout.setComponentAlignment(comp, dropAlignment); } }
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultVerticalLayoutDropHandler.java
License:Apache License
@Override protected void handleHTML5Drop(DragAndDropEvent event) { VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails(); AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget(); int idx = (details).getOverIndex(); // Increase index if component is dropped after or above a // previous/*from w w w. j a v a2s .c om*/ // component VerticalDropLocation loc = (details).getDropLocation(); if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) { idx++; } Component comp = resolveComponentFromHTML5Drop(event); // Add component if (idx >= 0) { layout.addComponent(comp, idx); } else { layout.addComponent(comp); } // Add component alignment if given if (dropAlignment != null) { layout.setComponentAlignment(comp, dropAlignment); } }
From source file:de.symeda.sormas.ui.statistics.StatisticsView.java
License:Open Source License
public void generateMap() { List<Object[]> resultData = generateStatistics(); if (resultData.isEmpty()) { resultsLayout.addComponent(emptyResultLabel); return;//from w w w . j av a 2 s . c om } HorizontalLayout mapLayout = new HorizontalLayout(); mapLayout.setSpacing(true); mapLayout.setMargin(false); mapLayout.setWidth(100, Unit.PERCENTAGE); mapLayout.setHeightUndefined(); LeafletMap map = new LeafletMap(); map.setTileLayerOpacity(0.5f); map.setWidth(100, Unit.PERCENTAGE); map.setHeight(580, Unit.PIXELS); map.setZoom(6); GeoLatLon mapCenter = FacadeProvider.getGeoShapeProvider().getCenterOfAllRegions(); map.setCenter(mapCenter.getLon(), mapCenter.getLat()); List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllAsReference(); List<LeafletPolygon> outlinePolygones = new ArrayList<LeafletPolygon>(); // draw outlines of all regions for (RegionReferenceDto region : regions) { GeoLatLon[][] regionShape = FacadeProvider.getGeoShapeProvider().getRegionShape(region); if (regionShape == null) { continue; } for (int part = 0; part < regionShape.length; part++) { GeoLatLon[] regionShapePart = regionShape[part]; LeafletPolygon polygon = new LeafletPolygon(); polygon.setCaption(region.getCaption()); // fillOpacity is used, so we can still hover the region polygon.setOptions("{\"weight\": 1, \"color\": '#888', \"fillOpacity\": 0.02}"); polygon.setLatLons(regionShapePart); outlinePolygones.add(polygon); } } map.addPolygonGroup("outlines", outlinePolygones); resultData.sort((a, b) -> { return Long.compare(((Number) a[0]).longValue(), ((Number) b[0]).longValue()); }); BigDecimal valuesLowerQuartile = new BigDecimal( resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.25))[0]).longValue() : null); BigDecimal valuesMedian = new BigDecimal( resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.5))[0]).longValue() : null); BigDecimal valuesUpperQuartile = new BigDecimal( resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.75))[0]).longValue() : null); List<LeafletPolygon> resultPolygons = new ArrayList<LeafletPolygon>(); // Draw relevant district fills for (Object[] resultRow : resultData) { ReferenceDto regionOrDistrict = (ReferenceDto) resultRow[1]; String shapeUuid = regionOrDistrict.getUuid(); BigDecimal regionOrDistrictValue = new BigDecimal(((Number) resultRow[0]).longValue()); GeoLatLon[][] shape; switch (visualizationComponent.getVisualizationMapType()) { case REGIONS: shape = FacadeProvider.getGeoShapeProvider().getRegionShape(new RegionReferenceDto(shapeUuid)); break; case DISTRICTS: shape = FacadeProvider.getGeoShapeProvider().getDistrictShape(new DistrictReferenceDto(shapeUuid)); break; default: throw new IllegalArgumentException(visualizationComponent.getVisualizationMapType().toString()); } if (shape == null) { continue; } for (int part = 0; part < shape.length; part++) { GeoLatLon[] shapePart = shape[part]; String fillColor; if (regionOrDistrictValue.compareTo(BigDecimal.ZERO) == 0) { fillColor = "#000"; } else if (regionOrDistrictValue.compareTo(valuesLowerQuartile) < 0) { fillColor = "#FEDD6C"; } else if (regionOrDistrictValue.compareTo(valuesMedian) < 0) { fillColor = "#FDBF44"; } else if (regionOrDistrictValue.compareTo(valuesUpperQuartile) < 0) { fillColor = "#F47B20"; } else { fillColor = "#ED1B24"; } LeafletPolygon polygon = new LeafletPolygon(); polygon.setCaption(regionOrDistrict.getCaption() + "<br>" + regionOrDistrictValue); // fillOpacity is used, so we can still hover the region polygon.setOptions("{\"stroke\": false, \"color\": '" + fillColor + "', \"fillOpacity\": 0.8}"); polygon.setLatLons(shapePart); resultPolygons.add(polygon); } } map.addPolygonGroup("results", resultPolygons); mapLayout.addComponent(map); mapLayout.setExpandRatio(map, 1); AbstractOrderedLayout regionLegend = DashboardMapComponent.buildRegionLegend(true, CaseMeasure.CASE_COUNT, false, valuesLowerQuartile, valuesMedian, valuesUpperQuartile); Label legendHeader = new Label(I18nProperties.getCaption(Captions.dashboardMapKey)); CssStyles.style(legendHeader, CssStyles.H4, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE); regionLegend.addComponent(legendHeader, 0); mapLayout.addComponent(regionLegend); mapLayout.setExpandRatio(regionLegend, 0); resultsLayout.addComponent(mapLayout); resultsLayout.setExpandRatio(mapLayout, 1); }
From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultPanelContentView.java
License:Apache License
@Override public Button addBackButton(String caption, ClickListener clickListener) { AbstractOrderedLayout layout = getLayoutInternal(); Button backButton = new Button(caption); backButton.addClickListener(clickListener); layout.addComponent(backButton, 0); layout.setComponentAlignment(backButton, Alignment.MIDDLE_RIGHT); return backButton; }
From source file:info.magnolia.security.app.dialog.field.WebAccessFieldFactory.java
License:Open Source License
private Component createRuleRow(final AbstractOrderedLayout parentContainer, final AbstractJcrNodeAdapter ruleItem, final Label emptyLabel) { final HorizontalLayout ruleLayout = new HorizontalLayout(); ruleLayout.setSpacing(true);// w w w. ja va 2 s. c o m ruleLayout.setWidth("100%"); NativeSelect accessRights = new NativeSelect(); accessRights.addItem(Permission.ALL); accessRights.setItemCaption(Permission.ALL, i18n.translate("security.web.field.getPost")); accessRights.addItem(Permission.READ); accessRights.setItemCaption(Permission.READ, i18n.translate("security.web.field.get")); accessRights.addItem(Permission.NONE); accessRights.setItemCaption(Permission.NONE, i18n.translate("security.web.field.deny")); accessRights.setNullSelectionAllowed(false); accessRights.setImmediate(true); accessRights.setInvalidAllowed(false); accessRights.setNewItemsAllowed(false); Property permissionsProperty = ruleItem.getItemProperty(PERMISSIONS_PROPERTY_NAME); if (permissionsProperty == null) { permissionsProperty = new DefaultProperty<Long>(Long.class, Permission.ALL); ruleItem.addItemProperty(PERMISSIONS_PROPERTY_NAME, permissionsProperty); } accessRights.setPropertyDataSource(permissionsProperty); ruleLayout.addComponent(accessRights); TextField path = new TextField(); path.setWidth("100%"); Property pathProperty = ruleItem.getItemProperty(PATH_PROPERTY_NAME); if (pathProperty == null) { pathProperty = new DefaultProperty<String>(String.class, "/*"); ruleItem.addItemProperty(PATH_PROPERTY_NAME, pathProperty); } path.setPropertyDataSource(pathProperty); ruleLayout.addComponent(path); ruleLayout.setExpandRatio(path, 1.0f); final Button deleteButton = new Button(); deleteButton.setHtmlContentAllowed(true); deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>"); deleteButton.addStyleName("inline"); deleteButton.setDescription(i18n.translate("security.web.field.delete")); deleteButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { parentContainer.removeComponent(ruleLayout); ruleItem.getParent().removeChild(ruleItem); if (parentContainer.getComponentCount() == 1) { parentContainer.addComponent(emptyLabel, 0); } } }); ruleLayout.addComponent(deleteButton); return ruleLayout; }
From source file:info.magnolia.security.app.dialog.field.WorkspaceAccessFieldFactory.java
License:Open Source License
protected Component createRuleRow(final AbstractOrderedLayout parentContainer, final AbstractJcrNodeAdapter ruleItem, final Label emptyLabel) { final HorizontalLayout ruleLayout = new HorizontalLayout(); ruleLayout.setSpacing(true);/*from w w w. ja v a2 s . c o m*/ ruleLayout.setWidth("100%"); NativeSelect accessRights = new NativeSelect(); accessRights.setNullSelectionAllowed(false); accessRights.setImmediate(true); accessRights.setInvalidAllowed(false); accessRights.setNewItemsAllowed(false); accessRights.addItem(Permission.ALL); accessRights.setItemCaption(Permission.ALL, i18n.translate("security.workspace.field.readWrite")); accessRights.addItem(Permission.READ); accessRights.setItemCaption(Permission.READ, i18n.translate("security.workspace.field.readOnly")); accessRights.addItem(Permission.NONE); accessRights.setItemCaption(Permission.NONE, i18n.translate("security.workspace.field.denyAccess")); accessRights.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME)); ruleLayout.addComponent(accessRights); NativeSelect accessType = new NativeSelect(); accessType.setNullSelectionAllowed(false); accessType.setImmediate(true); accessType.setInvalidAllowed(false); accessType.setNewItemsAllowed(false); accessType.setWidth("150px"); accessType.addItem(AccessControlList.ACCESS_TYPE_NODE); accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE, i18n.translate("security.workspace.field.selected")); accessType.addItem(AccessControlList.ACCESS_TYPE_CHILDREN); accessType.setItemCaption(AccessControlList.ACCESS_TYPE_CHILDREN, i18n.translate("security.workspace.field.subnodes")); accessType.addItem(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN); accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN, i18n.translate("security.workspace.field.selectedSubnodes")); Property accessTypeProperty = ruleItem.getItemProperty(ACCESS_TYPE_PROPERTY_NAME); accessType.setPropertyDataSource(accessTypeProperty); ruleLayout.addComponent(accessType); final TextField path = new TextField(); path.setWidth("100%"); path.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PATH_PROPERTY_NAME)); ruleLayout.addComponent(path); ruleLayout.setExpandRatio(path, 1.0f); Button chooseButton = new Button(i18n.translate("security.workspace.field.choose")); chooseButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { openChooseDialog(path); } }); ruleLayout.addComponent(chooseButton); Button deleteButton = new Button(); deleteButton.setHtmlContentAllowed(true); deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>"); deleteButton.addStyleName("inline"); deleteButton.setDescription(i18n.translate("security.workspace.field.delete")); deleteButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { parentContainer.removeComponent(ruleLayout); ruleItem.getParent().removeChild(ruleItem); if (parentContainer.getComponentCount() == 1) { parentContainer.addComponent(emptyLabel, 0); } } }); ruleLayout.addComponent(deleteButton); return ruleLayout; }
From source file:org.semanticsoft.vaaclipse.presentation.renderers.AreaRenderer.java
License:Open Source License
@Override public void addChildGui(MUIElement child, MElementContainer<MUIElement> element) { if (!(child instanceof MPartSashContainerElement)) return;/*from ww w . ja va2 s. c o m*/ AbstractOrderedLayout areaWidget = (AbstractOrderedLayout) element.getWidget(); int index = indexOf(child, element); areaWidget.addComponent((Component) child.getWidget(), index); }
From source file:org.semanticsoft.vaaclipse.presentation.renderers.ToolBarRenderer.java
License:Open Source License
@Override public void addChildGui(MUIElement child, MElementContainer<MUIElement> element) { if (!(child instanceof MToolBarElement && (MElementContainer<?>) element instanceof MToolBar)) return;//from w w w . j a v a 2 s . c o m MToolBar toolBar = (MToolBar) (MElementContainer<?>) element; AbstractOrderedLayout toolbarWidget = (AbstractOrderedLayout) element.getWidget(); Component childWidget = (Component) child.getWidget(); if (toolbarWidget == null || childWidget == null) return; int index = indexOf(child, element) + 1; //+1 becouse the first element is toolbar drag handler (separator) if (element instanceof MToolBarSeparator) { toolbarWidget.addComponent(GuiUtils.createSeparator(toolBar), index); } else { toolbarWidget.addComponent(childWidget, index); } toolbarWidget.requestRepaint(); }