Beispiel #1
0
  /** Modifies the existing password. */
  private void changePassword() {
    UserNotifier un;
    if (!oldPassword.isVisible()) {
      StringBuffer buf = new StringBuffer();
      buf.append(passwordNew.getPassword());
      String newPass = buf.toString();
      if (newPass == null || newPass.length() == 0) {
        un = MetadataViewerAgent.getRegistry().getUserNotifier();
        un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please enter the new password.");
        passwordNew.requestFocus();
        return;
      }
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Password changed.");
      passwordNew.setText("");
      model.resetPassword(newPass);
      return;
    }
    StringBuffer buf = new StringBuffer();
    buf.append(passwordNew.getPassword());
    String newPass = buf.toString();

    String pass = buf.toString();
    buf = new StringBuffer();
    buf.append(passwordConfirm.getPassword());
    String confirm = buf.toString();

    buf = new StringBuffer();
    buf.append(oldPassword.getPassword());
    String old = buf.toString();
    if (old == null || old.trim().length() == 0) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please specify your old password.");
      oldPassword.requestFocus();
      return;
    }
    if (newPass == null || newPass.length() == 0) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please enter your new password.");
      passwordNew.requestFocus();
      return;
    }

    if (pass == null || confirm == null || confirm.length() == 0 || !pass.equals(confirm)) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(
          PASSWORD_CHANGE_TITLE, "The passwords entered do not match. " + "Please try again.");
      passwordNew.setText("");
      passwordConfirm.setText("");
      passwordNew.requestFocus();
      return;
    }
    model.changePassword(old, confirm);
  }
 /**
  * Creates or recycles the existing figure dialog.
  *
  * @param name The name to display.
  * @param pixels The pixels object of reference.
  * @param index One of the constants defined by this class.
  * @return See above.
  */
 FigureDialog createFigureDialog(String name, PixelsData pixels, int index) {
   if (figureDialog != null) return figureDialog;
   UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();
   if (FigureDialog.needPixels(index) && pixels == null) {
     un.notifyInfo("Figure", "The image is not valid," + " cannot create the figure.");
     return null;
   }
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   figureDialog = new FigureDialog(f, name, pixels, index, view.getRefObject().getClass());
   figureDialog.addPropertyChangeListener(this);
   return figureDialog;
 }
