use of org.openlca.app.editors.graphical.model.Link in project olca-app by GreenDelta.
the class GraphEditor method createNecessaryLinks.
public void createNecessaryLinks(ProcessNode node) {
MutableProcessLinkSearchMap linkSearch = node.parent().linkSearch;
ProductSystemNode sysNode = node.parent();
long id = node.process.id;
for (ProcessLink pLink : linkSearch.getLinks(id)) {
boolean isProvider = pLink.providerId == id;
long otherID = isProvider ? pLink.processId : pLink.providerId;
ProcessNode otherNode = model.getProcessNode(otherID);
if (otherNode == null)
continue;
ProcessNode outNode = null;
ProcessNode inNode = null;
FlowType type = sysNode.flows.type(pLink.flowId);
if (type == FlowType.PRODUCT_FLOW) {
outNode = isProvider ? node : otherNode;
inNode = isProvider ? otherNode : node;
} else if (type == FlowType.WASTE_FLOW) {
outNode = isProvider ? otherNode : node;
inNode = isProvider ? node : otherNode;
}
if (outNode == null)
continue;
if (!outNode.isExpandedRight() && !inNode.isExpandedLeft())
continue;
Link link = new Link();
link.outputNode = outNode;
link.inputNode = inNode;
link.processLink = pLink;
link.link();
}
}
use of org.openlca.app.editors.graphical.model.Link in project olca-app by GreenDelta.
the class ReconnectLinkCommand method execute.
@Override
public void execute() {
ProductSystemNode systemNode = sourceNode.parent();
oldLink.unlink();
systemNode.getProductSystem().processLinks.remove(oldLink.processLink);
systemNode.linkSearch.remove(oldLink.processLink);
var processLink = new ProcessLink();
processLink.providerId = sourceNode.process.id;
processLink.setProviderType(sourceNode.process.type);
processLink.flowId = oldLink.processLink.flowId;
processLink.processId = targetNode.parent().process.id;
processLink.exchangeId = targetNode.exchange.id;
systemNode.getProductSystem().processLinks.add(processLink);
systemNode.linkSearch.put(processLink);
link = new Link();
link.outputNode = sourceNode;
link.inputNode = targetNode.parent();
link.processLink = processLink;
link.link();
systemNode.editor.setDirty();
}
use of org.openlca.app.editors.graphical.model.Link in project olca-app by GreenDelta.
the class DeleteLinkCommand method undo.
@Override
public void undo() {
if (links.isEmpty())
return;
ProductSystemNode sysNode = links.get(0).outputNode.parent();
for (Link link : links) {
sysNode.getProductSystem().processLinks.add(link.processLink);
sysNode.linkSearch.put(link.processLink);
link.link();
link.updateVisibility();
}
sysNode.editor.setDirty();
}
use of org.openlca.app.editors.graphical.model.Link in project olca-app by GreenDelta.
the class HideShowCommand method execute.
@Override
public void execute() {
ProcessNode node = model.getProcessNode(process.id);
if (type == SHOW && node == null) {
node = new ProcessNode(model.editor, process);
model.add(node);
model.editor.createNecessaryLinks(node);
}
node.setVisible(type == SHOW);
for (Link link : node.links) {
link.updateVisibility();
}
node.layout();
node.parent().editor.setDirty();
}
use of org.openlca.app.editors.graphical.model.Link in project olca-app by GreenDelta.
the class RemoveAllConnectionsAction method run.
@Override
public void run() {
if (processNodes.size() == 0)
return;
ProductSystemNode systemNode = editor.getModel();
List<Link> links = new ArrayList<>();
// create new link search to avoid problems with missing entries before
// ConnectionLink.unlink is called
List<ProcessLink> pLinks = systemNode.getProductSystem().processLinks;
MutableProcessLinkSearchMap linkSearch = new MutableProcessLinkSearchMap(pLinks);
for (ProcessNode processNode : processNodes) {
List<ProcessLink> processLinks = linkSearch.getLinks(processNode.process.id);
for (ProcessLink link : processLinks) linkSearch.remove(link);
for (Link link : processNode.links) if (!links.contains(link))
links.add(link);
}
Command command = new DeleteLinkCommand(links);
editor.getCommandStack().execute(command);
}
Aggregations