Example usage for com.vaadin.server ClassResource ClassResource

List of usage examples for com.vaadin.server ClassResource ClassResource

Introduction

In this page you can find the example usage for com.vaadin.server ClassResource ClassResource.

Prototype

public ClassResource(Class<?> associatedClass, String resourceName) 

Source Link

Document

Creates a new application resource instance.

Usage

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleTab.java

License:Open Source License

private void init() {

    setMargin(true);/*from w w  w.ja va 2 s . c  o  m*/
    setSpacing(true);

    // ----------------------------------------------------
    // Title
    // ----------------------------------------------------

    HorizontalLayout header = new HorizontalLayout();
    header.setSpacing(true);
    header.setMargin(true);

    Label title = new Label(format("Bundle %d: %s (%s)", bundle.getBundleId(),
            getHeader(bundle, Constants.BUNDLE_NAME), bundle.getVersion()));
    title.addStyleName("h1");
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    addComponent(header);

    // ----------------------------------------------------
    // Action(s) Bar
    // ----------------------------------------------------

    HorizontalLayout actions = new HorizontalLayout();
    if (BundleHelper.isState(bundle, Bundle.INSTALLED) || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
        Button changeState = new Button();
        changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
        //changeState.addStyleName("no-padding");
        changeState.setCaption("Start");
        changeState.setIcon(new ClassResource(getClass(), "/images/32x32/go-next.png"));
        actions.addComponent(changeState);
    }
    if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
        Button changeState = new Button();
        changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
        //changeState.addStyleName("no-padding");
        changeState.setCaption("Stop");
        changeState.setIcon(new ClassResource(getClass(), "/images/32x32/media-record.png"));
        actions.addComponent(changeState);
    }

    // Update
    Button update = new Button();
    update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
    //update.addStyleName("no-padding");
    update.setCaption("Update");
    update.setIcon(new ClassResource(getClass(), "/images/32x32/view-refresh.png"));
    actions.addComponent(update);

    // Trash
    Button trash = new Button();
    trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
    //trash.addStyleName("no-padding");
    trash.setCaption("Remove");
    trash.setIcon(new ClassResource(getClass(), "/images/32x32/user-trash-full.png"));
    actions.addComponent(trash);
    addComponent(actions);
    setComponentAlignment(actions, Alignment.MIDDLE_RIGHT);

    // ----------------------------------------------------
    // Standard Section
    // ----------------------------------------------------

    Table table = new Table();
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    table.setWidth("100%");

    Section mainSection = new Section("Standard", table);
    addComponent(mainSection);

    table.addContainerProperty("label", Label.class, null);
    table.addContainerProperty("value", Label.class, null);

    table.addItem(new Object[] { label("Bundle ID"), label(String.valueOf(bundle.getBundleId())) },
            "bundle.id");
    for (Map.Entry<String, String> entry : HEADERS.entrySet()) {
        String value = getHeader(bundle, entry.getKey());
        if (value != null) {
            table.addItem(new Object[] { label(entry.getValue()), label(value) }, entry.getKey());
        }
    }
    table.addItem(new Object[] { label("Location"), label(bundle.getLocation()) }, "bundle.location");
    Date date = new Date(bundle.getLastModified());
    table.addItem(new Object[] { label("Last Modified"), label(date.toString()) }, "last.modified");

    // ----------------------------------------------------
    // Packages Section
    // ----------------------------------------------------

    FilteredPackageTable exported = new FilteredPackageTable("Exported");

    FilteredPackageTable imported = new FilteredPackageTable("Imported");

    GridLayout packages = new GridLayout(2, 1);
    packages.addComponent(exported);
    packages.addComponent(imported);
    packages.setSpacing(true);
    packages.setWidth("100%");

    Section packagesSection = new Section("Packages", packages);
    addComponent(packagesSection);

    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    if (wiring != null) {
        for (BundleCapability capability : wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
            String name = (String) capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
            Version version = (Version) capability.getAttributes()
                    .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            exported.addPackage(format("%s (%s)", name, version));
        }
        for (BundleRequirement requirement : wiring.getRequirements(PackageNamespace.PACKAGE_NAMESPACE)) {
            String filter = requirement.getDirectives().get(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE);
            imported.addPackage(filter);
        }
    }

    // ----------------------------------------------------
    // Services Section
    // ----------------------------------------------------

    FilteredServiceTable registered = new FilteredServiceTable("Registered");

    FilteredServiceTable used = new FilteredServiceTable("Used Services");

    VerticalLayout services = new VerticalLayout(registered, used);
    services.setSpacing(true);
    services.setWidth("100%");

    ServiceReference<?>[] registeredServices = bundle.getRegisteredServices();
    if (registeredServices != null) {
        for (ServiceReference<?> reference : registeredServices) {
            registered.addService(reference);
        }
    }

    ServiceReference<?>[] inUseServices = bundle.getServicesInUse();
    if (inUseServices != null) {
        for (ServiceReference<?> reference : inUseServices) {
            used.addService(reference);
        }
    }

    if (!registered.isEmpty() || !used.isEmpty()) {
        Section servicesSection = new Section("Services", services);
        addComponent(servicesSection);
    }

    // ----------------------------------------------------
    // Raw Manifest Section
    // ----------------------------------------------------

    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".monospaced-font {font-family: monospace !important; }");

    Table manifest = new Table();
    manifest.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    manifest.setWidth("100%");
    manifest.addStyleName("monospaced-font");
    manifest.setPageLength(15);
    manifest.addContainerProperty("name", String.class, null);
    manifest.addContainerProperty("value", String.class, null);

    Dictionary<String, String> headers = bundle.getHeaders();
    for (String key : Collections.list(headers.keys())) {
        manifest.addItem(new Object[] { key, headers.get(key) }, null);
    }

    Section manifestSection = new Section("Manifest", manifest);
    addComponent(manifestSection);

}

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java

