Search in sources :

Example 21 with EJScreenItemController

use of org.entirej.framework.core.interfaces.EJScreenItemController in project rap by entirej.

the class EJRWTPieChartRecordBlockRenderer method refresh.

public void refresh(Object input) {
    if (_chartView != null && !_chartView.isDisposed()) {
        Collection<EJDataRecord> records = (!multi) ? Arrays.asList(currentRecord == null ? getFirstRecord() : currentRecord) : _block.getRecords();
        Collection<EJScreenItemController> screenItems = getScreenItems();
        List<String> xlabel = new ArrayList<String>(screenItems.size());
        for (EJScreenItemController sItem : screenItems) {
            if (sItem.isSpacerItem())
                continue;
            xlabel.add(sItem.getProperties().getLabel());
        }
        PieChartRowData chartRowData = new PieChartRowData(xlabel.toArray(new String[0]));
        for (EJDataRecord ejDataRecord : records) {
            if (ejDataRecord == null)
                continue;
            Object lbl = labelColumn != null ? ejDataRecord.getValue(labelColumn) : "";
            PieChartRowData.RowInfo rowInfo = new RowInfo();
            rowInfo.setLabel(lbl != null ? lbl.toString() : "");
            boolean[] hidden = new boolean[screenItems.size()];
            ChartStyle[] styles = new ChartStyle[screenItems.size()];
            double[] data = new double[screenItems.size()];
            int[] widths = new int[screenItems.size()];
            int index = 0;
            for (EJScreenItemController sItem : screenItems) {
                ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
                EJCoreVisualAttributeProperties attributeProperties = sItem.getItemRenderer().getVisualAttributeProperties();
                EJCoreVisualAttributeProperties visualAttribute = ejDataRecord.getItem(sItem.getName()).getVisualAttribute();
                if (visualAttribute != null) {
                    attributeProperties = visualAttribute;
                }
                if (attributeProperties != null) {
                    if (attributeProperties.getForegroundColor() != null) {
                        Color color = attributeProperties.getForegroundColor();
                        colors = new ChartStyle(color.getRed(), color.getGreen(), color.getBlue(), 0.8f);
                    }
                    if (attributeProperties.getBackgroundColor() != null) {
                        Color color = attributeProperties.getBackgroundColor();
                        colors.setFillColor(new RGB(color.getRed(), color.getGreen(), color.getBlue()));
                    }
                }
                EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) sItem.getProperties();
                styles[index] = (colors);
                hidden[index] = (!sItem.isVisible());
                widths[index] = (mainScreenItemProperties.getBlockRendererRequiredProperties().getIntProperty(LINE_WIDTH, 1));
                Object yvalue = ejDataRecord.getValue(sItem.getName());
                double val = 0;
                if (yvalue instanceof Number) {
                    val = ((Number) yvalue).doubleValue();
                }
                data[index] = (val);
                index++;
            }
            // rowInfo.setHidden(hidden);
            rowInfo.setChartStyle(styles);
            rowInfo.setBorderWidth(widths);
            rowInfo.setAction("_pie_select");
            chartRowData.addRow(rowInfo, data);
        }
        _chartView.load(chartRowData, options);
    }
}
Also used : Color(java.awt.Color) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) ChartStyle(org.eclipse.rap.chartjs.ChartStyle) RGB(org.eclipse.swt.graphics.RGB) RowInfo(org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) RowInfo(org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo) JsonObject(org.eclipse.rap.json.JsonObject) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) PieChartRowData(org.eclipse.rap.chartjs.pie.PieChartRowData) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 22 with EJScreenItemController

use of org.entirej.framework.core.interfaces.EJScreenItemController in project rap by entirej.

the class EJRWTPieChartRecordBlockRenderer method getScreenItems.

List<EJScreenItemController> getScreenItems() {
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    List<EJScreenItemController> list = new ArrayList<EJScreenItemController>();
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, mainScreenItemProperties.getReferencedItemName());
            list.add(item);
        }
    }
    return list;
}
Also used : EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)

Example 23 with EJScreenItemController

use of org.entirej.framework.core.interfaces.EJScreenItemController in project rap by entirej.

the class EJRWTPieChartRecordBlockRenderer method processAction.

