@After
  public void after() {

    // clean up parent directory
    File f = new File(Const.getKettleUserRepositoriesFile());
    f.delete();
    f = new File(Const.getKettleDirectory());
    f.delete();
    BasePropertyHandler.getInstance()
        .notify((PropertyHandler) LAFFactory.getHandler(PropertyHandler.class));
  }
  public Splash(Display display) throws KettleException {
    log = new LogChannel(Spoon.APP_NAME);

    Rectangle displayBounds = display.getPrimaryMonitor().getBounds();

    kettle_image =
        ImageUtil.getImageAsResource(
            display,
            BasePropertyHandler.getProperty("splash_image")); // "kettle_splash.png" //$NON-NLS-1$
    kettle_icon =
        ImageUtil.getImageAsResource(
            display, BasePropertyHandler.getProperty("splash_icon")); // "spoon.ico" //$NON-NLS-1$
    exclamation_image =
        ImageUtil.getImageAsResource(
            display,
            BasePropertyHandler.getProperty(
                "exclamation_image")); // "exclamation.png" //$NON-NLS-1$

    verFont = new Font(display, "Helvetica", 11, SWT.BOLD); // $NON-NLS-1$
    licFont = new Font(display, "Helvetica", licFontSize, SWT.NORMAL); // $NON-NLS-1$
    devWarningFont = new Font(display, "Helvetica", 10, SWT.NORMAL); // $NON-NLS-1$

    versionWarningBackgroundColor = new Color(display, 255, 253, 213);
    versionWarningForegroundColor = new Color(display, 220, 177, 20);

    splash = new Shell(display, SWT.APPLICATION_MODAL);
    splash.setImage(kettle_icon);

    splash.setText(
        BaseMessages.getString(
            PKG, "SplashDialog.Title")); // "Pentaho Data Integration" //$NON-NLS-1$

    FormLayout splashLayout = new FormLayout();
    splash.setLayout(splashLayout);

    Canvas canvas = new Canvas(splash, SWT.NO_BACKGROUND);

    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(0, 0);
    fdCanvas.top = new FormAttachment(0, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.bottom = new FormAttachment(100, 0);
    canvas.setLayoutData(fdCanvas);

    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            String versionText =
                BaseMessages.getString(PKG, "SplashDialog.Version")
                    + " "
                    + Const.VERSION; // $NON-NLS-1$ //$NON-NLS-2$

            StringBuilder sb = new StringBuilder();
            String line = null;

            try {
              BufferedReader reader =
                  new BufferedReader(
                      new InputStreamReader(
                          Splash.class
                              .getClassLoader()
                              .getResourceAsStream(
                                  "org/pentaho/di/ui/core/dialog/license/license.txt"))); //$NON-NLS-1$

              while ((line = reader.readLine()) != null) {
                sb.append(line + System.getProperty("line.separator")); // $NON-NLS-1$
              }
            } catch (Exception ex) {
              sb.append(""); // $NON-NLS-1$
              log.logError(
                  BaseMessages.getString(PKG, "SplashDialog.LicenseTextNotFound"),
                  ex); //$NON-NLS-1$
            }
            Calendar cal = Calendar.getInstance();
            String licenseText = String.format(sb.toString(), cal);
            e.gc.drawImage(kettle_image, 0, 0);

            // If this is a Milestone or RC release, warn the user
            if (Const.RELEASE.equals(Const.ReleaseType.MILESTONE)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.DeveloperRelease")
                      + " - "
                      + versionText; //$NON-NLS-1$ //$NON-NLS-2$
              drawVersionWarning(e);
            } else if (Const.RELEASE.equals(Const.ReleaseType.RELEASE_CANDIDATE)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.ReleaseCandidate")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            } else if (Const.RELEASE.equals(Const.ReleaseType.PREVIEW)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.PreviewRelease")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            } else if (Const.RELEASE.equals(Const.ReleaseType.GA)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.GA")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            }

            e.gc.setFont(verFont);
            e.gc.drawText(versionText, 290, 205, true);

            // try using the desired font size for the license text
            e.gc.setFont(licFont);

            // if the text will not fit the allowed space
            while (!willLicenseTextFit(licenseText, e.gc)) {
              licFontSize--;
              if (licFont != null) {
                licFont.dispose();
              }
              licFont = new Font(e.display, "Helvetica", licFontSize, SWT.NORMAL); // $NON-NLS-1$
              e.gc.setFont(licFont);
            }

            e.gc.drawText(licenseText, 290, 290, true);
          }
        });

    splash.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent arg0) {
            kettle_image.dispose();
            kettle_icon.dispose();
            exclamation_image.dispose();
            verFont.dispose();
            licFont.dispose();
            devWarningFont.dispose();
            versionWarningForegroundColor.dispose();
            versionWarningBackgroundColor.dispose();
          }
        });
    Rectangle bounds = kettle_image.getBounds();
    int x = (displayBounds.width - bounds.width) / 2;
    int y = (displayBounds.height - bounds.height) / 2;

    splash.setSize(bounds.width, bounds.height);
    splash.setLocation(x, y);

    splash.open();
  }
