Search in sources :

Example 11 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project translationstudio8 by heartsome.

the class RenameResourceAndCloseEditorAction method queryNewResourceName.

/**
	 * Return the new name to be given to the target resource.
	 * 
	 * @return java.lang.String
	 * @param resource
	 *            the resource to query status on
	 */
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = new IInputValidator() {

        public String isValid(String string) {
            if (resource.getName().equals(string)) {
                return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
            }
            IStatus status = workspace.validateName(string, resource.getType());
            if (!status.isOK()) {
                return status.getMessage();
            }
            if (workspace.getRoot().exists(prefix.append(string))) {
                return IDEWorkbenchMessages.RenameResourceAction_nameExists;
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(shellProvider.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    int result = dialog.open();
    if (result == Window.OK)
        return dialog.getValue();
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) Point(org.eclipse.swt.graphics.Point) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 12 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.

the class AzureDockerUIResources method getCurrentSelectedProject.

public static IProject getCurrentSelectedProject() {
    IProject project = null;
    ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    ISelection selection = selectionService.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof IResource) {
            project = ((IResource) element).getProject();
        } else if (element instanceof PackageFragmentRoot) {
            IJavaProject jProject = ((PackageFragmentRoot) element).getJavaProject();
            project = jProject.getProject();
        } else if (element instanceof IJavaElement) {
            IJavaProject jProject = ((IJavaElement) element).getJavaProject();
            project = jProject.getProject();
        }
    }
    if (project == null) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        if (workspace.getRoot() != null && workspace.getRoot().getProjects().length > 0) {
            IProject[] projects = workspace.getRoot().getProjects();
            project = projects[projects.length - 1];
        } else {
            PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "No Active Project", "Must have a project first");
        }
    }
    return project;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 13 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.

the class SparkSubmitModel method action.

public void action(@NotNull SparkSubmissionParameter submissionParameter) {
    this.submissionParameter = submissionParameter;
    if (isLocalArtifact()) {
        submit();
    } else {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        IProject proj = root.getProject(submissionParameter.getArtifactName());
        JarExportJob job = new JarExportJob("Building jar", proj);
        job.schedule();
        job.addJobChangeListener(new JobChangeAdapter() {

            public void done(IJobChangeEvent event) {
                if (event.getResult().isOK()) {
                    submit();
                }
            }

            ;
        });
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject)

Example 14 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.

the class CreateProjectUtil method convert.

@NotNull
private static IFile convert(@NotNull File file) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath location = Path.fromOSString(file.getAbsolutePath());
    IFile ifile = workspace.getRoot().getFileForLocation(location);
    return ifile;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 15 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsResourceRegistryEclipse method getInUseInstrumentationKeys.

/**
	 * Method scans all open Maven or Dynamic web projects form workspace
	 * and prepare a list of instrumentation keys which are in use.
	 * @return
	 */
public static List<String> getInUseInstrumentationKeys() {
    List<String> keyList = new ArrayList<String>();
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        for (IProject iProject : root.getProjects()) {
            if (iProject.isOpen() && WebPropertyTester.isWebProj(iProject)) {
                String aiXMLPath;
                if (iProject.hasNature(Messages.natMaven)) {
                    aiXMLPath = Messages.aiXMLPathMaven;
                } else {
                    aiXMLPath = Messages.aiXMLPath;
                }
                AILibraryHandler handler = new AILibraryHandler();
                IFile file = iProject.getFile(aiXMLPath);
                if (file.exists()) {
                    handler.parseAIConfXmlPath(file.getLocation().toOSString());
                    String key = handler.getAIInstrumentationKey();
                    if (key != null && !key.isEmpty()) {
                        keyList.add(key);
                    }
                }
            }
        }
    } catch (Exception ex) {
        Activator.getDefault().log(ex.getMessage(), ex);
    }
    return keyList;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IOException(java.io.IOException) RestOperationException(com.microsoft.applicationinsights.management.rest.client.RestOperationException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)71 CoreException (org.eclipse.core.runtime.CoreException)41 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)30 IProject (org.eclipse.core.resources.IProject)29 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IPath (org.eclipse.core.runtime.IPath)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)15 IFile (org.eclipse.core.resources.IFile)14 ArrayList (java.util.ArrayList)11 Status (org.eclipse.core.runtime.Status)11 Path (org.eclipse.core.runtime.Path)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 File (java.io.File)9 IOException (java.io.IOException)9 IResource (org.eclipse.core.resources.IResource)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)8