protected void processAction(String method, JsonObject parameters) {
    if (method.equals("_pie_select")) {
        if (parameters.names().contains("label") && parameters.names().contains("value")) {
            currentRecord = null;
            EJScreenItemController dataItem = null;
            List<EJScreenItemController> screenItems = getScreenItems();
            for (EJScreenItemController sItem : screenItems) {
                String label = sItem.getProperties().getLabel();
                if (label.trim().isEmpty()) {
                    label = sItem.getProperties().getReferencedItemName();
                }
                if (label.equals(parameters.get("label").asString())) {
                    dataItem = sItem;
                    break;
                }
            }
            if (dataItem != null) {
                // Collection<EJDataRecord> records = _block.getRecords();
                // Object lastVal=null;
                // for (EJDataRecord record : records)
                // {
                // Object value = record.getValue(dataItem.getName());
                // if(value==null)
                // value = lastVal;
                // 
                // if (
                // value != null && value.equals(parameters.get("value").asDouble()))
                // {
                // currentRecord = record;
                // break;
                // }
                // lastVal = value;
                // 
                // }
                EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) dataItem.getProperties();
                String action = mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty("action");
                if (action != null && !action.trim().isEmpty()) {
                    _block.executeActionCommand(action, EJScreenType.MAIN);
                }
            }
        }
    }
}
Also used : EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)

Example 24 with EJScreenItemController

use of org.entirej.framework.core.interfaces.EJScreenItemController in project rap by entirej.

the class EJRWTMultiRecordBlockRenderer method createScreenItem.

public ColumnLabelProvider createScreenItem(EJRWTTableViewerColumnFactory factory, EJCoreMainScreenItemProperties itemProps) {
    if (itemProps.isSpacerItem()) {
        return null;
    }
    EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, itemProps.getReferencedItemName());
    EJManagedItemRendererWrapper renderer = item.getManagedItemRenderer();
    if (renderer != null) {
        EJFrameworkExtensionProperties blockProperties = itemProps.getBlockRendererRequiredProperties();
        EJRWTAppItemRenderer itemRenderer = (EJRWTAppItemRenderer) renderer.getUnmanagedRenderer();
        ColumnLabelProvider labelProvider = itemRenderer.createColumnLabelProvider(itemProps, item);
        if (labelProvider != null) {
            String labelOrientation = blockProperties.getStringProperty(EJRWTMultiRecordBlockDefinitionProperties.COLUMN_ALIGNMENT);
            int displayedWidth = blockProperties.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0);
            // width
            if (displayedWidth == 0) {
                if (itemProps.getLabel() != null) {
                    // add offset
                    displayedWidth = itemProps.getLabel().length() + 2;
                } else {
                    displayedWidth = 5;
                }
            }
            String visualAttribute = blockProperties.getStringProperty(EJRWTMultiRecordBlockDefinitionProperties.VISUAL_ATTRIBUTE_PROPERTY);
            if (visualAttribute != null) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    itemRenderer.setInitialVisualAttribute(va);
                }
            }
            if (item.getProperties().getVisualAttributeProperties() != null) {
                renderer.setVisualAttribute(item.getProperties().getVisualAttributeProperties());
            }
            TableViewerColumn viewerColumn = factory.createColumn(itemProps.getLabel(), displayedWidth, labelProvider, getComponentStyle(labelOrientation));
            TableColumn column = viewerColumn.getColumn();
            EJ_RWT.setTestId(column, blockProperties.getName() + "." + itemProps.getReferencedItemName());
            column.setData("KEY", itemProps.getReferencedItemName());
            column.setData("ITEM", item);
            column.setToolTipText(itemProps.getHint());
            ColumnInfo info = new ColumnInfo();
            column.setData("INFO", info);
            column.setMoveable(blockProperties.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ALLOW_COLUMN_REORDER, true));
            column.setResizable(info.resizable = blockProperties.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ALLOW_COLUMN_RESIZE, true));
            if (blockProperties.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ALLOW_ROW_SORTING, true)) {
                EJRWTAbstractTableSorter columnSorter = itemRenderer.getColumnSorter(itemProps, item);
                if (columnSorter != null) {
                    new EJRWTTableSortSelectionListener(_tableViewer, column, columnSorter, SWT.UP, false);
                }
            }
            // ensure that the width property of the table column is in
            // Characters
            Font font = labelProvider.getFont(new Object());
            if (font == null) {
                font = _tableViewer.getTable().getFont();
            }
            if (font != null) {
                float avgCharWidth = EJRWTImageRetriever.getGraphicsProvider().getAvgCharWidth(font);
                if (avgCharWidth > 0) {
                    // add + 1 padding
                    column.setWidth(info.width = ((int) ((column.getWidth() + 1) * avgCharWidth)));
                }
            }
            if (!item.isVisible()) {
                column.setWidth(0);
                column.setResizable(false);
            }
            return labelProvider;
        }
    }
    return null;
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) TableColumn(org.eclipse.swt.widgets.TableColumn) EJRWTAppItemRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJRWTTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTableSortSelectionListener) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties) EJRWTAbstractTableSorter(org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter)

