List of usage examples for com.vaadin.ui TabSheet setCloseHandler
public void setCloseHandler(CloseHandler handler)
From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java
License:Open Source License
@PostConstruct public void createView() { setMargin(true);/* w ww . j ava 2 s . c o m*/ 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.purebred.core.view.FormComponent.java
License:Open Source License
private void initializeOptionalTabs(VerticalLayout layout) { final Set<String> tabNames = getFormFields().getTabNames(); menu = new LayoutContextMenu(layout); for (String tabName : tabNames) { TabSheet.Tab tab = getTabByName(tabName); if (getFormFields().isTabOptional(tabName)) { tab.setClosable(true);// w w w. jav a 2s.c o m menu.addAction(uiMessageSource.getMessage("formComponent.add") + " " + tabName, this, "executeContextAction").setVisible(true); menu.addAction(uiMessageSource.getMessage("formComponent.remove") + " " + tabName, this, "executeContextAction").setVisible(false); setIsRequiredEnable(tabName, false); tab.setVisible(false); } tab.setDescription(uiMessageSource.getMessage("formComponent.tab.description")); } tabSheet.setCloseHandler(new TabSheet.CloseHandler() { @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { String tabName = tabsheet.getTab(tabContent).getCaption(); String actionName = uiMessageSource.getMessage("formComponent.remove") + " " + tabName; executeContextAction(actionName); } }); }
From source file:kn.uni.gis.ui.GameApplication.java
License:Apache License
private Window createGameWindow() { tabsheet = new TabSheet(); tabsheet.setImmediate(true);/*from www.j a v a 2 s . co m*/ tabsheet.setCloseHandler(new CloseHandler() { @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { Game game = ((GameComposite) tabContent).getGame(); GameComposite remove = gameMap.remove(game); // closes the game and the running thread! remove.getLayer().handleApplicationClosedEvent(new ApplicationClosedEvent()); eventBus.unregister(remove); eventBus.unregister(remove.getLayer()); map.removeLayer(remove.getLayer()); tabsheet.removeComponent(tabContent); if (gameMap.isEmpty()) { pi.setVisible(false); } } }); final Window mywindow = new Window("Games"); mywindow.setPositionX(0); mywindow.setPositionY(0); mywindow.setHeight("50%"); mywindow.setWidth("25%"); VerticalLayout layout = new VerticalLayout(); HorizontalLayout lay = new HorizontalLayout(); final Button button_1 = new Button(); button_1.setCaption("Open Game"); button_1.setWidth("-1px"); button_1.setHeight("-1px"); button_1.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { final String id = textField_1.getValue().toString(); if (id.length() < 5) { window.showNotification("id must have at least 5 characters", Notification.TYPE_ERROR_MESSAGE); } else { String sql = String.format("select player_id,player_name,min(timestamp),max(timestamp) from %s" + " where id LIKE ? group by player_id, player_name", GisResource.FOX_HUNTER); final Game game = new Game(id); final PreparedStatement statement = geoUtil.getConn() .prepareStatement("select poly_geom,timestamp from " + GisResource.FOX_HUNTER + " where id LIKE ? and player_id=? and timestamp > ? order by timestamp LIMIT " + MAX_STATES_IN_MEM); try { geoUtil.getConn().executeSafeQuery(sql, new DoWithin() { @Override public void doIt(ResultSet executeQuery) throws SQLException { while (executeQuery.next()) { if (statement == null) { } String playerId = executeQuery.getString(1); Timestamp min = executeQuery.getTimestamp(3); Timestamp max = executeQuery.getTimestamp(4); game.addPlayer(playerId, executeQuery.getString(2), min, max, new TimingIterator(geoUtil, id, playerId, min.getTime(), statement)); } } }, id + "%"); } catch (SQLException e) { LOGGER.info("error on sql!", e); } game.finish(statement); if (!!!gameMap.containsKey(game)) { if (game.getStates().size() == 0) { window.showNotification("game not found!"); } else { LOGGER.info("received game info: {},{} ", game.getId(), game.getStates().size()); GameVectorLayer gameVectorLayer = new GameVectorLayer(GameApplication.this, eventBus, game, createColorMap(game)); final GameComposite gameComposite = new GameComposite(GameApplication.this, game, gameVectorLayer, eventBus); eventBus.register(gameComposite); eventBus.register(gameVectorLayer); map.addLayer(gameVectorLayer); gameMap.put(game, gameComposite); // Add the component to the tab sheet as a new tab. Tab addTab = tabsheet.addTab(gameComposite); addTab.setCaption(game.getId().substring(0, 5)); addTab.setClosable(true); pi.setVisible(true); // pl.get PlayerState playerState = game.getStates().get(game.getFox()).peek(); map.zoomToExtent(new Bounds(CPOINT_TO_POINT.apply(playerState.getPoint()))); } } } } private Map<Player, Integer> createColorMap(Game game) { Function<Double, Double> scale = HardTasks.scale(0, game.getStates().size()); ImmutableMap.Builder<Player, Integer> builder = ImmutableMap.builder(); int i = 0; for (Player play : game.getStates().keySet()) { builder.put(play, getColor(scale.apply((double) i++))); } return builder.build(); } private Integer getColor(double dob) { int toReturn = 0; toReturn = toReturn | 255 - (int) Math.round(255 * dob); toReturn = toReturn | (int) ((Math.round(255 * dob)) << 16); return toReturn; // return (int) (10000 + 35000 * dob + 5000 * dob + 1000 * dob + // 5 * dob); } }); Button button_2 = new Button(); button_2.setCaption("All seeing Hunter"); button_2.setImmediate(false); button_2.setWidth("-1px"); button_2.setHeight("-1px"); button_2.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (adminWindow == null) { adminWindow = new AdminWindow(password, geoUtil, new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { textField_1.setValue(event.getItemId().toString()); mywindow.bringToFront(); button_1.focus(); } }); window.addWindow(adminWindow); adminWindow.setWidth("30%"); adminWindow.setHeight("40%"); adminWindow.addListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { adminWindow = null; } }); } } }); lay.addComponent(button_1); textField_1 = new TextField(); textField_1.setImmediate(false); textField_1.setWidth("-1px"); textField_1.setHeight("-1px"); lay.addComponent(textField_1); lay.addComponent(button_2); lay.addComponent(pi); lay.setComponentAlignment(pi, Alignment.TOP_RIGHT); layout.addComponent(lay); layout.addComponent(tabsheet); mywindow.addComponent(layout); mywindow.setClosable(false); /* Add the window inside the main window. */ return mywindow; }
From source file:org.sensorhub.ui.GenericConfigForm.java
License:Mozilla Public License
protected Component buildTabs(final String propId, final ContainerProperty prop, final FieldGroup fieldGroup) { GridLayout layout = new GridLayout(); layout.setWidth(100.0f, Unit.PERCENTAGE); // title bar/* w ww . j a va 2 s . c o m*/ HorizontalLayout titleBar = new HorizontalLayout(); titleBar.setMargin(new MarginInfo(true, false, false, false)); titleBar.setSpacing(true); String label = prop.getLabel(); if (label == null) label = DisplayUtils.getPrettyName((String) propId); Label sectionLabel = new Label(label); sectionLabel.setDescription(prop.getDescription()); sectionLabel.addStyleName(STYLE_H3); sectionLabel.addStyleName(STYLE_COLORED); titleBar.addComponent(sectionLabel); layout.addComponent(titleBar); // create one tab per item in container final MyBeanItemContainer<Object> container = prop.getValue(); final TabSheet tabs = new TabSheet(); tabs.setSizeFull(); int i = 1; for (Object itemId : container.getItemIds()) { MyBeanItem<Object> childBeanItem = (MyBeanItem<Object>) container.getItem(itemId); IModuleConfigForm subform = AdminUI.getInstance().generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform).setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); Tab tab = tabs.addTab(subform, "Item #" + (i++)); tab.setClosable(true); // store item id so we can map a tab with the corresponding bean item ((AbstractComponent) subform).setData(itemId); } // draw icon on last tab to add new items tabs.addTab(new VerticalLayout(), "", UIConstants.ADD_ICON); // catch close event to delete item tabs.setCloseHandler(new CloseHandler() { private static final long serialVersionUID = 1L; @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { final Tab tab = tabs.getTab(tabContent); final ConfirmDialog popup = new ConfirmDialog( "Are you sure you want to delete " + tab.getCaption() + "?</br>All settings will be lost."); popup.addCloseListener(new CloseListener() { private static final long serialVersionUID = 1L; @Override public void windowClose(CloseEvent e) { if (popup.isConfirmed()) { // retrieve id of item shown on tab AbstractComponent tabContent = (AbstractComponent) tab.getComponent(); Object itemId = tabContent.getData(); // remove from UI int deletedTabPos = tabs.getTabPosition(tab); tabs.removeTab(tab); tabs.setSelectedTab(deletedTabPos - 1); // remove from container container.removeItem(itemId); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } }); // catch select event on '+' tab to add new item tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() { private static final long serialVersionUID = 1L; public void selectedTabChange(SelectedTabChangeEvent event) { Component selectedTab = event.getTabSheet().getSelectedTab(); final Tab tab = tabs.getTab(selectedTab); final int selectedTabPos = tabs.getTabPosition(tab); // case of + tab to add new item if (tab.getCaption().equals("")) { tabs.setSelectedTab(selectedTabPos - 1); try { // show popup to select among available module types String title = "Please select the desired option"; Map<String, Class<?>> typeList = GenericConfigForm.this.getPossibleTypes(propId); ObjectTypeSelectionPopup popup = new ObjectTypeSelectionPopup(title, typeList, new ObjectTypeSelectionCallback() { public void typeSelected(Class<?> objectType) { try { // add new item to container MyBeanItem<Object> childBeanItem = container.addBean( objectType.newInstance(), ((String) propId) + PROP_SEP); // generate form for new item IModuleConfigForm subform = AdminUI.getInstance() .generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform) .setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); // add new tab and select it Tab newTab = tabs.addTab(subform, "Item #" + (selectedTabPos + 1), null, selectedTabPos); newTab.setClosable(true); tabs.setSelectedTab(newTab); } catch (Exception e) { Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } catch (Exception e) { e.printStackTrace(); } } } }); // also register commit handler fieldGroup.addCommitHandler(new CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { // make sure new items are transfered to model prop.setValue(prop.getValue()); } }); layout.addComponent(tabs); return layout; }
From source file:ru.codeinside.adm.ui.AdminApp.java
License:Mozilla Public License
@Override public void init() { setUser(Flash.login());//from w ww . j av a2 s.c o m setTheme("custom"); TabSheet t = new TabSheet(); t.addStyleName(Reindeer.TABSHEET_MINIMAL); t.setSizeFull(); t.setCloseHandler(new DelegateCloseHandler()); UserInfoPanel.addClosableToTabSheet(t, getUser().toString()); TreeTableOrganization treeTableOrganization = new TreeTableOrganization(); CrudNews showNews = new CrudNews(); table = treeTableOrganization.getTreeTable(); Tab orgsTab = t.addTab(treeTableOrganization, ""); t.setSelectedTab(orgsTab); t.addTab(new GroupTab(), ""); GwsSystemTab systemTab = new GwsSystemTab(); t.addTab(systemTab, " ??"); t.addListener(systemTab); GwsLazyTab gwsLazyTab = new GwsLazyTab(); t.addTab(gwsLazyTab, "? ??"); t.addListener(gwsLazyTab); t.addTab(createEmployeeWidget(), ""); RefreshableTab settings = createSettings(); t.addTab(settings, "??"); t.addListener(settings); Component businessCalendar = createBusinessCalendar(); t.addTab(businessCalendar, "? "); LogTab logTab = new LogTab(); t.addListener(logTab); t.addTab(logTab, ""); t.addTab(showNews, "??"); t.addTab(registryTab(), "?"); setMainWindow(new Window( getUser() + " | | -" + Activator.getContext().getBundle().getVersion(), t)); AdminServiceProvider.get().createLog(Flash.getActor(), "Admin application", (String) getUser(), "login", null, true); }
From source file:ru.codeinside.gses.webui.Workplace.java
License:Mozilla Public License
public Workplace(String login, Set<Role> roles, boolean production) { TabSheet tabSheet = new TabSheet(); tabSheet.setSizeFull();// w w w . j av a2 s. c o m tabSheet.setStyleName(Reindeer.TABSHEET_BORDERLESS); tabSheet.setCloseHandler(new DelegateCloseHandler()); if (!production) { new MemoryUsage(tabSheet); } UserInfoPanel.addClosableToTabSheet(tabSheet, login); if (roles.contains(Role.Executor)) { TabChanger archiveChanger = new TabChanger(tabSheet); archiveChanger.set(ArchiveFactory.create(), "?"); TabChanger executorChanger = new TabChanger(tabSheet); executorChanger.set(ExecutorFactory.create(executorChanger, tabSheet), "?"); } if (roles.contains(Role.Declarant)) { new TabChanger(tabSheet).set(DeclarantFactory.create(), " ?"); } if (roles.contains(Role.Supervisor) || roles.contains(Role.SuperSupervisor)) { new TabChanger(tabSheet).set(new SupervisorWorkplace(), " ??"); } if (roles.contains(Role.SuperSupervisor)) { new TabChanger(tabSheet).set(new TaskManager(), "?? ??"); } if (roles.contains(Role.Manager)) { new TabChanger(tabSheet).set(new ManagerWorkplace(), " "); } if (roles.contains(Role.Executor) || roles.contains(Role.Declarant) || roles.contains(Role.Supervisor) || roles.contains(Role.SuperSupervisor)) { SmevTasksPanel smevTasksPanel = new SmevTasksPanel(); tabSheet.addTab(smevTasksPanel, " "); tabSheet.addListener(smevTasksPanel); } setCompositionRoot(tabSheet); setSizeFull(); }