Search in sources :

Example 6 with EJCoreMainScreenItemProperties

use of org.entirej.framework.core.properties.EJCoreMainScreenItemProperties in project rap by entirej.

the class EJRWTTreeTableRecordBlockRenderer method buildGuiComponent.

@Override
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);
        }
    }
    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();
    }
    _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);
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(section, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayoutHorizontal();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            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() {

                @Override
                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 {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayout();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.VIRTUAL | SWT.FULL_SELECTION;
    if (!_rendererProp.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.HIDE_TREE_BORDER, false)) {
        style = style | SWT.BORDER;
    }
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Tree table;
    if (_rendererProp.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.FILTER, true)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new GridLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                filterTree = new EJRWTAbstractFilteredTree(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;
                            filaterData(filter);
                        }
                    }
                };
            } else {
                filterTree = new EJRWTAbstractFilteredTree(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style) {

                    @Override
                    public void filter(String filter) {
                        if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
                            _filteredContentProvider.setFilter(filter);
                            filterText = filter;
                            filaterData(filter);
                        }
                    }
                };
                filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            filterTree = new EJRWTAbstractFilteredTree(_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;
                        filaterData(filter);
                    }
                }
            };
            filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        table = (_tableViewer = filterTree.getViewer()).getTree();
    } else {
        filterTree = null;
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                table = new Tree(group, style);
            } else {
                table = new Tree(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style);
                table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            table = new Tree(_mainPane, style);
            table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
    }
    table.setLinesVisible(_rendererProp.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.SHOW_VERTICAL_LINES, true));
    table.setHeaderVisible(_rendererProp.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true));
    Control[] children = table.getChildren();
    for (Control control : children) {
        hookKeyListener(control);
    }
    hookKeyListener(table);
    // final boolean hideSelection = (style & SWT.HIDE_SELECTION) != 0;
    _tableViewer = new TreeViewer(table);
    ColumnViewerToolTipSupport.enableFor(_tableViewer);
    EJRWTTreeTableViewerColumnFactory factory = new EJRWTTreeTableViewerColumnFactory(_tableViewer);
    final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
    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);
            }
        }
    }
    table.addFocusListener(new FocusListener() {

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

        @Override
        public void focusGained(FocusEvent arg0) {
            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 String pid = _rendererProp.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.PARENT_ITEM);
    final String rid = _rendererProp.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.RELATION_ITEM);
    final String imageid = _rendererProp.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.NODE_IMAGE_ITEM);
    if (imageid != null && _tableViewer.getTree().getColumnCount() > 0) {
        final ColumnLabelProvider baselabelProvider = (ColumnLabelProvider) _tableViewer.getLabelProvider(0);
        ColumnLabelProvider imgPatchedProvider = new ColumnLabelProvider() {

            final transient Map<Object, Image> imageMap = new HashMap<Object, Image>();

            @Override
            public void dispose() {
                for (Image img : imageMap.values()) {
                    img.dispose();
                }
                imageMap.clear();
                super.dispose();
            }

            @Override
            public Font getFont(Object element) {
                return baselabelProvider.getFont(element);
            }

            @Override
            public Color getBackground(Object element) {
                return baselabelProvider.getBackground(element);
            }

            @Override
            public Color getForeground(Object element) {
                return baselabelProvider.getForeground(element);
            }

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

            @Override
            public Color getToolTipBackgroundColor(Object object) {
                return baselabelProvider.getToolTipBackgroundColor(object);
            }

            @Override
            public int getToolTipDisplayDelayTime(Object object) {
                return baselabelProvider.getToolTipDisplayDelayTime(object);
            }

            @Override
            public Font getToolTipFont(Object object) {
                return baselabelProvider.getToolTipFont(object);
            }

            @Override
            public Color getToolTipForegroundColor(Object object) {
                return baselabelProvider.getToolTipForegroundColor(object);
            }

            @Override
            public Image getToolTipImage(Object object) {
                return baselabelProvider.getToolTipImage(object);
            }

            @Override
            public Point getToolTipShift(Object object) {
                return baselabelProvider.getToolTipShift(object);
            }

            @Override
            public int getToolTipStyle(Object object) {
                return baselabelProvider.getToolTipStyle(object);
            }

            @Override
            public String getToolTipText(Object element) {
                return baselabelProvider.getToolTipText(element);
            }

            @Override
            public int getToolTipTimeDisplayed(Object object) {
                return baselabelProvider.getToolTipTimeDisplayed(object);
            }

            @Override
            public Image getImage(Object element) {
                if (imageid != null && element instanceof EJDataRecord) {
                    EJDataRecord record = (EJDataRecord) element;
                    Object iV = record.getValue(imageid);
                    if (iV == null) {
                        return null;
                    }
                    Image image = imageMap.get(iV);
                    if (image != null && !image.isDisposed()) {
                        return image;
                    }
                    if (iV instanceof URL) {
                        image = ImageDescriptor.createFromURL((URL) iV).createImage();
                    } else if (iV instanceof byte[]) {
                        image = new Image(Display.getDefault(), new ByteArrayInputStream((byte[]) iV));
                    }
                    if (image != null) {
                        imageMap.put(iV, image);
                    }
                    return image;
                }
                return super.getImage(element);
            }
        };
        ((TreeViewerColumn) _tableViewer.getTree().getColumn(0).getData("VIEWER")).setLabelProvider(imgPatchedProvider);
    }
    int intProperty = _rendererProp.getIntProperty(EJRWTTreeTableBlockDefinitionProperties.NODE_EXPAND_LEVEL, 1);
    // workaround
    intProperty++;
    if (intProperty < 1 && intProperty < 2) {
        intProperty = 2;
    }
    if (intProperty > 1)
        _tableViewer.setAutoExpandLevel(intProperty);
    _tableViewer.setContentProvider(_filteredContentProvider = new FilteredContentProvider() {

        private List<EJDataRecord> root = new ArrayList<EJDataRecord>();

        private Map<Object, Object> indexMap = new HashMap<Object, Object>();

        private Map<Object, Object> fullindexMap = new HashMap<Object, Object>();

        private Map<Object, List<EJDataRecord>> cmap = new HashMap<Object, List<EJDataRecord>>();

        private List<EJDataRecord> froot = new ArrayList<EJDataRecord>();

        private Map<Object, List<EJDataRecord>> fcmap = new HashMap<Object, List<EJDataRecord>>();

        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;
        }

        @Override
        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
            _treeBaseRecords.clear();
            if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
                froot.clear();
                fcmap.clear();
                // filter
                for (Entry<Object, List<EJDataRecord>> entry : cmap.entrySet()) {
                    List<EJDataRecord> values = entry.getValue();
                    List<EJDataRecord> fvalues = new ArrayList<EJDataRecord>(values.size());
                    fcmap.put(entry.getKey(), fvalues);
                    for (EJDataRecord record : values) {
                        if (matchItem(record)) {
                            fvalues.add(record);
                            addParents(record);
                        }
                    }
                }
                // filter root
                for (EJDataRecord record : root) {
                    if (matchItem(record)) {
                        froot.add(record);
                    } else if (hasChildren(record)) {
                        froot.add(record);
                    }
                }
                for (EJDataRecord record : froot) {
                    _treeBaseRecords.add(record);
                    addSubRecords(record.getValue(pid), fcmap);
                }
            } else {
                filter = null;
                if (filterTree != null) {
                    filterTree.clearText();
                }
                root.clear();
                indexMap.clear();
                fullindexMap.clear();
                froot.clear();
                cmap.clear();
                fcmap.clear();
                Collection<EJDataRecord> records = _block.getRecords();
                for (EJDataRecord record : records) {
                    Object rV = record.getValue(rid);
                    Object pV = record.getValue(pid);
                    if (pV != null) {
                        fullindexMap.put(pV, record);
                    }
                    if (rV == null) {
                        root.add(record);
                        if (pid != null) {
                            indexMap.put(pV, record);
                        }
                        continue;
                    }
                    List<EJDataRecord> list = cmap.get(rV);
                    if (list == null) {
                        list = new ArrayList<EJDataRecord>();
                        cmap.put(rV, list);
                    }
                    list.add(record);
                }
                // child node with no parent need to consider as roots
                MAIN: for (Object key : new HashSet<Object>(cmap.keySet())) {
                    if (indexMap.containsKey(key)) {
                        continue;
                    }
                    for (EJDataRecord rec : records) {
                        if (key.equals(rec.getValue(pid))) {
                            continue MAIN;
                        }
                    }
                    List<EJDataRecord> list = cmap.get(key);
                    cmap.remove(key);
                    for (EJDataRecord record : list) {
                        Object pV = record.getValue(pid);
                        root.add(record);
                        if (pid != null) {
                            indexMap.put(pV, record);
                        }
                    }
                }
                for (EJDataRecord record : root) {
                    _treeBaseRecords.add(record);
                    addSubRecords(record.getValue(pid), cmap);
                }
            }
        }

        private void addParents(EJDataRecord record) {
            if (record != null) {
                EJDataRecord parent = (EJDataRecord) getParent(record);
                if (parent != null && !root.contains(parent)) {
                    Object rV = parent.getValue(rid);
                    if (rV != null) {
                        List<EJDataRecord> list = fcmap.get(rV);
                        if (list == null) {
                            list = new ArrayList<EJDataRecord>();
                            fcmap.put(rV, list);
                        }
                        if (!list.contains(parent))
                            list.add(parent);
                        addParents(parent);
                    }
                }
            }
        }

        private void addSubRecords(Object key, Map<Object, List<EJDataRecord>> cmap) {
            if (key != null) {
                List<EJDataRecord> list = cmap.get(key);
                if (list != null) {
                    for (EJDataRecord record : list) {
                        _treeBaseRecords.add(record);
                        addSubRecords(record.getValue(pid), cmap);
                    }
                }
            }
        }

        @Override
        public void dispose() {
            root.clear();
            indexMap.clear();
            fullindexMap.clear();
            cmap.clear();
            froot.clear();
            fcmap.clear();
        }

        @Override
        public Object[] getElements(Object arg0) {
            if (filter != null && filter.trim().length() > 0) {
                return froot.toArray();
            }
            return root.toArray();
        }

        @Override
        public Object[] getChildren(Object arg0) {
            Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
            if (arg0 instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) arg0;
                Object pV = record.getValue(pid);
                if (pV != null) {
                    List<EJDataRecord> list = map.get(pV);
                    if (list != null) {
                        return list.toArray();
                    }
                }
            }
            return new Object[0];
        }

        @Override
        public Object getParent(Object arg0) {
            if (arg0 instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) arg0;
                Object rV = record.getValue(rid);
                if (rV != null) {
                    return fullindexMap.get(rV);
                }
            }
            return null;
        }

        @Override
        public boolean hasChildren(Object arg0) {
            if (arg0 instanceof EJDataRecord) {
                Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
                EJDataRecord record = (EJDataRecord) arg0;
                Object pV = record.getValue(pid);
                if (pV != null) {
                    List<EJDataRecord> list = map.get(pV);
                    return list != null && list.size() > 0;
                }
            }
            return false;
        }
    });
    _tableViewer.setInput(new Object());
    selectFirst();
    // add double click action
    final String doubleClickActionCommand = _rendererProp.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
    if (doubleClickActionCommand != null) {
        _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent arg0) {
                _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
            }
        });
    }
    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent arg0) {
            EJDataRecord focusedRecord = getFocusedRecord();
            if (focusedRecord != null) {
                _block.newRecordInstance(focusedRecord);
            }
        }
    });
    table.addListener(SWT.MouseDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point pt = new Point(event.x, event.y);
            TreeItem item = table.getItem(pt);
            if (item == null)
                return;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    TreeColumn column = table.getColumn(i);
                    if (column != null && column.getData("ITEM") instanceof EJScreenItemController) {
                        ((EJScreenItemController) column.getData("ITEM")).executeActionCommand();
                    }
                }
            }
        }
    });
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) Rectangle(org.eclipse.swt.graphics.Rectangle) TreeViewer(org.eclipse.jface.viewers.TreeViewer) 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) EJRWTAbstractFilteredTree(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) ByteArrayInputStream(java.io.ByteArrayInputStream) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) FocusListener(org.eclipse.swt.events.FocusListener) Map(java.util.Map) HashMap(java.util.HashMap) 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) Listener(org.eclipse.swt.widgets.Listener) EJRWTTreeTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTreeTableSortSelectionListener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) KeyListener(org.eclipse.swt.events.KeyListener) ToolBarManager(org.eclipse.jface.action.ToolBarManager) URL(java.net.URL) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) TreeColumn(org.eclipse.swt.widgets.TreeColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) EJRWTAbstractFilteredTree(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree) Point(org.eclipse.swt.graphics.Point) Section(org.eclipse.ui.forms.widgets.Section) Point(org.eclipse.swt.graphics.Point) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) FilteredContentProvider(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree.FilteredContentProvider) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) EJRWTTreeTableViewerColumnFactory(org.entirej.applicationframework.rwt.table.EJRWTTreeTableViewerColumnFactory) 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) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Example 7 with EJCoreMainScreenItemProperties