License:Open Source License

@PostConstruct
public void createView() {
    setMargin(true);//w  w w.j  a  v  a  2  s  .c om
    setSpacing(true);

    /*
    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".no-padding {padding: 0em 0em 0em 0em !important; }");
    */

    HorizontalLayout header = new HorizontalLayout();
    //        header.setWidth("100%");
    header.setSpacing(true);
    header.setMargin(true);

    Label title = new Label("OSGi Bundles");
    title.addStyleName("h1");
    //        title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(BUNDLE_ID_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_NAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_SYMBOLICNAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(VERSION_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(PRETTY_STATE_COLUMN, trimmed, true, false));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);

    addComponent(tabSheet);

    table = new Table();
    table.setContainerDataSource(data);
    table.setSizeFull();
    table.setSortContainerPropertyId(BUNDLE_ID_COLUMN);
    table.setSortAscending(true);
    table.setImmediate(true);
    table.setColumnHeader(BUNDLE_ID_COLUMN, "Bundle ID");
    table.setColumnHeader(PRETTY_NAME_COLUMN, "Bundle Name");
    table.setColumnHeader(VERSION_COLUMN, "Version");
    table.setColumnHeader(PRETTY_STATE_COLUMN, "State");
    table.setColumnHeader("actions", "Actions");

    table.setColumnWidth(BUNDLE_ID_COLUMN, 100);

    table.setColumnAlignment(BUNDLE_ID_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(PRETTY_STATE_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(VERSION_COLUMN, Table.Align.CENTER);

    table.addGeneratedColumn("actions", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(final Table source, final Object itemId, final Object columnId) {
            HorizontalLayout layout = new HorizontalLayout();
            BeanItem<BundleItem> item = (BeanItem<BundleItem>) source.getContainerDataSource().getItem(itemId);
            Bundle bundle = item.getBean().getBundle();
            if (BundleHelper.isState(bundle, Bundle.INSTALLED)
                    || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
                Button changeState = new Button();
                changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Start");
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/go-next.png"));
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                layout.addComponent(changeState);
            }
            if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
                Button changeState = new Button();
                changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Stop");
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/media-record.png"));
                layout.addComponent(changeState);
            }

            // Update
            Button update = new Button();
            update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
            //update.addStyleName("no-padding");
            update.setCaption("Update");
            if (!securityManager.isUserInRole("admin")) {
                update.setDisableOnClick(true);
            }
            //update.setIcon(new ClassResource(BundleViewer.class, "/images/view-refresh.png"));
            layout.addComponent(update);

            // Trash
            Button trash = new Button();
            trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
            //trash.addStyleName("no-padding");
            trash.setCaption("Delete");
            if (!securityManager.isUserInRole("admin")) {
                trash.setDisableOnClick(true);
            }
            //trash.setIcon(new ClassResource(BundleViewer.class, "/images/user-trash-full.png"));
            layout.addComponent(trash);

            return layout;
        }
    });

    table.setVisibleColumns(BUNDLE_ID_COLUMN, PRETTY_NAME_COLUMN, VERSION_COLUMN, PRETTY_STATE_COLUMN,
            "actions");

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(final ItemClickEvent event) {
            if (event.isDoubleClick()) {
                BeanItem<BundleItem> item = (BeanItem<BundleItem>) table.getContainerDataSource()
                        .getItem(event.getItemId());
                Bundle bundle = item.getBean().getBundle();
                showBundle(bundle);
            }
        }
    });

    createBundleTracker();

    tabSheet.setSizeFull();
    selectedTabListener = new SelectedTabListener(uiContext.getViewNavigator());
    selectedTabListener.addLocation(table, uiContext.getViewNavigator().getLocation(this.getClass().getName()));
    tabSheet.addSelectedTabChangeListener(selectedTabListener);
    tabSheet.addTab(table, "Bundles", new ClassResource(BundleView.class, "/images/22x22/user-home.png"));
    setExpandRatio(tabSheet, 1.5f);

    tabSheet.setCloseHandler(new TabSheet.CloseHandler() {
        @Override
        public void onTabClose(TabSheet tabsheet, Component tabContent) {
            for (Map.Entry<Long, Component> tab : openTabs.entrySet()) {
                if (tabContent.equals(tab.getValue())) {
                    openTabs.remove(tab.getKey());
                }
            }
            tabsheet.removeComponent(tabContent);
            selectedTabListener.removeLocation(tabContent);
        }
    });
}

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java

