Java Code Examples for com.vaadin.server.Page

The following examples show how to use com.vaadin.server.Page. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cuba   Source File: UrlChangeHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void handleUrlChange(Page.PopStateEvent event) {
    if (notSuitableMode()) {
        log.debug("UrlChangeHandler is disabled for '{}' URL handling mode", webConfig.getUrlHandlingMode());
        return;
    }

    int hashIdx = event.getUri().indexOf("#");
    NavigationState requestedState = hashIdx < 0
            ? NavigationState.EMPTY
            : urlTools.parseState(event.getUri().substring(hashIdx + 1));

    if (requestedState == null) {
        log.debug("Unable to handle requested state: '{}'", Page.getCurrent().getUriFragment());
        reloadApp();
        return;
    }

    __handleUrlChange(requestedState);
}
 
Example 2
Source Project: cuba   Source File: UrlTools.java    License: Apache License 2.0 6 votes vote down vote up
public void pushState(String navigationState, UI ui) {
    checkNotNullArgument(navigationState, "Navigation state cannot be null");

    if (headless()) {
        log.debug("Unable to push navigation state in headless mode");
        return;
    }

    String state = !navigationState.isEmpty()
            ? "#" + navigationState
            : "";

    Page page = ui.getPage();
    if (!state.isEmpty()) {
        page.pushState(state);
    } else {
        page.pushState(getEmptyFragmentUri(page));
    }
}
 
Example 3
Source Project: cuba   Source File: UrlTools.java    License: Apache License 2.0 6 votes vote down vote up
public void replaceState(String navigationState, UI ui) {
    checkNotNullArgument(navigationState, "Navigation state cannot be null");

    if (headless()) {
        log.debug("Unable to replace navigation state in headless mode");
        return;
    }

    String state = !navigationState.isEmpty()
            ? "#" + navigationState
            : "";

    Page page = ui.getPage();
    if (!state.isEmpty()) {
        page.replaceState(state);
    } else {
        page.replaceState(getEmptyFragmentUri(page));
    }
}
 
Example 4
Source Project: cuba   Source File: WebAbstractDataGrid.java    License: Apache License 2.0 6 votes vote down vote up
protected void updateFooterVisibility(String style) {
    Page page = Page.getCurrent();
    if (page == null) {
        return;
    }
    WebBrowser webBrowser = page.getWebBrowser();
    boolean isPredefinedStyle = style.equals(BORDERLESS_STYLE)
            || style.equals(NO_HORIZONTAL_LINES_STYLE)
            || style.equals(NO_VERTICAL_LINES_STYLE);

    if (webBrowser.isSafari()
            && isPredefinedStyle
            && grid.getFooterRowCount() > 0
            && grid.isFooterVisible()) {
        ((CubaEnhancedGrid) grid).updateFooterVisibility();
    }
}
 
Example 5
Source Project: cuba   Source File: CubaTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
    if (Page.getCurrent().getWebBrowser().isIE() && variables.containsKey("clickEvent")) {
        focus();
    }

    super.changeVariables(source, variables);

    if (shortcutActionManager != null) {
        shortcutActionManager.handleActions(variables, this);
    }

    if (variables.containsKey("updateAggregationRow")) {
        Boolean updateAggregationRow = (Boolean) variables.get("updateAggregationRow");
        if (updateAggregationRow) {
            markAsDirty();
        }
    }
}
 
