Search in sources :

Example 11 with EJFrameworkExtensionProperties

use of org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties 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 12 with EJFrameworkExtensionProperties

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

the class EJRWTDateTimeItemRenderer method createDateFormat.

protected static DateFormat createDateFormat(EJScreenItemController item) {
    DateFormat dateFormat;
    Locale defaultLocale = Locale.getDefault();
    EJFrameworkExtensionProperties rendererProps = item.getReferencedItemProperties().getItemRendererProperties();
    String format = rendererProps.getStringProperty(EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS);
    boolean istime = EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE_TIME.equals(rendererProps.getStringProperty(EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE));
    if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_LONG.equals(format)) {
        if (istime) {
            dateFormat = new SimpleDateFormat("HH:mm:ss");
        } else {
            dateFormat = DateFormat.getDateInstance(DateFormat.LONG, defaultLocale);
        }
    } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_MEDIUM.equals(format)) {
        if (istime) {
            dateFormat = new SimpleDateFormat("HH:mm:ss");
        } else {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, defaultLocale);
        }
    } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_SHORT.equals(format)) {
        if (istime) {
            dateFormat = new SimpleDateFormat("HH:mm");
        } else {
            dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, defaultLocale);
        }
    } else {
        dateFormat = new SimpleDateFormat();
    }
    return dateFormat;
}
Also used : Locale(java.util.Locale) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with EJFrameworkExtensionProperties

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

the class EJRWTNumberItemRenderer method createFormatter.

static DecimalFormat createFormatter(EJScreenItemController item, NUMBER_TYPE numberType) {
    DecimalFormat _decimalFormatter = null;
    EJFrameworkExtensionProperties _rendererProps = item.getReferencedItemProperties().getItemRendererProperties();
    Locale defaultLocale = item.getForm().getFrameworkManager().getCurrentLocale();
    if (defaultLocale == null) {
        defaultLocale = Locale.getDefault();
    }
    String format = _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_FORMAT);
    if (format == null || format.length() == 0) {
        _decimalFormatter = (DecimalFormat) NumberFormat.getNumberInstance(defaultLocale);
    } else {
        DecimalFormatSymbols dfs = new DecimalFormatSymbols(defaultLocale);
        _decimalFormatter = new DecimalFormat(format, dfs);
        switch(numberType) {
            case INTEGER:
            case LONG:
                _decimalFormatter.setGroupingUsed(true);
                _decimalFormatter.setParseIntegerOnly(true);
                _decimalFormatter.setParseBigDecimal(false);
                break;
            default:
                char seperator = dfs.getDecimalSeparator();
                if (format.indexOf(seperator) != -1) {
                    _decimalFormatter.setGroupingUsed(true);
                }
                _decimalFormatter.setParseIntegerOnly(false);
                _decimalFormatter.setParseBigDecimal(true);
                break;
        }
    }
    return _decimalFormatter;
}
Also used : Locale(java.util.Locale) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 14 with EJFrameworkExtensionProperties

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

the class EJRWTStackedItemRenderer method connectLOVAction.

void connectLOVAction(final Text text) {
    final EJFrameworkExtensionProperties rendererProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
    final EJFrameworkExtensionProperties propertyGroup = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
    String lovKey = "SHIFT+ARROW_DOWN";
    if (propertyGroup != null) {
        lovKey = propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_LOV_KEY);
    }
    if (lovKey == null) {
        lovKey = "SHIFT+ARROW_DOWN";
    }
    String[] keys = new String[] { lovKey, "ENTER", "RETURN", "CR" };
    text.setData(EJ_RWT.ACTIVE_KEYS, keys);
    text.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent arg0) {
            if ((arg0.stateMask & SWT.SHIFT) != 0 && arg0.keyCode == SWT.ARROW_DOWN && isLovActivated()) {
                _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
            }
            if (arg0.keyCode == 13 && (SWT.MULTI != (text.getStyle() & SWT.MULTI) || (arg0.stateMask & SWT.CONTROL) != 0)) {
                if (_valueChanged) {
                    _valueChanged = false;
                    _item.itemValueChaged(getRealValue());
                    _oldvalue = null;
                    setMandatoryBorder(_mandatory);
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) KeyListener(org.eclipse.swt.events.KeyListener)

Example 15 with EJFrameworkExtensionProperties

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

the class EJRWTStackedItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    String alignmentProperty = _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_ALIGNMENT);
    if (alignmentProperty == null) {
        alignmentProperty = _rendererProps.getStringProperty("ALLIGNMENT");
    }
    _numberType = getNumberType(_baseValue);
    _decimalFormatter = createFormatter(_numberType, null);
    _dateFormat = new MultiDateFormater(DateFormat.getDateInstance(DateFormat.SHORT, _item.getForm().getFrameworkManager().getCurrentLocale()));
    String hint = _screenItemProperties.getHint();
    {
        final String alignmentProp = alignmentProperty;
        _actionControl = new EJRWTAbstractPanelAction(composite) {

            @Override
            public Composite createPanel(Composite parent) {
                stackedPane = new EJRWTEntireJStackedPane(parent);
                // _textField.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
                // String customCSSKey =
                // _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
                // 
                // if (customCSSKey != null && customCSSKey.trim().length()
                // > 0)
                // {
                // _textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
                // }
                buildStackUI(stackedPane);
                return stackedPane;
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                return createCustomButtonControl(parent);
            }

            @Override
            public Control createActionLabel(Composite parent) {
                Label label = new Label(parent, SWT.NONE);
                label.setImage(EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_FIND_LOV));
                label.addFocusListener(EJRWTStackedItemRenderer.this);
                label.addMouseListener(new MouseListener() {

                    private static final long serialVersionUID = 529634857284996692L;

                    @Override
                    public void mouseUp(MouseEvent arg0) {
                        _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
                    }

                    @Override
                    public void mouseDown(MouseEvent arg0) {
                    }

                    @Override
                    public void mouseDoubleClick(MouseEvent arg0) {
                    }
                });
                final EJFrameworkExtensionProperties rendererProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
                final EJFrameworkExtensionProperties propertyGroup = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
                String lovKey = "SHIFT+ARROW_DOWN";
                if (propertyGroup != null) {
                    lovKey = propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_LOV_KEY);
                }
                if (lovKey == null) {
                    lovKey = "SHIFT+ARROW_DOWN";
                }
                String[] keys = new String[] { lovKey, "ENTER", "RETURN", "CR" };
                label.setData(EJ_RWT.ACTIVE_KEYS, keys);
                return label;
            }
        };
        if (hint != null && hint.trim().length() > 0) {
            updateStackHint(hint);
        }
        _mandatoryDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_ERROR));
        _mandatoryDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_REQUIRED));
        _mandatoryDecoration.setShowHover(true);
        _mandatoryDecoration.setDescriptionText(_screenItemProperties.getLabel() == null || _screenItemProperties.getLabel().isEmpty() ? "Required Item" : String.format("%s is required", _screenItemProperties.getLabel()));
        if (_isValid) {
            _errorDecoration.hide();
        }
        if (message != null) {
            setMessage(message);
        }
        _mandatoryDecoration.hide();
        setInitialValue(_baseValue);
    }
}
Also used : MultiDateFormater(org.entirej.applicationframework.rwt.renderers.item.EJRWTDateItemRenderer.MultiDateFormater) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) EJRWTEntireJStackedPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJStackedPane) MouseListener(org.eclipse.swt.events.MouseListener) EJRWTAbstractPanelAction(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractPanelAction) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration)

Aggregations

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