Search in sources :

Example 1 with TYPE

use of difflib.Delta.TYPE in project Gargoyle by callakrsos.

the class HtmlBaseDiffAppController method extractedWrapperedChunk.

/**
	 * chunk객체를 UI로 표현하기 위해 wrapping처리함.
	 *
	 * @param deltaType
	 * @param deltas
	 * @param readLines
	 * @return
	 */
private List<ChunkWrapper> extractedWrapperedChunk(final DeltaType deltaType, final List<Delta> deltas, final List<String> readLines) {
    int size = readLines.size();
    ArrayList<ChunkWrapper> collect = deltas.stream().map(delta -> {
        Chunk chunk = null;
        if (DeltaType.ORIGINAL == deltaType) {
            chunk = delta.getOriginal();
        } else {
            chunk = delta.getRevised();
        }
        int position = chunk.getPosition();
        @SuppressWarnings("unchecked") List<String> lines = (List<String>) chunk.getLines();
        TYPE type = delta.getType();
        ChunkWrapper chunkWrapper = new ChunkWrapper();
        chunkWrapper.setType(type);
        chunkWrapper.setLines(lines);
        chunkWrapper.setChunk(chunk);
        chunkWrapper.setPosition(position);
        chunkWrapper.setDelta(delta);
        return chunkWrapper;
    }).collect(() -> {
        ArrayList<ChunkWrapper> newChunk = new ArrayList<>(size);
        for (int i = 0; i < readLines.size(); i++) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setStr(readLines.get(i));
            chunkWrapper.setPosition(i);
            newChunk.add(chunkWrapper);
        }
        return newChunk;
    }, (collection, item) -> {
        int position = item.getPosition();
        List<String> lines = item.getLines();
        TYPE type = item.getType();
        int tmpPosition = position;
        for (String str : lines) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setType(type);
            chunkWrapper.setLines(lines);
            chunkWrapper.setPosition(position);
            chunkWrapper.setChunk(item.getChunk());
            chunkWrapper.setStr(str);
            chunkWrapper.setDelta(item.getDelta());
            collection.set(tmpPosition++, chunkWrapper);
        }
    }, (collection1, collection2) -> collection1.addAll(collection2));
    return collect;
}
Also used : Button(javafx.scene.control.Button) TextArea(javafx.scene.control.TextArea) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ListCell(javafx.scene.control.ListCell) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) LoggerFactory(org.slf4j.LoggerFactory) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) Chunk(difflib.Chunk) BackgroundFill(javafx.scene.layout.BackgroundFill) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) WebView(javafx.scene.web.WebView) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) IOException(java.io.IOException) DiffComparable(com.kyj.fx.voeditor.visual.diff.DiffComparable) Background(javafx.scene.layout.Background) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) FXML(javafx.fxml.FXML) TextBaseComparator(com.kyj.fx.voeditor.visual.diff.TextBaseComparator) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) ValueUtil(kyj.Fx.dao.wizard.core.util.ValueUtil) ObservableValue(javafx.beans.value.ObservableValue) TYPE(difflib.Delta.TYPE) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) Delta(difflib.Delta) ArrayList(java.util.ArrayList) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) ArrayList(java.util.ArrayList) List(java.util.List) Chunk(difflib.Chunk) TYPE(difflib.Delta.TYPE)

Example 2 with TYPE

use of difflib.Delta.TYPE in project Gargoyle by callakrsos.

the class FileBaseDiffAppController method extractedWrapperedChunk.

/**
	 * chunk객체를 UI로 표현하기 위해 wrapping처리함.
	 *
	 * @param deltaType
	 * @param deltas
	 * @param readLines
	 * @return
	 */
