|
@@ -10,7 +10,9 @@ import java.util.Collection;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
+
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ImportController;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionImplementation;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionImplementation;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
@@ -21,6 +23,8 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.JavaFileFilter;
|
|
|
|
+
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
@@ -33,11 +37,9 @@ import javax.swing.JComboBox;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
import javax.swing.event.DocumentEvent;
|
|
import javax.swing.event.DocumentEvent;
|
|
import javax.swing.event.DocumentListener;
|
|
import javax.swing.event.DocumentListener;
|
|
-import javax.swing.filechooser.FileFilter;
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
public class ConnectionCreationPanel extends JScrollPane {
|
|
public class ConnectionCreationPanel extends JScrollPane {
|
|
-
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -276,64 +278,65 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
btnImportLink.addActionListener(a -> {
|
|
btnImportLink.addActionListener(a -> {
|
|
//Filechooser starting in the base directory
|
|
//Filechooser starting in the base directory
|
|
JFileChooser fc = new JFileChooser(new File(System.getProperty("user.dir")));
|
|
JFileChooser fc = new JFileChooser(new File(System.getProperty("user.dir")));
|
|
- fc.setFileFilter(new FileFilter() {
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public String getDescription() {
|
|
|
|
- return "Java Files(.java, .class)";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public boolean accept(File f) {
|
|
|
|
- if(f == null)
|
|
|
|
- return false;
|
|
|
|
- else if(f.isDirectory())
|
|
|
|
- return true;
|
|
|
|
- String[] parts = f.getName().split("[.]");
|
|
|
|
- if(parts.length<=1)
|
|
|
|
- return false;
|
|
|
|
- String ending = parts[parts.length-1].toLowerCase();
|
|
|
|
- if(ending.equals("class"))
|
|
|
|
- return true;
|
|
|
|
- else if(ending.equals("java"))
|
|
|
|
- return true;
|
|
|
|
- else
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ fc.setFileFilter(new JavaFileFilter());
|
|
int returnVal = fc.showOpenDialog(this);
|
|
int returnVal = fc.showOpenDialog(this);
|
|
|
|
|
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
|
|
+ /**
|
|
|
|
+ * selected File
|
|
|
|
+ */
|
|
File file = fc.getSelectedFile();
|
|
File file = fc.getSelectedFile();
|
|
- System.out.println("Opening: " + file.getName());
|
|
|
|
String[] parts = file.getName().split("[.]");
|
|
String[] parts = file.getName().split("[.]");
|
|
- for(int i = 0; i<parts.length; i++)
|
|
|
|
- System.out.println(i+" "+parts[i]);
|
|
|
|
if(parts.length <= 1)
|
|
if(parts.length <= 1)
|
|
return;
|
|
return;
|
|
|
|
+ /**
|
|
|
|
+ * Check the file type
|
|
|
|
+ */
|
|
String ending = parts[parts.length-1].toLowerCase();
|
|
String ending = parts[parts.length-1].toLowerCase();
|
|
- if(ending.equals("class")){
|
|
|
|
- System.out.println("Java Class File - not implemented");
|
|
|
|
- }
|
|
|
|
- else if(ending.equals("java")){
|
|
|
|
- System.out.println("Java File");
|
|
|
|
|
|
+ if(ending.equals("java")){
|
|
|
|
+
|
|
// Compile source file.
|
|
// Compile source file.
|
|
- Class imported = controller.getControllerImport().importJavaClass(file);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Imported Java Class
|
|
|
|
+ */
|
|
|
|
+ Class<? extends Protocol> imported = null;
|
|
|
|
+ try {
|
|
|
|
+ imported = ImportController.importJavaClass(file);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
if(imported==null){
|
|
if(imported==null){
|
|
- System.out.println("Importing failed");
|
|
|
|
|
|
+ System.out.println("WARNING: Importing failed");
|
|
}else{
|
|
}else{
|
|
- Class[] interfaces = imported.getInterfaces();
|
|
|
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
|
+ Class[] interfaces = imported.getInterfaces();
|
|
|
|
+ boolean isProtocol = false;
|
|
for(int i = 0; i<interfaces.length; i++){
|
|
for(int i = 0; i<interfaces.length; i++){
|
|
if(interfaces[i] == Protocol.class)
|
|
if(interfaces[i] == Protocol.class)
|
|
- System.out.println("YEAH PROTOCOL");
|
|
|
|
|
|
+ isProtocol = true;
|
|
|
|
+ }
|
|
|
|
+ if(!isProtocol){
|
|
|
|
+ System.out.println("WARNING: No valid protocol");
|
|
|
|
+ }
|
|
|
|
+ //Add Protocol
|
|
|
|
+ if(controller.getControllerImport().addProtocol(imported)){
|
|
|
|
+ //Update GUI
|
|
|
|
+ try {
|
|
|
|
+ cmbLinkType.addItem((imported.newInstance()).getName());
|
|
|
|
+ availableProtocols.add(imported);
|
|
|
|
+ } catch (Exception e1) {
|
|
|
|
+ System.out.println("Adding Protocol to the Links failed");
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("Importing into the model failed");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
- System.out.println("invalid File Type");
|
|
|
|
|
|
+ System.out.println("WARNING: Invalid File Type");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- System.out.println("Open command cancelled by user.");
|
|
|
|
|
|
+ //Importing Cancelled by user
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|