diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 8480522..9ad3b2a 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -29,6 +29,7 @@ import java.io.*; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Set; public class Editor { @@ -281,8 +282,7 @@ // Geometry output.append("geometry {\n"); - mxCell root = (mxCell) graph.getDefaultParent(); - buildGeometryOutput(output, root); + buildGeometryOutput(output, (mxCell) graph.getDefaultParent()); output.append("}\n"); return output.toString(); @@ -308,26 +308,30 @@ } // Search resource path matches to the identifier. If it exists, then build output string. - ResourcePath path = searchForResourcePath(identifier, model.getDataFlowGraph().getRootResourceNodes()); - if (path != null) { - output.append("\tnode r ").append(identifier).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); + String resourceUri = getResourceUri(identifier, model.getDataFlowGraph().getRootResourceNodes()); + if (resourceUri != null) { + output.append("\tnode r ").append(resourceUri).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); } // Search channel matches to the identifier. If it exists, then build output string for (Channel channel : model.getChannels()) { - if (channel instanceof FormulaChannel && identifier.equals(channel.getChannelName())) { - output.append("\tnode fc ").append(state.getLabel()).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); - } else if (channel != null && state.getLabel().equals(channel.getChannelName())) { - output.append("\tnode c ").append(state.getLabel()).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); + if (channel == null || !Objects.equals(channel.getChannelName(), identifier)) { + continue; } + if (channel instanceof FormulaChannel) { + output.append("\tnode fc "); + } else { + output.append("\tnode c "); + } + output.append(channel.getChannelName()).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); } - // Search IO channel matches to the identifier. If it exists, then build output string - for (Channel ioChannel : model.getInputChannels()) { - if (ioChannel != null && identifier.equals(ioChannel.getChannelName())) { - String channelName = state.getLabel(); - output.append("\tnode ioc ").append(channelName).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); + // Search input channel matches to the identifier. If it exists, then build output string + for (Channel channel : model.getInputChannels()) { + if (channel == null || !Objects.equals(channel.getChannelName(), identifier)) { + continue; } + output.append("\tnode ioc ").append(channel.getChannelName()).append(":").append(x).append(",").append(y).append(",").append(w).append(",").append(h).append("\n"); } // Recursive @@ -335,17 +339,41 @@ } } - private ResourcePath searchForResourcePath(final String identifier, final Set nodes) { + /** + * Search a resource node in provided nodes and their children whose uri matches to provided identifier + * + * @param identifier Target resource identifier + * @param nodes Root resource nodes + * @return The channel if its url matches to provided identifier, otherwise null + */ + private String getResourceUri(final String identifier, final Set nodes) { for (ResourceNode node : nodes) { ResourcePath path = node.getPrimaryResourcePath(); - if (path != null && identifier.equals(path.getName())) { - return path; + if (Objects.equals(path.toString(), identifier)) { + return path.toString(); } - return searchForResourcePath(identifier, node.getChildren()); + return getResourceUri(identifier, node.getChildren()); } return null; } +// /** +// * Search a channel whose name matches to provided identifier +// * +// * @param identifier Target channel identifier +// * @param channels All channels +// * @return The channel if its name matches to provided identifier, otherwise null +// */ +// private Channel searchForChannel(final String identifier, final Collection channels) { +// for (Channel channel : channels) { +// if (Objects.equals(channel.getChannelName(), identifier)) { +// return channel; +// } +// return searchForChannel(identifier, channel.getChildren()); +// } +// return null; +// } + public void delete() { boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) {