Example usage for com.vaadin.ui Panel setWidth

List of usage examples for com.vaadin.ui Panel setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui Panel setWidth.

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

From source file:org.lucidj.newview.NewView.java

License:Apache License

private Component form_type_panel() {
    HorizontalLayout group = new HorizontalLayout();
    group.setWidth(100, Unit.PERCENTAGE);
    group.setCaption("Artifact type");

    Map<String, Object> component = new HashMap<>();
    component.put("iconTitle", "LucidJ Application");
    component.put("iconUrl", "apps/system-run");

    List<Map<String, Object>> components = new ArrayList<>();
    components.add(component);// w  ww. ja  v  a2s  .c  om

    ObjectRenderer component_renderer = rendererFactory.newRenderer(components);
    component_renderer.setWidth(100, Unit.PERCENTAGE);

    Panel field_panel = new Panel();
    field_panel.setWidth(100, Unit.PERCENTAGE);
    field_panel.setContent(component_renderer);
    group.addComponent(field_panel);
    return (group);
}

From source file:org.lucidj.ui.gauss.GaussUI.java

License:Apache License

private void add_smart_tab(VerticalLayout container, String caption, Component contents) {
    String style_expanded = "ui-panel-caption-expanded";

    // Every panel is a glorified button disguised as accordion tab...
    final Button caption_button = new Button(caption);
    caption_button.setWidth(100, Unit.PERCENTAGE);
    container.addComponent(caption_button);
    caption_button.addStyleName("ui-panel-caption");
    caption_button.addStyleName(style_expanded);

    // ... with a panel for the contents and selective hide/show
    final Panel content_panel = new Panel();
    content_panel.setWidth(100, Unit.PERCENTAGE);
    content_panel.setContent(contents);/*from ww  w . j a v  a  2  s . co  m*/
    content_panel.addStyleName("ui-panel-contents");
    content_panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    container.addComponent(content_panel);

    caption_button.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (content_panel.isVisible()) {
                content_panel.setVisible(false);
                caption_button.removeStyleName(style_expanded);
            } else {
                content_panel.setVisible(true);
                caption_button.addStyleName(style_expanded);
            }
        }
    });
}

From source file:org.milleni.dunning.ui.customer.form.CustomProcessInstanceDetailPanel.java

License:Apache License

protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
            .getDeployedProcessDefinition(processDefinition.getId());

    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {

        boolean didDrawImage = false;

        if (ExplorerApp.get().isUseJavascriptDiagram()) {
            try {

                final InputStream definitionStream = repositoryService.getResourceAsStream(
                        processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XMLInputFactory.newInstance();
                XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

                if (bpmnModel.getFlowLocationMap().size() > 0) {

                    int maxX = 0;
                    int maxY = 0;
                    for (String key : bpmnModel.getLocationMap().keySet()) {
                        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                        double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                        if (maxX < elementX) {
                            maxX = (int) elementX;
                        }/*from  w w w  . j  a  va  2s .c  om*/
                        double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                        if (maxY < elementY) {
                            maxY = (int) elementY;
                        }
                    }

                    Panel imagePanel = new Panel(); // using panel for scrollbars
                    imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                    imagePanel.setWidth(100, UNITS_PERCENTAGE);
                    imagePanel.setHeight(100, UNITS_PERCENTAGE);
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(),
                            explorerURL.getPath().replace("/ui", "")
                                    + "diagram-viewer/index.html?processDefinitionId="
                                    + processDefinition.getId() + "&processInstanceId="
                                    + processInstance.getId());
                    Embedded browserPanel = new Embedded("", new ExternalResource(url));
                    browserPanel.setType(Embedded.TYPE_BROWSER);
                    browserPanel.setWidth(maxX + 350 + "px");
                    browserPanel.setHeight(maxY + 220 + "px");

                    HorizontalLayout panelLayoutT = new HorizontalLayout();
                    panelLayoutT.setSizeUndefined();
                    imagePanel.setContent(panelLayoutT);
                    imagePanel.addComponent(browserPanel);

                    panelLayout.addComponent(imagePanel);

                    didDrawImage = true;
                }

            } catch (Exception e) {
                LOGGER.error("Error loading process diagram component", e);
            }
        }

        if (didDrawImage == false && processDefinitionEntity.isGraphicalNotationDefined()) {

            StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder()
                    .buildStreamResource(processInstance, repositoryService, runtimeService);

            if (diagram != null) {
                Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
                header.addStyleName(ExplorerLayout.STYLE_H3);
                header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
                header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
                panelLayout.addComponent(header);

                Embedded embedded = new Embedded(null, diagram);
                embedded.setType(Embedded.TYPE_IMAGE);
                embedded.setSizeUndefined();

                Panel imagePanel = new Panel(); // using panel for scrollbars
                imagePanel.setScrollable(true);
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);

                HorizontalLayout panelLayoutT = new HorizontalLayout();
                panelLayoutT.setSizeUndefined();
                imagePanel.setContent(panelLayoutT);
                imagePanel.addComponent(embedded);

                panelLayout.addComponent(imagePanel);
            }
        }
    }
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *//*from w ww .  j  a  v  a 2 s  . c  om*/
public ChartsConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(410, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    /**
     * Adding the checkboxes
     */
    m_maximizeWidth = new CheckBox();
    m_maximizeWidth.setCaption("Maximize width");
    m_maximizeWidth.setDescription("Maximize width");

    m_maximizeHeight = new CheckBox();
    m_maximizeHeight.setCaption("Maximize height");
    m_maximizeHeight.setDescription("Maximize height");

    String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth");
    String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight");

    boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString)
            || "1".equals(maximizeHeightString));
    boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
            || "1".equals(maximizeWidthString));

    m_maximizeWidth.setValue(maximizeWidth);
    m_maximizeHeight.setValue(maximizeHeight);

    m_chartSelect = new NativeSelect();
    m_chartSelect.setDescription("Select chart to be displayed");
    m_chartSelect.setCaption("Chart");
    m_chartSelect.setNullSelectionAllowed(false);
    m_chartSelect.setInvalidAllowed(false);
    m_chartSelect.setNewItemsAllowed(false);

    String firstChartName = null;

    try {
        Iterator<BarChart> it = ChartUtils.getChartCollectionIterator();

        while (it.hasNext()) {
            BarChart chartConfig = (BarChart) it.next();

            if (firstChartName == null) {
                firstChartName = chartConfig.getName();
            }

            m_chartSelect.addItem(chartConfig.getName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    String chartName = m_dashletSpec.getParameters().get("chart");

    if (chartName == null || "".equals(chartName)) {
        chartName = firstChartName;
    }

    final Panel panel = new Panel();

    panel.setWidth(230, Unit.PIXELS);

    panel.setCaption("Preview");

    formLayout.addComponent(m_chartSelect);

    Page.getCurrent().getStyles().add(".preview { width:225px; }");

    m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue();
            Image image = new Image(null, new ExternalResource(newImage));
            image.setStyleName("preview");
            panel.setContent(image);
        }
    });

    m_chartSelect.setValue(chartName);
    m_chartSelect.setImmediate(true);

    formLayout.addComponent(m_maximizeWidth);
    formLayout.addComponent(m_maximizeHeight);

    horizontalLayout.addComponent(formLayout);
    horizontalLayout.addComponent(panel);

    /**
     * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    buttonLayout.addComponent(cancel);
    buttonLayout.setExpandRatio(cancel, 1.0f);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("maximizeHeight",
                    (m_maximizeHeight.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue()));

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties");

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonLayout.addComponent(ok);

    /**
     * Adding the layout and setting the content
     */
    //verticalLayout.addComponent(buttonLayout);

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

From source file:org.semanticsoft.vaaclipse.presentation.renderers.WorkbenchWindowRenderer.java

License:Open Source License

