public ActivityPaletteConfigurationPanel()

in taverna-activity-palette-impl/src/main/java/org/apache/taverna/workbench/ui/activitypalette/ActivityPaletteConfigurationPanel.java [71:174]


	public ActivityPaletteConfigurationPanel(ActivityPaletteConfiguration config) {
		super(new BorderLayout());
		this.config = config;

		model = new DefaultComboBoxModel<>();
		for (String key : config.getInternalPropertyMap().keySet()) {
			if (key.startsWith("taverna.")
					&& config.getPropertyStringList(key) != null) {
				model.addElement(key);
				values.put(key,
						new ArrayList<>(config.getPropertyStringList(key)));
			}
			if (key.startsWith("name.taverna."))
				names.put(key, config.getProperty(key).toString());
		}
		deleteTypeButton = new JButton("Delete");

		final JButton addTypeButton = new JButton("Add");
		final JComboBox<String> comboBox = new JComboBox<>(model);
		comboBox.setRenderer(new DefaultListCellRenderer() {
			@Override
			public Component getListCellRendererComponent(JList<?> list,
					Object value, int index, boolean isSelected,
					boolean cellHasFocus) {
				if (value != null && value instanceof String) {
					String name = names.get("name." + value);
					if (name != null)
						value = name;
				}
				return super.getListCellRendererComponent(list, value, index,
						isSelected, cellHasFocus);
			}
		});

		deleteTypeButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String displayText = names.get("name." + selectedKey);
				if (displayText == null)
					displayText = selectedKey;
				if (confirm("Confirm removal",
						"Are you sure you wish to remove the type "
								+ displayText + "?")) {
					names.remove("name." + selectedKey);
					values.remove(selectedKey);
					model.removeElement(selectedKey);
					comboBox.setSelectedIndex(0);
				}
			}
		});

		addTypeButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String key = input("New key", "Provide the new key.");
				if (key == null)
					return;
				String name = input("Name for the key",
						"Provide the name for the key: " + key);
				if (name == null)
					return;

				values.put(key, new ArrayList<String>());
				names.put("name." + key, name);
				model.addElement(key);
				comboBox.setSelectedItem(key);
			}
		});

		comboBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (comboBox.getSelectedItem() != null
						&& comboBox.getSelectedItem() instanceof String) {
					selectedKey = (String) comboBox.getSelectedItem();
					List<String> selectedList = values.get(selectedKey);
					populateList(selectedList);
					deleteTypeButton.setEnabled(selectedList.size() == 0);
				}
			}
		});

		JPanel propertySelectionPanel = new JPanel(new FlowLayout(LEFT));
		propertySelectionPanel.add(new JLabel("Activity type:"));
		propertySelectionPanel.add(comboBox);
		propertySelectionPanel.add(addTypeButton);
		propertySelectionPanel.add(deleteTypeButton);
		add(propertySelectionPanel, NORTH);

		JPanel listPanel = new JPanel(new BorderLayout());
		listModel = new DefaultListModel<>();
		propertyListItems = new JList<>(listModel);
		propertyListItems.setBorder(new BevelBorder(LOWERED));

		listPanel.add(propertyListItems, CENTER);
		listPanel.add(listButtons(), EAST);

		add(listPanel, CENTER);

		add(applyButtonPanel(), SOUTH);

		if (model.getSize() > 0)
			comboBox.setSelectedItem(model.getElementAt(0));
	}