/**
  * Implemented as specified by the {@link Importer} interface.
  *
  * @see Importer#activate(int, TreeImageDisplay, Collection)
  */
 public void activate(
     int type, TreeImageDisplay selectedContainer, Collection<TreeImageDisplay> objects) {
   if (model.getState() == DISCARDED) return;
   if (chooser == null) {
     chooser =
         new ImportDialog(
             view,
             model.getSupportedFormats(),
             selectedContainer,
             objects,
             type,
             ImporterAgent.getAvailableUserGroups());
     chooser.addPropertyChangeListener(controller);
     view.addComponent(chooser);
   } else {
     ExperimenterData exp = ImporterAgent.getUserDetails();
     chooser.reset(selectedContainer, objects, type, model.getGroupId(), exp.getId());
     chooser.requestFocusInWindow();
     view.selectChooser();
   }
   chooser.setSelectedGroup(getSelectedGroup());
   if (model.isMaster() || objects == null || objects.size() == 0)
     refreshContainers(new ImportLocationDetails(type));
   // load available disk space
   model.fireDiskSpaceLoading();
   view.setOnScreen();
   view.toFront();
 }
 /** Browses the node or the data object. */
 private void browse() {
   EventBus bus = ImporterAgent.getRegistry().getEventBus();
   Object d = dataset;
   if (dataset == null || data instanceof ScreenData) d = data;
   if (d == null) return;
   bus.post(new BrowseContainer(d, null));
 }
  /**
   * Implemented as specified by the {@link Importer} interface.
   *
   * @see Importer#getSelectedGroup()
   */
  public GroupData getSelectedGroup() {
    Collection<GroupData> m = loadGroups();

    if (m == null) {
      ExperimenterData exp = ImporterAgent.getUserDetails();
      return exp.getDefaultGroup();
    }

    long id = model.getGroupId();

    for (GroupData group : m) {
      if (group.getId() == id) return group;
    }
    ExperimenterData exp = ImporterAgent.getUserDetails();
    return exp.getDefaultGroup();
  }
  /**
   * Returns the sorted list of groups the current user has access to
   *
   * @return see above.
   */
  private Collection<GroupData> loadGroups() {
    Collection set = ImporterAgent.getAvailableUserGroups();

    if (set == null || set.size() <= 1) return null;

    ViewerSorter sorter = new ViewerSorter();
    List<GroupData> sortedGroups = sorter.sort(set);

    return sortedGroups;
  }
 /**
  * Imports the data for the specified import view.
  *
  * @param element The import view.
  */
 private void importData(ImporterUIElement element) {
   if (element == null) return;
   view.setSelectedPane(element, true);
   model.fireImportData(element.getData(), element.getID());
   if (!model.isMaster()) {
     EventBus bus = ImporterAgent.getRegistry().getEventBus();
     bus.post(new ImportStatusEvent(true, element.getExistingContainers()));
     fireStateChange();
   }
 }
 /**
  * Indicates that the group has been successfully switched if <code>true</code>, unsuccessfully if
  * <code>false</code>.
  *
  * @param success Pass <code>true</code> if successful, <code>false</code> otherwise.
  */
 void onGroupSwitched(boolean success) {
   if (!model.isMaster()) return;
   if (!success) return;
   ExperimenterData exp = ImporterAgent.getUserDetails();
   GroupData group = exp.getDefaultGroup();
   long oldGroup = model.getGroupId();
   model.setGroupId(group.getId());
   ImportLocationDetails details = new ImportLocationDetails(chooser.getType());
   refreshContainers(details);
   firePropertyChange(CHANGED_GROUP_PROPERTY, oldGroup, model.getGroupId());
 }
  /** Refreshes the view when a user reconnects. */
  void onReconnected() {
    ExperimenterData exp = ImporterAgent.getUserDetails();
    GroupData group = exp.getDefaultGroup();
    long oldGroup = -1;
    if (model.getExperimenterId() == exp.getId() && group.getId() == model.getGroupId()) return;
    view.reset();
    model.setGroupId(group.getId());

    ImportLocationDetails info = new ImportLocationDetails(chooser.getType());
    refreshContainers(info);
    firePropertyChange(CHANGED_GROUP_PROPERTY, oldGroup, model.getGroupId());
  }
 /**
  * Implemented as specified by the {@link Importer} interface.
  *
  * @see Importer#importData(ImportableObject)
  */
 public void importData(ImportableObject data) {
   if (model.getState() == DISCARDED) return;
   if (data == null || data.getFiles() == null || data.getFiles().size() == 0) {
     UserNotifier un = ImporterAgent.getRegistry().getUserNotifier();
     un.notifyInfo("Import", "No Files to import.");
     return;
   }
   view.showRefreshMessage(chooser.isRefreshLocation());
   if (data.hasNewTags()) model.setTags(null);
   ImporterUIElement element = view.addImporterElement(data);
   if (model.getState() == IMPORTING) return;
   importData(element);
 }
 /**
  * Implemented as specified by the {@link Importer} interface.
  *
  * @see Importer#close()
  */
 public void close() {
   if (model.isMaster()) {
     EventBus bus = ImporterAgent.getRegistry().getEventBus();
     bus.post(new ExitApplication());
     return;
   }
   Collection<ImporterUIElement> list = view.getImportElements();
   List<ImporterUIElement> toImport = new ArrayList<ImporterUIElement>();
   if (list == null || list.size() == 0) {
     view.setVisible(false);
     return;
   }
   Iterator<ImporterUIElement> i = list.iterator();
   ImporterUIElement element;
   ImporterUIElement started = null;
   while (i.hasNext()) {
     element = i.next();
     if (element.hasStarted()) started = element;
     if (!element.isDone()) toImport.add(element);
   }
   if (toImport.size() > 0) {
     MessageBox box =
         new MessageBox(
             view,
             CANCEL_TITLE,
             CANCEL_TEXT
                 + "\n"
                 + "If Yes, the window will close when the on-going "
                 + "import is completed.");
     if (box.centerMsgBox() == MessageBox.NO_OPTION) return;
     markToclose = true;
     i = toImport.iterator();
     while (i.hasNext()) {
       element = i.next();
       element.cancelLoading();
       // if (!element.hasStarted())
       model.cancel(element.getID());
     }
     if (started != null && started.isDone()) {
       markToclose = false;
     }
   } else markToclose = false;
   if (!markToclose) view.setVisible(false);
 }
 /**
  * Implemented as specified by the {@link Importer} interface.
  *
  * @see Importer#logOff()
  */
 public void logOff() {
   if (model.getState() == IMPORTING) return;
   Registry reg = ImporterAgent.getRegistry();
   reg.getEventBus().post(new LogOff());
 }