use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset.AssetWorkbenchListener in project mdw-designer by CenturyLinkCloud.
the class WorkflowElementActionHandler method getOpenAssetEditors.
public List<IEditorPart> getOpenAssetEditors(WorkflowProject project) {
List<IEditorPart> editors = new ArrayList<IEditorPart>();
Map<IFile, AssetWorkbenchListener> assetListeners = WorkflowAssetFactory.getWorkbenchListeners();
for (IEditorReference edRef : getPage().getEditorReferences()) {
IEditorPart edPart = edRef.getEditor(false);
if (assetListeners != null && edPart.getEditorInput() instanceof FileEditorInput) {
// find open workflow asset editors
FileEditorInput fileInput = (FileEditorInput) edPart.getEditorInput();
AssetWorkbenchListener wbListener = assetListeners.get(fileInput.getFile());
if (wbListener != null) {
WorkflowAsset asset = wbListener.getAsset();
if (asset.getProject().equals(project))
editors.add(edPart);
}
}
}
return editors;
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset.AssetWorkbenchListener in project mdw-designer by CenturyLinkCloud.
the class WorkflowElementActionHandler method syncOpenEditors.
public void syncOpenEditors(final WorkflowProject project) {
final WorkflowProjectManager projectMgr = WorkflowProjectManager.getInstance();
final List<ProcessEditor> processEditors = getOpenProcessEditors(project);
final List<IEditorPart> assetEditors = getOpenAssetEditors(project);
if (!processEditors.isEmpty() || !assetEditors.isEmpty()) {
// sync open editors
IRunnableWithProgress loader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Loading " + project.getLabel(), 100);
monitor.worked(25);
// sync process editors
for (ProcessEditor ed : processEditors) {
WorkflowProcess pv = ed.getProcess();
pv.setProject(projectMgr.getWorkflowProject(pv.getProject().getName()));
if (pv.getPackage() != null && !pv.getPackage().isDefaultPackage()) {
WorkflowPackage pkg = pv.getProject().getPackage(pv.getPackage().getName());
WorkflowProcess oldPv = pkg.getProcess(pv.getName());
if (oldPv != null)
pkg.removeProcess(oldPv);
pkg.addProcess(pv);
pv.setPackage(pkg);
}
}
monitor.worked(50);
// sync asset editors
Map<IFile, AssetWorkbenchListener> assetListeners = WorkflowAssetFactory.getWorkbenchListeners();
for (IEditorPart assetEd : assetEditors) {
FileEditorInput fileInput = (FileEditorInput) assetEd.getEditorInput();
AssetWorkbenchListener wbListener = assetListeners.get(fileInput.getFile());
if (wbListener != null) {
WorkflowAsset asset = wbListener.getAsset();
WorkflowProject wfProj = projectMgr.getWorkflowProject(asset.getProject().getName());
WorkflowAsset oldAsset = wfProj.getAsset(asset.getName(), asset.getLanguage(), asset.getVersion());
if (asset.getPackage() != null && !asset.getPackage().isDefaultPackage()) {
WorkflowPackage pkg = wfProj.getPackage(asset.getPackage().getName());
if (pkg != null) {
pkg.removeAsset(oldAsset);
pkg.addAsset(asset);
asset.setPackage(pkg);
} else {
asset.setPackage(wfProj.getDefaultPackage());
}
} else {
asset.setPackage(wfProj.getDefaultPackage());
}
asset.addElementChangeListener(wfProj);
if (oldAsset != null)
WorkflowAssetFactory.deRegisterAsset(oldAsset);
WorkflowAssetFactory.registerAsset(asset);
assetEd.addPropertyListener(asset.new AssetEditorPropertyListener(assetEd));
WorkflowAssetFactory.registerWorkbenchListener(fileInput.getFile(), wbListener);
}
}
monitor.worked(25);
monitor.done();
}
};
ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
try {
progMonDlg.run(true, false, loader);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Sync Open Editors", project);
}
}
}
Aggregations