Skip to content

Commit 255cf1c

Browse files
committed
Support opening CFG files in existing instance
1 parent 21dea8a commit 255cf1c

File tree

4 files changed

+105
-5
lines changed

4 files changed

+105
-5
lines changed

visualizer/C1Visualizer/CompilationView/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<artifactId>org-netbeans-modules-editor-mimelookup</artifactId>
3030
<version>${netbeans.version}</version>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.netbeans.modules</groupId>
34+
<artifactId>org-netbeans-modules-editor-mimelookup-impl</artifactId>
35+
<version>${netbeans.version}</version>
36+
</dependency>
3237
<dependency>
3338
<groupId>org.netbeans.api</groupId>
3439
<artifactId>org-netbeans-modules-sendopts</artifactId>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package at.ssw.visualizer.compilation.view.action;
24+
25+
import at.ssw.visualizer.model.CompilationModel;
26+
import org.netbeans.api.actions.Openable;
27+
import org.openide.DialogDisplayer;
28+
import org.openide.NotifyDescriptor;
29+
import org.openide.cookies.OpenCookie;
30+
import org.openide.filesystems.FileObject;
31+
import org.openide.filesystems.FileUtil;
32+
import org.openide.filesystems.MIMEResolver;
33+
import org.openide.loaders.DataObject;
34+
import org.openide.loaders.DataObjectExistsException;
35+
import org.openide.loaders.MultiDataObject;
36+
import org.openide.loaders.MultiFileLoader;
37+
import org.openide.util.Lookup;
38+
import org.openide.util.NbBundle;
39+
import org.openide.util.RequestProcessor;
40+
41+
import java.io.File;
42+
43+
/**
44+
* DataObject that represents a .CFG file. This object is NOT designed for presentation
45+
* as is usual for NB dataobjects. It just serves to provide Open file from commandline
46+
* feature, nothing more.
47+
*/
48+
@NbBundle.Messages(
49+
"LBL_GraalVMC1VisualizerFile=GraalVM C1Visualizer File"
50+
)
51+
@MIMEResolver.ExtensionRegistration(
52+
displayName = "#LBL_GraalVMC1VisualizerFile",
53+
mimeType = C1VisualizerDataObject.GRAAL_CFG_MIME_TYPE,
54+
position = 3232,
55+
extension = {"cfg"}
56+
)
57+
@DataObject.Registration(
58+
displayName = "LBL_GraalVMC1VisualizerFile",
59+
mimeType = C1VisualizerDataObject.GRAAL_CFG_MIME_TYPE,
60+
position = 400
61+
)
62+
public class C1VisualizerDataObject extends MultiDataObject {
63+
/**
64+
* MIME type for CFG dumps
65+
*/
66+
public static final String GRAAL_CFG_MIME_TYPE = "application/x-c1visualizer"; // NOI18N
67+
68+
public C1VisualizerDataObject(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
69+
super(fo, loader);
70+
getCookieSet().assign(Openable.class, new OpenImpl());
71+
}
72+
73+
private class OpenImpl implements OpenCookie {
74+
@Override
75+
public void open() {
76+
importPrimaryFile();
77+
}
78+
}
79+
80+
public void importPrimaryFile() {
81+
FileObject fo = getPrimaryFile();
82+
File f = FileUtil.toFile(fo);
83+
if (f == null) {
84+
return;
85+
}
86+
87+
final String fileName = f.getAbsolutePath();
88+
RequestProcessor.getDefault().post(new Runnable() {
89+
public void run() {
90+
CompilationModel model = Lookup.getDefault().lookup(CompilationModel.class);
91+
String errorMsg = model.parseInputFile(fileName);
92+
if (errorMsg != null) {
93+
NotifyDescriptor d = new NotifyDescriptor.Message("Errors while parsing input:\n" + errorMsg, NotifyDescriptor.ERROR_MESSAGE);
94+
DialogDisplayer.getDefault().notify(d);
95+
}
96+
}
97+
});
98+
}
99+
}
100+

visualizer/C1Visualizer/application/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,6 @@
775775
<groupId>org.netbeans.modules</groupId>
776776
<artifactId>org-netbeans-modules-utilities-project</artifactId>
777777
</exclusion>
778-
<exclusion>
779-
<groupId>org.netbeans.modules</groupId>
780-
<artifactId>org-netbeans-modules-utilities</artifactId>
781-
</exclusion>
782778
<exclusion>
783779
<groupId>org.netbeans.modules</groupId>
784780
<artifactId>org-netbeans-modules-versioning-core</artifactId>

visualizer/IdealGraphVisualizer/Coordinator/src/main/java/org/graalvm/visualizer/coordinator/impl/BinaryGraphDataObject.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public void importPrimaryFile() {
9696
return;
9797
}
9898
try {
99-
Thread.dumpStack();
10099
FileImporter.asyncImportDocument(f.toPath(), true, true, null);
101100
} catch (IOException ex) {
102101
Exceptions.printStackTrace(

0 commit comments

Comments
 (0)