Projekt

Obecné

Profil

« Předchozí | Další » 

Revize bf8bbb48

Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)

Added default groups creating on backend side.

Zobrazit rozdíly:

sources/src/cz/zcu/kiv/offscreen/api/GraphExport.java
1 1
package cz.zcu.kiv.offscreen.api;
2 2

  
3
import cz.zcu.kiv.offscreen.graph.EdgeArchetype;
4
import cz.zcu.kiv.offscreen.graph.Graph;
5
import cz.zcu.kiv.offscreen.graph.VertexArchetype;
6
import cz.zcu.kiv.offscreen.graph.AttributeType;
3
import cz.zcu.kiv.offscreen.graph.*;
7 4

  
8 5
import java.util.ArrayList;
9 6
import java.util.List;
......
35 32

  
36 33
    public GraphExport(Graph graph) {
37 34
        logger.trace("ENTRY");
38
        this.vertices = new ArrayList<Vertex>(graph.getVertices().values());
39
        this.edges = new ArrayList<Edge>(graph.getEdges());
40
        this.vertexArchetypes = new ArrayList<VertexArchetype>(graph.getVertexArchetypes());
41
        this.edgeArchetypes = new ArrayList<EdgeArchetype>(graph.getEdgeArchetypes());
35
        this.vertices = new ArrayList<>(graph.getVertices().values());
36
        this.edges = new ArrayList<>(graph.getEdges());
37
        this.vertexArchetypes = new ArrayList<>(graph.getVertexArchetypes());
38
        this.edgeArchetypes = new ArrayList<>(graph.getEdgeArchetypes());
42 39
        this.attributeTypes = new ArrayList<>(graph.getAttributeTypes());
43 40
        this.possibleEnumValues = graph.getPossibleEnumValues();
44 41
        this.archetypeIcons = graph.getArchetypeIcons();
42
        this.groups = graph.getGraphState().getGroups();
43
        this.positions = graph.getGraphState().getPositions();
44
        this.sideBar = graph.getGraphState().getSideBar();
45
        this.selectedVertex = graph.getGraphState().getSelectedVertex();
46
        this.selectedEdge = graph.getGraphState().getSelectedEdge();
45 47
        logger.trace("EXIT");
46 48
    }
47 49

  
sources/src/cz/zcu/kiv/offscreen/api/Group.java
1 1
package cz.zcu.kiv.offscreen.api;
2 2

  
3
import java.util.ArrayList;
3 4
import java.util.List;
4 5

  
5 6
/**
......
20 21
    /** List of vertices id whose incoming edges are visible. */
21 22
    private List<Integer> verticesEdgeToId;
22 23

  
24
    public Group(int groupId, int id, String name){
25
        this.groupId = groupId;
26
        this.id = id;
27
        this.name = name;
28
        verticesId = new ArrayList<>();
29
        verticesEdgeFromId = new ArrayList<>();
30
        verticesEdgeToId = new ArrayList<>();
31
    }
32

  
23 33
    public Group(int groupId, int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) {
24 34
        this.groupId = groupId;
25 35
        this.id = id;
......
76 86
    public void setVerticesEdgeToId(List<Integer> verticesEdgeToId) {
77 87
        this.verticesEdgeToId = verticesEdgeToId;
78 88
    }
89

  
90
    public void addVertexId(int vertexId){
91
        this.verticesId.add(vertexId);
92
    }
93

  
94
    public void addVetexEdgeToId(int vertexId){
95
        this.verticesEdgeToId.add(vertexId);
96
    }
97

  
98
    public void addVetexEdgeFromId(int vertexId){
99
        this.verticesEdgeFromId.add(vertexId);
100
    }
79 101
}
sources/src/cz/zcu/kiv/offscreen/graph/Graph.java
21 21
    private List<AttributeType> attributeTypes;
22 22
    private Map<String, List<String>> possibleEnumValues;
23 23
    private List<String> defaultGroupArchetypes;
24

  
25 24
    private Map<String, String> archetypeIcons;
25

  
26
    private GraphState graphState;
27

  
26 28
    private Logger logger = Logger.getLogger(Graph.class);
27 29

  
28 30
    public Graph() {
......
106 108
        this.vertices.put(name, vertex);
107 109
        logger.trace("EXIT");
108 110
    }
111

  
112
    public GraphState getGraphState() {
113
        return graphState;
114
    }
115

  
116
    public void setGraphState(GraphState graphState) {
117
        this.graphState = graphState;
118
    }
109 119
}
sources/src/cz/zcu/kiv/offscreen/graph/GraphManager.java
1 1
package cz.zcu.kiv.offscreen.graph;
2 2

  
3 3
import cz.zcu.kiv.offscreen.api.Edge;
4
import cz.zcu.kiv.offscreen.api.Group;
4 5
import cz.zcu.kiv.offscreen.api.SubedgeInfo;
5 6
import cz.zcu.kiv.offscreen.api.Vertex;
6 7
import cz.zcu.kiv.offscreen.graph.filter.*;
......
37 38
        }
38 39
    }
39 40

  
41
    private int lastVertexOrGroupId = 1;
42

  
40 43
    public List<VertexArchetype> vertexArchetypes = new ArrayList<>();
41 44
    public List<EdgeArchetype> edgeArchetypes = new ArrayList<>();
42 45
    public List<AttributeType> attributeTypes = new ArrayList<>();
......
291 294
        graph.setAttributeTypes(attributeTypes);
