private JButton addLocationButton()

in taverna-external-tool-activity-ui/src/main/java/org/apache/taverna/activities/externaltool/manager/ToolInvocationConfigurationPanel.java [234:303]


	private JButton addLocationButton() {
		final JButton result = new DeselectingButton("Add", new AbstractAction() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (isShowingGroups()) {
					Set<String> usedGroupNames = new HashSet<String>();
					for (InvocationGroup g : manager.getInvocationGroups()) {
						usedGroupNames.add(g.getName());
					}

					GroupPanel inputPanel = new GroupPanel(mechanismListModel.toArray(), manager);

					ValidatingUserInputDialog vuid = new ValidatingUserInputDialog(
							"Add symbolic location", inputPanel);
					vuid.addTextComponentValidation(inputPanel.getGroupNameField(),
							"Set the symbolic location name.", usedGroupNames,
							"Duplicate symbolic location name.", "[\\p{L}\\p{Digit}_.]+",
							"Invalid symbolic location name.");
					vuid.setSize(new Dimension(400, 250));

					if (vuid.show(ToolInvocationConfigurationPanel.this)) {
						String groupName = inputPanel.getGroupName();
						InvocationGroup newGroup = new InvocationGroup(mechanismCreators);
						newGroup.setName(groupName);
						newGroup.setMechanism(inputPanel.getSelectedMechanism());
						manager.addInvocationGroup(newGroup);
						locationList.setSelectedValue(newGroup, true);
					}
				} else {
					Set<String> usedNames = new HashSet<String>();
					for (InvocationMechanism m : manager.getMechanisms()) {
						usedNames.add(m.getName());
					}

					MechanismPanel inputPanel = new MechanismPanel(invocationMechanismEditors);

					ValidatingUserInputDialog vuid = new ValidatingUserInputDialog(
							"Add explicit location", inputPanel);
					vuid.addTextComponentValidation(inputPanel.getMechanismNameField(),
							"Set the explicit location name.", usedNames,
							"Duplicate explicit location name.", "[\\p{L}\\p{Digit}_.]+",
							"Invalid explicit location name.");
					vuid.addMessageComponent(inputPanel.getMechanismTypeSelector(),
							"Set the location name and type.");
					vuid.setSize(new Dimension(400, 250));

					if (vuid.show(ToolInvocationConfigurationPanel.this)) {
						String mechanismName = inputPanel.getMechanismName();
						String mechanismTypeName = inputPanel.getMechanismTypeName();
						InvocationMechanismEditor ime = findEditor(mechanismTypeName);
						InvocationMechanism newMechanism = ime.createMechanism(mechanismName);
						manager.addMechanism(newMechanism);
						ime.show(newMechanism);
						ime.setPreferredSize(new Dimension(550, 500));
						int answer = JOptionPane.showConfirmDialog(
								ToolInvocationConfigurationPanel.this, ime,
								"New explicit location", JOptionPane.OK_CANCEL_OPTION,
								JOptionPane.PLAIN_MESSAGE, null);
						if (answer == JOptionPane.OK_OPTION) {
							ime.updateInvocationMechanism();
							manager.mechanismChanged(newMechanism);
						}
						locationList.setSelectedValue(newMechanism, true);
					}
				}
			}
		});
		return result;
	}