Beispiel #3
0
 /**
  * Returns <code>true</code> if the user is an administrator, <code>false</code> otherwise.
  *
  * @return See above.
  */
 private boolean isUserAdministrator() {
   ExperimenterData user = (ExperimenterData) model.getRefObject();
   ExperimenterData loggedInUser = MetadataViewerAgent.getUserDetails();
   if (user.getId() == loggedInUser.getId()) return MetadataViewerAgent.isAdministrator();
   List<GroupData> groups = user.getGroups();
   Iterator<GroupData> i = groups.iterator();
   GroupData g;
   while (i.hasNext()) {
     g = i.next();
     if (GroupData.SYSTEM.equals(g.getName())) return true;
   }
   return false;
 }
  /** Brings up the folder chooser. */
  private void export() {
    DowngradeChooser chooser =
        new DowngradeChooser(
            new RefWindow(),
            FileChooser.SAVE,
            "Export",
            "Select where to export the image as OME-TIFF.",
            exportFilters);
    try {
      String path =
          MetadataViewerAgent.getRegistry()
              .getTaskBar()
              .getLibFileRelative(TransformsParser.SPECIFICATION + ".jar");
      chooser.parseData(path);
    } catch (Exception e) {
      LogMessage msg = new LogMessage();
      msg.print(e);
      MetadataViewerAgent.getRegistry().getLogger().debug(this, msg);
    }
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0) chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Export");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.EXPORT_AS_OMETIFF_48));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              File[] files = (File[]) evt.getNewValue();
              File folder = files[0];
              if (folder == null) folder = UIUtilities.getDefaultFolder();
              Object src = evt.getSource();
              Target target = null;
              if (src instanceof DowngradeChooser) {
                ((FileChooser) src).setVisible(false);
                ((FileChooser) src).dispose();
                target = ((DowngradeChooser) src).getSelectedSchema();
              }
              model.exportImageAsOMETIFF(folder, target);
            } else if (DowngradeChooser.HELP_DOWNGRADE_PROPERTY.equals(name)) {
              Registry reg = MetadataViewerAgent.getRegistry();
              String url = (String) reg.lookup("HelpDowngrade");
              reg.getTaskBar().openURL(url);
            }
          }
        });
    chooser.centerDialog();
  }
  /**
   * Fires an asynchronous call to update the passed group.
   *
   * @param data The object to update.
   * @param asynch Pass <code>true</code> to save data asynchronously, <code>false</code> otherwise.
   */
  void fireAdminSaving(AdminObject data, boolean asynch) {
    SecurityContext c = ctx;
    if (MetadataViewerAgent.isAdministrator()) c = getAdminContext();

    MetadataLoader loader;
    GroupData group = data.getGroup();

    switch (data.getIndex()) {
      case AdminObject.UPDATE_GROUP:
        loaderID++;
        loader =
            new GroupEditor(
                component, c, group, data.getPermissions(), loaderID, GroupEditor.UPDATE);
        loaders.put(loaderID, loader);
        loader.load();
        state = MetadataViewer.SAVING;
        break;
      case AdminObject.UPDATE_EXPERIMENTER:
        loaderID++;
        loader = new AdminEditor(component, c, data.getGroup(), data.getExperimenters(), loaderID);
        loaders.put(loaderID, loader);
        loader.load();
        state = MetadataViewer.SAVING;
    }
  }
  /** Opens the file. */
  private void openFile() {
    if (!(data instanceof FileAnnotationData)) return;

    FileAnnotationData fa = (FileAnnotationData) data;
    Registry reg = MetadataViewerAgent.getRegistry();
    UserNotifier un = reg.getUserNotifier();
    OriginalFile f = (OriginalFile) fa.getContent();
    Environment env = (Environment) reg.lookup(LookupNames.ENV);
    DownloadAndLaunchActivityParam activity;
    final long dataId = fa.getId();
    final File dir =
        new File(env.getOmeroFilesHome() + File.separatorChar + "file annotation " + dataId);
    if (!dir.exists()) {
      dir.mkdir();
    }
    if (f != null && f.isLoaded()) {
      activity = new DownloadAndLaunchActivityParam(f, dir, null);
    } else {
      activity =
          new DownloadAndLaunchActivityParam(
              dataId, DownloadAndLaunchActivityParam.FILE_ANNOTATION, dir, null);
    }
    un.notifyActivity(model.getSecurityContext(), activity);
    return;
  }
