Search in sources :

Example 1 with TaskTemplateDocument

use of com.centurylink.mdw.task.TaskTemplateDocument in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    textEditor = new StructuredTextEditor() {

        @Override
        public boolean isEditable() {
            return false;
        }

        @Override
        public boolean isEditorInputModifiable() {
            return false;
        }

        @Override
        public boolean isEditorInputReadOnly() {
            return true;
        }

        @Override
        public boolean isDirty() {
            return false;
        }
    };
    textEditor.setEditorPart(this);
    if (input instanceof FileEditorInput) {
        setInput(input);
        IFile file = ((FileEditorInput) input).getFile();
        WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(file.getProject());
        // force initialization
        project.getDesignerProxy();
        WorkflowPackage pkg = project.getPackage((IFolder) file.getParent());
        taskTemplate = (TaskTemplate) pkg.getTaskTemplate(file);
        // refresh from file system to make sure we're in sync
        try {
            Long taskId = taskTemplate.getId();
            int version = taskTemplate.getVersion();
            file.refreshLocal(IResource.DEPTH_ZERO, null);
            String content = new String(PluginUtil.readFile(file));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.parse(content);
                com.centurylink.mdw.task.TaskTemplate fileTemplate = doc.getTaskTemplate();
                taskVO = new TaskVO(fileTemplate);
            }
            taskTemplate.setTaskVO(taskVO);
            taskVO.setName(file.getName());
            taskVO.setTaskId(taskId);
            taskTemplate.setId(taskId);
            taskTemplate.setVersion(version);
            taskVO.setPackageName(pkg.getName());
        } catch (Exception ex) {
            throw new PartInitException(ex.getMessage(), ex);
        }
    } else {
        throw new PartInitException("Invalid input: " + input);
    }
    selectionProvider = new WorkflowSelectionProvider(taskTemplate);
    site.setSelectionProvider(selectionProvider);
    setPartName(taskTemplate.getName());
    addPageChangedListener(new IPageChangedListener() {

        public void pageChanged(PageChangedEvent event) {
            if (getSelectedPage() == pages.get("Variables")) {
                reconcileVariables();
            }
        }
    });
    partListener = new IPartListener2() {

        public void partOpened(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partActivated(IWorkbenchPartReference partRef) {
            IWorkbenchPart part = partRef.getPart(false);
            if (part == TaskTemplateEditor.this && getSelectedPage() == pages.get("Variables"))
                reconcileVariables();
        }

        public void partBroughtToTop(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partDeactivated(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partClosed(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partVisible(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partHidden(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partInputChanged(IWorkbenchPartReference partRef) {
        // do nothing
        }
    };
    getSite().getPage().addPartListener(partListener);
    workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            return MdwPlugin.getActivePage().closeEditor(TaskTemplateEditor.this, true);
        }

        public void postShutdown(IWorkbench workbench) {
        // do nothing
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) IFile(org.eclipse.core.resources.IFile) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) WorkflowSelectionProvider(com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException) IPartListener2(org.eclipse.ui.IPartListener2) IWorkbench(org.eclipse.ui.IWorkbench) JSONObject(org.json.JSONObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Example 2 with TaskTemplateDocument

use of com.centurylink.mdw.task.TaskTemplateDocument in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method saveDialog.

private int saveDialog(boolean closeButton) {
    VersionableSaveDialog saveDlg = new VersionableSaveDialog(getSite().getShell(), taskTemplate, closeButton);
    int result = saveDlg.open();
    if (result == VersionableSaveDialog.CANCEL)
        return result;
    try {
        if (result == VersionableSaveDialog.CLOSE_WITHOUT_SAVE) {
            // refresh from file
            String content = new String(PluginUtil.readFile(taskTemplate.getFile()));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument docx = TaskTemplateDocument.Factory.parse(content);
                taskVO = new TaskVO(docx.getTaskTemplate());
            }
            taskVO.setName(taskTemplate.getName());
            taskVO.setTaskId(taskTemplate.getId());
            taskVO.setPackageName(taskTemplate.getPackage().getName());
            taskTemplate.setTaskVO(taskVO);
            taskTemplate.setDirty(false);
            return result;
        } else // save the template
        {
            // clean out units attrs
            taskTemplate.removeAttribute("TaskSLA_UNITS");
            taskTemplate.removeAttribute("ALERT_INTERVAL_UNITS");
            Increment versionIncrement = saveDlg.getVersionIncrement();
            String pkgMeta = taskTemplate.getPackage().getMetaContent();
            if (pkgMeta != null && pkgMeta.trim().startsWith("{")) {
                taskTemplate.setContent(taskTemplate.getTaskVO().getJson().toString(2));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.newInstance();
                doc.setTaskTemplate(taskTemplate.getTaskVO().toTemplate());
                XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
                xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
                taskTemplate.setContent(doc.xmlText(xmlOptions));
            }
            taskTemplate.ensureFileWritable();
            InputStream is = new ByteArrayInputStream(taskTemplate.getContent().getBytes());
            taskTemplate.getAssetFile().setContents(is, true, true, new NullProgressMonitor());
            if (versionIncrement != Increment.Overwrite) {
                taskTemplate.setVersion(versionIncrement == Increment.Major ? taskTemplate.getNextMajorVersion() : taskTemplate.getNextMinorVersion());
                taskTemplate.setRevisionComment(saveDlg.getVersionComment());
                taskTemplate.getProject().getDesignerProxy().saveWorkflowAssetWithProgress(taskTemplate, false);
                taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate.getVersion());
            }
            dirtyStateChanged(false);
            if (!taskTemplate.getProject().isRemote())
                taskTemplate.getProject().getDesignerProxy().getCacheRefresh().fireRefresh(false);
            return result;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getSite().getShell(), ex, "Save Task Template", taskTemplate.getProject());
        return VersionableSaveDialog.CANCEL;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionableSaveDialog(com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Increment(com.centurylink.mdw.plugin.designer.model.Versionable.Increment) XmlOptions(org.apache.xmlbeans.XmlOptions) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with TaskTemplateDocument

use of com.centurylink.mdw.task.TaskTemplateDocument in project mdw-designer by CenturyLinkCloud.

the class NewTaskTemplateWizard method performFinish.

@Override
public boolean performFinish() {
    TaskTemplate taskTemplate = (TaskTemplate) getWorkflowAsset();
    try {
        TaskTemplateDocument doc;
        if (isImportFile()) {
            // load from selected file
            doc = TaskTemplateDocument.Factory.parse(new File(getImportFilePath()));
            com.centurylink.mdw.task.TaskTemplate template = doc.getTaskTemplate();
            // selection)
            if (template.getLogicalId() == null)
                throw new XmlException("Task template missing logicalId");
            else if (template.getCategory() == null)
                throw new XmlException("Task template missing category");
            else if (template.getName() == null || template.getName().isEmpty())
                throw new XmlException("Task template missing name");
        } else {
            doc = TaskTemplateDocument.Factory.newInstance();
            com.centurylink.mdw.task.TaskTemplate template = doc.addNewTaskTemplate();
            String taskName = taskTemplate.getName().substring(0, taskTemplate.getName().length() - 5);
            template.setLogicalId(taskName.replace(' ', '_'));
            template.setCategory("GEN");
            template.setName(taskName);
            if ("AUTOFORM".equals(taskTemplate.getLanguage())) {
                Attribute form = template.addNewAttribute();
                form.setName("FormName");
                form.setStringValue("Autoform");
            }
        }
        XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
        xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
        taskTemplate.setContent(doc.xmlText(xmlOptions));
        String templateName = taskTemplate.getName();
        taskTemplate.setTaskVO(new TaskVO(doc.getTaskTemplate()));
        taskTemplate.setName(templateName);
        taskTemplate.getTaskVO().setPackageName(taskTemplate.getPackage().getName());
        DesignerProxy designerProxy = taskTemplate.getProject().getDesignerProxy();
        designerProxy.createNewTaskTemplate(taskTemplate);
        if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
            taskTemplate.openFile(new NullProgressMonitor());
            taskTemplate.addElementChangeListener(taskTemplate.getProject());
            taskTemplate.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, taskTemplate);
            taskTemplate.setVersion(1);
            taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate);
            DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), taskTemplate);
            return true;
        } else {
            return false;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Create " + taskTemplate.getTitle(), taskTemplate.getProject());
        return false;
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) Attribute(com.centurylink.mdw.task.Attribute) XmlOptions(org.apache.xmlbeans.XmlOptions) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) XmlException(org.apache.xmlbeans.XmlException) XmlException(org.apache.xmlbeans.XmlException) File(java.io.File) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Aggregations

TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 TaskTemplateDocument (com.centurylink.mdw.task.TaskTemplateDocument)3 XmlOptions (org.apache.xmlbeans.XmlOptions)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PartInitException (org.eclipse.ui.PartInitException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)1 WorkflowSelectionProvider (com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider)1 VersionableSaveDialog (com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog)1 TaskTemplate (com.centurylink.mdw.plugin.designer.model.TaskTemplate)1 Increment (com.centurylink.mdw.plugin.designer.model.Versionable.Increment)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 Attribute (com.centurylink.mdw.task.Attribute)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 XmlException (org.apache.xmlbeans.XmlException)1 IFile (org.eclipse.core.resources.IFile)1