@Override
 protected boolean initialize(Object element) {
   file = (IFile) element;
   try {
     if (!file.getProject().hasNature(CeylonNature.NATURE_ID)) {
       return false;
     }
   } catch (CoreException e) {
     e.printStackTrace();
     return false;
   }
   RefactoringProcessor processor = getProcessor();
   if (processor instanceof MoveProcessor) {
     MoveProcessor moveProcessor = (MoveProcessor) processor;
     for (Object e : moveProcessor.getElements()) {
       IResource r = null;
       if (e instanceof IResource) {
         r = (IResource) e;
       } else if (e instanceof ICompilationUnit) {
         r = ((ICompilationUnit) e).getResource();
       }
       if (r != null) {
         movingFiles.add(r);
       }
     }
     return file.getFileExtension() != null
         && (file.getFileExtension().equals("ceylon") || file.getFileExtension().equals("java"));
   } else {
     return false;
   }
 }
Example #2
0
 /**
  * return the IFile corresponding to the selection
  *
  * @param selectedObj selected file
  * @return
  */
 public static IFile getIFile(Object selectedObj) {
   IFile result = null;
   if (selectedObj instanceof IFile) {
     result = (IFile) selectedObj;
   }
   // Try to adapt
   if (result == null && selectedObj instanceof IAdaptable) {
     result = (IFile) ((IAdaptable) selectedObj).getAdapter(IFile.class);
   }
   // adapt in ifile
   if (result == null) {
     result = (IFile) Platform.getAdapterManager().getAdapter(selectedObj, IFile.class);
   }
   if (result == null) {
     // try to check if it is a collection
     Collection<?> collec =
         (Collection<?>) Platform.getAdapterManager().getAdapter(selectedObj, Collection.class);
     if (collec != null) {
       for (Object o : collec) {
         if (o instanceof IFile) {
           IFile f = (IFile) o;
           if ("di".equals(f.getFileExtension())) { // $NON-NLS-1$
             result = f;
             break;
           }
         }
       }
     }
   }
   return result != null && "di".equals(result.getFileExtension())
       ? result //$NON-NLS-1$
       : null;
 }
  /**
   * Given a <code>file</code> get an editor for it. If an editor has already been retrieved for the
   * given <code>file</code> then return the same already open editor.
   *
   * <p>When opening the editor it will also standardized the line endings to <code>\n</code>
   *
   * @param file open and return an editor for this
   * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
   */
  public AbstractTextEditor getEditor(IFile file) {
    AbstractTextEditor editor = (AbstractTextEditor) fFileToEditorMap.get(file);

    if (editor == null) {
      try {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        IEditorPart editorPart = null;
        if (file.getFileExtension().equals("js")) {
          editorPart = IDE.openEditor(page, file, true, true);
        } else if (file.getFileExtension().equals("html")) {
          editorPart =
              IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source", true);
        }

        if (editorPart instanceof AbstractTextEditor) {
          editor = (AbstractTextEditor) editorPart;
        } else {
          Assert.fail("Unable to open structured text editor");
        }

        if (editor != null) {
          standardizeLineEndings(editor);
          fFileToEditorMap.put(file, editor);
        } else {
          Assert.fail("Could not open editor for " + file);
        }
      } catch (Exception e) {
        Assert.fail("Could not open editor for " + file + " exception: " + e.getMessage());
      }
    }

    return editor;
  }
  /**
   * Load the model from the given file, if possible.
   *
   * @param modelFile The IFile which contains the persisted model
   */
  @SuppressWarnings("unchecked")
  private synchronized Properties updateModel(IFile modelFile) {

    if (PROPERTIES_EXT.equals(modelFile.getFileExtension())) {
      Properties model = new Properties();
      if (modelFile.exists()) {
        try {
          model.load(modelFile.getContents());

          String propertyName;
          List properties = new ArrayList();
          for (Enumeration names = model.propertyNames(); names.hasMoreElements(); ) {
            propertyName = (String) names.nextElement();
            properties.add(
                new PropertiesTreeData(propertyName, model.getProperty(propertyName), modelFile));
          }
          PropertiesTreeData[] propertiesTreeData =
              (PropertiesTreeData[]) properties.toArray(new PropertiesTreeData[properties.size()]);

          cachedModelMap.put(modelFile, propertiesTreeData);
          return model;
        } catch (IOException e) {
        } catch (CoreException e) {
        }
      } else {
        cachedModelMap.remove(modelFile);
      }
    }
    return null;
  }
  /**
   * @param spaceSummary
   * @return
   */
  public List<XWikiEclipsePageSummary> getPageSummaries(String wiki, String space)
      throws XWikiEclipseStorageException {
    final List<XWikiEclipsePageSummary> result = new ArrayList<XWikiEclipsePageSummary>();

    try {
      final IFolder pagesFolder = StorageUtils.createFolder(baseFolder.getFolder(PAGES_DIRECTORY));

      List<IResource> pageFolderResources = getChildResources(pagesFolder, IResource.DEPTH_ONE);
      for (IResource pageFolderResource : pageFolderResources) {
        if (pageFolderResource instanceof IFile) {
          IFile file = (IFile) pageFolderResource;
          if (file.getFileExtension().equals(PAGE_SUMMARY_FILE_EXTENSION)) {
            IFile pageSummaryFile = (IFile) pageFolderResource;
            XWikiEclipsePageSummary pageSummary;
            try {
              pageSummary =
                  (XWikiEclipsePageSummary)
                      StorageUtils.readFromJSON(
                          pageSummaryFile, XWikiEclipsePageSummary.class.getCanonicalName());
              if (pageSummary.getWiki().equals(wiki) && pageSummary.getSpace().equals(space)) {
                result.add(pageSummary);
              }
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        }
      }
    } catch (CoreException e) {
      throw new XWikiEclipseStorageException(e);
    }

    return result;
  }
  /**
   * Tries and find an Acceleo compiled module (emtl file) corresponding to the given module (mtl
   * file), then loads it as an EMF resource.
   *
   * @param moduleFile The module file of which we seek the compiled version.
   * @param resourceSet The resource set in which to load the module.
   * @return The Acceleo compiled module (emtl file) corresponding to the given module (mtl file).
   *     <code>null</code> if none.
   */
  private static Resource getModule(IFile moduleFile, ResourceSet resourceSet) {
    IFile compiledModule = null;
    if (IAcceleoConstants.MTL_FILE_EXTENSION.equals(moduleFile.getFileExtension())) {
      final IProject project = moduleFile.getProject();
      if (project != null) {
        final String compiledName =
            moduleFile
                .getFullPath()
                .removeFileExtension()
                .addFileExtension(IAcceleoConstants.EMTL_FILE_EXTENSION)
                .lastSegment();
        compiledModule = findChild(project, compiledName);
      }
    }

    Resource module = null;
    if (compiledModule != null) {
      String path = compiledModule.getFullPath().toString();
      for (Resource resource : resourceSet.getResources()) {
        if (resource.getURI().toString().equals(path)) {
          return resource;
        }
      }
      try {
        module =
            ModelUtils.load(URI.createPlatformResourceURI(path, true), resourceSet).eResource();
      } catch (IOException e) {
        // FIXME log
      }
    }
    return module;
  }
  public void init(IWorkbench workbench, IStructuredSelection selection) {
    boolean false_file = true;

    if (selection.getFirstElement() instanceof IFile) {
      IFile file = (IFile) selection.getFirstElement();
      reportFileName = file.getName();
      reportFile = file;
      if (file.getFileExtension().equals("rptdesign")) false_file = false;
    }

    if (false_file) {
      MessageDialog.openError(
          getShell(),
          "Wizzard Error", //$NON-NLS-1$
          "Das gewählte File ist kein MAXIMO-BIRT Report File (.rptdesign)!"); //$NON-NLS-1$

      // abort wizard. There is no clean way to do it.
      /**
       * Remove the exception here 'cause It's safe since the wizard won't create any file without
       * an open project.
       */
      throw new RuntimeException();
    }

    // OK

    this.selection = selection;
    setWindowTitle("New MAXIMO Report");
  }
 private void handleFileSelection(final Object object) {
   IFile file = (IFile) object;
   boolean isWarProduct = WARProductConstants.FILE_EXTENSION.equals(file.getFileExtension());
   if (isWarProduct) {
     loadProductFromFile(file);
   }
 }
Example #9
0
 public Image getImage(Object obj) {
   if (obj instanceof IFolder) {
     IFolder folder = (IFolder) obj;
     String name = folder.getName().toLowerCase();
     Image image = imageCache.get(name);
     if (image == null) {
       ImageDescriptor imageDesc = UIActivator.getImageDescriptor("icons/" + name + ".png");
       if (imageDesc != null) {
         image = imageDesc.createImage();
         imageCache.put(name, image);
         return image;
       }
     } else {
       return image;
     }
     // use the folder image as a default
     return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
   } else if (obj instanceof IFile) {
     IFile file = (IFile) obj;
     String fileExt = file.getFileExtension();
     Image image = imageCache.get(fileExt);
     if (image == null) {
       ImageDescriptor imageDesc =
           PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor("." + fileExt);
       image = imageDesc.createImage();
       imageCache.put(fileExt, image);
     }
     return image;
   } else {
     return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
   }
 }
Example #10
0
  /**
   * Propagates the markers of the given source file, to the corresponding file at the features
   * folder.
   *
   * @param sourceFile The composed file
   */
  public void addFile(IFile sourceFile) {
    String fileExtension = sourceFile.getFileExtension();
    if (fileExtension == null) {
      return;
    }
    if ("java".equals(fileExtension) || "c".equals(fileExtension) || "h".equals(fileExtension)) {
      if (!composedFiles.contains(sourceFile)) {
        addComposedFile(sourceFile);
      }
      if (job == null) {
        job =
            new Job("Propagate problem markers") {
              @Override
              public IStatus run(IProgressMonitor monitor) {
                propagateMarkers();
                return Status.OK_STATUS;
              }
            };
        job.setPriority(Job.SHORT);
        job.schedule();
      }

      if (job.getState() == Job.NONE) {
        job.schedule();
      }
    }
  }
Example #11
0
  public void runTestsObject(Object element) {
    IResource[] members;

    try {
      if (element instanceof IProject) { // if it is a project go deeper
        if (((IProject) element).isOpen()) { // and it is open
          log.debug("Calling recursive method for" + ((IProject) element).getFullPath());
          members = ((IProject) element).members();
          for (int index = 0; index < members.length; index++) this.runTestsObject(members[index]);
        }
      } else if (element instanceof IFolder) { // if it is a folder go deeper
        members = ((IFolder) element).members();
        log.debug("Calling recursive method for" + ((IFolder) element).getLocation().toOSString());
        for (int index = 0; index < members.length; index++) this.runTestsObject(members[index]);
      } else if (element instanceof IFile) { // if it is a file
        IFile ifile = (IFile) element;
        if (ifile.getFileExtension().equals("rsl")) {
          log.debug("Calling runTestCasesActiveFile on " + ifile.getFullPath());
          RunTestCasesActiveFile.runandprint(ifile);
        }
      } else // only projects, folders and rsl files are of interest
      return;

    } catch (CoreException e) {
      log.error(e.getMessage(), e);
    }
  }
 /**
  * Visits the given resource delta that corresponds to a file.
  *
  * @param delta The given resource delta
  * @param file The file concerning by this delta
  * @return <code>true</code> if the resource delta's children should be visited; <code>false
  *     </code> if they should be skipped.
  * @exception CoreException if the visit fails for some reason.
  */
 protected boolean visitFile(IResourceDelta delta, IFile currentFile) throws CoreException {
   // By default, we do not visit the resource delta's children
   boolean visitChildren = false;
   final Option<ModelingProject> optionalModelingProject =
       ModelingProject.asModelingProject(currentFile.getProject());
   if (optionalModelingProject.some()) {
     if (IResourceDelta.REMOVED == delta.getKind()) {
       if (optionalModelingProject.get().isValid()) {
         // Check that this IFile is not the main representations
         // file of this project
         if (optionalModelingProject.get().isMainRepresentationsFile(currentFile)) {
           mainRepresentationsFileToDelete.add(currentFile);
         }
       } else if (new FileQuery(currentFile).isSessionResourceFile()) {
         // If the project is not valid and the deleted file is a
         // representations file, validate the project again.
         optionalModelingProject
             .get()
             .getMainRepresentationsFileURI(new NullProgressMonitor(), true, false);
       }
     } else if (IResourceDelta.ADDED == delta.getKind()) {
       // Check that the corresponding project does not already
       // have a main representations file
       if (SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(currentFile.getFileExtension())) {
         if (optionalModelingProject.get().isValid()) {
           representationsFileToAddOnValidModelingProject.add(currentFile);
         }
       }
     }
   }
   return visitChildren;
 }
  @Override
  public boolean performFinish() {
    try {
      final IDocument doc =
          createDocument(typePage.getDocumentType(), typePage.getRootElementName());

      final Style style =
          VexPlugin.getDefault().getPreferences().getPreferredStyle(typePage.getDocumentType());
      if (style == null) {
        MessageDialog.openError(
            getShell(),
            Messages.getString("NewDocumentWizard.noStyles.title"),
            Messages.getString("NewDocumentWizard.noStyles.message")); // $NON-NLS-1$ //$NON-NLS-2$
        return false;
        // TODO: don't allow selection of types with no stylesheets
      }

      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      final DocumentWriter writer = new DocumentWriter();
      writer.setWhitespacePolicy(new CssWhitespacePolicy(style.getStyleSheet()));
      writer.write(doc, baos);
      baos.close();
      final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

      filePage.setInitialContents(bais);
      final IFile file = filePage.createNewFile();
      IDE.setDefaultEditor(file, VexEditor.ID);
      this.selectAndReveal(file);

      registerEditorForFilename("*." + file.getFileExtension(), VexEditor.ID); // $NON-NLS-1$

      // Open editor on new file.
      final IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
      if (dw != null) {
        final IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          IDE.openEditor(page, file, true);
        }
      }

      typePage.saveSettings();

      return true;

    } catch (final Exception ex) {
      final String message =
          MessageFormat.format(
              Messages.getString("NewDocumentWizard.errorLoading.message"),
              new Object[] {filePage.getFileName(), ex.getMessage()});
      VexPlugin.getDefault().log(IStatus.ERROR, message, ex);
      MessageDialog.openError(
          getShell(),
          Messages.getString("NewDocumentWizard.errorLoading.title"),
          "Unable to create " + filePage.getFileName()); // $NON-NLS-1$ //$NON-NLS-2$
      return false;
    }
  }
Example #14
0
 /**
  * Overriding superclass implementation. Checks whether the <code>IFile</code> representing the
  * BPEL module has a bpel file extension (weak validation).
  *
  * @see ModuleDelegate#validate()
  *     <p>TODO should also allow for BPEL projects being valid modules
  */
 @Override
 public IStatus validate() {
   super.validate();
   if (IBPELModuleFacetConstants.DOT_BPEL_FILE_EXTENSION.equalsIgnoreCase(
       file.getFileExtension())) {
     return Status.OK_STATUS;
   }
   return new Status(
       IStatus.ERROR, RuntimesPlugin.PLUGIN_ID, 0, Messages.InvalidFileExtension, null);
 }
 private void initValidationJob() {
   final IFile file = ((IFileEditorInput) getEditorInput()).getFile();
   validationJob = new SCTValidationJob(getDiagram());
   IExpressionLanguageProvider registeredProvider =
       ExpressionLanguageProviderExtensions.getRegisteredProvider(
           SemanticTarget.StatechartSpecification, file.getFileExtension());
   Injector injector = registeredProvider.getInjector();
   injector.injectMembers(validationJob);
   validationJob.setRule(file);
 }
 /**
  * Checks if the given <code>file</code> is accessible and its file extension is in the list of
  * allowed file extensions.
  */
 public final boolean isBeansConfig(IFile file) {
   if (file.isAccessible() && getAllowedFileExtensions().contains(file.getFileExtension())) {
     Set<IPath> rootPaths = getRootDirectories(file.getProject());
     for (IPath path : rootPaths) {
       if (path.isPrefixOf(file.getFullPath())) {
         return locateBeansConfigs(file.getProject(), null).contains(file);
       }
     }
   }
   return false;
 }
Example #17
0
 /**
  * Returns the corresponding error propagation class of the given file.
  *
  * @param file
  * @return The corresponding <code>ErrorPropagation</code>
  */
 @CheckForNull
 private ErrorPropagation getErrorPropagation(IFile file) {
   String fileExtension = file.getFileExtension();
   if ("java".equals(fileExtension)) {
     return new JavaErrorPropagation();
   }
   if ("c".equals(fileExtension) || "h".equals(fileExtension)) {
     return new CErrorPropagation();
   }
   return null;
 }
 private boolean isImageFile(IFile f) {
   for (String ext :
       Activator.getDefault()
           .getPreferenceStore()
           .getString(PreferenceConstants.FILE_EXTENSIONS)
           .split(PreferenceConstants.FILE_EXTENSIONS_SEPARATOR)) {
     if (ext.equals(f.getFileExtension())) {
       return true;
     }
   }
   return false;
 }
 boolean shouldValidate(IFile file) {
   IResource resource = file;
   do {
     if (resource.isDerived()
         || resource.isTeamPrivateMember()
         || !resource.isAccessible()
         || resource.getName().charAt(0) == '.') {
       return false;
     }
     resource = resource.getParent();
   } while ((resource.getType() & IResource.PROJECT) == 0);
   return fValidFileExts.isEmpty() || fValidFileExts.contains(file.getFileExtension());
 }
 public static void setChangeTextType(TextFileChange change, IFile file) {
   // null guard in case a folder gets passed for whatever reason
   String name = file.getName();
   if (name == null) return;
   // mark a plugin.xml or a fragment.xml as PLUGIN2 type so they will be compared
   // with the PluginContentMergeViewer
   String textType =
       name.equals(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR)
               || name.equals(ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR)
           ? "PLUGIN2" //$NON-NLS-1$
           : file.getFileExtension();
   // if the file extension is null, the setTextType method will use type "txt", so no null guard
   // needed
   change.setTextType(textType);
 }
 /** Return the model elements for a *.properties IFile or NO_CHILDREN for otherwise. */
 public Object[] getChildren(Object parentElement) {
   Object[] children = null;
   if (parentElement instanceof PropertiesTreeData) {
     children = NO_CHILDREN;
   } else if (parentElement instanceof IFile) {
     /* possible model file */
     IFile modelFile = (IFile) parentElement;
     if (PROPERTIES_EXT.equals(modelFile.getFileExtension())) {
       children = (PropertiesTreeData[]) cachedModelMap.get(modelFile);
       if (children == null && updateModel(modelFile) != null) {
         children = (PropertiesTreeData[]) cachedModelMap.get(modelFile);
       }
     }
   }
   return children != null ? children : NO_CHILDREN;
 }
Example #22
0
 /** @return whether an IFile is a valid source file given its extension */
 public static boolean isValidSourceFile(IFile file) {
   String ext = file.getFileExtension();
   if (ext == null) { // no extension
     return false;
   }
   ext = ext.toLowerCase();
   for (String end : FileTypesPreferencesPage.getValidSourceFiles()) {
     if (ext.equals(end)) {
       return true;
     }
   }
   if (ext.equals(".pypredef")) {
     return true;
   }
   return false;
 }
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated not
   */
  public RuleSet createRuleSet(String name, String version, List<IFile> ruleIFiles) {
    RuleSet ruleSet = createRuleSet();
    ruleSet.setName(name);
    ruleSet.setVersion(version);

    for (IFile iFile : ruleIFiles) {
      final String fileExtension = iFile.getFileExtension();
      AbstractRuleFileManager ruleFileManager =
          HandlerUtils.instance.getAbstractRuleFileManager(fileExtension);
      if (ruleFileManager != null) {
        RuleFile rFile = ruleFileManager.createRuleFile(iFile);
        ruleSet.getRuleFiles().add(rFile);
      }
    }

    return ruleSet;
  }
Example #24
0
 @Override
 public void run() {
   SaveAsDialog dialog = new SaveAsDialog(getWorkbenchPart().getSite().getShell());
   dialog.setOriginalName(Messages.ExportAction_JPEG_ORIGINAL_TITLE);
   dialog.create();
   dialog.setMessage(
       BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.message")); // $NON-NLS-1$
   dialog.setOriginalName(Messages.ExportAction_PNG_ORIGINAL_TITLE);
   dialog.open();
   IPath path = dialog.getResult();
   if (path != null) {
     IWorkspace workspace = ResourcesPlugin.getWorkspace();
     IFile file = workspace.getRoot().getFile(path);
     String ext = file.getFileExtension();
     if (ext == null
         || ext.length() == 0
         || !(ext.equalsIgnoreCase("jpg")
             || ext.equalsIgnoreCase("bmp")
             || ext.equalsIgnoreCase("png"))) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       ErrorDialog.openError(
           getWorkbenchPart().getSite().getShell(),
           BeansGraphPlugin.getResourceString("Editor.SaveError.title"),
           null,
           BeansGraphPlugin //$NON-NLS-1$
               .createErrorStatus(
               BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.error"))); // $NON-NLS-1$
     } else if (ext.equalsIgnoreCase("PNG")
         && !SpringCoreUtils.isEclipseSameOrNewer(3, 3)) { // $NON-NLS-1$
       ErrorDialog.openError(
           getWorkbenchPart().getSite().getShell(),
           Messages.ExportAction_ERROR_TITLE,
           Messages.ExportAction_ERROR_PNG_EXPORT_33_OR_NEWER,
           BeansGraphPlugin.createErrorStatus(
               BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.error"))); // $NON-NLS-1$
     } else {
       if ("PNG".equalsIgnoreCase(ext)) { // $NON-NLS-1$
         saveImage(file, SWT.IMAGE_PNG);
       } else if ("JPG".equalsIgnoreCase(ext)
           || "JPEG".equalsIgnoreCase(ext)) { // $NON-NLS-1$ //$NON-NLS-2$
         saveImage(file, SWT.IMAGE_JPEG);
       } else if ("BMP".equalsIgnoreCase(ext)) { // $NON-NLS-1$
         saveImage(file, SWT.IMAGE_BMP);
       }
     }
   }
 }
  @Override
  public void build(IBuildContext context) throws CoreException {

    try {

      IFile file = context.getFile();

      ModuleDeclaration module = getModuleDeclaration(context);

      if (file.getFileExtension().equals("php")) {
        module.traverse(new AnnotationVisitor(context));
      }

    } catch (Exception e) {

      Logger.logException(e);
    }
  }
  public List<XWikiEclipseClass> getClasses() throws Exception {
    List<XWikiEclipseClass> result = new ArrayList<XWikiEclipseClass>();

    List<IResource> classFolderResources =
        getChildResources(baseFolder.getFolder(CLASSES_DIRECTORY), IResource.DEPTH_ONE);
    for (IResource classFolderResource : classFolderResources) {
      if (classFolderResource instanceof IFile) {
        IFile file = (IFile) classFolderResource;
        if (file.getFileExtension().equals(CLASS_FILE_EXTENSION)) {
          XWikiEclipseClass clazz =
              (XWikiEclipseClass)
                  StorageUtils.readFromJSON(file, XWikiEclipseClass.class.getCanonicalName());
          result.add(clazz);
        }
      }
    }

    return result;
  }
Example #27
0
  private Project getProject() throws Exception {
    File file = runFile.getLocation().toFile();

    Project result;
    if ("bndrun".equals(runFile.getFileExtension())) {
      result = new Project(Central.getWorkspace(), file.getParentFile(), file);

      File bndbnd = new File(file.getParentFile(), Project.BNDFILE);
      if (bndbnd.isFile()) {
        Project parentProject = Workspace.getProject(file.getParentFile());
        result.setParent(parentProject);
      }
    } else if (Project.BNDFILE.equals(runFile.getName())) {
      result = Workspace.getProject(file.getParentFile());
    } else {
      throw new Exception("Invalid run file: " + runFile.getLocation());
    }
    return result;
  }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) {
      IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
      URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);

      URI rootURI = URI.createURI("classpath:/");
      FModel model = loader.loadModel(uri, rootURI);
      if (model != null) {
        if (!validator.hasErrors(model.eResource())) {
          ResourceSet resourceSet = new ResourceSetImpl();
          resourceSet
              .getResourceFactoryRegistry()
              .getExtensionToFactoryMap()
              .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
          int extensionIndex =
              file.getFullPath().toString().lastIndexOf("." + file.getFileExtension());
          String outputFilePath =
              file.getFullPath().toString().substring(0, extensionIndex) + ".xmi";
          URI fileURI = URI.createPlatformResourceURI(outputFilePath, true);
          Resource resource = resourceSet.createResource(fileURI);
          resource.getContents().add(model);

          try {
            resource.save(Collections.EMPTY_MAP);
            file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
          } catch (IOException e) {
            e.printStackTrace();
          } catch (CoreException e) {
            e.printStackTrace();
          }
        } else {
          SpecificConsole console = new SpecificConsole("Franca");
          console.getErr().println("Aborting XMI generation due to validation errors!");
        }
      }
    }
    return null;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang. Object)
  */
 @Override
 public Object[] getChildren(Object parent) {
   // log.debug("getChildren: {}", parent.toString());
   try {
     if (parent instanceof IFile) {
       IFile f = (IFile) parent;
       if (IResourceConstants.CROSSWALK_EXTENSION.equals(f.getFileExtension())) {
         Map<Integer, MetadataCompartment> results = new HashMap<Integer, MetadataCompartment>();
         IProject p = f.getProject();
         MetsProjectNature n = (MetsProjectNature) p.getNature(MetsProjectNature.NATURE_ID);
         Collection<MdSecType> mdSecs = METSUtils.getAllMdSecTypes(n.getMets());
         for (MdSecType mdSec : mdSecs) {
           if (f.getName().equals(mdSec.getGROUPID())) {
             // crosswalk record IDs end in underscore and row number
             String row = mdSec.getID().substring(mdSec.getID().lastIndexOf("_") + 1);
             Integer r = Integer.valueOf(Integer.parseInt(row));
             MetadataCompartment mc = null;
             if (results.get(Integer.valueOf(r)) == null) {
               mc = new MetadataCompartment();
               mc.row = r.intValue();
               results.put(r, mc);
             } else {
               mc = results.get(r);
             }
             mc.metadataSections.add(mdSec);
           }
         }
         return results.values().toArray();
       }
     } else if (parent instanceof MetadataCompartment) {
       MetadataCompartment mc = (MetadataCompartment) parent;
       return mc.metadataSections.toArray();
     }
   } catch (CoreException e) {
     throw new Error(e);
   }
   return EMPTY_ARRAY;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
   */
  public boolean visit(IResourceDelta delta) {

    IResource source = delta.getResource();
    switch (source.getType()) {
      case IResource.ROOT:
      case IResource.PROJECT:
      case IResource.FOLDER:
        return true;
      case IResource.FILE:
        final IFile file = (IFile) source;
        if (PROPERTIES_EXT.equals(file.getFileExtension())) {
          updateModel(file);
          new UIJob("Update Properties Model in CommonViewer") { // $NON-NLS-1$
            public IStatus runInUIThread(IProgressMonitor monitor) {
              if (viewer != null && !viewer.getControl().isDisposed()) viewer.refresh(file);
              return Status.OK_STATUS;
            }
          }.schedule();
        }
        return false;
    }
    return false;
  }