Beispiel #7
0
 /** Brings up the dialog to choose the photo to upload. */
 private void uploadPicture() {
   UploadPictureDialog d =
       new UploadPictureDialog(MetadataViewerAgent.getRegistry().getTaskBar().getFrame());
   d.addPropertyChangeListener(this);
   d.pack();
   UIUtilities.centerAndShow(d);
 }
  /** Brings up the folder chooser. */
  private void download() {
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    FileChooser chooser =
        new FileChooser(
            f,
            FileChooser.FOLDER_CHOOSER,
            "Download",
            "Select where to download the file.",
            null,
            true);
    chooser.setSelectedFileFull(view.getRefObjectName());
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
    chooser.setApproveButtonText("Download");
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              String path = (String) evt.getNewValue();
              if (path == null) {
                path = UIUtilities.getDefaultFolderAsString();
              }
              if (!path.endsWith(File.separator)) path += File.separator;
              model.download(new File(path));
            }
          }
        });
    chooser.centerDialog();
  }
 /**
  * Sets the rendering settings associated to the image.
  *
  * @param viewedBy The value to set.
  */
 void setViewedBy(Map viewedBy) {
   Map m = new LinkedHashMap();
   if (viewedBy != null) {
     long id = MetadataViewerAgent.getUserDetails().getId();
     Entry entry;
     Iterator i = viewedBy.entrySet().iterator();
     ExperimenterData exp;
     while (i.hasNext()) {
       entry = (Entry) i.next();
       exp = (ExperimenterData) entry.getKey();
       if (exp.getId() == id) {
         m.put(exp, entry.getValue());
       }
     }
     i = viewedBy.entrySet().iterator();
     while (i.hasNext()) {
       entry = (Entry) i.next();
       exp = (ExperimenterData) entry.getKey();
       if (exp.getId() != id) {
         m.put(exp, entry.getValue());
       }
     }
   }
   this.viewedBy = m;
 }
 /**
  * Adds a new attachment.
  *
  * @param file The attachment to add.
  */
 public void addAttachment(FileAnnotationData file) {
   long userID = MetadataViewerAgent.getUserDetails().getId();
   if (time == null) {
     time = file.getLastModified();
     resultsButton.setToolTipText("Analysis run " + UIUtilities.formatTime(time));
   }
   if (file.getOwner().getId() == userID) deleteButton.setVisible(true);
   if (!attachments.contains(file)) attachments.add(file);
 }
 /** Launches a dialog to select the file to attach to the <code>DataObject</code>. */
 private void selectFileToAttach() {
   JFrame owner = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   FileChooser chooser =
       new FileChooser(
           owner, FileChooser.LOAD, "Choose File", "Select the file to attach.", filters, true);
   chooser.setMultiSelectionEnabled(true);
   IconManager icons = IconManager.getInstance();
   chooser.setTitleIcon(icons.getIcon(IconManager.ATTACHMENT_48));
   chooser.setApproveButtonText("Attach");
   chooser.addPropertyChangeListener(FileChooser.APPROVE_SELECTION_PROPERTY, this);
   UIUtilities.centerAndShow(chooser);
 }
 /** Adds or edits the description of the tag. */
 private void editDescription() {
   if (!(data instanceof AnnotationData)) return;
   String text = model.getAnnotationDescription((AnnotationData) data);
   originalDescription = text;
   SwingUtilities.convertPointToScreen(popupPoint, this);
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   int type = EditorDialog.EDIT_TYPE;
   if (isModulo) type = EditorDialog.VIEW_TYPE;
   EditorDialog d = new EditorDialog(f, (AnnotationData) data, false, type);
   if (isModulo) d.allowEdit(false);
   d.addPropertyChangeListener(this);
   d.setOriginalDescription(originalDescription);
   d.setSize(300, 250);
   UIUtilities.showOnScreen(d, popupPoint);
 }
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      File[] files = (File[]) evt.getNewValue();
      File folder = files[0];
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      if (attachments == null || attachments.size() == 0) return;
      IconManager icons = IconManager.getInstance();
      DownloadAndZipParam param =
          new DownloadAndZipParam(attachments, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // TODO: review
      // un.notifyActivity(param);
    }
  }
 /** Brings up a dialog so that the user can select where to download the file. */
 private void download() {
   String name = null;
   if (data instanceof FileAnnotationData) {
     name = ((FileAnnotationData) data).getFileName();
   }
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   FileChooser chooser =
       new FileChooser(
           f, FileChooser.SAVE, "Download", "Select where to download the files.", null, true);
   if (name != null && name.trim().length() > 0) chooser.setSelectedFileFull(name);
   IconManager icons = IconManager.getInstance();
   chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
   chooser.setApproveButtonText("Download");
   chooser.addPropertyChangeListener(this);
   chooser.centerDialog();
 }
 /**
  * Creates a new object and sets its state to {@link MetadataViewer#NEW}.
  *
  * @param refObject The reference object.
  * @param index One of the rendering constants defined by the <code>MetadataViewer</code> I/F.
  */
 MetadataViewerModel(Object refObject, int index) {
   state = MetadataViewer.NEW;
   switch (index) {
     case MetadataViewer.RND_GENERAL:
     case MetadataViewer.RND_SPECIFIC:
       this.index = index;
       break;
     default:
       this.index = MetadataViewer.RND_GENERAL;
   }
   this.refObject = refObject;
   loaderID = 0;
   loaders = new HashMap<Integer, MetadataLoader>();
   data = null;
   dataType = null;
   singleMode = true;
   userID = MetadataViewerAgent.getUserDetails().getId();
 }
Beispiel #16
0
 /**
  * Selects or not the {@link #ownerBox} if the selected user is an owner. Returns <code>true
  * </code> if the currently logged in user is an owner of the group.
  *
  * @param group The group to handle.
  */
 private boolean setGroupOwner(GroupData group) {
   ExperimenterData ref = (ExperimenterData) model.getRefObject();
   long userID = MetadataViewerAgent.getUserDetails().getId();
   Set leaders = group.getLeaders();
   ExperimenterData exp;
   boolean isOwner = false;
   if (leaders != null) {
     Iterator i = leaders.iterator();
     while (i.hasNext()) {
       exp = (ExperimenterData) i.next();
       if (exp.getId() == ref.getId()) {
         groupOwner = true;
         ownerBox.setSelected(true);
       }
       if (exp.getId() == userID) isOwner = true;
     }
   }
   return isOwner;
 }
