Search in sources :

Example 46 with EJFrameworkExtensionProperties

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

the class EJRWTStandardLovRenderer method buildGui.

protected void buildGui() {
    int width = _lovController.getDefinitionProperties().getWidth();
    int height = _lovController.getDefinitionProperties().getHeight();
    _dialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        private static final long serialVersionUID = -4685316941898120169L;

        private EJRWTAbstractFilteredTable filterTree;

        private String defaultMessage;

        @Override
        public boolean close() {
            _tableViewer = null;
            _dialog = null;
            return super.close();
        }

        @Override
        public void activateDialog() {
            super.activateDialog();
            filterTree.getFilterControl().forceFocus();
        }

        @Override
        public void createBody(Composite parent) {
            GridLayout layout = new GridLayout();
            EJ_RWT.setTestId(parent, "lov." + _lovController.getProperties().getLovDefinition().getName());
            layout.marginWidth = 0;
            // layout.horizontalSpacing = 0;
            layout.marginLeft = 0;
            layout.marginRight = 0;
            layout.marginHeight = 0;
            // layout.verticalSpacing = 0;
            layout.marginBottom = 0;
            layout.marginTop = 0;
            parent.setLayout(layout);
            int style = SWT.VIRTUAL;
            EJFrameworkExtensionProperties rendererProp = _lovController.getDefinitionProperties().getLovRendererProperties();
            if (!rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false)) {
                style = style | SWT.BORDER;
            }
            defaultMessage = rendererProp.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
            ;
            Table table;
            filterTree = new EJRWTAbstractFilteredTable(parent, style) {

                @Override
                public void filter(String filter) {
                    if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
                        _filteredContentProvider.setFilter(filter);
                        getViewer().setInput(filter);
                        getViewer().getTable().select(0);
                    }
                }

                @Override
                protected boolean doCreateCustomComponents(Composite parent) {
                    return createToolbar(parent) != null;
                }

                @Override
                protected TableViewer doCreateTableViewer(Composite parent, int style) {
                    _tableViewer = new TableViewer(new Table(parent, style));
                    return _tableViewer;
                }
            };
            if (defaultMessage != null)
                filterTree.getFilterControl().setMessage(defaultMessage);
            EJ_RWT.setTestId(filterTree.getFilterControl(), "lov-search");
            table = (_tableViewer = filterTree.getViewer()).getTable();
            table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            table.setLinesVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_VERTICAL_LINES, true));
            table.setHeaderVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true));
            EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
            ColumnViewerToolTipSupport.enableFor(_tableViewer);
            Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
            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);
                    }
                }
            }
            final EJBlockController blockController = _block.getBlockController();
            // _mainPane.addControlListener(new
            // TableAutoResizeAdapter(table));
            /*
                 * _tableViewer.setContentProvider(new ILazyContentProvider() {
                 * 
                 * @Override public void inputChanged(Viewer arg0, Object arg1,
                 * Object arg2) {
                 * _tableViewer.setItemCount(blockController.getDataBlock().
                 * getBlockRecordCount());
                 * 
                 * }
                 * 
                 * @Override public void dispose() { // TODO Auto-generated
                 * method stub
                 * 
                 * }
                 * 
                 * @Override public void updateElement(int index) { EJDataRecord
                 * record = null; if (index <=
                 * blockController.getDataBlock().getBlockRecordCount()) {
                 * record = blockController.getDataBlock().getRecord(index);
                 * 
                 * } _tableViewer.replace(record, index);
                 * 
                 * } });
                 */
            _tableViewer.setContentProvider(_filteredContentProvider = new FilteredContentProvider() {

                private static final long serialVersionUID = 7262009393527533868L;

                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) {
                        for (EJDataRecord record : blockController.getBlock().getRecords()) {
                            if (matchItem(record)) {
                                _tableBaseRecords.add(record);
                            }
                        }
                    } else {
                        filter = null;
                        if (filterTree != null) {
                            filterTree.clearText();
                        }
                        _tableBaseRecords.addAll(blockController.getBlock().getRecords());
                    }
                }

                @Override
                public void dispose() {
                }

                @Override
                public Object[] getElements(Object arg0) {
                    return _tableBaseRecords.toArray();
                }
            });
            _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

                @Override
                public void doubleClick(DoubleClickEvent arg0) {
                    buttonPressed(OK_ACTION_COMMAND);
                }
            });
            _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

                @Override
                public void selectionChanged(SelectionChangedEvent arg0) {
                    if (!_validate) {
                        return;
                    }
                    _validate = false;
                    try {
                        EJDataRecord record = getFocusedRecord();
                        if (_lovController.getFocusedRecord() == null || _lovController.getFocusedRecord() != record) {
                            _lovController.newRecordInstance(record);
                        }
                    } finally {
                        _validate = true;
                    }
                }
            });
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            EJ_RWT.setTestId(createButton(parent, OK_ACTION_COMMAND, "OK", true), "ok");
            EJ_RWT.setTestId(createButton(parent, CANCEL_ACTION_COMMAND, "Cancel", false), "cancel");
        }

        @Override
        public void canceled() {
            _lovController.lovCompleted(_itemToValidate, null);
            close();
        }

        @Override
        protected void buttonPressed(int buttonId) {
            switch(buttonId) {
                case OK_ACTION_COMMAND:
                    {
                        _lovController.lovCompleted(_itemToValidate, _lovController.getFocusedRecord());
                        if (_dialog != null) {
                            _dialog.close();
                        }
                        break;
                    }
                case CANCEL_ACTION_COMMAND:
                    {
                        _lovController.lovCompleted(_itemToValidate, null);
                        if (_dialog != null) {
                            _dialog.close();
                        }
                        break;
                    }
                default:
                    _lovController.lovCompleted(_itemToValidate, null);
                    break;
            }
            super.buttonPressed(buttonId);
        }
    };
    _dialog.create();
    _tableViewer.setInput(new Object());
    selectRow(0);
    // add dialog
    _dialog.getShell().setSize(width + 80, height + 100);