License:Open Source License

private void showBundle(Bundle bundle) {
    Component tab;/*  w w w  . ja  v  a2 s.  co  m*/
    if (!openTabs.containsKey(bundle.getBundleId())) {
        tab = new BundleTab(bundle, notifierService);
        tabSheet.addTab(tab, "Bundle " + bundle.getBundleId(),
                new ClassResource(BundleView.class, "/images/22x22/package-x-generic.png")).setClosable(true);
        openTabs.put(bundle.getBundleId(), tab);
        selectedTabListener.addLocation(tab, uiContext.getViewNavigator().getLocation(this.getClass().getName())
                + "/" + bundle.getBundleId());
    } else {
        tab = openTabs.get(bundle.getBundleId());
    }
    tabSheet.setSelectedTab(tab);
}

From source file:com.peergreen.webconsole.vaadin.tabs.TabScope.java

License:Open Source License

/**
 * Add extension tab//w ww.ja v  a 2s . com
 *
 * @param tab        extension
 * @param properties extension properties
 */
@Link("tab")
public void addTabs(Component tab, Dictionary properties) {
    tab.setSizeFull();
    String tabName = (String) properties.get("tab.value");
    String imgLocation = (String) properties.get("tab.imgPath");

    addTab(tab, tabName).setClosable(true);
    if (imgLocation != null && !"".equals(imgLocation)) {
        defaultTab.addExtension(tab, tabName, new ClassResource(tab.getClass(), imgLocation));
    } else {
        defaultTab.addExtension(tab, tabName);
    }

    String alias = (String) properties.get(Constants.EXTENSION_ALIAS);
    if (alias != null) {
        if (navigable) {
            selectedTabListener.addLocation(tab,
                    uiContext.getViewNavigator().getLocation(tab.getClass().getName()));
        }
        components.put(alias, tab);
    }
}

From source file:nz.co.senanque.perspectiveslibrary.SubApplicationimpl.java

License:Apache License

public Resource getIcon() {
    return new ClassResource(m_appFactory.getClass(), "/icon.png");
}

From source file:org.lucidj.httpservices.HttpServices.java

License:Apache License

@Override // MenuProvider
public void buildMenuEntries(MenuInstance menu, Map<String, Object> properties) {
    // The explicit class is used to bind the resource with its source bundle
    Resource icon = new ClassResource(this.getClass(), "META-INF/http-icon-32.svg");
    menu.addMenuEntry(menu.newMenuEntry("Http Services", icon, 250, NAVID));
}

