Search in sources :

Example 96 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class StarModelPainter method draw.

public void draw() {
    gc.setAntialias(true);
    Point center = new Point(area.x / 2, area.y / 2);
    gc.setBackground(EColor.BACKGROUND);
    gc.setForeground(EColor.BLACK);
    gc.fillRectangle(0, 0, area.x, area.y);
    // gc.drawText("bounds: x="+rect.x+", y="+rect.y+", height="+rect.height+", width="+rect.width, 10, 10);
    List<LogicalTable> tableList = new ArrayList<LogicalTable>();
    tableList.addAll(logicalModel.getLogicalTables());
    // Find the fact...
    // 
    LogicalTable fact = null;
    for (LogicalTable logicalTable : tableList) {
        if (TableType.FACT == ConceptUtil.getTableType(logicalTable)) {
            fact = logicalTable;
        }
    }
    if (fact != null) {
        tableList.remove(fact);
    }
    int maxWidth = Integer.MIN_VALUE;
    for (LogicalTable table : tableList) {
        String name = table.getName(locale);
        if (!Utils.isEmpty(name)) {
            Point p = gc.textExtent(name);
            if (p.x > maxWidth)
                maxWidth = p.x;
        }
    }
    List<TablePoint> points = new ArrayList<TablePoint>();
    if (fact != null) {
        points.add(new TablePoint(fact, center));
    }
    // 
    if (!tableList.isEmpty()) {
        List<TablePoint> dimPoints = getCirclePoints(center, center.x - maxWidth / 2 - 20, center.y - 20, tableList);
        points.addAll(dimPoints);
    }
    // 
    for (LogicalRelationship rel : logicalRelationships) {
        LogicalTable fromTable = rel.getFromTable();
        LogicalTable toTable = rel.getToTable();
        Point from = findPointOfTable(points, fromTable);
        Point to = findPointOfTable(points, toTable);
        if (from != null && to != null) {
            gc.drawLine(from.x, from.y, to.x, to.y);
        }
    }
    // 
    for (TablePoint tablePoint : points) {
        LogicalTable table = tablePoint.logicalTable;
        Point point = tablePoint.point;
        drawCircleName(point, table);
    }
}
Also used : ArrayList(java.util.ArrayList) Point(org.pentaho.di.core.gui.Point) LogicalTable(org.pentaho.metadata.model.LogicalTable) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship) Point(org.pentaho.di.core.gui.Point)

Example 97 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class JobGenerator method generateSqlJob.

