Example usage for com.vaadin.ui Window setModal

List of usage examples for com.vaadin.ui Window setModal

Introduction

In this page you can find the example usage for com.vaadin.ui Window setModal.

Prototype

public void setModal(boolean modal) 

Source Link

Document

Sets window modality.

Usage

From source file:annis.gui.admin.GroupManagementPanel.java

License:Apache License

public GroupManagementPanel() {
    groupsContainer.setBeanIdProperty("name");

    progress = new ProgressBar();
    progress.setCaption("Loading group list");
    progress.setIndeterminate(true);/*ww w .j  a v a 2s.  c o  m*/
    progress.setVisible(false);

    GeneratedPropertyContainer generated = new GeneratedPropertyContainer(groupsContainer);
    generated.addGeneratedProperty("edit", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Edit";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    groupsGrid.setContainerDataSource(generated);
    groupsGrid.setSelectionMode(Grid.SelectionMode.MULTI);
    groupsGrid.setSizeFull();
    groupsGrid.setColumns("name", "edit", "corpora");

    Grid.HeaderRow filterRow = groupsGrid.appendHeaderRow();
    TextField groupFilterField = new TextField();
    groupFilterField.setInputPrompt("Filter");
    groupFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            groupsContainer.removeContainerFilters("name");
            if (!event.getText().isEmpty()) {
                groupsContainer
                        .addContainerFilter(new SimpleStringFilter("name", event.getText(), true, false));
            }
        }
    });
    filterRow.getCell("name").setComponent(groupFilterField);

    TextField corpusFilterField = new TextField();
    corpusFilterField.setInputPrompt("Filter by corpus");
    corpusFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            groupsContainer.removeContainerFilters("corpora");
            if (!event.getText().isEmpty()) {
                groupsContainer.addContainerFilter(new StringPatternInSetFilter("corpora", event.getText()));
            }
        }
    });
    filterRow.getCell("corpora").setComponent(corpusFilterField);

    Grid.Column editColumn = groupsGrid.getColumn("edit");
    editColumn.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {
            Group g = groupsContainer.getItem(event.getItemId()).getBean();

            FieldGroup fields = new FieldGroup(groupsContainer.getItem(event.getItemId()));
            fields.addCommitHandler(new GroupCommitHandler(g.getName()));

            EditSingleGroup edit = new EditSingleGroup(fields, corpusContainer);

            Window w = new Window("Edit group \"" + g.getName() + "\"");
            w.setContent(edit);
            w.setModal(true);
            w.setWidth("500px");
            w.setHeight("250px");
            UI.getCurrent().addWindow(w);
        }
    }));

    Grid.Column corporaColumn = groupsGrid.getColumn("corpora");
    ;
    corporaColumn.setConverter(new CommaSeperatedStringConverterSet());

    txtGroupName = new TextField();
    txtGroupName.setInputPrompt("New group name");

    Button btAddNewGroup = new Button("Add new group");
    btAddNewGroup.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            handleAdd();
        }
    });
    btAddNewGroup.addStyleName(ChameleonTheme.BUTTON_DEFAULT);

    Button btDeleteGroup = new Button("Delete selected group(s)");
    btDeleteGroup.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get selected groups
            Set<String> selectedGroups = new TreeSet<>();
            for (Object id : groupsGrid.getSelectedRows()) {
                selectedGroups.add((String) id);
            }
            groupsGrid.getSelectionModel().reset();
            for (GroupListView.Listener l : listeners) {
                l.deleteGroups(selectedGroups);
            }
        }
    });

    actionLayout = new HorizontalLayout(txtGroupName, btAddNewGroup, btDeleteGroup);

    VerticalLayout layout = new VerticalLayout(actionLayout, progress, groupsGrid);
    layout.setSizeFull();
    layout.setExpandRatio(groupsGrid, 1.0f);
    layout.setExpandRatio(progress, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(actionLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(progress, Alignment.TOP_CENTER);

    setContent(layout);
    setSizeFull();

    addActionHandler(new AddGroupHandler(txtGroupName));
}

From source file:annis.gui.admin.UserManagementPanel.java

License:Apache License

public UserManagementPanel() {

    userContainer = new BeanContainer<>(User.class);
    userContainer.setBeanIdProperty("name");

    progress = new ProgressBar();
    progress.setCaption("Loading user list");
    progress.setIndeterminate(true);/*  w  w  w .j  a v  a2s .  c  o m*/
    progress.setVisible(false);

    GeneratedPropertyContainer generated = new GeneratedPropertyContainer(userContainer);
    generated.addGeneratedProperty("edit", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Edit";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    generated.addGeneratedProperty("changePassword", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Change password";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    userList = new Grid(generated);
    userList.setSizeFull();
    userList.setSelectionMode(Grid.SelectionMode.MULTI);
    userList.setColumns("name", "edit", "changePassword", "expires", "groups", "permissions");

    HeaderRow filterRow = userList.appendHeaderRow();
    TextField userFilterField = new TextField();
    userFilterField.setInputPrompt("Filter");
    userFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("name");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(new SimpleStringFilter("name", event.getText(), true, false));
            }
        }
    });
    filterRow.getCell("name").setComponent(userFilterField);

    CheckBox expiredFilterField = new CheckBox("has expired");
    expiredFilterField.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            userContainer.removeContainerFilters("expires");
            if ((Boolean) event.getProperty().getValue() == true) {
                userContainer.addContainerFilter(new ExpiredUserFilter("expires"));
            }
        }
    });
    filterRow.getCell("expires").setComponent(expiredFilterField);

    TextField groupFilterField = new TextField();
    groupFilterField.setInputPrompt("Filter by groups");
    groupFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("groups");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(
                        new GroupManagementPanel.StringPatternInSetFilter("groups", event.getText()));
            }
        }
    });
    filterRow.getCell("groups").setComponent(groupFilterField);

    Grid.Column editColum = userList.getColumn("edit");
    editColum.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {

            User u = userContainer.getItem(event.getItemId()).getBean();

            FieldGroup group = new FieldGroup(userContainer.getItem(event.getItemId()));
            group.addCommitHandler(new UserCommitHandler(u.getName()));

            EditSingleUser edit = new EditSingleUser(group, groupsContainer, permissionsContainer);

            Window w = new Window("Edit user \"" + u.getName() + "\"");
            w.setContent(edit);
            w.setModal(true);
            w.setWidth("500px");
            w.setHeight("400px");
            UI.getCurrent().addWindow(w);
        }
    }));
    editColum.setHeaderCaption("");
    editColum.setExpandRatio(0);

    Grid.Column passwordColumn = userList.getColumn("changePassword");
    passwordColumn.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {
            UserManagementPanel.this.askForPasswordChange((String) event.getItemId());
        }
    }));
    passwordColumn.setHeaderCaption("");
    passwordColumn.setExpandRatio(0);

    userList.getColumn("name").setHeaderCaption("Username");

    Grid.Column groupsColumm = userList.getColumn("groups");
    groupsColumm.setHeaderCaption("Groups");
    groupsColumm.setConverter(new CommaSeperatedStringConverterSet());
    groupsColumm.setExpandRatio(1);

    Grid.Column permissionsColumn = userList.getColumn("permissions");
    permissionsColumn.setHeaderCaption("Additional permissions");
    permissionsColumn.setConverter(new CommaSeperatedStringConverterSet());

    Grid.Column expiresColumn = userList.getColumn("expires");
    expiresColumn.setHeaderCaption("Expiration Date");
    expiresColumn.setConverter(new DateTimeStringConverter());

    txtUserName = new TextField();
    txtUserName.setInputPrompt("New user name");

    Button btAddNewUser = new Button("Add new user");
    btAddNewUser.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            handleAdd();
        }
    });
    btAddNewUser.addStyleName(ChameleonTheme.BUTTON_DEFAULT);

    Button btDeleteUser = new Button("Delete selected user(s)");
    btDeleteUser.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get selected users
            Set<String> selectedUsers = new TreeSet<>();
            for (Object id : userList.getSelectedRows()) {
                selectedUsers.add((String) id);
            }
            userList.getSelectionModel().reset();
            for (UserListView.Listener l : listeners) {
                l.deleteUsers(selectedUsers);
            }
        }
    });

    actionLayout = new HorizontalLayout(txtUserName, btAddNewUser, btDeleteUser);

    layout = new VerticalLayout(actionLayout, progress, userList);
    layout.setSizeFull();
    layout.setExpandRatio(userList, 1.0f);
    layout.setExpandRatio(progress, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(actionLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(progress, Alignment.TOP_CENTER);

    setContent(layout);
    setSizeFull();

    addActionHandler(new AddUserHandler(txtUserName));

}

From source file:annis.gui.controlpanel.CorpusListPanel.java

License:Apache License

public void initCorpusBrowser(String topLevelCorpusName, final Button l) {

    AnnisCorpus c = ui.getQueryState().getAvailableCorpora().getItem(topLevelCorpusName).getBean();
    MetaDataPanel meta = new MetaDataPanel(c.getName());

    CorpusBrowserPanel browse = new CorpusBrowserPanel(c, ui.getQueryController());
    GridLayout infoLayout = new GridLayout(2, 2);
    infoLayout.setSizeFull();/*from   w  w  w  .  j  a  v a2  s .co m*/

    String corpusURL = Helper.generateCorpusLink(Sets.newHashSet(topLevelCorpusName));
    Label lblLink = new Label("Link to corpus: <a href=\"" + corpusURL + "\">" + corpusURL + "</a>",
            ContentMode.HTML);
    lblLink.setHeight("-1px");
    lblLink.setWidth("-1px");

    infoLayout.addComponent(meta, 0, 0);
    infoLayout.addComponent(browse, 1, 0);
    infoLayout.addComponent(lblLink, 0, 1, 1, 1);

    infoLayout.setRowExpandRatio(0, 1.0f);
    infoLayout.setColumnExpandRatio(0, 0.5f);
    infoLayout.setColumnExpandRatio(1, 0.5f);
    infoLayout.setComponentAlignment(lblLink, Alignment.MIDDLE_CENTER);

    Window window = new Window("Corpus information for " + c.getName() + " (ID: " + c.getId() + ")",
            infoLayout);
    window.setWidth(70, UNITS_EM);
    window.setHeight(45, UNITS_EM);
    window.setResizable(true);
    window.setModal(false);
    window.setResizeLazy(true);

    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            l.setEnabled(true);
        }
    });

    UI.getCurrent().addWindow(window);
    window.center();
}

