Search in sources :

Example 1 with UserError

use of com.vaadin.terminal.UserError in project Activiti by Activiti.

the class CopyModelPopupWindow method addButtons.

protected void addButtons() {
    // Cancel
    Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL));
    cancelButton.addStyleName(Reindeer.BUTTON_SMALL);
    cancelButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            close();
        }
    });
    // Create
    Button createButton = new Button(i18nManager.getMessage(Messages.PROCESS_NEW_POPUP_CREATE_BUTTON));
    createButton.addStyleName(Reindeer.BUTTON_SMALL);
    createButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            if (StringUtils.isEmpty((String) nameTextField.getValue())) {
                form.setComponentError(new UserError("The name field is required."));
                return;
            }
            Model newModelData = repositoryService.newModel();
            ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
            modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
            String description = null;
            if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
                description = (String) descriptionTextArea.getValue();
            } else {
                description = "";
            }
            modelObjectNode.put(MODEL_DESCRIPTION, description);
            newModelData.setMetaInfo(modelObjectNode.toString());
            newModelData.setName((String) nameTextField.getValue());
            repositoryService.saveModel(newModelData);
            repositoryService.addModelEditorSource(newModelData.getId(), repositoryService.getModelEditorSource(modelData.getId()));
            repositoryService.addModelEditorSourceExtra(newModelData.getId(), repositoryService.getModelEditorSourceExtra(modelData.getId()));
            close();
            ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(newModelData.getId());
        }
    });
    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(createButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}
Also used : UserError(com.vaadin.terminal.UserError) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) Model(org.activiti.engine.repository.Model) ClickListener(com.vaadin.ui.Button.ClickListener) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 2 with UserError

use of com.vaadin.terminal.UserError in project Activiti by Activiti.

the class NewModelPopupWindow method addButtons.

protected void addButtons() {
    // Create
    Button createButton = new Button(i18nManager.getMessage(Messages.PROCESS_NEW_POPUP_CREATE_BUTTON));
    createButton.setWidth("200px");
    createButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            if (StringUtils.isEmpty((String) nameTextField.getValue())) {
                nameTextField.setComponentError(new UserError("The name field is required."));
                return;
            }
            if (selectEditorComponent.isModelerPreferred()) {
                try {
                    ObjectMapper objectMapper = new ObjectMapper();
                    ObjectNode editorNode = objectMapper.createObjectNode();
                    editorNode.put("id", "canvas");
                    editorNode.put("resourceId", "canvas");
                    ObjectNode stencilSetNode = objectMapper.createObjectNode();
                    stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
                    editorNode.put("stencilset", stencilSetNode);
                    Model modelData = repositoryService.newModel();
                    ObjectNode modelObjectNode = objectMapper.createObjectNode();
                    modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
                    modelObjectNode.put(MODEL_REVISION, 1);
                    String description = null;
                    if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
                        description = (String) descriptionTextArea.getValue();
                    } else {
                        description = "";
                    }
                    modelObjectNode.put(MODEL_DESCRIPTION, description);
                    modelData.setMetaInfo(modelObjectNode.toString());
                    modelData.setName((String) nameTextField.getValue());
                    repositoryService.saveModel(modelData);
                    repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
                    close();
                    ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "modeler.html?modelId=" + modelData.getId());
                    ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
                } catch (Exception e) {
                    notificationManager.showErrorNotification("error", e);
                }
            } else {
                close();
                ExplorerApp.get().getViewManager().showSimpleTableProcessEditor((String) nameTextField.getValue(), (String) descriptionTextArea.getValue());
            }
        }
    });
    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);
}
Also used : UserError(com.vaadin.terminal.UserError) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ClickEvent(com.vaadin.ui.Button.ClickEvent) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Button(com.vaadin.ui.Button) Model(org.activiti.engine.repository.Model) ClickListener(com.vaadin.ui.Button.ClickListener) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 UserError (com.vaadin.terminal.UserError)2 Button (com.vaadin.ui.Button)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 ClickListener (com.vaadin.ui.Button.ClickListener)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Model (org.activiti.engine.repository.Model)2 ExternalResource (com.vaadin.terminal.ExternalResource)1 URL (java.net.URL)1