public JobMeta generateSqlJob() throws KettleException {
    DatabaseMeta databaseMeta = findTargetDatabaseMeta();
    Database db = new Database(Spoon.loggingObject, databaseMeta);
    try {
        db.connect();
        JobMeta jobMeta = new JobMeta();
        jobMeta.setName("Create tables for '" + ConceptUtil.getName(domain, locale) + "'");
        jobMeta.setDescription(ConceptUtil.getDescription(domain, locale));
        // Let's not forget to add the database connection
        // 
        jobMeta.addDatabase(databaseMeta);
        Point location = new Point(GRAPH_LEFT, GRAPH_TOP);
        // Create a job entry
        // 
        JobEntryCopy startEntry = JobMeta.createStartEntry();
        startEntry.setLocation(location.x, location.y);
        startEntry.setDrawn();
        jobMeta.addJobEntry(startEntry);
        JobEntryCopy lastEntry = startEntry;
        nextLocation(location);
        // Create one SQL entry for all the physically unique dimensions and facts
        // We need to get a list of all known dimensions with physical table name.
        // 
        List<LogicalTable> tables = getUniqueLogicalTables();
        for (LogicalTable logicalTable : tables) {
            String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            String tableName = ConceptUtil.getName(logicalTable, locale);
            String tableDescription = ConceptUtil.getDescription(logicalTable, locale);
            TableType tableType = ConceptUtil.getTableType(logicalTable);
            DimensionType dimensionType = ConceptUtil.getDimensionType(logicalTable);
            boolean isFact = tableType == TableType.FACT;
            boolean isDimension = tableType == TableType.DIMENSION;
            boolean isJunk = isDimension && dimensionType == DimensionType.JUNK_DIMENSION;
            JobEntrySQL sqlEntry = new JobEntrySQL(phTable);
            sqlEntry.setDatabase(databaseMeta);
            // Get the SQL for this table...
            // 
            String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, phTable);
            String phKeyField = null;
            // The technical key is the first KEY field...
            // 
            LogicalColumn keyColumn = null;
            if (isDimension) {
                keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
            }
            if (keyColumn != null) {
                phKeyField = ConceptUtil.getString(keyColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
            }
            // Get all the fields for the logical table...
            // 
            RowMetaInterface fields = getRowForLogicalTable(databaseMeta, logicalTable);
            // Generate the required SQL to make this happen
            // 
            String sql = db.getCreateTableStatement(schemaTable, fields, phKeyField, databaseMeta.supportsAutoinc() && !isFact, null, true);
            // 
            if (keyColumn != null) {
                ValueMetaInterface keyValueMeta = getValueForLogicalColumn(databaseMeta, keyColumn);
                String indexName = databaseMeta.quoteField("IDX_" + phTable.replace(" ", "_").toUpperCase() + "_" + phKeyField.toUpperCase());
                String indexSql = db.getCreateIndexStatement(schemaTable, indexName, new String[] { keyValueMeta.getName() }, true, false, true, true);
                sql += Const.CR + indexSql;
            }
            // 
            if (isFact) {
                List<LogicalColumn> fks = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.TECHNICAL_KEY);
                for (LogicalColumn fk : fks) {
                    ValueMetaInterface keyValueMeta = getValueForLogicalColumn(databaseMeta, fk);
                    String phColumn = ConceptUtil.getString(fk, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
                    if (!Utils.isEmpty(phColumn)) {
                        String indexName = databaseMeta.quoteField("IDX_" + phTable.replace(" ", "_").toUpperCase() + "_" + phColumn.toUpperCase());
                        String indexSql = db.getCreateIndexStatement(schemaTable, indexName, new String[] { keyValueMeta.getName() }, true, false, true, true);
                        sql += Const.CR + indexSql;
                    }
                }
            }
            // 
            if (isDimension) {
                List<LogicalColumn> naturalKeys = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.NATURAL_KEY);
                if (!naturalKeys.isEmpty()) {
                    String indexName = databaseMeta.quoteField("IDX_" + phTable.replace(" ", "_").toUpperCase() + "_LOOKUP");
                    String[] fieldNames = new String[naturalKeys.size()];
                    for (int i = 0; i < fieldNames.length; i++) {
                        ValueMetaInterface keyValueMeta = getValueForLogicalColumn(databaseMeta, naturalKeys.get(i));
                        fieldNames[i] = keyValueMeta.getName();
                    }
                    String indexSql = db.getCreateIndexStatement(schemaTable, indexName, fieldNames, false, false, false, true);
                    sql += Const.CR + indexSql;
                }
            }
            if (isJunk) {
                List<LogicalColumn> attributes = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE);
                if (!attributes.isEmpty()) {
                    String indexName = databaseMeta.quoteField("IDX_" + phTable.replace(" ", "_").toUpperCase() + "_LOOKUP");
                    String[] fieldNames = new String[attributes.size()];
                    for (int i = 0; i < fieldNames.length; i++) {
                        ValueMetaInterface attrValueMeta = getValueForLogicalColumn(databaseMeta, attributes.get(i));
                        fieldNames[i] = attrValueMeta.getName();
                    }
                    String indexSql = db.getCreateIndexStatement(schemaTable, indexName, fieldNames, false, false, false, true);
                    sql += Const.CR + indexSql;
                }
            }
            // If it's
            sqlEntry.setSQL(sql);
            sqlEntry.setDescription("Generated based on logical table '" + tableName + "'" + Const.CR + Const.CR + Const.NVL(tableDescription, ""));
            JobEntryCopy sqlCopy = new JobEntryCopy(sqlEntry);
            sqlCopy.setLocation(location.x, location.y);
            sqlCopy.setDrawn();
            nextLocation(location);
            jobMeta.addJobEntry(sqlCopy);
            // Hook up with the previous job entry too...
            // 
            JobHopMeta jobHop = new JobHopMeta(lastEntry, sqlCopy);
            jobHop.setEnabled();
            jobHop.setConditional();
            jobHop.setEvaluation(true);
            if (lastEntry.isStart()) {
                jobHop.setUnconditional();
            }
            jobMeta.addJobHop(jobHop);
            lastEntry = sqlCopy;
        }
        return jobMeta;
    } catch (Exception e) {
        throw new KettleException("There was an error during the generation of the SQL job", e);
    } finally {
        if (db != null) {
            db.disconnect();
        }
    }
}
Also used : DimensionType(org.pentaho.di.starmodeler.DimensionType) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) JobHopMeta(org.pentaho.di.job.JobHopMeta) TableType(org.pentaho.metadata.model.concept.types.TableType) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Point(org.pentaho.di.core.gui.Point) LogicalTable(org.pentaho.metadata.model.LogicalTable) JobEntrySQL(org.pentaho.di.job.entries.sql.JobEntrySQL) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Database(org.pentaho.di.core.database.Database)

