Java Code Examples for org.eclipse.core.resources.IResource#PROJECT

The following examples show how to use org.eclipse.core.resources.IResource#PROJECT . 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: RefreshAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean checkEnabled(IStructuredSelection selection) {
	if (selection.isEmpty())
		return true;

	boolean okToRefresh= false;
	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		Object element= iter.next();
		if (element instanceof IWorkingSet) {
			// don't inspect working sets any deeper.
			okToRefresh= true;
		} else if (element instanceof IPackageFragmentRoot) {
			// on internal folders/JARs we do a normal refresh, and Java archive refresh on external
			okToRefresh= true;
		} else if (element instanceof PackageFragmentRootContainer) {
			// too expensive to look at children. assume we can refresh
			okToRefresh= true;
		} else if (element instanceof IAdaptable) { // test for IAdaptable last (types before are IAdaptable as well)
			IResource resource= (IResource)((IAdaptable)element).getAdapter(IResource.class);
			okToRefresh|= resource != null && (resource.getType() != IResource.PROJECT || ((IProject) resource).isOpen());
		} else {
			// nothing to say;
		}
	}
	return okToRefresh;
}
 
Example 2
Source File: TypeScriptNatureTester.java    From typescript.java with MIT License 6 votes vote down vote up
private boolean testCanAddToBuildPath(Object receiver) {
	if (receiver instanceof IAdaptable) {
		IResource resource = (IResource) ((IAdaptable) receiver).getAdapter(IResource.class);
		if (resource != null) {
			switch (resource.getType()) {
			case IResource.PROJECT:
			case IResource.FOLDER:
				return true;
			case IResource.FILE:
				if (TypeScriptResourceUtil.isTsConfigFile(resource)) {
					try {
						IIDETypeScriptProject tsProject = TypeScriptResourceUtil
								.getTypeScriptProject(resource.getProject());
						return !tsProject.getTypeScriptBuildPath().isInBuildPath((IFile) resource);

					} catch (CoreException e) {
					}
				}
			default:
				return false;
			}
		}
	}
	return false;
}
 
Example 3
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static WrappedResource<?, ?> privateCreateWrapping(final VirtualContent<?> parent, final IResource child) {
	if (DEBUG.IS_ON()) {
		DEBUG.OUT("Creation of the wrapped instance of " + child.getName());
	}
	switch (child.getType()) {
		case IResource.FILE:
			if (FileMetaDataProvider.GAML_CT_ID.equals(getContentTypeId((IFile) child))) {
				return new WrappedGamaFile((WrappedContainer<?>) parent, (IFile) child);
			}
			if (child.isLinked()) { return new WrappedLink((WrappedContainer<?>) parent, (IFile) child); }
			return new WrappedFile((WrappedContainer<?>) parent, (IFile) child);
		case IResource.FOLDER:
			return new WrappedFolder((WrappedContainer<?>) parent, (IFolder) child);
		case IResource.PROJECT:
			return new WrappedProject((TopLevelFolder) parent, (IProject) child);
	}
	return null;
}
 
Example 4
Source File: SharedProjectDecorator.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void decorate(Object element, IDecoration decoration) {
  // make a copy as this value might change while decorating
  ISarosSession currentSession = session;

  if (currentSession == null) return;

  IResource resource = (IResource) element;

  if (!currentSession.isShared(ResourceAdapterFactory.create(resource))) return;

  decoration.addOverlay(SharedProjectDecorator.PROJECT_DESCRIPTOR, IDecoration.TOP_LEFT);

  if (resource.getType() == IResource.PROJECT) {
    decoration.addSuffix(Messages.SharedProjectDecorator_shared);
  }
}
 
Example 5
Source File: SVNDecoratorPreferencesPage.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public Image getImage(Object element) {
	final String s;
	switch (((PreviewFile)element).type) {
	case IResource.PROJECT:
		s= SharedImages.IMG_OBJ_PROJECT; break;
	case IResource.FOLDER:
		s= ISharedImages.IMG_OBJ_FOLDER; break;
	default:
		s= ISharedImages.IMG_OBJ_FILE; break;
	}
	final Image baseImage= PlatformUI.getWorkbench().getSharedImages().getImage(s);
	final ImageDescriptor overlay = getOverlay(element);
	if (overlay == null)
		return baseImage;
	try {
              return fImageCache.createImage(new OverlayIcon(baseImage, new ImageDescriptor[] {overlay}, new int[] {OverlayIcon.BOTTOM_RIGHT}, new Point(baseImage.getBounds().width, baseImage.getBounds().height)));
          } catch (Exception e) {
          	SVNUIPlugin.log(e.getMessage());
          }
          return null;
}
 
