Example #1
0
    @Override
    public void actionPerformed(ActionEvent event) {
      String command = event.getActionCommand();
      if (command.equals("add")) {
        MultipleInputDialog inputDialog = new MultipleInputDialog();
        data.add(inputDialog.getDialogCar());

      } else if (command.equals("save")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.SAVE);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileOutputStream fileOut = new FileOutputStream(dir + filename);
          ObjectOutputStream out = new ObjectOutputStream(fileOut);
          out.writeObject(Layout.this.data);
          out.close();
          fileOut.close();
          System.out.println("save OK");
          System.out.println("Kiirva 1/1 adat " + data.get(1).getOne());

        } catch (IOException i) {
          i.printStackTrace();
        }
      } else if (command.equals("load")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.LOAD);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileInputStream fileIn = new FileInputStream(dir + filename);
          ObjectInputStream in = new ObjectInputStream(fileIn);

          Layout.this.data = (ArrayList<Car>) in.readObject();
          dataTable.repaint();

          fileIn.close();
          in.close();

          System.out.println("beolvasva");
          repaint();

          System.out.println("olvasva 1/1 adat data-ban " + data.get(1).getOne());
        } catch (IOException i) {
          i.printStackTrace();
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (command.equals("browse")) {
        FileDialog jf = new FileDialog(Layout.this, "Choose something", FileDialog.LOAD);
        jf.setVisible(true);
      }
    }
  private void edit(IStructuredSelection selection) {
    IStructuredSelection sel = (IStructuredSelection) selection;
    EnvironmentVariable var = (EnvironmentVariable) sel.getFirstElement();
    if (var == null) {
      return;
    }
    String originalName = var.getName();
    String value = var.getValue();
    MultipleInputDialog dialog =
        new MultipleInputDialog(
            fDialog.getShell(),
            InterpretersMessages.AbstractInterpreterEnvironmentVariablesBlock_editVariable);
    dialog.addTextField(NAME_LABEL, originalName, false);
    dialog.addVariablesField(VALUE_LABEL, value, true);

    if (dialog.open() != Window.OK) {
      return;
    }
    String name = dialog.getStringValue(NAME_LABEL);
    value = dialog.getStringValue(VALUE_LABEL);
    if (!originalName.equals(name)) {
      fEnvironmentVariablesContentProvider.add(
          new EnvironmentVariable[] {new EnvironmentVariable(name, value)}, selection);
    } else {
      var.setValue(value);
      fVariablesViewer.refresh(true);
    }
  }
  private EnvironmentVariable[] add() {
    MultipleInputDialog dialog =
        new MultipleInputDialog(
            fDialog.getShell(),
            InterpretersMessages.AbstractInterpreterEnvironmentVariablesBlock_addVariable);
    dialog.addTextField(NAME_LABEL, null, false);
    dialog.addVariablesField(VALUE_LABEL, null, true);

    if (dialog.open() != Window.OK) {
      return null;
    }

    String name = dialog.getStringValue(NAME_LABEL);
    String value = dialog.getStringValue(VALUE_LABEL);

    if (name != null && value != null && name.length() > 0 && value.length() > 0) {
      return new EnvironmentVariable[] {new EnvironmentVariable(name.trim(), value.trim())};
    }
    return null;
  }