Search in sources :

Example 31 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties in project rap by entirej.

the class EJRWTBlockPreviewerCreator method addItemGroup.

private void addItemGroup(Composite parent, EJDevBlockRendererDefinition blockRendererDef, EJDevBlockDisplayProperties blockDisplayProperties, EJDevItemGroupDisplayProperties itemGroupProperties, FormToolkit toolkit, List<EJDevItemRendererDefinitionControl> itemControls) {
    if (itemGroupProperties.isSeparator()) {
        int style = SWT.SEPARATOR;
        if (itemGroupProperties.getSeparatorOrientation() == EJSeparatorOrientation.HORIZONTAL) {
            style = style | SWT.HORIZONTAL;
        } else {
            style = style | SWT.VERTICAL;
        }
        Label layoutBody = new Label(parent, style);
        layoutBody.setLayoutData(createItemGroupGridData(itemGroupProperties));
        return;
    }
    Composite group = null;
    if (itemGroupProperties.dispayGroupFrame()) {
        if (itemGroupProperties.getFrameTitle() == null) {
            group = new Composite(parent, SWT.SHADOW_NONE);
            group.setLayoutData(createItemGroupGridData(itemGroupProperties));
        } else {
            EJFrameworkExtensionProperties rendererProperties = itemGroupProperties.getRendererProperties();
            if (rendererProperties != null && rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
                int style = ExpandableComposite.TITLE_BAR;
                String mode = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
                if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
                    style = style | ExpandableComposite.TWISTIE;
                } else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
                    style = style | ExpandableComposite.TREE_NODE;
                }
                if (rendererProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
                    style = style | ExpandableComposite.EXPANDED;
                }
                Section section = toolkit.createSection(parent, style);
                section.setFont(parent.getFont());
                section.setText(itemGroupProperties.getFrameTitle());
                group = toolkit.createComposite(section);
                section.setLayoutData(createItemGroupGridData(itemGroupProperties));
                section.setClient(group);
            } else {
                group = new Group(parent, SWT.SHADOW_ETCHED_IN);
                ((Group) group).setText(itemGroupProperties.getFrameTitle());
                group.setLayoutData(createItemGroupGridData(itemGroupProperties));
            }
        }
    } else {
        group = new Composite(parent, SWT.SHADOW_NONE);
        group.setLayoutData(createItemGroupGridData(itemGroupProperties));
    }
    // toolkit.adapt(group);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = itemGroupProperties.getNumCols();
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    group.setLayout(gridLayout);
    ItemCreator itemCreator = new ItemCreator();
    for (EJDevScreenItemDisplayProperties definition : itemGroupProperties.getAllItemDisplayProperties()) {
        if (definition.isSpacerItem()) {
            EJDevItemRendererDefinitionControl control = itemCreator.addSpacerItem(blockRendererDef, group, definition, toolkit);
            itemControls.add(control);
        } else {
            EJDevBlockItemDisplayProperties blockItemProperties = blockDisplayProperties.getBlockItemDisplayContainer().getItemProperties(definition.getReferencedItemName());
            if (blockItemProperties == null) {
                throw new IllegalStateException("Unable to retrrieve the blockItemProperties for: " + definition.getBlockName() + ":" + definition.getBlockItemDisplayProperties().getName());
            }
            EJDevItemRendererDefinitionControl control = itemCreator.createItem(itemGroupProperties.getNumCols(), blockItemProperties, (EJDevMainScreenItemDisplayProperties) definition, group, toolkit);
            itemControls.add(control);
        }
    }
    for (EJDevItemGroupDisplayProperties subGroup : itemGroupProperties.getChildItemGroupContainer().getAllItemGroupDisplayProperties()) {
        addItemGroup(group, blockRendererDef, blockDisplayProperties, subGroup, toolkit, itemControls);
    }
    toolkit.paintBordersFor(group);
}
Also used : Group(org.eclipse.swt.widgets.Group) EJDevItemGroupDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevItemGroupDisplayProperties) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJDevScreenItemDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevScreenItemDisplayProperties) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) EJDevBlockItemDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevBlockItemDisplayProperties) EJDevItemRendererDefinitionControl(org.entirej.framework.dev.renderer.definition.EJDevItemRendererDefinitionControl) Label(org.eclipse.swt.widgets.Label) Section(org.eclipse.ui.forms.widgets.Section) GridLayout(org.eclipse.swt.layout.GridLayout)

Example 32 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties in project rap by entirej.

the class EJRWTHtmlTableBlockRendererDefinition method addBlockControlToCanvas.

