Esempio n. 1
0
 @Override
 public void onClick(final View view) {
   final String text = mFileSelector.getSelectedFileName();
   if (checkFileName(text)) {
     final String filePath =
         mFileSelector.getCurrentLocation().getAbsolutePath() + File.separator + text;
     final File file = new File(filePath);
     int messageText = 0;
     // Check file access rights.
     switch (mOperation) {
       case SAVE:
         if ((file.exists()) && (!file.canWrite())) {
           messageText = R.string.cannotSaveFileMessage;
         }
         break;
       case LOAD:
         if (!file.exists()) {
           messageText = R.string.missingFile;
         } else if (!file.canRead()) {
           messageText = R.string.accessDenied;
         }
         break;
     }
     if (messageText != 0) {
       // Access denied.
       final Toast t = Toast.makeText(mContext, messageText, Toast.LENGTH_SHORT);
       t.setGravity(Gravity.CENTER, 0, 0);
       t.show();
     } else {
       // Access granted.
       mFileSelector.mOnHandleFileListener.handleFile(filePath);
       mFileSelector.dismiss();
     }
   }
 }
Esempio n. 2
0
  private void onOK() {
    if (!isValidInput()) {
      return;
    }
    dispose();
    String firstName = firstNameField.getText().trim();
    String lastName = lastNameField.getText().trim();
    String emailAddress = emailAddressField.getText().trim();
    SexOfPerson sexOfPerson;
    if (femaleRadioButton.isSelected()) {
      sexOfPerson = SexOfPerson.FEMALE;
    } else {
      sexOfPerson = SexOfPerson.MALE;
    }
    String country = (String) countryComboBox.getSelectedObject();
    Integer birthdayYear = (Integer) birthdayYearComboBox.getSelectedItem();
    Month birthdayMonth = (Month) birthdayMonthComboBox.getSelectedItem();
    Integer birthdayDay = (Integer) birthdayDayComboBox.getSelectedItem();
    char[] passwordArr = passwordField.getPassword();
    String password = new String(passwordArr);
    Arrays.fill(passwordArr, (char) 0);
    Image profilePicture = null;
    if (imageFromFileRadioButton.isSelected()) {
      if (fileSelector.getFilePath() != null) {
        profilePicture = new FileImage(fileSelector.getFilePath());
      }
    }
    Request request =
        new CreateUserRequest(
            communicator.getHttpClient(),
            frame,
            firstName,
            lastName,
            emailAddress,
            sexOfPerson,
            country,
            birthdayYear,
            birthdayMonth,
            birthdayDay,
            password,
            profilePicture) {

          @Override
          protected void onCreateUser(String status, Person person) {
            if (status.equals("INVALID_PROFILE_PICTURE")) {
              communicator.promptForCreateAccount("Invalid profile picture");
            } else if (status.equals("ERROR_CREATING_USER")) {
              communicator.promptForCreateAccount("Error creating user");
            } else if (status.equals("CONNECTION_ERROR")) {
              communicator.promptForCreateAccount("Error connecting to Modeling Commons");
            } else if (status.equals("SUCCESS")) {
              communicator.setPerson(person);
              communicator.promptForUpload();
            } else {
              communicator.promptForCreateAccount("Unknown server error");
            }
          }
        };
    request.execute();
  }
Esempio n. 3
0
 /** @return input files */
 public File[] getInputFiles() {
   if (traceSelector.isFileSelected()) {
     return traceSelector.getSelectedFiles();
   } else {
     JOptionPane.showMessageDialog(traceSelector, "Please select input trace files");
     return null;
   }
 }
Esempio n. 4
0
 public static File[] listFiles(File file, Set<String> exts, int noOfLevels) {
   FileSelector fs = null;
   if (!(null == exts || exts.size() == 0)) {
     fs = new FileSelector();
     fs.addExt(exts);
   }
   List<File> files = listFiles(file, fs, noOfLevels);
   return files.toArray(new File[files.size()]);
 }
Esempio n. 5
0
 public static String cleanFilenames(Collection<FileSelector> fileNames) {
   boolean first = true;
   StringBuffer sb = new StringBuffer();
   sb.append('[');
   for (FileSelector fileName : fileNames) {
     if (!first) {
       sb.append(", ");
     }
     sb.append(fileName.toString());
     first = false;
   }
   sb.append(']');
   return sb.toString();
 }
Esempio n. 6
0
 private static void addFileToList(File file, List<File> files, FileSelector fs) {
   if (null == fs) {
     files.add(file);
   } else {
     if (fs.accept(file, file.toString())) files.add(file);
   }
 }