From source file:annis.gui.MainToolbar.java

License:Apache License

public MainToolbar() {

    String bugmail = (String) VaadinSession.getCurrent().getAttribute(BUG_MAIL_KEY);
    if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${")
            && new EmailValidator("").isValid(bugmail)) {
        this.bugEMailAddress = bugmail;
    } else {//  www.j  a  va  2 s .c om
        this.bugEMailAddress = null;
    }

    UI ui = UI.getCurrent();
    if (ui instanceof CommonUI) {
        ((CommonUI) ui).getSettings().addedLoadedListener(MainToolbar.this);
    }

    setWidth("100%");
    setHeight("-1px");

    addStyleName("toolbar");
    addStyleName("border-layout");

    btAboutAnnis = new Button("About ANNIS");
    btAboutAnnis.addStyleName(ValoTheme.BUTTON_SMALL);
    btAboutAnnis.setIcon(new ThemeResource("images/annis_16.png"));
    btAboutAnnis.addClickListener(new AboutClickListener());

    btSidebar = new Button();
    btSidebar.setDisableOnClick(true);
    btSidebar.addStyleName(ValoTheme.BUTTON_SMALL);
    btSidebar.setDescription("Show and hide search sidebar");
    btSidebar.setIconAlternateText(btSidebar.getDescription());

    btBugReport = new Button("Report Problem");
    btBugReport.addStyleName(ValoTheme.BUTTON_SMALL);
    btBugReport.setDisableOnClick(true);
    btBugReport.setIcon(FontAwesome.ENVELOPE_O);
    btBugReport.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            reportBug();
        }
    });
    btBugReport.setVisible(this.bugEMailAddress != null);

    btNavigate = new Button();
    btNavigate.setVisible(false);
    btNavigate.setDisableOnClick(true);
    btNavigate.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            btNavigate.setEnabled(true);
            if (navigationTarget != null) {
                UI.getCurrent().getNavigator().navigateTo(navigationTarget.state);
            }
        }
    });
    lblUserName = new Label("not logged in");
    lblUserName.setWidth("-1px");
    lblUserName.setHeight("-1px");
    lblUserName.addStyleName("right-aligned-text");

    btLogin = new Button("Login", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            showLoginWindow(false);
        }
    });

    btLogout = new Button("Logout", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            // logout
            Helper.setUser(null);
            for (LoginListener l : loginListeners) {
                l.onLogout();
            }
            Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION);
            updateUserInformation();
        }
    });

    btLogin.setSizeUndefined();
    btLogin.setStyleName(ValoTheme.BUTTON_SMALL);
    btLogin.setIcon(FontAwesome.USER);

    btLogout.setSizeUndefined();
    btLogout.setStyleName(ValoTheme.BUTTON_SMALL);
    btLogout.setIcon(FontAwesome.USER);

    btOpenSource = new Button("Help us to make ANNIS better!");
    btOpenSource.setStyleName(BaseTheme.BUTTON_LINK);
    btOpenSource.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Window w = new HelpUsWindow();
            w.setCaption("Help us to make ANNIS better!");
            w.setModal(true);
            w.setResizable(true);
            w.setWidth("600px");
            w.setHeight("500px");
            UI.getCurrent().addWindow(w);
            w.center();
        }
    });

    addComponent(btSidebar);
    setComponentAlignment(btSidebar, Alignment.MIDDLE_LEFT);

    addComponent(btAboutAnnis);
    addComponent(btBugReport);
    addComponent(btNavigate);

    addComponent(btOpenSource);

    setSpacing(true);
    setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT);
    setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT);
    setComponentAlignment(btNavigate, Alignment.MIDDLE_LEFT);

    setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER);
    setExpandRatio(btOpenSource, 1.0f);

    addLoginButton();

    btSidebar.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            btSidebar.setEnabled(true);

            // decide new state
            switch (sidebarState) {
            case VISIBLE:
                if (event.isCtrlKey()) {
                    sidebarState = SidebarState.AUTO_VISIBLE;
                } else {
                    sidebarState = SidebarState.HIDDEN;
                }
                break;
            case HIDDEN:
                if (event.isCtrlKey()) {
                    sidebarState = SidebarState.AUTO_HIDDEN;
                } else {
                    sidebarState = SidebarState.VISIBLE;
                }
                break;

            case AUTO_VISIBLE:
                if (event.isCtrlKey()) {
                    sidebarState = SidebarState.VISIBLE;
                } else {
                    sidebarState = SidebarState.AUTO_HIDDEN;
                }
                break;
            case AUTO_HIDDEN:
                if (event.isCtrlKey()) {
                    sidebarState = SidebarState.HIDDEN;
                } else {
                    sidebarState = SidebarState.AUTO_VISIBLE;
                }
                break;
            }

            updateSidebarState();
        }
    });

    screenshotExtension = new ScreenshotMaker(this);

    JavaScript.getCurrent().addFunction("annis.gui.logincallback", new LoginCloseCallback());

    updateSidebarState();
    MainToolbar.this.updateUserInformation();
}

