Skip to content

Commit

Permalink
more json schema support
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed Oct 10, 2024
1 parent 9e90754 commit 5a5d05b
Show file tree
Hide file tree
Showing 43 changed files with 362 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
package org.cip4.tools.jdfeditor;

import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

import javax.swing.tree.TreePath;
import javax.swing.undo.CannotRedoException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

import org.cip4.jdflib.core.KElement;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* AddRequiredElemEdit.java
Expand Down
76 changes: 64 additions & 12 deletions src/main/java/org/cip4/tools/jdfeditor/CheckJDFScrollPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,19 @@
import org.cip4.jdflib.core.VString;
import org.cip4.jdflib.core.XMLDoc;
import org.cip4.tools.jdfeditor.view.renderer.CheckJDFOutputTreeCellRenderer;
import org.cip4.tools.jdfeditor.view.renderer.CheckJDFOutputWrapper;
import org.cip4.tools.jdfeditor.view.renderer.JSONSchemaOutputWrapper;

/**
* this class encapsulates the output of the dev caps test
*
* @author prosirai
*
*/
public class CheckJDFScrollPane extends ValidationScrollPane
{
private static final long serialVersionUID = 2367868076065696719L;

private CheckJDFOutputWrapper checkJDFRoot;
private CheckJDFOutputTreeCellRenderer treeCellRenderer;

public CheckJDFScrollPane()
Expand All @@ -108,27 +110,56 @@ public void updateCellRenderer()
/**
*
* TODO Please insert comment!
*
* @param bugReport
*/
public void drawCheckJDFOutputTree(final XMLDoc bugReport)
{
if (bugReport == null)
return;
KElement repRoot = bugReport.getRoot().getChildByTagName("CheckJDFOutput", null, 0, null, false, true);
final KElement repRoot = bugReport.getRoot().getChildByTagName("CheckJDFOutput", null, 0, null, false, true);
if (repRoot == null)
return;
checkJDFRoot = new CheckJDFOutputWrapper(repRoot);
final CheckJDFOutputWrapper checkJDFRoot = new CheckJDFOutputWrapper(repRoot);
m_reportTree = new JTree(checkJDFRoot);
m_reportTree.setModel(new JDFTreeModel(checkJDFRoot, false));
m_reportTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
m_reportTree.setExpandsSelectedPaths(true);
m_reportTree.setEditable(false);
ToolTipManager.sharedInstance().registerComponent(m_reportTree);

//DCOutputWrapper bugReportRoot = null;

setCheckJDFOutputTree(checkJDFRoot);
// m_reportTree.expandPath(new TreePath(bugReportRoot.getPath()));
m_reportTree.expandPath(new TreePath(checkJDFRoot.getPath()));

m_SelectionListener = new ValidationSelectionListener();
m_reportTree.addTreeSelectionListener(m_SelectionListener);

m_reportTree.setCellRenderer(treeCellRenderer);
m_reportTree.setRowHeight(0); // apply height of each cell from cell-renderer

final ValidationPopupListener popupListener = new ValidationPopupListener();
m_reportTree.addMouseListener(popupListener);

getViewport().setView(m_reportTree);
}

/**
*
* @param bugReport
*/
public void drawJSONSchemaOutputTree(final XMLDoc bugReport)
{
final KElement repRoot = bugReport.getRoot();
final JSONSchemaOutputWrapper checkJDFRoot = new JSONSchemaOutputWrapper(repRoot);
m_reportTree = new JTree(checkJDFRoot);
m_reportTree.setModel(new JDFTreeModel(checkJDFRoot, false));
m_reportTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
m_reportTree.setExpandsSelectedPaths(true);
m_reportTree.setEditable(false);
ToolTipManager.sharedInstance().registerComponent(m_reportTree);

setJSONSchemaOutputTree(checkJDFRoot);
// m_reportTree.expandPath(new TreePath(bugReportRoot.getPath()));
m_reportTree.expandPath(new TreePath(checkJDFRoot.getPath()));

m_SelectionListener = new ValidationSelectionListener();
Expand All @@ -145,9 +176,9 @@ public void drawCheckJDFOutputTree(final XMLDoc bugReport)

private void setCheckJDFOutputTree(final CheckJDFOutputWrapper bugReport)
{
KElement repElem = bugReport.getElement();
final KElement repElem = bugReport.getElement();
// now add the individual attributes
VString vAtts = repElem.getAttributeVector();
final VString vAtts = repElem.getAttributeVector();
for (int i = 0; i < vAtts.size(); i++)
{
final String stringAt = vAtts.get(i);
Expand All @@ -173,18 +204,39 @@ private void setCheckJDFOutputTree(final CheckJDFOutputWrapper bugReport)
continue;
if (stringAt.equals("Separation"))
continue;
CheckJDFOutputWrapper next = new CheckJDFOutputWrapper(repElem.getAttributeNode(stringAt));
final CheckJDFOutputWrapper next = new CheckJDFOutputWrapper(repElem.getAttributeNode(stringAt));
bugReport.add(next);
}
// recurse through children
VElement childVector = repElem.getChildElementVector(null, null, null, true, 0, false);
final VElement childVector = repElem.getChildElementVector(null, null, null, true, 0, false);
for (int i = 0; i < childVector.size(); i++)
{
KElement kEl = childVector.elementAt(i);
CheckJDFOutputWrapper next = new CheckJDFOutputWrapper(kEl);
final KElement kEl = childVector.elementAt(i);
final CheckJDFOutputWrapper next = new CheckJDFOutputWrapper(kEl);
setCheckJDFOutputTree(next);
bugReport.add(next);
}
}

private void setJSONSchemaOutputTree(final JSONSchemaOutputWrapper checkJDFRoot)
{
final KElement repElem = checkJDFRoot.getElement();
final VString vAtts = repElem.getAttributeVector();
for (final String stringAt : vAtts)
{
final JSONSchemaOutputWrapper next = new JSONSchemaOutputWrapper(repElem.getAttributeNode(stringAt));
checkJDFRoot.add(next);
}

final VElement childVector = repElem.getChildElementVector(null, null, null, true, 0, false);
childVector.unifyElement();
childVector.sort();
for (final KElement kEl : childVector)
{
final JSONSchemaOutputWrapper next = new JSONSchemaOutputWrapper(kEl);
setJSONSchemaOutputTree(next);
checkJDFRoot.add(next);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

import org.cip4.jdflib.core.KElement;
import org.cip4.jdflib.node.JDFNode;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;
import org.w3c.dom.Attr;


Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/DeleteItemEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
package org.cip4.tools.jdfeditor;

import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

import javax.swing.tree.TreePath;
import javax.swing.undo.CannotRedoException;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/EditorDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import org.cip4.tools.jdfeditor.service.SettingService;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;
import org.json.simple.JSONObject;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/EditorMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.cip4.tools.jdfeditor.menu.MenuEdit;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* Class to implement all the menu bar and menu related stuff moved here from JDFFrame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.cip4.jdflib.util.StringUtil;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* this handles anything located in the top right tabbed panes it has been misused as a dump from JDFFrame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.cip4.tools.jdfeditor.service.RuntimeProperties;
import org.cip4.tools.jdfeditor.util.FontUtil;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/EditorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import org.cip4.tools.jdfeditor.streamloader.PluginLoader;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* static utilities for the editor
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/InsertAttrEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import javax.swing.undo.CannotUndoException;

import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/*
* InsertAttrEdit.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

import org.cip4.jdflib.core.KElement;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/*
* InsertElementAfterEdit.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.cip4.jdflib.pool.JDFResourceLinkPool;
import org.cip4.jdflib.pool.JDFResourcePool;
import org.cip4.jdflib.resource.JDFResource;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* InsertResourceAndLinkEdit.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.cip4.jdflib.core.JDFResourceLink;
import org.cip4.jdflib.node.JDFNode;
import org.cip4.jdflib.pool.JDFResourceLinkPool;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/*
* InsertResourceLinkEdit.java
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/JDFFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
import org.cip4.tools.jdfeditor.util.RecentFileUtil;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* @author AnderssA ThunellE SvenoniusI Elena Skobchenko
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/JDFInOutScroll.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFResourceTreeCellRenderer;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/JDFTreeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeCellRenderer;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* This is a new dump for some of the JDFFrame classes that relate to the actual tree view TODO move some of the routines here into the model where they belong and reduce the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.cip4.tools.jdfeditor.service.SettingService;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* class to handle copy / paste actions from the frame
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/cip4/tools/jdfeditor/JDFTreeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import org.cip4.tools.jdfeditor.service.SettingService;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;
import org.w3c.dom.Attr;

import com.networknt.schema.ValidationMessage;
Expand Down Expand Up @@ -276,6 +277,7 @@ public boolean validate()
}
if (eDoc.isJson())
{
validateXJDF();
return validateJSON();
}
else if (eDoc.isXJDF())
Expand All @@ -299,17 +301,19 @@ boolean validateJSON()
final JSONSchemaReader sr = new JSONSchemaReader(EditorUtils.RES_SCHEMA_JSON);
final Collection<ValidationMessage> results = sr.checkJSON(json);
validationResult = null;
final KElement schemaValidationResult = KElement.createRoot("SchemaValidationOutput", null);
schemaValidationResult.setAttribute("SchemaLocation", EditorUtils.RES_SCHEMA_JSON);
schemaValidationResult.setAttribute("ValidationResult", ContainerUtil.isEmpty(results) ? "Valid" : "Error");
final KElement jsonSchemaResult = KElement.createRoot("JSONSchema", null);
jsonSchemaResult.setAttribute("SchemaLocation", EditorUtils.RES_SCHEMA_JSON);
jsonSchemaResult.setAttribute("ValidationResult", ContainerUtil.isEmpty(results) ? "Valid" : "Error");
for (final ValidationMessage m : results)
{
final KElement error = schemaValidationResult.appendElement("Error");
final String loc = m.getInstanceLocation().toString();
final String typ = "$".equals(loc) ? "Warning" : "Error";
final KElement error = jsonSchemaResult.appendElement(typ);
error.setAttribute("Message", m.toString());
error.setAttribute("Path", m.getInstanceLocation().toString());
error.setAttribute("Path", loc);
}
final JDFFrame m_frame = MainView.getFrame();
m_frame.getBottomTabs().m_SchemaErrScroll.drawSchemaOutputTree(schemaValidationResult.getOwnerDocument_KElement());
m_frame.getBottomTabs().m_validErrScroll.drawJSONSchemaOutputTree(jsonSchemaResult.getOwnerDocument_KElement());
if (MainView.getEditorDoc().getJDFTree() != null)
{
MainView.getEditorDoc().getJDFTree().repaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
package org.cip4.tools.jdfeditor;

import javax.swing.tree.TreeNode;

import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

import java.util.Enumeration;
import java.util.NoSuchElementException;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/ModifyAttrEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import javax.swing.undo.CannotUndoException;

import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;
import org.w3c.dom.Attr;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/PasteItemEdit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cip4.tools.jdfeditor;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

import javax.swing.tree.TreePath;
import javax.swing.undo.AbstractUndoableEdit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.cip4.tools.jdfeditor.service.SettingService;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
* Class to implement all the menu bar and menu related stuff moved here from JDFFrame
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/ProcessPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.cip4.jdflib.resource.JDFResource;
import org.cip4.tools.jdfeditor.util.ResourceUtil;
import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

/**
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cip4/tools/jdfeditor/RenameNodeEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
package org.cip4.tools.jdfeditor;

import org.cip4.tools.jdfeditor.view.MainView;
import org.cip4.tools.jdfeditor.view.renderer.JDFTreeNode;

import javax.swing.tree.TreePath;
import javax.swing.undo.CannotRedoException;
Expand Down
Loading

0 comments on commit 5a5d05b

Please sign in to comment.