@Override protected ComponentContainer createSectionWidget( ComponentContainer previousSectionWidget, String section, Map<String, String> attributes, ComponentContainer container, VaadinMetawidget metawidget) { TabSheet tabSheet; // Whole new tabbed pane? if (previousSectionWidget == null) { tabSheet = new TabSheet(); tabSheet.setWidth("100%"); // Add to parent container Map<String, String> tabbedPaneAttributes = CollectionUtils.newHashMap(); tabbedPaneAttributes.put(LABEL, ""); tabbedPaneAttributes.put(LARGE, TRUE); getDelegate().layoutWidget(tabSheet, PROPERTY, tabbedPaneAttributes, container, metawidget); } else { tabSheet = (TabSheet) previousSectionWidget.getParent(); } // New tab Panel tabPanel = new Panel(); // Tab name (possibly localized) String localizedSection = metawidget.getLocalizedKey(StringUtils.camelCase(section)); if (localizedSection == null) { localizedSection = section; } tabSheet.addTab(tabPanel, localizedSection, null); return tabPanel; }
public Component processWidget( final Component component, String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) { // Only bind to non-read-only Actions if (!ACTION.equals(elementName)) { return component; } if (component instanceof Stub) { return component; } if (!(component instanceof Button)) { throw WidgetProcessorException.newException( "ReflectionBindingProcessor only supports binding actions to Buttons"); } if (WidgetBuilderUtils.isReadOnly(attributes)) { return component; } if (metawidget == null) { return component; } Object toInspect = metawidget.getToInspect(); if (toInspect == null) { return component; } Button button = (Button) component; // Traverse to the last Object... String[] names = PathUtils.parsePath(metawidget.getPath()).getNamesAsArray(); for (String name : names) { toInspect = ClassUtils.getProperty(toInspect, name); if (toInspect == null) { return component; } } // ...and wire it up final Object fireActionOn = toInspect; final Class<?> fireActionOnClass = fireActionOn.getClass(); final String actionName = attributes.get(NAME); button.addListener( new ClickListener() { public void buttonClick(ClickEvent event) { try { Method method = fireActionOnClass.getMethod(actionName, (Class[]) null); method.invoke(fireActionOn, (Object[]) null); } catch (Exception e) { throw WidgetProcessorException.newException(e); } } }); return component; }