Search in sources :

Example 6 with IWorkspace

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

the class ApplicationWorkbenchWindowAdvisor method addWorkplaceListener.

public void addWorkplaceListener() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            //刷新项目导航视图
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
                    if (null == findView) {
                        return;
                    }
                    IAction refreshActionHandler = findView.getViewSite().getActionBars().getGlobalActionHandler(ActionFactory.REFRESH.getId());
                    if (null == refreshActionHandler) {
                        return;
                    }
                    refreshActionHandler.run();
                }
            });
        }
    });
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) IWorkspace(org.eclipse.core.resources.IWorkspace) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Example 7 with IWorkspace

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

the class SplitXliff method getFullPath.

/**
	 * 根据绝对路径获取其项目路径
	 * @param filePath
	 * @return
	 */
public String getFullPath(String filePath) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath location = Path.fromOSString(filePath);
    IFile ifile = workspace.getRoot().getFileForLocation(location);
    return ifile.getFullPath().toOSString();
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 8 with IWorkspace

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

the class ImportProjectWizardPage method isProjectInWorkspacePath.

/**
	 * Determine if there is a directory with the project name in the workspace path.
	 * 
	 * @param projectName the name of the project
	 * @return true if there is a directory with the same name of the imported project
	 */
private boolean isProjectInWorkspacePath(String projectName) {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath wsPath = workspace.getRoot().getLocation();
    IPath localProjectPath = wsPath.append(projectName);
    return localProjectPath.toFile().exists();
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 9 with IWorkspace

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

the class NewFolderDialogOfHs method isValidContainer.

/**
		 * Returns whether the container specified in the constructor is
		 * a valid parent for creating linked resources.
		 * 
		 * @return boolean <code>true</code> if the container specified in 
		 * 	the constructor is a valid parent for creating linked resources.
		 * 	<code>false</code> if no linked resources may be created with the
		 * 	specified container as a parent. 
		 */
private boolean isValidContainer() {
    if (container.getType() != IResource.PROJECT && container.getType() != IResource.FOLDER) {
        return false;
    }
    try {
        IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
        IProject project = container.getProject();
        String[] natureIds = project.getDescription().getNatureIds();
        for (int i = 0; i < natureIds.length; i++) {
            IProjectNatureDescriptor descriptor = workspace.getNatureDescriptor(natureIds[i]);
            if (descriptor != null && descriptor.isLinkingAllowed() == false) {
                return false;
            }
        }
    } catch (CoreException exception) {
        // project does not exist or is closed
        return false;
    }
    return true;
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) Point(org.eclipse.swt.graphics.Point)

Example 10 with IWorkspace

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

the class NewFolderDialogOfHs method validateFolderName.

/**
		 * Checks if the folder name is valid.
		 *
		 * @return null if the new folder name is valid.
		 * 	a message that indicates the problem otherwise.
		 */
@SuppressWarnings("restriction")
private boolean validateFolderName() {
    String name = folderNameField.getText();
    IWorkspace workspace = container.getWorkspace();
    IStatus nameStatus = workspace.validateName(name, IResource.FOLDER);
    if ("".equals(name)) {
        //$NON-NLS-1$
        updateStatus(IStatus.ERROR, IDEWorkbenchMessages.NewFolderDialog_folderNameEmpty);
        return false;
    }
    if (nameStatus.isOK() == false) {
        updateStatus(nameStatus);
        return false;
    }
    // 修改创建文件夹时,所进行的文件名特殊字符验证	--robert	2013-07-01
    String result = null;
    if ((result = CommonFunction.validResourceName(name)) != null) {
        updateStatus(new ResourceStatus(IResourceStatus.INVALID_VALUE, null, result));
        return false;
    }
    IPath path = new Path(name);
    if (container.getFolder(path).exists() || container.getFile(path).exists()) {
        updateStatus(IStatus.ERROR, NLS.bind(IDEWorkbenchMessages.NewFolderDialog_alreadyExists, name));
        return false;
    }
    //$NON-NLS-1$
    updateStatus(IStatus.OK, "");
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus)

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