use of com.centurylink.mdw.plugin.designer.model.DocumentTemplate in project mdw-designer by CenturyLinkCloud.
the class WorkflowAssetWizard method performFinish.
@Override
public boolean performFinish() {
if (!workflowAsset.getProject().checkRequiredVersion(5, 0))
workflowAsset.setPackage(workflowAsset.getProject().getDefaultPackage());
if (isImportFile()) {
try {
// load from selected file
File file = new File(importFilePath);
byte[] fileBytes = PluginUtil.readFile(file);
if (workflowAsset.isBinary())
workflowAsset.encodeAndSetContent(fileBytes);
else
workflowAsset.setContent(new String(fileBytes));
} catch (IOException ex) {
PluginMessages.uiError(getShell(), ex, "Create " + workflowAsset.getTitle(), workflowAsset.getProject());
}
} else {
try {
DocumentTemplate docTemplate = getNewDocTemplate();
if (docTemplate != null) {
byte[] templateContents = docTemplate.getContent();
if (workflowAsset.isBinary())
workflowAsset.encodeAndSetContent(templateContents);
else if (workflowAsset.getLanguage().equals(RuleSetVO.FACELET) || workflowAsset.getLanguage().equals(RuleSetVO.HTML))
workflowAsset.setContent(new String(templateContents));
else
workflowAsset.substituteAndSetContent(new String(templateContents));
}
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Create " + workflowAsset.getTitle(), workflowAsset.getProject());
}
}
DesignerProxy designerProxy = workflowAsset.getProject().getDesignerProxy();
try {
designerProxy.createNewWorkflowAsset(workflowAsset, true);
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "New " + workflowAsset.getTitle(), workflowAsset.getProject());
return false;
}
if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
if (!workflowAsset.isBinary() || getNewDocTemplate() != null)
workflowAsset.openFile(new NullProgressMonitor());
workflowAsset.addElementChangeListener(workflowAsset.getProject());
workflowAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, workflowAsset);
WorkflowAssetFactory.registerAsset(workflowAsset);
DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), workflowAsset);
return true;
} else {
return false;
}
}
Aggregations