From source file:annis.gui.resultview.SingleResultPanel.java

License:Apache License

private void showShareSingleMatchGenerator() {
    // select the current match
    if (ui != null) {
        ui.getQueryState().getSelectedMatches().getValue().clear();
        ui.getQueryState().getSelectedMatches().getValue().add(resultNumber);
        ui.getSearchView().updateFragment(ui.getQueryController().getSearchQuery());
    }/*from  w w w  .jav a2s . co  m*/

    Window window = new ShareSingleMatchGenerator(resolverEntries, match, query, segmentationName, ps);
    window.setWidth(790, Unit.PIXELS);
    window.setHeight(580, Unit.PIXELS);
    window.setResizable(true);
    window.setModal(true);

    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            btLink.setEnabled(true);
        }
    });
    window.setCaption("Match reference link");

    UI.getCurrent().addWindow(window);
}

From source file:annis.gui.resultview.SingleResultPanel.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {
    if (event.getButton() == btInfo && result != null) {
        Window infoWindow = new Window("Info for " + result.getId());

        infoWindow.setModal(false);
        MetaDataPanel meta = new MetaDataPanel(path.get(0), path.get(path.size() - 1));
        infoWindow.setContent(meta);/*from   w w w  . j a va 2  s .  com*/
        infoWindow.setWidth("400px");
        infoWindow.setHeight("400px");

        UI.getCurrent().addWindow(infoWindow);
    }
}

