public void actionPerformed(ActionEvent event) {
   NodeModel selected = Controller.getCurrentController().getSelection().getSelected();
   if (selected == null) {
     return;
   } else {
     URI uri = URIUtils.getAbsoluteURI(selected);
     try {
       ReadOnlyExceptionWarningHandler warningHandler = new ReadOnlyExceptionWarningHandler();
       warningHandler.prepare();
       while (warningHandler.retry()) {
         try {
           PdfAnnotationImporter importer = new PdfAnnotationImporter();
           List<AnnotationModel> annotations = importer.importAnnotations(uri);
           MonitoringUtils.insertChildNodesFrom(annotations, selected.isLeft(), selected);
           warningHandler.consume();
         } catch (DocumentReadOnlyException e) {
           if (warningHandler.skip()) {
             break;
           }
           warningHandler.showDialog(URIUtils.getFile(uri));
         }
       }
     } catch (IOException e) {
       LogUtils.severe(
           "ImportAllAnnotationsAction IOException at URI(" + uri + "): ",
           e); //$NON-NLS-1$ //$NON-NLS-2$
     } catch (COSRuntimeException e) {
       LogUtils.severe(
           "ImportAllAnnotationsAction COSRuntimeException at URI(" + uri + "): ",
           e); //$NON-NLS-1$ //$NON-NLS-2$
     }
   }
 }
 public String getSettingsPath(DocearUser user) {
   return URIUtils.getAbsoluteFile(WorkspaceController.getApplicationSettingsHome()).getPath()
       + File.separator
       + "users"
       + File.separator
       + user.getName();
 }
Exemplo n.º 3
0
 public void refresh() {
   File folder;
   try {
     inRefresh = true;
     folder = URIUtils.getAbsoluteFile(getPath());
     if (folder.isDirectory()) {
       getModel().removeAllElements(this);
       loadDirectoryFiles(folder);
       getModel().reload(this);
     }
   } catch (Exception e) {
     LogUtils.severe(e);
   } finally {
     inRefresh = false;
   }
 }
Exemplo n.º 4
0
 public WorkspaceTransferable getTransferable() {
   WorkspaceTransferable transferable = new WorkspaceTransferable();
   try {
     URI uri = URIUtils.getAbsoluteURI(getPath());
     transferable.addData(WorkspaceTransferable.WORKSPACE_URI_LIST_FLAVOR, uri.toString());
     List<File> fileList = new Vector<File>();
     fileList.add(new File(uri));
     transferable.addData(WorkspaceTransferable.WORKSPACE_FILE_LIST_FLAVOR, fileList);
     if (!this.isSystem()) {
       List<AWorkspaceTreeNode> objectList = new ArrayList<AWorkspaceTreeNode>();
       objectList.add(this);
       transferable.addData(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR, objectList);
     }
     return transferable;
   } catch (Exception e) {
     LogUtils.warn(e);
   }
   return null;
 }
  /**
   * ********************************************************************************* REQUIRED
   * METHODS FOR INTERFACES
   * ********************************************************************************
   */
  public void handleAction(WorkspaceActionEvent event) {
    if (event.getType() == WorkspaceActionEvent.MOUSE_LEFT_DBLCLICK) {
      try {
        AWorkspaceProject project = WorkspaceController.getSelectedProject(this);
        File f = URIUtils.getAbsoluteFile(getLinkURI());
        if (f == null) {
          return;
        }
        if (!f.exists()) {
          if (WorkspaceNewMapAction.createNewMap(project, f.toURI(), getName(), true) == null) {
            LogUtils.warn("could not create " + getLinkURI());
          }
        }

        Controller.getCurrentController().selectMode(MModeController.MODENAME);
        final MapIO mapIO = (MapIO) MModeController.getMModeController().getExtension(MapIO.class);

        try {
          if (mapIO.newMap(f.toURI().toURL())) {
            DocearEvent evnt =
                new DocearEvent(
                    this,
                    (DocearWorkspaceProject) project,
                    DocearEventType.NEW_MY_PUBLICATIONS,
                    Controller.getCurrentController().getMap());
            DocearController.getController().getEventQueue().dispatchEvent(evnt);
          }
        } catch (Exception e) {
          LogUtils.severe(e);
          return;
        }
      } catch (Exception e) {
        LogUtils.warn("could not open document (" + getLinkURI() + ")", e);
      }
    } else if (event.getType() == WorkspaceActionEvent.MOUSE_RIGHT_CLICK) {
      showPopup((Component) event.getBaggage(), event.getX(), event.getY());
    } else {
      // do nth for now
    }
  }
Exemplo n.º 6
0
  public boolean changeName(String newName, boolean renameLink) {
    assert (newName != null);
    assert (newName.trim().length() > 0);

    if (renameLink) {
      File oldFile = URIUtils.getAbsoluteFile(getPath());
      try {
        if (oldFile == null) {
          throw new Exception("failed to resolve the file for" + getName());
        }
        File destFile = new File(oldFile.getParentFile(), newName);
        if (oldFile.exists() && oldFile.renameTo(destFile)) {
          // this.setName(newName);
          try {
            getModel().changeNodeName(this, newName);
            return true;
          } catch (Exception ex) {
            destFile.renameTo(oldFile);
            return false;
          }
        } else {
          LogUtils.warn("cannot rename " + oldFile.getName());
        }
      } catch (Exception e) {
        LogUtils.warn("cannot rename " + oldFile.getName(), e);
      }
    } else {
      // this.setName(newName);
      try {
        getModel().changeNodeName(this, newName);
        return true;
      } catch (Exception ex) {
        // do nth.
      }
    }
    return false;
  }
Exemplo n.º 7
0
 private void createIfNeeded(URI uri) {
   File file = URIUtils.getAbsoluteFile(uri);
   if (file != null && !file.exists()) {
     file.mkdirs();
   }
 }
Exemplo n.º 8
0
 public File getFile() {
   return URIUtils.getAbsoluteFile(this.getPath());
 }