Java Code Examples for org.eclipse.core.resources.IContainer#isAccessible()

The following examples show how to use org.eclipse.core.resources.IContainer#isAccessible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUIValidatorExtension.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void deleteMarkersRecursively(FileURI location) {
	if (location == null) {
		return;
	}

	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	IContainer[] containers = root.findContainersForLocationURI(URI.create(location.toString()));
	if (containers == null || containers.length == 0) {
		return;
	}

	try {
		for (IContainer container : containers) {
			if (container.isAccessible()) {
				container.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: PyResourceDropAdapterAssistant.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget) {
    aDropTarget = getActual(aDropTarget);

    IContainer target = getActualTarget((IResource) aDropTarget);
    IResource[] resources = getSelectedResources(aDragSelection);

    MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell());
    operation.copyResources(resources, target);

    if (target != null && target.isAccessible()) {
        try {
            target.refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
        }
    }
    return Status.OK_STATUS;
}
 
Example 3
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget) {

		IContainer target = getActualTarget((IResource) aDropTarget);
		IResource[] resources = getSelectedResources(aDragSelection);
		
		MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(
				 getShell());
		operation.copyResources(resources, target);

		if (target != null && target.isAccessible()) {
			try {
				target.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException e) {
			}
		}
		return Status.OK_STATUS;
	}
 
Example 4
Source File: ResourceExtensionContentProvider.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean hasChildren(Object element) {
	try {
		if (element instanceof IContainer) {
			IContainer c = (IContainer) element;
			if (!c.isAccessible())
				return false;
			return c.members().length > 0;
		}
	} catch (CoreException ex) {
		WorkbenchNavigatorPlugin.getDefault().getLog().log(
				new Status(IStatus.ERROR, WorkbenchNavigatorPlugin.PLUGIN_ID, 0, ex.getMessage(), ex));
		return false;
	}

	return super.hasChildren(element);
}
 
Example 5
Source File: ResourceDropAdapterAssistant.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget) {

		IContainer target = getActualTarget((IResource) aDropTarget);
		IResource[] resources = getSelectedResources(aDragSelection);
		
		MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(
				 getShell());
		operation.copyResources(resources, target);

		if (target != null && target.isAccessible()) {
			try {
				target.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException e) {
			}
		}
		return Status.OK_STATUS;
	}
 
Example 6
Source File: ResourceExtensionContentProvider.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean hasChildren(Object element) {
	try {
		if (element instanceof IContainer) {
			IContainer c = (IContainer) element;
			if (!c.isAccessible())
				return false;
			return c.members().length > 0;
		}
	} catch (CoreException ex) {
		WorkbenchNavigatorPlugin.getDefault().getLog().log(
				new Status(IStatus.ERROR, WorkbenchNavigatorPlugin.PLUGIN_ID, 0, ex.getMessage(), ex));
		return false;
	}

	return super.hasChildren(element);
}
 
Example 7
Source File: FileTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) {

	boolean isPackageFragment= target instanceof IPackageFragment;
	boolean isJavaProject= target instanceof IJavaProject;
	boolean isPackageFragmentRoot= target instanceof IPackageFragmentRoot;
	boolean isContainer= target instanceof IContainer;

	if (!(isPackageFragment || isJavaProject || isPackageFragmentRoot || isContainer))
		return DND.DROP_NONE;

	if (isContainer) {
		IContainer container= (IContainer)target;
		if (container.isAccessible() && !Resources.isReadOnly(container))
			return DND.DROP_COPY;
	} else {
		IJavaElement element= (IJavaElement)target;
		if (!element.isReadOnly())
			return DND.DROP_COPY;
	}

	return DND.DROP_NONE;
}
 
Example 8
Source File: NavigatorResourceDropAssistant.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IStatus handlePluginTransferDrop(final IStructuredSelection aDragSelection, final Object aDropTarget) {

	final IContainer target = getActualTarget(ResourceManager.getResource(aDropTarget));
	final IResource[] resources = getSelectedResources(aDragSelection);

	final MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell());
	operation.copyResources(resources, target);

	if (target != null && target.isAccessible()) {
		try {
			target.refreshLocal(IResource.DEPTH_ONE, null);
		} catch (final CoreException e) {}
	}
	return Status.OK_STATUS;
}
 