Example 6
Source File: RestoreProjectListener.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta[] projectDeltas = event.getDelta().getAffectedChildren();
	for (IResourceDelta delta : projectDeltas) {
		if((delta.getResource().getType() == IResource.PROJECT) && 
			(delta.getKind() == IResourceDelta.CHANGED || delta.getKind() == IResourceDelta.ADDED) 
				&& (delta.getFlags() & IResourceDelta.OPEN) != 0){
			IProject project = delta.getResource().getProject();
			if(project.isOpen()){
				HybridProject hybridProject  = HybridProject.getHybridProject(project);
				if(hybridProject != null ) {
					RestoreProjectJob job = new RestoreProjectJob(project);
					ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project);
					job.setRule(rule);
					job.schedule();
				}
			}
		}
	}
}
 
Example 7
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkOpenResources( List<IResource> itemsToCheck,
		List<IEditorPart> openedEditorRefs,
		List<IEditorPart> openedDirtyEditorRefs ) throws CoreException
{
	for ( IResource resourceToCheck : itemsToCheck )
	{
		switch ( resourceToCheck.getType( ) )
		{
			case IResource.FILE :
				IEditorReference fileRef = getEditorRefInOpenFileList( (IFile) resourceToCheck );
				checkAndAddToEditorLists( openedEditorRefs,
						openedDirtyEditorRefs,
						fileRef );
				break;
			case IResource.PROJECT :
				getOpenedFileInProject( (IProject) resourceToCheck,
						openedEditorRefs,
						openedDirtyEditorRefs );
				break;
			default :
				checkOpenResources( Arrays.asList( ( (IContainer) resourceToCheck ).members( ) ),
						openedEditorRefs,
						openedDirtyEditorRefs );
		}
	}
}
 
Example 8
Source File: AbstractProjectPropertiesAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void run(IAction action) {
  Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

  if (resource != null && resource.getType() == IResource.PROJECT) {
    PreferenceDialog page = PreferencesUtil.createPropertyDialogOn(shell,
        resource, propertiesPageID, null, null);
    if (page != null) {
      page.open();
      return;
    }
  }

  CorePluginLog.logError("Could not create project properties dialog for resource "
      + resource.toString());
}
 
Example 9
Source File: WorkspaceSpecManager.java    From tlaplus with MIT License 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
    /*
     * remove elements from the storage if the projects are deleted
     */
    IResource resource = event.getResource();
    if (resource != null && IResource.PROJECT == resource.getType()
            && IResourceChangeEvent.PRE_DELETE == event.getType())
    {
        specStorage.remove(resource.getName());
    }

}
 
Example 10
Source File: WorkItem.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isDirectory() {
    IResource corespondingResource = getCorespondingResource();
    if (corespondingResource != null) {
        return corespondingResource.getType() == IResource.FOLDER || corespondingResource.getType() == IResource.PROJECT;
    }
    return false;
}
 
