Search in sources :

Example 1 with EJRWTScrolledComposite

use of org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite in project rap by entirej.

the class EJRWTHtmlTableBlockRenderer method buildGuiComponent.

@Override
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
    if (_browser != null && !_browser.isDisposed()) {
        _browser.dispose();
    }
    EJBlockProperties blockProperties = _block.getProperties();
    EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
    EJFrameworkExtensionProperties blockRendererProperties = blockProperties.getBlockRendererProperties();
    boolean addHeader = true;
    if (blockRendererProperties != null) {
        addHeader = blockRendererProperties.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true);
        EJCoreFrameworkExtensionPropertyList propertyList = blockRendererProperties.getPropertyList(ACTIONS);
        if (propertyList != null) {
            List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
            for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
                String actionID = entry.getProperty(ACTION_ID);
                String actionkey = entry.getProperty(ACTION_KEY);
                if (actionID != null && actionkey != null && actionID.trim().length() > 0 && actionkey.trim().length() > 0) {
                    addActionKeyinfo(actionkey, actionID);
                }
            }
        }
    }
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = mainScreenProperties.getWidth();
    gridData.heightHint = mainScreenProperties.getHeight();
    gridData.horizontalSpan = mainScreenProperties.getHorizontalSpan();
    gridData.verticalSpan = mainScreenProperties.getVerticalSpan();
    gridData.grabExcessHorizontalSpace = mainScreenProperties.canExpandHorizontally();
    gridData.grabExcessVerticalSpace = mainScreenProperties.canExpandVertically();
    // if (gridData.grabExcessHorizontalSpace)
    // gridData.minimumHeight = mainScreenProperties.getHeight();
    // if (gridData.grabExcessVerticalSpace)
    // gridData.minimumWidth = mainScreenProperties.getHeight();
    blockCanvas.setLayoutData(gridData);
    scrollComposite = new EJRWTScrolledComposite(blockCanvas, SWT.V_SCROLL | SWT.H_SCROLL);
    scrollComposite.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
    scrollComposite.setExpandHorizontal(true);
    scrollComposite.setExpandVertical(true);
    scrollComposite.setMinSize(mainScreenProperties.getWidth(), mainScreenProperties.getHeight());
    boolean filtered = blockRendererProperties.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false);
    this.filterKeepOnRefresh = blockRendererProperties.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER_KEEP_ON_REFRESH, false);
    this.textSelection = blockRendererProperties.getBooleanProperty(TEXT_SELECTION, false);
    if (mainScreenProperties.getDisplayFrame()) {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(scrollComposite, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            hookKeyListener(group);
            scrollComposite.setContent(group);
            group.setLayout(new GridLayout());
            scrollComposite.setLayoutData(gridData);
            if (frameTitle != null && frameTitle.length() > 0) {
                group.setText(frameTitle);
            }
            if (filtered) {
                filterHtml = new EJRWTAbstractFilteredHtml(group, SWT.NONE, textSelection) {

                    @Override
                    public void filter(String filter) {
                        _filteredContentProvider.setFilter(filter);
                        createHTML();
                    }

                    @Override
                    protected EJRWTHtmlView doCreateTableViewer(Composite parent, int style, boolean textSelection) {
                        return new EJRWTHtmlView(parent, SWT.NONE, textSelection) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void action(String method, JsonObject parameters) {
                                if ("eselect".equals(method)) {
                                    final Object arg1 = parameters.get("0").asString();
                                    if (arg1 instanceof String) {
                                        EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                                        if (currentRec != recordAt) {
                                            currentRec = recordAt;
                                            if (currentRec != null)
                                                _block.newRecordInstance(currentRec);
                                        }
                                    }
                                } else if ("eaction".equals(method)) {
                                    final Object arg1 = parameters.get("0").asString();
                                    Object arg2 = parameters.get("1").asString();
                                    if (arg1 instanceof String) {
                                        if (arg2 instanceof String) {
                                            EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                            if (currentRec != recordAt) {
                                                currentRec = recordAt;
                                                if (currentRec != null)
                                                    _block.newRecordInstance(currentRec);
                                            }
                                        }
                                        Display.getDefault().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                try {
                                                    _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                                } catch (EJApplicationException exception) {
                                                    _block.getFrameworkManager().handleException(exception);
                                                }
                                            }
                                        });
                                    }
                                } else if ("esort".equals(method)) {
                                    handleSort(parameters);
                                }
                            }
                        };
                    }
                };
                _browser = filterHtml.getViewer();
                defaultMessage = blockRendererProperties.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
                if (defaultMessage != null)
                    filterHtml.getFilterControl().setMessage(defaultMessage);
            } else {
                _browser = new EJRWTHtmlView(group, SWT.NONE, textSelection) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void action(String method, JsonObject parameters) {
                        if ("eselect".equals(method)) {
                            final Object arg1 = parameters.get("0").asString();
                            if (arg1 instanceof String) {
                                EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                                if (currentRec != recordAt) {
                                    currentRec = recordAt;
                                    if (currentRec != null)
                                        _block.newRecordInstance(currentRec);
                                }
                            }
                        } else if ("eaction".equals(method)) {
                            final Object arg1 = parameters.get("0").asString();
                            Object arg2 = parameters.get("1").asString();
                            if (arg1 instanceof String) {
                                if (arg2 instanceof String) {
                                    EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                    if (currentRec != recordAt) {
                                        currentRec = recordAt;
                                        if (currentRec != null)
                                            _block.newRecordInstance(currentRec);
                                    }
                                }
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        try {
                                            _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                        } catch (EJApplicationException exception) {
                                            _block.getFrameworkManager().handleException(exception);
                                        }
                                    }
                                });
                            }
                        } else if ("esort".equals(method)) {
                            handleSort(parameters);
                        }
                    }
                };
            }
        } else {
            if (filtered) {
                filterHtml = new EJRWTAbstractFilteredHtml(scrollComposite, SWT.NONE, textSelection) {

                    @Override
                    public void filter(String filter) {
                        _filteredContentProvider.setFilter(filter);
                        createHTML();
                    }

                    @Override
                    protected EJRWTHtmlView doCreateTableViewer(Composite parent, int style, boolean textSelection) {
                        return new EJRWTHtmlView(parent, SWT.NONE, textSelection) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void action(String method, JsonObject parameters) {
                                if ("eselect".equals(method)) {
                                    final Object arg1 = parameters.get("0").asString();
                                    if (arg1 instanceof String) {
                                        EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                                        if (currentRec != recordAt) {
                                            currentRec = recordAt;
                                            if (currentRec != null)
                                                _block.newRecordInstance(currentRec);
                                        }
                                    }
                                } else if ("eaction".equals(method)) {
                                    final Object arg1 = parameters.get("0").asString();
                                    Object arg2 = parameters.get("1").asString();
                                    if (arg1 instanceof String) {
                                        if (arg2 instanceof String) {
                                            EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                            if (currentRec != recordAt) {
                                                currentRec = recordAt;
                                                if (currentRec != null)
                                                    _block.newRecordInstance(currentRec);
                                            }
                                        }
                                        Display.getDefault().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                try {
                                                    _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                                } catch (EJApplicationException exception) {
                                                    _block.getFrameworkManager().handleException(exception);
                                                }
                                            }
                                        });
                                    }
                                } else if ("esort".equals(method)) {
                                    handleSort(parameters);
                                }
                            }
                        };
                    }
                };
                _browser = filterHtml.getViewer();
                defaultMessage = blockRendererProperties.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
                if (defaultMessage != null)
                    filterHtml.getFilterControl().setMessage(defaultMessage);
                scrollComposite.setContent(filterHtml);
                scrollComposite.setLayoutData(gridData);
            } else {
                filterHtml = null;
                _browser = new EJRWTHtmlView(scrollComposite, SWT.BORDER, textSelection) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void action(String method, JsonObject parameters) {
                        if ("eselect".equals(method)) {
                            final Object arg1 = parameters.get("0").asString();
                            if (arg1 instanceof String) {
                                EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                                if (currentRec != recordAt) {
                                    currentRec = recordAt;
                                    if (currentRec != null)
                                        _block.newRecordInstance(currentRec);
                                }
                            }
                        } else if ("eaction".equals(method)) {
                            final Object arg1 = parameters.get("0").asString();
                            Object arg2 = parameters.get("1").asString();
                            if (arg1 instanceof String) {
                                if (arg2 instanceof String) {
                                    EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                    if (currentRec != recordAt) {
                                        currentRec = recordAt;
                                        if (currentRec != null)
                                            _block.newRecordInstance(currentRec);
                                    }
                                }
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        try {
                                            _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                        } catch (EJApplicationException exception) {
                                            _block.getFrameworkManager().handleException(exception);
                                        }
                                    }
                                });
                            }
                        } else if ("esort".equals(method)) {
                            handleSort(parameters);
                        }
                    }
                };
                scrollComposite.setContent(_browser);
                scrollComposite.setLayoutData(gridData);
            }
        }
    } else {
        if (filtered) {
            filterHtml = new EJRWTAbstractFilteredHtml(scrollComposite, SWT.NONE, textSelection) {

                @Override
                public void filter(String filter) {
                    _filteredContentProvider.setFilter(filter);
                    createHTML();
                }

                @Override
                protected EJRWTHtmlView doCreateTableViewer(Composite parent, int style, boolean textSelection) {
                    return new EJRWTHtmlView(parent, SWT.NONE, textSelection) {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void action(String method, JsonObject parameters) {
                            if ("eselect".equals(method)) {
                                final Object arg1 = parameters.get("0").asString();
                                if (arg1 instanceof String) {
                                    EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                                    if (currentRec != recordAt) {
                                        currentRec = recordAt;
                                        if (currentRec != null)
                                            _block.newRecordInstance(currentRec);
                                    }
                                }
                            } else if ("eaction".equals(method)) {
                                final Object arg1 = parameters.get("0").asString();
                                Object arg2 = parameters.get("1").asString();
                                if (arg1 instanceof String) {
                                    if (arg2 instanceof String) {
                                        EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                        if (currentRec != recordAt) {
                                            currentRec = recordAt;
                                            if (currentRec != null)
                                                _block.newRecordInstance(currentRec);
                                        }
                                    }
                                    Display.getDefault().asyncExec(new Runnable() {

                                        @Override
                                        public void run() {
                                            try {
                                                _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                            } catch (EJApplicationException exception) {
                                                _block.getFrameworkManager().handleException(exception);
                                            }
                                        }
                                    });
                                }
                            } else if ("esort".equals(method)) {
                                handleSort(parameters);
                            }
                        }
                    };
                }
            };
            _browser = filterHtml.getViewer();
            scrollComposite.setContent(filterHtml);
            scrollComposite.setLayoutData(gridData);
            defaultMessage = blockRendererProperties.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
            if (defaultMessage != null)
                filterHtml.getFilterControl().setMessage(defaultMessage);
        } else {
            filterHtml = null;
            _browser = new EJRWTHtmlView(scrollComposite, SWT.NONE, textSelection) {

                private static final long serialVersionUID = 1L;

                @Override
                public void action(String method, JsonObject parameters) {
                    if ("eselect".equals(method)) {
                        final Object arg1 = parameters.get("0").asString();
                        if (arg1 instanceof String) {
                            EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg1));
                            if (currentRec != recordAt) {
                                currentRec = recordAt;
                                if (currentRec != null)
                                    _block.newRecordInstance(currentRec);
                            }
                        }
                    } else if ("eaction".equals(method)) {
                        final Object arg1 = parameters.get("0").asString();
                        Object arg2 = parameters.get("1").asString();
                        if (arg1 instanceof String) {
                            if (arg2 instanceof String) {
                                EJDataRecord recordAt = getRecordAt(Integer.valueOf((String) arg2));
                                if (currentRec != recordAt) {
                                    currentRec = recordAt;
                                    if (currentRec != null)
                                        _block.newRecordInstance(currentRec);
                                }
                            }
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        _block.executeActionCommand((String) arg1, EJScreenType.MAIN);
                                    } catch (EJApplicationException exception) {
                                        _block.getFrameworkManager().handleException(exception);
                                    }
                                }
                            });
                        }
                    } else if ("esort".equals(method)) {
                        handleSort(parameters);
                    }
                }
            };
            scrollComposite.setContent(_browser);
            scrollComposite.setLayoutData(gridData);
            hookKeyListener(scrollComposite);
        }
    }
    _browser.addFocusListener(new FocusListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void focusLost(FocusEvent arg0) {
            setHasFocus(false);
        }

        @Override
        public void focusGained(FocusEvent arg0) {
            setHasFocus(true);
        }
    });
    _browser.addMouseListener(new MouseAdapter() {

        private static final long serialVersionUID = 1L;

        @Override
        public void mouseDown(MouseEvent arg0) {
            setHasFocus(true);
        }
    });
    if (_items.isEmpty()) {
        Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
        int cellSpacing = blockProperties.getBlockRendererProperties().getIntProperty(CELL_SPACING_PROPERTY, 0);
        int cellPadding = blockProperties.getBlockRendererProperties().getIntProperty(CELL_PADDING_PROPERTY, 0);
        String paddingStyle = "";
        if (cellPadding > 0) {
            String str = String.valueOf(cellPadding);
            paddingStyle += String.format("padding: %spx %spx %spx %spx; ", str, str, str, str);
        }
        StringBuilder header = new StringBuilder("<thead><tr>");
        boolean rowSelection = blockProperties.getBlockRendererProperties().getBooleanProperty(ROW_SELECTION, false);
        String selectionTD = "<th width=1 ></td>";
        if (rowSelection) {
            header.append(selectionTD);
        }
        for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
            Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
            for (EJScreenItemProperties screenItemProperties : itemProperties) {
                EJCoreMainScreenItemProperties itemProps = (EJCoreMainScreenItemProperties) screenItemProperties;
                EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, itemProps.getReferencedItemName());
                EJManagedItemRendererWrapper renderer = item.getManagedItemRenderer();
                if (renderer != null) {
                    EJRWTAppItemRenderer itemRenderer = (EJRWTAppItemRenderer) renderer.getUnmanagedRenderer();
                    ColumnLabelProvider labelProvider = itemRenderer.createColumnLabelProvider(itemProps, item);
                    _items.add(itemProps);
                    _itemLabelProviders.put(itemProps.getReferencedItemName(), labelProvider);
                    if (addHeader) {
                        String styleClass = "default_all";
                        EJFrameworkExtensionProperties rendererProperties = item.getReferencedItemProperties().getItemRendererProperties();
                        EJFrameworkExtensionProperties extentionProperties = itemProps.getBlockRendererRequiredProperties();
                        int width = -1;
                        if (width == -1) {
                            width = extentionProperties.getIntProperty(DISPLAY_WIDTH_PROPERTY, 0);
                        }
                        header.append("<th ");
                        if (width > 0) {
                            Font font = labelProvider.getFont(new Object());
                            if (font == null)
                                font = _browser.getFont();
                            if (font != null) {
                                float avgCharWidth = RWTUtils.getAvgCharWidth(font);
                                if (avgCharWidth > 0) {
                                    if (width != 1) {
                                        // add +1 padding
                                        width = ((int) (((width + 1) * avgCharWidth)));
                                    }
                                }
                            }
                            header.append(String.format(" width=%s ", width));
                        }
                        header.append(" ");
                        String alignment = null;
                        String alignmentProperty = rendererProperties.getStringProperty(PROPERTY_ALIGNMENT);
                        if (alignmentProperty == null) {
                            alignmentProperty = rendererProperties.getStringProperty("ALLIGNMENT");
                        }
                        alignment = getComponentAlignment(alignmentProperty);
                        SortInfo sortInfo = null;
                        if (extentionProperties.getBooleanProperty(ALLOW_ROW_SORTING, true)) {
                            EJRWTAbstractTableSorter columnSorter = itemRenderer.getColumnSorter(itemProps, item);
                            if (columnSorter != null) {
                                _itemSortProviders.put(itemProps.getReferencedItemName(), columnSorter);
                                sortInfo = new SortInfo();
                                sortInfo.columnName = itemProps.getReferencedItemName();
                                _sortContext.put(sortInfo.id, sortInfo);
                            }
                        }
                        String functionDef = null;
                        if (sortInfo != null) {
                            functionDef = String.format("em='esort' earg='%s' ", sortInfo.id);
                        }
                        String valueVA = blockProperties.getBlockRendererProperties().getStringProperty(HEADER_VA);
                        if (valueVA != null && valueVA.length() > 0) {
                            styleClass = valueVA;
                            valueVA = rendererProperties.getStringProperty(HEADER_VA);
                            if (valueVA != null && valueVA.length() > 0)
                                styleClass = valueVA;
                        }
                        header.append(String.format(" class=\"%s\" ", styleClass));
                        if (alignment != null) {
                            header.append(String.format(" align=\'%s\'", alignment));
                        }
                        if (paddingStyle != null) {
                            header.append(String.format(" style=\'%s\'", paddingStyle));
                        }
                        if (itemProps.getHint() != null && !itemProps.getHint().isEmpty()) {
                            header.append(String.format(" title=\'%s\'", itemProps.getHint()));
                        }
                        header.append("> ");
                        if (itemProps.getLabel() != null) {
                            if (functionDef != null) {
                                header.append(String.format("<ejl><u %s class=\"%s, %s\"  ", "style=\"line-height: 100%\"", ("default_all".equals(styleClass) ? "default_link_fg" : "default_link"), styleClass));
                                header.append(functionDef).append(">");
                            }
                            header.append(!(extentionProperties.getBooleanProperty(ENABLE_MARKUP, false) || rendererProperties.getBooleanProperty("HTML_FORMAT", false)) ? ignoreHtml(itemProps.getLabel()) : itemProps.getLabel());
                            if (sortInfo != null)
                                header.append(String.format("<esh %s/>", sortInfo.id));
                        }
                        header.append("</th>");
                    }
                }
            }
        }
        if (addHeader) {
            header.append("</tr></thead>");
            _headerTag = header.toString();
        }
    }
    hookKeyListener(_browser);
    final EJRWTAbstractFilteredHtml _filterHtml = filterHtml;
    _filteredContentProvider = new FilteredContentProvider() {

        boolean matchItem(EJDataRecord rec) {
            if (filter != null && filter.trim().length() > 0) {
                for (ColumnLabelProvider filterTextProvider : _itemLabelProviders.values()) {
                    String text = filterTextProvider.getText(rec);
                    if (text != null && text.toLowerCase().contains(filter.toLowerCase())) {
                        return true;
                    }
                }
                // if no match try to match Numeric value
                try {
                    double parseDouble = Double.parseDouble(filter);
                    for (String item : _itemLabelProviders.keySet()) {
                        Object value = rec.getValue(item);
                        if (value instanceof Number) {
                            if (((Number) value).doubleValue() == parseDouble) {
                                return true;
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                // ignore
                }
            }
            return false;
        }

        @Override
        public void setFilter(String filter) {
            if (getFilter() != null && getFilter().equals(filter))
                return;
            super.setFilter(filter);
            _tableBaseRecords.clear();
            if (filter == null || filter.trim().length() == 0) {
                if (_filterHtml != null) {
                    _filterHtml.clearText();
                }
                _tableBaseRecords.addAll(_block.getBlock().getRecords());
            } else {
                for (EJDataRecord record : _block.getBlock().getRecords()) {
                    if (matchItem(record)) {
                        _tableBaseRecords.add(record);
                    }
                }
            }
        }
    };
    createHTML();
}
Also used : Group(org.eclipse.swt.widgets.Group) EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) JsonObject(org.eclipse.rap.json.JsonObject) FocusEvent(org.eclipse.swt.events.FocusEvent) Font(org.eclipse.swt.graphics.Font) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) EJCoreFrameworkExtensionPropertyList(org.entirej.framework.core.extensions.properties.EJCoreFrameworkExtensionPropertyList) EJRWTAbstractTableSorter(org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) EJApplicationException(org.entirej.framework.core.EJApplicationException) EJRWTHtmlView(org.entirej.applicationframework.rwt.component.EJRWTHtmlView) EJRWTAppItemRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) FilteredContentProvider(org.entirej.applicationframework.rwt.renderers.html.EJRWTAbstractFilteredHtml.FilteredContentProvider) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) GridData(org.eclipse.swt.layout.GridData) JsonObject(org.eclipse.rap.json.JsonObject) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) FocusListener(org.eclipse.swt.events.FocusListener)