@Override
public EJDevBlockRendererDefinitionControl addBlockControlToCanvas(EJMainScreenProperties mainScreenProperties, EJDevBlockDisplayProperties blockDisplayProperties, Composite parent, FormToolkit toolkit) {
    Composite layoutBody;
    if (mainScreenProperties.getDisplayFrame()) {
        if (mainScreenProperties.getFrameTitle() != null && mainScreenProperties.getFrameTitle().length() > 0) {
            layoutBody = new Group(parent, SWT.NONE);
            ((Group) layoutBody).setText(mainScreenProperties.getFrameTitle());
        } else {
            layoutBody = new Composite(parent, SWT.BORDER);
        }
    } else {
        layoutBody = new Composite(parent, SWT.NONE);
    }
    layoutBody.setLayout(new FillLayout());
    if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) {
        Label label = new Label(layoutBody, SWT.NONE);
        label.setText("HTML Table Block");
        return new EJDevBlockRendererDefinitionControl(blockDisplayProperties, Collections.<EJDevItemRendererDefinitionControl>emptyList());
    }
    EJDevItemGroupDisplayProperties displayProperties = null;
    if (blockDisplayProperties.getMainScreenItemGroupDisplayContainer().getAllItemGroupDisplayProperties().size() > 0) {
        displayProperties = blockDisplayProperties.getMainScreenItemGroupDisplayContainer().getAllItemGroupDisplayProperties().iterator().next();
    }
    EJFrameworkExtensionProperties blockRendererProperties = mainScreenProperties.getBlockProperties().getBlockRendererProperties();
    boolean addHeader = true;
    StringBuilder header = new StringBuilder();
    if (blockRendererProperties != null) {
        addHeader = blockRendererProperties.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true);
    }
    int cellPadding = blockDisplayProperties.getBlockRendererProperties().getIntProperty(CELL_PADDING_PROPERTY, 0);
    String paddingStyle = null;
    if (cellPadding > 0) {
        String str = String.valueOf(cellPadding);
        paddingStyle = String.format("padding: %spx %spx %spx %spx; ", str, str, str, str);
    }
    if (displayProperties != null) {
        for (final EJDevScreenItemDisplayProperties screenItem : displayProperties.getAllItemDisplayProperties()) {
            if (screenItem.isSpacerItem()) {
                continue;
            }
            if (addHeader) {
                String styleClass = "default_all";
                EJFrameworkExtensionProperties rendererProperties = screenItem.getBlockItemDisplayProperties().getItemRendererProperties();
                header.append("<th ");
                String alignment = "left";
                String alignmentProperty = rendererProperties.getStringProperty("ALIGNMENT");
                if (alignmentProperty != null && alignmentProperty.trim().length() > 0) {
                    if (alignmentProperty.equals("JUSTIFY")) {
                        alignment = "justify";
                    } else if (alignmentProperty.equals("RIGHT")) {
                        alignment = "right";
                    } else if (alignmentProperty.equals("CENTER")) {
                        alignment = "center";
                    }
                }
                String valueVA = blockDisplayProperties.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));
                }
                header.append("> ");
                header.append(screenItem.getLabel());
                header.append("</th>");
            }
        }
        final Browser browser = new Browser(layoutBody, SWT.NONE);
        StringBuilder builder = new StringBuilder();
        {
            builder.append("<html>");
            builder.append(getStyleDef(blockDisplayProperties.getEntireJProperties()));
            builder.append("<div id=\"table\" style=\"float:left;width:100%;height:100%; overflow:auto\">");
            {
                EJDevBlockDisplayProperties blockProperties = blockDisplayProperties;
                int cellSpacing = blockProperties.getBlockRendererProperties().getIntProperty(CELL_SPACING_PROPERTY, 0);
                builder.append("<table border=0 cellspacing=").append(cellSpacing).append(" width=\"100%\" >");
                {
                    int charHeight = (Display.getDefault().getSystemFont()).getFontData()[0].getHeight();
                    ;
                    String trDef = String.format("<tr style=\"height: %spx\">", String.valueOf(charHeight));
                    if (addHeader) {
                        builder.append(header.toString());
                    }
                    int lastRowSpan = 0;
                    String oddVA = "default_all";
                    String valueVA = blockProperties.getBlockRendererProperties().getStringProperty(ROW_ODD_VA);
                    if (valueVA != null && valueVA.length() > 0) {
                        oddVA = valueVA;
                    }
                    String evenVA = "default_all";
                    valueVA = blockProperties.getBlockRendererProperties().getStringProperty(ROW_EVEN_VA);
                    if (valueVA != null && valueVA.length() > 0) {
                        evenVA = valueVA;
                    }
                    int rowid = 0;
                    for (int k = 0; k < 4; k++) {
                        rowid++;
                        if (lastRowSpan > 1) {
                            for (int i = 1; i < lastRowSpan; i++) {
                                builder.append(trDef).append("</tr>");
                            }
                            lastRowSpan = 0;
                        }
                        builder.append(trDef);
                        for (final EJDevScreenItemDisplayProperties item : displayProperties.getAllItemDisplayProperties()) {
                            String styleClass = (rowid % 2) != 0 ? oddVA : evenVA;
                            String alignment = null;
                            float width = -1;
                            EJFrameworkExtensionProperties rendererProperties = ((EJDevMainScreenItemDisplayProperties) item).getBlockRendererRequiredProperties();
                            builder.append(String.format("<td class=\"%s\" ", styleClass));
                            if (paddingStyle != null) {
                                builder.append(String.format(" style=\'%s\'", paddingStyle));
                            }
                            if (width == -1) {
                                width = rendererProperties.getIntProperty(DISPLAY_WIDTH_PROPERTY, 0);
                            }
                            if (width > 0) {
                                Font font = browser.getFont();
                                if (font != null) {
                                    float avgCharWidth = getAvgCharWidth(font);
                                    if (avgCharWidth > 0) {
                                        if (width != 1) {
                                            // add +1 padding
                                            width = ((int) (((width + 1) * avgCharWidth)));
                                        }
                                    }
                                }
                                builder.append(String.format(" width=%s ", width));
                            }
                            if (alignment == null) {
                                String alignmentProperty = item.getBlockItemDisplayProperties().getItemRendererProperties().getStringProperty("ALIGNMENT");
                                alignment = "left";
                                if (alignmentProperty != null && alignmentProperty.trim().length() > 0) {
                                    if (alignmentProperty.equals("JUSTIFY")) {
                                        alignment = "justify";
                                    } else if (alignmentProperty.equals("RIGHT")) {
                                        alignment = "right";
                                    } else if (alignmentProperty.equals("CENTER")) {
                                        alignment = "center";
                                    }
                                }
                            }
                            if (alignment != null) {
                                builder.append(String.format(" align=\'%s\'", alignment));
                            }
                            builder.append(">");
                            // builder.append(String.format("<p class=\"default %s\">",
                            // styleClass));
                            String text = item.getReferencedItemName();
                            builder.append(text);
                            builder.append("</td>");
                        }
                        builder.append("</tr>");
                    }
                }
                builder.append("</table>");
            }
            builder.append("</<div>");
            builder.append("</html>");
        }
        browser.setText(builder.toString());
    }
    return new EJDevBlockRendererDefinitionControl(blockDisplayProperties, Collections.<EJDevItemRendererDefinitionControl>emptyList());
}
Also used : EJDevPropertyDefinitionGroup(org.entirej.framework.dev.properties.EJDevPropertyDefinitionGroup) EJPropertyDefinitionGroup(org.entirej.framework.core.properties.definitions.interfaces.EJPropertyDefinitionGroup) Group(org.eclipse.swt.widgets.Group) EJDevItemGroupDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevItemGroupDisplayProperties) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJDevScreenItemDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevScreenItemDisplayProperties) Composite(org.eclipse.swt.widgets.Composite) EJDevBlockDisplayProperties(org.entirej.framework.dev.properties.interfaces.EJDevBlockDisplayProperties) Label(org.eclipse.swt.widgets.Label) FillLayout(org.eclipse.swt.layout.FillLayout) Font(org.eclipse.swt.graphics.Font) EJDevBlockRendererDefinitionControl(org.entirej.framework.dev.renderer.definition.EJDevBlockRendererDefinitionControl) Browser(org.eclipse.swt.browser.Browser)