Example 11
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String getName(IResource resource) {
	String resourceLabel= BasicElementLabels.getResourceName(resource);
	switch (resource.getType()){
		case IResource.FILE:
			return Messages.format(RefactoringCoreMessages.ReorgUtils_0, resourceLabel);
		case IResource.FOLDER:
			return Messages.format(RefactoringCoreMessages.ReorgUtils_1, resourceLabel);
		case IResource.PROJECT:
			return Messages.format(RefactoringCoreMessages.ReorgUtils_2, resourceLabel);
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example 12
Source File: DerivedFoldersChangeListener.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	for (IResourceDelta delta : event.getDelta().getAffectedChildren()) {
		//check if resource is hybrid project
		if(delta.getResource().getType() == IResource.PROJECT){
			HybridProject hybridProject = HybridProject.getHybridProject((IProject)delta.getResource());
			if(hybridProject != null){
				DerivedFoldersJob job = new DerivedFoldersJob(hybridProject);
				job.schedule();
			}
		}
	}
	
}
 
Example 13
Source File: NewImpexWizardPage.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
private void dialogChanged() {
	IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
	String fileName = getFileName();

	if (getContainerName().length() == 0) {
		updateStatus("Project/Folder must be specified");
		return;
	}
	if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
		updateStatus("Project/Folder must exist");
		return;
	}
	if (!container.isAccessible()) {
		updateStatus("Project/Folder must be writable");
		return;
	}
	if (fileName.length() == 0) {
		updateStatus("File name must be specified");
		return;
	}
	if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
		updateStatus("File name must be valid");
		return;
	}
	int dotLoc = fileName.lastIndexOf('.');
	if (dotLoc != -1) {
		String ext = fileName.substring(dotLoc + 1);
		if (ext.equalsIgnoreCase("impex") == false && ext.equalsIgnoreCase("csv") == false) {
			updateStatus("File extension must be \"impex\" or \"csv\"");
			return;
		}
	}
	updateStatus(null);
}
 
Example 14
Source File: ResourceOutputPart.java    From depan with Apache License 2.0 5 votes vote down vote up
public String getErrorMsg() {
  IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(
      new Path(getContainerName()));
  String filename = getFilename();
  
  if (getContainerName().length() == 0) {
    return "File container must be specified";
  }
  if (container == null
      || (container.getType()
          & (IResource.PROJECT | IResource.FOLDER)) == 0) {
    return "File container must exist";
  }
  if (!container.isAccessible()) {
    return "Project must be writable";
  }
  if (filename.length() == 0) {
    return "File name must be specified";
  }
  if (filename.replace('\\', '/').indexOf('/', 1) > 0) {
    return "File name cannot include path";
  }
  int dotLoc = filename.lastIndexOf('.');
  if (dotLoc != -1) {
    String ext = filename.substring(dotLoc + 1);
    if (!ext.equalsIgnoreCase(requiredExt)) {
      return "File extension must be \"." + requiredExt + "\"";
    }
  }
  return null;
}
 
Example 15
Source File: JdtClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException {
	boolean includeAll = visited.isEmpty();
	if (visited.add(javaProject.getElementName())) {
		IProject project = javaProject.getProject();
		IResource resourceFromProjectRoot = project.findMember(path);
		if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) {
			return createPlatformResourceURI(resourceFromProjectRoot);
		}
		for(IClasspathEntry entry: javaProject.getResolvedClasspath(true)) {
			if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
				if (includeAll || entry.isExported()) {
					IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath());
					if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
						IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject);
						if (referencedJavaProject.exists()) {
							URI result = findResourceInProjectRoot(referencedJavaProject, path, visited);
							if (result != null) {
								return result;
							}
						}
					}
					break;
				}
			}
		}
	}
	return null;
}
 
Example 16
Source File: AbstractIProjectStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public int getType() {
    return IResource.PROJECT;
}
 
Example 17
Source File: JdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see JavaProject computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, boolean, java.util.Map)
 */
private void collectSourcePackageFragmentRoots(JavaProject javaProject, HashSet<String> rootIDs, IClasspathEntry referringEntry, ObjectVector result) throws JavaModelException {
	if (referringEntry == null){
		rootIDs.add(javaProject.rootID());
	} else if (rootIDs.contains(javaProject.rootID())) {
		return;
	}
	IWorkspaceRoot workspaceRoot = javaProject.getProject().getWorkspace().getRoot();
	for(IClasspathEntry entry: javaProject.getResolvedClasspath()) {
		switch(entry.getEntryKind()) {
			case IClasspathEntry.CPE_PROJECT:
				if (referringEntry != null && !entry.isExported())
					return;
				
				IPath pathToProject = entry.getPath();
				IResource referencedProject = workspaceRoot.findMember(pathToProject);
				if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
					IProject casted = (IProject) referencedProject;
					if (JavaProject.hasJavaNature(casted)) {
						rootIDs.add(javaProject.rootID());
						JavaProject referencedJavaProject = (JavaProject) JavaCore.create(casted);
						collectSourcePackageFragmentRoots(referencedJavaProject, rootIDs, entry, result);
					}
				}
				break;
			case IClasspathEntry.CPE_SOURCE:
				// inlined from org.eclipse.jdt.internal.core.JavaProject
				// .computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, boolean, Map)
				IPath projectPath = javaProject.getProject().getFullPath();
				IPath entryPath = entry.getPath();
				if (projectPath.isPrefixOf(entryPath)){
					Object target = JavaModel.getTarget(entryPath, true/*check existency*/);
					if (target != null) {
						if (target instanceof IFolder || target instanceof IProject){
							IPackageFragmentRoot root = javaProject.getPackageFragmentRoot((IResource)target);
							result.add(root);
						}
					}
				}
				break;
		}
	}
}
 
