Exemple #1
0
  public void add() {
    qprint.verbose("Add pressed. Create File");

    Display display = Display.getDefault();

    QFileManagerShell fm = new QFileManagerShell();
    while (!fm.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    QFileType file = fm.getFile();
    if (null == file) {
      qprint.error("file is null");
      return;
    }

    // create a new file and update tree
    File f = new File(file.getFilePath());
    try {
      qprint.verbose("create file " + f.getName());
      f.createNewFile();
      qtree.update();
    } catch (IOException e) {
      qprint.error("Imposible to create file");
    }
  }
Exemple #2
0
  public QFileManagerShell() {
    shell = this;
    shell.setText("Add");
    shell.setLayout(new GridLayout(3, false));

    Composite composite = new Composite(this.shell, SWT.NONE);
    composite.setLayout(new GridLayout(3, true));
    GridData gridData = new GridData();
    composite.setLayoutData(gridData);

    Label lblDir = new Label(composite, SWT.NONE);
    lblDir.setText("Directory");
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = false;
    lblDir.setLayoutData(gridData);

    final Text textDir = new Text(composite, SWT.BORDER);
    gridData = new GridData();
    if (System.getProperty("os.name").startsWith("Linux")) {
      textDir.setText("/home/qparrod/workspace/qedit/store/");
    } else if (System.getProperty("os.name").startsWith("Windows")) {
      textDir.setText("G:/repo_qedit/store/");
    }

    gridData.horizontalAlignment = GridData.FILL;
    textDir.setLayoutData(gridData);

    Button btnBrowse = new Button(composite, SWT.NONE);
    btnBrowse.setText("Browse...");
    btnBrowse.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            qprint.verbose("Browse");
            DirectoryDialog dd = new DirectoryDialog(shell, SWT.OPEN);
            dd.setText("Browse...");
            String s = "";
            if (System.getProperty("os.name").startsWith("Linux")) {
              s = "/home/qparrod/workspace/qedit/store/";
            } else if (System.getProperty("os.name").startsWith("Windows")) {
              s = "G:/repo_qedit/store/";
            }
            dd.setFilterPath(s);
            String selected = dd.open();
            if (selected != null) {
              textDir.setText(selected + "/");
            }
            qprint.verbose(selected);
          }
        });

    Label lblName = new Label(composite, SWT.NONE);
    lblName.setText("File name");
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = false;
    lblName.setLayoutData(gridData);
    final Text textName = new Text(composite, SWT.BORDER);
    gridData = new GridData();

    gridData.horizontalAlignment = GridData.FILL;
    textName.setLayoutData(gridData);

    Button btnOk = new Button(composite, SWT.NONE);
    btnOk.setText("OK");
    btnOk.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            qprint.verbose("OK. dir=" + textDir.getText() + ", file=" + textName.getText());
            Path path = Paths.get(textDir.getText() + textName.getText());
            qprint.verbose(path.toString());

            // TODO : check if path is a correct one

            file = new QFileType();
            qprint.verbose("path=" + path.toString());
            qprint.verbose("name=" + path.getFileName().toString());
            file.setFileName(path.getFileName().toString());
            file.setFilePath(path.toString());
            file.setTimeCreated("0h00");
            file.setTimeLastOpened("0h00");
            shell.dispose();
          }
        });

    qprint.verbose("begin");
    shell.open();
  }