List of usage examples for com.vaadin.ui Component getParent
@Override
public HasComponents getParent();
From source file:org.lucidj.renderer.DefaultObjectRenderer.java
License:Apache License
@Override // CustomComponent protected void setCompositionRoot(Component compositionRoot) { if (compositionRoot == null) // Sanity please {//from w w w . j ava2 s . c om return; } // Avoid the greedy CustomComponent problem HasComponents old_parent = compositionRoot.getParent(); if (old_parent instanceof DefaultObjectRenderer) { DefaultObjectRenderer greedy_parent = (DefaultObjectRenderer) old_parent; if (greedy_parent.getCompositionRoot() == compositionRoot) { // Makes the greedy CustomComponent drop the compositionRoot we need to // assign to another CustomComponent, otherwise we get // IllegalArgumentException: Content is already attached to another parent compositionRoot.setParent(null); } } // We'll catch events sent by the renderer compositionRoot.addListener(new Listener() { @Override public void componentEvent(Event event) { // Bypass all events, so the listeners can be hooked here on the // renderer proxy, while the renderer can be plugged in and out fireEvent(event); } }); // Proceed as intended super.setCompositionRoot(compositionRoot); }
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. * // w w w. ja va2 s .c om * @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.opencms.ui.CmsVaadinUtils.java
License:Open Source License
/** * Gets the window which contains a given component.<p> * * @param component the component//from w w w . j a v a2s.com * @return the window containing the component, or null if no component is found */ public static Window getWindow(Component component) { if (component == null) { return null; } else if (component instanceof Window) { return (Window) component; } else { return getWindow(component.getParent()); } }
From source file:org.opencms.ui.sitemap.CmsSitemapTreeController.java
License:Open Source License
/** * Creates a sitemap tree node widget from a tree node bean.<p> * * @param entry the tree node bean//from w ww.ja v a2 s . c o m * @return the tree node widget */ public CmsSitemapTreeNode createNode(final CmsSitemapTreeNodeData entry) { final CmsSitemapTreeNode node = new CmsSitemapTreeNode(); node.addLayoutClickListener(new LayoutClickListener() { private static final long serialVersionUID = 1L; @SuppressWarnings("synthetic-access") public void layoutClick(LayoutClickEvent event) { Component currentComponent = event.getClickedComponent(); if (currentComponent != null) { boolean linked = false; do { currentComponent = currentComponent.getParent(); if ((currentComponent != null) && "linked".equals(((AbstractComponent) currentComponent).getData())) { linked = true; } if (event.getClickedComponent() instanceof CmsResourceIcon) { if (currentComponent == node) { openTargetPage((CmsSitemapTreeNodeData) (node.getData()), linked); } else if (currentComponent instanceof CmsSitemapTreeNode) { break; } } } while (currentComponent != null); } } }); String icon = CmsResourceIcon.getSitemapResourceIcon(A_CmsUI.getCmsObject(), entry.getResource(), IconMode.localeCompare); CmsResourceInfo info = new CmsResourceInfo(entry.getClientEntry().getTitle(), entry.getClientEntry().getSitePath(), icon); info = CmsResourceInfo.createSitemapResourceInfo(entry.getResource(), OpenCms.getSiteManager().getSiteForRootPath(m_localeContext.getRoot().getRootPath())); info.getResourceIcon().addStyleName(OpenCmsTheme.POINTER); info.getResourceIcon() .setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_OPEN_PAGE_0)); if (entry.getClientEntry().isHiddenNavigationEntry()) { info.addStyleName(OpenCmsTheme.RESOURCE_INFO_WEAK); } final MenuBar menu = new MenuBar(); boolean noTranslation = false; noTranslation = entry.isMarkedNoTranslation(m_localeContext.getComparisonLocale()); final MenuItem main = menu.addItem("", null); main.setIcon(FontOpenCms.CONTEXT_MENU); CssLayout rightSide = new CssLayout(); info.setButtonWidget(rightSide); rightSide.addComponent(menu); main.setCommand(new Command() { /** Serial version id. */ private static final long serialVersionUID = 1L; public void menuSelected(MenuItem selectedItem) { List<I_CmsSimpleContextMenuEntry<MenuContext>> entries = Arrays.asList( new EntryOpen(), new EntryExplorer(), new EntryProperties(), new EntryLink(), new EntryUnlink(), new EntryMark(), new EntryRemoveMark(), new EntryCopy(), new EntryInfo()); MenuContext context = new MenuContext(entry, node); m_menu.setEntries(entries, context); m_menu.open(menu); } }); menu.addStyleName("borderless o-toolbar-button o-resourceinfo-toolbar"); if (entry.isLinked()) { CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(m_localeContext.getRoot().getRootPath()); CmsResourceInfo linkedInfo = CmsResourceInfo .createSitemapResourceInfo(readSitemapEntryFolderIfPossible(entry.getLinkedResource()), site); linkedInfo.addStyleName(OpenCmsTheme.RESOURCE_INFO_DIRECTLINK); rightSide.addComponent(linkedInfo, 0); linkedInfo.setWidth(RHS_WIDTH + "px"); node.setContent(info); linkedInfo.setData("linked"); // Data used by click handler to distinguish clicked resource icons linkedInfo.getResourceIcon() .setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_OPEN_PAGE_0)); linkedInfo.getResourceIcon().addStyleName(OpenCmsTheme.POINTER); } else { if (noTranslation) { CmsResourceInfo noTranslationInfo = new CmsResourceInfo(); String topMessage = CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_NO_TRANSLATION_TOP_0); String bottomMessage = CmsVaadinUtils .getMessageText(Messages.GUI_LOCALECOMPARE_NO_TRANSLATION_BOTTOM_0); noTranslationInfo.getTopLine().setValue(topMessage); noTranslationInfo.getBottomLine().setValue(bottomMessage); noTranslationInfo.getResourceIcon().setValue("<span class=\"" + OpenCmsTheme.RESOURCE_ICON + " " + OpenCmsTheme.NO_TRANSLATION_ICON + "\">" + FontAwesome.BAN.getHtml() + "</span>"); noTranslationInfo.addStyleName(OpenCmsTheme.RESOURCE_INFO_DIRECTLINK); noTranslationInfo.setWidth(RHS_WIDTH + "px"); rightSide.addComponent(noTranslationInfo, 0); } node.setContent(info); } if (entry.hasNoChildren()) { node.setOpen(true); node.setOpenerVisible(false); } node.setData(entry); return node; }
From source file:org.rhegium.vaadin.internal.mvc.ComponentHandler.java
License:Apache License
@Override public void handleEndElement(String uri, String name) { Component innerComponent = currentComponent; currentComponent = components.pop(); if (currentComponent instanceof Panel && innerComponent instanceof ComponentContainer) { ((Panel) currentComponent).setContent((ComponentContainer) innerComponent); } else if (currentComponent instanceof ComponentContainer) { ((ComponentContainer) currentComponent).addComponent(innerComponent); }/*from w ww. j av a 2 s. c om*/ if (expandRatios.size() > 0) { Iterator<Entry<Component, Float>> iterator = expandRatios.entrySet().iterator(); while (iterator.hasNext()) { Entry<Component, Float> entry = iterator.next(); Component expandingComponent = entry.getKey(); if (innerComponent != expandingComponent) { continue; } Component parentComponent = expandingComponent.getParent(); if (!(parentComponent instanceof AbstractOrderedLayout)) { throw new UiBinderException("Cannot set expandRatio for element " + expandingComponent + " since parent is no OrderedLayout"); } Float expandRatio = entry.getValue(); ((AbstractOrderedLayout) parentComponent).setExpandRatio(expandingComponent, expandRatio); iterator.remove(); } } }
From source file:org.semanticsoft.vaaclipse.presentation.renderers.PerspectiveStackRenderer.java
License:Open Source License
private void initializedPerspectiveSwticherPanel(MPerspectiveStack perspectiveStack) { if (perspectiveSwitcherPanel != null) return;/* w w w.j a v a 2s . c o m*/ //initialize perspective switcher panel perspectiveStackForSwitcher = perspectiveStack; boolean iconsOnly = perspectiveStackForSwitcher.getTags().contains(Tags.ICONS_ONLY); perspectiveSwitcherPanel = new HorizontalLayout(); perspectiveSwitcherPanel.setStyleName("perspectivepanel"); perspectiveSwitcherPanel.setSizeUndefined(); Button openPerspectiveButton = new Button("Open"); openPerspectiveButton.addStyleName("vaaclipsebutton"); openPerspectiveButton.addStyleName("icononly"); openPerspectiveButton.setIcon(new ThemeResource("../vaaclipse_default_theme/img/open_perspective.png")); perspectiveSwitcherPanel.addComponent(openPerspectiveButton); openPerspectiveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { openOpenPerspectiveWindow(); //change focus Component parent = event.getButton().getParent(); while (parent != null) { if (parent instanceof Component.Focusable) { ((Component.Focusable) parent).focus(); break; } else { parent = parent.getParent(); } } } }); //add separator between openPerspectiveButton and perspective's buttons Label separator = new Label(); separator.setSizeUndefined(); separator.addStyleName("horizontalseparator"); separator.setHeight("100%"); perspectiveSwitcherPanel.addComponent(separator); //add buttons to perspective switch panel for (final MPerspective perspective : perspectiveStackForSwitcher.getChildren()) { Component button = createPerspectiveButton(perspective); if (button != null) perspectiveSwitcherPanel.addComponent(button); } }
From source file:org.semanticsoft.vaaclipse.presentation.renderers.PlaceholderRenderer.java
License:Open Source License
@Override public void createWidget(MUIElement element, MElementContainer<MUIElement> parent) { MPlaceholder ph = (MPlaceholder) element; final MUIElement ref = ph.getRef(); ref.setCurSharedRef(ph);/*from w ww.j ava 2 s .co m*/ VerticalLayout phComp = new VerticalLayout(); //ExtendedVerticalLayout phComp = new ExtendedVerticalLayout(); phComp.setSizeFull(); phComp.setMargin(false); ph.setWidget(phComp); Component refWidget = (Component) ref.getWidget(); if (refWidget == null) { ref.setToBeRendered(true); refWidget = (Component) renderingEngine.createGui(ref); } if (refWidget.getParent() != phComp) { phComp.addComponent(refWidget); } if (ref instanceof MContext) { IEclipseContext context = ((MContext) ref).getContext(); IEclipseContext newParentContext = getContext(ph); if (context.getParent() != newParentContext) { context.setParent(newParentContext); } } }
From source file:org.semanticsoft.vaaclipse.presentation.renderers.SashRenderer.java
License:Open Source License
public void addSplitPaneListener(MUIElement element) { final MPartSashContainer sash = (MPartSashContainer) element; List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements( sash);/*from ww w.ja v a 2 s . c o m*/ if (renderableAndVisible.size() > 1) { for (MPartSashContainerElement child : renderableAndVisible) { Component childComponent = (Component) child.getWidget(); if (childComponent.getParent() instanceof SashWidget) { SashWidget sashWidget = (SashWidget) childComponent.getParent(); sashWidget.addListener(new SplitPositionChangedListener() { @Override public void processEvent(AbstractSplitPanel splitPanel, float newSplitPos) { AbstractComponent firstWidget = (AbstractComponent) splitPanel.getFirstComponent(); //filter renderable and visible again (list can be changed) List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements( sash); MPartSashContainerElement firstChild = null; double rest_weight = 0; List<MPartSashContainerElement> restChilds = new LinkedList<MPartSashContainerElement>(); for (int i = 0; i < renderableAndVisible.size(); i++) { MPartSashContainerElement child = renderableAndVisible.get(i); if (firstWidget.equals(child.getWidget())) { firstChild = child; } if (firstChild != null) { try { double w = parseContainerData(child.getContainerData()); rest_weight += w; } catch (NumberFormatException e) { logger.error( "Changing weights of SashContainer's childs is failed. Can not parse children container data"); return; } restChilds.add(child); } } if (restChilds.size() > 1) { //String debugstr = "weights: "; ignoreSashWeights = true; double rest_weight_except_first = rest_weight - parseContainerData(firstChild.getContainerData()); double newW1 = (newSplitPos / 100) * rest_weight; double new_rest_weight_except_first = rest_weight - newW1; long longVal1 = Math.round(newW1); firstChild.setContainerData(Long.toString(longVal1)); //debugstr += longVal1; //if the weight of remainder (except first) is not zero, then we distribute the new space appropriate weights if (rest_weight_except_first > 0.0) { for (int i = 1; i < restChilds.size(); i++) { MPartSashContainerElement child = restChilds.get(i); double w = parseContainerData(child.getContainerData()); double newW = (w / rest_weight_except_first) * new_rest_weight_except_first; long longVal = Math.round(newW); child.setContainerData(Long.toString(longVal)); //debugstr += ", " + longVal; } } else //otherwise we assign all new space to the last component { MPartSashContainerElement rest1 = restChilds.get(restChilds.size() - 1); rest1.setContainerData(Long.toString(Math.round(new_rest_weight_except_first))); } ignoreSashWeights = false; //System.out.println(debugstr); //ATTENTION! Really line below is not required if code above works correctly. //But if there are any wrong behaviour appear then we have wrong synchronized state //that may caused side effects, so we do back syncronization (and bug if it occur become obvious). //This is also zeroed weight mismatch occuring when double rounded (and possible when vaadin process changes), //so we avoid mismatch accumulating. //Most likely in the future this will be deleted (when this code will be proved that all ok). setWeights(sash); } else logger.error( "Changing SashContainer child weights is failed. User changes is not processed correctly"); //and last thing what we must do - tell the WorkbenchWindow to recalculate bounds of it content //(because bounds of some content of workbench window changed after sash widget split position changed) MWindow window = modelService.getTopLevelWindowFor(sash); TrimmedWindowContent windowContent = (TrimmedWindowContent) ((Panel) window.getWidget()) .getContent(); windowContent.invalidateBounds(); } }); } else logger.error( "Error in widget hierarchy detected - if sash container has more than one element its child widget must has SashWidget as a parent"); } } }
From source file:org.semanticsoft.vaaclipse.widgets.ToolbarButtonBase.java
License:Open Source License
public ToolbarButtonBase(String label, String iconURI) { this.setSizeUndefined(); setLabelAndIcon(label, iconURI);//from w w w . ja va2s .c om //hack super.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { //change focus Component parent = event.getButton().getParent(); while (parent != null) { if (parent instanceof Component.Focusable) { ((Component.Focusable) parent).focus(); break; } else { parent = parent.getParent(); } } } }); }
From source file:org.semanticsoft.vaaclipse.widgets.TwoStateToolbarButton.java
License:Open Source License
public TwoStateToolbarButton() { setState(false);//from www. j a v a2 s.c om setPrimaryStyle("vaaclipsebutton"); setSelectedStyle("pushed"); super.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { if (switchStateByUserClickEnabled) { setState(!switchOn); for (ClickListener l : userListeners) { l.buttonClick(event); } } //change focus Component parent = event.getButton().getParent(); while (parent != null) { if (parent instanceof Component.Focusable) { ((Component.Focusable) parent).focus(); break; } else { parent = parent.getParent(); } } } }); }