Example 9
Source File: PackageFilterEditor.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private List<IResource> handleContainer(IContainer container) {
  List<IResource> children = new ArrayList<>();
  if (container.isAccessible()) {
    try {
      IResource[] members = container.members();
      for (int i = 0; i < members.length; i++) {
        if (members[i].getType() != IResource.FILE) {
          children.add(members[i]);
        }
      }
    } catch (CoreException e) {
      // this should never happen because we call
      // #isAccessible before invoking #members
    }
  }
  return children;
}
 
Example 10
Source File: ContainerContentProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see ITreeContentProvider#getChildren
 */
public Object[] getChildren(Object element) {
	if (element instanceof IWorkspace) {
		// check if closed projects should be shown
		IProject[] allProjects = ((IWorkspace) element).getRoot().getProjects();
		if (showClosedProjects)
			return allProjects;
		
		ArrayList accessibleProjects = new ArrayList();
		for (int i = 0; i < allProjects.length; i++){
			if (allProjects[i].isOpen()){
				accessibleProjects.add(allProjects[i]);
			}
		}
		return accessibleProjects.toArray();
	} else if (element instanceof IContainer) {
		IContainer container = (IContainer)element;
		if (container.isAccessible()) {
		    try {
			    List children = new ArrayList();
			    IResource[] members = container.members();
			    for (int i = 0; i < members.length; i++) {
				    if (members[i].getType() != IResource.FILE) {
					    children.add(members[i]);
				    }
			    }
			    return children.toArray();
			} catch (CoreException e) {
				// this should never happen because we call #isAccessible before invoking #members
			}
		}
	}
	return new Object[0];
}
 
Example 11
Source File: PythonModulePickerDialog.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getChildren(Object element) {

    if (element instanceof IContainer) {
        IContainer container = (IContainer) element;

        if (container.isAccessible()) {
            try {
                List<IResource> children = new ArrayList<IResource>();

                IResource[] members = container.members();

                for (int i = 0; i < members.length; i++) {

                    if (members[i] instanceof IFile) {

                        IFile file = (IFile) members[i];

                        if (PythonPathHelper.isValidSourceFile(file)) {
                            children.add(file);
                        }
                    } else if (members[i] instanceof IContainer) {
                        children.add(members[i]);
                    }
                }
                return children.toArray();
            } catch (CoreException e) {
                // this should never happen because we call #isAccessible before invoking #members
            }
        }
    }

    return new Object[0];
}
 
Example 12
Source File: ProjectFolderSelectionGroup.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getChildren(Object element) {
    if (element instanceof IWorkspace) {
        // check if closed projects should be shown
        IProject[] allProjects = ((IWorkspace) element).getRoot().getProjects();
        if (showClosedProjects)
            return allProjects;

        ArrayList<IProject> accessibleProjects = new ArrayList<IProject>();
        for (int i = 0; i < allProjects.length; i++) {
            if (allProjects[i].isOpen()) {
                accessibleProjects.add(allProjects[i]);
            }
        }
        return accessibleProjects.toArray();
    } else if (element instanceof IContainer) {
        IContainer container = (IContainer) element;
        if (container.isAccessible()) {
            try {
                List<IResource> children = new ArrayList<IResource>();
                IResource[] members = container.members();
                for (int i = 0; i < members.length; i++) {
                    if (members[i].getType() != IResource.FILE) {
                        children.add(members[i]);
                    }
                }
                return children.toArray();
            } catch (CoreException e) {
                // this should never happen because we call #isAccessible before invoking #members
            }
        }
    }
    return new Object[0];
}
 