From source file:annis.gui.SearchUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    this.instanceConfig = getInstanceConfig(request);

    getPage().setTitle(instanceConfig.getInstanceDisplayName() + " (ANNIS Corpus Search)");

    queryController = new QueryController(this);

    refresh = new Refresher();
    // deactivate refresher by default
    refresh.setRefreshInterval(-1);//from   www .j ava2  s.  co m
    refresh.addListener(queryController);
    addExtension(refresh);

    // always get the resize events directly
    setImmediate(true);

    VerticalLayout mainLayout = new VerticalLayout();
    setContent(mainLayout);

    mainLayout.setSizeFull();
    mainLayout.setMargin(false);

    final ScreenshotMaker screenshot = new ScreenshotMaker(this);
    addExtension(screenshot);

    css = new CSSInject(this);

    HorizontalLayout layoutToolbar = new HorizontalLayout();
    layoutToolbar.setWidth("100%");
    layoutToolbar.setHeight("-1px");

    mainLayout.addComponent(layoutToolbar);
    layoutToolbar.addStyleName("toolbar");
    layoutToolbar.addStyleName("border-layout");

    Button btAboutAnnis = new Button("About ANNIS");
    btAboutAnnis.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btAboutAnnis.setIcon(new ThemeResource("info.gif"));

    btAboutAnnis.addClickListener(new AboutClickListener());

    btBugReport = new Button("Report Bug");
    btBugReport.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btBugReport.setDisableOnClick(true);
    btBugReport.setIcon(new ThemeResource("../runo/icons/16/email.png"));
    btBugReport.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            screenshot.makeScreenshot();
            btBugReport.setCaption("bug report is initialized...");
        }
    });

    String bugmail = (String) VaadinSession.getCurrent().getAttribute("bug-e-mail");
    if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${")
            && new EmailValidator("").isValid(bugmail)) {
        this.bugEMailAddress = bugmail;
    }
    btBugReport.setVisible(this.bugEMailAddress != null);

    lblUserName = new Label("not logged in");
    lblUserName.setWidth("-1px");
    lblUserName.setHeight("-1px");
    lblUserName.addStyleName("right-aligned-text");

    btLoginLogout = new Button("Login", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (isLoggedIn()) {
                // logout
                Helper.setUser(null);
                Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION);
                updateUserInformation();
            } else {
                showLoginWindow();
            }
        }
    });
    btLoginLogout.setSizeUndefined();
    btLoginLogout.setStyleName(ChameleonTheme.BUTTON_SMALL);
    btLoginLogout.setIcon(new ThemeResource("../runo/icons/16/user.png"));

    Button btOpenSource = new Button("Help us to make ANNIS better!");
    btOpenSource.setStyleName(BaseTheme.BUTTON_LINK);
    btOpenSource.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Window w = new HelpUsWindow();
            w.setCaption("Help us to make ANNIS better!");
            w.setModal(true);
            w.setResizable(true);
            w.setWidth("600px");
            w.setHeight("500px");
            addWindow(w);
            w.center();
        }
    });

    layoutToolbar.addComponent(btAboutAnnis);
    layoutToolbar.addComponent(btBugReport);
    layoutToolbar.addComponent(btOpenSource);
    layoutToolbar.addComponent(lblUserName);
    layoutToolbar.addComponent(btLoginLogout);

    layoutToolbar.setSpacing(true);
    layoutToolbar.setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER);
    layoutToolbar.setComponentAlignment(lblUserName, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setComponentAlignment(btLoginLogout, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setExpandRatio(btOpenSource, 1.0f);

    //HorizontalLayout hLayout = new HorizontalLayout();
    final HorizontalSplitPanel hSplit = new HorizontalSplitPanel();
    hSplit.setSizeFull();

    mainLayout.addComponent(hSplit);
    mainLayout.setExpandRatio(hSplit, 1.0f);

    AutoGeneratedQueries autoGenQueries = new AutoGeneratedQueries("example queries", this);

    controlPanel = new ControlPanel(queryController, instanceConfig, autoGenQueries);
    controlPanel.setWidth(100f, Layout.Unit.PERCENTAGE);
    controlPanel.setHeight(100f, Layout.Unit.PERCENTAGE);
    hSplit.setFirstComponent(controlPanel);

    tutorial = new TutorialPanel();
    tutorial.setHeight("99%");

    mainTab = new TabSheet();
    mainTab.setSizeFull();
    mainTab.addTab(autoGenQueries, "example queries");
    mainTab.addTab(tutorial, "Tutorial");

    queryBuilder = new QueryBuilderChooser(queryController, this, instanceConfig);
    mainTab.addTab(queryBuilder, "Query Builder");

    hSplit.setSecondComponent(mainTab);
    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
    hSplit.addSplitterClickListener(new AbstractSplitPanel.SplitterClickListener() {
        @Override
        public void splitterClick(AbstractSplitPanel.SplitterClickEvent event) {
            if (event.isDoubleClick()) {
                if (hSplit.getSplitPosition() == CONTROL_PANEL_WIDTH) {
                    // make small
                    hSplit.setSplitPosition(0.0f, Unit.PIXELS);
                } else {
                    // reset to default width
                    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
                }
            }
        }
    });
    // hLayout.setExpandRatio(mainTab, 1.0f);

    addAction(new ShortcutListener("^Query builder") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(queryBuilder);
        }
    });

    addAction(new ShortcutListener("Tutor^eial") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(tutorial);
        }
    });

    getPage().addUriFragmentChangedListener(this);

    getSession().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            checkCitation(request);

            if (request.getPathInfo() != null && request.getPathInfo().startsWith("/vis-iframe-res/")) {
                String uuidString = StringUtils.removeStart(request.getPathInfo(), "/vis-iframe-res/");
                UUID uuid = UUID.fromString(uuidString);
                IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
                if (map == null) {
                    response.setStatus(404);
                } else {
                    IFrameResource res = map.get(uuid);
                    if (res != null) {
                        response.setStatus(200);
                        response.setContentType(res.getMimeType());
                        response.getOutputStream().write(res.getData());
                    }
                }
                return true;
            }

            return false;
        }
    });

    getSession().setAttribute(MediaController.class, new MediaControllerImpl());

    getSession().setAttribute(PDFController.class, new PDFControllerImpl());

    loadInstanceFonts();

    checkCitation(request);
    lastQueriedFragment = "";
    evaluateFragment(getPage().getUriFragment());

    updateUserInformation();
}