Example 2 with EJRWTScrolledComposite

use of org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite in project rap by entirej.

the class EJRWTFormPopUp method showForm.

public void showForm() {
    final int height = _popupController.getPopupForm().getProperties().getFormHeight();
    final int width = _popupController.getPopupForm().getProperties().getFormWidth();
    EJManagedFormRendererWrapper wrapper = _popupController.getPopupForm().getManagedRenderer();
    final EJRWTAppFormRenderer formRenderer = (EJRWTAppFormRenderer) wrapper.getUnmanagedRenderer();
    _popupDialog = new EJRWTAbstractDialog(_mainShell) {

        @Override
        public void createBody(Composite parent) {
            parent.setLayout(new FillLayout());
            final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            formRenderer.createControl(scrollComposite);
            scrollComposite.setContent(formRenderer.getGuiComponent());
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            scrollComposite.setMinSize(width, height);
        }

        @Override
        public void canceled() {
            _popupController.getPopupForm().close();
        }
    };
    _popupDialog.create();
    _popupDialog.getShell().setText(_popupController.getPopupForm().getProperties().getTitle());
    // add offset
    _popupDialog.getShell().setSize(width + 50, height + 70);
    _popupDialog.open();
    _popupDialog.activateDialog();
}
Also used : EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FillLayout(org.eclipse.swt.layout.FillLayout) EJManagedFormRendererWrapper(org.entirej.framework.core.renderers.EJManagedFormRendererWrapper) EJRWTAppFormRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppFormRenderer)

