use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class OpenExistVersionProcessWizard method performFinish.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
if (mainPage.isCreateNewVersionJob()) {
try {
ProxyRepositoryFactory.getInstance().updateLockStatus();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
ERepositoryStatus repositoryStatus = ProxyRepositoryFactory.getInstance().getStatus(processObject);
if ((repositoryStatus.equals(ERepositoryStatus.READ_ONLY)) || repositoryStatus == ERepositoryStatus.LOCK_BY_OTHER || repositoryStatus.equals(ERepositoryStatus.LOCK_BY_USER)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(getShell(), "Warning", Messages.getString("OpenExistVersionProcessWizard.labelContent"));
}
});
return false;
} else {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
if (!alreadyEditedByUser) {
refreshNewJob();
RelationshipItemBuilder.getInstance().addOrUpdateItem(processObject.getProperty().getItem());
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
try {
Item newCreated = null;
if (processObject.getProperty() != null && processObject.getProperty().getItem() != null) {
newCreated = processObject.getProperty().getItem();
}
if (!(newCreated instanceof BusinessProcessItem)) {
ProxyRepositoryFactory.getInstance().lock(processObject);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (LoginException e) {
ExceptionHandler.process(e);
}
boolean locked = processObject.getRepositoryStatus().equals(ERepositoryStatus.LOCK_BY_USER);
openAnotherVersion((RepositoryNode) processObject.getRepositoryNode(), !locked);
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace
// runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e);
}
}
} else {
StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
RepositoryNode node = (RepositoryNode) selection.getFirstElement();
boolean lastVersion = node.getObject().getVersion().equals(processObject.getVersion());
// processObject.getProperty().setVersion(originalVersion);
if (lastVersion) {
lockObject(processObject);
}
ERepositoryStatus status = node.getObject().getRepositoryStatus();
boolean isLocked = false;
if (status == ERepositoryStatus.LOCK_BY_USER) {
isLocked = true;
}
// Only latest version can be editted
openAnotherVersion(node, !lastVersion || !isLocked);
}
return true;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class SaveAsProcessWizard method update.
private void update(final ProcessType processType) {
RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>("Save job") {
@Override
protected void run() throws LoginException, PersistenceException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
try {
oldProcessItem.setProcess(processType);
assginValues(oldProperty, property);
RelationshipItemBuilder.getInstance().addOrUpdateItem(oldProcessItem);
repositoryFactory.save(oldProcessItem);
// assign value
processItem = oldProcessItem;
} catch (PersistenceException pe) {
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "persistance error", //$NON-NLS-1$
pe));
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e.getCause());
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.setAvoidSvnUpdate(true);
repositoryFactory.executeRepositoryWorkUnit(rwu);
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method loadEmfPersistentData.
private static List<JetBean> loadEmfPersistentData(List<LightJetBean> datas, List<JetBean> completeJetBeanList, IProgressMonitor monitorWrap) throws BusinessException {
List<JetBean> toReturn = new ArrayList<JetBean>();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
//$NON-NLS-1$
IProject project = workspace.getRoot().getProject(".JETEmitters");
URL url = null;
try {
IFile file = project.getFile(Path.fromOSString("runtime"));
url = file.getLocationURI().toURL();
int lightBeanIndex = 0;
LightJetBean lightBean = null;
LightJetBean myLightJetBean = null;
//$NON-NLS-1$
String unitTemplateFullURI = "";
long unitTemplateHashCode = 0;
HashMap<String, LightJetBean> mapOnName = new HashMap<String, LightJetBean>();
boolean forceMethodLoad = ComponentCompilations.getMarkers();
if (forceMethodLoad) {
// init specific map based on component name : mapOnName
for (LightJetBean ljb : datas) {
//$NON-NLS-1$
mapOnName.put(ljb.getTemplateRelativeUri().substring(ljb.getTemplateRelativeUri().lastIndexOf("/")), ljb);
}
}
int monitorBuffer = 0;
for (JetBean unit : completeJetBeanList) {
monitorBuffer++;
if (monitorBuffer % 200 == 0) {
monitorWrap.worked(200);
monitorBuffer = 0;
}
unitTemplateFullURI = unit.getTemplateRelativeUri();
unitTemplateHashCode = unit.getCrc();
myLightJetBean = new LightJetBean(unitTemplateFullURI, unit.getVersion(), unitTemplateHashCode);
if (((lightBeanIndex = datas.indexOf(myLightJetBean)) > -1) || forceMethodLoad) {
if (!forceMethodLoad) {
lightBean = datas.get(lightBeanIndex);
} else {
lightBean = mapOnName.get(myLightJetBean.getTemplateRelativeUri().substring(//$NON-NLS-1$
myLightJetBean.getTemplateRelativeUri().lastIndexOf("/")));
}
if (lightBean != null && lightBean.getCrc() == unit.getCrc()) {
unit.setClassName(lightBean.getClassName());
unit.setMethodName(lightBean.getMethodName());
toReturn.add(unit);
}
}
}
monitorWrap.worked(monitorBuffer);
} catch (MalformedURLException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.JETEmitters.NoPresent"));
throw new BusinessException(e);
}
return toReturn;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class TalendJetEmitter method loadMethod.
/**
* DOC mhirt Comment method "loadMethod".
*
* @param methodName
* @return
* @throws MalformedURLException
* @throws ClassNotFoundException
*/
private Method loadMethod() throws ClassNotFoundException, MalformedURLException {
if (jetbean == null) {
return null;
}
if (currentClassLoader != jetbean.getClassLoader()) {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
//$NON-NLS-1$
URL url = new File(project.getLocation() + "/runtime").toURL();
currentClassLoader = jetbean.getClassLoader();
theClassLoader = new URLClassLoader(new URL[] { url }, jetbean.getClassLoader());
}
Class theClass;
try {
theClass = theClassLoader.loadClass(jetbean.getClassName());
} catch (Error e) {
throw new ClassNotFoundException(e.getMessage(), e);
}
// TDI-23079
try {
Method[] methods = theClass.getDeclaredMethods();
for (Method method2 : methods) {
if (method2.getName().equals(jetbean.getMethodName())) {
return method2;
}
}
} catch (Exception e) {
return null;
}
return null;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class GenericConnWizard method createOrUpdateConnectionItem.
private void createOrUpdateConnectionItem() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
Form form = wizPage.getForm();
if (form.isCallAfterFormFinish()) {
if (creation) {
factory.create(connectionItem, pathToSave);
}
compService.afterFormFinish(form.getName(), form.getProperties());
}
updateConnectionItem(factory);
} catch (Throwable e) {
throw new CoreException(new Status(IStatus.ERROR, IGenericConstants.REPOSITORY_PLUGIN_ID, "Error when saving the connection", e));
}
}
};
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification of changes before the end of the modifications.
workspace.run(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
// Move it from WorkspaceRunnable to avoid the conflicting rules with other jobs.
if (!creation) {
GenericUpdateManager.updateGenericConnection(connectionItem, oldMetadataTable);
}
}
Aggregations