Exemplo n.º 1
0
 /**
  * Creates a new file if the name is not <code>null</code> or a new blank file and opens it in the
  * browser.
  *
  * @param name The name of the default file or <code>null</code>.
  */
 void setBlankFile(String name) {
   fileToEdit = null;
   fileID = 0;
   boolean blank = false;
   if (name == null || name.trim().length() == 0) {
     blank = true;
     fileName = "New Blank File";
   } else fileName = name;
   TreeModel treeModel;
   if (blank) treeModel = TreeModelFactory.getTree();
   else {
     if (type == Editor.EXPERIMENT) treeModel = TreeModelFactory.getExperimentTree(name);
     else treeModel = TreeModelFactory.getTree();
   }
   browser.setTreeModel(treeModel);
   state = Editor.READY;
 }
Exemplo n.º 2
0
  /**
   * Sets the file to edit. If the file cannot be read by {@link TreeModelFactory#getTree()} then
   * the state of this model is re-set to {@link Editor#NEW}.
   *
   * @param file The file to edit.
   * @return See above.
   */
  boolean setFileToEdit(File file) {
    if (file == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }
    TreeModel treeModel = null;

    // try opening file as recognised OMERO.editor file (pro.xml or cpe.xml)
    try {
      treeModel = TreeModelFactory.getTree(file);
      fileToEdit = file;
    } catch (ParsingException e) {

      // may get a parsing exception simply because the file was not
      // recognised as Editor File..

      Registry reg = EditorAgent.getRegistry();
      UserNotifier un = reg.getUserNotifier();

      // ... try opening as ANY xml file
      try {
        treeModel = TreeModelFactory.getTreeXml(file);
        // if this worked, we have an XML file converted to cpe.xml
        // .. tell user..
        un.notifyInfo(
            "File not recognised",
            "File was converted from an unrecognised format into\n"
                + "OMERO.editor's cpe.xml format.\nOverwriting the "
                + "original file will erase the original XML format.");
        // must avoid overwriting the original file...
        // 'Save' won't work.
        if (fileID > 0) { // try to read a file downloaded
          file.delete();
        }
        fileToEdit = null;
        setFileAnnotationData(null);

      } catch (ParsingException ex) {

        LogMessage message = new LogMessage();
        message.print(ex);
        reg.getLogger().error(this, message);

        // ...and notify the user. Use the exception message.
        String errMsg = ex.getMessage();
        un.notifyInfo("File Failed to Open", errMsg);
      }
    }

    if (treeModel == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }

    fileName = file.getName();
    browser.setTreeModel(treeModel);
    state = Editor.READY;
    return true;
  }