Example 98 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class Spoon method copyTransformationImage.

public void copyTransformationImage(TransMeta transMeta) {
    TransGraph transGraph = delegates.trans.findTransGraphOfTransformation(transMeta);
    if (transGraph == null) {
        return;
    }
    Clipboard clipboard = GUIResource.getInstance().getNewClipboard();
    Point area = transMeta.getMaximum();
    Image image = transGraph.getTransformationImage(Display.getCurrent(), area.x, area.y, 1.0f);
    clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { ImageTransfer.getInstance() });
}
Also used : TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Image(org.eclipse.swt.graphics.Image)

Example 99 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class Spoon method pasteXML.

public void pasteXML(TransMeta transMeta, String clipcontent, Point loc) {
    if (RepositorySecurityUI.verifyOperations(shell, rep, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.EXECUTE_TRANSFORMATION)) {
        return;
    }
    try {
        Document doc = XMLHandler.loadXMLString(clipcontent);
        Node transNode = XMLHandler.getSubNode(doc, Spoon.XML_TAG_TRANSFORMATION_STEPS);
        // De-select all, re-select pasted steps...
        transMeta.unselectAll();
        Node stepsNode = XMLHandler.getSubNode(transNode, "steps");
        int nr = XMLHandler.countNodes(stepsNode, "step");
        if (getLog().isDebug()) {
            // "I found "+nr+" steps to paste on location: "
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundSteps", "" + nr) + loc);
        }
        StepMeta[] steps = new StepMeta[nr];
        ArrayList<String> stepOldNames = new ArrayList<>(nr);
        // Point min = new Point(loc.x, loc.y);
        Point min = new Point(99999999, 99999999);
        // Load the steps...
        for (int i = 0; i < nr; i++) {
            Node stepNode = XMLHandler.getSubNodeByNr(stepsNode, "step", i);
            steps[i] = new StepMeta(stepNode, transMeta.getDatabases(), metaStore);
            if (loc != null) {
                Point p = steps[i].getLocation();
                if (min.x > p.x) {
                    min.x = p.x;
                }
                if (min.y > p.y) {
                    min.y = p.y;
                }
            }
        }
        // Load the hops...
        Node hopsNode = XMLHandler.getSubNode(transNode, "order");
        nr = XMLHandler.countNodes(hopsNode, "hop");
        if (getLog().isDebug()) {
            // "I found "+nr+" hops to paste."
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundHops", "" + nr));
        }
        TransHopMeta[] hops = new TransHopMeta[nr];
        for (int i = 0; i < nr; i++) {
            Node hopNode = XMLHandler.getSubNodeByNr(hopsNode, "hop", i);
            hops[i] = new TransHopMeta(hopNode, Arrays.asList(steps));
        }
        // This is the offset:
        Point offset = new Point(loc.x - min.x, loc.y - min.y);
        // Undo/redo object positions...
        int[] position = new int[steps.length];
        for (int i = 0; i < steps.length; i++) {
            Point p = steps[i].getLocation();
            String name = steps[i].getName();
            steps[i].setLocation(p.x + offset.x, p.y + offset.y);
            steps[i].setDraw(true);
            // Check the name, find alternative...
            stepOldNames.add(name);
            steps[i].setName(transMeta.getAlternativeStepname(name));
            transMeta.addStep(steps[i]);
            position[i] = transMeta.indexOfStep(steps[i]);
            steps[i].setSelected(true);
        }
        // Add the hops too...
        for (TransHopMeta hop : hops) {
            transMeta.addTransHop(hop);
        }
        // Load the notes...
        Node notesNode = XMLHandler.getSubNode(transNode, "notepads");
        nr = XMLHandler.countNodes(notesNode, "notepad");
        if (getLog().isDebug()) {
            // "I found "+nr+" notepads to paste."
            getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundNotepads", "" + nr));
        }
        NotePadMeta[] notes = new NotePadMeta[nr];
        for (int i = 0; i < notes.length; i++) {
            Node noteNode = XMLHandler.getSubNodeByNr(notesNode, "notepad", i);
            notes[i] = new NotePadMeta(noteNode);
            Point p = notes[i].getLocation();
            notes[i].setLocation(p.x + offset.x, p.y + offset.y);
            transMeta.addNote(notes[i]);
            notes[i].setSelected(true);
        }
        // Set the source and target steps ...
        for (StepMeta step : steps) {
            StepMetaInterface smi = step.getStepMetaInterface();
            smi.searchInfoAndTargetSteps(transMeta.getSteps());
        }
        // Set the error handling hops
        Node errorHandlingNode = XMLHandler.getSubNode(transNode, TransMeta.XML_TAG_STEP_ERROR_HANDLING);
        int nrErrorHandlers = XMLHandler.countNodes(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG);
        for (int i = 0; i < nrErrorHandlers; i++) {
            Node stepErrorMetaNode = XMLHandler.getSubNodeByNr(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG, i);
            StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta.getParentVariableSpace(), stepErrorMetaNode, transMeta.getSteps());
            // Handle pasting multiple times, need to update source and target step names
            int srcStepPos = stepOldNames.indexOf(stepErrorMeta.getSourceStep().getName());
            int tgtStepPos = stepOldNames.indexOf(stepErrorMeta.getTargetStep().getName());
            StepMeta sourceStep = transMeta.findStep(steps[srcStepPos].getName());
            if (sourceStep != null) {
                sourceStep.setStepErrorMeta(stepErrorMeta);
            }
            sourceStep.setStepErrorMeta(null);
            if (tgtStepPos >= 0) {
                sourceStep.setStepErrorMeta(stepErrorMeta);
                StepMeta targetStep = transMeta.findStep(steps[tgtStepPos].getName());
                stepErrorMeta.setSourceStep(sourceStep);
                stepErrorMeta.setTargetStep(targetStep);
            }
        }
        // Save undo information too...
        addUndoNew(transMeta, steps, position, false);
        int[] hopPos = new int[hops.length];
        for (int i = 0; i < hops.length; i++) {
            hopPos[i] = transMeta.indexOfTransHop(hops[i]);
        }
        addUndoNew(transMeta, hops, hopPos, true);
        int[] notePos = new int[notes.length];
        for (int i = 0; i < notes.length; i++) {
            notePos[i] = transMeta.indexOfNote(notes[i]);
        }
        addUndoNew(transMeta, notes, notePos, true);
        if (transMeta.haveStepsChanged()) {
            refreshTree();
            refreshGraph();
        }
    } catch (KettleException e) {
        // "Error pasting steps...",
        // "I was unable to paste steps to this transformation"
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Document(org.w3c.dom.Document) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) TransHopMeta(org.pentaho.di.trans.TransHopMeta) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Example 100 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class Spoon method printTransFile.