// border
// offsets
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) List(java.util.List) ArrayList(java.util.ArrayList) EJBlockController(org.entirej.framework.core.data.controllers.EJBlockController) EJRWTTableViewerColumnFactory(org.entirej.applicationframework.rwt.table.EJRWTTableViewerColumnFactory) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) Table(org.eclipse.swt.widgets.Table) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredContentProvider(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable.FilteredContentProvider) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) TableViewer(org.eclipse.jface.viewers.TableViewer) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Example 47 with EJFrameworkExtensionProperties

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

the class EJRWTInsertScreenRenderer method setupInsertScreen.

private void setupInsertScreen() {
    // Setup pane for Insert window
    EJFrameworkExtensionProperties rendererProperties = _block.getProperties().getInsertScreenRendererProperties();
    String title = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.TITLE);
    final int width = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.WIDTH, 300);
    _maximize = rendererProperties.getBooleanProperty(EJRWTScreenRendererDefinitionProperties.MAXIMIZE, false);
    final int height = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.HEIGHT, 500);
    final int numCols = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.NUM_COLS, 1);
    final String insertButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXECUTE_BUTTON_TEXT);
    final String cancelButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CANCEL_BUTTON_TEXT);
    EJFrameworkExtensionProperties extraButtonsGroup = rendererProperties.getPropertyGroup(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTONS_GROUP);
    final String button1Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_ONE_LABEL);
    final String button1Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_ONE_COMMAND);
    final String button2Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_TWO_LABEL);
    final String button2Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_TWO_COMMAND);
    final String button3Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_THREE_LABEL);
    final String button3Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_THREE_COMMAND);
    final String button4Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FOUR_LABEL);
    final String button4Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FOUR_COMMAND);
    final String button5Label = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FIVE_LABEL);
    final String button5Command = extraButtonsGroup.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXTRA_BUTTON_FIVE_COMMAND);
    final int ID_BUTTON_1 = 1;
    final int ID_BUTTON_2 = 2;
    final int ID_BUTTON_3 = 3;
    final int ID_BUTTON_4 = 4;
    final int ID_BUTTON_5 = 5;
    _insertDialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        @Override
        public void createBody(Composite parent) {
            EJ_RWT.setTestId(parent, _block.getProperties().getName() + ".insert-screen");
            parent.setLayout(new FillLayout());
            final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            EJRWTEntireJGridPane _mainPane = new EJRWTEntireJGridPane(scrollComposite, numCols);
            _mainPane.cleanLayout();
            EJBlockProperties blockProperties = _block.getProperties();
            addAllItemGroups(blockProperties.getScreenItemGroupContainer(EJScreenType.INSERT), _mainPane, EJScreenType.INSERT);
            scrollComposite.setContent(_mainPane);
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            // remove the offset
            scrollComposite.setMinSize(width, height - 10);
            _block.addItemValueChangedListener(EJRWTInsertScreenRenderer.this);
            EJRWTItemTextChangeNotifier.ChangeListener changeListener = new ChangeListener() {

                @Override
                public void changed() {
                    validate();
                }
            };
            Collection<EJManagedItemRendererWrapper> registeredRenderers = _itemRegister.getRegisteredRenderers();
            for (EJManagedItemRendererWrapper ejManagedItemRendererWrapper : registeredRenderers) {
                if (ejManagedItemRendererWrapper.getUnmanagedRenderer() instanceof EJRWTItemTextChangeNotifier) {
                    ((EJRWTItemTextChangeNotifier) ejManagedItemRendererWrapper.getUnmanagedRenderer()).addListener(changeListener);
                }
            }
        }

        @Override
        public void validate() {
            Button button = getButton(INSERT_OK_ACTION_COMMAND);
            if (button == null) {
                return;
            }
            Collection<EJScreenItemController> allScreenItems = _block.getAllScreenItems(EJScreenType.INSERT);
            for (EJScreenItemController ejScreenItemController : allScreenItems) {
                if (!ejScreenItemController.getManagedItemRenderer().isValid()) {
                    button.setEnabled(false);
                    return;
                }
            }
            button.setEnabled(true);
        }

        @Override
        public int open() {
            validate();
            setFoucsItemRenderer();
            return super.open();
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            // Add the buttons in reverse order, as they will be added from left to right
            addExtraButton(parent, button5Label, ID_BUTTON_5);
            addExtraButton(parent, button4Label, ID_BUTTON_4);
            addExtraButton(parent, button3Label, ID_BUTTON_3);
            addExtraButton(parent, button2Label, ID_BUTTON_2);
            addExtraButton(parent, button1Label, ID_BUTTON_1);
            EJ_RWT.setTestId(createButton(parent, INSERT_OK_ACTION_COMMAND, insertButtonLabel == null ? "Insert" : insertButtonLabel, true), "ok");
            EJ_RWT.setTestId(createButton(parent, INSERT_CANCEL_ACTION_COMMAND, cancelButtonLabel == null ? "Cancel" : cancelButtonLabel, false), "cancel");
        }

        private void addExtraButton(Composite parent, String label, int id) {
            if (label == null) {
                return;
            }
            Button button = createButton(parent, id, label, false);
            EJ_RWT.setTestId(button, _block.getProperties().getName() + ".btn-" + id);
        }

        @Override
        public boolean close() {
            _block.removeItemValueChangedListener(EJRWTInsertScreenRenderer.this);
            _block.setRendererFocus(true);
            return super.close();
        }

        @Override
        public void canceled() {
            _block.insertCancelled();
            close();
        }

        @Override
        protected void buttonPressed(int buttonId) {
            Display.getDefault().asyncExec(() -> {
                try {
                    switch(buttonId) {
                        case INSERT_OK_ACTION_COMMAND:
                            {
                                EJDataRecord newRecord = getInsertRecord();
                                try {
                                    _block.getBlock().insertRecord(newRecord);
                                    if (_block.getInsertScreenDisplayProperties().getBooleanProperty(EJRWTScreenRendererDefinitionProperties.SAVE_FORM_AFTER_EXECUTE, false)) {
                                        _block.getBlock().getForm().saveChanges();
                                    }
                                } catch (EJApplicationException e) {
                                    setButtonEnable(buttonId, false);
                                    throw e;
                                }
                                close();
                                break;
                            }
                        case INSERT_CANCEL_ACTION_COMMAND:
                            {
                                _block.insertCancelled();
                                close();
                                break;
                            }
                        case ID_BUTTON_1:
                            {
                                _block.executeActionCommand(button1Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_2:
                            {
                                _block.executeActionCommand(button2Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_3:
                            {
                                _block.executeActionCommand(button3Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_4:
                            {
                                _block.executeActionCommand(button4Command, EJScreenType.UPDATE);
                                break;
                            }
                        case ID_BUTTON_5:
                            {
                                _block.executeActionCommand(button5Command, EJScreenType.UPDATE);
                                break;
                            }
                        default:
                            _block.updateCancelled();
                            break;
                    }
                } catch (EJApplicationException e) {
                    _logger.trace(e.getMessage());
                    _frameworkManager.handleException(e);
                    return;
                }
            });
        }
    };
    _insertDialog.create();
    _insertDialog.getShell().setData("INSERT - " + _block.getProperties().getName());
    _insertDialog.getShell().setText(title != null ? title : "");
    // add dialog border offsets
    _insertDialog.getShell().setSize(width + 80, height + 100);
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJApplicationException(org.entirej.framework.core.EJApplicationException) FillLayout(org.eclipse.swt.layout.FillLayout) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) Button(org.eclipse.swt.widgets.Button) EJRWTItemTextChangeNotifier(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Collection(java.util.Collection) ChangeListener(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 48 with EJFrameworkExtensionProperties

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

the class EJRWTQueryScreenRenderer method setupQueryScreen.

private void setupQueryScreen() {
    // Setup pane for query window
    EJFrameworkExtensionProperties rendererProperties = _block.getProperties().getQueryScreenRendererProperties();
    String title = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.TITLE);
    final int width = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.WIDTH, 300);
    final int height = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.HEIGHT, 500);
    _maximize = rendererProperties.getBooleanProperty(EJRWTScreenRendererDefinitionProperties.MAXIMIZE, false);
    final int numCols = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.NUM_COLS, 1);
    final String queryButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXECUTE_BUTTON_TEXT);
    final String cancelButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CANCEL_BUTTON_TEXT);
    final String clearButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CLEAR_BUTTON_TEXT);
    _queryDialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        private static final long serialVersionUID = -4685316941898120169L;

        @Override
        public void createBody(Composite parent) {
            EJ_RWT.setTestId(parent, _block.getProperties().getName() + ".query-screen");
            parent.setLayout(new FillLayout());
            final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            EJRWTEntireJGridPane _mainPane = new EJRWTEntireJGridPane(scrollComposite, numCols);
            _mainPane.cleanLayout();
            EJBlockProperties blockProperties = _block.getProperties();
            addAllItemGroups(blockProperties.getScreenItemGroupContainer(EJScreenType.QUERY), _mainPane, EJScreenType.QUERY);
            scrollComposite.setContent(_mainPane);
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            // remove the oddset
            scrollComposite.setMinSize(width, height - 10);
            _block.addItemValueChangedListener(EJRWTQueryScreenRenderer.this);
            EJRWTItemTextChangeNotifier.ChangeListener changeListener = new ChangeListener() {

                @Override
                public void changed() {
                    validate();
                }
            };
            Collection<EJManagedItemRendererWrapper> registeredRenderers = _itemRegister.getRegisteredRenderers();
            for (EJManagedItemRendererWrapper ejManagedItemRendererWrapper : registeredRenderers) {
                if (ejManagedItemRendererWrapper.getUnmanagedRenderer() instanceof EJRWTItemTextChangeNotifier) {
                    ((EJRWTItemTextChangeNotifier) ejManagedItemRendererWrapper.getUnmanagedRenderer()).addListener(changeListener);
                }
            }
        }

        @Override
        public void validate() {
            Button button = getButton(QUERY_OK_ACTION_COMMAND);
            if (button == null) {
                return;
            }
            Collection<EJScreenItemController> allScreenItems = _block.getAllScreenItems(EJScreenType.QUERY);
            for (EJScreenItemController ejScreenItemController : allScreenItems) {
                if (!ejScreenItemController.getManagedItemRenderer().isValid()) {
                    button.setEnabled(false);
                    return;
                }
            }
            button.setEnabled(true);
        }

        @Override
        public int open() {
            validate();
            setFoucsItemRenderer();
            return super.open();
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            EJ_RWT.setTestId(createButton(parent, QUERY_OK_ACTION_COMMAND, queryButtonLabel == null ? "Query" : queryButtonLabel, true), _block.getProperties().getName() + ".ok");
            EJ_RWT.setTestId(createButton(parent, QUERY_CLEAR_ACTION_COMMAND, clearButtonLabel == null ? "Clear" : clearButtonLabel, false), _block.getProperties().getName() + ".clear");
            EJ_RWT.setTestId(createButton(parent, QUERY_CANCEL_ACTION_COMMAND, cancelButtonLabel == null ? "Cancel" : cancelButtonLabel, false), _block.getProperties().getName() + ".cancel");
        }

        @Override
        public void canceled() {
            close();
        }

        @Override
        public boolean close() {
            _block.removeItemValueChangedListener(EJRWTQueryScreenRenderer.this);
            _block.setRendererFocus(true);
            return super.close();
        }

        @Override
        protected void buttonPressed(int buttonId) {
            Display.getDefault().asyncExec(() -> {
                try {
                    switch(buttonId) {
                        case QUERY_OK_ACTION_COMMAND:
                            {
                                EJQueryBlock b = new EJLovBlock(_block.getBlock());
                                EJQueryCriteria queryCriteria = new EJQueryCriteria(b);
                                EJDataRecord record = getQueryRecord();
                                for (EJDataItem item : record.getAllItems()) {
                                    boolean serviceItem = item.isBlockServiceItem();
                                    if (item.getValue() != null) {
                                        if (item.getProperties().getDataTypeClass().isAssignableFrom(String.class)) {
                                            String value = (String) item.getValue();
                                            if (value.contains("%")) {
                                                queryCriteria.add(EJRestrictions.like(item.getName(), serviceItem, item.getValue()));
                                            } else {
                                                queryCriteria.add(EJRestrictions.equals(item.getName(), serviceItem, item.getValue()));
                                            }
                                        } else {
                                            queryCriteria.add(EJRestrictions.equals(item.getName(), serviceItem, item.getValue()));
                                        }
                                    }
                                }
                                try {
                                    _block.executeQuery(queryCriteria);
                                } catch (EJApplicationException e) {
                                    setButtonEnable(buttonId, false);
                                    throw e;
                                }
                                close();
                                break;
                            }
                        case QUERY_CLEAR_ACTION_COMMAND:
                            {
                                _itemRegister.clearRegisteredValues();
                                _itemRegister.register(_block.createRecord(EJRecordType.QUERY));
                                break;
                            }
                        case QUERY_CANCEL_ACTION_COMMAND:
                            {
                                close();
                                break;
                            }
                    }
                } catch (EJApplicationException e) {
                    _logger.trace(e.getMessage());
                    _frameworkManager.handleException(e);
                    return;
                }
            });
        }
    };
    _queryDialog.create();
    _queryDialog.getShell().setData("QUERY - " + _block.getProperties().getName());
    _queryDialog.getShell().setText(title != null ? title : "");
    // add dialog border offsets
    _queryDialog.getShell().setSize(width + 80, height + 100);
}
Also used : EJQueryCriteria(org.entirej.framework.core.service.EJQueryCriteria) EJQueryBlock(org.entirej.framework.core.EJQueryBlock) EJLovBlock(org.entirej.framework.core.EJLovBlock) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) Button(org.eclipse.swt.widgets.Button) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ChangeListener(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJDataItem(org.entirej.framework.core.data.EJDataItem) EJApplicationException(org.entirej.framework.core.EJApplicationException) FillLayout(org.eclipse.swt.layout.FillLayout) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) EJRWTItemTextChangeNotifier(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier) Collection(java.util.Collection) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 49 with EJFrameworkExtensionProperties

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

