Search in sources :

Example 76 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class ExcelInputDialogTest method getFieldsTest.

@Test
public /**
 * http://jira.pentaho.com/browse/PDI-13930
 */
void getFieldsTest() throws Exception {
    ExcelInputDialog dialog = Mockito.mock(ExcelInputDialog.class);
    RowMeta fields = new RowMeta();
    ExcelInputMeta info = Mockito.mock(ExcelInputMeta.class);
    Mockito.doReturn(true).when(info).readAllSheets();
    int[] startColumn = { 0 };
    Mockito.doReturn(startColumn).when(info).getStartColumn();
    int[] startRow = { 0 };
    Mockito.doReturn(startRow).when(info).getStartRow();
    KWorkbook workbook = Mockito.mock(KWorkbook.class);
    Mockito.doReturn(1).when(workbook).getNumberOfSheets();
    KSheet sheet = Mockito.mock(KSheet.class);
    Mockito.doReturn(sheet).when(workbook).getSheet(0);
    KCell cell = Mockito.mock(KCell.class);
    int fieldCount = 400;
    for (int i = 0; i <= fieldCount - 1; i++) {
        Mockito.doReturn(cell).when(sheet).getCell(i, 0);
        Mockito.doReturn(cell).when(sheet).getCell(i, 1);
    }
    Mockito.doReturn("testValue").when(cell).getContents();
    Mockito.doReturn(KCellType.NUMBER).when(cell).getType();
    PluginRegistry pluginRegistry = Mockito.mock(PluginRegistry.class);
    PluginInterface stringPlugin = Mockito.mock(PluginInterface.class);
    Mockito.doReturn(stringPlugin).when(pluginRegistry).getPlugin(ValueMetaPluginType.class, "1");
    Mockito.doReturn(Mockito.mock(ValueMetaInterface.class)).when(pluginRegistry).loadClass(stringPlugin, ValueMetaInterface.class);
    ValueMetaFactory.pluginRegistry = pluginRegistry;
    Method processingWorkbookMethod = ExcelInputDialog.class.getDeclaredMethod("processingWorkbook", RowMetaInterface.class, ExcelInputMeta.class, KWorkbook.class);
    processingWorkbookMethod.setAccessible(true);
    processingWorkbookMethod.invoke(dialog, fields, info, workbook);
    Assert.assertEquals(fieldCount, fields.size());
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) RowMeta(org.pentaho.di.core.row.RowMeta) KWorkbook(org.pentaho.di.core.spreadsheet.KWorkbook) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) KSheet(org.pentaho.di.core.spreadsheet.KSheet) Method(java.lang.reflect.Method) KCell(org.pentaho.di.core.spreadsheet.KCell) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 77 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class RepositoryConnectControllerTest method setUp.

@Before
public void setUp() {
    controller = new RepositoryConnectController(pluginRegistry, () -> spoon, repositoriesMeta);
    when(pluginInterface.getName()).thenReturn(PLUGIN_NAME);
    when(pluginInterface.getIds()).thenReturn(new String[] { ID });
    when(pluginInterface.getDescription()).thenReturn(PLUGIN_DESCRIPTION);
    List<PluginInterface> plugins = new ArrayList<>();
    plugins.add(pluginInterface);
    when(pluginRegistry.getPlugins(RepositoryPluginType.class)).thenReturn(plugins);
    when(repositoryMeta.getId()).thenReturn(ID);
    when(repositoryMeta.getName()).thenReturn(PLUGIN_NAME);
    when(repositoryMeta.getDescription()).thenReturn(PLUGIN_DESCRIPTION);
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList) RepositoryConnectController(org.pentaho.di.ui.repo.controller.RepositoryConnectController) Before(org.junit.Before)

Example 78 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class JmsProducerDialog method getImage.

