use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.
the class SetupProcessDependenciesRoutinesAction method doRun.
@Override
protected void doRun() {
ISelection selection = getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj == null) {
return;
}
RepositoryNode node = (RepositoryNode) obj;
boolean readonly = false;
IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
ERepositoryStatus status = repFactory.getStatus(node.getObject());
if (!repFactory.isPotentiallyEditable(node.getObject()) || status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
readonly = true;
}
Item item = node.getObject().getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
ProcessType process = processItem.getProcess();
SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
if (dialog.open() == Window.OK && !readonly) {
process.getParameters().getRoutinesParameter().clear();
createRoutinesDependencies(process, dialog.getSystemRoutines());
createRoutinesDependencies(process, dialog.getUserRoutines());
try {
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(processItem);
RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobProcessItem = (JobletProcessItem) item;
ProcessType process = jobProcessItem.getJobletProcess();
SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
if (dialog.open() == Window.OK && !readonly) {
process.getParameters().getRoutinesParameter().clear();
createRoutinesDependencies(process, dialog.getSystemRoutines());
createRoutinesDependencies(process, dialog.getUserRoutines());
try {
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(jobProcessItem);
IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (jobletService != null) {
jobletService.loadComponentsFromProviders();
}
RelationshipItemBuilder.getInstance().addOrUpdateItem(jobProcessItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.
the class JobletUtil method needReadOnlyJoblet.
public boolean needReadOnlyJoblet(JobletProcessItem jobletItem) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart[] editors = page.getEditors();
for (IEditorPart editor : editors) {
if (editor instanceof AbstractMultiPageTalendEditor) {
List<? extends INode> nodeList = ((AbstractMultiPageTalendEditor) editor).getProcess().getGraphicalNodes();
for (INode node : nodeList) {
if (((Node) node).isJoblet() && jobletItem.getProperty() != null) {
if (jobletItem.getProperty().getId().equals(node.getComponent().getProcess().getId())) {
boolean haveLock = jobletItem.getState().isLocked();
boolean isSvn = false;
ISVNProviderService service = null;
if (PluginChecker.isSVNProviderPluginLoaded()) {
service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
}
if (service != null && service.isProjectInSvnMode()) {
isSvn = service.isProjectInSvnMode();
}
if (isSvn) {
IProxyRepositoryService proxyService = (IProxyRepositoryService) GlobalServiceRegister.getDefault().getService(IProxyRepositoryService.class);
IProxyRepositoryFactory factory = proxyService.getProxyRepositoryFactory();
ERepositoryStatus repositoryStatus = factory.getStatus(jobletItem);
if (repositoryStatus == ERepositoryStatus.LOCK_BY_USER) {
haveLock = true;
}
}
if (haveLock) {
return true;
}
}
}
}
}
}
return false;
}
use of org.talend.commons.runtime.model.repository.ERepositoryStatus 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.commons.runtime.model.repository.ERepositoryStatus 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.commons.runtime.model.repository.ERepositoryStatus in project tmdm-studio-se by Talend.
the class RepositoryResourceUtil method isLockedAndEdited.
public static boolean isLockedAndEdited(IRepositoryViewObject viewObj) {
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
ERepositoryStatus status = factory.getStatus(viewObj);
if (status == ERepositoryStatus.LOCK_BY_OTHER) {
return true;
} else if (status == ERepositoryStatus.LOCK_BY_USER) {
IEditorReference openRef = RepositoryResourceUtil.isOpenedInEditor(viewObj);
return openRef != null;
}
return false;
}
Aggregations