From source file:br.com.anteros.mobileserver.util.UserMessages.java

License:Apache License

public Window confirm(String title, String message, String okTitle, String cancelTitle,
        Button.ClickListener listener) {

    if (title == null) {
        title = CONFIRM_OK_TITLE;//from  w ww  . j av  a  2  s  .c  om
    }
    if (cancelTitle == null) {
        cancelTitle = CONFIRM_CANCEL_TITLE;
    }
    if (okTitle == null) {
        okTitle = CONFIRM_OK_TITLE;
    }

    final Window confirm = new Window(title);
    this.confirm = confirm;
    win.addWindow(confirm);

    confirm.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1971800928047045825L;

        public void windowClose(CloseEvent ce) {
            Object data = ce.getWindow().getData();
            if (data != null) {
                try {
                } catch (Exception exception) {
                    error("Unhandled Exception", exception);
                }
            }
        }
    });

    int chrW = 5;
    int chrH = 15;
    int txtWidth = Math.max(250, Math.min(350, message.length() * chrW));
    int btnHeight = 25;
    int vmargin = 100;
    int hmargin = 40;

    int txtHeight = 2 * chrH * (message.length() * chrW) / txtWidth;

    confirm.setWidth((txtWidth + hmargin) + "px");
    confirm.setHeight((vmargin + txtHeight + btnHeight) + "px");
    confirm.getContent().setSizeFull();

    confirm.center();
    confirm.setModal(true);

    Label text = new Label(message);
    text.setWidth("100%");
    text.setHeight("100%");

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setHeight(btnHeight + 5 + "px");
    buttons.setWidth("100%");
    buttons.setSpacing(true);
    buttons.setMargin(false);

    Button cancel = new Button(cancelTitle, listener);
    cancel.setIcon(new ThemeResource("icons/16/no.png"));
    cancel.setData(USER_CONFIRM_CANCEL);
    cancel.setClickShortcut(KeyCode.ESCAPE);
    Button ok = new Button(okTitle, listener);
    ok.setIcon(new ThemeResource("icons/16/yes.png"));
    ok.setData(USER_CONFIRM_OK);
    ok.setClickShortcut(KeyCode.ENTER);
    buttons.addComponent(ok);
    buttons.setExpandRatio(ok, 1);
    buttons.setComponentAlignment(ok, Alignment.MIDDLE_RIGHT);

    buttons.addComponent(cancel);
    buttons.setComponentAlignment(cancel, Alignment.MIDDLE_RIGHT);

    confirm.addComponent(text);
    confirm.addComponent(buttons);
    ((VerticalLayout) confirm.getContent()).setExpandRatio(text, 1f);
    confirm.setResizable(false);
    return confirm;
}

