Skip to content

Commit 3c844ea

Browse files
committed
rough extracting of VP diagrams
1 parent 606bbfd commit 3c844ea

18 files changed

+400
-110
lines changed

classes/.gitignore

-1
This file was deleted.
535 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

icons/puml-icon.png

43.4 KB
Loading

plugin.xml

+18-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@
88
<actionSets>
99
<actionSet id="plugins.plantUML.actionset">
1010
<action
11-
id="plugins.plantUML.actions.PlantUMLActionController"
11+
id="ImportAction"
1212
actionType="generalAction"
13-
label="TODO"
14-
tooltip="TODO"
13+
label="PlantUML..."
14+
tooltip="PlantUML..."
1515
style="normal"
16-
menuPath="Tools/Report">
16+
icon="icons/puml-icon.png"
17+
ribbonPath="Project/Import/Visio">
1718
<actionController
18-
class="plugins.plantUML.actions.PlantUMLActionController"/>
19+
class="plugins.plantUML.actions.PlantUMLImportController"/>
1920
</action>
21+
<action
22+
id="ExportAction"
23+
actionType="generalAction"
24+
label="PlantUML..."
25+
tooltip="PlantUML..."
26+
style="normal"
27+
icon="icons/puml-icon.png"
28+
ribbonPath="Project/Export/XML">
29+
<actionController
30+
class="plugins.plantUML.actions.PlantUMLExportController"/>
31+
</action>
2032
</actionSet>
2133
</actionSets>
22-
</plugin>
23-
34+
</plugin>

src/plugins/plantUML/actions/PlantUMLActionController.java

