Search in sources :

Example 6 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTCheckBoxItemRenderer method initialise.

@Override
public void initialise(EJScreenItemController item, EJScreenItemProperties screenItemProperties) {
    super.initialise(item, screenItemProperties);
    final String checkedValue = _rendererProps.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.CHECKED_VALUE);
    final String uncheckedValue = _rendererProps.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.UNCHECKED_VALUE);
    final String otherValueMapping = _rendererProps.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.OTHER_VALUE_MAPPING);
    if (checkedValue == null || uncheckedValue == null) {
        throw new EJApplicationException(new EJMessage("A checked and unchecked value must be specified for the Check Box Renderer for item: " + _itemProperties.getBlockName() + "." + _rendererProps.getName()));
    }
    // set 3 state checkBox
    if (_item.getScreenType() == EJScreenType.QUERY) {
        _useTriStateChaeckBox = _rendererProps.getBooleanProperty(EJRWTCheckBoxRendererDefinitionProperties.TRI_STATE, false);
    }
    _checkedValue = getValueAsObject(_itemProperties.getDataTypeClass(), checkedValue);
    _uncheckedValue = getValueAsObject(_itemProperties.getDataTypeClass(), uncheckedValue);
    _otherValueMappingValue = !EJRWTCheckBoxRendererDefinitionProperties.UNCHECKED.equals(otherValueMapping);
    _defaultValue = _itemProperties.getItemRendererProperties().getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.DEFAULT_VALUE);
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) EJMessage(org.entirej.framework.core.EJMessage)

Example 7 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTTextItemRenderer method setValue.

@Override
public void setValue(Object value) {
    _baseValue = value;
    _valueChanged = false;
    _oldvalue = null;
    try {
        _modifyListener.enable = false;
        if (_displayValueAsLabel) {
            if (controlState(_valueLabel)) {
                if (value == null) {
                    _valueLabel.setText("");
                    _valueLabel.setToolTipText("");
                } else {
                    _valueLabel.setText(toCaseValue(value.toString()));
                    _valueLabel.setToolTipText(value.toString());
                }
            }
        } else {
            if (controlState(_textField)) {
                if (value != null) {
                    if (_maxLength > 0 && value.toString().length() > _maxLength) {
                        EJMessage message = new EJMessage("The value for item, " + _item.getReferencedItemProperties().getBlockName() + "." + _item.getReferencedItemProperties().getName() + " is too long for its field definition.");
                        throw new EJApplicationException(message);
                    }
                }
                _textField.setText(value == null ? "" : toCaseValue(value.toString()));
                setMandatoryBorder(_mandatory);
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) EJMessage(org.entirej.framework.core.EJMessage)

Example 8 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTDefaultMenuBuilder method createApplicationMenu.

public static void createApplicationMenu(EJApplicationManager applicationManager, Shell shell, EJRWTMenuTreeRoot root) {
    EJMenuActionProcessor actionProcessor = null;
    if (root.getActionProcessorClassName() != null && root.getActionProcessorClassName().length() > 0) {
        try {
            Class<?> processorClass = Class.forName(root.getActionProcessorClassName());
            try {
                Object processorObject = processorClass.newInstance();
                if (processorObject instanceof EJMenuActionProcessor) {
                    actionProcessor = (EJMenuActionProcessor) processorObject;
                } else {
                    throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_NAME, processorClass.getName(), "EJMenuActionProcessor"));
                }
            } catch (InstantiationException e) {
                throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
            } catch (IllegalAccessException e) {
                throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
            }
        } catch (ClassNotFoundException e) {
            throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_FOR_MENU, root.getActionProcessorClassName()));
        }
    }
    Menu appMenuBar = shell.getDisplay().getMenuBar();
    if (appMenuBar == null) {
        appMenuBar = new Menu(shell, SWT.BAR);
        shell.setMenuBar(appMenuBar);
    }
    createMenu(applicationManager, appMenuBar, root, actionProcessor);
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) Menu(org.eclipse.swt.widgets.Menu) EJMenuActionProcessor(org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor)