Example 6
Source Project: hawkbit   Source File: DashboardMenu.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private Component buildUserMenu(final UiProperties uiProperties) {
    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    settings.setHtmlContentAllowed(true);

    final MenuItem settingsItem = settings.addItem("", getImage(uiProperties.isGravatar()), null);

    final String formattedTenant = UserDetailsFormatter.formatCurrentTenant();
    if (!StringUtils.isEmpty(formattedTenant)) {
        settingsItem.setText(formattedTenant);
        UserDetailsFormatter.getCurrentTenant().ifPresent(tenant -> settingsItem.setDescription(i18n
                .getMessage("menu.user.description", tenant, UserDetailsFormatter.getCurrentUser().getUsername())));
    } else {
        settingsItem.setText("...");
    }

    settingsItem.setStyleName("user-menuitem");

    final String logoutUrl = generateLogoutUrl();

    settingsItem.addItem(i18n.getMessage("label.sign.out"),
            selectedItem -> Page.getCurrent().setLocation(logoutUrl));
    return settings;
}
 
Example 7
Source Project: hawkbit   Source File: HawkbitUIErrorHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void error(final ErrorEvent event) {

    // filter upload exceptions
    if (event.getThrowable() instanceof UploadException) {
        return;
    }

    final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
    if (event instanceof ConnectorErrorEvent) {
        final Connector connector = ((ConnectorErrorEvent) event).getConnector();
        if (connector instanceof UI) {
            final UI uiInstance = (UI) connector;
            uiInstance.access(() -> message.show(uiInstance.getPage()));
            return;
        }
    }

    final Optional<Page> originError = getPageOriginError(event);
    if (originError.isPresent()) {
        message.show(originError.get());
        return;
    }

    HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE);
}
 
Example 8
Source Project: viritin   Source File: ClearableTextField.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void attach() {
    super.attach();
    // TODO optimize this so that it is added only once
    Page.getCurrent().getStyles().add(
            ".clearable-textfield .v-widget {\n"
            + "	border-radius: 4px 4px 4px 4px;\n"
            + "}\n"
            + ".clearable-textfield .v-slot:last-child>.v-widget {\n"
            + "	border-top-left-radius: 0;\n"
            + "	border-bottom-left-radius: 0; margin-left:-1px\n"
            + "}\n"
            + "\n"
            + ".clearable-textfield .v-slot:first-child>.v-widget {\n"
            + "	border-top-right-radius: 0;\n"
            + "	border-bottom-right-radius: 0;\n"
            + "}\n");
}
 
Example 9
Source Project: viritin   Source File: ClearableTextField.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void attach() {
    super.attach();
    Page.getCurrent().getStyles().add(
            ".clearable-textfield .v-widget {\n"
            + "	border-radius: 4px 4px 4px 4px;\n"
            + "}\n"
            + ".clearable-textfield .v-slot:last-child>.v-widget {\n"
            + "	border-top-left-radius: 0;\n"
            + "	border-bottom-left-radius: 0; margin-left:-1px\n"
            + "}\n"
            + "\n"
            + ".clearable-textfield .v-slot:first-child>.v-widget {\n"
            + "	border-top-right-radius: 0;\n"
            + "	border-bottom-right-radius: 0;\n"
            + "}\n");
}
 
Example 10
Source Project: mycollab   Source File: AboutWindow.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public AboutWindow() {
    MHorizontalLayout content = new MHorizontalLayout().withMargin(true).withFullWidth();
    this.setContent(content);

    Image about = new Image("", new ExternalResource(StorageUtils.generateAssetRelativeLink(WebResourceIds._about)));

    MVerticalLayout rightPanel = new MVerticalLayout();
    ELabel versionLbl = ELabel.h2(String.format("MyCollab Community Edition %s", Version.getVersion())).withFullWidth();
    ELabel javaNameLbl = new ELabel(String.format("%s, %s", System.getProperty("java.vm.name"),
            System.getProperty("java.runtime.version"))).withFullWidth();
    Label homeFolderLbl = new Label("Home folder: " + AppContextUtil.getSpringBean(ServerConfiguration.class).getHomeDir().getAbsolutePath());
    WebBrowser browser = Page.getCurrent().getWebBrowser();
    ELabel osLbl = new ELabel(String.format("%s, %s", System.getProperty("os.name"), browser.getBrowserApplication())).withFullWidth();
    Div licenseDiv = new Div().appendChild(new Text("Powered by: "))
            .appendChild(new A("https://www.mycollab.com")
                    .appendText("MyCollab")).appendChild(new Text(". Open source under GPL license"));
    ELabel licenseLbl = ELabel.html(licenseDiv.write()).withFullWidth();
    Label copyRightLbl = ELabel.html(String.format("&copy; %s - %s MyCollab Ltd. All rights reserved", "2011",
            LocalDate.now().getYear() + "")).withFullWidth();
    rightPanel.with(versionLbl, javaNameLbl, osLbl, homeFolderLbl, licenseLbl, copyRightLbl).withAlign(copyRightLbl, Alignment.BOTTOM_LEFT);
    content.with(about, rightPanel).expand(rightPanel);
}
 
