Java Code Examples for org.eclipse.core.resources.ResourcesPlugin

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala.editor/src-gen/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/model/scala/presentation/.

Source file: ScalaEditor.java

  19 
vote

/** 
 * This also changes the editor's input. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void doSaveAs(){
  SaveAsDialog saveAsDialog=new SaveAsDialog(getSite().getShell());
  saveAsDialog.open();
  IPath path=saveAsDialog.getResult();
  if (path != null) {
    IFile file=ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file != null) {
      doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(),true),new FileEditorInput(file));
    }
  }
}
 

Example 2

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.webapp.editor/src-gen/org/eclipse/acceleo/tutorial/webapp/presentation/.

Source file: WebappEditor.java

  19 
vote

/** 
 * This also changes the editor's input. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void doSaveAs(){
  SaveAsDialog saveAsDialog=new SaveAsDialog(getSite().getShell());
  saveAsDialog.open();
  IPath path=saveAsDialog.getResult();
  if (path != null) {
    IFile file=ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file != null) {
      doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(),true),new FileEditorInput(file));
    }
  }
}
 

Example 3

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/webproject/.

Source file: JavaWebProjectWizardPage.java

  19 
vote

public IStatus validate(Object obj){
  String value=(String)obj;
  if (value == null || value.trim().length() == 0) {
    String errorMessage="Enter a project name.";
    return ValidationStatus.info(errorMessage);
  }
  for (  IProject existingProject : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
    if (existingProject.getName().equals(value)) {
      String errorMessage="Project '" + value + "' already exists in the workspace";
      return ValidationStatus.error(errorMessage);
    }
  }
  return Status.OK_STATUS;
}
 

Example 4

From project Bio-PEPA, under directory /uk.ac.ed.inf.biopepa.ui/src/uk/ac/ed/inf/biopepa/ui/wizards/export/.

Source file: ExportWizard.java

  19 
vote

@Override public boolean performFinish(){
  Exporter exporter=exportPage.getExporter();
  exporter.setName(model.getUnderlyingResource().getName());
  SaveAsDialog saveAsDialog=new SaveAsDialog(getShell());
  IPath path=model.getUnderlyingResource().getFullPath();
  path=path.removeFileExtension().addFileExtension(exporter.getExportPrefix());
  IFile file=ResourcesPlugin.getWorkspace().getRoot().getFile(path);
  saveAsDialog.setOriginalFile(file);
  saveAsDialog.open();
  path=saveAsDialog.getResult();
  if (path == null)   return false;
  path=path.removeFileExtension().addFileExtension(exporter.getExportPrefix());
  file=ResourcesPlugin.getWorkspace().getRoot().getFile(path);
  String contents=null;
  try {
    contents=exporter.toString();
  }
 catch (  Exception e) {
    e.printStackTrace();
    return false;
  }
  InputStream source=new ByteArrayInputStream(contents.getBytes());
  try {
    if (file.exists()) {
      file.setContents(source,IResource.NONE,null);
    }
 else {
      file.create(source,IResource.NONE,null);
    }
    file.refreshLocal(0,null);
  }
 catch (  CoreException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}
 

Example 5

From project bioclipse.seneca, under directory /plugins/net.bioclipse.seneca/src/net/bioclipse/seneca/judge/.

Source file: Abstract13CJudge.java

  19 
vote

@Override public IJudge createJudge(IPath data) throws MissingInformationException {
  try {
    this.setData(data);
    CMLBuilder builder=new CMLBuilder();
    Document doc=builder.buildEnsureCML(ResourcesPlugin.getWorkspace().getRoot().getFile(this.getData()).getContents());
    SpectrumUtils.namespaceThemAll(doc.getRootElement().getChildElements());
    doc.getRootElement().setNamespaceURI(CMLUtil.CML_NS);
    Element element=builder.parseString(doc.toXML());
    if (element instanceof CMLCml)     this.configure((CMLCml)element);
 else     if (element instanceof CMLSpectrum) {
      CMLCml cmlcml=new CMLCml();
      cmlcml.appendChild(element);
      this.configure(cmlcml);
    }
    this.setEnabled(super.getEnabled());
    return this;
  }
 catch (  IOException e) {
    throw new MissingInformationException("Could not read the cmlString.");
  }
catch (  ParsingException e) {
    throw new MissingInformationException("Could not parse the cmlString; " + e.getMessage());
  }
catch (  CoreException e) {
    throw new MissingInformationException(e.getMessage());
  }
}
 

Example 6

From project bioclipse.speclipse, under directory /plugins/net.bioclipse.bibtex/src/net/bioclipse/bibtex/wizards/.

Source file: NewBibtexWizard.java

  19 
vote

/** 
 * This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using wizard as execution context.
 */