Example 25 with EJScreenItemController

use of org.entirej.framework.core.interfaces.EJScreenItemController in project rap by entirej.

the class EJRWTTreeTableRecordBlockRenderer method createScreenItem.

public ColumnLabelProvider createScreenItem(EJRWTTreeTableViewerColumnFactory factory, EJCoreMainScreenItemProperties itemProps) {
    if (itemProps.isSpacerItem()) {
        return null;
    }
    EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, itemProps.getReferencedItemName());
    EJManagedItemRendererWrapper renderer = item.getManagedItemRenderer();
    if (renderer != null) {
        EJFrameworkExtensionProperties blockProperties = itemProps.getBlockRendererRequiredProperties();
        EJRWTAppItemRenderer itemRenderer = (EJRWTAppItemRenderer) renderer.getUnmanagedRenderer();
        ColumnLabelProvider labelProvider = itemRenderer.createColumnLabelProvider(itemProps, item);
        if (labelProvider != null) {
            String labelOrientation = blockProperties.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.COLUMN_ALIGNMENT);
            int displayedWidth = blockProperties.getIntProperty(EJRWTTreeTableBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0);
            // width
            if (displayedWidth == 0) {
                if (itemProps.getLabel() != null) {
                    // add
                    displayedWidth = itemProps.getLabel().length() + 2;
                // offset
                } else {
                    displayedWidth = 5;
                }
            }
            String visualAttribute = blockProperties.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.VISUAL_ATTRIBUTE_PROPERTY);
            if (visualAttribute != null) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    itemRenderer.setInitialVisualAttribute(va);
                }
            }
            if (item.getProperties().getVisualAttributeProperties() != null) {
                renderer.setVisualAttribute(item.getProperties().getVisualAttributeProperties());
            }
            TreeViewerColumn viewerColumn = factory.createColumn(itemProps.getLabel(), displayedWidth, labelProvider, getComponentStyle(labelOrientation));
            TreeColumn column = viewerColumn.getColumn();
            EJ_RWT.setTestId(column, blockProperties.getName() + "." + itemProps.getReferencedItemName());
            column.setData("KEY", itemProps.getReferencedItemName());
            column.setData("VIEWER", viewerColumn);
            column.setData("ITEM", item);
            column.setToolTipText(itemProps.getHint());
            ColumnInfo info = new ColumnInfo();
            column.setData("INFO", info);
            column.setMoveable(blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_COLUMN_REORDER, true));
            column.setResizable(info.resizable = blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_COLUMN_RESIZE, true));
            if (blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_ROW_SORTING, true)) {
                EJRWTAbstractTableSorter columnSorter = itemRenderer.getColumnSorter(itemProps, item);
                if (columnSorter != null) {
                    new EJRWTTreeTableSortSelectionListener(_tableViewer, column, columnSorter, SWT.UP, false);
                }
            }
            // ensure that the width property of the table column is in
            // Characters
            Font font = labelProvider.getFont(new Object());
            if (font == null) {
                font = _tableViewer.getTree().getFont();
            }
            if (font != null) {
                float avgCharWidth = EJRWTImageRetriever.getGraphicsProvider().getAvgCharWidth(font);
                if (avgCharWidth > 0) {
                    // add
                    column.setWidth(info.width = ((int) ((column.getWidth() + 1) * avgCharWidth)));
                // +1
                // padding
                }
            }
            return labelProvider;
        }
    }
    return null;
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTAppItemRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJRWTTreeTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTreeTableSortSelectionListener) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) TreeColumn(org.eclipse.swt.widgets.TreeColumn) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties) EJRWTAbstractTableSorter(org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter)

Aggregations

EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)29 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)17 EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)14 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)13 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)12 EJRWTAppItemRenderer (org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer)11 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)11 EJScreenItemProperties (org.entirej.framework.core.properties.interfaces.EJScreenItemProperties)11 JsonObject (org.eclipse.rap.json.JsonObject)10 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)9 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)9 EJItemGroupProperties (org.entirej.framework.core.properties.interfaces.EJItemGroupProperties)9 ArrayList (java.util.ArrayList)8 FillLayout (org.eclipse.swt.layout.FillLayout)8 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)8 Action (org.eclipse.jface.action.Action)5 IAction (org.eclipse.jface.action.IAction)5 ToolBarManager (org.eclipse.jface.action.ToolBarManager)5 FocusEvent (org.eclipse.swt.events.FocusEvent)5 FocusListener (org.eclipse.swt.events.FocusListener)5