Search in sources :

Example 96 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project tesb-studio-se by Talend.

the class PublishMetadataRunnable method run.

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask(Messages.PublishMetadataAction_Importing, 3);
            final Collection<XmlFileConnectionItem> xmlObjs;
            try {
                xmlObjs = initFileConnection();
            } catch (Exception e) {
                String message = (null != e.getMessage()) ? e.getMessage() : e.getClass().getName();
                throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Can't retrieve schemas from metadata: " + message, e));
            }
            Collection<XmlFileConnectionItem> selectTables;
            if (xmlObjs.size() > 0) {
                RewriteSchemaDialogRunnable runnable = new RewriteSchemaDialogRunnable(shell, xmlObjs);
                Display.getDefault().syncExec(runnable);
                selectTables = runnable.getSelectTables();
                if (null == selectTables) {
                    return;
                }
            } else {
                selectTables = Collections.emptyList();
            }
            monitor.worked(1);
            if (monitor.isCanceled()) {
                return;
            }
            boolean validateWsdl = Activator.getDefault().getPreferenceStore().getBoolean(EsbSoapServicePreferencePage.ENABLE_WSDL_VALIDATION);
            if (validateWsdl) {
                WSDLUtils.validateWsdl(wsdlDefinition.getDocumentBaseURI());
            }
            monitor.worked(1);
            if (monitor.isCanceled()) {
                return;
            }
            try {
                process(wsdlDefinition, selectTables);
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error during schema processing", e));
            }
            monitor.done();
        }
    };
    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, monitor);
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem)

Example 97 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method refreshJobAndSave.

private void refreshJobAndSave(final IProxyRepositoryFactory repFactory) throws PersistenceException {
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                repFactory.save(item);
            } catch (PersistenceException e) {
                throw new CoreException(new Status(IStatus.ERROR, DesignerPlugin.ID, "Save Routine failed!", e));
            }
        }

        ;
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            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, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        throw new PersistenceException(e);
    } catch (InterruptedException e) {
        throw new PersistenceException(e);
    }
    setTitleImage(getTitleImage());
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 98 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.

the class ComponentProjectManager method createNewProject.

/**
     * Creates a new project resource with the selected name.
     * <p>
     * In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
     * Finish button implies that all controls on the pages currently contain valid values.
     * </p>
     * <p>
     * Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
     * this method will answer the same project resource without attempting to create it again.
     * </p>
     * 
     * @return the created project resource, or <code>null</code> if the project was not created
     */
public IProject createNewProject(String directroy, String projectName, Shell shell) {
    if (projDir.equals(directroy)) {
        return project;
    }
    final Shell currentShell = shell;
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (newProjectHandle.getRawLocation() != null) {
        if (newProjectHandle.getRawLocation().equals(directroy)) {
            return newProjectHandle;
        } else {
            try {
                newProjectHandle.delete(false, true, null);
            } catch (CoreException e) {
                // e.printStackTrace();
                org.talend.componentdesigner.exception.ExceptionHandler.process(e);
            }
        }
    }
    // final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
    // get a project descriptor
    URI location = null;
    if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
        return null;
    } else {
        location = new File(directroy).toURI();
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocationURI(location);
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
            Messages.getString("ComponentProjectManager.NewProject"));
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation o`peration
    try {
        ProgressUI.popProgressDialog(op, shell);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
                newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
                cause));
            }
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
            t));
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    project = newProjectHandle;
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) File(java.io.File)

Example 99 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project bndtools by bndtools.

the class FileUtils method toWorkspaceResource.

public static IResource toWorkspaceResource(File file) {
    IPath path = new Path(file.toString());
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot workspaceRoot = workspace.getRoot();
    IPath workspacePath = workspaceRoot.getLocation();
    if (workspacePath.isPrefixOf(path)) {
        final IPath relativePath = path.removeFirstSegments(workspacePath.segmentCount());
        IResource resource;
        if (file.isDirectory()) {
            resource = workspaceRoot.getFolder(relativePath);
        } else {
            resource = workspaceRoot.getFile(relativePath);
        }
        return resource;
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IResource(org.eclipse.core.resources.IResource)

Example 100 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project bndtools by bndtools.

the class BaselineErrorHandler method getResolutions.

@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
    List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
    final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    if (suggestedVersion != null) {
        result.add(new IMarkerResolution() {

            @Override
            public void run(IMarker marker) {
                final IFile file = (IFile) marker.getResource();
                final IWorkspace workspace = file.getWorkspace();
                try {
                    workspace.run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            String input = "version " + suggestedVersion;
                            ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
                            file.setContents(stream, false, true, monitor);
                        }
                    }, null);
                } catch (CoreException e) {
                    logger.logError("Error applying baseline version quickfix.", e);
                }
            }

            @Override
            public String getLabel() {
                return "Change package version to " + suggestedVersion;
            }
        });
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) IMarker(org.eclipse.core.resources.IMarker) LinkedList(java.util.LinkedList)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12