use of org.entirej.framework.core.properties.EJCoreMainScreenItemProperties in project rap by entirej.

the class EJRWTTreeRecordBlockRenderer method buildGuiComponent.

@Override
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);
        }
    }
    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();
    }
    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);
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(section, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            _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() {

                @Override
                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 {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayout();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.NONE;
    if (!rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_TREE_BORDER, false)) {
        style = style | SWT.BORDER;
    }
    if (!rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_SELECTION, false)) {
        style = style | SWT.FULL_SELECTION;
    }
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Tree table;
    if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, true)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new GridLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                filterTree = new EJRWTAbstractFilteredTree(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;
                            filaterData(filter);
                        }
                    }
                };
            } else {
                filterTree = new EJRWTAbstractFilteredTree(_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;
                            filaterData(filter);
                        }
                    }
                };
                filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            filterTree = new EJRWTAbstractFilteredTree(_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;
                        filaterData(filter);
                    }
                }
            };
            filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        table = (_tableViewer = filterTree.getViewer()).getTree();
        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() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                table = new Tree(group, style);
            } else {
                table = new Tree(_mainPane, style | (displayProperties.dispayGroupFrame() ? SWT.BORDER : SWT.NONE));
                table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            table = new Tree(_mainPane, style);
            table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        _tableViewer = new TreeViewer(table);
    }
    Control[] children = table.getChildren();
    for (Control control : children) {
        hookKeyListener(control);
    }
    hookKeyListener(table);
    ColumnViewerToolTipSupport.enableFor(_tableViewer);
    final List<TreeNodeTextProvider> nodeTextProviders = new ArrayList<EJRWTTreeRecordBlockRenderer.TreeNodeTextProvider>();
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            TreeNodeTextProvider screenItem = createScreenItem(mainScreenItemProperties);
            if (screenItem != null) {
                nodeTextProviders.add(screenItem);
            }
        }
    }
    table.addFocusListener(new FocusListener() {

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

        @Override
        public void focusGained(FocusEvent arg0) {
            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);
            }
        }
    });
    table.setLinesVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.COLORING_EFFECT, true));
    final String pid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.PARENT_ITEM);
    final String rid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.RELATION_ITEM);
    final String imageid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.NODE_IMAGE_ITEM);
    final EJCoreVisualAttributeProperties baseVA;
    String visualAttribute = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.VISUAL_ATTRIBUTE_PROPERTY);
    if (visualAttribute != null) {
        baseVA = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
    } else {
        baseVA = null;
    }
    final Map<Object, Image> imageMap = new HashMap<Object, Image>();
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(_tableViewer, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    _tableViewer.getTree().addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Tree table = (Tree) event.widget;
            int columnCount = table.getColumnCount();
            if (columnCount == 0)
                return;
            Rectangle area = table.getClientArea();
            int totalAreaWdith = area.width;
            column.setWidth(totalAreaWdith);
        }
    });
    table.setHeaderVisible(false);
    viewerColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (pid != null && element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(pid).getVisualAttribute();
            }
            if (properties == null) {
                properties = baseVA;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(element);
            if (properties != null) {
                Font font = super.getFont(element);
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, font != null ? font : _tableViewer.getTree().getFont());
            }
            return super.getFont(element);
        }

        @Override
        public Image getImage(Object element) {
            if (imageid != null && element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                Object iV = record.getValue(imageid);
                if (iV == null) {
                    return null;
                }
                Image image = imageMap.get(iV);
                if (image != null && !image.isDisposed()) {
                    return image;
                }
                if (iV instanceof URL) {
                    image = ImageDescriptor.createFromURL((URL) iV).createImage();
                } else if (iV instanceof byte[]) {
                    image = new Image(Display.getDefault(), new ByteArrayInputStream((byte[]) iV));
                } else {
                    if (iV != null) {
                        try {
                            URL url = this.getClass().getResource((String) iV);
                            if (url != null) {
                                image = ImageDescriptor.createFromURL((URL) url).createImage();
                            }
                        } catch (Exception e) {
                            image = null;
                        }
                    }
                }
                if (image != null) {
                    imageMap.put(iV, image);
                }
                return image;
            }
            return super.getImage(element);
        }

        @Override
        public String getText(Object element) {
            if (nodeTextProviders.size() == 1) {
                return nodeTextProviders.get(0).getText(element);
            }
            StringBuilder builder = new StringBuilder();
            for (TreeNodeTextProvider textProvider : nodeTextProviders) {
                builder.append(textProvider.getText(element));
            }
            return builder.toString();
        }
    });
    int intProperty = rendererProp.getIntProperty(EJRWTTreeBlockDefinitionProperties.NODE_EXPAND_LEVEL, 1);
    // workaround
    intProperty++;
    if (intProperty < 1 && intProperty < 2) {
        intProperty = 2;
    }
    if (intProperty > 1)
        _tableViewer.setAutoExpandLevel(intProperty);
    _tableViewer.setContentProvider(filteredContentProvider = new FilteredContentProvider() {

        private List<EJDataRecord> root = new ArrayList<EJDataRecord>();

        private Map<Object, Object> indexMap = new HashMap<Object, Object>();

        private Map<Object, Object> fullindexMap = new HashMap<Object, Object>();

        private Map<Object, List<EJDataRecord>> cmap = new HashMap<Object, List<EJDataRecord>>();

        private List<EJDataRecord> froot = new ArrayList<EJDataRecord>();

        private Map<Object, List<EJDataRecord>> fcmap = new HashMap<Object, List<EJDataRecord>>();

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

        private void addParents(EJDataRecord record) {
            if (record != null) {
                EJDataRecord parent = (EJDataRecord) getParent(record);
                if (parent != null && !root.contains(parent)) {
                    Object rV = parent.getValue(rid);
                    if (rV != null) {
                        List<EJDataRecord> list = fcmap.get(rV);
                        if (list == null) {
                            list = new ArrayList<EJDataRecord>();
                            fcmap.put(rV, list);
                        }
                        if (!list.contains(parent))
                            list.add(parent);
                        addParents(parent);
                    }
                }
            }
        }

        @Override
        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
            treeBaseRecords.clear();
            if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
                froot.clear();
                fcmap.clear();
                // filter
                for (Entry<Object, List<EJDataRecord>> entry : cmap.entrySet()) {
                    List<EJDataRecord> values = entry.getValue();
                    List<EJDataRecord> fvalues = new ArrayList<EJDataRecord>(values.size());
                    fcmap.put(entry.getKey(), fvalues);
                    for (EJDataRecord record : values) {
                        if (matchItem(record)) {
                            fvalues.add(record);
                            addParents(record);
                        }
                    }
                }
                // filter root
                for (EJDataRecord record : root) {
                    if (matchItem(record)) {
                        froot.add(record);
                    } else if (hasChildren(record)) {
                        froot.add(record);
                    }
                }
                for (EJDataRecord record : froot) {
                    treeBaseRecords.add(record);
                    addSubRecords(record.getValue(pid), fcmap);
                }
            } else {
                filter = null;
                if (filterTree != null) {
                    filterTree.clearText();
                }
                root.clear();
                indexMap.clear();
                fullindexMap.clear();
                froot.clear();
                cmap.clear();
                fcmap.clear();
                for (Image img : imageMap.values()) {
                    img.dispose();
                }
                imageMap.clear();
                Collection<EJDataRecord> records = _block.getRecords();
                for (EJDataRecord record : records) {
                    Object rV = record.getValue(rid);
                    Object pV = record.getValue(pid);
                    if (pV != null) {
                        fullindexMap.put(pV, record);
                    }
                    if (rV == null) {
                        root.add(record);
                        if (pid != null) {
                            indexMap.put(pV, record);
                        }
                        continue;
                    }
                    List<EJDataRecord> list = cmap.get(rV);
                    if (list == null) {
                        list = new ArrayList<EJDataRecord>();
                        cmap.put(rV, list);
                    }
                    list.add(record);
                }
                // child node with no parent need to consider as roots
                MAIN: for (Object key : new HashSet<Object>(cmap.keySet())) {
                    if (indexMap.containsKey(key)) {
                        continue;
                    }
                    for (EJDataRecord rec : records) {
                        if (key.equals(rec.getValue(pid))) {
                            continue MAIN;
                        }
                    }
                    List<EJDataRecord> list = cmap.get(key);
                    cmap.remove(key);
                    for (EJDataRecord record : list) {
                        Object pV = record.getValue(pid);
                        root.add(record);
                        if (pid != null) {
                            indexMap.put(pV, record);
                        }
                    }
                }
                for (EJDataRecord record : root) {
                    treeBaseRecords.add(record);
                    addSubRecords(record.getValue(pid), cmap);
                }
            }
        }

        private void addSubRecords(Object key, Map<Object, List<EJDataRecord>> cmap) {
            if (key != null) {
                List<EJDataRecord> list = cmap.get(key);
                if (list != null) {
                    for (EJDataRecord record : list) {
                        treeBaseRecords.add(record);
                        addSubRecords(record.getValue(pid), cmap);
                    }
                }
            }
        }

        @Override
        public void dispose() {
            root.clear();
            indexMap.clear();
            fullindexMap.clear();
            cmap.clear();
            froot.clear();
            fcmap.clear();
            for (Image img : imageMap.values()) {
                img.dispose();
            }
            imageMap.clear();
        }

        @Override
        public Object[] getElements(Object arg0) {
            if (filter != null && filter.trim().length() > 0) {
                return froot.toArray();
            }
            return root.toArray();
        }

        @Override
        public Object[] getChildren(Object arg0) {
            Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
            if (arg0 instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) arg0;
                Object pV = record.getValue(pid);
                if (pV != null) {
                    List<EJDataRecord> list = map.get(pV);
                    if (list != null) {
                        return list.toArray();
                    }
                }
            }
            return new Object[0];
        }

        @Override
        public Object getParent(Object arg0) {
            if (arg0 instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) arg0;
                Object rV = record.getValue(rid);
                if (rV != null) {
                    return fullindexMap.get(rV);
                }
            }
            return null;
        }

        @Override
        public boolean hasChildren(Object arg0) {
            if (arg0 instanceof EJDataRecord) {
                Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
                EJDataRecord record = (EJDataRecord) arg0;
                Object pV = record.getValue(pid);
                if (pV != null) {
                    List<EJDataRecord> list = map.get(pV);
                    return list != null && list.size() > 0;
                }
            }
            return false;
        }
    });
    _tableViewer.setInput(new Object());
    selectFirst();
    // add double click action
    final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
    if (doubleClickActionCommand != null) {
        _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent arg0) {
                _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
            }
        });
    }
    // add double click action
    final String clickActionCommand = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.CLICK_ACTION_COMMAND);
    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent arg0) {
            EJDataRecord focusedRecord = getFocusedRecord();
            if (focusedRecord != null) {
                _block.newRecordInstance(focusedRecord);
            }
            if (clickActionCommand != null && !onSelection.get()) {
                _block.executeActionCommand(clickActionCommand, EJScreenType.MAIN);
            }
            if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_SELECTION, false)) {
                _tableViewer.removeSelectionChangedListener(this);
                _tableViewer.getTree().deselectAll();
                _tableViewer.addSelectionChangedListener(this);
            }
        }
    });
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) HashMap(java.util.HashMap) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) Rectangle(org.eclipse.swt.graphics.Rectangle) TreeViewer(org.eclipse.jface.viewers.TreeViewer) 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) EJRWTAbstractFilteredTree(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) FocusListener(org.eclipse.swt.events.FocusListener) Map(java.util.Map) HashMap(java.util.HashMap) 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) Listener(org.eclipse.swt.widgets.Listener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) KeyListener(org.eclipse.swt.events.KeyListener) ToolBarManager(org.eclipse.jface.action.ToolBarManager) Font(org.eclipse.swt.graphics.Font) URL(java.net.URL) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) TreeColumn(org.eclipse.swt.widgets.TreeColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) EJRWTAbstractFilteredTree(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree) Section(org.eclipse.ui.forms.widgets.Section) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) FilteredContentProvider(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTree.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) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 8 with EJCoreMainScreenItemProperties