the class EJRWTTextItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    String alignmentProperty = _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_ALIGNMENT);
    if (alignmentProperty == null) {
        alignmentProperty = _rendererProps.getStringProperty("ALLIGNMENT");
    }
    String hint = _screenItemProperties.getHint();
    if (_displayValueAsLabel) {
        labelField = new EJRWTAbstractLabel(composite) {

            @Override
            public Label createLabel(Composite parent) {
                return _valueLabel = newVlaueLabel(parent);
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public Control createActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        _valueLabel.setData(_itemProperties.getName());
        _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        if (hint != null && hint.trim().length() > 0) {
            _valueLabel.setToolTipText(hint);
        }
        setValueLabelAlign(alignmentProperty);
        _visualContext = new EJRWTItemRendererVisualContext(_valueLabel.getBackground(), _valueLabel.getForeground(), _valueLabel.getFont());
        setInitialValue(_baseValue);
    } else {
        final String alignmentProp = alignmentProperty;
        _actionControl = new EJRWTAbstractActionText(composite) {

            @Override
            public Text createText(Composite parent) {
                int style = SWT.BORDER;
                if (_displayValueAsProtected) {
                    style = style | SWT.PASSWORD;
                }
                _textField = newTextField(parent, getComponentStyle(alignmentProp, style));
                _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);
                }
                return _textField;
            }

            @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(EJRWTTextItemRenderer.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);
                getTextControl().setData(EJ_RWT.ACTIVE_KEYS, keys);
                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 != (_textField.getStyle() & SWT.MULTI) || (arg0.stateMask & SWT.CONTROL) != 0)) {
                            commitValue();
                        }
                    }

                    @Override
                    public void keyPressed(KeyEvent arg0) {
                    }
                });
                return label;
            }
        };
        if (_maxLength > 0) {
            _textField.setTextLimit(_maxLength);
        }
        if (hint != null && hint.trim().length() > 0) {
            _textField.setToolTipText(hint);
        }
        _visualContext = new EJRWTItemRendererVisualContext(_textField.getBackground(), _textField.getForeground(), _textField.getFont());
        _textField.setData(_item.getReferencedItemProperties().getName());
        _textField.addFocusListener(this);
        _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();
        _textField.addModifyListener(_modifyListener);
        // TODO: Move to client side validation on Rap 2.4
        if (_valueCase != null && _valueCase != VALUE_CASE.DEFAULT) {
            _textField.addVerifyListener(new VerifyListener() {

                @Override
                public void verifyText(VerifyEvent event) {
                    String caseValue = toCaseValue(event.text);
                    if (!event.text.equals(caseValue)) {
                        event.text = caseValue;
                    }
                }
            });
        }
        setInitialValue(_baseValue);
        _textField.setMessage(defaultMessage == null ? "" : defaultMessage);
        setMessage(message);
    }
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) MouseEvent(org.eclipse.swt.events.MouseEvent) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) Text(org.eclipse.swt.widgets.Text) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) KeyEvent(org.eclipse.swt.events.KeyEvent) Control(org.eclipse.swt.widgets.Control) MouseListener(org.eclipse.swt.events.MouseListener) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) KeyListener(org.eclipse.swt.events.KeyListener) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

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