private List<ChunkWrapper> extractedWrapperedChunk(final DeltaType deltaType, final List<Delta> deltas, final List<String> readLines) {
    int size = readLines.size();
    ArrayList<ChunkWrapper> collect = deltas.stream().map(delta -> {
        Chunk chunk = null;
        if (DeltaType.ORIGINAL == deltaType) {
            chunk = delta.getOriginal();
        } else {
            chunk = delta.getRevised();
        }
        int position = chunk.getPosition();
        @SuppressWarnings("unchecked") List<String> lines = (List<String>) chunk.getLines();
        TYPE type = delta.getType();
        ChunkWrapper chunkWrapper = new ChunkWrapper();
        chunkWrapper.setType(type);
        chunkWrapper.setLines(lines);
        chunkWrapper.setChunk(chunk);
        chunkWrapper.setPosition(position);
        chunkWrapper.setDelta(delta);
        return chunkWrapper;
    }).collect(() -> {
        ArrayList<ChunkWrapper> newChunk = new ArrayList<>(size);
        for (int i = 0; i < readLines.size(); i++) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setStr(readLines.get(i));
            chunkWrapper.setPosition(i);
            newChunk.add(chunkWrapper);
        }
        return newChunk;
    }, (collection, item) -> {
        int position = item.getPosition();
        List<String> lines = item.getLines();
        TYPE type = item.getType();
        int tmpPosition = position;
        for (String str : lines) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setType(type);
            chunkWrapper.setLines(lines);
            chunkWrapper.setPosition(position);
            chunkWrapper.setChunk(item.getChunk());
            chunkWrapper.setStr(str);
            chunkWrapper.setDelta(item.getDelta());
            collection.set(tmpPosition++, chunkWrapper);
        }
    }, (collection1, collection2) -> collection1.addAll(collection2));
    return collect;
}
Also used : ListView(javafx.scene.control.ListView) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SnapshotParameters(javafx.scene.SnapshotParameters) ArrayList(java.util.ArrayList) FileBaseComparator(com.kyj.fx.voeditor.visual.diff.FileBaseComparator) Insets(javafx.geometry.Insets) Chunk(difflib.Chunk) BackgroundFill(javafx.scene.layout.BackgroundFill) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) DiffComparable(com.kyj.fx.voeditor.visual.diff.DiffComparable) ScrollEvent(javafx.scene.input.ScrollEvent) Background(javafx.scene.layout.Background) File(java.io.File) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) ValueUtil(kyj.Fx.dao.wizard.core.util.ValueUtil) TYPE(difflib.Delta.TYPE) BorderPane(javafx.scene.layout.BorderPane) Delta(difflib.Delta) ArrayList(java.util.ArrayList) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) ArrayList(java.util.ArrayList) List(java.util.List) Chunk(difflib.Chunk) TYPE(difflib.Delta.TYPE)

Example 3 with TYPE

use of difflib.Delta.TYPE in project spring-sync by spring-projects.

the class Diff method diffList.

// private helpers
private static void diffList(List<PatchOperation> operations, String path, List<?> original, List<?> modified) throws IOException, IllegalAccessException {
    difflib.Patch diff = DiffUtils.diff(original, modified);
    List<Delta> deltas = diff.getDeltas();
    for (Delta delta : deltas) {
        TYPE type = delta.getType();
        int revisedPosition = delta.getRevised().getPosition();
        if (type == TYPE.CHANGE) {
            List<?> lines = delta.getRevised().getLines();
            for (int offset = 0; offset < lines.size(); offset++) {
                Object originalObject = original.get(revisedPosition + offset);
                Object revisedObject = modified.get(revisedPosition + offset);
                diffNonList(operations, path + "/" + (revisedPosition + offset), originalObject, revisedObject);
            }
        } else if (type == TYPE.INSERT) {
            List<?> lines = delta.getRevised().getLines();
            for (int offset = 0; offset < lines.size(); offset++) {
                operations.add(new AddOperation(path + "/" + (revisedPosition + offset), lines.get(offset)));
            }
        } else if (type == TYPE.DELETE) {
            List<?> lines = delta.getOriginal().getLines();
            for (int offset = 0; offset < lines.size(); offset++) {
                Object originalObject = original.get(revisedPosition + offset);
                operations.add(new TestOperation(path + "/" + revisedPosition, originalObject));
                operations.add(new RemoveOperation(path + "/" + revisedPosition));
            }
        }
    }
}
Also used : Delta(difflib.Delta) List(java.util.List) ArrayList(java.util.ArrayList) TYPE(difflib.Delta.TYPE)