use of org.entirej.framework.core.properties.EJCoreMainScreenItemProperties in project rap by entirej.

the class EJRWTMultiRecordBlockRenderer method buildGuiComponent.

@Override
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);
        }
    }
    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);
        }
        String frameTitle = mainScreenProperties.getFrameTitle();
        EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(section, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setLayoutData(gridData);
            if (!mainScreenProperties.getDisplayFrame())
                _mainPane.cleanLayoutHorizontal();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            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() {

                @Override
                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 {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setLayoutData(gridData);
            if (!mainScreenProperties.getDisplayFrame())
                _mainPane.cleanLayout();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.VIRTUAL;
    if (!rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false)) {
        style = style | SWT.BORDER;
    }
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Table table;
    if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new GridLayout());
                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);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent, style);
                    }
                };
            } else {
                filterTree = new EJRWTAbstractFilteredTable(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : 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);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent, style);
                    }
                };
                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);
                        if (getFocusedRecord() == null) {
                            selectRow(0);
                        }
                        notifyStatus();
                    }
                }

                @Override
                protected TableViewer doCreateTableViewer(Composite parent, int style) {
                    return _tableViewer = new TableViewer(parent, style);
                }
            };
            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() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                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, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : 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);
    }
    table.setLinesVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_VERTICAL_LINES, true));
    table.setHeaderVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true));
    int fixedColumns = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.COLUMNS_FIXED, -1);
    if (fixedColumns > 0) {
        table.setData(EJ_RWT.FIXED_COLUMNS, fixedColumns);
    }
    int rowHeight = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_HEIGH_PROPERTY, -1);
    if (rowHeight > 0) {
        table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, rowHeight);
    }
    Control[] children = table.getChildren();
    for (Control control : children) {
        hookKeyListener(control);
    }
    hookKeyListener(table);
    EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
    ColumnViewerToolTipSupport.enableFor(_tableViewer);
    boolean autoSize = false;
    final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
    table.setData(EJ_RWT.MARKUP_ENABLED, rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ENABLE_MARKUP, false));
    boolean markEscapeHtml = false;
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        autoSize = itemProperties.size() == 1;
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            ColumnLabelProvider screenItem = createScreenItem(factory, mainScreenItemProperties);
            if (screenItem instanceof HtmlBaseColumnLabelProvider) {
                table.setData(EJ_RWT.MARKUP_ENABLED, true);
                markEscapeHtml = !rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ENABLE_MARKUP, false);
            }
            if (screenItem != null) {
                nodeTextProviders.add(screenItem);
                if (autoSize) {
                    EJFrameworkExtensionProperties itemBl = mainScreenItemProperties.getBlockRendererRequiredProperties();
                    autoSize = itemBl != null && itemBl.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0) <= 0;
                }
            }
        }
    }
    if (markEscapeHtml)
        for (ColumnLabelProvider columnLabelProvider : nodeTextProviders) {
            if (columnLabelProvider instanceof HtmlEscapeSupport) {
                HtmlEscapeSupport escapeSupport = (HtmlEscapeSupport) columnLabelProvider;
                escapeSupport.setEscape();
            }
        }
    if (autoSize) {
        table.addControlListener(new ControlListener() {

            @Override
            public void controlResized(ControlEvent e) {
                if (table.getSize().x > 10) {
                    table.getColumn(0).setWidth(table.getSize().x - 10);
                }
            }

            @Override
            public void controlMoved(ControlEvent e) {
            // TODO Auto-generated method stub
            }
        });
    }
    table.addFocusListener(new FocusListener() {

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

        @Override
        public void focusGained(FocusEvent arg0) {
            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);
            }
        }
    });
    _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;
        }

        @Override
        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
            _tableBaseRecords.clear();
            if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
                // filter
                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());
            }
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object arg0) {
            return _tableBaseRecords.toArray();
        }
    });
    _tableViewer.setInput(new Object());
    selectRow(0);
    // add double click action
    final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTMultiRecordBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
    if (doubleClickActionCommand != null) {
        _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent arg0) {
                _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
            }
        });
    }
    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent arg0) {
            EJDataRecord focusedRecord = getFocusedRecord();
            if (focusedRecord != null) {
                _block.newRecordInstance(focusedRecord);
            }
            notifyStatus();
        }
    });
    table.addListener(SWT.MouseDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point pt = new Point(event.x, event.y);
            TableItem item = table.getItem(pt);
            if (item == null || item.isDisposed())
                return;
            for (int i = 0; i < table.getColumnCount(); i++) {
                if (item == null || item.isDisposed())
                    return;
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    TableColumn column = table.getColumn(i);
                    if (column != null && column.getData("ITEM") instanceof EJScreenItemController) {
                        ((EJScreenItemController) column.getData("ITEM")).executeActionCommand();
                    }
                }
            }
        }
    });
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) Rectangle(org.eclipse.swt.graphics.Rectangle) 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) FocusEvent(org.eclipse.swt.events.FocusEvent) ControlListener(org.eclipse.swt.events.ControlListener) 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) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) HtmlEscapeSupport(org.entirej.applicationframework.rwt.table.HtmlEscapeSupport) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) 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) ControlListener(org.eclipse.swt.events.ControlListener) EJRWTTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTableSortSelectionListener) Listener(org.eclipse.swt.widgets.Listener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) KeyListener(org.eclipse.swt.events.KeyListener) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) 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) 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) Point(org.eclipse.swt.graphics.Point) Section(org.eclipse.ui.forms.widgets.Section) Point(org.eclipse.swt.graphics.Point) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) 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)