292 295
        graph.setPossibleEnumValues(possibleEnumValues);
293 296

  
297
        graph.setGraphState(createGraphState(graph));
298

  
294 299
        return graph;
295 300
    }
296 301

  
......
498 503
     * @param resultVertices - List of vertices to add to the graph.
499 504
     */
500 505
    private void addVerticesToGraph(Graph graph, Set<VertexImpl> resultVertices) {
501
        int idCounter = 1;
502 506
        for (VertexImpl vertexImpl : resultVertices) {
503 507

  
504 508
            VertexArchetype archetype = vertexArchetypes.get(vertexImpl.getArchetype());
505 509
            String title = archetype.name + ":" + vertexImpl.getTitle();
506 510
            List<String[]> attributes = getAttributesAsArray(vertexImpl.getSortedAttributes());
507 511

  
508
            Vertex vertex = new Vertex(idCounter++, vertexImpl.getOriginalId(), title, vertexImpl.getArchetype(), vertexImpl.getText(), attributes);
512
            Vertex vertex = new Vertex(lastVertexOrGroupId++, vertexImpl.getOriginalId(), title, vertexImpl.getArchetype(), vertexImpl.getText(), attributes);
509 513

  
510 514
            graph.addVertex("" + vertexImpl.getId(), vertex);
511 515
        }
......
556 560
        }
557 561
        return attrValue;
558 562
    }
563

  
564
    /**
565
     * Method is used for initialization of default graph status based on input graph.
566
     *
567
     * @param graph graph where are set vertices, defaultGroupArchetypes and vertexArchetypes.
568
     * @return instance of created GraphState
569
     */
570
    private GraphState createGraphState(Graph graph) {
571
        GraphState state = new GraphState();
572

  
573
        state.addGroupsAll(createDefaultGroups(graph));
574

  
575

  
576
        return state;
577
    }
578

  
579
    /**
580
     * Method create list of groups based on defaultGroupArchetypes whose are defined in graph. Vertices are taken
581
     * from graph too.
582
     *
583
     * @param graph graph from which are groups created.
584
     * @return created list of groups or empty list.
585
     */
586
    private Collection<Group> createDefaultGroups(Graph graph){
587

  
588
        Map<Integer, Group> groups = new HashMap<>();
589
        int groupId = 1;
590

  
591
        // find index of vertex archetypes names
592
        int index = 0;
593
        for(VertexArchetype archetype : graph.getVertexArchetypes()){
594
            if(graph.getDefaultGroupArchetypes().contains(archetype.name)){
595
                groups.put(index, new Group(groupId++, lastVertexOrGroupId++, archetype.name));
596
            }
597
            index++;
598
        }
599

  
600
        // find vertices with founded vertex archetypes indices
601
        for (Vertex vertex : graph.getVertices().values()){
602
            if(groups.keySet().contains(vertex.getArchetype())){
603
                groups.get(vertex.getArchetype()).addVertexId(vertex.getId());
604
            }
605
        }
606

  
607
        // remove groups without vertices
608
        List<Group> groupList = new ArrayList<>();
609
        for(Group group : groups.values()){
610
            if (!group.getVerticesId().isEmpty()){
611
                groupList.add(group);
612
            }
613
        }
614

  
615
        return groupList;
616
    }
559 617
}
sources/src/cz/zcu/kiv/offscreen/graph/GraphState.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
import cz.zcu.kiv.offscreen.api.Group;
4
import cz.zcu.kiv.offscreen.api.Position;
5
import cz.zcu.kiv.offscreen.api.SideBar;
6

  
7
import java.util.ArrayList;
8
import java.util.Collection;
9
import java.util.List;
10

  
11
public class GraphState {
12

  
13
    private List<Group> groups = new ArrayList<>();
14
    private List<Position> positions = new ArrayList<>();
15
    private List<SideBar> sideBar = new ArrayList<>();
16
    private int selectedVertex;
17
    private int selectedEdge;
18

  
19

  
20
    public List<Group> getGroups() {
21
        return groups;
22
    }
23

  
24
    public List<Position> getPositions() {
25
        return positions;
26
    }
27

  
28
    public List<SideBar> getSideBar() {
29
        return sideBar;
30
    }
31

  
32
    public int getSelectedVertex() {
33
        return selectedVertex;
34
    }
35

  
36
    public int getSelectedEdge() {
37
        return selectedEdge;
38
    }
39

  
40
    public void addGroup(Group group){
41
        this.groups.add(group);
42
    }
43

  
44
    public void addPosition(Position position){
45
        this.positions.add(position);
46
    }
47

  
48
    public void addSideBar(SideBar sideBar){
49
        this.sideBar.add(sideBar);
50
    }
51

  
52
    public void addGroupsAll(Collection<Group> collection){
53
        this.groups.addAll(collection);
54
    }
55

  
56
    public void addPositionsAll(Collection<Position> collection){
57
        this.positions.addAll(collection);
58
    }
59

  
60
    public void addSideBarsAll(Collection<SideBar> collection){
61
        this.sideBar.addAll(collection);
62
    }
63

  
64
    public void setSelectedVertex(int selectedVertex) {
65
        this.selectedVertex = selectedVertex;
66
    }
67

  
68
    public void setSelectedEdge(int selectedEdge) {
69
        this.selectedEdge = selectedEdge;
70
    }
71
}

Také k dispozici: Unified diff