From source file:com.bellkenz.modules.PersonalInformation.java

public ComponentContainer personalInformation() {
    employeeInformationDAO = new EmployeeInformationDAO(getEmployeeId());
    employeePersonalInformation = new EmployeePersonalInformation();

    GridLayout glayout = new GridLayout(5, 9);
    glayout.setSpacing(true);//  w w w.  j  ava 2  s . c o  m
    glayout.setMargin(true);

    final Panel imagePanel = new Panel();
    imagePanel.setStyleName("light");
    AbstractLayout panelLayout = (AbstractLayout) imagePanel.getContent();
    panelLayout.setMargin(false);
    imagePanel.setSizeFull();

    employeeImage = new Embedded(null, new ThemeResource("../myTheme/images/ronnie.jpg"));
    employeeImage.setImmediate(true);
    employeeImage.setWidth(90, Sizeable.UNITS_PIXELS);
    employeeImage.setHeight(90, Sizeable.UNITS_PIXELS);
    employeeImage.setStyleName("logo-img");
    imagePanel.addComponent(employeeImage);
    glayout.addComponent(employeeImage, 0, 0, 0, 1);
    glayout.setComponentAlignment(imagePanel, Alignment.MIDDLE_CENTER);

    firstname = createTextField("Firstname: ");
    glayout.addComponent(firstname, 1, 0, 2, 0);

    final TextField middlename = createTextField("Middlename: ");
    glayout.addComponent(middlename, 3, 0);

    final TextField lastname = createTextField("Lastname: ");
    glayout.addComponent(lastname, 4, 0);

    final TextField houseNo = createTextField("No: ");
    houseNo.setWidth("40px");
    glayout.addComponent(houseNo, 1, 1);

    final TextField street = createTextField("Street: ");
    street.setWidth("118");
    glayout.addComponent(street, 2, 1);

    final TextField city = createTextField("City: ");
    glayout.addComponent(city, 3, 1);

    final TextField zipCode = createTextField("Zip Code:");
    glayout.addComponent(zipCode, 4, 1);

    final TextField nickname = createTextField("Nickname: ");
    nickname.setWidth("90px");
    glayout.addComponent(nickname, 0, 2);

    final TextField permanentAddress = createTextField("Permanent/Provincial Address: ");
    permanentAddress.setWidth("533px");
    glayout.addComponent(permanentAddress, 1, 2, 4, 2);

    Button uploadPicture = new Button("Upload...");
    uploadPicture.setWidth("100%");
    uploadPicture.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (employeeId == null) {
                getWindow().showNotification("You did not select and Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window uploadImage = new UploadImage(imagePanel, employeeImage, employeeId);
            uploadImage.setWidth("450px");
            if (uploadImage.getParent() == null) {
                getWindow().addWindow(uploadImage);
            }
            uploadImage.setModal(true);
            uploadImage.center();
        }
    });
    glayout.addComponent(uploadPicture, 0, 3);

    final TextField landline = createTextField("Landline #: ");
    glayout.addComponent(landline, 1, 3, 2, 3);

    final TextField mobileNo = createTextField("Mobile #: ");
    glayout.addComponent(mobileNo, 3, 3);

    final TextField age = createTextField("Age: ");
    glayout.addComponent(age, 4, 3);

    final TextField emailAddress = createTextField("Email Address: ");
    glayout.addComponent(emailAddress, 1, 4, 2, 4);

    final PopupDateField dob = (PopupDateField) createDateField("Date of Birth: ");
    glayout.addComponent(dob, 3, 4);

    final TextField height = createTextField("Height: ");
    glayout.addComponent(height, 4, 4);

    final ComboBox civilStatus = new ComboBox("Civil Status: ");
    civilStatus.setWidth("100%");
    dropDownBoxList.populateCivilStatusList(civilStatus);
    glayout.addComponent(civilStatus, 1, 5, 2, 5);

    final ComboBox gender = new ComboBox("Gender: ");
    gender.setWidth("100%");
    dropDownBoxList.populateGenderList(gender);
    glayout.addComponent(gender, 3, 5);

    final TextField weight = createTextField("Weigth: ");
    glayout.addComponent(weight, 4, 5);

    final TextField driversLicenseNo = createTextField("Drivers License: ");
    glayout.addComponent(driversLicenseNo, 1, 6, 2, 6);

    final TextField restrictionCode = createTextField("Restriction Code: ");
    glayout.addComponent(restrictionCode, 3, 6);

    final TextField religion = createTextField("Religion: ");
    glayout.addComponent(religion, 4, 6);

    final ComboBox division = new ComboBox("Division: ");
    division.setWidth("100%");
    dropDownBoxList.populateBranchComboBox(division);
    glayout.addComponent(division, 1, 7, 2, 7);

    final ComboBox department = dropDownBoxList.populateDepartment(new ComboBox());
    department.setWidth("100%");
    division.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (division.getValue() == null) {
            } else {
                divisionId = branchDAO.getBranchId(division.getValue().toString());
            }
        }

    });
    glayout.addComponent(department, 3, 7);

    final TextField position = createTextField("Position: ");
    glayout.addComponent(position, 4, 7);
    //glayout.setComponentAlignment(position, Alignment.BOTTOM_LEFT);

    Button transferButton = new Button("Transfer Employee");
    transferButton.setWidth("100%");
    transferButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (getEmployeeId() == null) {
                getWindow().showNotification("You did not select an Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window subWindow = transferEmployee(getEmployeeId(), division, department, position);
            if (subWindow.getParent() == null) {
                getWindow().addWindow(subWindow);
            }
            subWindow.setModal(true);
            subWindow.center();
        }
    });
    glayout.addComponent(transferButton, 1, 8, 2, 8);
    glayout.setComponentAlignment(transferButton, Alignment.BOTTOM_CENTER);

    if (employeeId != null) {
        epiList = employeeInformationDAO.employeePersonalInformation();
        for (EmployeePersonalInformation epi : epiList) {
            final byte[] image = epi.getImage();
            if (image != null) {
                StreamResource.StreamSource imageSource = new StreamResource.StreamSource() {

                    @Override
                    public InputStream getStream() {
                        return new ByteArrayInputStream(image);
                    }

                };

                StreamResource imageResource = new StreamResource(imageSource, epi.getFirstname() + ".jpg",
                        getApplication());
                imageResource.setCacheTime(0);
                employeeImage.setSource(imageResource);
            }
            firstname.setValue(epi.getFirstname());
            middlename.setValue(epi.getMiddlename());
            lastname.setValue(epi.getLastname());
            houseNo.setValue(epi.getHouseNumber());

            street.setValue(epi.getStreet());
            city.setValue(epi.getStreet());
            zipCode.setValue(epi.getZipCode());
            nickname.setValue(epi.getNickname());
            permanentAddress.setValue(epi.getPermanentAddress());
            landline.setValue(epi.getLandlineNumber());
            mobileNo.setValue(epi.getMobileNumber());
            age.setValue(epi.getAge());
            emailAddress.setValue(epi.getEmailAddress());

            if (epi.getDob() != null) {
                dob.setValue(conUtil.parsingDate(epi.getDob()));
            } else {
                dob.setValue(null);
            }

            height.setValue(epi.getHeight());

            if (epi.getCivilStatus() != null) {
                Object civilStatusId = civilStatus.addItem();
                civilStatus.setItemCaption(civilStatusId, epi.getCivilStatus());
                civilStatus.setValue(civilStatusId);
            }

            if (epi.getGender() != null) {
                Object genderId = gender.addItem();
                gender.setItemCaption(genderId, epi.getGender());
                gender.setValue(genderId);
            }

            weight.setValue(epi.getWeight());
            driversLicenseNo.setValue(epi.getDriversLicense());
            restrictionCode.setValue(epi.getRestrictionCode());
            religion.setValue(epi.getReligion());
            position.setValue(epi.getPosition());

            Object divisionObjectId = division.addItem();
            division.setItemCaption(divisionObjectId, epi.getDivision());
            division.setValue(divisionObjectId);

            Object departmentObjectId = department.addItem();
            department.setItemCaption(departmentObjectId, epi.getDepartment());
            department.setValue(departmentObjectId);
        }
    }

    firstname.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            employeePersonalInformation.setFirstname(event.getProperty().getValue().toString());
        }
    });
    firstname.setImmediate(true);
    setInformation(employeePersonalInformation);

    return glayout;
}

