Search in sources :

Example 96 with IProject

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

the class MultiSelectionPropertyTester method test.

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IProject curProject = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            if (page.getActivePartReference() == null) {
                return false;
            }
            String partId = page.getActivePartReference().getId();
            if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
                // 导航视图处于激活状态
                IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
                StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
                ArrayList<IFile> selectedIFileList = new ArrayList<IFile>();
                if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                    List<?> lstObj = ((IStructuredSelection) selection).toList();
                    for (Object obj : lstObj) {
                        if (obj instanceof IFile) {
                            IFile file = (IFile) obj;
                            // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                            if (file.getFileExtension() == null || !CommonFunction.validXlfExtension(file.getFileExtension())) {
                                return false;
                            } else {
                                String xlfFolderPath = file.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                                if (!file.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                    return false;
                                }
                                if (curProject == null) {
                                    curProject = file.getProject();
                                } else {
                                    if (curProject != file.getProject()) {
                                        return false;
                                    }
                                }
                                selectedIFileList.add(file);
                            }
                        } else if (obj instanceof IFolder) {
                            IFolder folder = (IFolder) obj;
                            String xlfFolderPath = folder.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                            if (!folder.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                return false;
                            }
                            try {
                                ResourceUtils.getXliffs(folder, selectedIFileList);
                            } catch (CoreException e) {
                                logger.error(Messages.getString("propertyTester.MultiSelectionPropertyTester.logger1"), folder.getFullPath().toOSString(), e);
                            }
                            if (curProject == null) {
                                curProject = folder.getProject();
                            } else {
                                if (curProject != folder.getProject()) {
                                    return false;
                                }
                            }
                        }
                    }
                    CommonFunction.removeRepeateSelect(selectedIFileList);
                    if (selectedIFileList.size() < 2) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFolder(org.eclipse.core.resources.IFolder)

Example 97 with IProject

use of org.eclipse.core.resources.IProject in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method createJavaProject.

public static IJavaProject createJavaProject(String projectName, String binFolderName) throws Exception {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }
    if (!project.isOpen()) {
        project.open(null);
    }
    final IFolder binFolder = project.getFolder(binFolderName);
    createFolder(binFolder);
    addNatureToProject(project, JavaCore.NATURE_ID);
    final IJavaProject javaProject = JavaCore.create(project);
    javaProject.setOutputLocation(binFolder.getFullPath(), null);
    javaProject.setRawClasspath(new IClasspathEntry[0], null);
    return javaProject;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 98 with IProject

use of org.eclipse.core.resources.IProject in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method addSourceContainer.

private static IPackageFragmentRoot addSourceContainer(IJavaProject javaProject, String containerName) throws Exception {
    final IProject project = javaProject.getProject();
    final IFolder folder = project.getFolder(containerName);
    createFolder(folder);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
    IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), EMPTY_PATHS, EMPTY_PATHS, null);
    addToClasspath(javaProject, Arrays.asList(cpe));
    return root;
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 99 with IProject

use of org.eclipse.core.resources.IProject in project lwjgl by LWJGL.

the class LWJGLClasspathContainerPage method getPlaceholderProject.

public static IJavaProject getPlaceholderProject() {
    //$NON-NLS-1$
    String name = "####internal";
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    while (true) {
        IProject project = root.getProject(name);
        if (!project.exists()) {
            return JavaCore.create(project);
        }
        name += '1';
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Example 100 with IProject

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

the class ViewDockerHostAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent e) {
    IProject project;
    try {
        project = AzureDockerUIResources.getCurrentSelectedProject();
    } catch (Exception Ignored) {
        project = null;
    }
    if (project == null) {
        project = (IProject) dockerHostNode.getProject();
    }
    AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(PluginUtil.getParentShell(), project, dockerHost, dockerManager);
    viewDockerDialog.open();
    if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
        if (dockerHost != null && !dockerHost.isUpdating) {
            AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(dockerHost), dockerManager, true);
        } else {
            PluginUtil.displayErrorDialog(PluginUtil.getParentShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
        }
    }
}
Also used : AzureViewDockerDialog(com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProject (org.eclipse.core.resources.IProject)461 CoreException (org.eclipse.core.runtime.CoreException)114 IFile (org.eclipse.core.resources.IFile)88 IResource (org.eclipse.core.resources.IResource)85 IPath (org.eclipse.core.runtime.IPath)66 IFolder (org.eclipse.core.resources.IFolder)64 ArrayList (java.util.ArrayList)60 File (java.io.File)53 IJavaProject (org.eclipse.jdt.core.IJavaProject)53 Test (org.junit.Test)48 IOException (java.io.IOException)47 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)45 ByteArrayInputStream (java.io.ByteArrayInputStream)36 PersistenceException (org.talend.commons.exception.PersistenceException)34 Path (org.eclipse.core.runtime.Path)33 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 IWorkspace (org.eclipse.core.resources.IWorkspace)31 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)31 Project (org.talend.core.model.general.Project)30 ServerAdapter (org.apache.sling.ide.test.impl.helpers.ServerAdapter)28