Exemplo n.º 1
0
 public Object insertEdge(mxCell v1, mxCell v2) {
   graph.getModel().beginUpdate();
   //		log.log(Level.INFO, "Inserting edge between " +
   //							((VertexValue) v1.getValue()).getId() +
   //							" and " +
   //							((VertexValue) v2.getValue()).getId());
   Object parent = graph.getDefaultParent();
   mxCell inserted;
   try {
     inserted = (mxCell) graph.insertEdge(parent, null, null, v1, v2);
     //			log.log(Level.INFO, "Edge inserted");
     EdgeValue value =
         new EdgeValue(
             ((VertexValue) v2.getValue())
                 .getInitialImmunity()); // na razie waga krawędzi to po prostu odporność
                                         // wierzchołka do którego ta krawędź prowadzi
     ((VertexValue) v1.getValue()).addNeighbour(v2); // dodajemy v2 jako sąsiednią krawędź v1
     //			log.log(Level.INFO, "Neighbour added to target vertex");
     inserted.setValue(value); // ustawiamy wartość dodanej krawędzi
     //			log.log(Level.INFO, "Edge value set");
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     graph.getModel().endUpdate();
   }
   return inserted;
 }
Exemplo n.º 2
0
    public void invoke(Object sender, mxEventObject evt) {

      if (DEBUG)
        System.out.println(
            "[TrackScheme] CellRemovalListener: cells removed - Source of event is "
                + sender.getClass()
                + ". Fire flag is "
                + doFireModelChangeEvent);

      if (!doFireModelChangeEvent) return;

      // Separate spots from edges
      Object[] objects = (Object[]) evt.getProperty("cells");
      HashSet<Spot> spotsToRemove = new HashSet<Spot>();
      ArrayList<DefaultWeightedEdge> edgesToRemove = new ArrayList<DefaultWeightedEdge>();
      for (Object obj : objects) {
        mxCell cell = (mxCell) obj;
        if (null != cell) {
          if (cell.isVertex()) {
            // Build list of removed spots
            Spot spot = graph.getSpotFor(cell);
            spotsToRemove.add(spot);
            // Clean maps
            graph.removeMapping(spot);
          } else if (cell.isEdge()) {
            // Build list of removed edges
            DefaultWeightedEdge edge = graph.getEdgeFor(cell);
            if (null == edge) continue;
            edgesToRemove.add(edge);
            // Clean maps
            graph.removeMapping(edge);
          }
        }
      }

      evt.consume();

      // Clean model
      doFireModelChangeEvent = false;
      model.beginUpdate();
      try {
        selectionModel.clearSelection();
        // We remove edges first so that we ensure we do not end having orphan edges.
        // Normally JGraphT handles that well, but we enforce things here. To be sure.
        for (DefaultWeightedEdge edge : edgesToRemove) {
          model.removeEdge(edge);
        }
        for (Spot spot : spotsToRemove) {
          model.removeSpot(spot);
        }

      } finally {
        model.endUpdate();
      }
      doFireModelChangeEvent = true;
    }
  /**
   * Inserts a given Relation in a graph
   *
   * @param graph the graph as target for insertion
   * @param relation the relation that should be inserted
   * @param verticalOffset the vertical offset of the relation
   * @return the mxCell representing the Relation
   */
  private Object insertRelation(mxGraph graph, RelationSchema relation, int verticalOffset) {
    int attributeOffset;
    int horizontalOffset = 0;
    ArrayList<mxCell> attributeCells = new ArrayList<>();

    mxCell relationVertex =
        (mxCell)
            graph.insertVertex(
                parentPane,
                relation.getName(),
                relation,
                horizontalOffset,
                verticalOffset,
                15 * relation.getName().length(),
                25,
                "RELATION_HEADER");

    attributeOffset = (int) (relationVertex.getGeometry().getY() + 25);

    // Add attributes
    for (Attribute attr : relation.getAttributes()) {
      attributeCells.add(
          (mxCell)
              graph.insertVertex(
                  parentPane,
                  attr.getName(),
                  attr,
                  horizontalOffset,
                  attributeOffset,
                  30,
                  25,
                  super.getAttributeStyle(attr, getImageSizeClass(attr))));
      graph.updateCellSize(attributeCells.get(attributeCells.size() - 1));
      horizontalOffset += 30;
    }

    double currentXPos = 0;
    for (int i = 0; i < attributeCells.size(); i++) {
      mxGeometry geo = attributeCells.get(i).getGeometry();
      if (i > 0) {
        currentXPos += attributeCells.get(i - 1).getGeometry().getWidth();
        geo.setX(currentXPos);
      }

      geo.setHeight(25);
      geo.setWidth(geo.getWidth() + 5);
    }

    drawFunctionalDependencies(
        relation.getAttributes(), attributeCells, relation.getFunctionalDependencies());

    return relationVertex;
  }
Exemplo n.º 4
0
 public void selectNodes(mxCell[] cells) {
   Set<String> lids = new HashSet<String>();
   if (cells != null) {
     for (mxCell cell : cells) {
       lids.add(cell.getId());
     }
   }
   if (hasChanges(lids)) {
     graph.setSelectionCells(cells);
     graph.refresh();
   }
 }
  /** Displays all relations with their functional dependencies */
  private void display() {
    int offset = 5;
    mxCell relationCell;

    removeAllRelations();

    for (RelationSchema relation : dbRelations) {
      relationCell = (mxCell) insertRelation(graph, relation, offset);
      offset +=
          relationCell.getGeometry().getHeight()
              + (50 + 30 * relation.getFunctionalDependencies().size());
    }
  }
  /**
   * Draws a node beneath each Attribute-mxCell (horizontal-Center)
   *
   * @param attributes the cells to draw a node beneath them
   * @param offset the vertical offset between the cell and the node
   * @return returns a ArrayList containing all inserted nodes
   */
  private ArrayList<mxCell> drawNodes(ArrayList<mxCell> attributes, int offset) {
    ArrayList<mxCell> nodes = new ArrayList<>();

    for (mxCell cell : attributes) {
      nodes.add(
          (mxCell)
              graph.insertVertex(
                  parentPane,
                  null,
                  null,
                  cell.getGeometry().getCenterX(),
                  getCellLowestYPoint(cell) + offset,
                  1,
                  1,
                  "NODE"));
    }

    return nodes;
  }
Exemplo n.º 7
0
 public mxCell findVertex(String id) {
   Object[] cells = graph.getChildCells(graph.getDefaultParent());
   String logMessage = "\nLooking for vertex with ID: \"" + id + "\"\n";
   for (int i = 0; i < cells.length; i++) {
     mxCell cell = (mxCell) cells[i];
     if (cell.isVertex()) {
       String cellsId = ((VertexValue) cell.getValue()).getId();
       logMessage += "checking vertex ID: \"" + cellsId + "\"\n";
       if (cellsId.equals(id)) {
         logMessage += "vertex found!\n";
         log.log(Level.INFO, logMessage);
         return cell;
       }
     }
   }
   logMessage += "Can't find vertex for ID: \"" + id + "\"\n";
   log.log(Level.INFO, logMessage);
   return null;
 }