Esempio n. 7
0
 /** @return selected output directory or file */
 public File getOutputFile() {
   if (outputSelector.isFileSelected()) {
     return outputSelector.getSelectedFiles()[0];
   } else {
     // FIXME: returns null!
     if (JOptionPane.showConfirmDialog(
             null,
             "You did not selected output folder. Do you want to use input folder as output too?",
             "No output folder",
             JOptionPane.YES_NO_OPTION)
         != JOptionPane.YES_OPTION) {
       File firstFile = getInputFiles()[0];
       return new File(
           firstFile.getPath().substring(0, firstFile.getPath().indexOf(firstFile.getName())));
     } else {
       return null;
     }
   }
 }
Esempio n. 8
0
 /**
  * Allows the custom selector to choose whether to select a file. This is also where the
  * Parameters are passed to the custom selector, since we know we must have them all by now. And
  * since we must know both classpath and classname, creating the class is deferred to here as
  * well.
  *
  * @param basedir The the base directory.
  * @param filename The name of the file to check.
  * @param file A File object for this filename.
  * @return whether the file should be selected or not.
  * @exception BuildException if an error occurs.
  */
 public boolean isSelected(File basedir, String filename, File file) throws BuildException {
   validate();
   if (paramVec.size() > 0 && dynselector instanceof ExtendFileSelector) {
     Parameter[] paramArray = new Parameter[paramVec.size()];
     paramVec.copyInto(paramArray);
     // We know that dynselector must be non-null if no error message
     ((ExtendFileSelector) dynselector).setParameters(paramArray);
   }
   return dynselector.isSelected(basedir, filename, file);
 }
 /**
  * Create a file selector widget and related widgets for this class. This class assumes that the
  * layout manager for the parent Composite object is a GridLayout with 4 columns.
  *
  * @param parent
  * @param id
  * @param selectorID
  * @param def
  */
 public FileSelectorRowWidget(
     Composite parent, String id, Integer selectorID, IAttributeDefinition<?, ?, ?> def) {
   attr = def;
   label = new Label(parent, SWT.NONE);
   // TODO drw label.setText(Messages.getString(attr.getName()));
   label.setText(attr.getName());
   nonDefaultMarker = new Label(parent, SWT.NONE);
   nonDefaultMarker.setText(" "); // $NON-NLS-1$
   gridData = new GridData(GridData.FILL_HORIZONTAL);
   gridData.grabExcessHorizontalSpace = false;
   label.setLayoutData(gridData);
   // TODO drw widget = new FileSelector(parent, selectorID,
   // Messages.getString(attr.getDescription()));
   widget = new FileSelector(parent, selectorID, attr.getDescription());
   widget.setData(id);
   try {
     defaultValue = attr.create().getValueAsString();
   } catch (IllegalValueException e) {
     defaultValue = ""; // $NON-NLS-1$
   }
   eventMonitor = new EventMonitor();
   widget.addModifyListener(eventMonitor);
 }
Esempio n. 10
0
 /**
  * Get the data value (attribute name) for this object
  *
  * @return The data value
  */
 public Object getData() {
   return widget.getData();
 }
Esempio n. 11
0
 /**
  * Set the pathname for this object
  *
  * @param path Pathname
  */
 public void setPath(String path) {
   widget.setPath(path);
 }
Esempio n. 12
0
 /**
  * Add a selection listener which will receive notifications when the path name field in this
  * object has changed value
  *
  * @param listener The listener
  */
 public void addModifyListener(ModifyListener listener) {
   widget.addModifyListener(listener);
 }
Esempio n. 13
0
 /**
  * Return status indicating that the actual widget contained in this object is the widget that is
  * being searched for
  *
  * @param source - The widget that is being searched for
  * @return - status indicating this object contains the matching widget.
  */
 public boolean isMatchingWidget(Widget source) {
   return widget.isMatchingWidget(source);
 }
Esempio n. 14
0
 /** Set focus to the text field within this object */
 public void setFocus() {
   widget.setFocus();
 }
Esempio n. 15
0
 /**
  * Add a selection listener which will receive notifications when the browse button in this object
  * has been clicked.
  *
  * @param listener The listener
  */
 public void addSelectionListener(SelectionListener listener) {
   widget.addSelectionListener(listener);
 }
Esempio n. 16
0
 /**
  * Get the enable state for this object
  *
  * @return The enable state
  */
 public boolean isEnabled() {
   return widget.isEnabled();
 }
Esempio n. 17
0
 /**
  * Get the pathname specified in this object
  *
  * @return Pathname
  */
 public String getValue() {
   return widget.getPath().trim();
 }
Esempio n. 18
0
 public FileFilter getSelectedFilter() {
   return traceSelector.getSelectedFileFilter();
 }
Esempio n. 19
0
 /**
  * Set the data value (attribute name) for this object
  *
  * @param value The data value
  */
 public void setData(Object value) {
   widget.setData(value);
 }
Esempio n. 20
0
 /**
  * Set the enable state for this object
  *
  * @param state The enable state
  */
 public void setEnabled(boolean state) {
   widget.setEnabled(state);
 }