Example 11
public static <S extends SearchCriteria> ApplicationEventListener<ShellEvent.AddQueryParam> queryParamHandler() {
    return new ApplicationEventListener<ShellEvent.AddQueryParam>() {
        @Subscribe
        @Override
        public void handle(ShellEvent.AddQueryParam event) {
            List<SearchFieldInfo<S>> searchFieldInfos = (List<SearchFieldInfo<S>>) event.getData();
            String query = QueryAnalyzer.toQueryParams(searchFieldInfos);
            String fragment = Page.getCurrent().getUriFragment();
            int index = fragment.indexOf("?");
            if (index > 0) {
                fragment = fragment.substring(0, index);
            }

            if (StringUtils.isNotBlank(query)) {
                fragment += "?" + UrlEncodeDecoder.encode(query);
                Page.getCurrent().setUriFragment(fragment, false);
            }
        }
    };
}
 
Example 12
Source Project: chipster   Source File: CSCTextToToolClickListener.java    License: MIT License 6 votes vote down vote up
@Override
public void buttonClick(ClickEvent event) {
	
	ChipsterSADLParser parser = new ChipsterSADLParser();
	try {
		SADLDescription description = parser.parse(root.getTextEditor().getHeader());
		root.getToolEditor().removeItems();
		root.getTreeToolEditor().removeAllChildren();
		root.getToolEditor().addTool(description);
		List<Input> inputs = description.getInputs();
		for(int i = 0 ; i < inputs.size(); i++) {
			root.getToolEditor().addInput(inputs.get(i));
		}
		List<Output> outputs = description.getOutputs();
		for(int i = 0 ; i < outputs.size(); i++) {
			root.getToolEditor().addOutput(outputs.get(i));
		}
		List<Parameter> parameters = description.getParameters();
		for(int i = 0 ; i < parameters.size(); i++) {
			root.getToolEditor().addParameter(parameters.get(i));
		}
		
	} catch (Exception e) {
		new Notification("Something wrong with the header\n\n" + e.getMessage(), Type.WARNING_MESSAGE).show(Page.getCurrent());
	}
}
 
Example 13
Source Project: chipster   Source File: Parameter.java    License: MIT License 6 votes vote down vote up
private Name[] getEnumList() {
	if (typeTable == null || typeTable.getItemIds().isEmpty())
		return null;
	Name[] names = typeTable.getItemIds().toArray(new Name[0]);
	ArrayList<Name> list = new ArrayList<Name>();
	for (Name name : names) {
		if (!name.getID().isEmpty()) {
			if ("".equals(name.getDisplayName())) {
				name.setDisplayName(null);
			}

			list.add(name);
		} else {
			new Notification(
					"Not all ENUM types were generated to text, because id was empty",
					Type.WARNING_MESSAGE).show(Page.getCurrent());
		}
	}
	return list.toArray(new Name[0]);
}
 
Example 14
Source Project: anx   Source File: MainUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest vaadinRequest) {
	Page.getCurrent().setTitle("Advanced Netconf Explorer");
    addStyleName(ValoTheme.UI_WITH_MENU);
    
    setContent(new RetrieverView(this, vaadinRequest));
    addStyleName("loginview");
}
 
