View Issue Details

IDProjectCategoryView StatusLast Update
0000018KafkaEsqueImprovementpublic2019-01-18 17:12
ReporterEminAssigned Topatschuh 
PrioritynormalSeveritytrivialReproducibilityN/A
Status resolvedResolutionfixed 
Product Version0.12.0 
Target VersionFixed in Version 
Summary0000018: Open in Editor Patch
Description

Patch to add open in txt/json editor functionality in message list context menu.

Currently throws exception if no default program is set for the file type you are trying to open (.txt or .json), should have popup or check

TagsNo tags attached.

Activities

Emin

Emin

2018-12-18 14:05

reporter  

openineditor.patch (3,182 bytes)
Index: src/main/java/com/modulo/kafkaesque/Controller.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/Controller.java	(revision 0303f2f6aa0c77c8b767f5ea5a0b89b268ff70d9)
+++ src/main/java/com/modulo/kafkaesque/Controller.java	(date 1545141786551)
@@ -34,7 +34,12 @@
 import javafx.fxml.FXML;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
+import javafx.scene.control.Button;
 import javafx.scene.control.*;
+import javafx.scene.control.Label;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextField;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.image.Image;
 import javafx.stage.DirectoryChooser;
@@ -60,10 +65,12 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.awt.*;
 import java.io.*;
 import java.time.Duration;
 import java.time.Instant;
 import java.util.*;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -172,7 +179,13 @@
                     MenuItem openinPublisher = new MenuItem("open in publisher");
                     openinPublisher.setGraphic(new FontIcon(FontAwesome.SHARE));
                     openinPublisher.setOnAction(event -> showPublishMessageDialog(row.getItem()));
-                    rowMenu.getItems().addAll(openinPublisher);
+                    MenuItem openAsTxt = new MenuItem("open in text editor");
+                    openAsTxt.setGraphic(new FontIcon(FontAwesome.EDIT));
+                    openAsTxt.setOnAction(event -> openInTextEditor(row.getItem(), "txt"));
+                    MenuItem openAsJson = new MenuItem("open in json editor");
+                    openAsJson.setGraphic(new FontIcon(FontAwesome.EDIT));
+                    openAsJson.setOnAction(event -> openInTextEditor(row.getItem(), "json"));
+                    rowMenu.getItems().addAll(openinPublisher, openAsTxt, openAsJson);
 
                     // only display context menu for non-null items:
                     row.contextMenuProperty().bind(
@@ -238,6 +251,24 @@
         bindDisableProperties();
     }
 
+    private void openInTextEditor(KafkaMessage value, String suffix) {
+        File temp;
+        try {
+            temp = File.createTempFile("kafkaEsque-export", "." + suffix);
+
+            try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))) {
+                bw.write(value.getValue());
+            }
+
+            Desktop.getDesktop().edit(temp);
+        } catch (IOException e) {
+            //TODO: this can be thrown if no default program is set
+            e.printStackTrace();
+        }
+
+
+    }
+
     private void bindDisableProperties() {
         BooleanProperty backgroundTaskInProgressProperty = backGroundTaskHolder.isInProgressProperty();
         topicListView.disableProperty().bind(backgroundTaskInProgressProperty);
openineditor.patch (3,182 bytes)
Emin

Emin

2018-12-18 14:26

reporter   ~0000021

Desktop.getDesktop().edit() auf Desktop.getDesktop.open() ändern - funktioniert dann besser mit default editors und keinem gesetzten editor

Related Changesets

KafkaEsque: master 66874898

2019-01-18 13:40:24

patschuh

Details Diff
[ESQUE-18]: Added open in editor option for messages
Affected Issues
0000018

Issue History

Date Modified Username Field Change
2018-12-18 14:05 Emin New Issue
2018-12-18 14:05 Emin File Added: openineditor.patch
2018-12-18 14:26 Emin Note Added: 0000021
2019-01-18 17:10 patschuh Changeset attached => KafkaEsque master 66874898
2019-01-18 17:12 patschuh Assigned To => patschuh
2019-01-18 17:12 patschuh Status new => resolved
2019-01-18 17:12 patschuh Resolution open => fixed