Exemplo n.º 8
0
  protected boolean hasChanges(Set<String> cells) {
    // graphSelections is always not null
    Object[] graphSelections = graph.getSelectionCells();

    if (cells == null) {
      return graphSelections.length != 0;
    }
    if (graphSelections.length != cells.size()) {
      return true;
    }

    for (int i = 0; i < graphSelections.length; i++) {
      mxCell graphCell = (mxCell) graphSelections[i];
      if (!cells.contains(graphCell.getId())) {
        return true;
      }
    }
    return false;
  }
Exemplo n.º 9
0
  @Override
  public void decode(
      StepMetaInterface stepMetaInterface,
      mxCell cell,
      List<DatabaseMeta> databases,
      IMetaStore metaStore)
      throws Exception {
    CheckSumMeta checkSumMeta = (CheckSumMeta) stepMetaInterface;

    checkSumMeta.setCheckSumType(Integer.parseInt(cell.getAttribute("checkSumType")));
    checkSumMeta.setResultFieldName(cell.getAttribute("resultfieldName"));
    checkSumMeta.setCompatibilityMode("true".equals(cell.getAttribute("compatibilityMode")));

    String fields = cell.getAttribute("fields");
    JSONArray jsonArray = JSONArray.fromObject(fields);
    String[] fieldName = new String[jsonArray.size()];
    for (int i = 0; i < jsonArray.size(); i++) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);
      fieldName[i] = jsonObject.optString("name");
    }
    checkSumMeta.setFieldName(fieldName);
  }
  @SuppressWarnings({"unchecked", "unchecked"})
  // private mxGraphModel ExtractGraphFromSTD_INPUT() {
  private DirectedGraph<Object, ObjectEdge> ExtractGraphFromSTD_INPUT() {
    ActivityPort stdInput = getInput("STD_INPUT");
    ActivityPort inputfile = getInput("INPUT_FILE_BASE");

    /* @Todo: Reads directly from STD_INPUT. Should (be better) read from file (lots of .log .dot, .dat are generated by vivado workflow */
    Collection<String> lines = UtilStr.SeparateComponents((String) stdInput.getValue(), "\n");
    String startString = "<<BEGIN>><<" + (String) inputfile.getValue() + "_graph_minimized>>";
    String stopString = "<<END>><<" + (String) inputfile.getValue() + "_graph_minimized>>";
    boolean reading = false;

    // rebuild circuit graph
    DirectedGraph<Object, ObjectEdge> graph =
        new DefaultDirectedGraph<Object, ObjectEdge>(ObjectEdge.class);
    Map<String, Object> vertexMap = new HashMap<String, Object>();

    // mxGraphModel circuitGraph = new mxGraphModel();
    // circuitGraph.setCreateIds(false);
    // circuitGraph.beginUpdate();
    // Object rootCell = circuitGraph.getRoot();
    for (String line : lines) {
      if (reading) {
        if (line.equals(stopString)) {
          reading = false;
          break;
        } else {
          // rebuild graph
          Collection<String> wordsCollection = UtilStr.SeparateComponents(line, " ");
          String[] words = wordsCollection.toArray(new String[wordsCollection.size()]);
          int index = 1;
          int i;
          switch (words[0]) {
            case "Vertex":
              mxCell vertexCell = new mxCell();
              vertexCell.setVertex(true);
              vertexCell.setId(words[1]);
              switch (words[2]) {
                case "cell":
                  PLDConfigurableElement pldCell = new PLDConfigurableElement("Cell_0");
                  pldCell.setName(words[5]);
                  pldCell.setInitialValue(words[4]);
                  pldCell.setComponentType(ElectricalComponentType.INTRACHIP);
                  pldCell.setDescription(words[3]);
                  i = 6;
                  while ((i < words.length) && !words[i].equals("=>")) {
                    // String name, Direction direction, Long address, Integer bit, Boolean
                    // mandatory
                    // PhysicalPortPin  pin = new PhysicalPortPin(words[i], Direction.UNKNOWN, 0L,
                    // 0, true);
                    CPSPort pin =
                        new CPSPort(
                            words[i],
                            Direction.UNKNOWN,
                            0L,
                            0,
                            true); // PhysicalPortPin(words[i], Direction.UNKNOWN, 0L, 0, true);
                    if (pldCell.getInterfaceComponent().getChannels().size() == 0) {
                      pldCell
                          .getInterfaceComponent()
                          .getChannels()
                          .add(new ChannelPrimitive("default chanel"));
                    }
                    ChannelAbstract channel =
                        pldCell.getInterfaceComponent().getChannels().iterator().next();
                    channel.getPorts().add(pin);
                    vertexMap.put(words[i], pin);
                    i++;
                  }
                  while (i < words.length - 1) {
                    i++;
                    words[i] = words[i].replaceAll("@", " ");
                    int indexOfEqualSignal = words[i].indexOf("=");
                    String property = words[i].substring(0, indexOfEqualSignal);
                    String propValue = words[i].substring(indexOfEqualSignal + 1);
                    // Boolean isConst, String name, String defaultValue, String type, Direction
                    // direction
                    DiscreteVariable attribute =
                        new DiscreteVariable(
                            false, property, propValue, "UNKNOWN", Direction.UNKNOWN);
                    pldCell.getExtraAttributes().add(attribute);
                  }
                  // pldCell.getInterfaceElectrical().setElectricalFeature(new ElectricalFeature());
                  vertexCell.setValue(pldCell);
                  vertexMap.put(words[1], pldCell);
                  System.out.println("Vertex cell: " + pldCell);
                  graph.addVertex(pldCell);
                  break;
                case "port":
                  // Vertex <NodoIdx> port <Direction> <Name>
                  // EX: Vertex node18 port IN SA
                  Long address = Long.parseLong(words[1].replace("node", ""));
                  Direction dir = Direction.valueOf(words[3]);
                  // String name, Direction direction, Long address, Integer bit, Boolean mandatory
                  PhysicalPortPin pin = new PhysicalPortPin(words[4], dir, address, 0, true);
                  i = 5; // to be ++
                  while (i < words.length - 1) {
                    i++;
                    words[i] = words[i].replaceAll("@", " ");
                    int indexOfEqualSignal = words[i].indexOf("=");
                    String property = words[i].substring(0, indexOfEqualSignal);
                    String propValue = words[i].substring(indexOfEqualSignal + 1);
                    // Boolean isConst, String name, String defaultValue, String type, Direction
                    // direction
                    DiscreteVariable attribute =
                        new DiscreteVariable(
                            false, property, propValue, "UNKNOWN", Direction.UNKNOWN);
                    pin.getExtraAttributes().add(attribute);
                  }
                  vertexCell.setValue(pin);
                  vertexMap.put(words[1], pin); // nodeX
                  vertexMap.put(words[4], pin); // real name
                  System.out.println("Vertex port: " + pin);
                  graph.addVertex(pin);
                  break;
                default:
                  break;
              }
              // circuitGraph.add(rootCell, vertexCell, index++);
              break;
            case "Edge":
              // mxCell edgeCell = new mxCell();
              // edgeCell.setEdge(true);
              // edgeCell.setId(circuitGraph.createId(edgeCell));
              // mxCell source = (mxCell) circuitGraph.getCell(words[1]);
              // assert source != null;
              // edgeCell.setSource(source);
              // mxCell target = (mxCell) circuitGraph.getCell(words[2]);
              // assert target != null;
              // edgeCell.setTarget(target);
              String sourcePinOrPortStr = words[3];
              PhysicalPortPin sourcePinPort, targetPinPort;
              if (sourcePinOrPortStr.indexOf(":") > -1) {
                // is a CELL:PIN (takes only the pin part)
                sourcePinOrPortStr =
                    sourcePinOrPortStr.substring(sourcePinOrPortStr.indexOf(":") + 1);
                sourcePinPort = (PhysicalPortPin) vertexMap.get(sourcePinOrPortStr);
                assert sourcePinPort != null;
                sourcePinPort.setDirection(
                    Direction.OUT); // it is an OUT PIN, so we can read from it
              } else {
                sourcePinPort = (PhysicalPortPin) vertexMap.get(sourcePinOrPortStr);
                assert sourcePinPort != null;
                sourcePinPort.setDirection(
                    Direction.IN); // it is an IN PORT, so we can read from it
              }
              String targetPinOrPortStr = words[4];
              if (targetPinOrPortStr.indexOf(":") > -1) { // is a CELL:PIN (takes only the pin part)
                targetPinOrPortStr =
                    targetPinOrPortStr.substring(targetPinOrPortStr.indexOf(":") + 1);
                targetPinPort = (PhysicalPortPin) vertexMap.get(targetPinOrPortStr);
                assert targetPinPort != null;
                targetPinPort.setDirection(Direction.IN); // it is an IN PIN, so we can write to it
              } else {
                targetPinPort = (PhysicalPortPin) vertexMap.get(targetPinOrPortStr);
                assert targetPinPort != null;
                targetPinPort.setDirection(
                    Direction.OUT); // it is an OUT PORT, so we can write to it
              }
              PhysicalCommunicationNet hardwareNet =
                  new PhysicalCommunicationNet(sourcePinPort, targetPinPort);
              // edgeCell.setValue(hardwareNet);
              //                            i = 5; // to be ++
              //                            while (i < words.length - 1) {
              //                                i++;
              //                                words[i] = words[i].replaceAll("@", " ");
              //                                int indexOfEqualSignal = words[i].indexOf("=");
              //                                String property = words[i].substring(0,
              // indexOfEqualSignal);
              //                                String propValue =
              // words[i].substring(indexOfEqualSignal + 1);
              //                                //Boolean isConst, String name, String defaultValue,
              // String type, Direction direction
              //                                DiscreteVariable attribute = new
              // DiscreteVariable(false, property, propValue, "UNKNOWN", Direction.UNKNOWN);
              //                                //pin.getExtraAttributes().add(attribute);
              //                                /**
              //                                 * @TODO: where net properties are inserted into? *
              //                                 */
              //                            }
              // circuitGraph.add(rootCell, edgeCell, index++);
              Object vSource = vertexMap.get(words[1]);
              Object vTarget = vertexMap.get(words[2]);
              System.out.println(
                  "Edge: "
                      + vSource
                      + " -> "
                      + vTarget
                      + "   << "
                      + sourcePinOrPortStr
                      + " -> "
                      + targetPinOrPortStr
                      + "  >>");
              ObjectEdge edge = graph.addEdge(vSource, vTarget);
              edge.setUserObject(hardwareNet);
              break;
            default:
              Logger.getGlobal()
                  .warning(
                      "Error: Line not recognized when expecting to rebuild the circuit graph: "
                          + line);
              break;
          }
        }
      } else if (line.equals(startString)) {
        reading = true;
      }
    }
    // circuitGraph.endUpdate();
    //        return circuitGraph;
    return graph;
  }