@Override
public void createWidget(MUIElement element, MElementContainer<MUIElement> parent) {
    if (element instanceof MWindow) {
        final MWindow mWindow = (MWindow) element;
        Component currentMainWindow = vaadinUI.getContent();
        if (element.getTags().contains(Tags.MAIN_WINDOW)) {
            Panel window = new Panel();
            window.setContent(new TrimmedWindowContent());
            vaadinUI.getPage().setTitle(mWindow.getLocalizedLabel());
            element.setWidget(window);// w  w  w. j a v  a  2 s. com
            ((MWindow) element).getContext().set(Panel.class, window);
            window.setSizeFull();

            vaadinUI.setContent(window);

            app.setSelectedElement(mWindow);
            mWindow.getContext().activate();
        } else {// case child windows
            if (currentMainWindow != null) {
                Window window = new Window();
                window.setContent(new TrimmedWindowContent());
                window.setImmediate(true);
                window.setPositionX(mWindow.getX());
                window.setPositionY(mWindow.getY());
                window.setWidth(mWindow.getWidth(), Unit.PIXELS);
                window.setHeight(mWindow.getHeight(), Unit.PIXELS);
                window.setCaption(mWindow.getLocalizedLabel());
                element.setWidget(window);
                ((MWindow) element).getContext().set(Panel.class, window);
                vaadinUI.addWindow(window);
            } else {
                throw new IllegalStateException(
                        "Can not add child window because application has not main window");
            }
        }

        IEclipseContext localContext = getContext(element);
        localContext.set(ISaveHandler.class, new ISaveHandler() {
            public Save promptToSave(MPart dirtyPart) {
                // Object[] elements =
                // promptForSave(Collections.singleton(dirtyPart));
                // if (elements == null) {
                // return Save.CANCEL;
                // }
                // return elements.length == 0 ? Save.NO : Save.YES;

                if (saveCandidate == null) {
                    saveCandidate = dirtyPart;

                    PartRenderer partRenderer = (PartRenderer) saveCandidate.getRenderer();
                    SavePromptSetup setup = partRenderer.getSavePromptSetup(saveCandidate);
                    String caption = setup.getCaption() != null ? setup.getCaption() : "Save";
                    String msg = setup.getMessage() != null ? setup.getMessage()
                            : String.format("%s has been modified. Save changes?",
                                    saveCandidate instanceof MInputPart
                                            ? ((MInputPart) saveCandidate).getInputURI()
                                            : "Data");

                    OptionDialog.show(vaadinUI, caption, msg, new String[] { "Yes", "No", "Cancel" }, 400, 80,
                            Component.UNITS_PIXELS, new OptionDialog.OptionListener() {

                                @Override
                                public void optionSelected(OptionDialog dlg, int optionId) {
                                    switch (optionId) {
                                    case 0:
                                        s = Save.YES;
                                        break;
                                    case 1:
                                        s = Save.NO;
                                        break;
                                    case 2:
                                        s = Save.CANCEL;
                                        break;

                                    default:
                                        s = null;
                                    }

                                    if (partService.savePart(saveCandidate, true)) {
                                        partService.hidePart(saveCandidate);
                                    }
                                    saveCandidate = null;
                                    dlg.close();
                                }
                            });

                    return Save.CANCEL;
                } else {
                    return s;
                }

            }

            public Save[] promptToSave(Collection<MPart> dirtyParts) {
                // List<MPart> parts = new ArrayList<MPart>(dirtyParts);
                //
                // Save[] response = new Save[dirtyParts.size()];
                // Object[] elements = promptForSave(parts);
                // if (elements == null) {
                // Arrays.fill(response, Save.CANCEL);
                // } else {
                // Arrays.fill(response, Save.NO);
                // for (int i = 0; i < elements.length; i++) {
                // response[parts.indexOf(elements[i])] = Save.YES;
                // }
                // }
                // return response;

                throw new RuntimeException("Multiple saving is not implemented yet");
            }
        });
    }
}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