Example 33 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties in project rap by entirej.

the class EJRWTLineChartRecordBlockDefinition method addBlockControlToCanvas.

@Override
public EJDevBlockRendererDefinitionControl addBlockControlToCanvas(EJMainScreenProperties mainScreenProperties, EJDevBlockDisplayProperties blockDisplayProperties, Composite parent, FormToolkit toolkit) {
    EJFrameworkExtensionProperties rendererProperties = blockDisplayProperties.getBlockRendererProperties();
    if (blockDisplayProperties != null) {
        rendererProperties = rendererProperties.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
    }
    Composite layoutBody;
    if (rendererProperties != null && rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
        int style = ExpandableComposite.TITLE_BAR;
        String mode = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
        if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
            style = style | ExpandableComposite.TWISTIE;
        } else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
            style = style | ExpandableComposite.TREE_NODE;
        }
        if (rendererProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
            style = style | ExpandableComposite.EXPANDED;
        }
        String title = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
        Section section = toolkit.createSection(parent, style);
        if (title != null)
            section.setText(title);
        section.setFont(parent.getFont());
        section.setForeground(parent.getForeground());
        if (mainScreenProperties.getDisplayFrame()) {
            layoutBody = new Group(section, SWT.NONE);
            layoutBody.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
            if (mainScreenProperties.getFrameTitle() != null)
                ((Group) layoutBody).setText(mainScreenProperties.getFrameTitle());
        } else {
            layoutBody = toolkit.createComposite(section);
        }
        section.setClient(layoutBody);
    } else {
        if (mainScreenProperties.getDisplayFrame()) {
            layoutBody = new Group(parent, SWT.NONE);
            if (mainScreenProperties.getFrameTitle() != null)
                ((Group) layoutBody).setText(mainScreenProperties.getFrameTitle());
        } else {
            layoutBody = new Composite(parent, SWT.NONE);
        }
    }
    layoutBody.setLayout(new GridLayout(mainScreenProperties.getNumCols(), false));
    EJDevBlockRendererDefinitionControl control = addTreeTable(blockDisplayProperties, layoutBody, toolkit);
    return control;
}
Also used : EJDevPropertyDefinitionGroup(org.entirej.framework.dev.properties.EJDevPropertyDefinitionGroup) EJPropertyDefinitionGroup(org.entirej.framework.core.properties.definitions.interfaces.EJPropertyDefinitionGroup) Group(org.eclipse.swt.widgets.Group) EJDevBlockRendererDefinitionControl(org.entirej.framework.dev.renderer.definition.EJDevBlockRendererDefinitionControl) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Section(org.eclipse.ui.forms.widgets.Section)

Example 34 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties in project rap by entirej.

the class EJRWTHtmlTableBlockRenderer method createHTML.