Example 9 with EJCoreMainScreenItemProperties

use of org.entirej.framework.core.properties.EJCoreMainScreenItemProperties in project rap by entirej.

the class EJRWTBarChartRecordBlockRenderer method buildGuiComponent.

@Override
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);
        }
    }
    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();
    }
    _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);
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(section, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayoutHorizontal();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            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() {

                @Override
                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 {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1);
            _mainPane.setLayoutData(gridData);
            _mainPane.cleanLayout();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.NONE;
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    {
        _chartView = null;
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                _chartView = new BarChart(group, style) {

                    protected void action(String method, org.eclipse.rap.json.JsonObject parameters) {
                        processAction(method, parameters);
                    }
                };
            } else {
                _chartView = new BarChart(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style) {

                    protected void action(String method, org.eclipse.rap.json.JsonObject parameters) {
                        processAction(method, parameters);
                    }
                };
                _chartView.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            _chartView = new BarChart(_mainPane, style) {

                protected void action(String method, org.eclipse.rap.json.JsonObject parameters) {
                    processAction(method, parameters);
                }
            };
            _chartView.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
    }
    _chartView.addFocusListener(new FocusListener() {

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

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

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

        @Override
        public void mouseDown(MouseEvent arg0) {
            if (!_chartView.isFocusControl()) {
                setHasFocus(true);
            }
        }
    });
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            String visualAttribute = mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty(VISUAL_ATTRIBUTE_PROPERTY);
            EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, mainScreenItemProperties.getReferencedItemName());
            EJRWTAppItemRenderer itemRenderer = (EJRWTAppItemRenderer) item.getManagedItemRenderer().getUnmanagedRenderer();
            if (visualAttribute != null) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    itemRenderer.setInitialVisualAttribute(va);
                }
            }
            if (item.getProperties().getVisualAttributeProperties() != null) {
                itemRenderer.setVisualAttribute(item.getProperties().getVisualAttributeProperties());
            }
        }
    }
    appItemRenderer = null;
    final EJItemController blockItemController = _block.getBlockItemController(xAxisColumn);
    String itemRendererName = blockItemController.getProperties().getItemRendererName();
    if (itemRendererName != null) {
        EJScreenItemController itemController = new EJScreenItemController() {

            @Override
            public boolean validateFromLov() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public void setItemLovMapping(String lovMapping) {
            // TODO Auto-generated method stub
            }

            @Override
            public void removeItemValueChangedListener(EJScreenItemValueChangedListener listener) {
            // TODO Auto-generated method stub
            }

            @Override
            public void removeItemFocusListener(EJItemFocusListener listener) {
            // TODO Auto-generated method stub
            }

            @Override
            public void itemValueChaged(Object newValue) {
            // TODO Auto-generated method stub
            }

            @Override
            public void itemFocusLost() {
            // TODO Auto-generated method stub
            }

            @Override
            public void itemFocusGained() {
            // TODO Auto-generated method stub
            }

            @Override
            public boolean isVisible() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public boolean isSpacerItem() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public void initialiseRenderer() {
            // TODO Auto-generated method stub
            }

            @Override
            public void initialise(EJBlockItemRendererRegister blockItemRegister) {
            // TODO Auto-generated method stub
            }

            @Override
            public EJScreenType getScreenType() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJItemProperties getReferencedItemProperties() {
                return blockItemController.getProperties();
            }

            @Override
            public EJScreenItemProperties getProperties() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getName() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJManagedItemRendererWrapper getManagedItemRenderer() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJBlockItemRendererRegister getItemRendererRegister() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJItemRenderer getItemRenderer() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJItemLovController getItemLovController() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public EJInternalForm getForm() {
                // TODO Auto-generated method stub
                return _block.getForm();
            }

            @Override
            public EJInternalBlock getBlock() {
                return _block.getBlock();
            }

            @Override
            public void gainFocus() {
            // TODO Auto-generated method stub
            }

            @Override
            public void executeActionCommand() {
            // TODO Auto-generated method stub
            }

            @Override
            public void addItemValueChangedListener(EJScreenItemValueChangedListener listener) {
            // TODO Auto-generated method stub
            }

            @Override
            public void addItemFocusListener(EJItemFocusListener listener) {
            // TODO Auto-generated method stub
            }
        };
        EJManagedItemRendererWrapper renderer = EJRendererFactory.getInstance().getItemRenderer(itemController, new EJCoreMainScreenItemProperties(_block.getProperties(), false));
        if (renderer != null && renderer.getUnmanagedRenderer() instanceof EJRWTAppItemRenderer) {
            appItemRenderer = (EJRWTAppItemRenderer) renderer.getUnmanagedRenderer();
        }
    }
    refresh();
}
Also used : Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) 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) Action(org.eclipse.jface.action.Action) EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) EJBlockItemRendererRegister(org.entirej.framework.core.renderers.registry.EJBlockItemRendererRegister) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) JsonObject(org.eclipse.rap.json.JsonObject) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ToolBarManager(org.eclipse.jface.action.ToolBarManager) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) BarChart(org.eclipse.rap.chartjs.bar.BarChart) EJScreenItemValueChangedListener(org.entirej.framework.core.renderers.eventhandlers.EJScreenItemValueChangedListener) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) MouseEvent(org.eclipse.swt.events.MouseEvent) EJItemFocusListener(org.entirej.framework.core.renderers.eventhandlers.EJItemFocusListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Section(org.eclipse.ui.forms.widgets.Section) EJRWTAppItemRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) EJItemController(org.entirej.framework.core.data.controllers.EJItemController) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) JsonObject(org.eclipse.rap.json.JsonObject) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) EJItemFocusListener(org.entirej.framework.core.renderers.eventhandlers.EJItemFocusListener) FocusListener(org.eclipse.swt.events.FocusListener) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 10 with EJCoreMainScreenItemProperties

