use of com.centurylink.mdw.plugin.workspace.TempFileRemover in project mdw-designer by CenturyLinkCloud.
the class ArtifactEditor method openTempFile.
public void openTempFile(IProgressMonitor monitor) {
tempFileEditor = null;
try {
IFolder folder = getTempFolder();
if (!folder.exists())
PluginUtil.createFoldersAsNeeded(getElement().getProject().getSourceProject(), folder, monitor);
final IFile file = getTempFile(folder);
final IWorkbenchPage activePage = MdwPlugin.getActivePage();
if (file.exists()) {
IEditorInput editorInput = new FileEditorInput(file);
tempFileEditor = activePage.findEditor(editorInput);
if (tempFileEditor == null) {
// we'll refresh from attribute value
new TempFileRemover(folder, file).remove(monitor);
} else {
// activate existing editor
tempFileEditor = IDE.openEditor(activePage, file, true);
}
}
if (tempFileEditor == null) {
// either the file didn't exist or it was not currently open,
// set from value
byte[] value = valueProvider.getArtifactContent();
if (value == null)
value = "".getBytes();
InputStream source = new ByteArrayInputStream(value);
file.create(source, true, monitor);
if (getElement().isReadOnly()) {
ResourceAttributes resourceAttrs = file.getResourceAttributes();
resourceAttrs.setReadOnly(true);
file.setResourceAttributes(resourceAttrs);
}
final Display display = Display.getCurrent();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
try {
if (!valueProvider.beforeTempFileOpened())
return;
tempFileEditor = IDE.openEditor(activePage, file, true);
if (tempFileEditor != null) {
// listen for artifact made dirty and
// propagate to process canvas
tempFileEditor.addPropertyListener(new IPropertyListener() {
public void propertyChanged(Object source, int propId) {
if (source instanceof EditorPart && propId == IWorkbenchPartConstants.PROP_DIRTY) {
if (((EditorPart) source).isDirty())
// process
fireValueChanged(null, true);
// editor
// should
// show
// dirty
}
}
});
// listen for artifact resource changes
ArtifactResourceListener resourceListener = new ArtifactResourceListener(getElement(), valueProvider, file);
getProject().addArtifactResourceListener(resourceListener);
// listen for workbench closed to prevent
// re-opening editor when the workbench is
// next opened
PlatformUI.getWorkbench().addWorkbenchListener(new ArtifactEditorWorkbenchListener(tempFileEditor));
}
valueProvider.afterTempFileOpened(tempFileEditor);
} catch (PartInitException ex) {
PluginMessages.log(ex);
}
}
});
}
// register to listen to process editor events
WorkflowProcess processVersion = null;
if (getElement() instanceof Activity)
processVersion = ((Activity) getElement()).getProcess();
else if (getElement() instanceof WorkflowProcess)
processVersion = (WorkflowProcess) getElement();
if (processVersion != null) {
IEditorPart processEditor = activePage.findEditor(processVersion);
if (processEditor != null && tempFileEditor != null)
((ProcessEditor) processEditor).addActiveScriptEditor(tempFileEditor);
}
}
} catch (Exception ex) {
PluginMessages.uiError(ex, "Open Temp File", getElement().getProject());
}
}
use of com.centurylink.mdw.plugin.workspace.TempFileRemover in project mdw-designer by CenturyLinkCloud.
the class WorkflowAsset method openTempFile.
@SuppressWarnings("restriction")
public void openTempFile(IProgressMonitor monitor) {
assetFileEditor = null;
try {
IFolder folder = getTempFolder();
folder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
if (!folder.exists())
PluginUtil.createFoldersAsNeeded(getProject().getSourceProject(), folder, monitor);
final IFile file = getTempFile(folder);
final IWorkbenchPage activePage = MdwPlugin.getActivePage();
boolean externalEditorAlreadyOpen = false;
if (file.exists()) {
IEditorInput editorInput = new FileEditorInput(file);
assetFileEditor = activePage.findEditor(editorInput);
if (assetFileEditor == null) {
// we'll refresh from saved value
WorkflowAssetFactory.deRegisterWorkbenchListener(file);
try {
new TempFileRemover(folder, file).remove(monitor);
} catch (org.eclipse.core.internal.resources.ResourceException ex) {
if (isForceExternalEditor()) {
// assume this is because the temp file is already
// open in an external editor; reactivate
PluginMessages.log(ex);
externalEditorAlreadyOpen = true;
activePage.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
} else {
throw ex;
}
}
} else {
// activate existing editor
assetFileEditor = IDE.openEditor(activePage, file, true);
}
}
if (assetFileEditor == null) {
// set from value
if (!externalEditorAlreadyOpen)
createTempFile(file, monitor);
final Display display = Display.getCurrent();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
try {
beforeFileOpened();
if (isForceExternalEditor())
activePage.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
else
assetFileEditor = IDE.openEditor(activePage, file, true);
if (assetFileEditor != null) {
assetFileEditor.addPropertyListener(new AssetEditorPropertyListener(assetFileEditor));
WorkflowAssetFactory.registerWorkbenchListener(file, new AssetWorkbenchListener(assetFileEditor));
}
afterFileOpened(assetFileEditor);
} catch (PartInitException ex) {
PluginMessages.log(ex);
}
}
});
}
}
} catch (Exception ex) {
PluginMessages.uiError(ex, "Open Temp File", getProject());
}
}
use of com.centurylink.mdw.plugin.workspace.TempFileRemover in project mdw-designer by CenturyLinkCloud.
the class ProjectConfigurator method loadJavaLibraries.
public void loadJavaLibraries(IProgressMonitor monitor) {
// locally save all the Java libraries
for (WorkflowAsset asset : project.getTopLevelWorkflowAssets()) {
if (asset instanceof JavaSource) {
if (!asset.isLoaded())
asset.load();
try {
IFolder folder = asset.getTempFolder();
if (!folder.exists())
PluginUtil.createFoldersAsNeeded(project.getSourceProject(), folder, monitor);
IFile tempFile = asset.getTempFile(folder);
if (tempFile.exists())
new TempFileRemover(folder, tempFile).remove(monitor);
tempFile.create(new ByteArrayInputStream(asset.getFileContent()), true, monitor);
PluginMessages.log("Created Java lib file: " + tempFile.getFullPath().toString());
} catch (CoreException ex) {
PluginMessages.uiError(ex, "Load Java Libraries", project);
}
}
}
}
use of com.centurylink.mdw.plugin.workspace.TempFileRemover in project mdw-designer by CenturyLinkCloud.
the class ProjectConfigurator method loadGroovyScriptLibraries.
public void loadGroovyScriptLibraries(IProgressMonitor monitor) {
// locally save all the groovy libraries
for (WorkflowAsset asset : project.getTopLevelWorkflowAssets()) {
if (asset instanceof Script && ((Script) asset).isGroovy()) {
if (!asset.isLoaded())
asset.load();
try {
IFolder folder = asset.getTempFolder();
if (!folder.exists())
PluginUtil.createFoldersAsNeeded(project.getSourceProject(), folder, monitor);
IFile tempFile = asset.getTempFile(folder);
if (tempFile.exists())
new TempFileRemover(folder, tempFile).remove(monitor);
tempFile.create(new ByteArrayInputStream(asset.getFileContent()), true, monitor);
PluginMessages.log("Created groovy lib file: " + tempFile.getFullPath().toString());
} catch (CoreException ex) {
PluginMessages.uiError(ex, "Load Groovy Libraries", project);
}
}
}
}
Aggregations