Skip to content

Commit 29ed4f7

Browse files
committed
Change JSON location
1 parent 5a3728b commit 29ed4f7

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

org.sofproject.gst.topo/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Bundle-ClassPath: lib/jackson-annotations-2.10.1.jar,
1515
lib/jackson-databind-2.10.1.jar,
1616
.
1717
Export-Package: org.sofproject.gst.json
18+
Import-Package: org.eclipse.ui

org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonCustomOptionPane.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
package org.sofproject.gst.json;
3131

32-
import java.io.BufferedWriter;
33-
import java.io.File;
34-
import java.io.FileWriter;
3532
import java.io.IOException;
3633

3734
import org.eclipse.core.runtime.CoreException;
@@ -51,9 +48,6 @@
5148
import org.eclipse.swt.widgets.Text;
5249
import org.sofproject.topo.ui.graph.ITopoGraph;
5350
import org.sofproject.gst.json.JsonUtils;
54-
import com.fasterxml.jackson.databind.ObjectMapper;
55-
56-
import org.sofproject.gst.topo.model.GstTopoGraph;
5751

5852
public class JsonCustomOptionPane {
5953

org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonUtils.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,33 @@
3333
import java.io.File;
3434
import java.io.FileWriter;
3535
import java.io.IOException;
36+
import java.nio.file.Paths;
3637

38+
import org.eclipse.core.resources.IProject;
39+
import org.eclipse.core.resources.IResource;
3740
import org.eclipse.core.runtime.CoreException;
41+
import org.eclipse.core.runtime.IPath;
42+
import org.eclipse.ui.IEditorInput;
43+
import org.eclipse.ui.IEditorPart;
44+
import org.eclipse.ui.IWorkbenchPage;
45+
import org.eclipse.ui.IWorkbenchWindow;
46+
import org.eclipse.ui.PlatformUI;
3847

3948
import com.fasterxml.jackson.databind.ObjectMapper;
4049

4150
public class JsonUtils {
4251

4352
public void serializeJson(JsonProperty jsonProperty, String pipelineString) throws CoreException, IOException {
4453
try {
45-
File file = new File(jsonProperty.getName() + ".json");
54+
String projectPath = getProjectPath();
55+
File file;
56+
if (projectPath != null) {
57+
String path = Paths.get(projectPath, jsonProperty.getName(), jsonProperty.getVersion()).toString();
58+
new File(path).mkdirs();
59+
file = new File(Paths.get(path, "pipeline.json").toString());
60+
} else {
61+
file = new File(jsonProperty.getName() + ".json");
62+
}
4663
jsonProperty.setTemplate(pipelineString);
4764
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
4865
ObjectMapper obj = new ObjectMapper();
@@ -54,4 +71,27 @@ public void serializeJson(JsonProperty jsonProperty, String pipelineString) thro
5471
}
5572
}
5673

74+
public String getProjectPath() {
75+
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
76+
IWorkbenchPage activePage = window.getActivePage();
77+
78+
IEditorPart activeEditor = activePage.getActiveEditor();
79+
80+
if (activeEditor != null) {
81+
IEditorInput input = activeEditor.getEditorInput();
82+
83+
IProject project = input.getAdapter(IProject.class);
84+
if (project == null) {
85+
IResource resource = input.getAdapter(IResource.class);
86+
if (resource != null) {
87+
project = resource.getProject();
88+
IPath path = project.getLocation();
89+
return path.toString();
90+
}
91+
}
92+
}
93+
94+
return null;
95+
}
96+
5797
}

org.sofproject.gst.topo/src/org/sofproject/gst/topo/model/GstTopoGraph.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.eclipse.jface.window.Window;
5252
import org.sofproject.core.binfile.BinFile;
5353
import org.sofproject.core.ops.IRemoteOpsProvider;
54-
import org.sofproject.gst.json.JsonProperty;
5554
import org.sofproject.gst.topo.ops.GstGraphOpsProvider;
5655
import org.sofproject.gst.topo.plugins.GstElement;
5756
import org.sofproject.gst.topo.plugins.GstPlugin;
@@ -62,8 +61,6 @@
6261
import org.sofproject.topo.ui.graph.ITopoGraph;
6362
import org.sofproject.topo.ui.graph.ITopoNode;
6463

65-
import com.fasterxml.jackson.databind.ObjectMapper;
66-
6764
public class GstTopoGraph implements ITopoGraph {
6865

6966
public static final String[] NODE_TYPE_IDS = { "org.sofproject.gst.topo.element" };

org.sofproject.topo.ui/src/org/sofproject/topo/ui/editor/policies/TopoEditorOnClickHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
package org.sofproject.topo.ui.editor.policies;
3131

32-
import java.awt.Frame;
3332
import java.io.IOException;
3433

3534
import org.eclipse.core.runtime.CoreException;
@@ -131,18 +130,15 @@ public void handle(ActionEvent event) {
131130
}
132131
});
133132
menu.getItems().add(miSerialize);
134-
135133
MenuItem miSerializeJson = new MenuItem("Serialize Topology to Json");
136134
miSerializeJson.setOnAction(new EventHandler<ActionEvent>() {
137135
@Override
138136
public void handle(ActionEvent event) {
139-
140137
menu.hide();
141138
new JsonCustomOptionPane(Display.getCurrent(), getGraphFromHost());
142139
}
143140
});
144141
menu.getItems().add(miSerializeJson);
145-
146142
menu.show(((InfiniteCanvasViewer) viewer).getScene().getWindow(), e.getScreenX(), e.getScreenY());
147143
}
148144
}

0 commit comments

Comments
 (0)