};
private mxGraphComponent getRolegraph(){
LoggerManager.info(Constants.EDITOR_LOGGER, Messages.getString("PetriNet.Resources.DrawRoleGraph"));
mxGraph graph;
mxGraphComponent graphComponent;
graph = new mxGraph();
Object parentVertex = graph.getDefaultParent();
graph.getModel().beginUpdate();
//Colors
String[] colors = {"00DB26" ,
"8DF200" ,
"F2B705" ,
"F29A2E" ,
"F37542" ,
"F25456" ,
"A73ADB" ,
"5549F2" ,
"40ADDB" ,
"04F9BE" ,
"938466" ,
"C6B38F" ,
"F99249" ,
"E26537" ,
"FC553D" ,
"E52C3B"};
int alreadyPaintedFlag = 0;
try {
LogicalModel lm = new LogicalModel(objectsAssignedListModel,objectsUnassignedListModel,RolesTreeModel,RolesTopNode,GroupsTreeModel,GroupsTopNode,superRolesTreeModel,superGroupsTreeModel,superRolesTopNode, superGroupsTopNode);
LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm();
layoutAlgorithm.createLayout(lm);
Set<Layout> RoleLayoutSet = layoutAlgorithm.RoleLayoutSet;
//Assign color associations to the single Roles
String[] RoleColorAssociation = new String[lm.allRoles.size()];
int index = 0;
Iterator<?> colorIt = lm.allRoles.iterator();
while (colorIt.hasNext()) {
Role currentRole = (Role) colorIt.next();
RoleColorAssociation[index] = currentRole.name;
index+=1;
}
Iterator<Layout> it = RoleLayoutSet.iterator();
while (it.hasNext()) {
Layout currentLayout = it.next();
//Compound
int dimensionX = 140;
int dimensionY = 30;
// Width== Number of Roles * dimensionX
int compound_dimensionX = currentLayout.grid.length*dimensionX+20;
int compoundDimensionY = 0;
// maxRow= Longest Colum(with maximum of Rows)
int maxRow = 0;
// for each Role-Column -> do search the longest column, and remeber the Y
for (int i=0;i<currentLayout.grid.length;i++) {
if (currentLayout.grid[i] != null) {
for (int y=currentLayout.grid[i].length-1;y>=0;y--) {
if (currentLayout.grid[i][y] != null) {
if (y>maxRow) {
maxRow = y;
}
break;
}
}
}
}
// Search for the deepest Place
Integer maxDepth[] = new Integer[currentLayout.grid.length];
Integer firstKill[] = new Integer[currentLayout.grid.length];
Iterator<RoleLocator> deepBlue = currentLayout.Roles.iterator();
while (deepBlue.hasNext()) {
RoleLocator currentRole = deepBlue.next();
if(maxDepth[currentRole.column]==null){
maxDepth[currentRole.column]=1;
}else {
maxDepth[currentRole.column]++;
}
}
int deepestSubset = 0;
for(int i=0;i<maxDepth.length;i++){
if(maxDepth[i]>deepestSubset){
deepestSubset=maxDepth[i];
}
}
if(deepestSubset==1){
// so finally -> compound_dim_Y = LongestColumn * dimensionY
compoundDimensionY = (maxRow+1)*dimensionY+60;
// now draw compound x y x-length y-length
graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX + 40, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );
// So now we build an Iterator to travel trough all Roles of the compound Role
//Roles
Iterator<RoleLocator> subIt = currentLayout.Roles.iterator();
while (subIt.hasNext()) {
RoleLocator currentRole = subIt.next();
//Find the related color
int colorRelation = 0;
for (int i=0; i<RoleColorAssociation.length;i++) {
if (RoleColorAssociation[i] == currentRole.name) {
colorRelation = i;
if (colorRelation>=colors.length) {
colorRelation = colorRelation - colors.length;
}
break;
}
}
graph.insertVertex(parentVertex, null, currentRole.name, 15+dimensionX*currentRole.column, 20+dimensionY*currentRole.ystart+alreadyPaintedFlag, dimensionX, dimensionY*(currentRole.yend-currentRole.ystart+1)+30, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black"); //kursiv ;fontStyle=1;fontColor=black
}
//Components
String containsString = new String();
// for each column
for (int x1=0; x1<currentLayout.grid.length;x1++) {
// for each row/ Component
for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
int xMultiplicator = 0;
// is the object availible ?
if (currentLayout.grid[x1][y1] != null) {
if(containsString.contains(currentLayout.grid[x1][y1].name)){}
//do nothing -> cause it is already included
else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
// Add current user
containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
//for each column
for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
// for each row
for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
// is the object availible ?
if(currentLayout.grid[x2][y2] != null){
if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
if((x2 - x1) > xMultiplicator)
// if the multiplicator has to be augmented by more than one column, it will not be done, cause in this case there ist a gap
if((x2-x1)==(xMultiplicator+1)){
xMultiplicator = x2 - x1;
}else {
containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
xMultiplicator = 0;
}
}
}
}
}
if(xMultiplicator==0){
graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10) + (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
}
if(xMultiplicator>0){
graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10) + (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
}
}
}
}
}
}else{
compoundDimensionY = (maxRow+1)*dimensionY+70;
graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );
//Roles
Iterator<RoleLocator> subIt = currentLayout.Roles.iterator();
while (subIt.hasNext()) {
RoleLocator currentRole = subIt.next();
if(firstKill[currentRole.column]==null){
firstKill[currentRole.column]=0;
}else{
firstKill[currentRole.column]=1;
}
//Find the related color
int colorRelation = 0;
for (int i=0; i<RoleColorAssociation.length;i++) {
if (RoleColorAssociation[i] == currentRole.name) {
colorRelation = i;
if (colorRelation>=colors.length) {
colorRelation = colorRelation - colors.length;
}
break;
}
}
graph.insertVertex(parentVertex, null, currentRole.name, 15+dimensionX*currentRole.column, 20+(dimensionY*currentRole.ystart*2)+alreadyPaintedFlag+(firstKill[currentRole.column]*20), dimensionX, dimensionY*(currentRole.yend-currentRole.ystart+1)-(firstKill[currentRole.column]*dimensionY)+44, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black");
}
//Components
String containsString = new String();
for (int x1=0; x1<currentLayout.grid.length;x1++) {
for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
int xMultiplicator = 0;
if (currentLayout.grid[x1][y1] != null) {
if(containsString.contains(currentLayout.grid[x1][y1].name)){}
else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
if(currentLayout.grid[x2][y2] != null){
if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
if((x2 - x1) > xMultiplicator)
if((x2-x1)==(xMultiplicator+1)){
xMultiplicator = x2 - x1;
}else {
containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
xMultiplicator = 0;
}
}
}
}
}
// x y x-length y-length
if(xMultiplicator==0){
graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10) + (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
}
if(xMultiplicator>0){
graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10) + (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
}
}
}
}
}
}
alreadyPaintedFlag = alreadyPaintedFlag + compoundDimensionY + 10;
}
} finally {
graph.getModel().endUpdate();
}
if(alreadyPaintedFlag==0){
graph.insertVertex(parentVertex, null,Messages.getString("PetriNet.Resources.NoRolesDefined"),10,10,150,30, "rounded=1;opacity=0;fontStyle=1;fontColor=black");
}
// Create Listener, first parameter in constructor is the observed graph
mxIEventListener mySelectListener = new selectListener(graph);
// add Listener as CHANGE-Listener
graph.getSelectionModel().addListener(mxEvent.CHANGE, mySelectListener);
graphComponent = new mxGraphComponent(graph);
temp_Role_graph = graph;
temp_Role_graphComponent= graphComponent;