-102
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package plugins.plantUML.actions;
2+
3+
import java.awt.Component;
4+
import java.io.File;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
8+
import javax.swing.JFileChooser;
9+
import javax.swing.filechooser.FileFilter;
10+
11+
import com.vp.plugin.ApplicationManager;
12+
import com.vp.plugin.ViewManager;
13+
import com.vp.plugin.action.VPAction;
14+
import com.vp.plugin.action.VPActionController;
15+
import com.vp.plugin.diagram.IConnectorUIModel;
16+
import com.vp.plugin.diagram.IDiagramElement;
17+
import com.vp.plugin.diagram.IDiagramUIModel;
18+
import com.vp.plugin.model.IModelElement;
19+
import com.vp.plugin.model.IRelationship;
20+
21+
import plugins.plantUML.export.ClassDiagramExporter;
22+
import plugins.plantUML.export.UseCaseDiagramExporter;
23+
24+
public class PlantUMLExportController implements VPActionController {
25+
26+
public void performAction(VPAction action) {
27+
// Get the view manager and the parent component for the modal dialog
28+
// ViewManager viewManager = ApplicationManager.instance().getViewManager();
29+
// Component parentFrame = viewManager.getRootFrame();
30+
//
31+
// // Popup a file chooser for choosing the output file
32+
// JFileChooser fileChooser = viewManager.createJFileChooser();
33+
// fileChooser.setFileFilter(new FileFilter() {
34+
//
35+
// public String getDescription() {
36+
// return "*.txt, *.puml";
37+
// }
38+
//
39+
// public boolean accept(File file) {
40+
// return file.isDirectory() ||
41+
// file.getName().toLowerCase().endsWith(".txt") ||
42+
// file.getName().toLowerCase().endsWith(".puml");
43+
// }
44+
//
45+
// });
46+
//
47+
// // Show save dialog and get the selected file
48+
// int userSelection = fileChooser.showSaveDialog(parentFrame);
49+
// if (userSelection == JFileChooser.APPROVE_OPTION) {
50+
// File file = fileChooser.getSelectedFile();
51+
// String fileName = file.getName().toLowerCase();
52+
//
53+
// // Ensure the file has either .txt or .puml extension
54+
// if (!fileName.endsWith(".txt") && !fileName.endsWith(".puml")) {
55+
// // Default to .txt if no extension is provided
56+
// file = new File(file.getAbsolutePath() + ".txt");
57+
// }
58+
//
59+
// if (file != null && !file.isDirectory()) {
60+
// String messageContent = "Test message"; // Fixed test message
61+
//
62+
// // Write the test message to the file
63+
// try (FileWriter writer = new FileWriter(file)) {
64+
// writer.write(messageContent);
65+
// viewManager.showMessageDialog(parentFrame, "Diagram exported to " + file.getAbsolutePath());
66+
// } catch (IOException e) {
67+
// viewManager.showMessageDialog(parentFrame, "Error writing to file: " + e.getMessage());
68+
// }
69+
// }
70+
// }
71+
72+
IDiagramUIModel activeDiagram = ApplicationManager.instance().getDiagramManager().getActiveDiagram();
73+
String diagramType = activeDiagram.getType();
74+
75+
switch(diagramType) {
76+
case "ClassDiagram":
77+
ClassDiagramExporter cde = new ClassDiagramExporter();
78+
cde.extract(activeDiagram);
79+
break;
80+
case "UseCaseDiagram":
81+
UseCaseDiagramExporter ucde = new UseCaseDiagramExporter();
82+
ucde.extract(activeDiagram);
83+
break;
84+
default:
85+
ApplicationManager.instance().getViewManager().showMessage("TYPE " + diagramType + " not yet implemented");
86+
IDiagramElement[] allElements = activeDiagram.toDiagramElementArray();
87+
88+
for (IDiagramElement diagramElement : allElements){
89+
ApplicationManager.instance().getViewManager().showMessage("NAME:");
90+
ApplicationManager.instance().getViewManager().showMessage(diagramElement.getModelElement().getName());
91+
ApplicationManager.instance().getViewManager().showMessage("DESCRIPTION:");
92+
ApplicationManager.instance().getViewManager().showMessage(diagramElement.getModelElement().getDescription()); // getDocumentation is deprecated
93+
ApplicationManager.instance().getViewManager().showMessage("TYPE:");
94+
ApplicationManager.instance().getViewManager().showMessage(diagramElement.getModelElement().getModelType());
95+
}
96+
IDiagramElement[] connectors = activeDiagram.toDiagramElementArray();
97+
for (IDiagramElement connector : connectors) {
98+
IModelElement connectorModel = connector.getModelElement();
99+
if (connectorModel instanceof IRelationship) {
100+
101+
IRelationship relationship = (IRelationship) connectorModel;
102+
String id = relationship.getId();
103+
IModelElement source = relationship.getFrom();
104+
IModelElement target = relationship.getTo();
105+
106+
String sourceAlias = source.getName();
107+
String targetAlias = target.getName();
108+
109+
IConnectorUIModel connection = (IConnectorUIModel) connector;
110+
ApplicationManager.instance().getViewManager().showMessage("connector of type " + connector.getModelElement().getModelType() + " from: " + sourceAlias + " to " + targetAlias);
111+
ApplicationManager.instance().getViewManager().showMessage(connector.getModelElement().getModelType());
112+
113+
}
114+
}
115+
}
116+
117+
118+
119+
}
120+
121+
public void update(VPAction action) {
122+
// No update behavior needed for this action
123+
}
124+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package plugins.plantUML.actions;
2+
3+
import java.awt.Component;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.io.BufferedReader;
8+
9+
import javax.swing.JFileChooser;
10+
import javax.swing.filechooser.FileFilter;
11+
12+
import com.vp.plugin.ApplicationManager;
13+
import com.vp.plugin.ViewManager;
14+
import com.vp.plugin.action.VPAction;
15+
import com.vp.plugin.action.VPActionController;
16+
17+
public class PlantUMLImportController implements VPActionController {
18+
19+
public void performAction(VPAction action) {
20+
// Get the view manager and the parent component for the modal dialog
21+
ViewManager viewManager = ApplicationManager.instance().getViewManager();
22+
Component parentFrame = viewManager.getRootFrame();
23+
24+
// Popup a file chooser to select the .txt or .puml file to import
25+
JFileChooser fileChooser = viewManager.createJFileChooser();
26+
fileChooser.setFileFilter(new FileFilter() {
27+
28+
public String getDescription() {
29+
return "*.txt, *.puml";
30+
}
31+
32+
public boolean accept(File file) {
33+
return file.isDirectory() ||
34+
file.getName().toLowerCase().endsWith(".txt") ||
35+
file.getName().toLowerCase().endsWith(".puml");
36+
}
37+
38+
});
39+
40+
// Show open dialog and get the selected file
41+
int userSelection = fileChooser.showOpenDialog(parentFrame);
42+
if (userSelection == JFileChooser.APPROVE_OPTION) {
43+
File file = fileChooser.getSelectedFile();
44+
StringBuilder fileContent = new StringBuilder();
45+
46+
// Read the file content
47+
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
48+
String line;
49+
while ((line = reader.readLine()) != null) {
50+
fileContent.append(line).append("\n");
51+
}
52+
53+
// Display success message with file path
54+
viewManager.showMessageDialog(parentFrame, "File imported from: " + file.getAbsolutePath());
55+
56+
// Process or store fileContent.toString() as needed for the import functionality
57+
58+
} catch (IOException e) {
59+
// Show error message if file reading fails
60+
viewManager.showMessageDialog(parentFrame, "Error reading file: " + e.getMessage());
61+
}
62+
}
63+
}
64+
65+
public void update(VPAction action) {
66+
}
67+
}

0 commit comments

Comments
 (0)