コード例 #1
0
  /**
   * Starts an asynchronous call to save the passed file back to the server.
   *
   * @param file The file to save.
   * @param asynch Pass <code>true</code> to save asynchronously, <code>false</code> otherwise.
   */
  void fireFileSaving(File file, boolean asynch) {
    boolean fileIsExp = browser.isModelExperiment();
    int fileType = (fileIsExp ? FileSaver.EXPERIMENT : FileSaver.PROTOCOL);

    saveFile(file);
    FileAnnotationData data = null;
    DataObject linkTo = parent;
    if (fileAnnotation != null) data = fileAnnotation;
    else data = new FileAnnotationData(file);
    if (data.getId() > 0) linkTo = null;
    String description = CPEsummaryExport.export(browser.getTreeModel());
    if (description != null) data.setDescription(description);

    if (asynch) {
      currentLoader = new FileSaver(component, ctx, file, data, fileType, linkTo);
      currentLoader.load();
      state = Editor.SAVING;
    } else {
      OmeroMetadataService svc = EditorAgent.getRegistry().getMetadataService();
      try {
        svc.archivedFile(ctx, fileAnnotation, file, fileType, linkTo);
      } catch (Exception e) {
        LogMessage msg = new LogMessage();
        msg.print("State: " + state);
        msg.print("Cannot save file back to server");
        msg.print(e);
        EditorAgent.getRegistry().getLogger().error(this, msg);
      }
    }
  }
コード例 #2
0
    /**
     * Opens a dialog box for users to enter a URL
     *
     * @see ActionListener#actionPerformed(ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
      JFrame f = EditorAgent.getRegistry().getTaskBar().getFrame();
      InputDialog dialog = new InputDialog(f, "Enter ID of Editor File on Server", "");

      int option = dialog.centerMsgBox();
      if (option == InputDialog.SAVE) {
        String newFileID = dialog.getText();

        // could check valid ID (integer) etc?
        if (EditorLinkParam.isLinkValidId(newFileID)) {
          attributeEdited(TextParam.PARAM_VALUE, newFileID);
        } else {
          UserNotifier un = EditorAgent.getRegistry().getUserNotifier();
          un.notifyInfo("Not valid ID", "Did not enter a valid Editor file ID");
        }
      }
    }
コード例 #3
0
 /** Creates an instance. Sets the Name, Description and Icon. */
 public GetIDAction() {
   boolean server = EditorAgent.isServerAvailable();
   putValue(Action.NAME, "File on Server");
   putValue(
       Action.SHORT_DESCRIPTION,
       server ? "Choose the ID of a file on the server." : "Server not available");
   putValue(Action.SMALL_ICON, editorLinkIcon);
   setEnabled(server);
 }
コード例 #4
0
  /**
   * This listener for the linkButton uses BareBonesBrowserLauncher, passing it URLlink.
   *
   * @see ActionListener#actionPerformed(ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {

    if (filePath != null) {

      File f = new File(filePath);
      // if link to local file that exists, open in Editor.
      if (f.exists()) EditorAgent.openLocalFile(f);
    } else if (fileID > 0) {
      /*TODO: review that work
      EventBus bus = MetadataViewerAgent.getRegistry().getEventBus();
      bus.post(new EditFileEvent(fileID));
      */
    }
  }
コード例 #5
0
 /**
  * Returns <code>true</code> if the user is the owner of the file, <code>false</code> otherwise.
  * If the file is <code>null</code>, return <code>true</code>.
  *
  * @return See above.
  */
 boolean isUserOwner() {
   if (fileAnnotation == null) return true;
   long userID = EditorAgent.getUserDetails().getId();
   return EditorUtil.isUserOwner(fileAnnotation, userID);
 }
コード例 #6
0
 /**
  * Creates a temporary file in the Editor Home Directory with the given fileName, sends the file
  * to the server by calling {@link #fireFileSaving(File)}, saving according to the current {@link
  * #fileAnnotation}.
  *
  * @param fileName The name of the file.
  * @param asynch Pass <code>true</code> to save asynchronously, <code>false</code> otherwise.
  */
 void fireFileSaving(String fileName, boolean asynch) {
   String filePath = EditorAgent.getEditorHome() + File.separator + fileName;
   File toEdit = new File(filePath);
   fireFileSaving(toEdit, asynch);
 }
コード例 #7
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;
  }