Exemplo n.º 11
0
  public Port() {
    super("Hello, World!");

    mxGraph graph =
        new mxGraph() {

          // Ports are not used as terminals for edges, they are
          // only used to compute the graphical connection point
          public boolean isPort(Object cell) {
            mxGeometry geo = getCellGeometry(cell);

            return (geo != null) ? geo.isRelative() : false;
          }

          // Implements a tooltip that shows the actual
          // source and target of an edge
          public String getToolTipForCell(Object cell) {
            if (model.isEdge(cell)) {
              return convertValueToString(model.getTerminal(cell, true))
                  + " -> "
                  + convertValueToString(model.getTerminal(cell, false));
            }

            return super.getToolTipForCell(cell);
          }

          // Removes the folding icon and disables any folding
          public boolean isCellFoldable(Object cell, boolean collapse) {
            return false;
          }
        };

    // Sets the default edge style
    Map<String, Object> style = graph.getStylesheet().getDefaultEdgeStyle();
    style.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector);

    Object parent = graph.getDefaultParent();

    graph.getModel().beginUpdate();
    try {
      mxCell v1 = (mxCell) graph.insertVertex(parent, null, "Hello", 20, 20, 100, 100, "");
      v1.setConnectable(false);
      mxGeometry geo = graph.getModel().getGeometry(v1);
      // The size of the rectangle when the minus sign is clicked
      geo.setAlternateBounds(new mxRectangle(20, 20, 100, 50));

      mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER);
      // Because the origin is at upper left corner, need to translate to
      // position the center of port correctly
      geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo1.setRelative(true);

      mxCell port1 = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter");
      port1.setVertex(true);

      mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER);
      geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo2.setRelative(true);

      mxCell port2 = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter");
      port2.setVertex(true);

      graph.addCell(port1, v1);
      graph.addCell(port2, v1);

      Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);

      graph.insertEdge(parent, null, "Edge", port2, v2);
    } finally {
      graph.getModel().endUpdate();
    }

    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    getContentPane().add(graphComponent);
    graphComponent.setToolTips(true);
  }