Example 9 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTUpdateScreenRenderer method setupUpdateScreen.

private void setupUpdateScreen() {
    // Setup pane for query window
    EJFrameworkExtensionProperties rendererProperties = _block.getProperties().getUpdateScreenRendererProperties();
    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 updateButtonLabel = 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;
    _updateDialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        @Override
        public void createBody(Composite parent) {
            EJ_RWT.setTestId(parent, _block.getProperties().getName() + ".update-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.UPDATE), _mainPane, EJScreenType.UPDATE);
            scrollComposite.setContent(_mainPane);
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            // remove the offset
            scrollComposite.setMinSize(width, height - 10);
            _block.addItemValueChangedListener(EJRWTUpdateScreenRenderer.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 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, UPDATE_OK_ACTION_COMMAND, updateButtonLabel == null ? "Update" : updateButtonLabel, true), _block.getProperties().getName() + ".ok");
            EJ_RWT.setTestId(createButton(parent, UPDATE_CANCEL_ACTION_COMMAND, cancelButtonLabel == null ? "Cancel" : cancelButtonLabel, false), _block.getProperties().getName() + ".cancel");
        }

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

        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(EJRWTUpdateScreenRenderer.this);
            _block.setRendererFocus(true);
            return super.close();
        }

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

        @Override
        protected void buttonPressed(int buttonId) {
            Display.getDefault().asyncExec(() -> {
                try {
                    switch(buttonId) {
                        case UPDATE_OK_ACTION_COMMAND:
                            {
                                try {
                                    _block.getBlock().updateRecord(_itemRegister.getRegisteredRecord());
                                    if (_block.getUpdateScreenDisplayProperties().getBooleanProperty(EJRWTScreenRendererDefinitionProperties.SAVE_FORM_AFTER_EXECUTE, false)) {
                                        _block.getBlock().getForm().saveChanges();
                                    }
                                } catch (EJApplicationException e) {
                                    setButtonEnable(buttonId, false);
                                    throw e;
                                }
                                close();
                                break;
                            }
                        case UPDATE_CANCEL_ACTION_COMMAND:
                            {
                                _block.updateCancelled();
                                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;
                }
            });
        }
    };
    _updateDialog.create();
    _updateDialog.getShell().setData("UPDATE - " + _block.getProperties().getName());
    _updateDialog.getShell().setText(title != null ? title : "");
    // add dialog border offsets
    _updateDialog.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) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 10 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTFileDownload method download.

public static void download(String sourcePath, String outputName) {
    File file = new File(sourcePath);
    if (!file.exists()) {
        throw new EJApplicationException(String.format("File not found :%s", file.getName()));
    }
    UUID randomUUID = UUID.randomUUID();
    String fileKey = randomUUID.toString();
    keys.put(fileKey, sourcePath);
    StringBuffer url = new StringBuffer();
    url.append(RWT.getServiceManager().getServiceHandlerUrl(SERVICE_HANDLER));
    url.append("&filename=");
    url.append(fileKey);
    url.append("&output=");
    url.append(outputName);
    String encodedURL = RWT.getResponse().encodeURL(url.toString());
    // UrlLauncher urlLauncher =
    // RWT.getClient().getService(UrlLauncher.class);
    // urlLauncher.openURL(encodedURL);
    JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
    javaScriptExecutor.execute(String.format("window.location = '%s'", encodedURL));
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) EJApplicationException(org.entirej.framework.core.EJApplicationException) UUID(java.util.UUID) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

EJApplicationException (org.entirej.framework.core.EJApplicationException)18 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)6 Composite (org.eclipse.swt.widgets.Composite)6 EJRWTScrolledComposite (org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite)6 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)5 EJMessage (org.entirej.framework.core.EJMessage)5 Collection (java.util.Collection)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)4 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)4 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)4 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)4 Button (org.eclipse.swt.widgets.Button)3 EJRWTAbstractDialog (org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog)3 EJRWTItemTextChangeNotifier (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier)3 ChangeListener (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener)3 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Control (org.eclipse.swt.widgets.Control)2