List of usage examples for com.vaadin.ui AbstractComponent getData
public Object getData()
From source file:org.lunifera.runtime.web.vaadin.common.sharedState.SharedStateUtil.java
License:Open Source License
/** * Tries to find the {@link ISharedStateContext} registered with the Vaadin * component. It also iterates the parents recursively to find it. * /*ww w .ja v a 2s .c o m*/ * @param component * @return */ public static ISharedStateContext getSharedState(Component component) { if (component == null) { return null; } if (component instanceof AbstractComponent) { AbstractComponent comp = (AbstractComponent) component; if (comp.getData() != null && (comp.getData() instanceof Map)) { @SuppressWarnings("unchecked") Map<Object, Object> map = (Map<Object, Object>) comp.getData(); ISharedStateContext sharedState = (ISharedStateContext) map.get(ISharedStateContext.class); if (sharedState != null) { return sharedState; } } } return getSharedState(component.getParent()); }
From source file:org.metawidget.vaadin.ui.VaadinMetawidget.java
License:LGPL
@Override public void addComponent(Component component) { if (!mIgnoreAddRemove) { invalidateWidgets();//from w w w . ja v a 2 s . c om // Don't fall through to super.addImpl for facets. Tuck them away // in mFacets instead. Some layouts may never use them, and // others (eg. MigLayout) don't like adding components // without constraints AbstractComponent abstractComponent = (AbstractComponent) component; if (component instanceof Facet) { mFacets.put(abstractComponent.getData(), (Facet) component); return; } mExistingComponents.add(abstractComponent); } else { setCompositionRoot(component); } }
From source file:org.metawidget.vaadin.ui.VaadinMetawidget.java
License:LGPL
private Component getComponent(ComponentContainer container, String name) { Iterator<Component> iterator = container.getComponentIterator(); while (iterator.hasNext()) { AbstractComponent childComponent = (AbstractComponent) iterator.next(); // Drill into unnamed containers if (childComponent.getData() == null && childComponent instanceof ComponentContainer) { childComponent = (AbstractComponent) getComponent((ComponentContainer) childComponent, name); if (childComponent != null) { return childComponent; }/*from www .j a va2 s .c o m*/ continue; } // Match by name if (name.equals(childComponent.getData())) { return childComponent; } } // Not found return null; }
From source file:org.metawidget.vaadin.ui.widgetbuilder.OverriddenWidgetBuilder.java
License:LGPL
public Component buildWidget(String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) { String name = attributes.get(NAME); if (name == null) { return null; }/* w w w. j a v a 2 s . co m*/ Component component = null; List<AbstractComponent> existingUnusedComponents = metawidget.fetchExistingUnusedComponents(); for (AbstractComponent componentExisting : existingUnusedComponents) { if (name.equals(componentExisting.getData())) { component = componentExisting; break; } } if (component != null) { existingUnusedComponents.remove(component); } return component; }
From source file:org.semanticsoft.vaaclipse.presentation.dnd.VaadinDropHandler.java
License:Open Source License
public void drop(DragAndDropEvent event) { if (!(event.getTransferable() instanceof LayoutBoundTransferable)) return;/*from ww w.j a v a 2 s .c om*/ LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails(); if (transferable.getSourceComponent() instanceof StackWidget) { StackWidget sourceTabSheet = (StackWidget) transferable.getSourceComponent(); MPartStack targetFolder = targetPartStack; MPartStack sourceFolder = (MPartStack) sourceTabSheet.getData(); // this component is dragged by user AbstractComponent draggingComponent = (AbstractComponent) transferable.getComponent(); //This is model element that match to draggingComponent MStackElement draggingElement = (MStackElement) draggingComponent.getData(); //draggingElement must be in sourceFolder if (!sourceFolder.getChildren().contains(draggingElement)) return; String dropType = (String) details.getData("dropType"); if (dropType.equals("DropToTabsheetBar")) { int idx = details.getOverIndex(); HorizontalDropLocation location = details.getDropLocation(); if (draggingComponent == details.getOverComponent()) { // Dropped on itself return; } if (sourceTabSheet == targetTabSheet) {//reordering tabs if (sourceFolder != targetFolder) return; int modelOldPos = sourceFolder.getChildren().indexOf(draggingElement); Tab tabInNewPos = targetTabSheet.getTab(idx); if (tabInNewPos == null) return; MUIElement elementInInsertPos = (MUIElement) ((AbstractComponent) tabInNewPos.getComponent()) .getData(); int modelNewPos = targetPartStack.getChildren().indexOf(elementInInsertPos); targetPartStack.getChildren().remove(draggingElement); if (location == HorizontalDropLocation.RIGHT) { if (modelOldPos > modelNewPos) targetPartStack.getChildren().add(modelNewPos + 1, draggingElement); else targetPartStack.getChildren().add(modelNewPos, draggingElement); } else {//LEFT OR CENTER - processed as LEFT if (modelOldPos > modelNewPos) targetPartStack.getChildren().add(modelNewPos, draggingElement); else targetPartStack.getChildren().add(modelNewPos - 1, draggingElement); } } else {// Adding new tab sourceFolder.getChildren().remove(draggingElement); if (idx == -1) targetFolder.getChildren().add(draggingElement); else { Tab tabInNewPos = targetTabSheet.getTab(idx); MUIElement elementInNewPos = (MUIElement) ((AbstractComponent) tabInNewPos.getComponent()) .getData(); int modelNewPos = targetPartStack.getChildren().indexOf(elementInNewPos); int newPos = -1; if (location == HorizontalDropLocation.RIGHT) { targetFolder.getChildren().add(modelNewPos + 1, draggingElement); } else {//LEFT or CENTER - processed both as LEFT targetFolder.getChildren().add(modelNewPos, draggingElement); } } } targetFolder.setSelectedElement(draggingElement); } else if (dropType.equals("DropToTabsheetBody")) { //target widget coordinates: int x0 = (Integer) details.getData("targetWidgetAbsoluteLeft"); int y0 = (Integer) details.getData("targetWidgetAbsoluteTop"); int dx = (Integer) details.getData("targetWidgetOffsetWidth"); int dy = (Integer) details.getData("targetWidgetOffsetHeight"); int docPrcnt = 30; double docX = dx * docPrcnt / 100; double docY = dy * docPrcnt / 100; int mouseX = details.getMouseEvent().getClientX(); int mouseY = details.getMouseEvent().getClientY(); Vector mousePos = Vector.valueOf(mouseX, mouseY); Integer side = GeomUtils.findDockSide(x0, y0, dx, dy, docX, docY, mousePos); if (side != null) { targetPartStack.getChildren().remove(draggingElement); if (side == Side.CENTER) {//drop in center is equivalent tab adding at the end of target folder targetFolder.getChildren().add(draggingElement); targetFolder.setSelectedElement(draggingElement); } else {//if drop to sides, we must different what kind is target widget - tabsheet or area boolean onEdge = false; // Find the root of the targetFolder's sash structure //This root - is area, perspective or window MUIElement outerRelTo = targetFolder.getParent(); if (outerRelTo instanceof MPartSashContainer) { while (outerRelTo != null && !(outerRelTo instanceof MArea || outerRelTo instanceof MPerspective || outerRelTo instanceof MWindow)) outerRelTo = outerRelTo.getParent(); } //Outer element can not be null, becouse mpartstack or his sash structure must be located in one of place: area, perspective or window if (outerRelTo == null) return; if (outerRelTo.getParent() == null && outerRelTo.getCurSharedRef() != null) { outerRelTo = outerRelTo.getCurSharedRef(); } MPartSashContainerElement relTo = null; if (outerRelTo instanceof MArea || onEdge) relTo = (MPartSashContainerElement) outerRelTo; else relTo = targetFolder; //store original container data for using after model operations String containerDataBeforeModelOperations = targetFolder.getContainerData(); // wrap it in a stack if it's a part MPartStack toInsert; MStackElement stackElement = (MStackElement) draggingElement; toInsert = BasicFactoryImpl.eINSTANCE.createPartStack(); toInsert.getChildren().add(stackElement); toInsert.setSelectedElement(stackElement); float pct = (float) (onEdge ? 0.15 : 0.3); MUIElement relToParent = relTo.getParent(); modelService.insert(toInsert, relTo, convert(side), pct); // Force the new sash to have the same weight as the original element if (relTo.getParent() != relToParent && !onEdge) relTo.getParent().setContainerData(containerDataBeforeModelOperations); } } } } }