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; }
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; }
/** * 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; }
@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; }