use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.
the class BusinessDiagramEditor method doSave.
@Override
public void doSave(IProgressMonitor progressMonitor) {
if (repositoryEditorInput != null) {
final BusinessProcessItem businessProcessItem = (BusinessProcessItem) repositoryEditorInput.getItem();
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.updateLockStatus();
// For TDI-23825, if not lock by user try to lock again.
boolean locked = repFactory.getStatus(businessProcessItem) == ERepositoryStatus.LOCK_BY_USER;
if (!locked) {
repFactory.lock(businessProcessItem);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(businessProcessItem);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("BusinessDiagramEditor.canNotSaveTitle"), //$NON-NLS-1$
Messages.getString("BusinessDiagramEditor.canNotSaveMessage"));
return;
}
super.doSave(progressMonitor);
DiagramResourceManager diagramResourceManager = new DiagramResourceManager();
diagramResourceManager.updateFromResource(businessProcessItem, repositoryEditorInput.getFile());
final IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
RepositoryWorkUnit rwu = new RepositoryWorkUnit("save Business") {
@Override
protected void run() throws LoginException, PersistenceException {
ProxyRepositoryFactory.getInstance().save(businessProcessItem);
}
};
rwu.setAvoidUnloadResources(true);
rwu.setAvoidSvnUpdate(true);
factory.executeRepositoryWorkUnit(rwu);
propertyIsDirty = false;
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.
the class ProjectSettingsPreferenceDialog method commiteProjectSettings.
private void commiteProjectSettings() {
// excute a workUnit to do svn commite
RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
RepositoryWorkUnit(//$NON-NLS-1$
ProjectManager.getInstance().getCurrentProject(), //$NON-NLS-1$
"") {
@Override
public void run() throws PersistenceException {
// do nothing
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
}
use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method doSave.
@Override
public void doSave(final IProgressMonitor monitor) {
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.lock(item);
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(item);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
return;
}
EList adapters = item.getProperty().eAdapters();
adapters.remove(dirtyListener);
super.doSave(monitor);
try {
resetItem();
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
runProcessService.buildJavaProject();
// check syntax error
addProblems();
//$NON-NLS-1$
String name = "Save Routine";
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {
@Override
protected void run() throws LoginException, PersistenceException {
refreshJobAndSave(repFactory);
}
};
repositoryWorkUnit.setAvoidSvnUpdate(true);
repositoryWorkUnit.setAvoidUnloadResources(true);
repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
// for bug 11930: Unable to save Routines.* in db project
// repFactory.save(item);
// startRefreshJob(repFactory);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.
the class NodePart method performRequest.
@Override
public void performRequest(Request req) {
Node node = (Node) getModel();
IExternalData oldExternalData = node.getExternalData();
if (req.getType().equals(RequestConstants.REQ_OPEN)) {
IExternalNode externalNode = null;
if (node.isExternalNode()) {
IElementParameter externalParam = node.getElementParameterFromField(EParameterFieldType.EXTERNAL);
if (externalParam != null && externalParam.isShow(node.getElementParameters())) {
externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
}
}
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
boolean isOriginalNode = false;
ITestContainerProviderService testContainerService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
isOriginalNode = testContainerService.isOriginalNode(node);
if (isOriginalNode) {
testContainerService.renameConnection(node, true);
}
}
}
int returnValue = externalNode.open(getViewer().getControl().getShell());
if (!node.isReadOnly()) {
if (returnValue == SWT.OK) {
Command cmd = new ExternalNodeChangeCommand(node, externalNode, oldExternalData);
CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
cmdStack.execute(cmd);
} else {
externalNode.setExternalData(oldExternalData);
}
}
if (isOriginalNode && (testContainerService != null)) {
testContainerService.renameConnection(node, false);
}
} else {
// add for feature 13361
boolean isJoblet = false;
if (PluginChecker.isJobLetPluginLoaded()) {
AbstractProcessProvider jobletProcessProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
final IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
boolean isAvoidShowJobletAfterDoubleClick = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
IComponentsLocalProviderService componentService = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
if (componentService != null) {
isAvoidShowJobletAfterDoubleClick = componentService.isAvoidToShowJobletAfterDoubleClick();
}
}
if (service != null && service.isJobletComponent(node) && !isAvoidShowJobletAfterDoubleClick) {
isJoblet = true;
String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
final Item jobletItem = jobletProcessProvider.getJobletItem(node, version);
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
if (jobletItem != null) {
service.openJobletItem((JobletProcessItem) jobletItem);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
}
}
if (!isJoblet) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String processName = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_PROCESS.getName());
String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
boolean isAvoidShowJobAfterDoubleClick = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
if (service != null) {
isAvoidShowJobAfterDoubleClick = service.isAvoidToShowJobAfterDoubleClick();
}
}
// bug 20796
boolean isSelectUseDynamic = false;
Object useDynamicJobValue = node.getPropertyValue(EParameterName.USE_DYNAMIC_JOB.getName());
if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
isSelectUseDynamic = (Boolean) useDynamicJobValue;
}
if (processName != null && !"".equals(processName) && !isAvoidShowJobAfterDoubleClick && !isSelectUseDynamic) {
//$NON-NLS-1$
ItemCacheManager.clearCache();
ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
if (processItem == null) {
return;
}
Property updatedProperty = null;
try {
updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(processItem)), processName).getProperty();
} catch (PersistenceException e) {
CommonExceptionHandler.process(e);
}
// update the property of the node repository object
// node.getObject().setProperty(updatedProperty);
processItem = (ProcessItem) updatedProperty.getItem();
final ProcessItem item = processItem;
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
try {
if (item != null) {
ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
}
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
} else {
try {
// modified for feature 2454.
page.showView(ComponentSettingsView.ID);
} catch (PartInitException e) {
CommonExceptionHandler.process(e);
}
}
}
}
}
super.performRequest(req);
}
use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method updateRunJobContext.
protected void updateRunJobContext() {
final JobContextManager manager = (JobContextManager) getProcess().getContextManager();
if (manager.isModified()) {
final Map<String, String> nameMap = manager.getNameMap();
// gcui:add a progressDialog.
Shell shell = null;
Display display = PlatformUI.getWorkbench().getDisplay();
if (display != null) {
shell = display.getActiveShell();
}
if (shell == null) {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
if (display != null) {
shell = display.getActiveShell();
}
}
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("AbstractMultiPageTalendEditor_pleaseWait"), IProgressMonitor.UNKNOWN);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
factory.executeRepositoryWorkUnit(new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
"..", //$NON-NLS-1$
this) {
@Override
protected void run() throws LoginException, PersistenceException {
try {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
Set<String> curContextVars = getCurrentContextVariables(manager);
IProcess2 process2 = getProcess();
String jobId = process2.getProperty().getId();
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
// gcui:if nameMap is empty it do nothing.
if (!nameMap.isEmpty()) {
UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(factory, nameMap, jobId, curContextVars);
UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, nameMap, jobId, curContextVars);
}
// add for bug 9564
List<IRepositoryViewObject> all = factory.getAll(ERepositoryObjectType.PROCESS, true);
List<ProcessItem> allProcess = new ArrayList<ProcessItem>();
for (IRepositoryViewObject repositoryObject : all) {
Item item = repositoryObject.getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
allProcess.add(processItem);
}
}
UpdateRunJobComponentContextHelper.updateRefJobRunJobComponentContext(factory, allProcess, process2);
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
manager.setModified(false);
}
});
}
});
monitor.done();
if (monitor.isCanceled()) {
try {
//$NON-NLS-1$
throw new InterruptedException("Save Fail");
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
}
};
try {
progressDialog.run(true, true, runnable);
} catch (InvocationTargetException e1) {
ExceptionHandler.process(e1);
} catch (InterruptedException e1) {
ExceptionHandler.process(e1);
}
}
}
Aggregations