public boolean performFinish(){
  IFile newRes=ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePage.getCompleteFileName()));
  try {
    if (filePage.getYesButton().getSelection()) {
      InputStream ins=this.getClass().getClassLoader().getResourceAsStream("/net/bioclipse/bibtex/resources/template.bib");
      newRes.create(ins,false,new NullProgressMonitor());
    }
 else {
      newRes.create(new ByteArrayInputStream(new String("").getBytes()),false,new NullProgressMonitor());
    }
  }
 catch (  Exception ex) {
    LogUtils.handleException(ex,logger,net.bioclipse.bibtex.Activator.PLUGIN_ID);
  }
  return true;
}
 

Example 7

From project bndtools, under directory /bndtools.core/src/bndtools/builder/.

Source file: NewBuilder.java

  19 
vote

private Project getDependencyTargetChange() throws Exception {
  IWorkspaceRoot wsroot=ResourcesPlugin.getWorkspace().getRoot();
  Collection<Project> dependson=model.getDependson();
  log(LOG_FULL,"project depends on: %s",dependson);
  for (  Project dep : dependson) {
    File targetDir=dep.getTarget();
    if (targetDir != null && !(targetDir.isDirectory()))     return dep;
    IProject project=WorkspaceUtils.findOpenProject(wsroot,dep);
    if (project == null) {
      logger.logWarning(String.format("Dependency project '%s' from project '%s' is not in the Eclipse workspace.",dep.getName(),model.getName()),null);
      return null;
    }
    IFile buildFile=project.getFolder(targetDir.getName()).getFile(Workspace.BUILDFILES);
    IPath buildFilePath=buildFile.getProjectRelativePath();
    IResourceDelta delta=getDelta(project);
    if (delta == null) {
      log(LOG_FULL,"null delta in dependency project %s",dep.getName());
      return dep;
    }
 else     if (!isChangeDelta(delta)) {
      continue;
    }
 else {
      IResourceDelta buildFileDelta=delta.findMember(buildFilePath);
      if (buildFileDelta != null && isChangeDelta(buildFileDelta)) {
        log(LOG_FULL,"detected change due to file %s, kind=0x%x, flags=0x%x",buildFile,delta.getKind(),delta.getFlags());
        return dep;
      }
    }
  }
  return null;
}
 

Example 8

From project bpelunit, under directory /tycho/net.bpelunit.framework.client.eclipse/src/net/bpelunit/framework/client/eclipse/launch/.

Source file: BPELLaunchMainTab.java

  19 
vote

/** 
 * Show a dialog that lists all main types
 */
