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);
}
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;
}
}
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;
}
}
Aggregations