Beispiel #17
0
 /** Builds and lays out the UI. */
 void buildGUI() {
   removeAll();
   initComponents();
   setLayout(new GridBagLayout());
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.anchor = GridBagConstraints.WEST;
   c.insets = new Insets(0, 2, 2, 0);
   c.gridx = 0;
   c.gridy = 0;
   c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
   c.weightx = 1.0;
   add(buildContentPanel(), c);
   if (model.isUserOwner(model.getRefObject()) || MetadataViewerAgent.isAdministrator()) {
     c.gridy++;
     add(Box.createVerticalStrut(5), c);
     c.gridy++;
     add(buildPasswordPanel(), c);
   }
 }
  /** Brings up the folder chooser to select where to save the files. */
  private void saveAsJPEG() {
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    FileChooser chooser =
        new FileChooser(
            f,
            FileChooser.FOLDER_CHOOSER,
            "Save As",
            "Select where to save locally the images as JPEG.",
            saveAsFilters);
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0) chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Save");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.SAVE_AS_48));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              // File[] files = (File[]) evt.getNewValue();
              String value = (String) evt.getNewValue();
              File folder = null; // files[0];
              if (value == null || value.trim().length() == 0)
                folder = UIUtilities.getDefaultFolder();
              else folder = new File(value);
              Object src = evt.getSource();
              if (src instanceof FileChooser) {
                ((FileChooser) src).setVisible(false);
                ((FileChooser) src).dispose();
              }
              model.saveAs(folder);
            }
          }
        });
    chooser.centerDialog();
  }
 /**
  * Posts an event to view the protocol.
  *
  * @param protocolID The id of the protocol to view.
  */
 private void viewProtocol(long protocolID) {
   EventBus bus = MetadataViewerAgent.getRegistry().getEventBus();
   bus.post(new EditFileEvent(model.getSecurityContext(), protocolID));
 }
 /**
  * Posts an event to view the image.
  *
  * @param imageID The id of the image to view.
  */
 private void viewImage(long imageID) {
   EventBus bus = MetadataViewerAgent.getRegistry().getEventBus();
   bus.post(new ViewImage(model.getSecurityContext(), new ViewImageObject(imageID), null));
 }
 /**
  * Returns the user currently logged in.
  *
  * @return See above.
  */
 ExperimenterData getCurrentUser() {
   return MetadataViewerAgent.getUserDetails();
 }
 /** Launches RAPID. */
 private void openFLIM() {
   String url = (String) MetadataViewerAgent.getRegistry().lookup(LookupNames.RAPID);
   MetadataViewerAgent.getRegistry().getTaskBar().openURL(url);
 }
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
      // reset text and tooltip
      String text = "";
      String description = "";
      AnnotationData annotation = null;
      if (data instanceof TagAnnotationData
          || data instanceof TermAnnotationData
          || data instanceof XMLAnnotationData) {
        annotation = (AnnotationData) data;
        text = annotation.getContentAsString();
        text = EditorUtil.truncate(text, TEXT_LENGTH, false);
      }
      if (data instanceof DoubleAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((DoubleAnnotationData) data).getDataValue();
      }
      if (data instanceof LongAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((LongAnnotationData) data).getDataValue();
      }
      if (data instanceof BooleanAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((BooleanAnnotationData) data).getValue();
      }
      description = model.getAnnotationDescription(annotation);
      if (annotation == null) return;
      label.setText(text);
      label.setToolTipText(formatToolTip(annotation, null));
      originalName = text;
      originalDescription = description;
      firePropertyChange(AnnotationUI.EDIT_TAG_PROPERTY, null, this);
    } else if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      if (data == null) return;
      FileAnnotationData fa = (FileAnnotationData) data;
      OriginalFile f = (OriginalFile) fa.getContent();
      File folder;
      Object o = evt.getNewValue();
      if (o instanceof String) {
        String path = (String) o;
        if (!path.endsWith(File.separator)) {
          path += File.separator;
        }
        path += fa.getFileName();
        folder = new File(path);
      } else {
        File[] files = (File[]) o;
        folder = files[0];
      }
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      IconManager icons = IconManager.getInstance();

      DownloadActivityParam activity =
          new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // Check Name space
      activity.setLegend(fa.getDescription());
      un.notifyActivity(model.getSecurityContext(), activity);
    }
  }