private void printTransFile(TransMeta transMeta) {
    TransGraph transGraph = getActiveTransGraph();
    if (transGraph == null) {
        return;
    }
    PrintSpool ps = new PrintSpool();
    Printer printer = ps.getPrinter(shell);
    // Create an image of the screen
    Point max = transMeta.getMaximum();
    Image img = transGraph.getTransformationImage(printer, max.x, max.y, 1.0f);
    ps.printImage(shell, img);
    img.dispose();
    ps.dispose();
}
Also used : TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) PrintSpool(org.pentaho.di.ui.core.PrintSpool) Printer(org.eclipse.swt.printing.Printer) Image(org.eclipse.swt.graphics.Image)

Aggregations

Point (org.pentaho.di.core.gui.Point)141 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)72 Test (org.junit.Test)37 StepMeta (org.pentaho.di.trans.step.StepMeta)34 NotePadMeta (org.pentaho.di.core.NotePadMeta)29 KettleException (org.pentaho.di.core.exception.KettleException)28 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)28 PrintWriter (java.io.PrintWriter)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)26 HttpServletResponse (javax.servlet.http.HttpServletResponse)26 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)26 TransMeta (org.pentaho.di.trans.TransMeta)25 StringWriter (java.io.StringWriter)24 AreaOwner (org.pentaho.di.core.gui.AreaOwner)22 Trans (org.pentaho.di.trans.Trans)18 JobMeta (org.pentaho.di.job.JobMeta)17 ArrayList (java.util.ArrayList)16 TransHopMeta (org.pentaho.di.trans.TransHopMeta)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)12