Example 13
Source File: JarFileExportOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Map<String, ArrayList<IResource>> buildJavaToClassMap(IContainer container, IProgressMonitor monitor) throws CoreException {
	if (container == null || !container.isAccessible())
		return new HashMap<String, ArrayList<IResource>>(0);
	/*
	 * XXX: Bug 6584: Need a way to get class files for a java file (or CU)
	 */
	IClassFileReader cfReader= null;
	IResource[] members= container.members();
	Map<String, ArrayList<IResource>> map= new HashMap<String, ArrayList<IResource>>(members.length);
	for (int i= 0;  i < members.length; i++) {
		if (isClassFile(members[i])) {
			IFile classFile= (IFile)members[i];
			URI location= classFile.getLocationURI();
			if (location != null) {
				InputStream contents= null;
				try {
					contents= EFS.getStore(location).openInputStream(EFS.NONE, monitor);
					cfReader= ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.CLASSFILE_ATTRIBUTES);
				} finally {
					try {
						if (contents != null)
							contents.close();
					} catch (IOException e) {
						throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR,
							Messages.format(JarPackagerMessages.JarFileExportOperation_errorCannotCloseConnection, BasicElementLabels.getURLPart(Resources.getLocationString(classFile))),
							e));
					}
				}
				if (cfReader != null) {
					ISourceAttribute sourceAttribute= cfReader.getSourceFileAttribute();
					if (sourceAttribute == null) {
						/*
						 * Can't fully build the map because one or more
						 * class file does not contain the name of its
						 * source file.
						 */
						addWarning(Messages.format(
							JarPackagerMessages.JarFileExportOperation_classFileWithoutSourceFileAttribute,
							BasicElementLabels.getURLPart(Resources.getLocationString(classFile))), null);
						return null;
					}
					String javaName= new String(sourceAttribute.getSourceFileName());
					ArrayList<IResource> classFiles= map.get(javaName);
					if (classFiles == null) {
						classFiles= new ArrayList<IResource>(3);
						map.put(javaName, classFiles);
					}
					classFiles.add(classFile);
				}
			}
		}
	}
	return map;
}
 
Example 14
Source File: ResourceDropAdapterAssistant.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public IStatus handleDrop(CommonDropAdapter aDropAdapter,
		DropTargetEvent aDropTargetEvent, Object aTarget) {

	if (Policy.DEBUG_DND) {
		System.out
				.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
	}

	// alwaysOverwrite = false;
	if (aTarget == null || aDropTargetEvent.data == null) {
		return Status.CANCEL_STATUS;
	}
	IStatus status = null;
	IResource[] resources = null;
	TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
	if (LocalSelectionTransfer.getTransfer().isSupportedType(
			currentTransfer)) {
		resources = getSelectedResources();
	} else if (ResourceTransfer.getInstance().isSupportedType(
			currentTransfer)) {
		resources = (IResource[]) aDropTargetEvent.data;
	}

	if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
		status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
	} else if (resources != null && resources.length > 0) {
		if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY)
				|| (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) {
			if (Policy.DEBUG_DND) {
				System.out
						.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
			}
			status = performResourceCopy(aDropAdapter, getShell(),
					resources);
		} else {
			if (Policy.DEBUG_DND) {
				System.out
						.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
			}

			status = performResourceMove(aDropAdapter, resources);
		}
	}
	openError(status);
	IContainer target = getActualTarget((IResource) aTarget);
	if (target != null && target.isAccessible()) {
		try {
			target.refreshLocal(IResource.DEPTH_ONE, null);
		} catch (CoreException e) {
		}
	}
	return status;
}
 
Example 15
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public IStatus handleDrop(CommonDropAdapter aDropAdapter,
		DropTargetEvent aDropTargetEvent, Object aTarget) {

	if (Policy.DEBUG_DND) {
		System.out
				.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
	}

	// alwaysOverwrite = false;
	if (aTarget == null || aDropTargetEvent.data == null) {
		return Status.CANCEL_STATUS;
	}
	IStatus status = null;
	IResource[] resources = null;
	TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
	if (LocalSelectionTransfer.getTransfer().isSupportedType(
			currentTransfer)) {
		resources = getSelectedResources();
	} else if (ResourceTransfer.getInstance().isSupportedType(
			currentTransfer)) {
		resources = (IResource[]) aDropTargetEvent.data;
	}

	if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
		status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
	} else if (resources != null && resources.length > 0) {
		if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY)
				|| (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) {
			if (Policy.DEBUG_DND) {
				System.out
						.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
			}
			status = performResourceCopy(aDropAdapter, getShell(),
					resources);
		} else {
			if (Policy.DEBUG_DND) {
				System.out
						.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
			}

			status = performResourceMove(aDropAdapter, resources);
		}
	}
	openError(status);
	IContainer target = getActualTarget((IResource) aTarget);
	if (target != null && target.isAccessible()) {
		try {
			target.refreshLocal(IResource.DEPTH_ONE, null);
		} catch (CoreException e) {
		}
	}
	return status;
}
 