private Image getImage() {
    PluginInterface plugin = PluginRegistry.getInstance().getPlugin(StepPluginType.class, stepMeta.getStepMetaInterface());
    String id = plugin.getIds()[0];
    if (id != null) {
        return GUIResource.getInstance().getImagesSteps().get(id).getAsBitmapForSize(shell.getDisplay(), ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
    }
    return null;
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString)

Example 79 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class Spoon method refreshCoreObjects.

public void refreshCoreObjects() {
    if (shell.isDisposed()) {
        return;
    }
    if (!designSelected) {
        return;
    }
    if (coreObjectsTree == null || coreObjectsTree.isDisposed()) {
        addCoreObjectsTree();
    }
    showTrans = getActiveTransformation() != null;
    showJob = getActiveJob() != null;
    if (showTrans == previousShowTrans && showJob == previousShowJob) {
        return;
    }
    // First remove all the entries that where present...
    // 
    TreeItem[] expandItems = coreObjectsTree.getItems();
    for (TreeItem item : expandItems) {
        item.dispose();
    }
    if (showTrans) {
        // Fill the base components...
        // 
        // ////////////////////////////////////////////////////////////////////////////////////////////////
        // TRANSFORMATIONS
        // ////////////////////////////////////////////////////////////////////////////////////////////////
        PluginRegistry registry = PluginRegistry.getInstance();
        final List<PluginInterface> baseSteps = registry.getPlugins(StepPluginType.class);
        final List<String> baseCategories = registry.getCategories(StepPluginType.class);
        for (String baseCategory : baseCategories) {
            TreeItem item = new TreeItem(coreObjectsTree, SWT.NONE);
            item.setText(baseCategory);
            item.setImage(GUIResource.getInstance().getImageFolder());
            List<PluginInterface> sortedCat = baseSteps.stream().filter(baseStep -> baseStep.getCategory().equalsIgnoreCase(baseCategory)).sorted(Comparator.comparing(PluginInterface::getName)).collect(Collectors.toList());
            for (PluginInterface p : sortedCat) {
                final Image stepImage = GUIResource.getInstance().getImagesStepsSmall().get(p.getIds()[0]);
                String pluginName = p.getName();
                String pluginDescription = p.getDescription();
                if (!filterMatch(pluginName) && !filterMatch(pluginDescription)) {
                    continue;
                }
                createTreeItem(item, pluginName, stepImage, p.getIds()[0]);
                coreStepToolTipMap.put(pluginName, pluginDescription);
            }
        }
        // Add History Items...
        TreeItem item = new TreeItem(coreObjectsTree, SWT.NONE);
        item.setText(BaseMessages.getString(PKG, "Spoon.History"));
        item.setImage(GUIResource.getInstance().getImageFolder());
        List<ObjectUsageCount> pluginHistory = props.getPluginHistory();
        // 
        for (int i = 0; i < pluginHistory.size() && i < 10; i++) {
            ObjectUsageCount usage = pluginHistory.get(i);
            PluginInterface stepPlugin = PluginRegistry.getInstance().findPluginWithId(StepPluginType.class, usage.getObjectName());
            if (stepPlugin != null) {
                final Image stepImage = GUIResource.getInstance().getImagesSteps().get(stepPlugin.getIds()[0]).getAsBitmapForSize(display, ConstUI.MEDIUM_ICON_SIZE, ConstUI.MEDIUM_ICON_SIZE);
                String pluginName = Const.NVL(stepPlugin.getName(), "");
                String pluginDescription = Const.NVL(stepPlugin.getDescription(), "");
                if (!filterMatch(pluginName) && !filterMatch(pluginDescription)) {
                    continue;
                }
                TreeItem stepItem = createTreeItem(item, pluginName, stepImage);
                stepItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        System.out.println("Tree item Listener fired");
                    }
                });
                coreStepToolTipMap.put(stepPlugin.getDescription(), pluginDescription + " (" + usage.getNrUses() + ")");
            }
        }
    }
    if (showJob) {
        // Fill the base components...
        // 
        // ////////////////////////////////////////////////////////////////////////////////////////////////
        // JOBS
        // ////////////////////////////////////////////////////////////////////////////////////////////////
        PluginRegistry registry = PluginRegistry.getInstance();
        List<PluginInterface> baseJobEntries = registry.getPlugins(JobEntryPluginType.class);
        List<String> baseCategories = registry.getCategories(JobEntryPluginType.class);
        TreeItem generalItem = null;
        for (String baseCategory : baseCategories) {
            TreeItem item = new TreeItem(coreObjectsTree, SWT.NONE);
            item.setText(baseCategory);
            item.setImage(GUIResource.getInstance().getImageFolder());
            if (baseCategory.equalsIgnoreCase(JobEntryPluginType.GENERAL_CATEGORY)) {
                generalItem = item;
            }
            for (int j = 0; j < baseJobEntries.size(); j++) {
                if (!baseJobEntries.get(j).getIds()[0].equals(JobMeta.STRING_SPECIAL)) {
                    if (baseJobEntries.get(j).getCategory().equalsIgnoreCase(baseCategory)) {
                        final Image jobEntryImage = GUIResource.getInstance().getImagesJobentriesSmall().get(baseJobEntries.get(j).getIds()[0]);
                        String pluginName = Const.NVL(baseJobEntries.get(j).getName(), "");
                        String pluginDescription = Const.NVL(baseJobEntries.get(j).getDescription(), "");
                        if (!filterMatch(pluginName) && !filterMatch(pluginDescription)) {
                            continue;
                        }
                        TreeItem stepItem = createTreeItem(item, pluginName, jobEntryImage);
                        stepItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                System.out.println("Tree item Listener fired");
                            }
                        });
                        // if (isPlugin)
                        // stepItem.setFont(GUIResource.getInstance().getFontBold());
                        coreJobToolTipMap.put(pluginName, pluginDescription);
                    }
                }
            }
        }
        // First add a few "Special entries: Start, Dummy, OK, ERROR
        // We add these to the top of the base category, we don't care about
        // the sort order here.
        // 
        JobEntryCopy startEntry = JobMeta.createStartEntry();
        JobEntryCopy dummyEntry = JobMeta.createDummyEntry();
        String[] specialText = new String[] { startEntry.getName(), dummyEntry.getName() };
        String[] specialTooltip = new String[] { startEntry.getDescription(), dummyEntry.getDescription() };
        Image[] specialImage = new Image[] { GUIResource.getInstance().getImageStartMedium(), GUIResource.getInstance().getImageDummyMedium() };
        int pos = 0;
        for (int i = 0; i < specialText.length; i++) {
            if (!filterMatch(specialText[i]) && !filterMatch(specialTooltip[i])) {
                continue;
            }
            TreeItem specialItem = new TreeItem(generalItem, SWT.NONE, pos);
            specialItem.setImage(specialImage[i]);
            specialItem.setText(specialText[i]);
            specialItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event arg0) {
                    System.out.println("Tree item Listener fired");
                }
            });
            coreJobToolTipMap.put(specialText[i], specialTooltip[i]);
            pos++;
        }
    }
    variableComposite.layout(true, true);
    previousShowTrans = showTrans;
    previousShowJob = showJob;
}
Also used : ObjectUsageCount(org.pentaho.di.core.ObjectUsageCount) FileLoggingEventListener(org.pentaho.di.core.logging.FileLoggingEventListener) PluginTypeListener(org.pentaho.di.core.plugins.PluginTypeListener) ModifyListener(org.eclipse.swt.events.ModifyListener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) PropertyChangeListener(java.beans.PropertyChangeListener) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) TabListener(org.pentaho.xul.swt.tab.TabListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeItem(org.eclipse.swt.widgets.TreeItem) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Image(org.eclipse.swt.graphics.Image) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) SpoonLifeCycleEvent(org.pentaho.di.ui.spoon.SpoonLifecycleListener.SpoonLifeCycleEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) Event(org.eclipse.swt.widgets.Event) TreeEvent(org.eclipse.swt.events.TreeEvent)

Example 80 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class Spoon method helpStep.

public void helpStep() {
    final StepMeta stepMeta = (StepMeta) selectionObject;
    PluginInterface stepPlugin = PluginRegistry.getInstance().findPluginWithId(StepPluginType.class, stepMeta.getStepID());
    HelpUtils.openHelpDialog(shell, stepPlugin);
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)99 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)45 KettleException (org.pentaho.di.core.exception.KettleException)24 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)12 TransMeta (org.pentaho.di.trans.TransMeta)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)10 Test (org.junit.Test)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)9 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 Point (org.pentaho.di.core.gui.Point)8 JobMeta (org.pentaho.di.job.JobMeta)8 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 TreeItem (org.eclipse.swt.widgets.TreeItem)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 LongObjectId (org.pentaho.di.repository.LongObjectId)6 ObjectId (org.pentaho.di.repository.ObjectId)6