97993a7d579516343aae5ecd2f7cf6b348bac935
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / ViewModelModifiable.java
1 package net.mograsim.logic.model.model;
2
3 import java.util.Set;
4
5 import net.mograsim.logic.model.model.components.GUIComponent;
6 import net.mograsim.logic.model.model.wires.GUIWire;
7
8 //TODO a ViewModel is modifiable without casting to ViewModelModifiable via GUIWire::destroy and GUIComponent::destroy
9 public class ViewModelModifiable extends ViewModel
10 {
11         public String getDefaultComponentName(GUIComponent component)
12         {
13                 Set<String> componentNames = getComponentsByName().keySet();
14                 // TODO get the ID of component
15                 // The following does not work because this method is called in the constructor of DeserializedSubmodelComponent at a time where
16                 // idForSerializingOverride is not yet set
17 //              String componentID = null;
18 //              if (component instanceof DeserializedSubmodelComponent)
19 //                      componentID = ((DeserializedSubmodelComponent) component).idForSerializingOverride;
20 //              if (componentID == null)
21 //                      componentID = component.getClass().getSimpleName();
22                 String componentID = component.getClass().getSimpleName();
23                 String nameBase = componentID + '#';
24                 for (int i = 0;; i++)
25                 {
26                         String nameCandidate = nameBase + i;
27                         if (!componentNames.contains(nameCandidate))
28                                 return nameCandidate;
29                 }
30         }
31
32         public String getDefaultWireName()
33         {
34                 Set<String> wireNames = getWiresByName().keySet();
35                 for (int i = 0;; i++)
36                 {
37                         String nameCandidate = "unnamedWire#" + i;
38                         if (!wireNames.contains(nameCandidate))
39                                 return nameCandidate;
40                 }
41         }
42
43         @Override
44         public void componentCreated(GUIComponent component)
45         {
46                 super.componentCreated(component);
47         }
48
49         @Override
50         public void componentDestroyed(GUIComponent component)
51         {
52                 super.componentDestroyed(component);
53         }
54
55         @Override
56         public void wireCreated(GUIWire wire)
57         {
58                 super.wireCreated(wire);
59         }
60
61         @Override
62         public void wireDestroyed(GUIWire wire)
63         {
64                 super.wireDestroyed(wire);
65         }
66 }