From source file:com.cavisson.gui.dashboard.components.calender.BeanItemContainerTestUI.java

License:Apache License

/**
 * Opens up a modal dialog window where an event can be modified
 * /*from w  w  w  . j ava2s  .  co m*/
 * @param event
 *            The event to modify
 */
private void editEvent(final BasicEvent event) {
    Window modal = new Window("Add event");
    modal.setModal(true);
    modal.setResizable(false);
    modal.setDraggable(false);
    modal.setWidth("300px");
    final FieldGroup fieldGroup = new FieldGroup();

    FormLayout formLayout = new FormLayout();
    TextField captionField = new TextField("Caption");
    captionField.setImmediate(true);
    TextField descriptionField = new TextField("Description");
    descriptionField.setImmediate(true);
    DateField startField = new DateField("Start");
    startField.setResolution(Resolution.MINUTE);
    startField.setImmediate(true);
    DateField endField = new DateField("End");
    endField.setImmediate(true);
    endField.setResolution(Resolution.MINUTE);

    formLayout.addComponent(captionField);
    formLayout.addComponent(descriptionField);
    formLayout.addComponent(startField);
    formLayout.addComponent(endField);

    fieldGroup.bind(captionField, ContainerEventProvider.CAPTION_PROPERTY);
    fieldGroup.bind(descriptionField, ContainerEventProvider.DESCRIPTION_PROPERTY);
    fieldGroup.bind(startField, ContainerEventProvider.STARTDATE_PROPERTY);
    fieldGroup.bind(endField, ContainerEventProvider.ENDDATE_PROPERTY);

    fieldGroup.setItemDataSource(new BeanItem<BasicEvent>(event,
            Arrays.asList(ContainerEventProvider.CAPTION_PROPERTY, ContainerEventProvider.DESCRIPTION_PROPERTY,
                    ContainerEventProvider.STARTDATE_PROPERTY, ContainerEventProvider.ENDDATE_PROPERTY)));
    modal.setContent(formLayout);
    modal.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            // Commit changes to bean
            try {
                fieldGroup.commit();
            } catch (CommitException e1) {
                e1.printStackTrace();
            }

            if (events.containsId(event)) {
                /*
                 * BeanItemContainer does not notify container listeners
                 * when the bean changes so we need to trigger a
                 * ItemSetChange event
                 */
                BasicEvent dummy = new BasicEvent();
                events.addBean(dummy);
                events.removeItem(dummy);

            } else {
                events.addBean(event);
            }
        }
    });
    getUI().addWindow(modal);
}