private Panel createControls() {
    Panel panel = new Panel();
    panel.setWidth(100, Unit.PERCENTAGE);

    controls = new HorizontalLayout();
    controls.setSpacing(true);//from   w ww  . ja  v  a 2s. co  m
    controls.setMargin(true);
    panel.setContent(controls);

    start = createStartDateField();
    end = createEndDateField();

    Button createStep = new Button("Create New Step...", createStepClickListener);

    HorizontalLayout heightAndUnit = new HorizontalLayout(Util.createHeightEditor(gantt),
            Util.createHeightUnitEditor(gantt));

    HorizontalLayout widthAndUnit = new HorizontalLayout(Util.createWidthEditor(gantt),
            Util.createWidthUnitEditor(gantt));

    reso = new NativeSelect("Resolution");
    reso.setNullSelectionAllowed(false);
    reso.addItem(org.tltv.gantt.client.shared.Resolution.Hour);
    reso.addItem(org.tltv.gantt.client.shared.Resolution.Day);
    reso.addItem(org.tltv.gantt.client.shared.Resolution.Week);
    reso.setValue(gantt.getResolution());
    reso.setImmediate(true);
    reso.addValueChangeListener(resolutionValueChangeListener);

    localeSelect = new NativeSelect("Locale") {
        @Override
        public void attach() {
            super.attach();

            if (getValue() == null) {
                // use default locale
                setValue(gantt.getLocale());
                addValueChangeListener(localeValueChangeListener);
            }
        }
    };
    localeSelect.setNullSelectionAllowed(false);
    for (Locale l : Locale.getAvailableLocales()) {
        localeSelect.addItem(l);
        localeSelect.setItemCaption(l, l.getDisplayName(getLocale()));
    }
    localeSelect.setImmediate(true);

    String[] zones = new String[] { "GMT-0", "GMT-1", "GMT-2", "GMT-3", "GMT-4", "GMT-5", "GMT-6", "GMT-7",
            "GMT-8", "GMT-9", "GMT-10", "GMT-11", "GMT-12", "GMT+1", "GMT+2", "GMT+3", "GMT+4", "GMT+5",
            "GMT+6", "GMT+7", "GMT+8", "GMT+9", "GMT+10", "GMT+11", "GMT+12", "GMT+13", "GMT+14" };
    NativeSelect timezoneSelect = new NativeSelect("Timezone");
    timezoneSelect.setNullSelectionAllowed(false);
    timezoneSelect.addItem("Default");
    timezoneSelect.setItemCaption("Default", "Default (" + TimeZone.getDefault().getDisplayName() + ")");
    for (String timezoneId : zones) {
        TimeZone tz = TimeZone.getTimeZone(timezoneId);
        timezoneSelect.addItem(timezoneId);
        timezoneSelect.setItemCaption(timezoneId, tz.getDisplayName(getLocale()));
    }
    timezoneSelect.setValue("Default");
    timezoneSelect.setImmediate(true);
    timezoneSelect.addValueChangeListener(timezoneValueChangeListener);

    controls.addComponent(start);
    controls.addComponent(end);
    controls.addComponent(reso);
    controls.addComponent(localeSelect);
    controls.addComponent(timezoneSelect);
    controls.addComponent(heightAndUnit);
    controls.addComponent(widthAndUnit);
    controls.addComponent(createStep);
    controls.setComponentAlignment(createStep, Alignment.MIDDLE_LEFT);

    return panel;
}

From source file:pt.ist.vaadinframework.terminal.DefaultSystemErrorWindow.java

License:Open Source License

@Override
protected void setErrorContext(Throwable systemError) {
    removeAllComponents();//from   www . j  av a2s.c  o  m
    setCaption(VaadinResources.getString(ERROR_WINDOW_TITLE));
    getContent().setSizeUndefined();
    setModal(true);
    center();
    setBorder(Window.BORDER_NONE);
    setClosable(false);
    setCloseShortcut(KeyCode.ESCAPE);
    setResizable(false);
    ((MarginHandler) getContent()).setMargin(new MarginInfo(true));
    ((SpacingHandler) getContent()).setSpacing(true);
    addComponent(new Label(VaadinResources.getString(ERROR_WINDOW_ANNOUNCEMENT_LABEL)));

    Panel scroll = new Panel();
    addComponent(scroll);
    scroll.setWidth(450, UNITS_PIXELS);
    scroll.setHeight(450, UNITS_PIXELS);
    stacktrace = new Label();
    scroll.addComponent(stacktrace);
    ByteArrayOutputStream stream = null;
    try {
        stream = new ByteArrayOutputStream();
        systemError.printStackTrace(new PrintStream(stream));
        stacktrace.setValue(stream.toString());
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }
}