You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/12/22 18:54:58 UTC
[incubator-hop] branch master updated: HOP-3577 : Explorer perspective should allow editing of all text file types HOP-3578 : Open a couple of special files as editable text
This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git
The following commit(s) were added to refs/heads/master by this push:
new 71c08b9 HOP-3577 : Explorer perspective should allow editing of all text file types HOP-3578 : Open a couple of special files as editable text
new 8e0db77 Merge pull request #1241 from mattcasters/master
71c08b9 is described below
commit 71c08b9b4d859f02c976ced7d0be902877b86103
Author: Matt Casters <ma...@gmail.com>
AuthorDate: Wed Dec 22 13:48:20 2021 +0100
HOP-3577 : Explorer perspective should allow editing of all text file types
HOP-3578 : Open a couple of special files as editable text
---
.../transforms/types/JsonExplorerFileType.java | 4 +-
.../types/JsonExplorerFileTypeHandler.java | 66 +-------------------
.../transforms/types/CsvExplorerFileType.java | 4 +-
.../transforms/types/LogExplorerFileType.java | 4 +-
.../transforms/types/MarkDownExplorerFileType.java | 4 +-
.../transforms/types/TextExplorerFileType.java | 4 +-
.../types/TextExplorerFileTypeHandler.java | 32 +---------
.../transforms/xml/types/XmlExplorerFileType.java | 4 +-
.../xml/types/XmlExplorerFileTypeHandler.java | 32 +---------
.../file/types/log/LogExplorerFileType.java | 13 +++-
.../file/types/log/LogExplorerFileTypeHandler.java | 48 ++++-----------
.../types/noext/NoExtensionExplorerFileType.java | 71 +++++++++++++++++-----
.../NoExtensionExplorerFileTypeHandler.java} | 42 ++-----------
.../BaseTextExplorerFileType.java} | 39 ++++++------
.../text/BaseTextExplorerFileTypeHandler.java | 16 +++--
15 files changed, 125 insertions(+), 258 deletions(-)
diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java
index 542d932..3712267 100644
--- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java
+++ b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -30,13 +29,14 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.capabilities.FileTypeCapabilities;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
@HopFileTypePlugin(
id = "JsonExplorerFileType",
name = "JSON File Type",
description = "JSON file handling in the explorer perspective",
image = "json.svg")
-public class JsonExplorerFileType extends BaseExplorerFileType<JsonExplorerFileTypeHandler>
+public class JsonExplorerFileType extends BaseTextExplorerFileType<JsonExplorerFileTypeHandler>
implements IExplorerFileType<JsonExplorerFileTypeHandler> {
public JsonExplorerFileType() {
diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java
index ca4c1ab..0f0ba4e 100644
--- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java
+++ b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -29,6 +28,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileTypeHandler;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileTypeHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -40,73 +40,11 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/** How do we handle a JSON file in file explorer perspective? */
-public class JsonExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+public class JsonExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
- private Text wText;
-
public JsonExplorerFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
-
- @Override
- public void renderFile(Composite composite) {
- // Render the file by simply showing the file content as a text widget...
- //
- wText = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- PropsUi.getInstance().setLook(wText, Props.WIDGET_STYLE_FIXED);
- FormData fdText = new FormData();
- fdText.left = new FormAttachment(0, 0);
- fdText.right = new FormAttachment(100, 0);
- fdText.top = new FormAttachment(0, 0);
- fdText.bottom = new FormAttachment(100, 0);
- wText.setLayoutData(fdText);
-
- // TODO: add bottom section to show status, size, changed dates, cursor position...
- // TODO: options for validation, pretty print, ...
- // TODO: options for reading the file with a JSON Input transform
- // TODO: option to discard changes (reload from disk)
- // TODO: find in file feature, hook it up to the project find function
- //
-
- try {
- String contents = readTextFileContent("UTF-8");
- wText.setText(Const.NVL(contents, ""));
- } catch (Exception e) {
- LogChannel.UI.logError(
- "Error reading contents of file '" + explorerFile.getFilename() + "'", e);
- }
-
- // If the widget changes after this it's been changed by the user
- //
- wText.addModifyListener(
- e -> {
- explorerFile.setChanged();
- perspective.updateGui();
- });
- }
-
- @Override
- public void save() throws HopException {
-
- try {
- // Save the current explorer file ....
- //
- String filename = explorerFile.getFilename();
-
- // Save the file...
- //
- try (OutputStream outputStream = HopVfs.getOutputStream(filename,false)) {
- outputStream.write(wText.getText().getBytes(StandardCharsets.UTF_8));
- outputStream.flush();
- }
-
- explorerFile.clearChanged();
- perspective.refresh(); // refresh the explorer perspective tree
- perspective.updateGui(); // Update menu options
- } catch (Exception e) {
- throw new HopException("Unable to save JSON file '" + explorerFile.getFilename() + "'", e);
- }
- }
}
diff --git a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/CsvExplorerFileType.java b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/CsvExplorerFileType.java
index 15f9811..5729950 100644
--- a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/CsvExplorerFileType.java
+++ b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/CsvExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -28,6 +27,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,7 +36,7 @@ import java.util.Properties;
name = "JSON File Type",
description = "JSON file handling in the explorer perspective",
image = "textfile.svg")
-public class CsvExplorerFileType extends BaseExplorerFileType<TextExplorerFileTypeHandler>
+public class CsvExplorerFileType extends BaseTextExplorerFileType<TextExplorerFileTypeHandler>
implements IExplorerFileType<TextExplorerFileTypeHandler> {
public CsvExplorerFileType() {
diff --git a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/LogExplorerFileType.java b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/LogExplorerFileType.java
index e91df87..9342c3f 100644
--- a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/LogExplorerFileType.java
+++ b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/LogExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -28,6 +27,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,7 +36,7 @@ import java.util.Properties;
name = "Log File Type",
description = "Log file handling in the explorer perspective",
image = "ui/images/log.svg")
-public class LogExplorerFileType extends BaseExplorerFileType<TextExplorerFileTypeHandler>
+public class LogExplorerFileType extends BaseTextExplorerFileType<TextExplorerFileTypeHandler>
implements IExplorerFileType<TextExplorerFileTypeHandler> {
public LogExplorerFileType() {
diff --git a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
index 4acd86f..02954fd 100644
--- a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
+++ b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -28,6 +27,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,7 +36,7 @@ import java.util.Properties;
name = "MarkDown File Type",
description = "MarkDown file handling in the explorer perspective",
image = "textfile.svg")
-public class MarkDownExplorerFileType extends BaseExplorerFileType<TextExplorerFileTypeHandler>
+public class MarkDownExplorerFileType extends BaseTextExplorerFileType<TextExplorerFileTypeHandler>
implements IExplorerFileType<TextExplorerFileTypeHandler> {
public MarkDownExplorerFileType() {
diff --git a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileType.java b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileType.java
index fe5de83..46d7780 100644
--- a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileType.java
+++ b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -28,6 +27,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,7 +36,7 @@ import java.util.Properties;
name = "TXT File Type",
description = "Text file handling in the explorer perspective",
image = "textfile.svg")
-public class TextExplorerFileType extends BaseExplorerFileType<TextExplorerFileTypeHandler>
+public class TextExplorerFileType extends BaseTextExplorerFileType<TextExplorerFileTypeHandler>
implements IExplorerFileType<TextExplorerFileTypeHandler> {
public TextExplorerFileType() {
diff --git a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileTypeHandler.java b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileTypeHandler.java
index fe50d0d..45e9823 100644
--- a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileTypeHandler.java
+++ b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/TextExplorerFileTypeHandler.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.types;
@@ -27,6 +26,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileTypeHandler;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileTypeHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -34,39 +34,11 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
/** How do we handle an SVG file in file explorer perspective? */
-public class TextExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+public class TextExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
public TextExplorerFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
-
- @Override
- public void renderFile(Composite composite) {
- // Render the file by simply showing the TXT content as a text widget...
- //
- Text wText = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- PropsUi.getInstance().setLook(wText, Props.WIDGET_STYLE_FIXED);
- wText.setEditable(false);
- FormData fdText = new FormData();
- fdText.left = new FormAttachment(0, 0);
- fdText.right = new FormAttachment(100, 0);
- fdText.top = new FormAttachment(0, 0);
- fdText.bottom = new FormAttachment(100, 0);
- wText.setLayoutData(fdText);
-
- // TODO: add bottom section to show status, size, cursor position...
- //
-
- // Load the content of the JSON file...
- //
- try {
- String contents = readTextFileContent("UTF-8");
- wText.setText(Const.NVL(contents, ""));
- } catch (Exception e) {
- LogChannel.UI.logError(
- "Error reading contents of file '" + explorerFile.getFilename() + "'", e);
- }
- }
}
diff --git a/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileType.java b/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileType.java
index 78f9c89..e064cfb 100644
--- a/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileType.java
+++ b/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.xml.types;
@@ -28,6 +27,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,7 +36,7 @@ import java.util.Properties;
name = "XML File Type",
description = "XML file handling in the explorer perspective",
image = "add_xml.svg")
-public class XmlExplorerFileType extends BaseExplorerFileType<XmlExplorerFileTypeHandler>
+public class XmlExplorerFileType extends BaseTextExplorerFileType<XmlExplorerFileTypeHandler>
implements IExplorerFileType<XmlExplorerFileTypeHandler> {
public XmlExplorerFileType() {
diff --git a/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileTypeHandler.java b/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileTypeHandler.java
index c46fba0..7e56526 100644
--- a/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileTypeHandler.java
+++ b/plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/types/XmlExplorerFileTypeHandler.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.pipeline.transforms.xml.types;
@@ -27,6 +26,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileTypeHandler;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileTypeHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -34,39 +34,11 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
/** How do we handle an SVG file in file explorer perspective? */
-public class XmlExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+public class XmlExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
public XmlExplorerFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
-
- @Override
- public void renderFile(Composite composite) {
- // Render the file by simply showing the XML content as a text widget...
- //
- Text wXml = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- PropsUi.getInstance().setLook(wXml, Props.WIDGET_STYLE_FIXED);
- wXml.setEditable(false);
- FormData fdXml = new FormData();
- fdXml.left = new FormAttachment(0, 0);
- fdXml.right = new FormAttachment(100, 0);
- fdXml.top = new FormAttachment(0, 0);
- fdXml.bottom = new FormAttachment(100, 0);
- wXml.setLayoutData(fdXml);
-
- // TODO: add bottom section to show status, size, cursor position...
- //
-
- // Load the content of the XML file...
- //
- try {
- String contents = readTextFileContent("UTF-8");
- wXml.setText(Const.NVL(contents, ""));
- } catch (Exception e) {
- LogChannel.UI.logError(
- "Error reading contents of file '" + explorerFile.getFilename() + "'", e);
- }
- }
}
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java
index 72c1392..5577c4b 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.ui.hopgui.perspective.explorer.file.types.log;
@@ -22,12 +21,15 @@ import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
+import org.apache.hop.ui.hopgui.file.IHopFileType;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
import org.apache.hop.ui.hopgui.file.empty.EmptyHopFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.capabilities.FileTypeCapabilities;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
import java.util.Properties;
@@ -36,11 +38,16 @@ import java.util.Properties;
name = "LOG File Type",
description = "Log file handling in the explorer perspective",
image = "ui/images/log.svg")
-public class LogExplorerFileType extends BaseExplorerFileType<LogExplorerFileTypeHandler>
+public class LogExplorerFileType extends BaseTextExplorerFileType<LogExplorerFileTypeHandler>
implements IExplorerFileType<LogExplorerFileTypeHandler> {
public LogExplorerFileType() {
- super("Log File", ".log", new String[] {"*.log"}, new String[] {"Log files"}, new Properties());
+ super(
+ "Log File",
+ ".log",
+ new String[] {"*.log"},
+ new String[] {"Log files"},
+ FileTypeCapabilities.getCapabilities(IHopFileType.CAPABILITY_SAVE));
}
@Override
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java
index 8c6d0a3..5853e22 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.hop.ui.hopgui.perspective.explorer.file.types.log;
@@ -26,6 +25,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileTypeHandler;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileTypeHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -36,8 +36,18 @@ import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-/** How do we handle a log file in file explorer perspective? */
-public class LogExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+/**
+ * How do we handle a log file in file explorer perspective?
+ *
+ * <p>
+ *
+ * <p>TODO: add bottom section to show status, size, cursor position...
+ *
+ * <p>TODO: add a checkbox so that we can implement a "tail -f" log viewer
+ *
+ * <p>
+ */
+public class LogExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
private Text wText;
@@ -46,36 +56,4 @@ public class LogExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
-
- @Override
- public void renderFile(Composite composite) {
- // Render the file by simply showing the file content as a text widget...
- //
- wText = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- PropsUi.getInstance().setLook(wText, Props.WIDGET_STYLE_FIXED);
- wText.setEditable(false);
- FormData fdText = new FormData();
- fdText.left = new FormAttachment(0, 0);
- fdText.right = new FormAttachment(100, 0);
- fdText.top = new FormAttachment(0, 0);
- fdText.bottom = new FormAttachment(100, 0);
- wText.setLayoutData(fdText);
-
- // TODO: add bottom section to show status, size, cursor position...
- // TODO: add a checkbox so that we can implement a "tail -f" log viewer
- //
-
- // Load the content of the JSON file...
- //
- File file = new File(explorerFile.getFilename());
- if (file.exists()) {
- try {
- String contents = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
- wText.setText(contents);
- } catch (Exception e) {
- LogChannel.UI.logError(
- "Error reading contents of file '" + explorerFile.getFilename() + "'", e);
- }
- }
- }
}
diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileType.java
similarity index 51%
copy from plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java
copy to ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileType.java
index 542d932..f35feef 100644
--- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileType.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileType.java
@@ -13,13 +13,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-package org.apache.hop.pipeline.transforms.types;
+package org.apache.hop.ui.hopgui.perspective.explorer.file.types.noext;
+import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
import org.apache.hop.ui.hopgui.file.IHopFileType;
@@ -30,33 +31,71 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
import org.apache.hop.ui.hopgui.perspective.explorer.file.capabilities.FileTypeCapabilities;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileType;
+
+import java.util.Properties;
@HopFileTypePlugin(
- id = "JsonExplorerFileType",
- name = "JSON File Type",
- description = "JSON file handling in the explorer perspective",
- image = "json.svg")
-public class JsonExplorerFileType extends BaseExplorerFileType<JsonExplorerFileTypeHandler>
- implements IExplorerFileType<JsonExplorerFileTypeHandler> {
-
- public JsonExplorerFileType() {
+ id = "NoExtensionExplorerFileType",
+ name = "Text files without extensions",
+ description = "No extension files handling in the explorer perspective",
+ image = "ui/images/script-active.svg")
+public class NoExtensionExplorerFileType
+ extends BaseTextExplorerFileType<NoExtensionExplorerFileTypeHandler>
+ implements IExplorerFileType<NoExtensionExplorerFileTypeHandler> {
+
+ public NoExtensionExplorerFileType() {
super(
- "JSON File",
- ".json",
- new String[] {"*.json"},
- new String[] {"JSON files"},
+ "Text files without extensions",
+ "",
+ new String[] {
+ "config",
+ ".gitignore",
+ ".profile",
+ ".bashrc",
+ ".gitconfig",
+ "Dockerfile",
+ "Jenkinsfile",
+ "README",
+ "READ.me"
+ },
+ new String[] {
+ "Config file",
+ "Git ignore file",
+ "Profile config",
+ "Bash startup script",
+ "Git config file",
+ "Docker file",
+ "Jenkins file",
+ "README file",
+ "README file"
+ },
FileTypeCapabilities.getCapabilities(IHopFileType.CAPABILITY_SAVE));
}
@Override
- public JsonExplorerFileTypeHandler createFileTypeHandler(
+ public boolean isHandledBy(String filename, boolean checkContent) throws HopException {
+ FileObject fileObject = HopVfs.getFileObject(filename);
+ String baseName = fileObject.getName().getBaseName();
+
+ for (String extension : getFilterExtensions()) {
+ if (extension.equals(baseName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public NoExtensionExplorerFileTypeHandler createFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile file) {
- return new JsonExplorerFileTypeHandler(hopGui, perspective, file);
+ return new NoExtensionExplorerFileTypeHandler(hopGui, perspective, file);
}
@Override
public IHopFileTypeHandler newFile(HopGui hopGui, IVariables parentVariableSpace)
throws HopException {
+ // Not implemented
return new EmptyHopFileTypeHandler();
}
}
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileTypeHandler.java
similarity index 58%
copy from ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java
copy to ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileTypeHandler.java
index 8c6d0a3..ee3d556 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileTypeHandler.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/noext/NoExtensionExplorerFileTypeHandler.java
@@ -13,10 +13,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-package org.apache.hop.ui.hopgui.perspective.explorer.file.types.log;
+package org.apache.hop.ui.hopgui.perspective.explorer.file.types.noext;
import org.apache.hop.core.Props;
import org.apache.hop.core.logging.LogChannel;
@@ -26,6 +25,7 @@ import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileTypeHandler;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExplorerFileTypeHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -37,45 +37,11 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
/** How do we handle a log file in file explorer perspective? */
-public class LogExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+public class NoExtensionExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
- private Text wText;
-
- public LogExplorerFileTypeHandler(
+ public NoExtensionExplorerFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
-
- @Override
- public void renderFile(Composite composite) {
- // Render the file by simply showing the file content as a text widget...
- //
- wText = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- PropsUi.getInstance().setLook(wText, Props.WIDGET_STYLE_FIXED);
- wText.setEditable(false);
- FormData fdText = new FormData();
- fdText.left = new FormAttachment(0, 0);
- fdText.right = new FormAttachment(100, 0);
- fdText.top = new FormAttachment(0, 0);
- fdText.bottom = new FormAttachment(100, 0);
- wText.setLayoutData(fdText);
-
- // TODO: add bottom section to show status, size, cursor position...
- // TODO: add a checkbox so that we can implement a "tail -f" log viewer
- //
-
- // Load the content of the JSON file...
- //
- File file = new File(explorerFile.getFilename());
- if (file.exists()) {
- try {
- String contents = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
- wText.setText(contents);
- } catch (Exception e) {
- LogChannel.UI.logError(
- "Error reading contents of file '" + explorerFile.getFilename() + "'", e);
- }
- }
- }
}
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileType.java
similarity index 66%
copy from ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java
copy to ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileType.java
index 72c1392..f6f76fa 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/log/LogExplorerFileType.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileType.java
@@ -13,46 +13,43 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-package org.apache.hop.ui.hopgui.perspective.explorer.file.types.log;
+package org.apache.hop.ui.hopgui.perspective.explorer.file.types.text;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
+import org.apache.hop.ui.hopgui.file.IHopFileType;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
import org.apache.hop.ui.hopgui.file.empty.EmptyHopFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import org.apache.hop.ui.hopgui.perspective.explorer.file.IExplorerFileType;
+import org.apache.hop.ui.hopgui.perspective.explorer.file.capabilities.FileTypeCapabilities;
import org.apache.hop.ui.hopgui.perspective.explorer.file.types.base.BaseExplorerFileType;
import java.util.Properties;
-@HopFileTypePlugin(
- id = "LogExplorerFileType",
- name = "LOG File Type",
- description = "Log file handling in the explorer perspective",
- image = "ui/images/log.svg")
-public class LogExplorerFileType extends BaseExplorerFileType<LogExplorerFileTypeHandler>
- implements IExplorerFileType<LogExplorerFileTypeHandler> {
+public abstract class BaseTextExplorerFileType<T extends BaseTextExplorerFileTypeHandler>
+ extends BaseExplorerFileType<T> implements IExplorerFileType<T> {
- public LogExplorerFileType() {
- super("Log File", ".log", new String[] {"*.log"}, new String[] {"Log files"}, new Properties());
- }
+ public BaseTextExplorerFileType() {}
- @Override
- public LogExplorerFileTypeHandler createFileTypeHandler(
- HopGui hopGui, ExplorerPerspective perspective, ExplorerFile file) {
- return new LogExplorerFileTypeHandler(hopGui, perspective, file);
+ public BaseTextExplorerFileType(
+ String name,
+ String defaultFileExtension,
+ String[] filterExtensions,
+ String[] filterNames,
+ Properties capabilities) {
+ super(name, defaultFileExtension, filterExtensions, filterNames, capabilities);
}
+ public abstract T createFileTypeHandler(
+ HopGui hopGui, ExplorerPerspective perspective, ExplorerFile file);
+
@Override
- public IHopFileTypeHandler newFile(HopGui hopGui, IVariables parentVariableSpace)
- throws HopException {
- // Not implemented
- return new EmptyHopFileTypeHandler();
- }
+ public abstract IHopFileTypeHandler newFile(HopGui hopGui, IVariables parentVariableSpace)
+ throws HopException;
}
diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
similarity index 89%
copy from plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java
copy to ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
index ca4c1ab..bb75001 100644
--- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/types/JsonExplorerFileTypeHandler.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
@@ -13,10 +13,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-package org.apache.hop.pipeline.transforms.types;
+package org.apache.hop.ui.hopgui.perspective.explorer.file.types.text;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
@@ -35,17 +34,16 @@ import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
-import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
-/** How do we handle a JSON file in file explorer perspective? */
-public class JsonExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
+/** This handles a text file in the file explorer perspective: open, save, ... */
+public class BaseTextExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
implements IExplorerFileTypeHandler {
private Text wText;
- public JsonExplorerFileTypeHandler(
+ public BaseTextExplorerFileTypeHandler(
HopGui hopGui, ExplorerPerspective perspective, ExplorerFile explorerFile) {
super(hopGui, perspective, explorerFile);
}
@@ -65,7 +63,7 @@ public class JsonExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
// TODO: add bottom section to show status, size, changed dates, cursor position...
// TODO: options for validation, pretty print, ...
- // TODO: options for reading the file with a JSON Input transform
+ // TODO: options for reading the file with a various transform plugins
// TODO: option to discard changes (reload from disk)
// TODO: find in file feature, hook it up to the project find function
//
@@ -97,7 +95,7 @@ public class JsonExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
// Save the file...
//
- try (OutputStream outputStream = HopVfs.getOutputStream(filename,false)) {
+ try (OutputStream outputStream = HopVfs.getOutputStream(filename, false)) {
outputStream.write(wText.getText().getBytes(StandardCharsets.UTF_8));
outputStream.flush();
}
@@ -106,7 +104,7 @@ public class JsonExplorerFileTypeHandler extends BaseExplorerFileTypeHandler
perspective.refresh(); // refresh the explorer perspective tree
perspective.updateGui(); // Update menu options
} catch (Exception e) {
- throw new HopException("Unable to save JSON file '" + explorerFile.getFilename() + "'", e);
+ throw new HopException("Unable to save file '" + explorerFile.getFilename() + "'", e);
}
}
}