public void actionPerformed()

in taverna-results-view/src/main/java/org/apache/taverna/workbench/views/results/ReportView.java [264:414]


		public void actionPerformed(ActionEvent e) {
			final JDialog dialog = new HelpEnabledDialog(getMainWindow(), TITLE, true);
			dialog.setResizable(false);
			dialog.setLocationRelativeTo(getMainWindow());
			JPanel panel = new JPanel(new BorderLayout());
			DialogTextArea explanation = new DialogTextArea();
			explanation.setText("Select the input and output ports to save the associated data");
			explanation.setColumns(40);
			explanation.setEditable(false);
			explanation.setOpaque(false);
			explanation.setBorder(new EmptyBorder(5, 20, 5, 20));
			explanation.setFocusable(false);
			explanation.setFont(new JLabel().getFont()); // make the font the same as for other
															// components in the dialog
			panel.add(explanation, NORTH);
			final Map<String, JCheckBox> inputChecks = new HashMap<>();
			final Map<String, JCheckBox> outputChecks = new HashMap<>();
			final Map<JCheckBox, Path> checkReferences = new HashMap<>();
			final Map<String, Path> chosenReferences = new HashMap<>();
			final Set<Action> actionSet = new HashSet<>();

			ItemListener listener = new ItemListener() {
				@Override
				public void itemStateChanged(ItemEvent e) {
					JCheckBox source = (JCheckBox) e.getItemSelectable();
					if (inputChecks.containsValue(source)
							&& source.isSelected()
							&& outputChecks.containsKey(source.getText()))
						outputChecks.get(source.getText()).setSelected(false);
					if (outputChecks.containsValue(source)
							&& source.isSelected()
							&& inputChecks.containsKey(source.getText()))
						inputChecks.get(source.getText()).setSelected(false);
					chosenReferences.clear();
					for (JCheckBox checkBox : checkReferences.keySet())
						if (checkBox.isSelected())
							chosenReferences.put(checkBox.getText(),
									checkReferences.get(checkBox));
				}
			};

			SortedMap<String, Path> inputPorts = selectedInvocation.getInputs();
			SortedMap<String, Path> outputPorts = selectedInvocation.getOutputs();

			JPanel portsPanel = new JPanel();
			portsPanel.setLayout(new GridBagLayout());
			if (!inputPorts.isEmpty()) {
				GridBagConstraints gbc = new GridBagConstraints();
				gbc.gridx = 0;
				gbc.gridy = 0;
				gbc.anchor = WEST;
				gbc.fill = NONE;
				gbc.weightx = 0.0;
				gbc.weighty = 0.0;
				gbc.insets = new Insets(5, 10, 5, 10);
				portsPanel.add(new JLabel("Workflow inputs:"), gbc);

				TreeMap<String, JCheckBox> sortedBoxes = new TreeMap<>();
				for (Entry<String, Path> entry : inputPorts.entrySet()) {
					String portName = entry.getKey();
					Path value = entry.getValue();
					if (value != null) {
						JCheckBox checkBox = new JCheckBox(portName);
						checkBox.setSelected(!outputPorts.containsKey(portName));
						checkBox.addItemListener(listener);
						inputChecks.put(portName, checkBox);
						sortedBoxes.put(portName, checkBox);
						checkReferences.put(checkBox, value);
					}
				}
				gbc.insets = new Insets(0, 10, 0, 10);
				for (String portName : sortedBoxes.keySet()) {
					gbc.gridy++;
					portsPanel.add(sortedBoxes.get(portName), gbc);
				}
				gbc.gridy++;
				gbc.fill = BOTH;
				gbc.weightx = 1.0;
				gbc.weighty = 1.0;
				gbc.insets = new Insets(5, 10, 5, 10);
				portsPanel.add(new JLabel(""), gbc); // empty space
			}
			if (!outputPorts.isEmpty()) {
				GridBagConstraints gbc = new GridBagConstraints();
				gbc.gridx = 1;
				gbc.gridy = 0;
				gbc.anchor = WEST;
				gbc.fill = NONE;
				gbc.weightx = 0.0;
				gbc.weighty = 0.0;
				gbc.insets = new Insets(5, 10, 5, 10);
				portsPanel.add(new JLabel("Workflow outputs:"), gbc);
				TreeMap<String, JCheckBox> sortedBoxes = new TreeMap<>();
				for (Entry<String, Path> entry : outputPorts.entrySet()) {
					String portName = entry.getKey();
					Path value = entry.getValue();
					if (value != null) {
						JCheckBox checkBox = new JCheckBox(portName);
						checkBox.setSelected(true);

						checkReferences.put(checkBox, value);
						checkBox.addItemListener(listener);
						outputChecks.put(portName, checkBox);
						sortedBoxes.put(portName, checkBox);
					}
				}
				gbc.insets = new Insets(0, 10, 0, 10);
				for (String portName : sortedBoxes.keySet()) {
					gbc.gridy++;
					portsPanel.add(sortedBoxes.get(portName), gbc);
				}
				gbc.gridy++;
				gbc.fill = BOTH;
				gbc.weightx = 1.0;
				gbc.weighty = 1.0;
				gbc.insets = new Insets(5, 10, 5, 10);
				portsPanel.add(new JLabel(""), gbc); // empty space
			}
			panel.add(portsPanel, CENTER);
			chosenReferences.clear();
			for (JCheckBox checkBox : checkReferences.keySet())
				if (checkBox.isSelected())
					chosenReferences.put(checkBox.getText(), checkReferences.get(checkBox));

			JPanel buttonsBar = new JPanel();
			buttonsBar.setLayout(new FlowLayout());
			// Get all existing 'Save result' actions
			for (SaveAllResultsSPI spi : saveActions) {
				AbstractAction action = spi.getAction();
				actionSet.add(action);
				JButton saveButton = new JButton((AbstractAction) action);
				if (action instanceof SaveAllResultsSPI) {
					((SaveAllResultsSPI) action).setChosenReferences(chosenReferences);
					((SaveAllResultsSPI) action).setParent(dialog);
				}
				buttonsBar.add(saveButton);
			}
			JButton cancelButton = new JButton("Cancel", closeIcon);
			cancelButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					dialog.setVisible(false);
				}
			});
			buttonsBar.add(cancelButton);
			panel.add(buttonsBar, SOUTH);
			panel.revalidate();
			dialog.add(panel);
			dialog.pack();
			dialog.setVisible(true);
		}