Example 18
Source File: ResourceUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean canSync(IResource resource) {
	return resource.getType() != IResource.PROJECT && resource.getType() != IResource.ROOT;
}
 
Example 19
Source File: PasteAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * The <code>PasteAction</code> implementation of this
   * <code>SelectionListenerAction</code> method enables this action if 
   * a resource compatible with what is on the clipboard is selected.
   * 
   * -Clipboard must have IResource or java.io.File
   * -Projects can always be pasted if they are open
   * -Workspace folder may not be copied into itself
   * -Files and folders may be pasted to a single selected folder in open 
   * 	project or multiple selected files in the same folder 
   */
  protected boolean updateSelection(IStructuredSelection selection) {
      if (!super.updateSelection(selection)) {
	return false;
}

      final IResource[][] clipboardData = new IResource[1][];
      shell.getDisplay().syncExec(new Runnable() {
          public void run() {
              // clipboard must have resources or files
              ResourceTransfer resTransfer = ResourceTransfer.getInstance();
              clipboardData[0] = (IResource[]) clipboard
                      .getContents(resTransfer);
          }
      });
      IResource[] resourceData = clipboardData[0];
      boolean isProjectRes = resourceData != null && resourceData.length > 0
              && resourceData[0].getType() == IResource.PROJECT;

      if (isProjectRes) {
          for (int i = 0; i < resourceData.length; i++) {
              // make sure all resource data are open projects
              // can paste open projects regardless of selection
              if (resourceData[i].getType() != IResource.PROJECT
                      || ((IProject) resourceData[i]).isOpen() == false) {
			return false;
		}
          }
          return true;
      }

      if (getSelectedNonResources().size() > 0) {
	return false;
}

      IResource targetResource = getTarget();
      // targetResource is null if no valid target is selected (e.g., open project) 
      // or selection is empty	
      if (targetResource == null) {
	return false;
}

      // can paste files and folders to a single selection (file, folder, 
      // open project) or multiple file selection with the same parent
      List selectedResources = getSelectedResources();
      if (selectedResources.size() > 1) {
          for (int i = 0; i < selectedResources.size(); i++) {
              IResource resource = (IResource) selectedResources.get(i);
              if (resource.getType() != IResource.FILE) {
			return false;
		}
              if (!targetResource.equals(resource.getParent())) {
			return false;
		}
          }
      }
      if (resourceData != null) {
          // linked resources can only be pasted into projects
          if (isLinked(resourceData)
              && targetResource.getType() != IResource.PROJECT
              && targetResource.getType() != IResource.FOLDER) {
		return false;
	}

          if (targetResource.getType() == IResource.FOLDER) {
              // don't try to copy folder to self
              for (int i = 0; i < resourceData.length; i++) {
                  if (targetResource.equals(resourceData[i])) {
				return false;
			}
              }
          }
          return true;
      }
      TransferData[] transfers = clipboard.getAvailableTypes();
      FileTransfer fileTransfer = FileTransfer.getInstance();
      for (int i = 0; i < transfers.length; i++) {
          if (fileTransfer.isSupportedType(transfers[i])) {
		return true;
	}
      }
      return false;
  }
 
Example 20
Source File: GwtLaunchTargetTester.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Is this resource a project?
 *
 * @param resource
 * @return true iff the resource is a project.
 */
private boolean resourceIsProject(IResource resource) {
  return resource != null && resource.getType() == IResource.PROJECT;
}