protected void handleSearchButtonSelected(){
  ElementTreeSelectionDialog dialog=new ElementTreeSelectionDialog(getShell(),new WorkbenchLabelProvider(),new WorkbenchContentProvider());
  dialog.setTitle("Select a .bpts file:");
  dialog.setMessage("Select the .bpts file to run:");
  dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
  dialog.setSorter(new ResourceSorter(ResourceSorter.NAME));
  dialog.addFilter(new ViewerFilter(){
    @Override public boolean select(    Viewer viewer,    Object parentElement,    Object element){
      if (element instanceof IFile) {
        IFile file=(IFile)element;
        if (!file.getFileExtension().equals("bpts"))         return false;
      }
      return true;
    }
  }
);
  dialog.setAllowMultiple(false);
  dialog.setValidator(new ISelectionStatusValidator(){
    public IStatus validate(    Object[] selection){
      if ((selection != null) && (selection.length > 0)) {
        Object first=selection[0];
        if (first instanceof IFile) {
          IFile file=(IFile)first;
          if (file.getFileExtension().equals("bpts"))           return Status.OK_STATUS;
        }
      }
      return new Status(IStatus.ERROR,BPELUnitActivator.getUniqueIdentifier(),-1,"Select a .bpts file.",null);
    }
  }
);
  if (dialog.open() == IDialogConstants.OK_ID) {
    IResource resource=(IResource)dialog.getFirstResult();
    if (!(resource instanceof IFile) || !resource.getFileExtension().equals("bpts")) {
      MessageDialog.openError(this.getShell(),"BPELUnit Test Suite","Must select a file with a .bpts ending");
    }
 else {
      fSuiteText.setText(resource.getProjectRelativePath().toString());
    }
  }
}
 

Example 9

From project BPMN2-Editor-for-Eclipse, under directory /org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/.

Source file: ModelHandlerLocator.java

  19 
vote

private static ModelHandler createNewModelHandler(URI path,final Bpmn2ResourceImpl resource){
  ModelHandler handler=new ModelHandler();
  map.put(path,handler);
  handler.resource=resource;
  URI uri=resource.getURI();
  try {
    IWorkspace workspace=ResourcesPlugin.getWorkspace();
    String platformString=uri.toPlatformString(true);
    if ((platformString == null || workspace.getRoot().getFile(new Path(platformString)).exists()) && !resource.isLoaded()) {
      handler.loadResource();
    }
  }
 catch (  IllegalStateException e) {
    if (!resource.isLoaded()) {
      handler.loadResource();
    }
  }
  handler.createDefinitionsIfMissing();
  return handler;
}
 

Example 10

From project bundlemaker, under directory /main/org.bundlemaker.core/src/org/bundlemaker/core/exporter/util/.

Source file: Helper.java

  19 
vote

/** 
 * <p> </p>
 * @param projectName
 * @return
 * @throws CoreException
 */
public static IProject deleteAndCreateProject(String projectName,IPath location) throws CoreException {
  IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  if (project.exists()) {
    project.delete(true,true,null);
  }
  if (!project.exists()) {
    IProjectDescription desc=project.getWorkspace().newProjectDescription(project.getName());
    if (location != null) {
      desc.setLocation(location);
    }
    project.create(desc,null);
    if (!project.isOpen()) {
      project.open(null);
    }
    IFile file=project.getFile(".bundlemakergenerated");
    if (!file.exists()) {
      file.create(new ByteArrayInputStream(new byte[0]),true,null);
    }
 else {
      file.setContents(new ByteArrayInputStream(new byte[0]),IFile.FORCE,null);
    }
  }
  return project;
}
 

Example 11

From project ccw, under directory /ccw.core/src/java/ccw/.

Source file: ClojureCore.java

  19 
vote

