Search in sources :

Example 16 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class SpoonJobDelegateTest method testGetJobEntryDialogClass.

@Test
public void testGetJobEntryDialogClass() throws KettlePluginException {
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginMockInterface plugin = mock(PluginMockInterface.class);
    when(plugin.getIds()).thenReturn(new String[] { "mockJobPlugin" });
    when(plugin.matches("mockJobPlugin")).thenReturn(true);
    when(plugin.getName()).thenReturn("mockJobPlugin");
    JobEntryInterface jobEntryInterface = mock(JobEntryInterface.class);
    when(jobEntryInterface.getDialogClassName()).thenReturn(String.class.getName());
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(JobEntryInterface.class, jobEntryInterface.getClass().getName());
            put(JobEntryDialogInterface.class, JobEntryDialogInterface.class.getName());
        }
    });
    registry.registerPlugin(JobEntryPluginType.class, plugin);
    SpoonJobDelegate delegate = mock(SpoonJobDelegate.class);
    Spoon spoon = mock(Spoon.class);
    delegate.spoon = spoon;
    delegate.log = mock(LogChannelInterface.class);
    when(spoon.getShell()).thenReturn(mock(Shell.class));
    doCallRealMethod().when(delegate).getJobEntryDialog(any(JobEntryInterface.class), any(JobMeta.class));
    JobMeta meta = mock(JobMeta.class);
    // verify that dialog class is requested from plugin
    try {
        // exception is expected here
        delegate.getJobEntryDialog(jobEntryInterface, meta);
    } catch (Throwable ignore) {
        verify(jobEntryInterface, never()).getDialogClassName();
    }
    // verify that the deprecated way is still valid
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(JobEntryInterface.class, jobEntryInterface.getClass().getName());
        }
    });
    try {
        // exception is expected here
        delegate.getJobEntryDialog(jobEntryInterface, meta);
    } catch (Throwable ignore) {
        verify(jobEntryInterface, times(1)).getDialogClassName();
    }
    // cleanup
    registry.removePlugin(JobEntryPluginType.class, plugin);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryDialogInterface(org.pentaho.di.job.entry.JobEntryDialogInterface) Shell(org.eclipse.swt.widgets.Shell) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Spoon(org.pentaho.di.ui.spoon.Spoon) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 17 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class SpoonStepsDelegateTest method testGetStepDialogClass.

@Test
public void testGetStepDialogClass() throws Exception {
    PluginMockInterface plugin = mock(PluginMockInterface.class);
    when(plugin.getIds()).thenReturn(new String[] { "mockPlugin" });
    when(plugin.matches("mockPlugin")).thenReturn(true);
    when(plugin.getName()).thenReturn("mockPlugin");
    StepMetaInterface meta = mock(StepMetaInterface.class);
    when(meta.getDialogClassName()).thenReturn(String.class.getName());
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(StepMetaInterface.class, meta.getClass().getName());
            put(StepDialogInterface.class, StepDialogInterface.class.getName());
        }
    });
    PluginRegistry.getInstance().registerPlugin(StepPluginType.class, plugin);
    SpoonStepsDelegate delegate = mock(SpoonStepsDelegate.class);
    Spoon spoon = mock(Spoon.class);
    delegate.spoon = spoon;
    delegate.log = mock(LogChannelInterface.class);
    when(spoon.getShell()).thenReturn(mock(Shell.class));
    doCallRealMethod().when(delegate).getStepDialog(any(StepMetaInterface.class), any(TransMeta.class), any(String.class));
    TransMeta trans = mock(TransMeta.class);
    // verify that dialog class is requested from plugin
    try {
        // exception is expected here
        delegate.getStepDialog(meta, trans, "");
    } catch (Throwable ignore) {
        verify(meta, never()).getDialogClassName();
    }
    // verify that the deprecated way is still valid
    when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {

        {
            put(StepMetaInterface.class, meta.getClass().getName());
        }
    });
    try {
        // exception is expected here
        delegate.getStepDialog(meta, trans, "");
    } catch (Throwable ignore) {
        verify(meta, times(1)).getDialogClassName();
    }
    // cleanup
    PluginRegistry.getInstance().removePlugin(StepPluginType.class, plugin);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StepDialogInterface(org.pentaho.di.trans.step.StepDialogInterface) Spoon(org.pentaho.di.ui.spoon.Spoon) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) TransMeta(org.pentaho.di.trans.TransMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 18 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class ModelerHelper method getInstance.

public static ModelerHelper getInstance() {
    if (instance == null) {
        instance = new ModelerHelper();
        Spoon spoon = ((Spoon) SpoonFactory.getInstance());
        spoon.addSpoonMenuController(instance);
    }
    return instance;
}
Also used : Spoon(org.pentaho.di.ui.spoon.Spoon)

Example 19 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class StarModelerPerspective method generateSqlJobButton.

protected void generateSqlJobButton(StarDomain starDomain) {
    final Spoon spoon = Spoon.getInstance();
    List<DatabaseMeta> sharedDatabases = SharedDatabaseUtil.loadSharedDatabases();
    // TODO: validate presence of repository, repository directory
    // 
    JobGenerator jobGenerator = new JobGenerator(starDomain, spoon.rep, new RepositoryDirectory(), sharedDatabases, defaultLocale);
    try {
        JobMeta jobMeta = jobGenerator.generateSqlJob();
        spoon.addJobGraph(jobMeta);
        SpoonPerspectiveManager.getInstance().activatePerspective(MainSpoonPerspective.class);
    } catch (Exception e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingSqlJob.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingSqlJob.Message"), e);
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) JobGenerator(org.pentaho.di.starmodeler.generator.JobGenerator) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) XulException(org.pentaho.ui.xul.XulException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleException(org.pentaho.di.core.exception.KettleException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)

Example 20 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class RepositoryConnectController method connectToRepository.

public void connectToRepository(RepositoryMeta repositoryMeta, String username, String password) throws KettleException {
    final Repository repository = loadRepositoryObject(repositoryMeta.getId());
    repository.init(repositoryMeta);
    repositoryConnect(repository, username, password);
    if (username != null) {
        getPropsUI().setLastRepositoryLogin(username);
    }
    Spoon spoon = spoonSupplier.get();
    Runnable execute = () -> {
        if (spoon.getRepository() != null) {
            spoon.closeRepository();
        } else {
            spoon.closeAllJobsAndTransformations(true);
        }
        spoon.setRepository(repository);
        setConnectedRepository(repositoryMeta);
        fireListeners();
    };
    if (spoon.getShell() != null) {
        spoon.getShell().getDisplay().asyncExec(execute);
    } else {
        execute.run();
    }
}
Also used : ReconnectableRepository(org.pentaho.di.repository.ReconnectableRepository) AbstractRepository(org.pentaho.di.repository.AbstractRepository) Repository(org.pentaho.di.repository.Repository) Spoon(org.pentaho.di.ui.spoon.Spoon)

Aggregations

Spoon (org.pentaho.di.ui.spoon.Spoon)26 KettleException (org.pentaho.di.core.exception.KettleException)11 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)8 TransMeta (org.pentaho.di.trans.TransMeta)6 JobMeta (org.pentaho.di.job.JobMeta)5 XulException (org.pentaho.ui.xul.XulException)5 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)5 File (java.io.File)3 Shell (org.eclipse.swt.widgets.Shell)3 Test (org.junit.Test)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 PurRepository (org.pentaho.di.repository.pur.PurRepository)3 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)2