Example 3 with EJRWTScrolledComposite

use of org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite in project rap by entirej.

the class EJRWTUpdateScreenRenderer method setupUpdateScreen.

private void setupUpdateScreen() {
    // Setup pane for query window
    EJFrameworkExtensionProperties rendererProperties = _block.getProperties().getUpdateScreenRendererProperties();
    String title = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.TITLE);
    final int width = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.WIDTH, 300);
    final int height = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.HEIGHT, 500);
    _maximize = rendererProperties.getBooleanProperty(EJRWTScreenRendererDefinitionProperties.MAXIMIZE, false);
    final int numCols = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.NUM_COLS, 1);
    final String updateButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXECUTE_BUTTON_TEXT);
    final String cancelButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CANCEL_BUTTON_TEXT);
    EJFrameworkExtensionProperties extraButtonsGroup = rendererProperties.getPropertyGroup(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTONS_GROUP);
    final String button1Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_ONE_LABEL);
    final String button1Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_ONE_COMMAND);
    final String button2Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_TWO_LABEL);
    final String button2Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_TWO_COMMAND);
    final String button3Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_THREE_LABEL);
    final String button3Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_THREE_COMMAND);
    final String button4Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FOUR_LABEL);
    final String button4Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FOUR_COMMAND);
    final String button5Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FIVE_LABEL);
    final String button5Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FIVE_COMMAND);
    final int ID_BUTTON_1 = 1;
    final int ID_BUTTON_2 = 2;
    final int ID_BUTTON_3 = 3;
    final int ID_BUTTON_4 = 4;
    final int ID_BUTTON_5 = 5;
    _updateDialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        @Override
        public void createBody(Composite parent) {
            EJ_RWT.setTestId(parent, _block.getProperties().getName() + ".update-screen");
            parent.setLayout(new FillLayout());
            final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            EJRWTEntireJGridPane _mainPane = new EJRWTEntireJGridPane(scrollComposite, numCols);
            _mainPane.cleanLayout();
            EJBlockProperties blockProperties = _block.getProperties();
            addAllItemGroups(blockProperties.getScreenItemGroupContainer(EJScreenType.UPDATE), _mainPane, EJScreenType.UPDATE);
            scrollComposite.setContent(_mainPane);
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            // remove the offset
            scrollComposite.setMinSize(width, height - 10);
            _block.addItemValueChangedListener(EJRWTUpdateScreenRenderer.this);
            EJRWTItemTextChangeNotifier.ChangeListener changeListener = new ChangeListener() {

                @Override
                public void changed() {
                    validate();
                }
            };
            Collection<EJManagedItemRendererWrapper> registeredRenderers = _itemRegister.getRegisteredRenderers();
            for (EJManagedItemRendererWrapper ejManagedItemRendererWrapper : registeredRenderers) {
                if (ejManagedItemRendererWrapper.getUnmanagedRenderer() instanceof EJRWTItemTextChangeNotifier) {
                    ((EJRWTItemTextChangeNotifier) ejManagedItemRendererWrapper.getUnmanagedRenderer()).addListener(changeListener);
                }
            }
        }

        @Override
        public int open() {
            validate();
            setFoucsItemRenderer();
            return super.open();
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            // Add the buttons in reverse order, as they will be added from
            // left to right
            addExtraButton(parent, button5Label, ID_BUTTON_5);
            addExtraButton(parent, button4Label, ID_BUTTON_4);
            addExtraButton(parent, button3Label, ID_BUTTON_3);
            addExtraButton(parent, button2Label, ID_BUTTON_2);
            addExtraButton(parent, button1Label, ID_BUTTON_1);
            EJ_RWT.setTestId(createButton(parent, UPDATE_OK_ACTION_COMMAND, updateButtonLabel == null ? "Update" : updateButtonLabel, true), _block.getProperties().getName() + ".ok");
            EJ_RWT.setTestId(createButton(parent, UPDATE_CANCEL_ACTION_COMMAND, cancelButtonLabel == null ? "Cancel" : cancelButtonLabel, false), _block.getProperties().getName() + ".cancel");
        }

        @Override
        public void validate() {
            Button button = getButton(UPDATE_OK_ACTION_COMMAND);
            if (button == null) {
                return;
            }
            Collection<EJScreenItemController> allScreenItems = _block.getAllScreenItems(EJScreenType.UPDATE);
            for (EJScreenItemController ejScreenItemController : allScreenItems) {
                if (!ejScreenItemController.getManagedItemRenderer().isValid()) {
                    button.setEnabled(false);
                    return;
                }
            }
            button.setEnabled(true);
        }

        private void addExtraButton(Composite parent, String label, int id) {
            if (label == null) {
                return;
            }
            Button button = createButton(parent, id, label, false);
            EJ_RWT.setTestId(button, _block.getProperties().getName() + ".btn-" + id);
        }

        @Override
        public boolean close() {
            _block.removeItemValueChangedListener(EJRWTUpdateScreenRenderer.this);
            _block.setRendererFocus(true);
            return super.close();
        }

        @Override
        public void canceled() {
            _block.updateCancelled();
            close();
        }

        @Override
        protected void buttonPressed(int buttonId) {
            Display.getDefault().asyncExec(() -> {
                try {
                    switch(buttonId) {
                        case UPDATE_OK_ACTION_COMMAND:
                            {
                                try {
                                    _block.getBlock().updateRecord(_itemRegister.getRegisteredRecord());
                                    if (_block.getUpdateScreenDisplayProperties().getBooleanProperty(EJRWTScreenRendererDefinitionProperties.SAVE_FORM_AFTER_EXECUTE, false)) {
                                        _block.getBlock().getForm().saveChanges();
                                    }
                                } catch (EJApplicationException e) {
                                    setButtonEnable(buttonId, false);
                                    throw e;
                                }
                                close();
                                break;
                            }
                        case UPDATE_CANCEL_ACTION_COMMAND:
                            {
                                _block.updateCancelled();
                                close();
                                break;
                            }
                        case ID_BUTTON_1:
                            {
                                _block.executeActionCommand(button1Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_2:
                            {
                                _block.executeActionCommand(button2Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_3:
                            {
                                _block.executeActionCommand(button3Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_4:
                            {
                                _block.executeActionCommand(button4Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_5:
                            {
                                _block.executeActionCommand(button5Command, EJScreenType.UPDATE);
                                break;
                            }
                        default:
                            _block.updateCancelled();
                            break;
                    }
                } catch (EJApplicationException e) {
                    _logger.trace(e.getMessage());
                    _frameworkManager.handleException(e);
                    return;
                }
            });
        }
    };
    _updateDialog.create();
    _updateDialog.getShell().setData("UPDATE - " + _block.getProperties().getName());
    _updateDialog.getShell().setText(title != null ? title : "");
    // add dialog border offsets
    _updateDialog.getShell().setSize(width + 80, height + 100);
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJApplicationException(org.entirej.framework.core.EJApplicationException) FillLayout(org.eclipse.swt.layout.FillLayout) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) Button(org.eclipse.swt.widgets.Button) EJRWTItemTextChangeNotifier(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Collection(java.util.Collection) ChangeListener(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 4 with EJRWTScrolledComposite

use of org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite in project rap by entirej.

the class EJRWTTabPaneFormContainer method addForm.

@Override
public EJInternalForm addForm(EJInternalForm form) {
    CTabItem tabItem = new CTabItem(_folder, SWT.NONE);
    _tabPages.put(form, tabItem);
    tabItem.setData(form);
    EJ_RWT.setTestId(tabItem, form.getProperties().getName());
    EJRWTFormRenderer renderer = (EJRWTFormRenderer) form.getRenderer();
    final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(_folder, SWT.V_SCROLL | SWT.H_SCROLL);
    renderer.createControl(scrollComposite);
    scrollComposite.setContent(renderer.getGuiComponent());
    scrollComposite.setExpandHorizontal(true);
    scrollComposite.setExpandVertical(true);
    scrollComposite.setMinSize(form.getProperties().getFormWidth(), form.getProperties().getFormHeight());
    final EJCoreFormProperties coreFormProperties = form.getProperties();
    tabItem.setText(coreFormProperties.getTitle() == null ? coreFormProperties.getName() : coreFormProperties.getTitle());
    tabItem.setControl(scrollComposite);
    _folder.setSelection(tabItem);
    renderer.gainInitialFocus();
    return form;
}
Also used : EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJCoreFormProperties(org.entirej.framework.core.properties.EJCoreFormProperties) EJRWTFormRenderer(org.entirej.applicationframework.rwt.renderers.form.EJRWTFormRenderer) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 5 with EJRWTScrolledComposite

use of org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite in project rap by entirej.

the class EJRWTApplicationContainer method buildApplication.

void buildApplication(EJRWTApplicationManager applicationManager, Composite mainWindow, String serviceForm) {
    _applicationManager = applicationManager;
    _mainPane = new Composite(mainWindow, SWT.NO_FOCUS);
    _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
    mainWindow.setLayout(new FillLayout());
    if (serviceForm == null)
        buildApplicationContainer();
    else
        buildServiceApplicationContainer(serviceForm);
    if (_formContainer == null) {
        _formContainer = new EJRWTFormContainer() {

            EJRWTAbstractDialog _popupDialog;

            EJRWTFormPopUp _formPopup;

            @Override
            public EJInternalForm switchToForm(String key) {
                // ignore
                return null;
            }

            @Override
            public EJInternalForm switchToForm(EJInternalForm form) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public void removeFormSelectedListener(EJRWTFormSelectedListener selectionListener) {
            // ignore
            }

            @Override
            public void popupFormClosed() {
                if (_formPopup != null) {
                    _formPopup.close();
                    _formPopup = null;
                }
            }

            @Override
            public void openPopupForm(EJPopupFormController popupController) {
                _formPopup = new EJRWTFormPopUp(_applicationManager.getShell(), popupController);
                _formPopup.showForm();
            }

            @Override
            public Collection<EJInternalForm> getAllForms() {
                // ignore
                return Collections.emptyList();
            }

            @Override
            public EJInternalForm getActiveForm() {
                // ignore
                return null;
            }

            @Override
            public boolean containsForm(String formName) {
                // ignore
                return false;
            }

            @Override
            public void closeForm(EJInternalForm form) {
                if (_formPopup != null && _formPopup.getPopupController().getPopupForm().equals(form)) {
                    _formPopup.close();
                    _formPopup = null;
                    return;
                }
                if (_popupDialog != null) {
                    _popupDialog.close();
                    _popupDialog = null;
                }
            }

            @Override
            public void addFormSelectedListener(EJRWTFormSelectedListener selectionListener) {
            // ignore
            }

            @Override
            public EJInternalForm addForm(final EJInternalForm form) {
                final int height = form.getProperties().getFormHeight();
                final int width = form.getProperties().getFormWidth();
                final EJRWTFormRenderer formRenderer = (EJRWTFormRenderer) form.getRenderer();
                _popupDialog = new EJRWTAbstractDialog(_applicationManager.getShell()) {

                    private static final long serialVersionUID = -4685316941898120169L;

                    @Override
                    public void createBody(Composite parent) {
                        parent.setLayout(new FillLayout());
                        final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
                        formRenderer.createControl(scrollComposite);
                        scrollComposite.setContent(formRenderer.getGuiComponent());
                        scrollComposite.setExpandHorizontal(true);
                        scrollComposite.setExpandVertical(true);
                        scrollComposite.setMinSize(form.getProperties().getFormWidth(), form.getProperties().getFormHeight());
                        formRenderer.gainInitialFocus();
                    }

                    @Override
                    public int open() {
                        return super.open();
                    }

                    private void addExtraButton(Composite parent, String label, int id) {
                        if (label == null || label.length() == 0) {
                            return;
                        }
                        createButton(parent, id, label, false);
                    }

                    @Override
                    public boolean close() {
                        return super.close();
                    }
                };
                _popupDialog.create();
                final EJCoreFormProperties coreFormProperties = form.getProperties();
                _popupDialog.getShell().setData("POPUP - " + coreFormProperties.getName());
                _popupDialog.getShell().setText(coreFormProperties.getTitle() == null ? coreFormProperties.getName() : coreFormProperties.getTitle());
                // add dialog border offsets
                _popupDialog.getShell().setSize(width + 80, height + 100);
                _popupDialog.centreLocation();
                _popupDialog.open();
                _popupDialog.activateDialog();
                return form;
            }

            @Override
            public void updateFormTitle(EJInternalForm form) {
            // TODO Auto-generated method stub
            }
        };
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJRWTFormPopUp(org.entirej.applicationframework.rwt.application.form.containers.EJRWTFormPopUp) FillLayout(org.eclipse.swt.layout.FillLayout) EJInternalForm(org.entirej.framework.core.internal.EJInternalForm) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJCoreFormProperties(org.entirej.framework.core.properties.EJCoreFormProperties) EJRWTFormContainer(org.entirej.applicationframework.rwt.application.interfaces.EJRWTFormContainer) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) Collection(java.util.Collection) EJRWTFormRenderer(org.entirej.applicationframework.rwt.renderers.form.EJRWTFormRenderer) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJRWTFormSelectedListener(org.entirej.applicationframework.rwt.application.interfaces.EJRWTFormSelectedListener) EJPopupFormController(org.entirej.framework.core.data.controllers.EJPopupFormController)

Aggregations

ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)10 EJRWTScrolledComposite (org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite)10 Composite (org.eclipse.swt.widgets.Composite)8 FillLayout (org.eclipse.swt.layout.FillLayout)6 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)6 Collection (java.util.Collection)5 EJApplicationException (org.entirej.framework.core.EJApplicationException)5 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)5 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)5 EJRWTAbstractDialog (org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog)4 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)4 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)4 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)4 Button (org.eclipse.swt.widgets.Button)3 EJRWTItemTextChangeNotifier (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier)3 ChangeListener (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener)3 FocusEvent (org.eclipse.swt.events.FocusEvent)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 GridData (org.eclipse.swt.layout.GridData)2