From source file:org.vaadin.addon.ewopener.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button1 = new Button("Click me");
    button1.addClickListener(e -> {//from   w w w.  ja  v a 2  s .  c o m
        opener1.open(generateResource());
    });
    opener1.extend(button1);

    EnhancedBrowserWindowOpener opener4 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button4 = new Button("Nothing to open here");
    button4.addClickListener(e -> {
        opener4.open((Resource) null);
    });
    opener4.extend(button4);

    Button button2 = new Button("Click me");
    button2.addClickListener(e -> {
        EnhancedBrowserWindowOpener.extendOnce(button2).open(generateResource());
    });

    Button button3 = new Button("Click me");
    EnhancedBrowserWindowOpener opener3 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(button3);
    button3.addClickListener(opener3::open);

    Link link = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(link);

    Link link2 = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent, resource -> {
                resource.setCacheTime(0);
                resource.setFilename("runtimeFileName-" + Instant.now().getEpochSecond() + ".txt");
            }).doExtend(link2);

    EnhancedBrowserWindowOpener opener5 = new EnhancedBrowserWindowOpener(
            new ClassResource(DemoUI.class, "static.txt"));
    CssLayout hiddenComponent = new MCssLayout().withWidth("0").withHeight("0");
    opener5.extend(hiddenComponent);
    CompletableFuture.runAsync(this::doSomeLongProcessing).thenRun(() -> getUI().access(opener5::open));

    table = new Table("Select items to download",
            new BeanItemContainer<>(DummyService.Person.class, DummyService.data()));
    table.setImmediate(true);
    table.setVisibleColumns("name", "age");
    table.setColumnHeaders("Name", "Age");
    table.setWidth("100%");
    table.setPageLength(20);
    table.setMultiSelectMode(MultiSelectMode.DEFAULT);
    table.setMultiSelect(true);
    table.setSelectable(true);

    final MyPopupContent popupContent = new MyPopupContent();
    Button popupButton = new Button("Open modal", event -> {
        Window window = new Window("Test", popupContent);
        window.setWidth(40, Sizeable.Unit.PERCENTAGE);
        window.setHeight(200, Sizeable.Unit.PIXELS);
        window.setModal(true);
        window.setDraggable(false);
        window.setResizable(false);
        window.center();
        getUI().addWindow(window);
    });

    MenuBar.Command cmd = selectedItem -> Notification.show("Item clicked",
            "Item is " + selectedItem.getDescription(), Notification.Type.TRAY_NOTIFICATION);
    MenuBar menuBar = new MenuBar();
    menuBar.setSizeFull();
    EnhancedBrowserWindowOpener opener6 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-serverside.txt", this::generateContent)
            .popupBlockerWorkaround(true);
    EnhancedBrowserWindowOpener opener7 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-1.txt", this::generateContent).clientSide(true);
    EnhancedBrowserWindowOpener opener8 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-2.txt", this::generateContent).clientSide(true);
    MenuBar.MenuItem menuItem = menuBar.addItem("Download from Menu (Client side)", selectedItem -> {
        System.out.println("OK, Invoked");
    });
    MenuBar.MenuItem subMenu = menuBar.addItem("Sub menu", null);
    subMenu.addItem("Item 1", cmd);
    subMenu.addItem("Item 2", cmd);
    MenuBar.MenuItem subItem = subMenu.addItem("Download (client side)", cmd);
    MenuBar.MenuItem subItem2 = subMenu.addItem("Download (server side)", selectedItem -> opener6.open());
    opener7.doExtend(menuBar, menuItem);
    opener6.doExtend(menuBar, subItem2);
    opener8.doExtend(menuBar, subItem);

    // Show it in the middle of the screen
    final Layout layout = new MVerticalLayout(
            new MLabel("Enhanced Window Opener Demo").withStyleName(ValoTheme.LABEL_COLORED,
                    ValoTheme.LABEL_H1),
            new MHorizontalLayout().add(table, 1)
                    .add(new MCssLayout(menuBar, readMarkdown("code_menu.md").withFullWidth(),
                            new MVerticalLayout(readMarkdown("code1.md"), button1)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code2.md"), button2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code7.md"), button3)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code5.md"), link)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code6.md"), link2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code3.md"), button4)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code8.md"), popupButton)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code4.md"), hiddenComponent)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false))
                                            .withFullWidth().withStyleName("demo-samples"),
                            5)
                    .withFullWidth()).withFullWidth().withMargin(true);

    setContent(layout);

}