use of org.entirej.framework.core.properties.EJCoreMainScreenItemProperties in project rap by entirej.

the class EJRWTBarChartRecordBlockRenderer method refresh.

public void refresh(Object input) {
    if (_chartView != null && !_chartView.isDisposed()) {
        if (xAxisColumn == null && xAxisColumn.isEmpty()) {
            return;
        }
        Map<Object, Map<String, Float>> dataset = new HashMap<Object, Map<String, Float>>();
        Map<Object, Map<String, EJCoreVisualAttributeProperties>> datasetVa = new HashMap<Object, Map<String, EJCoreVisualAttributeProperties>>();
        Collection<EJDataRecord> records = _block.getRecords();
        Collection<EJScreenItemController> screenItems = getScreenItems();
        List<Object> labelsIndex = new ArrayList<Object>();
        Map<String, Number> lastVal = new HashMap<String, Number>();
        for (EJDataRecord ejDataRecord : records) {
            Object xobject = ejDataRecord.getValue(xAxisColumn);
            if (xobject != null) {
                Map<String, Float> set = dataset.get(xobject);
                Map<String, EJCoreVisualAttributeProperties> setVa = datasetVa.get(xobject);
                if (set == null) {
                    set = new HashMap<String, Float>();
                    setVa = new HashMap<String, EJCoreVisualAttributeProperties>();
                    dataset.put(xobject, set);
                    datasetVa.put(xobject, setVa);
                    labelsIndex.add(xobject);
                }
                for (EJScreenItemController sItem : screenItems) {
                    if (!sItem.isSpacerItem()) {
                        Object yvalue = ejDataRecord.getValue(sItem.getName());
                        Float val = null;
                        if (yvalue instanceof Number) {
                            lastVal.put(sItem.getName(), (Number) yvalue);
                            val = ((Number) yvalue).floatValue();
                        } else {
                            Number last = lastVal.get(sItem.getName());
                            val = last != null ? last.floatValue() : 0f;
                        }
                        set.put(sItem.getName(), val);
                        EJCoreVisualAttributeProperties visualAttribute = ejDataRecord.getItem(sItem.getName()).getVisualAttribute();
                        if (visualAttribute == null)
                            visualAttribute = sItem.getItemRenderer().getVisualAttributeProperties();
                        setVa.put(sItem.getName(), visualAttribute);
                    }
                }
            }
        }
        List<String> xlabel = new ArrayList<String>(labelsIndex.size());
        for (Object object : labelsIndex) {
            String xvalue;
            xvalue = getStrValue(object);
            xlabel.add(xvalue);
        }
        BarChartRowData chartRowData = new BarChartRowData(xlabel.toArray(new String[0]));
        for (EJScreenItemController sItem : screenItems) {
            if (sItem.isSpacerItem())
                continue;
            List<Float> row = new ArrayList<Float>();
            List<EJCoreVisualAttributeProperties> rowVa = new ArrayList<EJCoreVisualAttributeProperties>();
            for (Object object : labelsIndex) {
                Map<String, Float> map = dataset.get(object);
                Map<String, EJCoreVisualAttributeProperties> mapVa = datasetVa.get(object);
                if (map == null || mapVa == null)
                    continue;
                row.add(map.get(sItem.getName()));
                rowVa.add(mapVa.get(sItem.getName()));
            }
            float[] floatArray = new float[row.size()];
            ChartStyle[] styleArray = new ChartStyle[row.size()];
            int i = 0;
            for (Float f : row) {
                floatArray[i] = (f != null ? f : 0);
                ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
                EJCoreVisualAttributeProperties attributeProperties = rowVa.get(i);
                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()));
                    }
                }
                styleArray[i] = colors;
                i++;
            }
            /*
                 * String pointStyle = "circle";
                 * 
                 * ChartStyle chartStyle;
                 */
            BarChartRowData.RowInfo info = new BarChartRowData.RowInfo();
            String label = sItem.getProperties().getLabel();
            if (label.trim().isEmpty()) {
                label = sItem.getProperties().getReferencedItemName();
            }
            info.setLabel(label);
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) sItem.getProperties();
            String action = mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty("action");
            if (action == null || action.trim().isEmpty()) {
                action = "select";
            }
            ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
            EJCoreVisualAttributeProperties attributeProperties = sItem.getItemRenderer().getVisualAttributeProperties();
            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()));
                }
            }
            info.setAction(action);
            info.setChartStyle(colors);
            info.setHidden(!sItem.isVisible());
            chartRowData.addRow(info, floatArray, styleArray);
        // chartRowData.addRow(floatArray, colors);
        }
        if (horizontalBar)
            _chartView.loadHorizontal(chartRowData, options);
        else
            _chartView.load(chartRowData, options);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) ChartStyle(org.eclipse.rap.chartjs.ChartStyle) Color(java.awt.Color) RGB(org.eclipse.swt.graphics.RGB) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) JsonObject(org.eclipse.rap.json.JsonObject) Map(java.util.Map) HashMap(java.util.HashMap) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties) BarChartRowData(org.eclipse.rap.chartjs.bar.BarChartRowData)

Aggregations

EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)18 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)14 EJItemGroupProperties (org.entirej.framework.core.properties.interfaces.EJItemGroupProperties)12 EJScreenItemProperties (org.entirej.framework.core.properties.interfaces.EJScreenItemProperties)12 ArrayList (java.util.ArrayList)11 GridData (org.eclipse.swt.layout.GridData)10 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)10 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)10 JsonObject (org.eclipse.rap.json.JsonObject)8 FocusEvent (org.eclipse.swt.events.FocusEvent)8 FocusListener (org.eclipse.swt.events.FocusListener)8 MouseAdapter (org.eclipse.swt.events.MouseAdapter)8 MouseEvent (org.eclipse.swt.events.MouseEvent)8 Group (org.eclipse.swt.widgets.Group)8 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)8 Action (org.eclipse.jface.action.Action)7 IAction (org.eclipse.jface.action.IAction)7 ToolBarManager (org.eclipse.jface.action.ToolBarManager)7 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)7 DisposeEvent (org.eclipse.swt.events.DisposeEvent)7