Beispiel #24
0
  /**
   * Returns the experimenter to save.
   *
   * @return See above.
   */
  Object getExperimenterToSave() {
    ExperimenterData original = (ExperimenterData) model.getRefObject();
    // Required fields first

    String v = loginArea.getText();
    if (v == null || v.trim().length() == 0) showRequiredField();
    original.setLastName(v);
    JTextField f = items.get(EditorUtil.EMAIL);
    v = f.getText();
    if (v == null || v.trim().length() == 0) v = ""; // showRequiredField();
    original.setEmail(v);
    f = items.get(EditorUtil.INSTITUTION);
    v = f.getText();
    if (v == null) v = "";
    original.setInstitution(v.trim());
    f = items.get(EditorUtil.LAST_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setLastName(v.trim());

    f = items.get(EditorUtil.FIRST_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setFirstName(v.trim());

    f = items.get(EditorUtil.MIDDLE_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setMiddleName(v.trim());

    // set the groups
    GroupData g = null;
    /*

     	if (selectedIndex != originalIndex) {
     		if (selectedIndex < groupData.length)
     			g = groupData[selectedIndex];
     		ExperimenterData user = (ExperimenterData) model.getRefObject();
     		List userGroups = user.getGroups();
     		List<GroupData> newGroups = new ArrayList<GroupData>();
     		if (g != null) newGroups.add(g);
     		Iterator i = userGroups.iterator();
     		long id = -1;
     		if (g != null) id = g.getId();
     		GroupData group;
     		while (i.hasNext()) {
    	group = (GroupData) i.next();
    	if (group.getId() != id)
    		newGroups.add(group);
    }
     		//Need to see what to do b/c no ExperimenterGroupMap
     		original.setGroups(newGroups);
     	}
     	*/
    String value = loginArea.getText().trim();
    UserCredentials uc = new UserCredentials(value, "");
    Boolean b = ownerBox.isSelected();
    // if (g == null) g = original.getDefaultGroup();
    boolean a = false;
    if (b.compareTo(groupOwner) != 0) {
      a = true;
      uc.setOwner(b);
      Object parent = model.getParentRootObject();
      if (parent instanceof GroupData) {
        Map<GroupData, Boolean> map = new HashMap<GroupData, Boolean>();
        map.put((GroupData) parent, b);
        uc.setGroupsOwner(map);
      }
    }
    if (adminBox.isVisible()) {
      b = adminBox.isSelected();
      if (b.compareTo(admin) != 0) {
        a = true;
        uc.setAdministrator(b);
      }
    }
    if (activeBox.isVisible()) {
      b = activeBox.isSelected();
      if (b.compareTo(active) != 0) {
        a = true;
        uc.setActive(b);
      }
    }
    if (!original.getUserName().equals(value)) a = true;
    // if admin
    if (MetadataViewerAgent.isAdministrator()) a = true;
    if (a) {
      Map<ExperimenterData, UserCredentials> m = new HashMap<ExperimenterData, UserCredentials>();
      m.put(original, uc);
      AdminObject object = new AdminObject(g, m, AdminObject.UPDATE_EXPERIMENTER);
      return object;
    }
    return original; // newOne;
  }
Beispiel #25
0
  /**
   * Builds the UI component hosting the UI component used to modify the password.
   *
   * @return See above.
   */
  private JPanel buildPasswordPanel() {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    Registry reg = MetadataViewerAgent.getRegistry();
    String ldap = (String) reg.lookup(LookupNames.USER_AUTHENTICATION);
    if (ldap != null && ldap.length() > 0) {
      content.setBorder(BorderFactory.createTitledBorder("LDAP Authentication"));
      content.setLayout(new FlowLayout(FlowLayout.LEFT));
      content.add(new JLabel(ldap));
      return content;
    }
    content.setBorder(BorderFactory.createTitledBorder("Change Password"));

    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
    c.fill = GridBagConstraints.NONE; // reset to default
    c.weightx = 0.0;
    if (MetadataViewerAgent.isAdministrator()) {
      content.add(UIUtilities.setTextFont(PASSWORD_NEW), c);
      c.gridx++;
      c.gridwidth = GridBagConstraints.REMAINDER; // end row
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1.0;
      content.add(passwordNew, c);
    } else {
      content.add(UIUtilities.setTextFont(PASSWORD_OLD), c);
      c.gridx++;
      c.gridwidth = GridBagConstraints.REMAINDER; // end row
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1.0;
      content.add(oldPassword, c);
      c.gridy++;
      c.gridx = 0;
      c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
      c.fill = GridBagConstraints.NONE; // reset to default
      c.weightx = 0.0;
      content.add(UIUtilities.setTextFont(PASSWORD_NEW), c);
      c.gridx++;
      c.gridwidth = GridBagConstraints.REMAINDER; // end row
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1.0;
      content.add(passwordNew, c);
      c.gridy++;
      c.gridx = 0;
      c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
      c.fill = GridBagConstraints.NONE; // reset to default
      c.weightx = 0.0;
      content.add(UIUtilities.setTextFont(PASSWORD_CONFIRMATION), c);
      c.gridx++;
      c.gridwidth = GridBagConstraints.REMAINDER; // end row
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1.0;
      content.add(passwordConfirm, c);
      c.gridy++;
      c.gridx = 0;
    }

    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(content);
    JPanel buttonPanel = UIUtilities.buildComponentPanel(passwordButton);
    buttonPanel.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(buttonPanel);
    return p;
  }
Beispiel #26
0
 /** Message displayed when one of the required fields is left blank. */
 private void showRequiredField() {
   UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();
   un.notifyInfo("Edit Profile", "The required fields cannot be left " + "blank.");
   return;
 }
 /**
  * Reacts to property change.
  *
  * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
  */
 public void propertyChange(PropertyChangeEvent evt) {
   String name = evt.getPropertyName();
   if (SAVE_PROPERTY.equals(name)
       || DataComponent.DATA_MODIFIED_PROPERTY.equals(name)
       || PreviewPanel.PREVIEW_EDITED_PROPERTY.equals(name)) {
     view.setDataToSave(view.hasDataToSave());
   } else if (MetadataViewer.SAVE_DATA_PROPERTY.equals(name)) {
     Boolean b = (Boolean) evt.getNewValue();
     view.saveData(b.booleanValue());
   } else if (MetadataViewer.CLEAR_SAVE_DATA_PROPERTY.equals(name)
       || MetadataViewer.ON_DATA_SAVE_PROPERTY.equals(name)
       || MetadataViewer.ADMIN_UPDATED_PROPERTY.equals(name)) {
     view.clearData();
   } else if (UIUtilities.COLLAPSED_PROPERTY_JXTASKPANE.equals(name)) {
     view.handleTaskPaneCollapsed((JXTaskPane) evt.getSource());
   } else if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
     File[] files = (File[]) evt.getNewValue();
     view.attachFiles(files);
   } else if (AnnotationUI.REMOVE_ANNOTATION_PROPERTY.equals(name)) {
     Object object = evt.getNewValue();
     if (object instanceof DocComponent) {
       DocComponent doc = (DocComponent) object;
       Object data = doc.getData();
       if (data instanceof File) view.removeAttachedFile(data);
       else if (data instanceof FileAnnotationData) view.removeAttachedFile(data);
       else if (data instanceof TagAnnotationData) view.removeObject((DataObject) data);
     }
   } else if (AnnotationUI.DELETE_ANNOTATION_PROPERTY.equals(name)) {
     Object object = evt.getNewValue();
     if (object instanceof DocComponent) {
       DocComponent doc = (DocComponent) object;
       Object data = doc.getData();
       if (data instanceof FileAnnotationData) {
         view.deleteAnnotation((FileAnnotationData) data);
         view.removeAttachedFile(data);
       }
     } else if (object instanceof TextualAnnotationComponent) {
       TextualAnnotationComponent doc = (TextualAnnotationComponent) object;
       TextualAnnotationData data = doc.getData();
       // view.deleteAnnotation((TextualAnnotationData) data);
       view.removeObject(data);
     }
   } else if (AnnotationUI.EDIT_TAG_PROPERTY.equals(name)) {
     Object object = evt.getNewValue();
     if (object instanceof DocComponent) {
       // Save the tag w/o update.
       DataObject d = (DataObject) ((DocComponent) object).getData();
       // Save the tag
       OmeroMetadataService svc = MetadataViewerAgent.getRegistry().getMetadataService();
       long id = MetadataViewerAgent.getUserDetails().getId();
       try {
         svc.saveData(model.getSecurityContext(), Arrays.asList(d), null, null, id);
       } catch (Exception e) {
         Logger l = MetadataViewerAgent.getRegistry().getLogger();
         LogMessage msg = new LogMessage();
         msg.print("Saving object");
         msg.print(e);
         l.error(this, msg);
       }
     }
   } else if (OMEWikiComponent.WIKI_DATA_OBJECT_PROPERTY.equals(name)) {
     WikiDataObject object = (WikiDataObject) evt.getNewValue();
     long id;
     switch (object.getIndex()) {
       case WikiDataObject.IMAGE:
         id = object.getId();
         if (id < 0) viewImage(object.getName());
         else viewImage(id);
         break;
       case WikiDataObject.PROTOCOL:
         viewProtocol(object.getId());
         break;
     }
   } else if (SelectionWizard.SELECTED_ITEMS_PROPERTY.equals(name)) {
     Map m = (Map) evt.getNewValue();
     if (m == null || m.size() != 1) return;
     Set set = m.entrySet();
     Entry entry;
     Iterator i = set.iterator();
     Class type;
     while (i.hasNext()) {
       entry = (Entry) i.next();
       type = (Class) entry.getKey();
       view.handleObjectsSelection(type, (Collection) entry.getValue());
     }
   } else if (PreviewPanel.OPEN_FILE_PROPERTY.equals(name)) {
     Long id = (Long) evt.getNewValue();
     if (id != null) viewProtocol(id.longValue());
   } else if (MetadataViewer.SETTINGS_APPLIED_PROPERTY.equals(name)) {
     model.loadRenderingControl(RenderingControlLoader.RELOAD);
     view.onSettingsApplied(true);
   } else if (MetadataViewer.ACTIVITY_OPTIONS_PROPERTY.equals(name)) {
     List l = (List) evt.getNewValue();
     view.activityOptions((Component) l.get(0), (Point) l.get(1), (Integer) l.get(2));
   } else if (FigureDialog.CREATE_FIGURE_PROPERTY.equals(name)) {
     view.createFigure(evt.getNewValue());
   } else if (FigureDialog.CLOSE_FIGURE_PROPERTY.equals(name)) {
     figureDialog = null;
   } else if (MetadataViewer.CLOSE_RENDERER_PROPERTY.equals(name)) {
     view.discardRenderer(evt.getNewValue());
   } else if (MetadataViewer.RELATED_NODES_PROPERTY.equals(name)) {
     view.onRelatedNodesSet();
   } else if (ScriptingDialog.RUN_SELECTED_SCRIPT_PROPERTY.equals(name)) {
     // view.manageScript((ScriptObject) evt.getNewValue(),
     //		MetadataViewer.RUN);
   } else if (ScriptingDialog.DOWNLOAD_SELECTED_SCRIPT_PROPERTY.equals(name)) {
     Object value = evt.getNewValue();
     if (value instanceof ScriptObject)
       view.manageScript((ScriptObject) value, MetadataViewer.DOWNLOAD);
     else if (value instanceof String) {
       ScriptObject script = view.getScriptFromName((String) value);
       if (script != null) view.manageScript(script, MetadataViewer.DOWNLOAD);
     }
   } else if (ScriptingDialog.VIEW_SELECTED_SCRIPT_PROPERTY.equals(name)) {
     Object value = evt.getNewValue();
     if (value instanceof ScriptObject)
       view.manageScript((ScriptObject) value, MetadataViewer.VIEW);
     else if (value instanceof String) {
       ScriptObject script = view.getScriptFromName((String) value);
       if (script != null) view.manageScript(script, MetadataViewer.VIEW);
     }
   } else if (AnalysisResultsItem.ANALYSIS_RESULTS_DELETE.equals(name)) {
     AnalysisResultsItem item = (AnalysisResultsItem) evt.getNewValue();
     List<FileAnnotationData> list = item.getAttachments();
     view.fireAnnotationsDeletion(list);
   } else if (AnalysisResultsItem.ANALYSIS_RESULTS_VIEW.equals(name)) {
     AnalysisResultsItem item = (AnalysisResultsItem) evt.getNewValue();
     if (view.getRndIndex() == MetadataViewer.RND_GENERAL) {
       model.displayAnalysisResults(item);
       /*
       ViewImage event = new ViewImage(item.getData(), null);
       event.setAnalysis(item);
       EventBus bus = MetadataViewerAgent.getRegistry().getEventBus();
       bus.post(event);
       */
     } else {
       model.displayAnalysisResults(item);
     }
   } else if (AnalysisResultsItem.ANALYSIS_RESULTS_CANCEL.equals(name)) {
     AnalysisResultsItem item = (AnalysisResultsItem) evt.getNewValue();
     view.cancelAnalysisResultsLoading(item);
   }
 }
 /**
  * Fires an asynchronous call to modify the default group of the logged in experimenter.
  *
  * @param group
  */
 void fireChangeGroup(GroupData group) {
   SecurityContext c = ctx;
   if (MetadataViewerAgent.isAdministrator()) c = getAdminContext();
   MetadataLoader loader = new GroupEditor(component, c, group, loaderID, GroupEditor.CHANGE);
   loader.load();
 }
  /**
   * Handles events.
   *
   * @see ActionListener#actionPerformed(ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() instanceof ScriptMenuItem) {
      ScriptMenuItem item = (ScriptMenuItem) e.getSource();
      if (item.isScriptWithUI()) {
        switch (item.getIndex()) {
          case ScriptMenuItem.MOVIE_FIGURE_SCRIPT:
            model.createFigure(FigureDialog.MOVIE);
            break;
          case ScriptMenuItem.ROI_FIGURE_SCRIPT:
            model.createFigure(FigureDialog.SPLIT_ROI);
            break;
          case ScriptMenuItem.THUMBNAIL_FIGURE_SCRIPT:
            model.createFigure(FigureDialog.THUMBNAILS);
            break;
          case ScriptMenuItem.SPLIT_VIEW_FIGURE_SCRIPT:
            model.createFigure(FigureDialog.SPLIT);
            break;
          case ScriptMenuItem.MOVIE_EXPORT_SCRIPT:
            view.makeMovie(-1, null);
            break;
          case ScriptMenuItem.FLIM_SCRIPT:
            openFLIM();
        }
      } else {
        ScriptObject object = item.getScript();
        if (!object.isParametersLoaded()) model.loadScript(object.getScriptID());
        else model.setScript(object);
      }
      return;
    }

    int index = Integer.parseInt(e.getActionCommand());

    switch (index) {
      case ADD_LOCAL_DOCS:
        selectFileToAttach();
        break;
      case ADD_UPLOADED_DOCS:
        model.loadExistingAttachments();
        break;
      case SAVE:
        view.saveData(true);
        break;
      case DOWNLOAD:
        download();
        break;
      case ADD_TAGS:
        loadExistingTags();
        break;
      case CREATE_NEW_EXPERIMENT:
        view.createNewExperiment();
        break;
      case CREATE_MOVIE:
        view.makeMovie(-1, null);
        break;
      case RENDERER:
        model.loadRenderingControl(RenderingControlLoader.LOAD);
        break;
      case ANALYSE_FLIM:
        view.analyse(AnalysisParam.FLIM);
        break;
      case ANALYSE_FRAP:
        view.analyse(AnalysisParam.FRAP);
        break;
      case REFRESH:
        model.refresh();
        break;
      case EXPORT_AS_OMETIFF:
        export();
        break;
      case SPLIT_VIEW_FIGURE:
        model.createFigure(FigureDialog.SPLIT);
        break;
      case SPLIT_VIEW_ROI_FIGURE:
        model.createFigure(FigureDialog.SPLIT_ROI);
        break;
      case THUMBNAILS_FIGURE:
        model.createFigure(FigureDialog.THUMBNAILS);
        break;
      case MOVIE_FIGURE:
        model.createFigure(FigureDialog.MOVIE);
        break;
      case UPLOAD_SCRIPT:
        view.uploadScript();
        break;
      case RELOAD_SCRIPT:
        view.reloadScript();
        break;
        /*
        case REMOVE_TAGS:
        	view.removeTags();
        	break;
        case REMOVE_DOCS:
        	view.removeAttachedFiles();
        	break;
        	*/
      case SAVE_AS:
        saveAsJPEG();
        break;
      case VIEW_IMAGE:
        Object refObject = view.getRefObject();
        ImageData img = null;
        if (refObject instanceof ImageData) {
          img = (ImageData) refObject;
        } else if (refObject instanceof WellSampleData) {
          img = ((WellSampleData) refObject).getImage();
        }
        if (img != null) {
          ViewImageObject vio = new ViewImageObject(img);
          MetadataViewerAgent.getRegistry()
              .getEventBus()
              .post(new ViewImage(model.getSecurityContext(), vio, null));
        }
        break;
      case VIEW_IMAGE_IN_IJ:
        Object object = view.getRefObject();
        ImageData image = null;
        if (object instanceof ImageData) {
          image = (ImageData) object;
        } else if (object instanceof WellSampleData) {
          image = ((WellSampleData) object).getImage();
        }
        if (image != null) {
          ViewInPluginEvent event =
              new ViewInPluginEvent(
                  model.getSecurityContext(), (DataObject) object, MetadataViewer.IMAGE_J);
          MetadataViewerAgent.getRegistry().getEventBus().post(event);
        }
    }
  }
 /**
  * Returns the security context.
  *
  * @return See above.
  */
 SecurityContext getAdminContext() {
   if (MetadataViewerAgent.isAdministrator()) return MetadataViewerAgent.getAdminContext();
   return null;
 }