Search in sources :

Example 66 with IWorkspaceRoot

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

the class XLFValidator method validateXliffFile.

public static boolean validateXliffFile(String fileLocalPath) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = root.getFileForLocation(URIUtil.toPath(new File(fileLocalPath).toURI()));
    if (file == null) {
        Shell shell = Display.getDefault().getActiveShell();
        MessageDialog.openError(shell, Messages.getString("file.XLFValidator.msgTitle"), Messages.getString("file.XLFValidator.msg9"));
        return false;
    }
    return validateXliffFile(file);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 67 with IWorkspaceRoot

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

the class MergeXliff method getFullPath.

/**
	 * 获取相对于项目的相对路径
	 * @param absolutePath
	 * @return
	 */
public String getFullPath(String absolutePath) {
    // UNDO 合并后的文件好像不能转换回原文件,这里还需完善。
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IFile iFile = root.getFileForLocation(Path.fromOSString(absolutePath));
    return iFile.getFullPath().toOSString();
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot)

Example 68 with IWorkspaceRoot

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

the class ImportProjectWizardPage2 method resetSqliteTMNameAndPath.

private void resetSqliteTMNameAndPath(IProject project, DatabaseModelBean bean, int index) {
    IFolder folder = project.getFolder("TM");
    if (!folder.exists()) {
        return;
    }
    String dbName = bean.getDbName();
    IFile file = folder.getFile("Exported_" + index + "_" + dbName);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String rootLocation = root.getLocation().toOSString();
    String fileSeparator = System.getProperty("file.separator");
    if (file.exists()) {
        bean.setDbName("Exported_" + index + "_" + dbName);
    }
    if (file.exists() || folder.getFile(dbName).exists()) {
        bean.setItlDBLocation(rootLocation + fileSeparator + project.getName() + fileSeparator + "TM");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFolder(org.eclipse.core.resources.IFolder)

Example 69 with IWorkspaceRoot

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

the class NewFolderDialogOfHs method createFolderHandle.

/**
		 * Creates a folder resource handle for the folder with the given name.
		 * The folder handle is created relative to the container specified during 
		 * object creation. 
		 *
		 * @param folderName the name of the folder resource to create a handle for
		 * @return the new folder resource handle
		 */
private IFolder createFolderHandle(String folderName) {
    IWorkspaceRoot workspaceRoot = container.getWorkspace().getRoot();
    IPath folderPath = container.getFullPath().append(folderName);
    IFolder folderHandle = workspaceRoot.getFolder(folderPath);
    return folderHandle;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder)

Example 70 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project OpenGrok by OpenGrok.

the class ResultsDialog method setResults.

public void setResults(List<Hit> results) {
    final Map<String, HitContainer> roots = new HashMap<String, HitContainer>();
    for (Hit hit : results) {
        String key = hit.getDirectory() + "/" + hit.getFilename();
        HitContainer container = roots.get(key);
        if (container == null) {
            container = new HitContainer(key);
            roots.put(key, container);
        }
        container.add(hit);
    }
    viewer.setHits(roots);
    if (resultsView != null) {
        resultsView.setHits(roots);
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            if (!viewer.getControl().isDisposed()) {
                viewer.refresh();
            }
        }
    });
    if (Activator.getDefault().getPreferenceStore().getBoolean(EGrokPreferencePage.WORKSPACE_MATCHES)) {
        Runnable workspaceLocator = new Runnable() {

            @Override
            public void run() {
                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                final Map<HitContainer, HashMap<IProject, Integer>> potentialProjects = new HashMap<HitContainer, HashMap<IProject, Integer>>();
                final Map<IProject, ArrayList<String>> locationSegments = new HashMap<IProject, ArrayList<String>>();
                try {
                    workspaceRoot.accept(new IResourceVisitor() {

                        @Override
                        public boolean visit(IResource resource) throws CoreException {
                            if (resource instanceof IWorkspaceRoot) {
                                return true;
                            }
                            if (resource instanceof IProject) {
                                IProject project = (IProject) resource;
                                IPath location = project.getLocation();
                                for (String segment : location.segments()) {
                                    ArrayList<String> segments = locationSegments.get(project);
                                    if (segments == null) {
                                        segments = new ArrayList<String>();
                                        locationSegments.put(project, segments);
                                    }
                                    segments.add(segment);
                                }
                            }
                            return false;
                        }
                    });
                } catch (CoreException e) {
                    e.printStackTrace();
                }
                Map<HitContainer, ArrayList<String>> hitcontainerSegments = new HashMap<HitContainer, ArrayList<String>>();
                for (HitContainer hitcontainer : roots.values()) {
                    ArrayList<String> segments = new ArrayList<String>();
                    for (String segment : hitcontainer.getName().split("/")) {
                        segments.add(segment);
                    }
                    hitcontainerSegments.put(hitcontainer, segments);
                }
                for (IProject project : locationSegments.keySet()) {
                    ArrayList<String> segments = locationSegments.get(project);
                    int idx = 0;
                    for (String segment : segments) {
                        for (HitContainer container : hitcontainerSegments.keySet()) {
                            for (String containerPathSegment : hitcontainerSegments.get(container)) {
                                if (segment.equals(containerPathSegment)) {
                                    HashMap<IProject, Integer> matches = potentialProjects.get(container);
                                    if (matches == null) {
                                        matches = new HashMap<IProject, Integer>();
                                        potentialProjects.put(container, matches);
                                    }
                                    matches.put(project, idx);
                                }
                            }
                        }
                        idx++;
                    }
                }
                for (HitContainer container : potentialProjects.keySet()) {
                    String fullLocation = container.getName();
                    HashMap<IProject, Integer> matches = potentialProjects.get(container);
                    System.out.println(container.getName());
                    for (Entry<IProject, Integer> match : matches.entrySet()) {
                        IProject project = match.getKey();
                        Integer matchingLocation = match.getValue();
                        String matchingString = project.getLocation().segment(matchingLocation);
                        System.out.println("match: " + matchingString);
                        String local = fullLocation.substring(fullLocation.indexOf(matchingString) + matchingString.length());
                        System.out.println("local: " + local);
                        IResource member = project.findMember(local);
                        System.out.println("member: " + member);
                        if (member instanceof IFile) {
                            IFile file = (IFile) member;
                            container.setCorrespondingFile(file);
                        }
                    }
                }
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!viewer.getControl().isDisposed()) {
                            viewer.refresh();
                        }
                        if (resultsView != null) {
                            resultsView.refresh();
                        }
                    }
                });
            }
        };
        workspaceLocator.run();
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) Point(org.eclipse.swt.graphics.Point) HitContainer(org.opensolaris.opengrok.egrok.model.HitContainer) Hit(org.opensolaris.opengrok.egrok.model.Hit) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)92 IPath (org.eclipse.core.runtime.IPath)41 IProject (org.eclipse.core.resources.IProject)31 IFile (org.eclipse.core.resources.IFile)30 IResource (org.eclipse.core.resources.IResource)29 CoreException (org.eclipse.core.runtime.CoreException)25 File (java.io.File)19 IWorkspace (org.eclipse.core.resources.IWorkspace)15 Path (org.eclipse.core.runtime.Path)14 IFolder (org.eclipse.core.resources.IFolder)12 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 ArrayList (java.util.ArrayList)10 IContainer (org.eclipse.core.resources.IContainer)10 IOException (java.io.IOException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 URI (java.net.URI)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IStatus (org.eclipse.core.runtime.IStatus)5 Project (aQute.bnd.build.Project)4 Workspace (aQute.bnd.build.Workspace)4