Search in sources :

Example 1 with EditorSelectedListener

use of org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener in project Activiti by Activiti.

the class EditModelClickListener method showSelectEditorPopupWindow.

protected void showSelectEditorPopupWindow() {
    final PopupWindow selectEditorPopupWindow = new PopupWindow();
    selectEditorPopupWindow.setModal(true);
    selectEditorPopupWindow.setResizable(false);
    selectEditorPopupWindow.setWidth("350px");
    selectEditorPopupWindow.setHeight("250px");
    selectEditorPopupWindow.addStyleName(Reindeer.PANEL_LIGHT);
    selectEditorPopupWindow.center();
    final SelectEditorComponent selectEditorComponent = new SelectEditorComponent(false);
    selectEditorComponent.getModelerDescriptionLabel().setValue(ExplorerApp.get().getI18nManager().getMessage(Messages.PROCESS_EDITOR_CONVERSION_WARNING_MODELER));
    selectEditorComponent.getModelerDescriptionLabel().addStyleName(ExplorerLayout.STYLE_LABEL_RED);
    selectEditorComponent.preferTableDrivenEditor();
    selectEditorPopupWindow.getContent().addComponent(selectEditorComponent);
    selectEditorComponent.setEditorSelectedListener(new EditorSelectedListener() {

        public void editorSelectionChanged() {
            try {
                WorkflowDefinition workflowDefinition = loadWorkflowDefinition();
                // When using the modeler, the format must first be converted to the modeler json format
                if (selectEditorComponent.isModelerPreferred()) {
                    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
                    conversion.convert();
                    RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
                    model.setCategory(null);
                    ObjectMapper objectMapper = new ObjectMapper();
                    ObjectNode metaInfoJson = objectMapper.createObjectNode();
                    metaInfoJson.put("name", model.getName());
                    model.setMetaInfo(metaInfoJson.toString());
                    repositoryService.saveModel(model);
                    BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
                    ObjectNode json = bpmnJsonConverter.convertToJson(conversion.getBpmnModel());
                    repositoryService.addModelEditorSource(model.getId(), json.toString().getBytes("utf-8"));
                    // Show modeler
                    showModeler();
                } else {
                    // Load and show table editor
                    ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(model.getId(), workflowDefinition);
                }
            } catch (Exception e) {
                LOGGER.error("Error showing editor", e);
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_EDITOR_LOADING_ERROR, e);
            } finally {
                ExplorerApp.get().getMainWindow().removeWindow(selectEditorPopupWindow);
            }
        }
    });
    ExplorerApp.get().getViewManager().showPopupWindow(selectEditorPopupWindow);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PopupWindow(org.activiti.explorer.ui.custom.PopupWindow) SelectEditorComponent(org.activiti.editor.ui.SelectEditorComponent) EditorSelectedListener(org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)1 SelectEditorComponent (org.activiti.editor.ui.SelectEditorComponent)1 EditorSelectedListener (org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener)1 RepositoryService (org.activiti.engine.RepositoryService)1 PopupWindow (org.activiti.explorer.ui.custom.PopupWindow)1 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)1 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)1