private static boolean openInEditor(final String searchedNS,final String initialSearchedFileName,final int line,final String projectName,final boolean onlyExportedEntries) throws PartInitException {
  if (initialSearchedFileName == null) {
    return false;
  }
  final String searchedFileName=getFileName(initialSearchedFileName);
  final IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  final IJavaProject javaProject=JavaCore.create(project);
  try {
    System.out.println("search file name : " + searchedFileName);
    System.out.println("searched ns : " + searchedNS);
    final String searchedPackage=namespaceToPackage(searchedNS);
    System.out.println("searched package: " + searchedPackage);
    for (    IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) {
      final IEditorInput editorInput=findEditorInput(packageFragmentRoot,searchedPackage,searchedFileName);
      if (editorInput != null) {
        IEditorPart editor=IDE.openEditor(CCWPlugin.getActivePage(),editorInput,ClojureEditor.ID);
        gotoEditorLine(editor,line);
        return true;
      }
 else {
        continue;
      }
    }
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
  return false;
}
 

Example 12

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/editor/.

Source file: EditorInputUtils.java

  19 
vote

/** 
 * @return the IPath corresponding to the given input, or null if none
 */
public static IPath getPath(IEditorInput editorInput){
  IPath path=null;
  if (editorInput instanceof IFileEditorInput) {
    IFileEditorInput fileEditorInput=(IFileEditorInput)editorInput;
    path=fileEditorInput.getFile().getProjectRelativePath();
  }
 else   if (editorInput instanceof IPathEditorInput) {
    IPathEditorInput pathInput=(IPathEditorInput)editorInput;
    path=pathInput.getPath();
  }
 else   if (editorInput instanceof IStorageEditorInput) {
    IStorageEditorInput storageEditorInput=(IStorageEditorInput)editorInput;
    try {
      path=storageEditorInput.getStorage().getFullPath();
    }
 catch (    CoreException e) {
    }
  }
 else   if (editorInput instanceof IURIEditorInput) {
    IURIEditorInput uriEditorInput=(IURIEditorInput)editorInput;
    IWorkspaceRoot wsRoot=ResourcesPlugin.getWorkspace().getRoot();
    path=new Path(uriEditorInput.getURI().getPath());
    if (wsRoot.getProject(path.segment(0)).exists()) {
      path=path.removeFirstSegments(1);
    }
  }
  return path;
}
 

Example 13

From project cilia-workbench, under directory /cilia-workbench-common/src/fr/liglab/adele/cilia/workbench/common/ui/view/ciliaerrorview/.

Source file: CiliaMarkerUtil.java

  19 
vote

/** 
 * Creates a Cilia marker.
 * @param severity the markers's severity. see  {@link IMarker} file for gettingconstants.
 * @param description the marker description
 * @param rootSourceProvider the root source provider, which should be a repository.
 * @param sourceProvider the source provider. Object responsible of this marker creation.
 * @return the marker
 */
public static IMarker createMarker(int severity,String description,Object rootSourceProvider,Object sourceProvider){
  IMarker marker=null;
  try {
    marker=ResourcesPlugin.getWorkspace().getRoot().createMarker(MARKER_TYPE);
    marker.setAttribute(IMarker.MESSAGE,description);
    marker.setAttribute(IMarker.SEVERITY,severity);
    marker.setAttribute(IMarker.TRANSIENT,true);
    if (rootSourceProvider != null)     marker.setAttribute(RootSourceProviderField.FIELD_ID,rootSourceProvider);
    if (sourceProvider != null)     marker.setAttribute(SourceProviderField.FIELD_ID,sourceProvider);
  }
 catch (  CoreException e) {
    e.printStackTrace();
  }
  return marker;
}
 

Example 14

From project Database-Designer, under directory /plugins/org.obeonetwork.dsl.database.editor/src/org/obeonetwork/dsl/database/presentation/.

Source file: DatabaseEditor.java

  19 
vote

/** 
 * This also changes the editor's input. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void doSaveAs(){
  SaveAsDialog saveAsDialog=new SaveAsDialog(getSite().getShell());
  saveAsDialog.open();
  IPath path=saveAsDialog.getResult();
  if (path != null) {
    IFile file=ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file != null) {
      doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(),true),new FileEditorInput(file));
    }
  }
}
 

Example 15

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/project/.

Source file: DawbResourcePage.java

  19 
vote

/** 
 * Returns the container resource specified in the container name entry field, or <code>null</code> if such a container does not exist in the workbench.
 * @return the container resource specified in the container name entry field,or <code>null</code>
 */
protected IContainer getSpecifiedContainer(){
  IWorkspace workspace=ResourcesPlugin.getWorkspace();
  IPath path=getContainerFullPath();
  if (workspace.getRoot().exists(path)) {
    IResource resource=workspace.getRoot().findMember(path);
    if (resource.getType() == IResource.FILE) {
      return null;
    }
    return (IContainer)resource;
  }
  return null;
}
 

Example 16

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model/src/main/java/com/isencia/passerelle/workbench/model/utils/.

Source file: ModelUtils.java

  19 
vote

public static IFile getProjectFile(final String modelPath){
  final String workspacePath=ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
  String relPath=modelPath.substring(workspacePath.length());
  IFile projFile=(IFile)ResourcesPlugin.getWorkspace().getRoot().findMember(relPath);
  if (projFile == null) {
    relPath=modelPath.substring(workspacePath.length() + 2);
    projFile=(IFile)ResourcesPlugin.getWorkspace().getRoot().findMember(relPath);
  }
  return projFile;
}
 

Example 17

From project dawn-product, under directory /org.dawnsci.intro/src/org/dawnsci/intro/util/.

Source file: IntroUtils.java

  19 
vote

public static boolean isProjectExisting(final String natureId){
  final IWorkspaceRoot root=ResourcesPlugin.getWorkspace().getRoot();
  boolean isProject=false;
  final IProject[] projects=root.getProjects();
  for (  IProject iProject : projects) {
    try {
      if (iProject.getNature(natureId) != null) {
        isProject=true;
        break;
      }
    }
 catch (    CoreException e) {
      continue;
    }
  }
  return isProject;
}
 

Example 18

From project dawn-tango, under directory /org.dawb.passerelle.actors.tango/src/org/dawb/passerelle/actors/hardware/.

Source file: TangoCommandTransformer.java

  19 
vote

protected IResource getResource(final boolean setParameterValue) throws Exception {
  String path=specFileParam.getExpression();
  IFile file=null;
  if (path == null || "".equals(path)) {
    final IProject project=getProject();
    final IContainer src=project.getFolder("src");
    file=IFileUtils.getUniqueIFile(src,"macro","mac");
    path=file.getFullPath().toOSString();
    path=StringUtil.replace(path,"/" + file.getProject().getName() + "/","/${project_name}/",true);
    if (setParameterValue)     specFileParam.setExpression(path);
  }
  if (ResourcesPlugin.getWorkspace().getRoot().findMember(path) != null)   if (ResourcesPlugin.getWorkspace().getRoot().findMember(path).exists()) {
    file=(IFile)ResourcesPlugin.getWorkspace().getRoot().findMember(path);
  }
  if (file == null) {
    path=ParameterUtils.substitute(path,this);
    final IProject project=getProject();
    final String srcP=IFileUtils.getPathWithoutProject(path.substring(0,path.lastIndexOf('/')));
    IContainer specDir=(IContainer)project.findMember(srcP);
    if (specDir == null) {
      try {
        IFolder srcf=project.getFolder(srcP);
        specDir=srcf;
      }
 catch (      Exception ne) {
        logger.error("Cannot create folder " + srcP,ne);
      }
    }
    final String fileName=path.substring(path.lastIndexOf('/'));
    file=(IFile)specDir.findMember(fileName);
    if (file == null && specDir instanceof IProject) {
      file=((IProject)specDir).getFile(fileName);
    }
    if (file == null && specDir instanceof IFolder) {
      file=((IFolder)specDir).getFile(fileName);
    }
  }
  return file;
}
 

Example 19

From project dawn-ui, under directory /org.dawb.workbench.ui/src/org/dawb/workbench/ui/editors/actions/.

Source file: HightlightWorkflowHandler.java

  19 
vote

private void toggleHighlightSelection(){
  final boolean isSel=store.getBoolean(EditorConstants.HIGHLIGHT_ACTORS_CHOICE);
  store.setValue(EditorConstants.HIGHLIGHT_ACTORS_CHOICE,!isSel);
  IWorkspace ws=ResourcesPlugin.getWorkspace();
  try {
    ws.save(true,new NullProgressMonitor());
  }
 catch (  CoreException e) {
    logger.error("Cannot save workspace",e);
  }
}