Exemplo n.º 12
0
  @Override
  public String encode(AbstractMeta meta) throws Exception {
    TransMeta transMeta = (TransMeta) meta;

    mxGraph graph = new mxGraph();
    graph.getModel().beginUpdate();
    mxCell parent = (mxCell) graph.getDefaultParent();
    Document doc = mxUtils.createDocument();

    try {
      Element e = super.encodeCommRootAttr(transMeta, doc);
      e.setAttribute("trans_version", transMeta.getTransversion());
      e.setAttribute("trans_type", transMeta.getTransformationType().getCode());
      e.setAttribute("trans_status", String.valueOf(transMeta.getTransstatus()));

      // variables
      Properties sp = new Properties();
      JSONArray jsonArray = new JSONArray();

      String[] keys = Variables.getADefaultVariableSpace().listVariables();
      for (int i = 0; i < keys.length; i++) {
        sp.put(keys[i], Variables.getADefaultVariableSpace().getVariable(keys[i]));
      }

      List<String> vars = transMeta.getUsedVariables();
      for (int i = 0; i < vars.size(); i++) {
        String varname = vars.get(i);
        if (!varname.startsWith(Const.INTERNAL_VARIABLE_PREFIX)
            && Const.indexOfString(varname, transMeta.listParameters()) < 0) {
          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", sp.getProperty(varname, ""));
          jsonArray.add(param);
        }
      }

      for (String varname : Const.INTERNAL_JOB_VARIABLES) {
        String value = transMeta.getVariable(varname);
        if (!Const.isEmpty(value)) {

          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", value);
          jsonArray.add(param);
        }
      }
      e.setAttribute("variables", jsonArray.toString());

      TransLogTable transLogTable = transMeta.getTransLogTable();
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("connection", transLogTable.getConnectionName());
      jsonObject.put("schema", transLogTable.getSchemaName());
      jsonObject.put("table", transLogTable.getTableName());
      jsonObject.put("size_limit_lines", transLogTable.getLogSizeLimit());
      jsonObject.put("interval", transLogTable.getLogInterval());
      jsonObject.put("timeout_days", transLogTable.getTimeoutInDays());
      JSONArray fields = new JSONArray();
      for (LogTableField field : transLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("subjectAllowed", field.isSubjectAllowed());
        if (field.isSubjectAllowed()) {
          jsonField.put("subject", field.getSubject() == null ? "" : field.getSubject().toString());
        } else {
          jsonField.put("subject", "-");
        }
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("transLogTable", jsonObject.toString());

      StepLogTable stepLogTable = transMeta.getStepLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", stepLogTable.getConnectionName());
      jsonObject.put("schema", stepLogTable.getSchemaName());
      jsonObject.put("table", stepLogTable.getTableName());
      jsonObject.put("timeout_days", stepLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : stepLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("stepLogTable", jsonObject.toString());

      PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", performanceLogTable.getConnectionName());
      jsonObject.put("schema", performanceLogTable.getSchemaName());
      jsonObject.put("table", performanceLogTable.getTableName());
      jsonObject.put("interval", performanceLogTable.getLogInterval());
      jsonObject.put("timeout_days", performanceLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : performanceLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("performanceLogTable", jsonObject.toString());

      MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", metricsLogTable.getConnectionName());
      jsonObject.put("schema", metricsLogTable.getSchemaName());
      jsonObject.put("table", metricsLogTable.getTableName());
      jsonObject.put("timeout_days", metricsLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : metricsLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("metricsLogTable", jsonObject.toString());

      jsonObject = new JSONObject();
      jsonObject.put(
          "connection",
          transMeta.getMaxDateConnection() == null
              ? ""
              : transMeta.getMaxDateConnection().getName());
      jsonObject.put("table", transMeta.getMaxDateTable());
      jsonObject.put("field", transMeta.getMaxDateField());
      jsonObject.put("offset", transMeta.getMaxDateOffset());
      jsonObject.put("maxdiff", transMeta.getMaxDateDifference());
      e.setAttribute("maxdate", jsonObject.toString());

      e.setAttribute("size_rowset", String.valueOf(transMeta.getSizeRowset()));
      e.setAttribute("sleep_time_empty", String.valueOf(transMeta.getSleepTimeEmpty()));
      e.setAttribute("sleep_time_full", String.valueOf(transMeta.getSleepTimeFull()));
      e.setAttribute("unique_connections", transMeta.isUsingUniqueConnections() ? "Y" : "N");
      e.setAttribute("feedback_shown", transMeta.isFeedbackShown() ? "Y" : "N");
      e.setAttribute("feedback_size", String.valueOf(transMeta.getFeedbackSize()));
      e.setAttribute(
          "using_thread_priorities", transMeta.isUsingThreadPriorityManagment() ? "Y" : "N");
      e.setAttribute(
          "capture_step_performance", transMeta.isCapturingStepPerformanceSnapShots() ? "Y" : "N");
      e.setAttribute(
          "step_performance_capturing_delay",
          String.valueOf(transMeta.getStepPerformanceCapturingDelay()));
      e.setAttribute(
          "step_performance_capturing_size_limit",
          transMeta.getStepPerformanceCapturingSizeLimit());

      super.encodeSlaveServers(e, transMeta);
      encodeClusterSchema(e, transMeta);
      encodePartitionSchema(e, transMeta);

      try {
        if (transMeta.getKey() != null) {
          e.setAttribute("key_for_session_key", XMLHandler.encodeBinaryData(transMeta.getKey()));
        } else {
          e.setAttribute("key_for_session_key", "");
        }
      } catch (Exception e1) {
        e1.printStackTrace();
        e.setAttribute("key_for_session_key", "");
      }
      e.setAttribute("is_key_private", transMeta.isPrivateKey() ? "Y" : "N");

      super.encodeNote(doc, graph, transMeta);

      super.encodeDatabases(e, transMeta);
      parent.setValue(e);

      // encode steps and hops
      HashMap<StepMeta, Object> cells = new HashMap<StepMeta, Object>();
      List<StepMeta> list = transMeta.getSteps();
      for (int i = 0; i < list.size(); i++) {
        StepMeta step = (StepMeta) list.get(i);
        Point p = step.getLocation();
        StepEncoder stepEncoder = (StepEncoder) PluginFactory.getBean(step.getStepID());

        PluginInterface plugin =
            PluginRegistry.getInstance().getPlugin(StepPluginType.class, step.getStepID());
        Object cell =
            graph.insertVertex(
                parent,
                null,
                stepEncoder.encodeStep(step),
                p.x,
                p.y,
                40,
                40,
                "icon;image=" + SvgImageUrl.getUrl(plugin));
        cells.put(step, cell);
      }

      for (int i = 0; i < transMeta.nrTransHops(); i++) {
        TransHopMeta transHopMeta = transMeta.getTransHop(i);

        Object v1 = cells.get(transHopMeta.getFromStep());
        Object v2 = cells.get(transHopMeta.getToStep());

        graph.insertEdge(parent, null, TransHopMetaCodec.encode(transHopMeta), v1, v2);
      }
    } finally {
      graph.getModel().endUpdate();
    }

    mxCodec codec = new mxCodec();
    return mxUtils.getPrettyXml(codec.encode(graph.getModel()));
  }
Exemplo n.º 13
0
  @Override
  public AbstractMeta decode(String graphXml) throws Exception {
    mxGraph graph = new mxGraph();
    mxCodec codec = new mxCodec();
    Document doc = mxUtils.parseXml(graphXml);
    codec.decode(doc.getDocumentElement(), graph.getModel());
    mxCell root = (mxCell) graph.getDefaultParent();

    TransMeta transMeta = new TransMeta();
    decodeCommRootAttr(root, transMeta);
    transMeta.setTransstatus(Const.toInt(root.getAttribute("trans_status"), -1));
    transMeta.setTransversion(root.getAttribute("trans_version"));

    if (transMeta.getRepository() != null)
      transMeta.setSharedObjects(transMeta.getRepository().readTransSharedObjects(transMeta));
    else transMeta.setSharedObjects(transMeta.readSharedObjects());

    transMeta.importFromMetaStore();

    decodeDatabases(root, transMeta);
    decodeNote(graph, transMeta);

    int count = graph.getModel().getChildCount(root);
    for (int i = 0; i < count; i++) {
      mxCell cell = (mxCell) graph.getModel().getChildAt(root, i);
      if (cell.isVertex()) {
        Element e = (Element) cell.getValue();
        if (PropsUI.TRANS_STEP_NAME.equals(e.getTagName())) {
          StepDecoder stepDecoder = (StepDecoder) PluginFactory.getBean(cell.getAttribute("ctype"));
          StepMeta stepMeta =
              stepDecoder.decodeStep(cell, transMeta.getDatabases(), transMeta.getMetaStore());
          stepMeta.setParentTransMeta(transMeta);
          if (stepMeta.isMissing()) {
            transMeta.addMissingTrans((MissingTrans) stepMeta.getStepMetaInterface());
          }

          StepMeta check = transMeta.findStep(stepMeta.getName());
          if (check != null) {
            if (!check.isShared()) {
              // Don't overwrite shared objects
              transMeta.addOrReplaceStep(stepMeta);
            } else {
              check.setDraw(stepMeta.isDrawn()); // Just keep the  drawn flag  and location
              check.setLocation(stepMeta.getLocation());
            }
          } else {
            transMeta.addStep(stepMeta); // simply add it.
          }
        }
      }
    }

    // Have all StreamValueLookups, etc. reference the correct source steps...
    //
    for (int i = 0; i < transMeta.nrSteps(); i++) {
      StepMeta stepMeta = transMeta.getStep(i);
      StepMetaInterface sii = stepMeta.getStepMetaInterface();
      if (sii != null) {
        sii.searchInfoAndTargetSteps(transMeta.getSteps());
      }
    }

    count = graph.getModel().getChildCount(root);
    for (int i = 0; i < count; i++) {
      mxCell cell = (mxCell) graph.getModel().getChildAt(root, i);
      if (cell.isEdge()) {
        mxCell source = (mxCell) cell.getSource();
        mxCell target = (mxCell) cell.getTarget();

        TransHopMeta hopinf = new TransHopMeta(null, null, true);
        String[] stepNames = transMeta.getStepNames();
        for (int j = 0; j < stepNames.length; j++) {
          if (stepNames[j].equalsIgnoreCase(source.getAttribute("label")))
            hopinf.setFromStep(transMeta.getStep(j));
          if (stepNames[j].equalsIgnoreCase(target.getAttribute("label")))
            hopinf.setToStep(transMeta.getStep(j));
        }
        transMeta.addTransHop(hopinf);
      }
    }

    JSONObject jsonObject = JSONObject.fromObject(root.getAttribute("transLogTable"));
    TransLogTable transLogTable = transMeta.getTransLogTable();
    transLogTable.setConnectionName(jsonObject.optString("connection"));
    transLogTable.setSchemaName(jsonObject.optString("schema"));
    transLogTable.setTableName(jsonObject.optString("table"));
    transLogTable.setLogSizeLimit(jsonObject.optString("size_limit_lines"));
    transLogTable.setLogInterval(jsonObject.optString("interval"));
    transLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    JSONArray jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = transLogTable.findField(id);
        if (field == null) {
          field = transLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
          field.setSubject(StepMeta.findStep(transMeta.getSteps(), fieldJson.optString("subject")));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("stepLogTable"));
    StepLogTable stepLogTable = transMeta.getStepLogTable();
    stepLogTable.setConnectionName(jsonObject.optString("connection"));
    stepLogTable.setSchemaName(jsonObject.optString("schema"));
    stepLogTable.setTableName(jsonObject.optString("table"));
    stepLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = stepLogTable.findField(id);
        if (field == null && i < stepLogTable.getFields().size()) {
          field = stepLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("performanceLogTable"));
    PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
    performanceLogTable.setConnectionName(jsonObject.optString("connection"));
    performanceLogTable.setSchemaName(jsonObject.optString("schema"));
    performanceLogTable.setTableName(jsonObject.optString("table"));
    performanceLogTable.setLogInterval(jsonObject.optString("interval"));
    performanceLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = performanceLogTable.findField(id);
        if (field == null && i < performanceLogTable.getFields().size()) {
          field = performanceLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("metricsLogTable"));
    MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
    metricsLogTable.setConnectionName(jsonObject.optString("connection"));
    metricsLogTable.setSchemaName(jsonObject.optString("schema"));
    metricsLogTable.setTableName(jsonObject.optString("table"));
    metricsLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = metricsLogTable.findField(id);
        if (field == null && i < metricsLogTable.getFields().size()) {
          field = metricsLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonArray = JSONArray.fromObject(root.getAttribute("partitionschemas"));
    for (int i = 0; i < jsonArray.size(); i++) {
      jsonObject = jsonArray.getJSONObject(i);
      PartitionSchema partitionSchema = decodePartitionSchema(jsonObject);
      PartitionSchema check = transMeta.findPartitionSchema(partitionSchema.getName());
      if (check != null) {
        if (!check.isShared()) {
          transMeta.addOrReplacePartitionSchema(partitionSchema);
        }
      } else {
        transMeta.getPartitionSchemas().add(partitionSchema);
      }
    }

    decodeSlaveServers(root, transMeta);

    jsonArray = JSONArray.fromObject(root.getAttribute("clusterSchemas"));
    for (int i = 0; i < jsonArray.size(); i++) {
      jsonObject = jsonArray.getJSONObject(i);
      ClusterSchema clusterSchema = decodeClusterSchema(jsonObject, transMeta.getSlaveServers());
      clusterSchema.shareVariablesWith(transMeta);

      ClusterSchema check = transMeta.findClusterSchema(clusterSchema.getName());
      if (check != null) {
        if (!check.isShared()) {
          transMeta.addOrReplaceClusterSchema(clusterSchema);
        }
      } else {
        transMeta.getClusterSchemas().add(clusterSchema);
      }
    }

    for (int i = 0; i < transMeta.nrSteps(); i++) {
      transMeta.getStep(i).setClusterSchemaAfterLoading(transMeta.getClusterSchemas());
    }

    transMeta.setSizeRowset(Const.toInt(root.getAttribute("size_rowset"), Const.ROWS_IN_ROWSET));
    transMeta.setSleepTimeEmpty(
        Const.toInt(root.getAttribute("sleep_time_empty"), Const.TIMEOUT_GET_MILLIS));
    transMeta.setSleepTimeFull(
        Const.toInt(root.getAttribute("sleep_time_full"), Const.TIMEOUT_PUT_MILLIS));
    transMeta.setUsingUniqueConnections(
        "Y".equalsIgnoreCase(root.getAttribute("unique_connections")));

    transMeta.setFeedbackShown(!"N".equalsIgnoreCase(root.getAttribute("feedback_shown")));
    transMeta.setFeedbackSize(Const.toInt(root.getAttribute("feedback_size"), Const.ROWS_UPDATE));
    transMeta.setUsingThreadPriorityManagment(
        !"N".equalsIgnoreCase(root.getAttribute("using_thread_priorities")));

    transMeta.setCapturingStepPerformanceSnapShots(
        "Y".equalsIgnoreCase(root.getAttribute("capture_step_performance")));
    transMeta.setStepPerformanceCapturingDelay(
        Const.toLong(root.getAttribute("step_performance_capturing_delay"), 1000));
    transMeta.setStepPerformanceCapturingSizeLimit(
        root.getAttribute("step_performance_capturing_size_limit"));

    transMeta.setKey(XMLHandler.stringToBinary(root.getAttribute("key_for_session_key")));
    transMeta.setPrivateKey("Y".equals(root.getAttribute("is_key_private")));

    return transMeta;
  }
Exemplo n.º 14
0
  /**
   * Called when the user makes a selection change in the graph. Used to forward this event to the
   * {@link InfoPane} and to other {@link SelectionChangeListener}s.
   *
   * @param model the selection model
   * @param added the cells <b>removed</b> from selection (careful, inverted)
   * @param removed the cells <b>added</b> to selection (careful, inverted)
   */
  private void userChangedSelection(
      mxGraphSelectionModel mxGSmodel,
      Collection<Object> added,
      Collection<Object> removed) { // Seems to be inverted
    if (!doFireSelectionChangeEvent) return;
    Collection<Spot> spotsToAdd = new ArrayList<Spot>();
    Collection<Spot> spotsToRemove = new ArrayList<Spot>();
    Collection<DefaultWeightedEdge> edgesToAdd = new ArrayList<DefaultWeightedEdge>();
    Collection<DefaultWeightedEdge> edgesToRemove = new ArrayList<DefaultWeightedEdge>();

    if (null != added) {
      for (Object obj : added) {
        mxCell cell = (mxCell) obj;

        if (cell.getChildCount() > 0) {

          for (int i = 0; i < cell.getChildCount(); i++) {
            mxICell child = cell.getChildAt(i);
            if (child.isVertex()) {
              Spot spot = graph.getSpotFor(child);
              spotsToRemove.add(spot);
            } else {
              DefaultWeightedEdge edge = graph.getEdgeFor(child);
              edgesToRemove.add(edge);
            }
          }

        } else {

          if (cell.isVertex()) {
            Spot spot = graph.getSpotFor(cell);
            spotsToRemove.add(spot);
          } else {
            DefaultWeightedEdge edge = graph.getEdgeFor(cell);
            edgesToRemove.add(edge);
          }
        }
      }
    }

    if (null != removed) {
      for (Object obj : removed) {
        mxCell cell = (mxCell) obj;

        if (cell.getChildCount() > 0) {

          for (int i = 0; i < cell.getChildCount(); i++) {
            mxICell child = cell.getChildAt(i);
            if (child.isVertex()) {
              Spot spot = graph.getSpotFor(child);
              spotsToAdd.add(spot);
            } else {
              DefaultWeightedEdge edge = graph.getEdgeFor(child);
              edgesToAdd.add(edge);
            }
          }

        } else {

          if (cell.isVertex()) {
            Spot spot = graph.getSpotFor(cell);
            spotsToAdd.add(spot);
          } else {
            DefaultWeightedEdge edge = graph.getEdgeFor(cell);
            edgesToAdd.add(edge);
          }
        }
      }
    }
    if (DEBUG_SELECTION)
      System.out.println("[TrackScheme] userChangeSelection: sending selection change to model.");
    doFireSelectionChangeEvent = false;
    if (!edgesToAdd.isEmpty()) selectionModel.addEdgeToSelection(edgesToAdd);
    if (!spotsToAdd.isEmpty()) selectionModel.addSpotToSelection(spotsToAdd);
    if (!edgesToRemove.isEmpty()) selectionModel.removeEdgeFromSelection(edgesToRemove);
    if (!spotsToRemove.isEmpty()) selectionModel.removeSpotFromSelection(spotsToRemove);
    doFireSelectionChangeEvent = true;
  }
  private void next(mxCell cell, List<String> task) {
    if (cell == null
        || StringUtils.equals(cell.getAttribute(ActivityGraphConverter.GRAPH_TYPE), "UserTask")) {

      return;
    }
    int count = cell.getEdgeCount();
    for (int i = 0; i < count; i++) {
      mxCell edge = (mxCell) cell.getEdgeAt(i);
      mxCell source = (mxCell) edge.getSource();
      mxCell target = (mxCell) edge.getTarget();
      mxCell next = null;
      if (target != null && target.getId().equals(cell.getId())) {
        continue;
      }
      if (target == null) {

        return;
      }
      if (StringUtils.equals(target.getAttribute(ActivityGraphConverter.GRAPH_TYPE), "UserTask")) {
        next(target, task);
      }
      task.add(ActivityGraphConverter.EDITOR_SHAPE_ID_PREFIX + target.getId());
    }
  }
Exemplo n.º 16
0
  /**
   * This method is called when the user has created manually an edge in the graph, by dragging a
   * link between two spot cells. It checks whether the matching edge in the model exists, and tune
   * what should be done accordingly.
   *
   * @param cell the mxCell of the edge that has been manually created.
   */
  protected void addEdgeManually(mxCell cell) {
    if (cell.isEdge()) {
      final mxIGraphModel graphModel = graph.getModel();
      cell.setValue("New");
      model.beginUpdate();
      graphModel.beginUpdate();
      try {

        Spot source = graph.getSpotFor(cell.getSource());
        Spot target = graph.getSpotFor(cell.getTarget());

        if (DEBUG) {
          System.out.println(
              "[TrackScheme] #addEdgeManually: edge is between 2 spots belonging to the same frame. Removing it.");
          System.out.println(
              "[TrackScheme] #addEdgeManually: adding edge between source "
                  + source
                  + " at frame "
                  + source.getFeature(Spot.FRAME).intValue()
                  + " and target "
                  + target
                  + " at frame "
                  + target.getFeature(Spot.FRAME).intValue());
        }

        if (Spot.frameComparator.compare(source, target) == 0) {
          // Prevent adding edges between spots that belong to the same frame

          if (DEBUG) {
            System.out.println(
                "[TrackScheme] addEdgeManually: edge is between 2 spots belonging to the same frame. Removing it.");
          }
          graph.removeCells(new Object[] {cell});

        } else {
          // We can add it to the model

          // Put them right in order: since we use a oriented graph,
          // we want the source spot to precede in time.
          if (Spot.frameComparator.compare(source, target) > 0) {

            if (DEBUG) {
              System.out.println(
                  "[TrackScheme] #addEdgeManually: Source "
                      + source
                      + " succeed target "
                      + target
                      + ". Inverting edge direction.");
            }

            Spot tmp = source;
            source = target;
            target = tmp;
          }
          // We add a new jGraphT edge to the underlying model, if it does not exist yet.
          DefaultWeightedEdge edge = model.getTrackModel().getEdge(source, target);
          if (null == edge) {
            edge = model.addEdge(source, target, -1);
            if (DEBUG) {
              System.out.println(
                  "[TrackScheme] #addEdgeManually: Creating new edge: " + edge + ".");
            }
          } else {
            // Ah. There was an existing edge in the model we were trying to re-add there, from the
            // graph.
            // We remove the graph edge we have added,
            if (DEBUG) {
              System.out.println("[TrackScheme] #addEdgeManually: Edge pre-existed. Retrieve it.");
            }
            graph.removeCells(new Object[] {cell});
            // And re-create a graph edge from the model edge.
            cell = graph.addJGraphTEdge(edge);
            cell.setValue(String.format("%.1f", model.getTrackModel().getEdgeWeight(edge)));
            // We also need now to check if the edge belonged to a visible track. If not,
            // we make it visible.
            int ID = model.getTrackModel().trackIDOf(edge);
            // This will work, because track indices will be reprocessed only after the
            // graphModel.endUpdate()
            // reaches 0. So now, it's like we are dealing with the track indices priori to
            // modification.
            if (model.getTrackModel().isVisible(ID)) {
              if (DEBUG) {
                System.out.println(
                    "[TrackScheme] #addEdgeManually: Track was visible. Do nothing.");
              }
            } else {
              if (DEBUG) {
                System.out.println(
                    "[TrackScheme] #addEdgeManually: Track was invisible. Make it visible.");
              }
              importTrack(ID);
            }
          }
          graph.mapEdgeToCell(edge, cell);
        }

      } finally {
        graphModel.endUpdate();
        model.endUpdate();
        selectionModel.clearEdgeSelection();
      }
    }
  }
Exemplo n.º 17
0
  /**
   * Create links between all the spots currently in the {@link Model} selection. We update
   * simultaneously the {@link Model} and the {@link JGraphXAdapter}.
   */
  public void linkSpots() {

    // Sort spots by time
    TreeMap<Integer, Spot> spotsInTime = new TreeMap<Integer, Spot>();
    for (Spot spot : selectionModel.getSpotSelection()) {
      spotsInTime.put(spot.getFeature(Spot.FRAME).intValue(), spot);
    }

    // Find adequate column
    int targetColumn = getUnlaidSpotColumn();

    // Then link them in this order
    model.beginUpdate();
    graph.getModel().beginUpdate();
    try {
      Iterator<Integer> it = spotsInTime.keySet().iterator();
      Integer previousTime = it.next();
      Spot previousSpot = spotsInTime.get(previousTime);
      // If this spot belong to an invisible track, we make it visible
      Integer ID = model.getTrackModel().trackIDOf(previousSpot);
      if (ID != null && !model.getTrackModel().isVisible(ID)) {
        importTrack(ID);
      }

      while (it.hasNext()) {
        Integer currentTime = it.next();
        Spot currentSpot = spotsInTime.get(currentTime);
        // If this spot belong to an invisible track, we make it visible
        ID = model.getTrackModel().trackIDOf(currentSpot);
        if (ID != null && !model.getTrackModel().isVisible(ID)) {
          importTrack(ID);
        }
        // Check that the cells matching the 2 spots exist in the graph
        mxICell currentCell = graph.getCellFor(currentSpot);
        if (null == currentCell) {
          currentCell = insertSpotInGraph(currentSpot, targetColumn);
          if (DEBUG) {
            System.out.println(
                "[TrackScheme] linkSpots: creating cell "
                    + currentCell
                    + " for spot "
                    + currentSpot);
          }
        }
        mxICell previousCell = graph.getCellFor(previousSpot);
        if (null == previousCell) {
          int frame = previousSpot.getFeature(Spot.FRAME).intValue();
          int column = Math.max(targetColumn, getNextFreeColumn(frame));
          rowLengths.put(frame, column);
          previousCell = insertSpotInGraph(previousSpot, column);
          if (DEBUG) {
            System.out.println(
                "[TrackScheme] linkSpots: creating cell "
                    + previousCell
                    + " for spot "
                    + previousSpot);
          }
        }
        // Check if the model does not have already a edge for these 2 spots (that is
        // the case if the 2 spot are in an invisible track, which track scheme does not
        // know of).
        DefaultWeightedEdge edge = model.getTrackModel().getEdge(previousSpot, currentSpot);
        if (null == edge) {
          // We create a new edge between 2 spots, and pair it with a new cell edge.
          edge = model.addEdge(previousSpot, currentSpot, -1);
          mxCell cell = (mxCell) graph.addJGraphTEdge(edge);
          cell.setValue("New");
        } else {
          // We retrieve the edge, and pair it with a new cell edge.
          mxCell cell = (mxCell) graph.addJGraphTEdge(edge);
          cell.setValue(String.format("%.1f", model.getTrackModel().getEdgeWeight(edge)));
          // Also, if the existing edge belonged to an existing invisible track, we make it visible.
          ID = model.getTrackModel().trackIDOf(edge);
          if (ID != null && !model.getTrackModel().isVisible(ID)) {
            importTrack(ID);
          }
        }
        previousSpot = currentSpot;
      }
    } finally {
      graph.getModel().endUpdate();
      model.endUpdate();
    }
  }
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    System.out.println("ktos mnie zawolal: " + event);
    tabbedPane.removeAll();

    if (event.getNewValue() instanceof XmlDocument) {
      final XmlDocument xmlDocument = (XmlDocument) event.getNewValue();

      JPanel generalPanel = new JPanel();

      GridBagLayout gridBagLayout = new GridBagLayout();
      generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
      generalPanel.setLayout(gridBagLayout);

      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.anchor = GridBagConstraints.LINE_START;
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Root element name: "), c);

      final JTextField rootElementName =
          new JTextField(
              xmlDocument.getRootElement() != null ? xmlDocument.getRootElement().getName() : "");
      rootElementName.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.getRootElement().setName(rootElementName.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(rootElementName, c);

      c.gridx = 0;
      c.gridy = 1;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Encoding: "), c);

      final JTextField encoding =
          new JTextField(xmlDocument.getEncoding() != null ? xmlDocument.getEncoding() : "");
      encoding.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.setEncoding(encoding.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 1;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(encoding, c);

      c.gridx = 0;
      c.gridy = 2;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Version: "), c);

      final JTextField version =
          new JTextField(xmlDocument.getVersion() != null ? xmlDocument.getVersion() : "");
      version.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.setVersion(version.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 2;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(version, c);

      c.gridx = 0;
      c.gridy = 3;
      c.gridwidth = 1;
      c.weighty = 1;
      generalPanel.add(new JPanel(), c);

      tabbedPane.addTab("General", null, generalPanel, "General options");

    } else if (event.getNewValue() instanceof XmlTag) {
      final XmlTag xmlTag = (XmlTag) event.getNewValue();
      JPanel generalPanel = new JPanel();

      GridBagLayout gridBagLayout = new GridBagLayout();
      generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
      generalPanel.setLayout(gridBagLayout);

      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.anchor = GridBagConstraints.LINE_START;
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Tag name: "), c);

      final JTextField tagName = new JTextField(xmlTag.getName());
      tagName.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlTag.setName(tagName.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(tagName, c);

      c.gridx = 0;
      c.gridy = 1;
      c.gridwidth = 2;
      c.weighty = 1;
      generalPanel.add(new JPanel(), c);

      tabbedPane.addTab("General", null, generalPanel, "General options");

      AttributesModel attributesModel = new AttributesModel(xmlTag);

      JTable attributesTable = new JTable(attributesModel);
      TableColumn columnName = attributesTable.getColumn("Name");
      columnName.setWidth(140);
      TableColumn columnValue = attributesTable.getColumn("Value");
      columnValue.setWidth(140);
      JPanel attrPanel = new JPanel(new BorderLayout());
      attrPanel.add(attributesTable.getTableHeader(), BorderLayout.PAGE_START);
      JScrollPane scrollPane = new JScrollPane(attributesTable);
      attrPanel.add(scrollPane, BorderLayout.CENTER);

      Schema schema = xmlTag.getSchema();
      String path = xmlTag.getPath();

      AvailableAttributesFinder aaf = new AvailableAttributesFinder(schema.getContent());
      Map<String, Boolean> availableAttributes = aaf.getAvailableAttributesForNode(path);

      attributesTable.addMouseListener(
          new AttributeTableClickListener(
              attributesTable, true, xmlTag.getSchemaType(), availableAttributes));
      scrollPane.addMouseListener(
          new AttributeTableClickListener(
              attributesTable, false, xmlTag.getSchemaType(), availableAttributes));

      tabbedPane.addTab("Attributes", null, attrPanel, "Attributes of this element");
      String text = ((XmlTag) event.getNewValue()).toString(0);

      JPanel textPanel = new JPanel();
      textPanel.setLayout(new GridLayout(0, 1));
      JTextArea textArea = new JTextArea(text);
      textArea.setEditable(false);
      textPanel.add(textArea);

      tabbedPane.addTab("Text", null, textPanel, "The text in the element");
    } else if (event.getNewValue() instanceof mxCell && ((mxCell) event.getNewValue()).isEdge()) {
      mxCell cell = (mxCell) event.getNewValue();
      mxICell source = cell.getSource();
      mxICell target = cell.getTarget();
      if (source != null
          && target != null
          && source.getParent() != null
          && target.getParent() != null) {
        XmlTag sourceTag = (XmlTag) source.getParent().getValue();
        XmlTag targetTag = (XmlTag) target.getParent().getValue();

        System.out.println(sourceTag + " -> " + targetTag);

        JPanel generalPanel = new JPanel();

        GridBagLayout gridBagLayout = new GridBagLayout();
        generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
        generalPanel.setLayout(gridBagLayout);

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.LINE_START;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(new JLabel("Source tag name: "), c);

        final JTextField sourceTagName =
            new JTextField(sourceTag.getName() != null ? sourceTag.getName() : "");
        sourceTagName.setEditable(false);

        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(sourceTagName, c);

        c.gridx = 0;
        c.gridy = 1;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(new JLabel("Target tag name: "), c);

        final JTextField targetTagName =
            new JTextField(targetTag.getName() != null ? targetTag.getName() : "");
        targetTagName.setEditable(false);

        c.gridx = 1;
        c.gridy = 1;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(targetTagName, c);

        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 1;
        c.weighty = 1;
        generalPanel.add(new JPanel(), c);

        tabbedPane.addTab("General", null, generalPanel, "General options");
      }
    }
  }
  private void getPreNextTask(mxCell cell, List<String> task, boolean next) {
    if (cell == null || cell.isEdge()) return;
    int count = cell.getEdgeCount();
    for (int i = 0; i < count; i++) {
      mxCell edge = (mxCell) cell.getEdgeAt(i);
      mxCell source = (mxCell) edge.getSource();
      mxCell target = (mxCell) edge.getTarget();
      mxCell preNext = null;
      if (next) {
        if (target != null && target.getId().equals(cell.getId())) {
          continue;
        }
        preNext = target;
      } else {
        if (source != null && source.getId().equals(cell.getId())) {
          mxCell sourceParent = (mxCell) source.getParent();
          if (!StringUtils.equals(
              sourceParent.getAttribute(ActivityGraphConverter.GRAPH_TYPE),
              ActivityGraphConverter.GRAPH_SUBPROCESS)) {
            continue;
          }
        }
        preNext = source;
        mxCell sourceParent = (mxCell) source.getParent();
        if (source != null
            && StringUtils.equals(
                source.getAttribute(ActivityGraphConverter.GRAPH_TYPE), "startEvent")
            && StringUtils.equals(
                sourceParent.getAttribute(ActivityGraphConverter.GRAPH_TYPE),
                ActivityGraphConverter.GRAPH_SUBPROCESS)) {
          preNext = sourceParent;
        }

        if (source == null
            && StringUtils.equals(
                cell.getAttribute(ActivityGraphConverter.GRAPH_TYPE), "startEvent")) {
          preNext = (mxCell) cell.getParent();
        }
      }
      if (preNext == null) return;

      //
      // if(StringUtils.equals(preNext.getAttribute(ActivityGraphConverter.GRAPH_TYPE),ActivityGraphConverter.GRAPH_SUBPROCESS)){
      //                int childCount=cell.getChildCount();
      //                for(int j=0;j<childCount;j++){
      //                    mxCell child=(mxCell)cell.getChildAt(j);
      //                    getPreNextTask(child,task,next);
      //                }
      //            }

      if (StringUtils.equals(
              preNext.getAttribute(ActivityGraphConverter.GRAPH_TYPE),
              ActivityGraphConverter.GRAPH_GATEWAY)
          || StringUtils.equals(
              preNext.getAttribute(ActivityGraphConverter.GRAPH_TYPE),
              ActivityGraphConverter.GRAPH_SUBPROCESS)) {
        getPreNextTask(preNext, task, next);
      } else {
        task.add(ActivityGraphConverter.EDITOR_SHAPE_ID_PREFIX + preNext.getId());
      }
    }
  }
 /**
  * Returns the lower end of the cell (max y-coordinate)
  *
  * @param cell the cell to work with
  * @return the y-coordinate
  */
 private double getCellLowestYPoint(mxCell cell) {
   return cell.getGeometry().getY() + cell.getGeometry().getHeight();
 }