use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class DeleteAllJobWhenStartUp method earlyStartup.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
@Override
public void earlyStartup() {
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
return;
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
if (!codeProject.exists() || !codeProject.isAccessible()) {
return;
}
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
if (talendJavaProject != null) {
IJavaProject jProject = talendJavaProject.getJavaProject();
if (!jProject.isOpen()) {
jProject.open(monitor);
}
// empty the src/main/java...
IFolder srcFolder = talendJavaProject.getSrcFolder();
talendJavaProject.cleanFolder(monitor, srcFolder);
// contexts
IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
emptyContexts(monitor, resourcesFolder, talendJavaProject);
// empty the outputs, target
IFolder targetFolder = talendJavaProject.getTargetFolder();
talendJavaProject.cleanFolder(monitor, targetFolder);
// empty the src/test/java
IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
talendJavaProject.cleanFolder(monitor, testSrcFolder);
// empty the src/test/java (main for contexts)
IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
talendJavaProject.cleanFolder(monitor, testResourcesFolder);
// empty temp
IFolder tempFolder = talendJavaProject.getTempFolder();
talendJavaProject.cleanFolder(monitor, tempFolder);
// empty lib/...
IFolder libFolder = talendJavaProject.getLibFolder();
talendJavaProject.cleanFolder(monitor, libFolder);
// rules
IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
talendJavaProject.cleanFolder(monitor, rulesResFolder);
// sqltempalte
IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
}
}
;
};
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(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
if (e.getCause() != null) {
ExceptionHandler.process(e.getCause());
} else {
ExceptionHandler.process(e);
}
}
executed = true;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method save.
protected void save() {
List<String> checkedObjects = new ArrayList<String>();
List<IRepositoryViewObject> allProcess = null;
try {
allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
for (IRepositoryViewObject object : allProcess) {
if (isStatUseProjectSetting(object)) {
if (!checkedObjects.contains(object.getProperty().getId())) {
checkedObjects.add(object.getProperty().getId());
if (!checkedNodeObject.contains(object)) {
checkedNodeObject.add(object);
}
}
}
}
List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
if (allOpenedProcessList != null) {
for (int i = 0; i < allOpenedProcessList.size(); i++) {
if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
openedProcessList.add(allOpenedProcessList.get(i));
}
}
}
//
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
// must init this
addContextModel = false;
if (!contextVars.isEmpty()) {
// boolean showDialog = false;
Set<String> contextSet = new HashSet<String>();
for (String key : contextVars.keySet()) {
contextSet = contextVars.get(key);
break;
}
Connection connection = null;
IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null) {
IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object proValue = propertyElem.getValue();
if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String value = (String) repositoryElem.getValue();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
connection = connectionItem.getConnection();
if (connection != null && connection.isContextMode()) {
addContextModel = true;
// ContextItem contextItem =
// ContextUtils.getContextItemById(connection.getContextId());
// for (IProcess process : openedProcessList) {
// Set<String> addedContext =
// ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, process.getContextManager(), false);
// if (addedContext != null && !addedContext.isEmpty()) {
// showDialog = true;
// break;
// }
// }
}
}
}
if (addContextModel) {
// if the context is not existed in job, will add or not.
Display disp = Display.getCurrent();
if (disp == null) {
disp = Display.getDefault();
}
if (disp != null) {
disp.syncExec(new Runnable() {
@Override
public void run() {
showContextAndCheck(contextVars);
}
});
} else {
showContextAndCheck(contextVars);
}
}
}
monitor.worked(10);
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IRepositoryViewObject object : checkedNodeObject) {
saveProcess(object, addContextModel, contextVars, monitor);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.done();
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class SaveAsBusinessModelWizard method update.
private void update() {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
assginVlaues(oldProperty, property);
repositoryFactory.save(oldBusinessProcessItem);
// assign value
businessProcessItem = oldBusinessProcessItem;
} 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());
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class EmfEmittersPersistenceFactory method getJetProject.
/**
* DOC mhirt Comment method "getJetProject".
*
* @return
* @throws CoreException
*/
private static IProject getJetProject() {
IProject project = null;
try {
IProgressMonitor monitor = new NullProgressMonitor();
IProgressMonitor progressMonitor = new SubProgressMonitor(monitor, 1);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
//$NON-NLS-1$
project = workspace.getRoot().getProject(".JETEmitters");
if (!project.exists()) {
project.create(new SubProgressMonitor(progressMonitor, 1));
progressMonitor.subTask(//$NON-NLS-1$
CodeGenPlugin.getPlugin().getString(//$NON-NLS-1$
"_UI_JETCreatingProject_message", new Object[] { project.getName() }));
project.open(new SubProgressMonitor(progressMonitor, 1));
}
} catch (CoreException e) {
log.error(e.getMessage(), e);
project = null;
}
return project;
}
use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.
the class AIResourceChangeListener method getProjectNameAsPerKey.
/**
* Method scans all open Maven or Dynamic web projects form workspace
* and returns name of project who is using specific key.
* @return
*/
public static String getProjectNameAsPerKey(String keyToRemove) {
String name = "";
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
for (IProject iProject : root.getProjects()) {
if (iProject.isOpen() && WebPropertyTester.isWebProj(iProject)) {
String aiXMLPath;
String webXMLPath;
if (iProject.hasNature(Messages.natMaven)) {
aiXMLPath = Messages.aiXMLPathMaven;
webXMLPath = Messages.webxmlPathMaven;
} else {
aiXMLPath = Messages.aiXMLPath;
webXMLPath = Messages.webxmlPath;
}
AILibraryHandler handler = new AILibraryHandler();
IFile aiFile = iProject.getFile(aiXMLPath);
IFile webFile = iProject.getFile(webXMLPath);
if (aiFile.exists() && webFile.exists()) {
handler.parseWebXmlPath(webFile.getLocation().toOSString());
handler.parseAIConfXmlPath(aiFile.getLocation().toOSString());
// if application insights configuration is enabled.
if (handler.isAIWebFilterConfigured()) {
String key = handler.getAIInstrumentationKey();
if (key != null && !key.isEmpty() && key.equals(keyToRemove)) {
return iProject.getName();
}
}
}
}
}
} catch (Exception ex) {
Activator.getDefault().log(Messages.genKeyListErr, ex);
}
return name;
}
Aggregations