public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) {
   if (p == null) {
     IFile f = EclipseResourceUtil.getFile(jarFile);
     if (f == null) return null;
     p = f.getProject();
   }
   if (p == null) return null;
   IModelNature n = EclipseResourceUtil.getModelNature(p);
   XModel model = null;
   if (n != null) {
     model = n.getModel();
   } else {
     XModelObject o = EclipseResourceUtil.createObjectForResource(p);
     if (o != null) model = o.getModel();
   }
   if (model == null) return null;
   XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren();
   for (XModelObject s : fs) {
     String loc =
         Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties());
     if (new File(loc).equals(new File(jarFile))) {
       XModelObject result = s.getChildByPath(entry);
       if (result == null && entry != null) {
         int q = entry.indexOf('/');
         int d = entry.indexOf('.');
         if (q > d && d >= 0) {
           String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q);
           result = s.getChildByPath(entry1);
         }
       }
       if (result != null) return result;
     }
   }
   return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$
 }
 public void synchronize() {
   XModelObject o = getXModelObject();
   IFile f1 = super.getFile();
   if (o == null || o.getPath() == null) return;
   IFile f2 = getFileByObject(o);
   if (!f1.equals(f2) && f2 != null) hackSetFile(f2);
 }
 public boolean isFileChanged() {
   XModelObject o = getXModelObject();
   IFile f1 = super.getFile();
   if (o == null || o.getPath() == null) return false;
   IFile f2 = getFileByObject(o);
   return !f1.equals(f2);
 }
 public void revalidate() {
   IFile f = getFile();
   if (f == null || f.equals(super.getFile())) return;
   try {
     Field field = FileEditorInput.class.getDeclaredField("file"); // $NON-NLS-1$
     field.setAccessible(true);
     field.set(this, f);
   } catch (NoSuchFieldException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   } catch (IllegalArgumentException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   } catch (IllegalAccessException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   }
 }
 public boolean checkIfFileInTarget(IFile fileToCheck) {
   String[] strings = selectedListBox.getItems();
   int size = selectedListBox.getItemCount();
   for (int i = 0; i < size; i++) {
     if (strings[i].compareTo(fileToCheck.getFullPath().toString()) == 0) return true;
   }
   return false;
 }
 private static IEditorInput convertFileInput(IFileEditorInput input) {
   IFileEditorInput fi = (IFileEditorInput) input;
   IFile f = fi.getFile();
   if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) {
     try {
       f.refreshLocal(IResource.DEPTH_INFINITE, null);
     } catch (CoreException e) {
       // ignore
     }
   }
   XModelObject o = EclipseResourceUtil.getObjectByResource(f);
   if (o == null) {
     o = EclipseResourceUtil.createObjectForResource(f);
   }
   return (o == null || o.getFileType() != XModelObject.FILE)
       ? input
       : new XModelObjectEditorInput(getMainObject(o));
 }
 public boolean equals(Object o) {
   getXModelObject();
   if (this == o) return true;
   if (o instanceof FileEditorInput) {
     if (getFile() == null) return false;
     FileEditorInput other = (FileEditorInput) o;
     IFile f1 = getFile();
     IFile f2 = other.getFile();
     if (f1 == null || f2 == null) return f1 == f2;
     if (f1.equals(f2)) return true;
     IPath loc1 = f1.getLocation();
     IPath loc2 = f2.getLocation();
     if (loc1 == null || loc2 == null) return loc1 == loc2;
     return loc1.equals(loc2);
   }
   if (o instanceof XModelObjectEditorInput) {
     return object.equals(((XModelObjectEditorInput) o).getXModelObject());
   }
   return false;
 }
Esempio n. 8
0
 /**
  * The worker method. It will find the container, create the file if missing or just replace its
  * contents, and open the editor on the newly created file.
  */
 private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
     throws CoreException {
   // create a sample file
   monitor.beginTask("Creating " + fileName, 2);
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(containerName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     throwCoreException("Container \"" + containerName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = openContentStream();
     if (file.exists()) {
       file.setContents(stream, true, true, monitor);
     } else {
       file.create(stream, true, monitor);
     }
     stream.close();
   } catch (IOException e) {
   }
   monitor.worked(1);
   monitor.setTaskName("Opening file for editing...");
   getShell()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, file, true);
               } catch (PartInitException e) {
               }
             }
           });
   monitor.worked(1);
 }
Esempio n. 9
0
  /**
   * The worker method. It will create a new project, then create the appropriate Soar heirarchy and
   * files.
   */
  private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException {

    monitor.beginTask("Creating " + projectName, 7);

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject newProject = root.getProject(projectName);

    // creation of the project
    if (newProject.exists()) {
      throwCoreException("Project \"" + projectName + "\" already exists");
    } else {

      newProject.create(monitor);
      newProject.open(monitor);

      try {

        IProjectDescription description = newProject.getDescription();
        String[] natures = description.getNatureIds();
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = SoarProjectNature.NATURE_ID;
        description.setNatureIds(newNatures);

        newProject.setDescription(description, IResource.FORCE, monitor);

        newProject.setPersistentProperty(DataMap.VERTEX_ID, "0");

      } catch (CoreException e) {
        e.printStackTrace();
      } // catch
    } // else

    monitor.worked(2);

    // Create the contents of the project's root directory
    IFolder folderAll = newProject.getFolder("all");
    if (!folderAll.exists()) {
      folderAll.create(true, true, monitor);
    } // if
    FileMarker.markResource(folderAll, "file");

    IFolder folderElaborations = newProject.getFolder("elaborations");
    if (!folderElaborations.exists()) {
      folderElaborations.create(true, true, monitor);
    } // if
    FileMarker.markResource(folderElaborations, "file");

    IFile file_firstload = newProject.getFile("_firstload.soar");
    if (!file_firstload.exists()) {
      file_firstload.create(
          Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor);
    } // if
    FileMarker.markResource(file_firstload, "file");

    IFile filedatamap = newProject.getFile("datamap.xdm");
    if (!filedatamap.exists()) {
      filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor);
    } // if

    monitor.worked(3);

    // Create the contents of the elaborations folder
    IFile file_all = folderElaborations.getFile("_all.soar");
    if (!file_all.exists()) {
      file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor);
    } // if
    FileMarker.markResource(file_all, "file");

    IFile filetopstate = folderElaborations.getFile("top-state.soar");
    if (!filetopstate.exists()) {
      filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor);
    } // if
    FileMarker.markResource(filetopstate, "file");

    SourcingFile.createSourcingFile(newProject, monitor);

    newProject.close(monitor);
    newProject.open(monitor);

    monitor.worked(2);
    monitor.done();
  } // void doFinish(...)
Esempio n. 10
0
 public static String getPath(IFile file) {
   IPath p = file.getLocation();
   //		String s=p.toString();
   //		return getPath(s);
   return getPath(p);
 }
 public boolean exists() {
   IFile f = getFile();
   return f != null && f.exists();
 }
 public String getToolTipText() {
   IFile f = (IFile) EclipseResourceUtil.getResource(object);
   if (f != null && f.exists()) return f.getLocation().toString();
   return object.getPresentationString();
 }