use of com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog 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.plugin.designer.dialogs.VersionableSaveDialog in project mdw-designer by CenturyLinkCloud.
the class WorkflowAsset method resourceChanged.
/**
* Change listener so we'll know when the resource is changed in the
* workspace.
*/
public void resourceChanged(IResourceChangeEvent event) {
if (isForceExternalEditor())
return;
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
final IFile file = getAssetFile();
IResourceDelta rootDelta = event.getDelta();
IResourceDelta assetDelta = rootDelta.findMember(file.getFullPath());
if (assetDelta != null && assetDelta.getKind() == IResourceDelta.CHANGED && (assetDelta.getFlags() & IResourceDelta.CONTENT) != 0) {
// the file has been changed
final Display display = Display.getCurrent();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
if (isRawEdit()) {
if (getProject().isReadOnly())
MessageDialog.openWarning(display.getActiveShell(), "Not Editable", "Your changes to " + getFile().getName() + " will be overwritten the next time project '" + getProject().getLabel() + "' is refreshed.");
} else {
if (!isUserAuthorized(UserRoleVO.ASSET_DESIGN)) {
MessageDialog.openWarning(display.getActiveShell(), "Can't Update " + getTitle(), "You're not authorized to update '" + getLabel() + "'\nin workflow project '" + getProject().getName() + "'.");
return;
} else if (!isLockedToUser()) {
MessageDialog.openWarning(display.getActiveShell(), "Can't Update " + getTitle(), "Resource '" + getLabel() + "' is not locked by you, so updates are not allowed.");
return;
}
}
if (isBinary())
encodeAndSetContent(PluginUtil.readFile(file));
else
setContent(new String(PluginUtil.readFile(file)));
Increment versionIncrement = Increment.Overwrite;
int previousVersion = getVersion();
String versionComment = null;
if (getProject().checkRequiredVersion(5, 0)) {
VersionableSaveDialog saveDialog = new VersionableSaveDialog(display.getActiveShell(), WorkflowAsset.this);
int res = saveDialog.open();
if (res == VersionableSaveDialog.CANCEL) {
if (isRawEdit()) {
String message = "Version for '" + WorkflowAsset.this.getName() + "' remains " + WorkflowAsset.this.getVersionLabel();
MessageDialog.openInformation(display.getActiveShell(), WorkflowAsset.this.getTitle() + " Overwrite", message);
return;
} else {
String message = "Database save for '" + WorkflowAsset.this.getName() + "' was canceled.\nTemp file changes were not persisted.";
MessageDialog.openWarning(display.getActiveShell(), WorkflowAsset.this.getTitle() + " Not Saved", message);
return;
}
}
versionIncrement = saveDialog.getVersionIncrement();
if (versionIncrement != Increment.Overwrite) {
setVersion(versionIncrement == Increment.Major ? getNextMajorVersion() : getNextMinorVersion());
versionComment = saveDialog.getVersionComment();
}
}
if (isRawEdit()) {
if (versionIncrement == Increment.Overwrite) {
// just fire cache refresh
if (!getProject().isRemote())
getProject().getDesignerProxy().getCacheRefresh().fireRefresh(RuleSetVO.JAVA.equals(getLanguage()));
} else {
setRevisionComment(versionComment);
getProject().getDesignerProxy().saveWorkflowAssetWithProgress(WorkflowAsset.this, false);
fireElementChangeEvent(ChangeType.VERSION_CHANGE, getVersion());
}
} else {
try {
IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
boolean keepLocked = prefsStore.getBoolean(PreferenceConstants.PREFS_KEEP_RESOURCES_LOCKED_WHEN_SAVING);
if (versionIncrement != Increment.Overwrite) {
RuleSetVO prevVO = new RuleSetVO(WorkflowAsset.this.getRuleSetVO());
prevVO.setId(getId());
prevVO.setVersion(previousVersion);
setComment(versionComment);
if (!isInDefaultPackage()) {
getPackage().removeAsset(WorkflowAsset.this);
getProject().getUnpackagedWorkflowAssets().add(new WorkflowAsset(prevVO, getProject().getDefaultPackage()));
}
RunnerResult result = getProject().getDesignerProxy().createNewWorkflowAsset(WorkflowAsset.this, keepLocked);
if (result.getStatus() == RunnerStatus.SUCCESS) {
getRuleSetVO().setPrevVersion(prevVO);
fireElementChangeEvent(ChangeType.VERSION_CHANGE, getVersion());
} else if (result.getStatus() == RunnerStatus.DISALLOW) {
// deregister since save never
// happened
WorkflowAssetFactory.deRegisterAsset(WorkflowAsset.this);
}
} else {
getProject().getDesignerProxy().saveWorkflowAssetWithProgress(WorkflowAsset.this, keepLocked);
fireElementChangeEvent(ChangeType.SETTINGS_CHANGE, null);
}
if (!keepLocked)
fireElementChangeEvent(ChangeType.PROPERTIES_CHANGE, null);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Save Definition Doc", getProject());
}
}
}
});
}
}
}
}
Aggregations