Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Developer12145
    started a topic Problems with showPrintPreview

    Problems with showPrintPreview

    Hi Isomorphic,

    first of all, my setup:
    SmartClient Version: v12.0p_2019-07-29/PowerEdition Deployment (built 2019-07-29)

    Tested Browsers:
    • Firefox 26.0
    • Chrome Version 75.0.3770.142
    • Chromium Version 61.0.3163.79
    • Edge 42.17134.1.0

    Code:
    package com.smartgwt.sample.client;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.ReadOnlyDisplayAppearance;
    import com.smartgwt.client.types.VerticalAlignment;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.PrintProperties;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.layout.VStack;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class BuiltInDS implements EntryPoint {
        private DynamicForm boundFormAnimals;
        private DynamicForm boundFormEmployees;
        private DynamicForm boundFormSupplyItem;
        private DynamicForm boundForm2Animals;
        private List<DynamicForm> dFlist = new ArrayList<DynamicForm>();
        private IButton printBtn;
        private IButton print2Btn;
    
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            VStack vStack = new VStack();
            vStack.setWidth100();
            boundFormAnimals = new PrintDynamicForm();
            boundFormAnimals.setDataSource(DataSource.get("animals"));
            boundFormAnimals.setImplicitCriteria(new Criteria("scientificName", "Allligator mississippiensis"));
            boundFormAnimals.fetchData();
    
            boundFormEmployees = new PrintDynamicForm();
            boundFormEmployees.setDataSource(DataSource.get("employees"));
            boundFormEmployees.setImplicitCriteria(new Criteria("EmployeeId", "4"));
            boundFormEmployees.fetchData();
    
            boundFormSupplyItem = new PrintDynamicForm();
            boundFormSupplyItem.setDataSource(DataSource.get("supplyItem"));
            boundFormSupplyItem.setImplicitCriteria(new Criteria("itemID", "1"));
            boundFormSupplyItem.fetchData();
    
            boundForm2Animals = new PrintDynamicForm();
            boundForm2Animals.setDataSource(DataSource.get("animals"));
            boundForm2Animals.setImplicitCriteria(new Criteria("scientificName", "Allligator mississippiensis"));
            boundForm2Animals.fetchData();
    
            dFlist.add(boundFormAnimals);
            dFlist.add(boundFormEmployees);
            dFlist.add(boundFormSupplyItem);
            dFlist.add(boundForm2Animals);
    
            HLayout hLayout = new HLayout();
            hLayout.setWidth100();
            hLayout.setHeight100();
    
            VLayout left = new VLayout();
            VLayout right = new VLayout();
    
            hLayout.addMembers(left, right);
    
            int i = 0;
            for (DynamicForm df : dFlist) {
                if (i % 2 == 0)
                    left.addMember(df);
                else
                    right.addMember(df);
                i++;
            }
    
            hLayout.setMembersMargin(10);
    
            printBtn = new IButton("Left Layout not Top Aligned, IButton not omitted") {
                {
                    setWidth(200);
                }
            };
    
            printBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    Canvas.showPrintPreview(vStack.getMembers(), new PrintProperties() {
                        {
                            setOmitControls(new String[] { "IButton" });
                        }
                    }, null, null);
                }
            });
    
            print2Btn = new IButton("Left Layout not Top Aligned, IButton not omitted") {
                {
                    setWidth(200);
                }
            };
            Object[] objects = new Object[1];
            objects[0] = vStack;
    
            print2Btn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    Canvas.showPrintPreview(objects, new PrintProperties() {
                        {
                            setOmitControls(new String[] { "IButton" });
                        }
                    }, null, null);
                }
            });
    
            left.draw();
            right.draw();
            vStack.addMember(hLayout);
            vStack.addMember(printBtn);
            vStack.addMember(print2Btn);
            vStack.draw();
            int height1 = left.getVisibleHeight();
            int height2 = right.getVisibleHeight();
            Integer height3 = height1 - height2;
            if (height3 != 0) {
                if (i % 2 == 0) {
                    left.addMember(new VStack() {
                        {
                            setHeight(Math.abs(height3));
                            setBackgroundColor("green");
                        }
                    });
                } else {
                    right.addMember(new VStack() {
                        {
                            setHeight(Math.abs(height3));
                            setBackgroundColor("green");
                        }
                    });
                }
            }
        }
    
        private class PrintDynamicForm extends DynamicForm {
    
            PrintDynamicForm() {
                setClipItemTitles(true);
                setCellPadding(7);
                setNumCols(2);
                setWidth100();
                setHeight100();
                setNumCols(2);
                setColWidths("200", "*");
                setIsGroup(true);
                setGroupBorderCSS("1px solid black");
                setReadOnlyDisplay(ReadOnlyDisplayAppearance.STATIC);
                setCanEdit(false);
            }
        }
    }
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.1//EN"
       "http://www.gwtproject.org/doctype/2.6.1/gwt-module.dtd">
    <module rename-to="builtinds">
        <inherits name='com.google.gwt.user.User'/>
    
        <inherits name="com.smartgwt.tools.SmartGwtToolsNoTheme"/>
        <inherits name="com.smartgwtee.tools.Tools"/>
    
        <!-- Inheriting SmartGwtTools picks up Enterprise resources since the developer console may
             have some minor functionality issues in other skins, and it will load Enterprise skin
             if its resources are found.  To have it instead pick up the skin used by this project
             (which you can change below), substitute:
    
             <inherits name="com.smartgwt.tools.SmartGwtToolsNoTheme"/>
    
             For other tools, you may need to inherit specific skin resources, such as tool skins.
             For example, VisualBuilder needs Tahoe and the took skins, so you may need to add:
    
             <inherits name="com.smartclient.theme.tahoe.TahoeResources"/>
             <inherits name="com.smartclientee.toolskin.ToolSkinResources"/>
             <inherits name="com.smartclientee.toolskinnative.ToolSkinNativeResources"/>
        -->
    
        <inherits name="com.smartgwtee.SmartGwtEENoTheme"/>
    
        <inherits name="com.smartclient.theme.tahoe.Tahoe"/>
    
        <!-- Uncomment lines below for GWT Super Dev Mode Support in GWT versions before 2.7.0:
           - both lines needed for GWT < 2.6, only the first line needed for GWT 2.6.x
           - see http://www.smartclient.com/docs/release/a/b/c/go.html#group..debugging -->
        <!-- <add-linker name="xsiframe" />                                             -->
        <!-- <set-configuration-property name="devModeRedirectEnabled" value="true" />  -->
    
        <!-- Uncomment lines below for GWT "stack emulation" with file/line number info -->
        <!-- <set-property               name="compiler.stackMode"  value="emulated" /> -->
        <!-- <set-configuration-property name="compiler.emulatedStack.recordFileNames"
                                         value="true" />                                -->
        <!-- <set-configuration-property name="compiler.emulatedStack.recordLineNumbers"
                                         value="true" />                                -->
    
        <!-- Uncomment the lines below in GWT 2.7+ to enable configuring of the path of the module
             relative to the main HTML page.  By default for our sample projects, the main page is
             directly in the root (war) directory above the module directory, so the relative
             path is just the module (directory) name.
    
             The syntax is <moduleName>=<relative path> as the example binding below illustrates.
             Multiple bindings can be added to support multiple modules inheriting this module file. 
        -->
        <!-- <define-configuration-property name="scriptInjector.pageRelativeModulePath"
                                            is-multi-valued="true"/> -->
        <!-- <extend-configuration-property name="scriptInjector.pageRelativeModulePath"
                                            value="builtinds=builtinds"/> -->
    
        <entry-point class='com.smartgwt.sample.client.BuiltInDS'/>
    </module>
    Now lets see what I wanna accomplish:

    In our Application, we have several DynamicForms, we would like to print via "Canvas.showPrintPreview(...)" as PDF or directly using a printer. We also want so safe space, that's why I used a HLayout "hLayout" which gets two VLayouts as members (VLayout left, and VLayout right). Depending on the number of DynamicForms that are visible I put them in left, right, once after another. This works fine so far, all DynamicForms align from top to bottom one under another, but when I open the PrintPreview via printBtn or print2Btn, The DynamicForms align centered within the HLayout (I guess).

    And that is my 1. Problem:

    For VLayouts, the Docs say: Alignment of all members in this Layout on the length axis. Defaults to "top" for vertical Layouts, and "left" for horizontal Layouts.
    It does the default within the VStack "vStack", but not within the "showPrintPreview" Window. Is there a setter, so I could achieve that or is this behavior not intended? I want the first DynamicForm of "left" aligned on the same edge as the first DynamicForm within "right.

    also tried, to pass

    Code:
            Object[] objects = new Object[1];
            objects[0] = vStack;
    to the showPrintPreview components array, because I saw earlier that it could make a difference. But here it didn't, same behavior as before.


    2. Problem:

    The Canvas.showPrintPreview() can take PrintProperties in the parameter list. As you can see within the printBtn/print2Btn I tried it.
    The docs for the "setOmitControls()" method say:
    "An array of Strings indicating the classNames of controls that should be omitted from printing. By default, omitControls includes all button-based controls, menus and similar interactive controls that are typically useless in printed output."

    If You take a look, at what I pass as "components" for the PrintPreview, the printBtn/print2Bt are withing vStack.getMembers(), but not omitted. Did I understand the docs wrong? How can I achieve that the two buttons are not shown within the PrintPreview Window?

    3. Problem:

    I also pass another VStack to VLayout left/right, depending on the amount of DynamicForms that are in those two layouts. This VStack gets the color green. The problem is, it does not appear within the PrintPreview Window. Why?

    Thanks in Advance,
    Kind Regards










  • Isomorphic
    replied
    1. As the docs cover, and as we covered in the related thread, sizing and alignment is not preserved when printing.

    2. Buttons are automatically omitted, as you can see by printing just about any Showcase example. If you are not seeing buttons omitted from print previews, it seems like you must have attempted some kind of global customization that was invalid. Please look into this. As far as the usage of omitControls, you would need to use the classname as shown in the Watch Tab. However again, buttons are already omitted so there is no need to explicitly omit them.

    3. Not all styling is included in printed output because it would often be wrong to do so. The rationale is explained in more depth here

    Leave a comment:


  • Developer12145
    replied
    This post is related to this one: https://forums.smartclient.com/forum...-print-preview

    Leave a comment:

Working...
X