Example 4 with TYPE

use of difflib.Delta.TYPE in project Gargoyle by callakrsos.

the class TextBaseDiffAppController method extractedWrapperedChunk.

/**
	 * chunk객체를 UI로 표현하기 위해 wrapping처리함.
	 *
	 * @param deltaType
	 * @param deltas
	 * @param readLines
	 * @return
	 */
private List<ChunkWrapper> extractedWrapperedChunk(final DeltaType deltaType, final List<Delta> deltas, final List<String> readLines) {
    int size = readLines.size();
    ArrayList<ChunkWrapper> collect = deltas.stream().map(delta -> {
        Chunk chunk = null;
        if (DeltaType.ORIGINAL == deltaType) {
            chunk = delta.getOriginal();
        } else {
            chunk = delta.getRevised();
        }
        int position = chunk.getPosition();
        @SuppressWarnings("unchecked") List<String> lines = (List<String>) chunk.getLines();
        TYPE type = delta.getType();
        ChunkWrapper chunkWrapper = new ChunkWrapper();
        chunkWrapper.setType(type);
        chunkWrapper.setLines(lines);
        chunkWrapper.setChunk(chunk);
        chunkWrapper.setPosition(position);
        chunkWrapper.setDelta(delta);
        return chunkWrapper;
    }).collect(() -> {
        ArrayList<ChunkWrapper> newChunk = new ArrayList<>(size);
        for (int i = 0; i < readLines.size(); i++) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setStr(readLines.get(i));
            chunkWrapper.setPosition(i);
            newChunk.add(chunkWrapper);
        }
        return newChunk;
    }, (collection, item) -> {
        int position = item.getPosition();
        List<String> lines = item.getLines();
        TYPE type = item.getType();
        int tmpPosition = position;
        for (String str : lines) {
            ChunkWrapper chunkWrapper = new ChunkWrapper();
            chunkWrapper.setType(type);
            chunkWrapper.setLines(lines);
            chunkWrapper.setPosition(position);
            chunkWrapper.setChunk(item.getChunk());
            chunkWrapper.setStr(str);
            chunkWrapper.setDelta(item.getDelta());
            collection.set(tmpPosition++, chunkWrapper);
        }
    }, (collection1, collection2) -> collection1.addAll(collection2));
    return collect;
}
Also used : Button(javafx.scene.control.Button) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SnapshotParameters(javafx.scene.SnapshotParameters) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) Chunk(difflib.Chunk) BackgroundFill(javafx.scene.layout.BackgroundFill) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) DiffComparable(com.kyj.fx.voeditor.visual.diff.DiffComparable) ScrollEvent(javafx.scene.input.ScrollEvent) Background(javafx.scene.layout.Background) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) TextBaseComparator(com.kyj.fx.voeditor.visual.diff.TextBaseComparator) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) ValueUtil(kyj.Fx.dao.wizard.core.util.ValueUtil) ObservableValue(javafx.beans.value.ObservableValue) TYPE(difflib.Delta.TYPE) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) ChangeListener(javafx.beans.value.ChangeListener) Delta(difflib.Delta) ArrayList(java.util.ArrayList) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) ArrayList(java.util.ArrayList) List(java.util.List) Chunk(difflib.Chunk) TYPE(difflib.Delta.TYPE)

Example 5 with TYPE

use of difflib.Delta.TYPE in project Gargoyle by callakrsos.