private void createHTML() {
    if (_browser == null || _browser.isDisposed()) {
        return;
    }
    StringBuilder builder = new StringBuilder();
    {
        builder.append("<div id=\"table\" style=\"float:left;width:100%;height:100%; overflow:auto\">");
        {
            EJCoreBlockProperties blockProperties = _block.getProperties();
            int cellSpacing = blockProperties.getBlockRendererProperties().getIntProperty(CELL_SPACING_PROPERTY, 0);
            int cellPadding = blockProperties.getBlockRendererProperties().getIntProperty(CELL_PADDING_PROPERTY, 0);
            boolean rowSelection = blockProperties.getBlockRendererProperties().getBooleanProperty(ROW_SELECTION, false);
            String rowSelectionVA = blockProperties.getBlockRendererProperties().getStringProperty(ROW_SELECTION_VA);
            String selectionTD = "<td width=1 class=\"rowindi\" style=\" border-left: 2px solid #4D90F0;\n" + "    background-color: #fafafa; visibility:hidden \"></td>";
            if (rowSelectionVA != null && !rowSelectionVA.isEmpty()) {
                EJCoreVisualAttributeProperties selectVa = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(rowSelectionVA);
                Color backgroundColor = selectVa.getBackgroundColor();
                if (selectVa != null) {
                    String hexString = toHex(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue());
                    selectionTD = "<td width=1 class=\"rowindi\" style=\" border-left: 2px solid " + hexString + ";\n" + "    background-color: #fafafa; visibility:hidden \"></td>";
                }
            }
            String tdStyle = null;
            if (cellPadding > 0) {
                String str = String.valueOf(cellPadding);
                tdStyle = String.format("padding: %spx %spx %spx %spx; ", str, str, str, str);
            }
            builder.append("<table border=0 cellspacing=").append(cellSpacing).append(" width=\"100%\" >");
            {
                builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
                builder.append(createVACSSUrl());
                builder.append("\">");
                int charHeight = EJRWTImageRetriever.getGraphicsProvider().getCharHeight(Display.getDefault().getSystemFont());
                if (_headerTag != null) {
                    String sortHeader = _headerTag;
                    if (activeSortColumn != null) {
                        StringBuilder header = new StringBuilder();
                        if (activeSortColumn.direction != SortInfo.DIRECTION.NONE) {
                            header.append("&nbsp <img name=\"open\" ");
                            header.append("src=\"");
                            header.append(createImageUrl(activeSortColumn.direction == SortInfo.DIRECTION.ASC ? "resource/widget/rap/column/sort-indicator-up.png" : "resource/widget/rap/column/sort-indicator-down.png"));
                            header.append("\"");
                            header.append(" >");
                        }
                        sortHeader = _headerTag.replace(String.format("<esh %s/>", activeSortColumn.id), header.toString());
                    }
                    builder.append(sortHeader);
                }
                Collection<EJDataRecord> records = _tableBaseRecords;
                builder.append("<tbody>");
                if (records.size() > 0) {
                    records = sortedRecords(records);
                    int lastRowSpan = 0;
                    String oddVA = "default_all";
                    String valueVA = blockProperties.getBlockRendererProperties().getStringProperty(ROW_ODD_VA);
                    if (valueVA != null && valueVA.length() > 0) {
                        oddVA = valueVA;
                    }
                    String evenVA = "default_all";
                    valueVA = blockProperties.getBlockRendererProperties().getStringProperty(ROW_EVEN_VA);
                    if (valueVA != null && valueVA.length() > 0) {
                        evenVA = valueVA;
                    }
                    int rowid = 0;
                    for (EJDataRecord record : records) {
                        String trDef = String.format("<tr style=\"height: %spx\" recid=\"%s\" >", String.valueOf(charHeight), String.valueOf(getDisplayedRecordNumber(record)));
                        rowid++;
                        if (lastRowSpan > 1) {
                            for (int i = 1; i < lastRowSpan; i++) {
                                builder.append(trDef).append("</tr>");
                            }
                            lastRowSpan = 0;
                        }
                        builder.append(trDef);
                        if (rowSelection) {
                            builder.append(selectionTD);
                        }
                        for (EJCoreMainScreenItemProperties item : _items) {
                            String styleClass = (rowid % 2) != 0 ? oddVA : evenVA;
                            String actionDef = null;
                            String alignment = null;
                            float width = -1;
                            ColumnLabelProvider columnLabelProvider = _itemLabelProviders.get(item.getReferencedItemName());
                            EJScreenItemController screenItem = _block.getScreenItem(EJScreenType.MAIN, item.getReferencedItemName());
                            EJCoreVisualAttributeProperties iva = screenItem.getManagedItemRenderer().getVisualAttributeProperties();
                            if (iva != null) {
                                styleClass = iva.getName();
                            }
                            EJFrameworkExtensionProperties rendererProperties = item.getReferencedItemProperties().getItemRendererProperties();
                            EJCoreVisualAttributeProperties diva = record.getItem(item.getReferencedItemName()).getVisualAttribute();
                            if (diva != null) {
                                styleClass = diva.getName();
                            }
                            builder.append(String.format("<td class=\"%s\" ", styleClass));
                            if (tdStyle != null) {
                                builder.append(String.format(" style=\'%s\'", tdStyle));
                            }
                            EJFrameworkExtensionProperties extentionProperties = item.getBlockRendererRequiredProperties();
                            if (width == -1) {
                                width = extentionProperties.getIntProperty(DISPLAY_WIDTH_PROPERTY, 0);
                            }
                            String action = extentionProperties.getStringProperty(CELL_ACTION_COMMAND);
                            if (action == null || action.length() == 0) {
                                action = item.getActionCommand();
                            }
                            if (action != null && action.length() > 0) {
                                actionDef = String.format("em='eaction' earg='%s , %s' ", action, String.valueOf(getDisplayedRecordNumber(record)));
                            }
                            if (width > 0) {
                                Font font = columnLabelProvider.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)));
                                        }
                                    }
                                }
                                builder.append(String.format(" width=%s ", width));
                            }
                            if (alignment == null) {
                                String alignmentProperty = rendererProperties.getStringProperty(PROPERTY_ALIGNMENT);
                                if (alignmentProperty == null) {
                                    alignmentProperty = rendererProperties.getStringProperty("ALLIGNMENT");
                                }
                                alignment = getComponentAlignment(alignmentProperty);
                            }
                            if (alignment != null) {
                                builder.append(String.format(" align=\'%s\'", alignment));
                            }
                            final String caseProperty = getComponentCase(rendererProperties.getStringProperty(PROPERTY_CASE));
                            builder.append(String.format(" font style=\'%s\'", caseProperty));
                            if (item.getHint() != null && !item.getHint().isEmpty()) {
                                builder.append(String.format(" title=\'%s\'", item.getHint()));
                            }
                            builder.append(">");
                            String text = columnLabelProvider instanceof HtmlBaseColumnLabelProvider ? ((HtmlBaseColumnLabelProvider) columnLabelProvider).getSrcText(record) : columnLabelProvider.getText(record);
                            boolean htmlformatting = extentionProperties.getBooleanProperty(ENABLE_MARKUP, false) || rendererProperties.getBooleanProperty("HTML_FORMAT", false);
                            if (!htmlformatting)
                                text = ignoreHtml(text);
                            if (actionDef != null && text != null && text.length() > 0) {
                                builder.append(String.format("<ejl><u %s class=\"%s, %s\"  ", "style=\"line-height: 100%;cursor: pointer; cursor: hand;\"", ("default_all".equals(styleClass) ? "default_link_fg" : "default_link"), styleClass));
                                builder.append(actionDef).append(">");
                            }
                            Image image = columnLabelProvider instanceof HtmlBaseColumnLabelProvider ? ((HtmlBaseColumnLabelProvider) columnLabelProvider).getSrcImage(record) : columnLabelProvider.getImage(record);
                            if (image != null) {
                                if (actionDef == null) {
                                    builder.append("<img src=\"");
                                    builder.append(ImageFactory.getImagePath(image));
                                    builder.append("\"");
                                    builder.append(String.format(" class=\"default %s\"  >", styleClass));
                                } else {
                                    builder.append("<ejl><img src=\"");
                                    builder.append(ImageFactory.getImagePath(image));
                                    builder.append("\"");
                                    builder.append(String.format("style=\"cursor: hand;\" class=\"%s \" %s  > </ejl>", styleClass, actionDef));
                                }
                            }
                            // builder.append(String.format("<p class=\"default %s\">",
                            // styleClass));
                            // if(textSelection && actionDef == null && !htmlformatting)
                            // {
                            // builder.append("<input value=\"");
                            // builder.append(text);
                            // builder.append("\" ");
                            // builder.append("style=\"border:none;\"");
                            // builder.append(" readonly />");
                            // }
                            // else
                            builder.append(text);
                            builder.append("</td>");
                        }
                        builder.append("</tr>");
                    }
                } else {
                    String trDef = String.format("<tr style=\"height: %spx\"  >", String.valueOf(charHeight));
                    builder.append(trDef);
                    for (EJCoreMainScreenItemProperties item : _items) {
                        String padding = tdStyle;
                        float width = -1;
                        ColumnLabelProvider columnLabelProvider = _itemLabelProviders.get(item.getReferencedItemName());
                        builder.append(String.format("<td class=\"%s\" ", "default_all"));
                        if (padding != null) {
                            builder.append(String.format(" style=\'%s\'", padding));
                        }
                        EJFrameworkExtensionProperties extentionProperties = item.getBlockRendererRequiredProperties();
                        if (width == -1) {
                            width = extentionProperties.getIntProperty(DISPLAY_WIDTH_PROPERTY, 0);
                        }
                        if (width > 0) {
                            Font font = columnLabelProvider.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)));
                                    }
                                }
                            }
                            builder.append(String.format(" width=%s ", width));
                        }
                        builder.append(">");
                        builder.append("</td>");
                    }
                    builder.append("</tr>");
                }
            }
            builder.append("</tbody></table>");
        }
        builder.append("</<div>");
    }
    String html = builder.toString();
    if (_browser.getText() == null || (!html.equals(_browser.getText()))) {
        _browser.setText(html);
        LOGGER.debug(html);
    }
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) Color(java.awt.Color) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) Collection(java.util.Collection) JsonObject(org.eclipse.rap.json.JsonObject) EJCoreBlockProperties(org.entirej.framework.core.properties.EJCoreBlockProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 35 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties in project rap by entirej.

the class EJRWTListRecordBlockRenderer method buildGuiComponent.

public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
    EJFrameworkExtensionProperties appProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
    if (appProp != null) {
        EJFrameworkExtensionProperties propertyGroup = appProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
        if (propertyGroup != null) {
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY);
        }
    }
    // blockCanvas.cleanLayoutVertical();
    EJBlockProperties blockProperties = _block.getProperties();
    EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
    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.minimumWidth = mainScreenProperties.getWidth();
    if (gridData.grabExcessVerticalSpace)
        gridData.minimumHeight = mainScreenProperties.getHeight();
    EJFrameworkExtensionProperties rendererProp = blockProperties.getBlockRendererProperties();
    blockCanvas.setLayoutData(gridData);
    EJFrameworkExtensionProperties sectionProperties = null;
    if (rendererProp != null) {
        sectionProperties = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
    }
    if (sectionProperties != null && sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
        int style = ExpandableComposite.TITLE_BAR;
        String mode = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
        if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
            style = style | ExpandableComposite.TWISTIE;
        } else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
            style = style | ExpandableComposite.TREE_NODE;
        }
        if (sectionProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
            style = style | ExpandableComposite.EXPANDED;
        }
        Section section = toolkit.createSection(blockCanvas, style);
        section.setLayoutData(gridData);
        String title = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
        if (title != null)
            section.setText(title);
        EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
        if (mainScreenProperties.getDisplayFrame()) {
            Group group = new Group(section, SWT.NONE);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                group.setText(frameTitle);
            }
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayoutHorizontal();
            section.setClient(_mainPane);
        }
        final EJFrameworkExtensionPropertyList propertyList = sectionProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
        if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
            ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
            final ToolBar toolbar = toolBarManager.createControl(section);
            final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
            toolbar.setCursor(handCursor);
            // Cursor needs to be explicitly disposed
            toolbar.addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    if ((handCursor != null) && (handCursor.isDisposed() == false)) {
                        handCursor.dispose();
                    }
                }
            });
            List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
            for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
                final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
                String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
                String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
                String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
                if (actionID != null) {
                    Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {

                        @Override
                        public void runWithEvent(Event event) {
                            _block.executeActionCommand(actionID, EJScreenType.MAIN);
                        }
                    };
                    if (actionName != null)
                        action.setText(actionName);
                    if (actionTooltip != null)
                        action.setDescription(actionTooltip);
                    if (actionImage != null && actionImage.length() > 0) {
                        action.setImageDescriptor((EJRWTImageRetriever.createDescriptor(actionImage)));
                    }
                    toolBarManager.add(action);
                }
            }
            toolBarManager.update(true);
            section.setTextClient(toolbar);
        }
    } else {
        if (mainScreenProperties.getDisplayFrame()) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                group.setText(frameTitle);
            }
            _mainPane = new EJRWTEntireJGridPane(group, 1);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayoutHorizontal();
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.VIRTUAL | SWT.V_SCROLL;
    if (!rendererProp.getBooleanProperty(EJRWTListRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false))
        style = style | SWT.BORDER;
    if (rendererProp.getBooleanProperty(EJRWTListRecordBlockDefinitionProperties.ROW_SELECTION_PROPERTY, true))
        style = style | SWT.FULL_SELECTION;
    else
        style = style | SWT.HIDE_SELECTION;
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Table table;
    final boolean hideSelection = (style & SWT.HIDE_SELECTION) != 0;
    // final EJRWTAbstractFilteredTable filterTree;
    if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame()) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                if (displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0)
                    group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                filterTree = new EJRWTAbstractFilteredTable(group, style) {

                    @Override
                    public void filter(String filter) {
                        if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
                            filteredContentProvider.setFilter(filter);
                            filterText = filter;
                            getViewer().setInput(filter);
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent) {

                            @Override
                            public void setSelection(ISelection selection) {
                                if (hideSelection)
                                    selection = new StructuredSelection();
                                super.setSelection(selection);
                            }

                            @Override
                            public void setSelection(ISelection selection, boolean reveal) {
                                if (hideSelection)
                                    selection = new StructuredSelection();
                                super.setSelection(selection, reveal);
                            }
                        };
                    }
                };
            } else {
                filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {

                    @Override
                    public void filter(String filter) {
                        if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
                            filteredContentProvider.setFilter(filter);
                            filterText = filter;
                            getViewer().setInput(filter);
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent) {

                            @Override
                            public void setSelection(ISelection selection) {
                                if (hideSelection)
                                    selection = new StructuredSelection();
                                super.setSelection(selection);
                            }

                            @Override
                            public void setSelection(ISelection selection, boolean reveal) {
                                if (hideSelection)
                                    selection = new StructuredSelection();
                                super.setSelection(selection, reveal);
                            }
                        };
                    }
                };
                filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {

                @Override
                public void filter(String filter) {
                    if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
                        filteredContentProvider.setFilter(filter);
                        filterText = filter;
                        getViewer().setInput(filter);
                        notifyStatus();
                    }
                }

                @Override
                protected TableViewer doCreateTableViewer(Composite parent, int style) {
                    return _tableViewer = new TableViewer(parent) {

                        @Override
                        public void setSelection(ISelection selection) {
                            if (hideSelection)
                                selection = new StructuredSelection();
                            super.setSelection(selection);
                        }

                        @Override
                        public void setSelection(ISelection selection, boolean reveal) {
                            if (hideSelection)
                                selection = new StructuredSelection();
                            super.setSelection(selection, reveal);
                        }
                    };
                }
            };
            filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        table = (_tableViewer = filterTree.getViewer()).getTable();
        defaultMessage = rendererProp.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
        if (defaultMessage != null)
            filterTree.getFilterControl().setMessage(defaultMessage);
    } else {
        filterTree = null;
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame()) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                if (displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0)
                    group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                table = new Table(group, style);
            } else {
                table = new Table(_mainPane, style);
                table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            table = new Table(_mainPane, style);
            table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        _tableViewer = new TableViewer(table) {

            @Override
            public void setSelection(ISelection selection) {
                if (hideSelection)
                    selection = new StructuredSelection();
                super.setSelection(selection);
            }

            @Override
            public void setSelection(ISelection selection, boolean reveal) {
                if (hideSelection)
                    selection = new StructuredSelection();
                super.setSelection(selection, reveal);
            }
        };
    }
    table.setLinesVisible(false);
    table.setHeaderVisible(false);
    Control[] children = table.getChildren();
    for (Control control : children) {
        hookKeyListener(control);
    }
    hookKeyListener(table);
    EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
    ColumnViewerToolTipSupport.enableFor(_tableViewer);
    final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
    final Map<ColumnLabelProvider, EJScreenItemProperties> nodeTextProvidersMap = new HashMap<ColumnLabelProvider, EJScreenItemProperties>();
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            ColumnLabelProvider screenItem = createScreenItem(factory, mainScreenItemProperties);
            if (screenItem != null) {
                nodeTextProviders.add(screenItem);
                nodeTextProvidersMap.put(screenItem, screenItemProperties);
            }
        }
    }
    if (!nodeTextProviders.isEmpty()) {
        table.setData(EJ_RWT.MARKUP_ENABLED, Boolean.TRUE);
        int height = rendererProp.getIntProperty(EJRWTListRecordBlockDefinitionProperties.ROW_HEIGHT, -1);
        if (height == -1 && nodeTextProviders.size() > 1) {
            table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, Integer.valueOf(nodeTextProviders.size() * 20));
        } else if (height > 0) {
            table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, Integer.valueOf(height));
        }
        // add double click action
        final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTListRecordBlockDefinitionProperties.CLICK_ACTION_COMMAND);
        final boolean hasAction = doubleClickActionCommand != null && doubleClickActionCommand.length() != 0;
        if (hasAction) {
            _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

                public void doubleClick(DoubleClickEvent arg0) {
                    _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
                }
            });
        }
        final TableViewerColumn dataColumn = factory.createColumn("HTML", 500, new ColumnLabelProvider() {

            public String toHex(int r, int g, int b) {
                return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
            }

            private String toBrowserHexValue(int number) {
                StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
                while (builder.length() < 2) {
                    builder.append("0");
                }
                return builder.toString().toUpperCase();
            }

            @Override
            public String getText(Object element) {
                StringBuilder builder = new StringBuilder();
                boolean addBr = false;
                for (ColumnLabelProvider labelProvider : nodeTextProviders) {
                    if (addBr) {
                        builder.append("<br/>");
                    }
                    boolean added = false;
                    EJScreenItemProperties item = nodeTextProvidersMap.get(labelProvider);
                    if (item != null && item.getLabel() != null && item.getLabel().trim().length() > 0) {
                        builder.append(item.getLabel());
                        builder.append(" : ");
                        added = true;
                    }
                    Image image = labelProvider.getImage(element);
                    if (image != null) {
                        String imagePath = ImageFactory.getImagePath(image);
                        if (imagePath != null) {
                            builder.append("<img src=\"");
                            builder.append(imagePath);
                            Rectangle bounds = image.getBounds();
                            builder.append("\" style=\"vertical-align:middle;\" ");
                            builder.append(" width=\"");
                            builder.append(bounds.width);
                            builder.append("\" ");
                            builder.append(" height=\"");
                            builder.append(bounds.height);
                            builder.append("\"/>");
                            added = true;
                        }
                    }
                    String text = labelProvider.getText(element);
                    if (text != null && text.length() != 0) {
                        Font vaFont = labelProvider.getFont(element);
                        builder.append("<span style=\"");
                        if (vaFont != null && vaFont.getFontData().length > 0) {
                            FontData fontData = vaFont.getFontData()[0];
                            if ((fontData.getStyle() & SWT.BOLD) != 0) {
                                builder.append("font-weight:bold;");
                            }
                            if ((fontData.getStyle() & SWT.ITALIC) != 0) {
                                builder.append("font-style:italic;");
                            }
                            builder.append("font-size:");
                            builder.append(fontData.getHeight());
                            builder.append("px;");
                            builder.append("font-family:");
                            builder.append(fontData.getName().replace('"', ' '));
                            builder.append(";");
                        }
                        Color background = labelProvider.getBackground(element);
                        if (background != null) {
                            builder.append("background-color:");
                            builder.append(toHex(background.getRed(), background.getGreen(), background.getBlue()));
                            builder.append(";");
                        }
                        Color foreground = labelProvider.getForeground(element);
                        if (foreground != null) {
                            builder.append("color:");
                            builder.append(toHex(foreground.getRed(), foreground.getGreen(), foreground.getBlue()));
                            builder.append(";");
                        }
                        builder.append("\">");
                        builder.append(text);
                        builder.append("</span>");
                        added = true;
                    }
                    if (added) {
                        addBr = true;
                    }
                }
                return builder.toString();
            }
        });
        if (hasAction) {
            final Image arrow = EJRWTImageRetriever.get("icons/left-arrow.png");
            final TableViewerColumn actionColumn = factory.createColumn("HTML-ACTION", 40, new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    return "";
                }

                @Override
                public Image getImage(Object element) {
                    return arrow;
                }
            });
            actionColumn.getColumn().setAlignment(SWT.RIGHT);
            actionColumn.setEditingSupport(new EditingSupport(_tableViewer) {

                protected void setValue(Object arg0, Object arg1) {
                // ignore
                }

                protected Object getValue(Object arg0) {
                    // ignore
                    return null;
                }

                protected CellEditor getCellEditor(Object arg0) {
                    return new CellEditor() {

                        @Override
                        protected void doSetValue(Object arg0) {
                        // ignore
                        }

                        @Override
                        protected void doSetFocus() {
                        // ignore
                        }

                        @Override
                        protected Object doGetValue() {
                            // ignore
                            return null;
                        }

                        @Override
                        protected Control createControl(Composite parent) {
                            Label action = new Label(parent, SWT.NONE);
                            action.setImage(arrow);
                            return action;
                        }
                    };
                }

                protected boolean canEdit(Object arg0) {
                    _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
                    return false;
                }
            });
        }
        table.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                int offset = hasAction ? 50 : 10;
                if (table.getSize().x > offset)
                    dataColumn.getColumn().setWidth(table.getSize().x - offset);
            }
        });
    }
    table.addFocusListener(new FocusListener() {

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

        public void focusGained(FocusEvent arg0) {
            setHasFocus(true);
        }
    });
    // setHasFocus(true);
    _mainPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent arg0) {
            if (!table.isFocusControl())
                setHasFocus(true);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent arg0) {
            if (!table.isFocusControl())
                setHasFocus(true);
        }
    });
    final EJBlockController blockController = _block;
    _tableViewer.setContentProvider(filteredContentProvider = new FilteredContentProvider() {

        boolean matchItem(EJDataRecord rec) {
            if (filter != null && filter.trim().length() > 0) {
                for (ColumnLabelProvider filterTextProvider : nodeTextProviders) {
                    String text = filterTextProvider.getText(rec);
                    if ((text != null) && text.toLowerCase().contains(filter.toLowerCase())) {
                        return true;
                    }
                }
            }
            return false;
        }

        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
            tableBaseRecords.clear();
            if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
                for (EJDataRecord record : _block.getBlock().getRecords()) {
                    if (matchItem(record))
                        tableBaseRecords.add(record);
                }
            } else {
                filter = null;
                if (filterTree != null)
                    filterTree.clearText();
                tableBaseRecords.addAll(_block.getBlock().getRecords());
            }
        }

        public void dispose() {
        }

        public Object[] getElements(Object arg0) {
            return tableBaseRecords.toArray();
        }
    });
    _tableViewer.setInput(new Object());
    selectRow(0);
    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent arg0) {
            EJDataRecord focusedRecord = getFocusedRecord();
            if (focusedRecord != null)
                _block.newRecordInstance(focusedRecord);
            notifyStatus();
        }
    });
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) ControlAdapter(org.eclipse.swt.events.ControlAdapter) HashMap(java.util.HashMap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) FocusEvent(org.eclipse.swt.events.FocusEvent) EJRWTTableViewerColumnFactory(org.entirej.applicationframework.rwt.table.EJRWTTableViewerColumnFactory) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) FocusListener(org.eclipse.swt.events.FocusListener) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane) Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) EJRWTDeleteAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTDeleteAction) EJRWTQueryAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTQueryAction) EJRWTUpdateAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTUpdateAction) EJRWTInsertAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTInsertAction) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) CellEditor(org.eclipse.jface.viewers.CellEditor) ToolBarManager(org.eclipse.jface.action.ToolBarManager) Font(org.eclipse.swt.graphics.Font) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Control(org.eclipse.swt.widgets.Control) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) EJBlockController(org.entirej.framework.core.data.controllers.EJBlockController) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Section(org.eclipse.ui.forms.widgets.Section) FilteredContentProvider(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable.FilteredContentProvider) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Aggregations

EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)49 Composite (org.eclipse.swt.widgets.Composite)23 Group (org.eclipse.swt.widgets.Group)20 Section (org.eclipse.ui.forms.widgets.Section)19 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)17 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)14 MouseEvent (org.eclipse.swt.events.MouseEvent)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 GridLayout (org.eclipse.swt.layout.GridLayout)14 KeyEvent (org.eclipse.swt.events.KeyEvent)13 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)13 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)13 GridData (org.eclipse.swt.layout.GridData)12 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)12 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)12 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)12 Label (org.eclipse.swt.widgets.Label)11 EJRWTAppItemRenderer (org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer)11 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)11 EJFrameworkExtensionPropertyListEntry (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry)11