public boolean savePathway() { Pathway pathway = engine.getActivePathway(); boolean result = true; // Overwrite the existing xml file. // If the target file is read-only, let the user select a new pathway if (pathway.getSourceFile() != null && pathway.getSourceFile().canWrite()) { try { engine.savePathway(pathway.getSourceFile()); } catch (ConverterException e) { handleConverterException(e.getMessage(), null, e); } } else { result = savePathwayAs(); } return result; }
/** * Creates the list of interaction partners displayed in the top part of the {@link RegIntTab} * * @param parent The {@link JScrollPane} containing either the regulators or the targets of the * selected element * @param map The map of interaction partners, either regulators or targets, also found in results * @param results The entire {@link ResultsObj}. Must have map as either its regulator or target * map * @param builder The {@link PanelBuilder} that will include this pathway * @return the list of interaction partners (in pathway form for expression visualization) */ private VPathwaySwing createPathway( JScrollPane parent, Map<Xref, Interaction> map, ResultsObj results, PanelBuilder builder) { VPathwaySwing vPathwaySwing = new VPathwaySwing(parent); VPathway vPathway = vPathwaySwing.createVPathway(); vPathway.setEditMode(false); Pathway sourcePw = new Pathway(); Map<Xref, Interaction> sorted = sortXrefs(map); x = 0; for (Xref xref : sorted.keySet()) { PathwayElement pwe = createPathwayELement(xref); sourcePw.add(pwe); JLabel linkout = new JLabel(icon); JPanel linkoutPane = new JPanel(); linkout.addMouseListener(new InfoButtonListener(xref, results, plugin)); linkoutPane.add(linkout); linkoutPane.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkoutPane.setVisible(true); List<File> uniqueFiles = new ArrayList<File>(); for (File intFile : sorted.get(xref).getFiles()) { if (!uniqueFiles.contains(intFile) && RegIntPreferences.getPreferences().getSelectedIntFiles().contains(intFile)) { uniqueFiles.add(intFile); } } builder.addLabel( uniqueFiles.size() + "/" + RegIntPreferences.getPreferences().getSelectedIntFiles().size(), cc.xy(6, y)); builder.add(linkoutPane, cc.xy(4, y)); y = y + 2; x++; } vPathway.fromModel(sourcePw); vPathway.setSelectionEnabled(false); vPathway.addVPathwayListener(plugin.getDesktop().getVisualizationManager()); return vPathwaySwing; }
/** * Call this when the user is about to perform an action that could lead to discarding the current * pathway. (For example when creating a new pathway) * * <p>Checks if there are any unsaved changes, and asks the user if they want to save those * changes. * * @return true if the user allows discarding the pathway, possibly after saving. */ public boolean canDiscardPathway() { Pathway pathway = engine.getActivePathway(); // checking not necessary if there is no pathway or if pathway is not changed. if (pathway == null || !pathway.hasChanged()) return true; int result = JOptionPane.showConfirmDialog( frame, "Save changes?", "Your pathway has changed. Do you want to save?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.CANCEL_OPTION) // cancel { return false; } else if (result == JOptionPane.YES_OPTION) // yes { // return false if save is cancelled. return (savePathway()); } // yes or no return true; }