Example 15
Source Project: cuba   Source File: UrlTools.java    License: Apache License 2.0 5 votes vote down vote up
protected URI getEmptyFragmentUri(Page page) {
    URI location = page.getLocation();

    try {
        return new URI(location.getScheme(), location.getSchemeSpecificPart(), null);
    } catch (URISyntaxException e) {
        log.info("Failed to form new location to reset fragment");
    }

    return location;
}
 
Example 16
Source Project: cuba   Source File: UrlTools.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * INTERNAL
 *
 * @return whether application is running in headless mode
 */
public static boolean headless() {
    Page current = Page.getCurrent();
    if (current == null) {
        return true;
    }
    return current.getUI().getSession() == null;
}
 
Example 17
Source Project: cuba   Source File: WebUrlRouting.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NavigationState getState() {
    if (UrlHandlingMode.URL_ROUTES != webConfig.getUrlHandlingMode()) {
        log.debug("UrlRouting is disabled for '{}' URL handling mode", webConfig.getUrlHandlingMode());
        return NavigationState.EMPTY;
    }

    if (UrlTools.headless()) {
        log.debug("Unable to resolve navigation state in headless mode");
        return NavigationState.EMPTY;
    }

    return urlTools.parseState(Page.getCurrent().getLocation().getRawFragment());
}
 
Example 18
Source Project: cuba   Source File: CubaTreeTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void changeVariables(Object source, Map<String, Object> variables) {

    if (Page.getCurrent().getWebBrowser().isIE()
            && variables.containsKey("clickEvent")) {
        focus();
    }

    super.changeVariables(source, variables);

    if (shortcutActionManager != null) {
        shortcutActionManager.handleActions(variables, this);
    }
}
 
Example 19
Source Project: cuba   Source File: CubaImage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void attach() {
    super.attach();

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    if (webBrowser.isIE() || webBrowser.isEdge()) {
        CubaImageObjectFitPolyfillExtension.get(getUI());
    }
}
 
Example 20
Source Project: cuba   Source File: CubaPickerField.java    License: Apache License 2.0 5 votes vote down vote up
protected void initLayout() {
    container = new CubaCssActionsLayout();
    container.setPrimaryStyleName(LAYOUT_STYLENAME);

    container.setWidth(100, Unit.PERCENTAGE);
    field.setWidth(100, Unit.PERCENTAGE);

    Page current = Page.getCurrent();
    if (current != null) {
        WebBrowser browser = current.getWebBrowser();
        if (browser != null
                && browser.isSafari()) {
            inputWrapper = new CssLayout();
            inputWrapper.setWidth(100, Unit.PERCENTAGE);
            inputWrapper.setPrimaryStyleName("safari-input-wrap");
            inputWrapper.addComponent(field);

            container.addComponent(inputWrapper);
        } else {
            container.addComponent(field);
        }
    } else {
        container.addComponent(field);
    }

    setFocusDelegate((Focusable) field);
}
 
Example 21
Source Project: hawkbit   Source File: AbstractHawkbitLoginUI.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void init(final VaadinRequest request) {
    HawkbitCommonUtil.initLocalization(this, uiProperties.getLocalization(), i18n);
    SpringContextHelper.setContext(context);

    params = UriComponentsBuilder.fromUri(Page.getCurrent().getLocation()).build().getQueryParams();

    setContent(buildContent());

    fillOutUsernameTenantFields();
}
 
