Search in sources :

Example 1 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException 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 EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTMessenger method handleException.

@Override
public void handleException(final Exception exception, boolean showUserMessage) {
    if (exception instanceof EJApplicationException && showUserMessage) {
        EJApplicationException ejApplicationException = (EJApplicationException) exception;
        if (ejApplicationException.stopProcessing() && ejApplicationException.getFrameworkMessage() == null) {
            return;
        }
        // If the EJApplicationException is created with no parameters, the
        // user is using it to halt application processing, therefore there
        // is not need to handler the exception
        logger.error(exception.getMessage(), exception);
        final EJMessage frameworkMessage = ejApplicationException.getFrameworkMessage();
        Display current = Display.getCurrent();
        if (current != null) {
            current.asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (frameworkMessage != null && frameworkMessage.getMessage() != null) {
                        handleMessage(frameworkMessage);
                    } else {
                        handleMessage(new EJMessage(exception.getMessage()));
                    }
                }
            });
        }
    } else if (showUserMessage) {
        logger.error(exception.getMessage(), exception);
        Display current = Display.getCurrent();
        if (current != null) {
            current.asyncExec(new Runnable() {

                @Override
                public void run() {
                    Status status = new Status(IStatus.ERROR, "rwt.ej", exception.getMessage());
                    ErrorDialog dialog = new ErrorDialog(manager.getShell(), "Error", "Internal Error", status, IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR);
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                }
            });
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) EJApplicationException(org.entirej.framework.core.EJApplicationException) EJMessage(org.entirej.framework.core.EJMessage) Display(org.eclipse.swt.widgets.Display)

Example 3 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTNumberItemRenderer method commitValue.

protected void commitValue() {
    if (_valueChanged) {
        _valueChanged = false;
        Number value = (Number) getValue();
        if (value != null && value.doubleValue() > maxValue.doubleValue()) {
            value = (Number) _oldvalue;
            _textField.setText(_oldvalue != null ? _decimalFormatter.format(_oldvalue) : "");
            _item.getForm().getFrameworkManager().handleException(new EJApplicationException(String.format("The maximum allowable value: %s", _decimalFormatter.format(maxValue.doubleValue()))), true);
        }
        if (value != null && value.doubleValue() < minValue.doubleValue()) {
            value = (Number) _oldvalue;
            _textField.setText(_oldvalue != null ? _decimalFormatter.format(_oldvalue) : "");
            _item.getForm().getFrameworkManager().handleException(new EJApplicationException(String.format("The minimum allowable value: %s", _decimalFormatter.format(minValue.doubleValue()))), true);
        }
        _item.itemValueChaged(value);
        _oldvalue = null;
        setMandatoryBorder(_mandatory);
    }
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException)

Example 4 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTFormRenderer method createGroupCanvas.

private void createGroupCanvas(Composite parent, final EJCanvasProperties canvasProperties, EJCanvasController canvasController) {
    final EJRWTTrayPane trayPane = new EJRWTTrayPane(parent);
    trayPane.setLayoutData(createCanvasGridData(canvasProperties));
    EJ_RWT.setTestId(trayPane, _form.getProperties().getName() + "." + canvasProperties.getName());
    parent = trayPane;
    String frameTitle = canvasProperties.getGroupFrameTitle();
    if (canvasProperties.getDisplayGroupFrame() && frameTitle != null && frameTitle.length() > 0) {
        Group group = new Group(parent, SWT.NONE);
        group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_FORM);
        group.setLayout(new FillLayout());
        group.setLayoutData(createCanvasGridData(canvasProperties));
        group.setText(frameTitle);
        trayPane.initBase(group);
        parent = group;
    }
    final EJRWTEntireJGridPane groupPane = new EJRWTEntireJGridPane(parent, canvasProperties.getNumCols(), canvasProperties.getDisplayGroupFrame() && (frameTitle == null || frameTitle.length() == 0) ? SWT.BORDER : SWT.NONE);
    groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_FORM);
    if (canvasProperties.getDisplayGroupFrame()) {
    // .cleanLayoutTop();
    } else {
    // groupPane.cleanLayout();
    }
    groupPane.setPaneName(canvasProperties.getName());
    if (!(canvasProperties.getDisplayGroupFrame() && frameTitle != null && frameTitle.length() > 0)) {
        groupPane.setLayoutData(createCanvasGridData(canvasProperties));
        trayPane.initBase(groupPane);
    }
    CanvasHandler canvasHandler = new CanvasHandler() {

        private Collection<EJMessage> msgs;

        @Override
        public void clearCanvasMessages() {
            this.msgs = null;
            if (trayPane != null && !trayPane.isDisposed()) {
                trayPane.closeTray();
            }
        }

        @Override
        public void setCanvasMessages(Collection<EJMessage> messages) {
            this.msgs = messages;
            if (trayPane != null && !trayPane.isDisposed()) {
                if (trayPane.getTray() != null) {
                    trayPane.closeTray();
                }
                {
                    MessageTray messageTray = new MessageTray(canvasProperties.getCloseableMessagePane()) {

                        @Override
                        void close() {
                            if (trayPane != null && !trayPane.isDisposed()) {
                                trayPane.closeTray();
                            }
                        }
                    };
                    messageTray.setMessages(msgs);
                    TrayLocation location = TrayLocation.RIGHT;
                    switch(canvasProperties.getMessagePosition()) {
                        case BOTTOM:
                            location = TrayLocation.BOTTOM;
                            break;
                        case LEFT:
                            location = TrayLocation.LEFT;
                            break;
                        case RIGHT:
                            location = TrayLocation.RIGHT;
                            break;
                        case TOP:
                            location = TrayLocation.TOP;
                            break;
                        default:
                            break;
                    }
                    trayPane.openTray(location, messageTray, canvasProperties.getMessagePaneSize());
                }
            }
        }

        @Override
        public void add(EJInternalBlock block) {
            EJRWTAppBlockRenderer blockRenderer = (EJRWTAppBlockRenderer) block.getRendererController().getRenderer();
            if (blockRenderer == null) {
                throw new EJApplicationException(new EJMessage("Block " + block.getProperties().getName() + " has a canvas defined but no renderer. A block cannot be rendererd if no canvas has been defined."));
            }
            blockRenderer.buildGuiComponent(groupPane);
            trayPane.setLayoutData(groupPane.getLayoutData());
        }

        @Override
        public EJCanvasType getType() {
            return EJCanvasType.BLOCK;
        }
    };
    _canvases.put(groupPane.getPaneName(), canvasHandler);
    _canvasesIds.add(groupPane.getPaneName());
    EJInternalBlock block = _blocks.get(groupPane.getPaneName());
    if (block != null) {
        canvasHandler.add(block);
    }
    if (!canvasProperties.getCloseableMessagePane()) {
        canvasHandler.setCanvasMessages(Collections.<EJMessage>emptyList());
    }
    if (canvasProperties.getType() == EJCanvasType.GROUP) {
        for (EJCanvasProperties containedCanvas : canvasProperties.getGroupCanvasContainer().getAllCanvasProperties()) {
            switch(containedCanvas.getType()) {
                case BLOCK:
                case GROUP:
                    createGroupCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case FORM:
                    createFormCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case SEPARATOR:
                    createSeparatorCanvas(groupPane, containedCanvas);
                    break;
                case SPLIT:
                    createSplitCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case STACKED:
                    createStackedCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case TAB:
                    createTabCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case DRAWER:
                    createDrawerCanvas(groupPane, containedCanvas, canvasController);
                    break;
                case POPUP:
                    throw new AssertionError();
            }
        }
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) EJInternalBlock(org.entirej.framework.core.internal.EJInternalBlock) EJCanvasProperties(org.entirej.framework.core.properties.interfaces.EJCanvasProperties) EJApplicationException(org.entirej.framework.core.EJApplicationException) FillLayout(org.eclipse.swt.layout.FillLayout) EJRWTAppBlockRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppBlockRenderer) EJMessage(org.entirej.framework.core.EJMessage) TrayLocation(org.entirej.applicationframework.rwt.application.form.containers.EJRWTTrayDialog.TrayLocation) Collection(java.util.Collection) EJRWTTrayPane(org.entirej.applicationframework.rwt.application.form.containers.EJRWTTrayPane) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 5 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTFormRenderer method closeEmbeddedForm.

@Override
public void closeEmbeddedForm(EJEmbeddedFormController formController) {
    if (formController == null) {
        throw new EJApplicationException("No embedded form controller has been passed to closeEmbeddedForm");
    }
    if (formController.getCanvasName() != null) {
        Composite composite = _formPanes.get(formController.getCanvasName());
        if (composite != null) {
            Control[] children = composite.getChildren();
            for (Control control : children) {
                if (!control.isDisposed()) {
                    control.dispose();
                }
            }
            composite.layout(true);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJApplicationException(org.entirej.framework.core.EJApplicationException)

Aggregations

EJApplicationException (org.entirej.framework.core.EJApplicationException)18 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)6 Composite (org.eclipse.swt.widgets.Composite)6 EJRWTScrolledComposite (org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite)6 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)5 EJMessage (org.entirej.framework.core.EJMessage)5 Collection (java.util.Collection)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)4 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)4 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)4 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)4 Button (org.eclipse.swt.widgets.Button)3 EJRWTAbstractDialog (org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog)3 EJRWTItemTextChangeNotifier (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier)3 ChangeListener (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener)3 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Control (org.eclipse.swt.widgets.Control)2