This repository was archived by the owner on Nov 1, 2026. It is now read-only.
Repository navigation
Add JSON serialize functionality #25
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <classpath> | ||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
| <accessrules> | ||
| <accessrule kind="accessible" pattern="javafx/**"/> | ||
| </accessrules> | ||
| </classpathentry> | ||
| <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
| <classpathentry exported="true" kind="lib" path="lib/jackson-annotations-2.10.1.jar"/> | ||
| <classpathentry exported="true" kind="lib" path="lib/jackson-core-2.10.1.jar"/> | ||
| <classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.10.1.jar"/> | ||
| <classpathentry kind="src" path="src"/> | ||
| <classpathentry kind="output" path="bin"/> | ||
| </classpath> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,7 @@ source.. = src/ | |
| output.. = bin/ | ||
| bin.includes = META-INF/,\ | ||
| .,\ | ||
| plugin.xml | ||
| plugin.xml,\ | ||
| lib/jackson-annotations-2.10.1.jar,\ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not import external binaries to the plug-in repository. Add a dependency to an existing Eclipse plug-in(s) to the manifest (and adjust the documentation if any of them is not a part of core bundle, see how the dependency on GEF is handled). |
||
| lib/jackson-core-2.10.1.jar,\ | ||
| lib/jackson-databind-2.10.1.jar | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
169 changes: 169 additions & 0 deletions
169
org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonCustomOptionPane.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| * Copyright (c) 2018, Intel Corporation | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * * Neither the name of the Intel Corporation nor the | ||
| * names of its contributors may be used to endorse or promote products | ||
| * derived from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| package org.sofproject.gst.json; | ||
|
edominia marked this conversation as resolved.
Resolved
|
||
|
|
||
| import java.io.BufferedWriter; | ||
| import java.io.File; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
|
|
||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.swt.SWT; | ||
| import org.eclipse.swt.events.SelectionAdapter; | ||
| import org.eclipse.swt.events.SelectionEvent; | ||
| import org.eclipse.swt.graphics.Rectangle; | ||
| import org.eclipse.swt.layout.GridData; | ||
| import org.eclipse.swt.layout.GridLayout; | ||
| import org.eclipse.swt.widgets.Button; | ||
| import org.eclipse.swt.widgets.Combo; | ||
| import org.eclipse.swt.widgets.Display; | ||
| import org.eclipse.swt.widgets.Label; | ||
| import org.eclipse.swt.widgets.MessageBox; | ||
| import org.eclipse.swt.widgets.Monitor; | ||
| import org.eclipse.swt.widgets.Shell; | ||
| import org.eclipse.swt.widgets.Text; | ||
| import org.sofproject.topo.ui.graph.ITopoGraph; | ||
| import org.sofproject.gst.json.JsonUtils; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| import org.sofproject.gst.topo.model.GstTopoGraph; | ||
|
|
||
| public class JsonCustomOptionPane { | ||
|
|
||
| ITopoGraph graph; | ||
|
|
||
| private static boolean isInteger(String s) { | ||
| try { | ||
| Integer.parseInt(s); | ||
| } catch (NumberFormatException e) { | ||
| return false; | ||
| } catch (NullPointerException e) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public JsonCustomOptionPane(Display display, ITopoGraph graph) { | ||
| this.graph = graph; | ||
| Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN); | ||
|
|
||
| shell.setText("Serialize JSON"); | ||
|
|
||
| GridLayout gridLayout = new GridLayout(4, false); | ||
| gridLayout.verticalSpacing = 8; | ||
| shell.setLayout(gridLayout); | ||
|
|
||
| new Label(shell, SWT.NULL).setText("Name:"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name, description, and other properties collected here should be properties accessible via the ITopoGraph interface, displayed and editable in the Properties view. So that the serialize-to-json operation would not require any user interaction. |
||
| Text nameText = new Text(shell, SWT.SINGLE | SWT.BORDER); | ||
| GridData nameGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| nameGridData.horizontalSpan = 3; | ||
| nameText.setLayoutData(nameGridData); | ||
|
|
||
| new Label(shell, SWT.NULL).setText("Version:"); | ||
| Text versionText = new Text(shell, SWT.BORDER); | ||
| GridData versionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| versionGridData.horizontalSpan = 3; | ||
| versionText.setLayoutData(versionGridData); | ||
|
|
||
| new Label(shell, SWT.NULL).setText("Description:"); | ||
| Text descriptionText = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); | ||
| GridData descriptionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| descriptionGridData.horizontalSpan = 3; | ||
| descriptionGridData.heightHint = 100; | ||
| descriptionGridData.widthHint = 200; | ||
| descriptionText.setLayoutData(descriptionGridData); | ||
|
|
||
| new Label(shell, SWT.NULL).setText("Type:"); | ||
| Combo typeCombo = new Combo(shell, SWT.READ_ONLY); | ||
| typeCombo.setBounds(50, 50, 200, 65); | ||
| String items[] = { "Gstreamer", "Ffmpeg" }; | ||
| typeCombo.setItems(items); | ||
| typeCombo.setText(items[0]); | ||
| GridData typeGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| typeGridData.horizontalSpan = 3; | ||
| typeCombo.setLayoutData(typeGridData); | ||
|
|
||
| Button okButton = new Button(shell, SWT.PUSH); | ||
| okButton.setText("Ok"); | ||
| GridData buttonGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| okButton.setLayoutData(buttonGridData); | ||
| okButton.addSelectionListener(new SelectionAdapter() { | ||
|
jajanusz marked this conversation as resolved.
Resolved
|
||
|
|
||
| @Override | ||
| public void widgetSelected(SelectionEvent e) { | ||
| if (nameText.getText().isEmpty()) { | ||
| MessageBox messageBox = new MessageBox(shell, SWT.ERROR); | ||
| messageBox.setMessage("Name cannot be empty!"); | ||
| messageBox.open(); | ||
| } else if (!isInteger(versionText.getText())) { | ||
| MessageBox messageBox = new MessageBox(shell, SWT.ERROR); | ||
| messageBox.setMessage("Version number should be an integer!"); | ||
| messageBox.open(); | ||
| } else { | ||
| try { | ||
| JsonProperty jsonProperty = new JsonProperty(nameText.getText(), descriptionText.getText(), | ||
| versionText.getText(), typeCombo.getItem(typeCombo.getSelectionIndex())); | ||
| new JsonUtils().serializeJson(jsonProperty, graph.getPipelinesString()); | ||
| shell.close(); | ||
| } catch (CoreException | IOException error) { | ||
| error.printStackTrace(); // TODO: | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| Button cancelButton = new Button(shell, SWT.PUSH); | ||
| cancelButton.setText("Cancel"); | ||
| GridData cancelbuttonGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | ||
| cancelButton.setLayoutData(cancelbuttonGridData); | ||
| cancelButton.addSelectionListener(new SelectionAdapter() { | ||
|
|
||
| @Override | ||
| public void widgetSelected(SelectionEvent e) { | ||
| shell.close(); | ||
| } | ||
| }); | ||
|
|
||
| Monitor primary = display.getPrimaryMonitor(); | ||
| Rectangle bounds = primary.getBounds(); | ||
| Rectangle rect = shell.getBounds(); | ||
| int x = bounds.x + (bounds.width - rect.width) / 2; | ||
| int y = bounds.y + (bounds.height - rect.height) / 2; | ||
| shell.setLocation(x, y); | ||
|
|
||
| shell.pack(); | ||
| shell.open(); | ||
| while (!shell.isDisposed()) { | ||
| if (!display.readAndDispatch()) | ||
| display.sleep(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
70 changes: 70 additions & 0 deletions
70
org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonProperty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) 2019, Intel Corporation | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * * Neither the name of the Intel Corporation nor the | ||
| * names of its contributors may be used to endorse or promote products | ||
| * derived from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| package org.sofproject.gst.json; | ||
|
|
||
| public class JsonProperty { | ||
|
|
||
| private String name; | ||
| private String description; | ||
| private String version; | ||
| private String type; | ||
| private String template; | ||
|
|
||
| public JsonProperty(String name, String description, String version, String type) { | ||
| this.name = name; | ||
| this.description = description; | ||
| this.version = version; | ||
| this.type = type; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public String getVersion() { | ||
| return version; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public String getTemplate() { | ||
| return template; | ||
| } | ||
|
|
||
| public void setTemplate(String newTemplate) { | ||
| this.template = newTemplate; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright (c) 2019, Intel Corporation | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * * Neither the name of the Intel Corporation nor the | ||
| * names of its contributors may be used to endorse or promote products | ||
| * derived from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| package org.sofproject.gst.json; | ||
|
|
||
| import java.io.BufferedWriter; | ||
| import java.io.File; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
|
|
||
| import org.eclipse.core.runtime.CoreException; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| public class JsonUtils { | ||
|
|
||
| public void serializeJson(JsonProperty jsonProperty, String pipelineString) throws CoreException, IOException { | ||
| try { | ||
| File file = new File(jsonProperty.getName() + ".json"); | ||
| jsonProperty.setTemplate(pipelineString); | ||
| BufferedWriter writer = new BufferedWriter(new FileWriter(file)); | ||
| ObjectMapper obj = new ObjectMapper(); | ||
| obj.writeValue(writer, jsonProperty); | ||
| writer.close(); | ||
|
|
||
| } catch (Exception e) { | ||
| System.out.println(e.toString()); | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.