Example 22
Source Project: hawkbit   Source File: ShortCutModifierUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the ctrl or meta modifier depending on the platform.
 * 
 * @return on mac return
 *         {@link com.vaadin.event.ShortcutAction.ModifierKey#META} other
 *         platform return
 *         {@link com.vaadin.event.ShortcutAction.ModifierKey#CTRL}
 */
public static int getCtrlOrMetaModifier() {
    final WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    if (webBrowser.isMacOSX()) {
        return ShortcutAction.ModifierKey.META;
    }

    return ShortcutAction.ModifierKey.CTRL;
}
 
Example 23
Source Project: hawkbit   Source File: UploadArtifactView.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
void init() {
    buildLayout();
    restoreState();
    checkNoDataAvaialble();
    eventBus.subscribe(this);
    Page.getCurrent().addBrowserWindowResizeListener(this);
    showOrHideFilterButtons(Page.getCurrent().getBrowserWindowWidth());
}
 
Example 24
Source Project: hawkbit   Source File: BulkUploadHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void uploadStarted(final StartedEvent event) {
    if (!event.getFilename().endsWith(".csv")) {

        new HawkbitErrorNotificationMessage(SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE, null,
                i18n.getMessage("bulk.targets.upload"), true).show(Page.getCurrent());
        LOG.error("Wrong file format for file {}", event.getFilename());
        upload.interruptUpload();
    } else {
        eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_UPLOAD_STARTED));
    }
}
 
Example 25
Source Project: hawkbit   Source File: DeploymentView.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
void init() {
    buildLayout();
    restoreState();
    checkNoDataAvaialble();
    Page.getCurrent().addBrowserWindowResizeListener(this);
    showOrHideFilterButtons(Page.getCurrent().getBrowserWindowWidth());
    getEventBus().publish(this, ManagementUIEvent.SHOW_COUNT_MESSAGE);
}
 
Example 26
Source Project: hawkbit   Source File: SwModuleTable.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void styleTableOnDistSelection() {
    Page.getCurrent().getJavaScript().execute(HawkbitCommonUtil.getScriptSMHighlightReset());
    setCellStyleGenerator(new Table.CellStyleGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public String getStyle(final Table source, final Object itemId, final Object propertyId) {
            return createTableStyle(itemId, propertyId);
        }
    });
}
 
Example 27
Source Project: hawkbit   Source File: DistributionsView.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
void init() {
    buildLayout();
    restoreState();
    checkNoDataAvaialble();
    Page.getCurrent().addBrowserWindowResizeListener(this);
    showOrHideFilterButtons(Page.getCurrent().getBrowserWindowWidth());
}
 
Example 28
Source Project: jpa-invoicer   Source File: VaadinUI.java    License: The Unlicense 5 votes vote down vote up
protected void workaroundForFirefoxIssue(boolean initial) {
    if (initial && Page.getCurrent().getWebBrowser().getBrowserApplication().
            contains("Firefox")) {
        // Responsive, FF, cross site is currently broken :-(
        Extension r = null;
        for (Extension ext : getExtensions()) {
            if (ext instanceof Responsive) {
                r = ext;
            }
        }
        removeExtension(r);
    }
}
 
Example 29
Source Project: jpa-invoicer   Source File: LoginWindow.java    License: The Unlicense 5 votes vote down vote up
private OAuthService createService() {
    ServiceBuilder sb = new ServiceBuilder();
    sb.provider(Google2Api.class);
    sb.apiKey(gpluskey);
    sb.apiSecret(gplussecret);
    sb.scope("email");
    String callBackUrl = Page.getCurrent().getLocation().toString();
    if(callBackUrl.contains("#")) {
        callBackUrl = callBackUrl.substring(0, callBackUrl.indexOf("#"));
    }
    sb.callback(callBackUrl);
    return sb.build();
}
 
Example 30
Source Project: cia   Source File: AbstractChartDataManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the chart window height.
 *
 * @param fullPage the full page
 * @return the chart window height
 */
private static int getChartWindowHeight(final boolean fullPage) {
	if (fullPage) {
		return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCENTAGE_FULL_PAGE) ,MINIMUM_CHART_HEIGHT_FULL_PAGE);
	} else {
		return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCETAGE_HALF_PAGE),NINIMUM_CHART_HEIGHT_HALF_PAGE);
	}
}