From source file:org.vaadin.addons.lazyquerycontainer.example.mock.VaadinApplication.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setMargin(true);/*from  w w w.j  a v  a  2 s.c o  m*/
    mainLayout.setSpacing(true);
    setContent(mainLayout);

    Panel buttonPanel = new Panel();
    buttonPanel.addStyleName(Runo.PANEL_LIGHT);
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setMargin(false);
    buttonLayout.setSpacing(true);
    buttonPanel.setContent(buttonLayout);
    mainLayout.addComponent(buttonPanel);

    Panel buttonPanel2 = new Panel();
    buttonPanel2.addStyleName(Runo.PANEL_LIGHT);
    HorizontalLayout buttonLayout2 = new HorizontalLayout();
    buttonLayout2.setMargin(false);
    buttonLayout2.setSpacing(true);
    buttonPanel2.setContent(buttonLayout2);
    mainLayout.addComponent(buttonPanel2);

    refreshButton = new Button("Refresh");
    refreshButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/table_refresh.png"));
    refreshButton.addClickListener(this);
    buttonLayout.addComponent(refreshButton);

    editButton = new Button("Edit");
    editButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/table_edit.png"));
    editButton.addClickListener(this);
    buttonLayout.addComponent(editButton);

    addPropertyButton = new Button("Add Column");
    addPropertyButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/tab_add.png"));
    addPropertyButton.addClickListener(this);
    buttonLayout.addComponent(addPropertyButton);

    removeAllItemsButton = new Button("Remove All Rows");
    removeAllItemsButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/delete.png"));
    removeAllItemsButton.addClickListener(this);
    buttonLayout.addComponent(removeAllItemsButton);

    saveButton = new Button("Save");
    saveButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/table_save.png"));
    saveButton.addClickListener(this);
    saveButton.setEnabled(false);
    buttonLayout2.addComponent(saveButton);

    cancelButton = new Button("Cancel");
    cancelButton.setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/cancel.png"));
    cancelButton.addClickListener(this);
    cancelButton.setEnabled(false);
    buttonLayout2.addComponent(cancelButton);

    addItemButton = new Button("Add Row");
    addItemButton
            .setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/table_row_insert.png"));
    addItemButton.addClickListener(this);
    addItemButton.setEnabled(false);
    buttonLayout2.addComponent(addItemButton);

    removeItemButton = new Button("Remove Row");
    removeItemButton
            .setIcon(new ClassResource(QueryItemStatusColumnGenerator.class, "images/table_row_delete.png"));
    removeItemButton.addClickListener(this);
    removeItemButton.setEnabled(false);
    buttonLayout2.addComponent(removeItemButton);

    table = new Table();
    mainLayout.addComponent(table);

    table.setPageLength(20);

    mockQueryFactory = new MockQueryFactory(2000, 10, 20);
    container = new LazyQueryContainer(new LazyQueryDefinition(true, 50, "Index"), mockQueryFactory);

    container.addContainerProperty(LazyQueryView.PROPERTY_ID_ITEM_STATUS, QueryItemStatus.class,
            QueryItemStatus.None, true, false);
    container.addContainerProperty("Index", Integer.class, 0, true, true);
    container.addContainerProperty("ReverseIndex", Integer.class, 0, true, true);
    container.addContainerProperty("Editable", String.class, "", false, false);
    container.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_QUERY_INDEX, Integer.class, 0, true, false);
    container.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_INDEX, Integer.class, 0, true, false);
    container.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_QUERY_TIME, Long.class, 0, true,
            false);

    table.setContainerDataSource(container);

    visibleColumnIds.add(LazyQueryView.PROPERTY_ID_ITEM_STATUS);
    visibleColumnIds.add("Index");
    visibleColumnIds.add("ReverseIndex");
    visibleColumnIds.add("Editable");
    visibleColumnIds.add(LazyQueryView.DEBUG_PROPERTY_ID_QUERY_INDEX);
    visibleColumnIds.add(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_INDEX);
    visibleColumnIds.add(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_QUERY_TIME);

    visibleColumnLabels.add("");
    visibleColumnLabels.add("Index");
    visibleColumnLabels.add("Reverse Index");
    visibleColumnLabels.add("Editable");
    visibleColumnLabels.add("Query");
    visibleColumnLabels.add("Batch");
    visibleColumnLabels.add("Time [ms]");

    table.setColumnWidth("Editable", 135);

    table.setVisibleColumns(visibleColumnIds.toArray());
    table.setColumnHeaders(visibleColumnLabels.toArray(new String[0]));

    table.setColumnWidth(LazyQueryView.PROPERTY_ID_ITEM_STATUS, 16);
    table.addGeneratedColumn(LazyQueryView.PROPERTY_ID_ITEM_STATUS, new QueryItemStatusColumnGenerator());

    table.setEditable(false);
    table.setMultiSelect(true);
    table.setMultiSelectMode(MultiSelectMode.DEFAULT);
    table.setSelectable(true);
    //table.setWriteThrough(true);
}

