Exemplo n.º 1
0
  /** Rename the tabs */
  public void renameTabs() {
    List<TabMapEntry> list = new ArrayList<TabMapEntry>(tabMap);
    for (TabMapEntry entry : list) {
      if (entry.getTabItem().isDisposed()) {
        // this should not be in the map, get rid of it.
        tabMap.remove(entry.getObjectName());
        continue;
      }

      // TabItem before = entry.getTabItem();
      // PDI-1683: need to get the String here, otherwise using only the "before" instance below,
      // the reference gets
      // changed and result is always the same
      // String beforeText=before.getText();
      //
      Object managedObject = entry.getObject().getManagedObject();
      if (managedObject != null) {
        if (entry.getObject() instanceof TransGraph) {
          TransMeta transMeta = (TransMeta) managedObject;
          String tabText = makeTabName(transMeta, entry.isShowingLocation());
          entry.getTabItem().setText(tabText);
          String toolTipText = BaseMessages.getString(PKG, "Spoon.TabTrans.Tooltip", tabText);
          if (Const.isWindows() && !Const.isEmpty(transMeta.getFilename())) {
            toolTipText += Const.CR + Const.CR + transMeta.getFilename();
          }
          entry.getTabItem().setToolTipText(toolTipText);
        } else if (entry.getObject() instanceof JobGraph) {
          JobMeta jobMeta = (JobMeta) managedObject;
          entry.getTabItem().setText(makeTabName(jobMeta, entry.isShowingLocation()));
          String toolTipText =
              BaseMessages.getString(
                  PKG, "Spoon.TabJob.Tooltip", makeTabName(jobMeta, entry.isShowingLocation()));
          if (Const.isWindows() && !Const.isEmpty(jobMeta.getFilename())) {
            toolTipText += Const.CR + Const.CR + jobMeta.getFilename();
          }
          entry.getTabItem().setToolTipText(toolTipText);
        }
      }

      /*
       * String after = entry.getTabItem().getText();
       *
       * if (!beforeText.equals(after)) // PDI-1683, could be improved to rename all the time {
       * entry.setObjectName(after);
       *
       * // Also change the transformation map if (entry.getObject() instanceof TransGraph) {
       * spoon.delegates.trans.removeTransformation(beforeText); spoon.delegates.trans.addTransformation(after,
       * (TransMeta) entry.getObject().getManagedObject()); } // Also change the job map if (entry.getObject()
       * instanceof JobGraph) { spoon.delegates.jobs.removeJob(beforeText); spoon.delegates.jobs.addJob(after, (JobMeta)
       * entry.getObject().getManagedObject()); } }
       */
    }
    spoon.setShellText();
  }
Exemplo n.º 2
0
  protected void openDialog() {

    if (Const.isWindows()) {
      shell.setSize(653, 671);
    }
    if (Const.isLinux()) {
      shell.setSize(740, 678);
    }
    if (Const.isOSX()) {
      shell.setSize(653, 678);
    }

    // Set the focus on the OK button
    wOK.setFocus();
    shell.open();

    Rectangle shellBounds = getParent().getBounds();
    Point dialogSize = shell.getSize();

    shell.setLocation(
        shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
        shellBounds.y + (shellBounds.height - dialogSize.y) / 2);

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
  private boolean classicPing(String hostname, int nrpackets) {
    boolean retval = false;
    try {
      String lignePing = "";
      String CmdPing = "ping ";
      if (Const.isWindows()) {
        CmdPing += hostname + " " + Windows_CHAR + " " + nrpackets;
      } else {
        CmdPing += hostname + " " + NIX_CHAR + " " + nrpackets;
      }

      if (log.isDetailed()) {
        logDetailed(BaseMessages.getString(PKG, "JobPing.NbrPackets.Label", "" + nrpackets));
        logDetailed(BaseMessages.getString(PKG, "JobPing.ExecClassicPing.Label", CmdPing));
      }
      Process processPing = Runtime.getRuntime().exec(CmdPing);
      try {
        processPing.waitFor();
      } catch (InterruptedException e) {
        logDetailed(BaseMessages.getString(PKG, "JobPing.ClassicPingInterrupted"));
      }
      if (log.isDetailed()) {
        logDetailed(BaseMessages.getString(PKG, "JobPing.Gettingresponse.Label", hostname));
      }
      // Get ping response
      BufferedReader br = new BufferedReader(new InputStreamReader(processPing.getInputStream()));

      // Read response lines
      while ((lignePing = br.readLine()) != null) {
        if (log.isDetailed()) {
          logDetailed(lignePing);
        }
      }
      // We succeed only when 0% lost of data
      if (processPing.exitValue() == 0) {
        retval = true;
      }
    } catch (IOException ex) {
      logError(BaseMessages.getString(PKG, "JobPing.Error.Label") + ex.getMessage());
    }
    return retval;
  }
Exemplo n.º 4
0
  private FileObject createTemporaryShellFile(FileObject tempFile, String fileContent)
      throws Exception {
    // Create a unique new temporary filename in the working directory, put the script in there
    // Set the permissions to execute and then run it...
    //
    if (tempFile != null && fileContent != null) {
      try {
        // flag indicates if current OS is Windows or not
        boolean isWindows = Const.isWindows();
        if (!isWindows) {
          fileContent = replaceWinEOL(fileContent);
        }
        tempFile.createFile();
        OutputStream outputStream = tempFile.getContent().getOutputStream();
        outputStream.write(fileContent.getBytes());
        outputStream.close();
        if (!isWindows) {
          String tempFilename = KettleVFS.getFilename(tempFile);
          // Now we have to make this file executable...
          // On Unix-like systems this is done using the command "/bin/chmod +x filename"
          //
          ProcessBuilder procBuilder = new ProcessBuilder("chmod", "+x", tempFilename);
          Process proc = procBuilder.start();
          // Eat/log stderr/stdout all messages in a different thread...
          StreamLogger errorLogger =
              new StreamLogger(log, proc.getErrorStream(), toString() + " (stderr)");
          StreamLogger outputLogger =
              new StreamLogger(log, proc.getInputStream(), toString() + " (stdout)");
          new Thread(errorLogger).start();
          new Thread(outputLogger).start();
          proc.waitFor();
        }

      } catch (Exception e) {
        throw new Exception("Unable to create temporary file to execute script", e);
      }
    }
    return tempFile;
  }
  public JobEntryInterface open() {
    Shell parent = getParent();
    display = parent.getDisplay();

    shell = new Shell(parent, props.getJobsDialogStyle());
    props.setLook(shell);
    JobDialog.setShellImage(shell, jobEntry);

    backupChanged = jobEntry.hasChanged();

    createElements();

    // Detect [X] or ALT-F4 or something that kills this window...
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            cancel();
          }
        });

    getData();
    setActive();

    BaseStepDialog.setSize(shell);

    int width = 750;
    int height = Const.isWindows() ? 730 : 720;

    shell.setSize(width, height);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return jobEntry;
  }