Exemple #3
0
  private void init() throws KettleException {
    this.lineStyle = ELineStyle.SOLID;
    this.lineWidth = 1;
    this.alpha = 255;

    this.background = new Color(255, 255, 255);
    this.black = new Color(0, 0, 0);
    this.red = new Color(255, 0, 0);
    this.yellow = new Color(255, 255, 0);
    this.orange = new Color(255, 165, 0);
    this.green = new Color(0, 255, 0);
    this.blue = new Color(0, 0, 255);
    this.magenta = new Color(255, 0, 255);
    this.gray = new Color(128, 128, 128);
    this.lightGray = new Color(200, 200, 200);
    this.darkGray = new Color(80, 80, 80);

    imageLocked = getImageIcon(BasePropertyHandler.getProperty("Locked_image"));
    imageStepError = getImageIcon(BasePropertyHandler.getProperty("StepErrorLines_image"));
    imageEdit = getImageIcon(BasePropertyHandler.getProperty("Edit_image"));
    imageContextMenu = getImageIcon(BasePropertyHandler.getProperty("ContextMenu_image"));
    imageTrue = getImageIcon(BasePropertyHandler.getProperty("True_image"));
    imageFalse = getImageIcon(BasePropertyHandler.getProperty("False_image"));
    imageErrorHop = getImageIcon(BasePropertyHandler.getProperty("ErrorHop_image"));
    imageInfoHop = getImageIcon(BasePropertyHandler.getProperty("InfoHop_image"));
    imageHopTarget = getImageIcon(BasePropertyHandler.getProperty("HopTarget_image"));
    imageHopInput = getImageIcon(BasePropertyHandler.getProperty("HopInput_image"));
    imageHopOutput = getImageIcon(BasePropertyHandler.getProperty("HopOutput_image"));
    imageArrow = getImageIcon(BasePropertyHandler.getProperty("ArrowIcon_image"));
    imageCopyHop = getImageIcon(BasePropertyHandler.getProperty("CopyHop_image"));
    imageLoadBalance = getImageIcon(BasePropertyHandler.getProperty("LoadBalance_image"));
    imageCheckpoint = getImageIcon(BasePropertyHandler.getProperty("CheckeredFlag_image"));
    imageParallelHop = getImageIcon(BasePropertyHandler.getProperty("ParallelHop_image"));
    imageUnconditionalHop = getImageIcon(BasePropertyHandler.getProperty("UnconditionalHop_image"));
    imageStart = getImageIcon(BasePropertyHandler.getProperty("STR_image"));
    imageDummy = getImageIcon(BasePropertyHandler.getProperty("DUM_image"));
    imageBusy = getImageIcon(BasePropertyHandler.getProperty("Busy_image"));
    imageInject = getImageIcon(BasePropertyHandler.getProperty("Inject_image"));

    fontGraph = new Font("FreeSans", Font.PLAIN, 10);
    fontNote = new Font("FreeSans", Font.PLAIN, 10);
    fontSmall = new Font("FreeSans", Font.PLAIN, 8);

    gc.setFont(fontGraph);

    gc.setColor(background);
    gc.fillRect(0, 0, area.x, area.y);
  }
  @Test
  public void testSyncWebService() throws Exception {

    // first init kettle

    KettleEnvironment.init(false);
    BasePropertyHandler.getInstance().notify(new TestPropertyHandler());
    File f = new File(Const.getKettleDirectory());
    f.mkdirs();

    // second init platform
    PentahoSystem.registerObjectFactory(new SimpleObjectFactory());
    PentahoSystem.init(new TestAppContext(), null);
    PentahoSystem.setSystemSettingsService(
        new ISystemSettings() {
          public String getSystemCfgSourceName() {
            return null;
          }

          public String getSystemSetting(String arg0, String arg1) {
            if ("singleDiServerInstance".equals(arg0)) {
              return "false";
            }
            return arg1;
          }

          public String getSystemSetting(String arg0, String arg1, String arg2) {
            return null;
          }

          public List getSystemSettings(String arg0) {
            return null;
          }

          public List getSystemSettings(String arg0, String arg1) {
            return null;
          }

          public Document getSystemSettingsDocument(String arg0) {
            return null;
          }

          public Properties getSystemSettingsProperties(String arg0) {
            return null;
          }

          public void resetSettingsCache() {}
        });

    // now test the webservice
    IRepositorySyncWebService webservice = getRepositorySyncWebService();

    // first without the plugin available
    try {
      webservice.sync("test id", "http://localhost:8080/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(
          e.getMessage().indexOf("unable to load the PentahoEnterpriseRepository plugin") >= 0);
    }

    // second with plugin but not registered
    RepositoryPluginType.getInstance()
        .registerCustom(
            TestRepositoryMeta.class,
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "");
    PluginRegistry.getInstance()
        .getPlugin(RepositoryPluginType.class, "PentahoEnterpriseRepository")
        .getClassMap()
        .put(
            RepositoryMeta.class,
            "com.pentaho.pdi.ws.RepositorySyncWebServiceTest$TestRepositoryMeta");

    RepositorySyncStatus status = webservice.sync("test id", "http://localhost:8080/pentaho-di");

    Assert.assertEquals(RepositorySyncStatus.REGISTERED, status);

    // third after already registered
    status = webservice.sync("test id", "http://localhost:8080/pentaho-di");

    Assert.assertEquals(RepositorySyncStatus.ALREADY_REGISTERED, status);

    // forth test with different url
    try {
      webservice.sync("test id", "http://localhost:9090/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(e.getMessage().indexOf("with the URL:") >= 0);
    }

    // fifth test different base-url
    fullyQualifiedServerUrl = "http://localhost:9090/pentaho-di";
    try {
      webservice.sync("test id", "http://localhost:8080/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(e.getMessage().indexOf("fully qualified server url") >= 0);
    }
  }