From source file:org.vaadin.addons.lazyquerycontainer.QueryItemStatusColumnGenerator.java

License:Apache License

/**
 * Generates cell component.//from  w  w w  . jav  a  2  s. co  m
 *
 * @param source   The table this cell is generated for.
 * @param itemId   ID of the item this cell is presenting property of.
 * @param columnId ID of the column this cell is located at.
 * @return Component used to render this cell.
 */
public Component generateCell(final Table source, final Object itemId, final Object columnId) {
    Property statusProperty = source.getItem(itemId).getItemProperty(columnId);

    noneIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield.png");
    addedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield_add.png");
    modifiedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class,
            "images/textfield_rename.png");
    removedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class,
            "images/textfield_delete.png");

    statusIcon = new Image(null, noneIconResource);
    statusIcon.setHeight("16px");

    if (statusProperty instanceof ValueChangeNotifier) {
        ValueChangeNotifier notifier = (ValueChangeNotifier) statusProperty;
        notifier.addValueChangeListener(this);
    }

    refreshImage(statusProperty);

    return statusIcon;
}

From source file:org.vaadin.overlay.sample.OverlaySampleApplication.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout();

    final Label label = new Label("Alignment.TOP_LEFT");
    layout.addComponent(label);//from   w  w  w .  jav a2s .  c o  m

    for (int i = 0; i < 20; i++) {

        Button button = new Button("Sample Button");
        layout.addComponent(button);

        final ImageOverlay io = new ImageOverlay(button);

        Resource res = new ClassResource(this.getClass(), "../icon-new.png");
        io.setImage(res);
        io.setComponentAnchor(Alignment.TOP_LEFT); // Top left of the button
        io.setOverlayAnchor(Alignment.MIDDLE_CENTER); // Center of the image
        io.setClickListener(new OverlayClickListener() {
            public void overlayClicked(CustomClickableOverlay overlay) {
                Notification.show("ImageOverlay Clicked!");
            }
        });
        layout.addComponent(io);
        io.setEnabled(true);

        final TextOverlay to = new TextOverlay(button, "New!");
        to.setComponentAnchor(Alignment.MIDDLE_RIGHT); // Top right of the button
        to.setOverlayAnchor(Alignment.MIDDLE_CENTER); // Center of the image
        to.setClickListener(new OverlayClickListener() {
            public void overlayClicked(CustomClickableOverlay overlay) {
                Notification.show("TextOverlay Clicked!");
            }
        });
        layout.addComponent(to);

        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                Alignment a = io.getComponentAnchor();
                String s = "";
                if (Alignment.TOP_LEFT.equals(a)) {
                    a = Alignment.TOP_CENTER;
                    s = "TOP_CENTER";
                } else if (Alignment.TOP_CENTER.equals(a)) {
                    a = Alignment.TOP_RIGHT;
                    s = "TOP_RIGHT";
                } else if (Alignment.TOP_RIGHT.equals(a)) {
                    a = Alignment.MIDDLE_RIGHT;
                    s = "MIDDLE_RIGHT";
                } else if (Alignment.MIDDLE_RIGHT.equals(a)) {
                    a = Alignment.BOTTOM_RIGHT;
                    s = "BOTTOM_RIGHT";
                } else if (Alignment.BOTTOM_RIGHT.equals(a)) {
                    a = Alignment.BOTTOM_CENTER;
                    s = "BOTTOM_CENTER";
                } else if (Alignment.BOTTOM_CENTER.equals(a)) {
                    a = Alignment.BOTTOM_LEFT;
                    s = "BOTTOM_LEFT";
                } else if (Alignment.BOTTOM_LEFT.equals(a)) {
                    a = Alignment.MIDDLE_LEFT;
                    s = "MIDDLE_LEFT";
                } else if (Alignment.MIDDLE_LEFT.equals(a)) {
                    a = Alignment.TOP_LEFT;
                    s = "TOP_LEFT";
                }
                io.setComponentAnchor(a);
                label.setValue("Alignment." + s);
            }
        });
    }

    setContent(layout);
}