the class TextBaseDiffAppController method initialize.

@FXML
public void initialize() {
    /* initControls */
    ivReviced = new ImageView();
    ivpReviced = new ImageViewPane(ivReviced);
    ivpReviced.setPrefWidth(200);
    ivpReviced.setPrefHeight(150);
    ivOrigin = new ImageView();
    ivpOrigin = new ImageViewPane(ivOrigin);
    ivpOrigin.setPrefWidth(200);
    ivpOrigin.setPrefHeight(150);
    gpSnap.add(ivpReviced, 0, 0);
    gpSnap.add(ivpOrigin, 1, 0);
    lvOrinal.setCellFactory(param -> new DefaultTextFieldListCell(ORIGINAL));
    lvRevice.setCellFactory(param -> new DefaultTextFieldListCell(REVICED));
    fileCompareResultProperty.addListener(compareResultListener);
    lvRevice.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvRevice.getSelectionModel().getSelectedItem();
            Delta delta = selectedItem.getDelta();
            if (delta != null && delta.getOriginal() != null) {
                movePosition = selectedItem.getPosition();
                lvOrinal.scrollTo(movePosition - 1);
                lvOrinal.getSelectionModel().select(movePosition);
            }
        }
    });
    lvOrinal.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvOrinal.getSelectionModel().getSelectedItem();
            if (selectedItem != null) {
                Delta delta = selectedItem.getDelta();
                if (delta != null && delta.getRevised() != null) {
                    movePosition = delta.getRevised().getPosition();
                    lvRevice.scrollTo(movePosition - 1);
                    lvRevice.getSelectionModel().select(movePosition);
                }
            }
        }
    });
    lvOrinal.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappOriginShot();
    });
    lvRevice.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappReviceShot();
    });
    btnCompare.setOnMouseClicked(event -> {
        String ori = txtOrigin.getText();
        String rev = txtRevice.getText();
        if (!(ori.isEmpty() && rev.isEmpty())) {
            clear();
            try {
                this.compare.setOriginal(ori);
                this.compare.setRevised(rev);
                CompareResult chunkResult = this.compare.getChunkResult();
                this.fileCompareResultProperty.set(chunkResult);
                snappOriginShot();
                snappReviceShot();
            } catch (Exception e) {
                LOGGER.error(ValueUtil.toString(e));
            }
        }
    });
    colStatus.setCellValueFactory(new Callback<CellDataFeatures<ChunkWrapper, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<ChunkWrapper, String> param) {
            TYPE type = param.getValue().getType();
            StringProperty prop = new SimpleStringProperty();
            if (type != null)
                prop.set(type.name());
            return prop;
        }
    });
    colPosition.setCellValueFactory(param -> new SimpleIntegerProperty(new Integer(param.getValue().getPosition() + 1)));
    colRevice.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getRevised();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
    colOrigin.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getOriginal();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Chunk(difflib.Chunk) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) IOException(java.io.IOException) Delta(difflib.Delta) ImageView(javafx.scene.image.ImageView) TYPE(difflib.Delta.TYPE) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) FXML(javafx.fxml.FXML)

Aggregations

Delta (difflib.Delta)8 TYPE (difflib.Delta.TYPE)8 ChunkWrapper (com.kyj.fx.voeditor.visual.diff.ChunkWrapper)7 CompareResult (com.kyj.fx.voeditor.visual.diff.CompareResult)7 Chunk (difflib.Chunk)7 IOException (java.io.IOException)7 FXML (javafx.fxml.FXML)7 ImageView (javafx.scene.image.ImageView)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)6 StringProperty (javafx.beans.property.StringProperty)6 ObservableValue (javafx.beans.value.ObservableValue)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)5 DiffComparable (com.kyj.fx.voeditor.visual.diff.DiffComparable)4 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)4 Insets (javafx.geometry.Insets)4 Label (javafx.scene.control.Label)4