Search in sources :

Example 16 with IWorkspaceRoot

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

the class ImportProjectWizardPage2 method resetSqliteTBNameAndPath.

private void resetSqliteTBNameAndPath(IProject project, DatabaseModelBean bean, int index) {
    IFolder folder = project.getFolder("TB");
    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()) {
        // FIXME
        bean.setDbName("Exported_" + index + "_" + dbName);
    }
    if (file.exists() || folder.getFile(dbName).exists()) {
        bean.setItlDBLocation(rootLocation + fileSeparator + project.getName() + fileSeparator + "TB");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with IWorkspaceRoot

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

the class WorkbenchLabelProvider method getDecorateFileCount.

private String getDecorateFileCount(IFolder ifolder) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String rootPath = root.getLocation().toOSString();
    String filePath = ifolder.getFullPath().toOSString();
    String folder = rootPath + filePath;
    File file = new File(folder);
    if (!file.exists()) {
        return "";
    }
    List<File> temp = new ArrayList<File>(10);
    lookUp(file, temp);
    int size = temp.size();
    if (null == temp || temp.isEmpty()) {
        return "";
    } else if (size == 1) {
        return " [1]";
    } else {
        return " [" + size + "]";
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) File(java.io.File)

Example 18 with IWorkspaceRoot

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

the class XLIFFEditorImplWithNatTable method performSaveAs.

/**
	 * 执行另存为
	 * @param progressMonitor
	 *            进度条;
	 */
private void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    final IEditorInput input = getEditorInput();
    // 新的EditorInput
    final IEditorInput newInput;
    // 原始的file
    final File oldFile;
    // if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) { // 外部文件
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    URI uri = ((IURIEditorInput) input).getURI();
    IPath oldPath = URIUtil.toPath(uri);
    if (oldPath != null) {
        dialog.setFileName(oldPath.lastSegment());
        // 设置所在文件夹
        dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        oldFile = oldPath.toFile();
    } else {
        oldFile = new File(uri);
    }
    // 得到保存路径
    String newPath = dialog.open();
    if (newPath == null) {
        if (progressMonitor != null)
            progressMonitor.setCanceled(true);
        return;
    }
    // 检查文件是否存在,如果存在则确认是否覆盖
    final File localFile = new File(newPath);
    if (localFile.exists()) {
        String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg1"), newPath);
        MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("editor.XLIFFEditorImplWithNatTable.overwriteDialog"), null, msg, MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
        if (overwriteDialog.open() != MessageDialog.OK) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
                return;
            }
        }
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // 得到新文件
    IFile file = root.getFileForLocation(URIUtil.toPath(localFile.toURI()));
    if (file != null) {
        // 是“WorkSpace”内的文件
        newInput = new FileEditorInput(file);
    } else {
        // 不是“WorkSpace”内的文件
        try {
            IFileStore fileStore = EFS.getStore(localFile.toURI());
            newInput = new FileStoreEditorInput(fileStore);
        } catch (CoreException ex) {
            // EditorsPlugin.log(ex.getStatus());
            LOGGER.error("", ex);
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
    }
    // } else {
    // SaveAsDialog dialog = new SaveAsDialog(shell);
    // // 源文件
    // IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
    // if (original != null) {
    // dialog.setOriginalFile(original); // 添加源文件信息
    // oldFile = original.getLocation().toFile();
    // if ((!oldFile.exists() || !oldFile.canRead()) && original != null) {
    // String message = MessageFormat.format(
    // "The original file ''{0}'' has been deleted or is not accessible.", original.getName());
    // dialog.setErrorMessage(null);
    // dialog.setMessage(message, IMessageProvider.WARNING);
    // }
    // } else {
    // oldFile = null;
    // }
    // dialog.create();
    //
    // if (dialog.open() == MessageDialog.CANCEL) { // 打开“另存为”对话框,用户点击了“取消”按钮
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IPath filePath = dialog.getResult(); // 获得用户选择的路径
    // if (filePath == null) { // 检查路径
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // IFile file = root.getFile(filePath);
    // newInput = new FileEditorInput(file);
    // }
    saveAs(newInput, oldFile, progressMonitor);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 19 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot 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 20 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot 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)

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