Example 16
Source File: GTestExecutor.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public void execute(IFile programFile) throws IOException, InterruptedException {
	IContainer programContainer = programFile.getParent();
	if (!programContainer.isAccessible()) {
		throw new RuntimeException(
				"Test program container " + programContainer.getLocation().toOSString() + " inaccessible");
	}

	File directory = programContainer.getLocation().toFile();
	Process process = new ProcessBuilder(programFile.getLocation().toOSString()).redirectErrorStream(true)
			.directory(directory).start();
	BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

	boolean started = false;
	boolean running = false;
	StringBuilder message = new StringBuilder();
	String line;
	while ((line = reader.readLine()) != null) {
		if (line.startsWith("[====")) {
			if (started) {
				started = false;
				// Eat remaining input
				char[] buffer = new char[4096];
				while (reader.read(buffer) != -1);
				break;
			}
			started = true;
		} else {
			TestOutput testOutput = parseTestOutput(line);
			if (testOutput != null) {
				Description description = testOutput.toDescription();
				switch (testOutput.getStatus()) {
					case TestOutput.RUN :
						running = true;
						message.setLength(0);
						testStarted(description);
						break;
					case TestOutput.OK :
						running = false;
						testFinished(description);
						break;
					default :
						running = false;
						testFailed(description, message.toString());
						testFinished(description);
						break;
				}
			} else if (running) {
				message.append(line);
				message.append("\n");
			}
		}
	}

	process.waitFor();

	if (started) {
		throw new RuntimeException("Test quit unexpectedly (exit status " + process.exitValue() + "):\n" + message);
	}
}
 
Example 17
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Object[] getChildren( Object element )
{
	if ( element instanceof IWorkspace )
	{
		// check if closed projects should be shown
		IProject[] allProjects = ( (IWorkspace) element ).getRoot( )
				.getProjects( );
		if ( showClosedProjects )
			return allProjects;

		ArrayList accessibleProjects = new ArrayList( );
		for ( int i = 0; i < allProjects.length; i++ )
		{
			if ( allProjects[i].isOpen( ) )
			{
				accessibleProjects.add( allProjects[i] );
			}
		}
		return accessibleProjects.toArray( );
	}
	else if ( element instanceof IContainer )
	{
		IContainer container = (IContainer) element;
		if ( container.isAccessible( ) )
		{
			try
			{
				List children = new ArrayList( );
				IResource[] members = container.members( );
				for ( int i = 0; i < members.length; i++ )
				{
					if ( members[i].getType( ) != IResource.FILE )
					{
						children.add( members[i] );
					}
				}
				return children.toArray( );
			}
			catch ( CoreException e )
			{
				// this should never happen because we call #isAccessible
				// before invoking #members
			}
		}
	}
	return new Object[0];
}
 
Example 18
Source File: PyResourceDropAdapterAssistant.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
    //        aTarget = getActual(aTarget);
    if (DEBUG) {
        System.out.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
    }

    // alwaysOverwrite = false;
    if (getCurrentTarget(aDropAdapter) == null || aDropTargetEvent.data == null) {
        return Status.CANCEL_STATUS;
    }
    IStatus status = null;
    IResource[] resources = null;
    TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
    if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) {
        resources = getSelectedResources();
    } else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
        resources = (IResource[]) aDropTargetEvent.data;
    }

    if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
        status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
    } else if (resources != null && resources.length > 0) {
        if (aDropAdapter.getCurrentOperation() == DND.DROP_COPY) {
            if (DEBUG) {
                System.out.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
            }
            status = performResourceCopy(aDropAdapter, getShell(), resources);
        } else {
            if (DEBUG) {
                System.out.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
            }

            status = performResourceMove(aDropAdapter, resources);
        }
    }
    openError(status);
    IContainer target = getActualTarget((IResource) getCurrentTarget(aDropAdapter));
    if (target != null && target.isAccessible()) {
        try {
            target.refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
        }
    }
    return status;
}