You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:35:56 UTC
[41/58] [abbrv] incubator-taverna-plugin-component git commit:
org.apache.taverna.component.ui
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChoiceMessage.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChoiceMessage.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChoiceMessage.java
new file mode 100644
index 0000000..57eb466
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChoiceMessage.java
@@ -0,0 +1,24 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import org.apache.taverna.component.api.profile.Profile;
+
+/**
+ * @author alanrw
+ */
+public class ProfileChoiceMessage {
+ private final Profile chosenProfile;
+
+ public ProfileChoiceMessage(Profile chosenProfile) {
+ this.chosenProfile = chosenProfile;
+ }
+
+ /**
+ * @return the chosenProfile
+ */
+ public Profile getChosenProfile() {
+ return chosenProfile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChooserPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChooserPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChooserPanel.java
new file mode 100644
index 0000000..0e5b928
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/ProfileChooserPanel.java
@@ -0,0 +1,204 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+import static java.awt.event.ItemEvent.SELECTED;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.util.Utils.LONG_STRING;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.api.profile.Profile;
+
+/**
+ * @author alanrw
+ */
+public class ProfileChooserPanel extends JPanel implements
+ Observer<RegistryChoiceMessage>, Observable<ProfileChoiceMessage> {
+ private static final String READING_MSG = "Reading profiles";
+ private static final String PROFILE_LABEL = "Profile:";
+ private static final long serialVersionUID = 2175274929391537032L;
+ private static Logger logger = getLogger(ProfileChooserPanel.class);
+
+ private final List<Observer<ProfileChoiceMessage>> observers = new ArrayList<>();
+ private final JComboBox<String> profileBox = new JComboBox<>();
+ private final SortedMap<String, Profile> profileMap = new TreeMap<>();
+
+ private Registry registry;
+
+ public ProfileChooserPanel(RegistryChooserPanel registryPanel) {
+ this();
+ registryPanel.addObserver(new Observer<RegistryChoiceMessage>() {
+ @Override
+ public void notify(Observable<RegistryChoiceMessage> sender,
+ RegistryChoiceMessage message) throws Exception {
+ try {
+ registry = message.getChosenRegistry();
+ updateProfileModel();
+ } catch (Exception e) {
+ logger.error("failure when notifying about chosen registry", e);
+ }
+ }
+ });
+ }
+
+ public ProfileChooserPanel() {
+ super();
+ profileBox.setPrototypeDisplayValue(LONG_STRING);
+ this.setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.anchor = WEST;
+ gbc.fill = NONE;
+ this.add(new JLabel(PROFILE_LABEL), gbc);
+ gbc.gridx = 1;
+ gbc.weightx = 1;
+ gbc.fill = BOTH;
+ this.add(profileBox, gbc);
+ profileBox.addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent event) {
+ if (event.getStateChange() == SELECTED)
+ setProfile(profileMap.get(profileBox.getSelectedItem()));
+ }
+ });
+
+ profileBox.setEditable(false);
+ }
+
+ @Override
+ public void notify(Observable<RegistryChoiceMessage> sender,
+ RegistryChoiceMessage message) throws Exception {
+ try {
+ registry = message.getChosenRegistry();
+ updateProfileModel();
+ } catch (Exception e) {
+ logger.error("failure when notifying about chosen registry", e);
+ }
+ }
+
+ private void updateProfileModel() {
+ profileMap.clear();
+ profileBox.removeAllItems();
+ profileBox.setToolTipText(null);
+ profileBox.addItem(READING_MSG);
+ profileBox.setEnabled(false);
+ new ProfileUpdater().execute();
+ }
+
+ private void setProfile(Profile componentProfile) {
+ if (componentProfile != null)
+ profileBox.setToolTipText(componentProfile.getDescription());
+ else
+ profileBox.setToolTipText(null);
+
+ Profile chosenProfile = getChosenProfile();
+ ProfileChoiceMessage message = new ProfileChoiceMessage(chosenProfile);
+ for (Observer<ProfileChoiceMessage> o : getObservers())
+ try {
+ o.notify(this, message);
+ } catch (Exception e) {
+ logger.error("failure when notifying about profile choice", e);
+ }
+ }
+
+ public Profile getChosenProfile() {
+ if (profileBox.getSelectedIndex() < 0)
+ return null;
+
+ return profileMap.get(profileBox.getSelectedItem());
+ }
+
+ private class ProfileUpdater extends SwingWorker<String, Object> {
+ @Override
+ protected String doInBackground() throws Exception {
+ if (registry == null)
+ return null;
+ List<Profile> componentProfiles;
+ try {
+ componentProfiles = registry.getComponentProfiles();
+ } catch (ComponentException e) {
+ logger.error("failed to get profiles", e);
+ throw e;
+ } catch (NullPointerException e) {
+ logger.error("failed to get profiles", e);
+ throw e;
+ }
+ for (Profile profile : componentProfiles)
+ try {
+ profileMap.put(profile.getName(), profile);
+ } catch (NullPointerException e) {
+ logger.error("failure getting profile name", e);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void done() {
+ profileBox.removeAllItems();
+ try {
+ get();
+ for (String name : profileMap.keySet())
+ profileBox.addItem(name);
+ if (!profileMap.isEmpty()) {
+ String firstKey = profileMap.firstKey();
+ profileBox.setSelectedItem(firstKey);
+ setProfile(profileMap.get(firstKey));
+ } else
+ profileBox.addItem("No profiles available");
+ } catch (InterruptedException | ExecutionException e) {
+ logger.error(e);
+ profileBox.addItem("Unable to read profiles");
+ }
+ profileBox.setEnabled(!profileMap.isEmpty());
+ }
+ }
+
+ @Override
+ public void addObserver(Observer<ProfileChoiceMessage> observer) {
+ observers.add(observer);
+ ProfileChoiceMessage message = new ProfileChoiceMessage(getChosenProfile());
+ try {
+ observer.notify(this, message);
+ } catch (Exception e) {
+ logger.error("failure when notifying about profile choice", e);
+ }
+ }
+
+ @Override
+ public void removeObserver(Observer<ProfileChoiceMessage> observer) {
+ observers.remove(observer);
+ }
+
+ @Override
+ public List<Observer<ProfileChoiceMessage>> getObservers() {
+ return observers;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserComponentEntryPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserComponentEntryPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserComponentEntryPanel.java
new file mode 100644
index 0000000..7c69a42
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserComponentEntryPanel.java
@@ -0,0 +1,82 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.apache.taverna.component.api.Family;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+
+/**
+ * @author alanrw
+ */
+public class RegistryAndFamilyChooserComponentEntryPanel extends JPanel {
+ private static final long serialVersionUID = -6675545311458594678L;
+ private static final String T2FLOW = ".t2flow";
+ private static final String WFBUNDLE = ".wfbundle";
+
+ private JTextField componentNameField = new JTextField(20);
+ private RegistryAndFamilyChooserPanel registryAndFamilyChooserPanel;
+
+ public RegistryAndFamilyChooserComponentEntryPanel(ComponentPreference prefs) {
+ super(new GridBagLayout());
+ registryAndFamilyChooserPanel = new RegistryAndFamilyChooserPanel(prefs);
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.anchor = GridBagConstraints.WEST;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.gridwidth = 2;
+ gbc.weightx = 1;
+ this.add(registryAndFamilyChooserPanel, gbc);
+ gbc.gridy = 1;
+
+ gbc.gridwidth = 1;
+ gbc.gridx = 0;
+ gbc.weightx = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ this.add(new JLabel("Component name:"), gbc);
+ gbc.gridx = 1;
+ gbc.weightx = 1;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ this.add(componentNameField, gbc);
+ }
+
+ public String getComponentName() {
+ return componentNameField.getText();
+ }
+
+ public void setComponentName(String name) {
+ componentNameField.setText(name);
+ }
+
+ public Version.ID getComponentVersionIdentification() {
+ String componentName = getComponentName();
+ Family familyChoice = registryAndFamilyChooserPanel.getChosenFamily();
+ Registry registry = registryAndFamilyChooserPanel.getChosenRegistry();
+
+ if (familyChoice == null || registry == null || componentName == null
+ || componentName.isEmpty())
+ return null;
+
+ return new Version.Identifier(registry.getRegistryBase(),
+ familyChoice.getName(), trim(componentName), -1);
+ }
+
+ private static String trim(String name) {
+ if (name.endsWith(WFBUNDLE))
+ return name.substring(0, name.length() - WFBUNDLE.length());
+ else if (name.endsWith(T2FLOW))
+ return name.substring(0, name.length() - T2FLOW.length());
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserPanel.java
new file mode 100644
index 0000000..a4a7910
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryAndFamilyChooserPanel.java
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.WEST;
+import static org.apache.log4j.Logger.getLogger;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.util.List;
+
+import javax.swing.JPanel;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.Family;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+
+/**
+ * @author alanrw
+ */
+public class RegistryAndFamilyChooserPanel extends JPanel implements
+ Observer<ProfileChoiceMessage>, Observable<FamilyChoiceMessage> {
+ private static Logger logger = getLogger(RegistryAndFamilyChooserPanel.class);
+ private static final long serialVersionUID = -535518473593617735L;
+ final RegistryChooserPanel registryPanel;
+ final FamilyChooserPanel familyPanel;
+
+ public RegistryAndFamilyChooserPanel(ComponentPreference prefs) {
+ super(new GridBagLayout());
+ registryPanel = new RegistryChooserPanel(prefs);
+ familyPanel = new FamilyChooserPanel(registryPanel);
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.anchor = WEST;
+ gbc.fill = BOTH;
+ gbc.gridwidth = 2;
+ gbc.weightx = 1;
+ add(registryPanel, gbc);
+
+ gbc.gridx = 0;
+ gbc.gridy = 1;
+ gbc.weighty = 1;
+ add(familyPanel, gbc);
+ }
+
+ public Registry getChosenRegistry() {
+ return registryPanel.getChosenRegistry();
+ }
+
+ public Family getChosenFamily() {
+ return familyPanel.getChosenFamily();
+ }
+
+ @Override
+ public void addObserver(Observer<FamilyChoiceMessage> observer) {
+ familyPanel.addObserver(observer);
+ }
+
+ @Override
+ public List<Observer<FamilyChoiceMessage>> getObservers() {
+ return familyPanel.getObservers();
+ }
+
+ @Override
+ public void removeObserver(Observer<FamilyChoiceMessage> observer) {
+ familyPanel.removeObserver(observer);
+ }
+
+ @Override
+ public void notify(Observable<ProfileChoiceMessage> sender,
+ ProfileChoiceMessage message) {
+ try {
+ familyPanel.notify(sender, message);
+ } catch (Exception e) {
+ logger.error("problem handling notification about profile choice",
+ e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChoiceMessage.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChoiceMessage.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChoiceMessage.java
new file mode 100644
index 0000000..7af5969
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChoiceMessage.java
@@ -0,0 +1,24 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import org.apache.taverna.component.api.Registry;
+
+/**
+ * @author alanrw
+ */
+public class RegistryChoiceMessage {
+ private final Registry chosenRegistry;
+
+ public RegistryChoiceMessage(Registry chosenRegistry) {
+ this.chosenRegistry = chosenRegistry;
+ }
+
+ /**
+ * @return the chosenRegistry
+ */
+ public Registry getChosenRegistry() {
+ return chosenRegistry;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChooserPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChooserPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChooserPanel.java
new file mode 100644
index 0000000..6df902f
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/RegistryChooserPanel.java
@@ -0,0 +1,123 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.WEST;
+import static java.awt.event.ItemEvent.SELECTED;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.util.Utils.LONG_STRING;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.Vector;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+
+/**
+ * @author alanrw
+ */
+public class RegistryChooserPanel extends JPanel implements
+ Observable<RegistryChoiceMessage> {
+ private static final String REGISTRY_LABEL = "Component registry:";
+ private static final long serialVersionUID = 8390860727800654604L;
+ private static final Logger logger = getLogger(RegistryChooserPanel.class);
+
+ private final List<Observer<RegistryChoiceMessage>> observers = new ArrayList<>();
+ private final JComboBox<String> registryBox;
+ private final SortedMap<String, Registry> registryMap;
+
+ public RegistryChooserPanel(ComponentPreference pref) {
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ registryMap = pref.getRegistryMap();
+ registryBox = new JComboBox<>(new Vector<>(registryMap.keySet()));
+ registryBox.setPrototypeDisplayValue(LONG_STRING);
+ registryBox.setEditable(false);
+
+ gbc.gridx = 0;
+ gbc.anchor = WEST;
+ this.add(new JLabel(REGISTRY_LABEL), gbc);
+ gbc.gridx = 1;
+ gbc.weightx = 1;
+ gbc.fill = BOTH;
+ this.add(registryBox, gbc);
+
+ registryBox.addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent event) {
+ if (event.getStateChange() == SELECTED)
+ dealWithSelection();
+ }
+ });
+
+ String firstKey = registryMap.firstKey();
+ registryBox.setSelectedItem(firstKey);
+ dealWithSelection();
+ }
+
+ private void updateToolTipText() {
+ String key = (String) registryBox.getSelectedItem();
+ Registry registry = registryMap.get(key);
+ registryBox.setToolTipText(registry.getRegistryBase().toString());
+ }
+
+ private void dealWithSelection() {
+ updateToolTipText();
+ Registry chosenRegistry = getChosenRegistry();
+ RegistryChoiceMessage message = new RegistryChoiceMessage(
+ chosenRegistry);
+ for (Observer<RegistryChoiceMessage> o : getObservers())
+ try {
+ o.notify(this, message);
+ } catch (Exception e) {
+ logger.error("problem handling selection update", e);
+ }
+ }
+
+ @Override
+ public void addObserver(Observer<RegistryChoiceMessage> observer) {
+ observers.add(observer);
+ Registry chosenRegistry = getChosenRegistry();
+ RegistryChoiceMessage message = new RegistryChoiceMessage(
+ chosenRegistry);
+ try {
+ observer.notify(this, message);
+ } catch (Exception e) {
+ logger.error("problem handling addition of observer", e);
+ }
+ }
+
+ @Override
+ public List<Observer<RegistryChoiceMessage>> getObservers() {
+ return observers;
+ }
+
+ @Override
+ public void removeObserver(Observer<RegistryChoiceMessage> observer) {
+ observers.remove(observer);
+ }
+
+ public Registry getChosenRegistry() {
+ if (registryBox.getSelectedIndex() < 0)
+ return null;
+ return registryMap.get(registryBox.getSelectedItem());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SearchChoicePanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SearchChoicePanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SearchChoicePanel.java
new file mode 100644
index 0000000..2e53219
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SearchChoicePanel.java
@@ -0,0 +1,243 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.panel;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.WEST;
+import static java.awt.event.ItemEvent.SELECTED;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.util.Utils.LONG_STRING;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+
+/**
+ * @author alanrw
+ */
+@SuppressWarnings("serial")
+public class SearchChoicePanel extends JPanel {
+ private static final Logger logger = getLogger(SearchChoicePanel.class);
+ private static final String SEARCHING = "Searching...";
+ private static final String[] SEARCHING_ARRAY = new String[] { SEARCHING };
+ private static final String NO_MATCHES = "No matches";
+ private static final String SEARCH_FAILED = "Search failed";
+ private static final List<String> RESERVED_WORDS = Arrays.asList(SEARCHING,
+ NO_MATCHES, SEARCH_FAILED);
+
+ private ComponentPreference preference;//FIXME beaninject from constructor
+ private ComponentFactory factory;//FIXME beaninject from constructor
+ private Registry registry;
+ private String prefixes;
+ private String queryText;
+ private JLabel registryURLLabel;
+ private JComboBox<String> familyBox;
+ private JComboBox<String> componentBox;
+ private JComboBox<Object> versionBox;
+
+ public SearchChoicePanel(Registry registry, String prefixes,
+ String queryText) {
+ super(new GridBagLayout());
+ this.registry = registry;
+ this.prefixes = prefixes;
+ this.queryText = queryText;
+
+ componentBox = new JComboBox<>(SEARCHING_ARRAY);
+ componentBox.setPrototypeDisplayValue(LONG_STRING);
+ familyBox = new JComboBox<>(SEARCHING_ARRAY);
+ familyBox.setPrototypeDisplayValue(LONG_STRING);
+ versionBox = new JComboBox<Object>(SEARCHING_ARRAY);
+ versionBox.setPrototypeDisplayValue(LONG_STRING);
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ JLabel registryLabel = new JLabel("Component registry:");
+
+ gbc.insets.left = 5;
+ gbc.insets.right = 5;
+ gbc.gridx = 0;
+ gbc.anchor = WEST;
+ gbc.fill = BOTH;
+ gbc.gridwidth = 1;
+ gbc.weightx = 1;
+ gbc.gridy++;
+ this.add(registryLabel, gbc);
+ gbc.gridx = 1;
+ registryURLLabel = new JLabel(SEARCHING);
+ this.add(registryURLLabel, gbc);
+ gbc.gridx = 0;
+ gbc.gridy++;
+ this.add(new JLabel("Component family:"), gbc);
+ gbc.gridx = 1;
+
+ this.add(familyBox, gbc);
+ gbc.gridx = 0;
+ gbc.gridy++;
+ this.add(new JLabel("Component:"), gbc);
+ gbc.gridx = 1;
+ this.add(componentBox, gbc);
+
+ gbc.gridx = 0;
+ gbc.gridy++;
+
+ this.add(new JLabel("Component version:"), gbc);
+ gbc.gridx = 1;
+ this.add(versionBox, gbc);
+
+ new Searcher().execute();
+ }
+
+ private class Searcher extends SwingWorker<Set<Version.ID>, Object> {
+ @Override
+ protected Set<Version.ID> doInBackground() throws Exception {
+ return registry.searchForComponents(prefixes, queryText);
+ }
+
+ @Override
+ protected void done() {
+ clearAll();
+ try {
+ Set<Version.ID> matches = get();
+ if (matches.isEmpty())
+ setAll(NO_MATCHES);
+ else
+ searchCompletedSuccessfully(matches);
+ } catch (InterruptedException e) {
+ logger.error("search was interrupted", e);
+ setAll(SEARCH_FAILED);
+ } catch (ExecutionException e) {
+ logger.error("problem in execution", e.getCause());
+ setAll(SEARCH_FAILED);
+ }
+ }
+ }
+
+ private void clearAll() {
+ familyBox.removeAllItems();
+ componentBox.removeAllItems();
+ versionBox.removeAllItems();
+ }
+
+ private void setAll(String text) {
+ registryURLLabel.setText(text);
+ familyBox.addItem(text);
+ componentBox.addItem(text);
+ versionBox.addItem(text);
+ }
+
+ private String[] calculateMatchingFamilyNames(
+ Set<Version.ID> matchingComponents) {
+ Set<String> result = new TreeSet<>();
+ for (Version.ID v : matchingComponents)
+ result.add(v.getFamilyName());
+ return result.toArray(new String[0]);
+ }
+
+ private void updateComponentBox(Set<Version.ID> matchingComponents,
+ JComboBox<String> componentBox, String selectedItem) {
+ componentBox.removeAllItems();
+ String[] matchingComponentNames = calculateMatchingComponentNames(
+ matchingComponents, selectedItem);
+ for (String componentName : matchingComponentNames)
+ componentBox.addItem(componentName);
+ componentBox.setSelectedIndex(0);
+ }
+
+ private String[] calculateMatchingComponentNames(
+ Set<Version.ID> matchingComponents, String familyName) {
+ Set<String> result = new TreeSet<>();
+ for (Version.ID v : matchingComponents)
+ if (v.getFamilyName().equals(familyName))
+ result.add(v.getComponentName());
+ return result.toArray(new String[0]);
+ }
+
+ private void updateVersionBox(Set<Version.ID> matchingComponents,
+ JComboBox<Object> versionBox, String componentName,
+ String familyName) {
+ versionBox.removeAllItems();
+ for (Integer v : calculateMatchingVersionNumbers(matchingComponents,
+ componentName, familyName))
+ versionBox.addItem(v);
+ versionBox.setSelectedIndex(0);
+ }
+
+ private Integer[] calculateMatchingVersionNumbers(
+ Set<Version.ID> matchingComponents, String componentName,
+ String familyName) {
+ Set<Integer> result = new TreeSet<>();
+ for (Version.ID v : matchingComponents)
+ if (v.getFamilyName().equals(familyName)
+ && v.getComponentName().equals(componentName))
+ result.add(v.getComponentVersion());
+ return result.toArray(new Integer[0]);
+ }
+
+ public Version.ID getVersionIdentification() {
+ String registryString = registryURLLabel.getText();
+ if (RESERVED_WORDS.contains(registryString))
+ return null;
+
+ try {
+ return factory.getVersion(registry.getRegistryBase(),
+ (String) familyBox.getSelectedItem(),
+ (String) componentBox.getSelectedItem(),
+ (Integer) versionBox.getSelectedItem()).getID();
+ } catch (ComponentException e) {
+ logger.warn(
+ "unexpected failure to construct component version token",
+ e);
+ return null;
+ }
+ }
+
+ private void searchCompletedSuccessfully(final Set<Version.ID> matches) {
+ Version.ID one = (Version.ID) matches.toArray()[0];
+ registryURLLabel.setText(preference.getRegistryName(one
+ .getRegistryBase()));
+ for (String familyName : calculateMatchingFamilyNames(matches))
+ familyBox.addItem(familyName);
+ familyBox.addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == SELECTED)
+ updateComponentBox(matches, componentBox,
+ (String) familyBox.getSelectedItem());
+ }
+ });
+ componentBox.addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == SELECTED)
+ updateVersionBox(matches, versionBox,
+ (String) componentBox.getSelectedItem(),
+ (String) familyBox.getSelectedItem());
+ }
+ });
+ familyBox.setSelectedIndex(0);
+ updateComponentBox(matches, componentBox,
+ (String) familyBox.getSelectedItem());
+ updateVersionBox(matches, versionBox,
+ (String) componentBox.getSelectedItem(),
+ (String) familyBox.getSelectedItem());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SharingPolicyChooserPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SharingPolicyChooserPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SharingPolicyChooserPanel.java
new file mode 100644
index 0000000..2544f40
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/panel/SharingPolicyChooserPanel.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (C) 2013 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package org.apache.taverna.component.ui.panel;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.util.Utils.LONG_STRING;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.concurrent.ExecutionException;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.api.SharingPolicy;
+
+/**
+ * @author alanrw
+ */
+public class SharingPolicyChooserPanel extends JPanel {
+ private static final String SHARING_LABEL = "Sharing policy:";
+ private static final String READING_MSG = "Reading sharing policies";
+ private static final String NO_PERMISSIONS_MSG = "No permissions available";
+ private static final long serialVersionUID = 2175274929391537032L;
+ private static final Logger logger = getLogger(SharingPolicyChooserPanel.class);
+
+ private final JComboBox<String> permissionBox = new JComboBox<>();
+ private final SortedMap<String, SharingPolicy> permissionMap = new TreeMap<>();
+ private Registry registry;
+
+ public SharingPolicyChooserPanel(RegistryChooserPanel registryPanel) {
+ this();
+ registryPanel.addObserver(new Observer<RegistryChoiceMessage>(){
+ @Override
+ public void notify(Observable<RegistryChoiceMessage> sender,
+ RegistryChoiceMessage message) throws Exception {
+ try {
+ registry = message.getChosenRegistry();
+ updateProfileModel();
+ } catch (Exception e) {
+ logger.error("problem when handling notification of registry", e);
+ }
+ }
+ });
+ }
+ public SharingPolicyChooserPanel() {
+ super();
+ permissionBox.setPrototypeDisplayValue(LONG_STRING);
+ this.setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.anchor = WEST;
+ gbc.fill = NONE;
+ this.add(new JLabel(SHARING_LABEL), gbc);
+ gbc.gridx = 1;
+ gbc.weightx = 1;
+ gbc.fill = BOTH;
+ this.add(permissionBox, gbc);
+
+ permissionBox.setEditable(false);
+ }
+
+ private void updateProfileModel() {
+ permissionMap.clear();
+ permissionBox.removeAllItems();
+ permissionBox.addItem(READING_MSG);
+ permissionBox.setEnabled(false);
+ new SharingPolicyUpdater().execute();
+ }
+
+ public SharingPolicy getChosenPermission() {
+ if (permissionBox.getSelectedIndex() < 0)
+ return null;
+ return permissionMap.get(permissionBox.getSelectedItem());
+ }
+
+ private class SharingPolicyUpdater extends SwingWorker<String, Object> {
+ @Override
+ protected String doInBackground() throws Exception {
+ List<SharingPolicy> sharingPolicies;
+ if (registry == null)
+ return null;
+ try {
+ sharingPolicies = registry.getPermissions();
+ if (sharingPolicies == null)
+ return null;
+ } catch (ComponentException e) {
+ logger.error("problem getting permissions", e);
+ throw e;
+ } catch (NullPointerException e) {
+ logger.error("null pointer getting permissions", e);
+ throw e;
+ }
+
+ for (SharingPolicy policy : sharingPolicies)
+ try {
+ permissionMap.put(policy.getName(), policy);
+ } catch (NullPointerException e) {
+ logger.error("problem getting name of policy", e);
+ }
+ return null;
+ }
+
+ @Override
+ protected void done() {
+ permissionBox.removeAllItems();
+ try {
+ get();
+ for (String name : permissionMap.keySet())
+ permissionBox.addItem(name);
+ if (!permissionMap.isEmpty()) {
+ String firstKey = permissionMap.firstKey();
+ permissionBox.setSelectedItem(firstKey);
+ } else {
+ permissionBox.addItem(NO_PERMISSIONS_MSG);
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ logger.error(e);
+ permissionBox.addItem("Unable to read permissions");
+ }
+ permissionBox.setEnabled(!permissionMap.isEmpty());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentDefaults.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentDefaults.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentDefaults.java
new file mode 100644
index 0000000..85a5e4f
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentDefaults.java
@@ -0,0 +1,39 @@
+package org.apache.taverna.component.ui.preference;
+
+import java.io.File;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+/**
+ * Factored out defaults location system.
+ *
+ * @author Donal Fellows
+ */
+public class ComponentDefaults {
+ public static final String REGISTRY_LIST = "REGISTRY_NAMES";
+ private static final String LOCAL_NAME = "local registry";
+ private static final String MYEXPERIMENT_NAME = "myExperiment";
+ private static final String MYEXPERIMENT_SITE = "http://www.myexperiment.org";
+ public static final String DEFAULT_REGISTRY_LIST = LOCAL_NAME + "," + MYEXPERIMENT_NAME;
+
+ public static Map<String, String> getDefaultProperties() {
+ // Capacity = 3; we know that this is going to have 3 entries
+ Map<String, String> defaults = new LinkedHashMap<>(3);
+ defaults.put(LOCAL_NAME, calculateComponentsDirectoryPath());
+ defaults.put(MYEXPERIMENT_NAME, MYEXPERIMENT_SITE);
+ defaults.put(REGISTRY_LIST, DEFAULT_REGISTRY_LIST);
+ return defaults;
+ }
+
+ static ApplicationConfiguration config;//FIXME beaninject (and beanify!)
+
+ public static String calculateComponentsDirectoryPath() {
+ return new File(config.getApplicationHomeDir(), "components").toURI()
+ .toASCIIString();
+ }
+
+ private ComponentDefaults() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreference.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreference.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreference.java
new file mode 100644
index 0000000..ff7bfe6
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreference.java
@@ -0,0 +1,128 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.preference;
+
+import static org.apache.commons.lang.StringUtils.join;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.preference.ComponentDefaults.REGISTRY_LIST;
+import static org.apache.taverna.component.ui.preference.ComponentDefaults.getDefaultProperties;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Registry;
+
+import uk.org.taverna.configuration.AbstractConfigurable;
+import uk.org.taverna.configuration.ConfigurationManager;
+
+/**
+ * @author alanrw
+ */
+public class ComponentPreference extends AbstractConfigurable {
+ public static final String DISPLAY_NAME = "Components";
+ private final Logger logger = getLogger(ComponentPreference.class);
+
+ private SortedMap<String, Registry> registryMap = new TreeMap<>();
+ private ComponentFactory factory;
+
+ public ComponentPreference(ConfigurationManager cm, ComponentFactory factory) {
+ super(cm);
+ this.factory = factory;
+ updateRegistryMap();
+ }
+
+ private void updateRegistryMap() {
+ registryMap.clear();
+
+ for (String key : getRegistryKeys()) {
+ String value = super.getProperty(key);
+ try {
+ registryMap.put(key, factory.getRegistry(new URL(
+ value)));
+ } catch (MalformedURLException e) {
+ logger.error("bogus url (" + value
+ + ") in configuration file", e);
+ } catch (ComponentException e) {
+ logger.error("failed to construct registry handle for "
+ + value, e);
+ }
+ }
+ }
+
+ private String[] getRegistryKeys() {
+ String registryNamesConcatenated = super.getProperty(REGISTRY_LIST);
+ if (registryNamesConcatenated == null)
+ return getDefaultPropertyMap().keySet().toArray(new String[]{});
+ return registryNamesConcatenated.split(",");
+ }
+
+ @Override
+ public String getFilePrefix() {
+ return "Component";
+ }
+
+ @Override
+ public String getUUID() {
+ return "2317A297-2AE0-42B5-86DC-99C9B7C0524A";
+ }
+
+ /**
+ * @return the registryMap
+ */
+ public SortedMap<String, Registry> getRegistryMap() {
+ return registryMap;
+ }
+
+ public String getRegistryName(URL registryBase) {
+ // Trim trailing '/' characters to ensure match.
+ String base = registryBase.toString();
+ while (base.endsWith("/"))
+ base = base.substring(0, base.length() - 1);
+
+ for (Entry<String, Registry> entry : registryMap.entrySet())
+ if (entry.getValue().getRegistryBaseString().equals(base))
+ return entry.getKey();
+ return base;
+ }
+
+ public void setRegistryMap(SortedMap<String, Registry> registries) {
+ registryMap.clear();
+ registryMap.putAll(registries);
+ super.clear();
+ List<String> keyList = new ArrayList<>();
+ for (Entry<String, Registry> entry : registryMap.entrySet()) {
+ String key = entry.getKey();
+ keyList.add(key);
+ super.setProperty(key, entry.getValue().getRegistryBaseString());
+ }
+ Collections.sort(keyList);
+ String registryNamesConcatenated = join(keyList, ",");
+ super.setProperty(REGISTRY_LIST, registryNamesConcatenated);
+ }
+
+ @Override
+ public Map<String, String> getDefaultPropertyMap() {
+ return getDefaultProperties();
+ }
+
+ @Override
+ public String getDisplayName() {
+ return DISPLAY_NAME;
+ }
+
+ @Override
+ public String getCategory() {
+ return "general";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferencePanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferencePanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferencePanel.java
new file mode 100644
index 0000000..ff29d32
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferencePanel.java
@@ -0,0 +1,282 @@
+package org.apache.taverna.component.ui.preference;
+
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.CENTER;
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.WEST;
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN;
+import static javax.swing.ListSelectionModel.SINGLE_SELECTION;
+import static net.sf.taverna.t2.workbench.helper.Helper.showHelp;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ui.util.Utils.URL_PATTERN;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.awt.event.MouseEvent;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.swing.AbstractAction;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.border.EmptyBorder;
+
+import net.sf.taverna.t2.lang.ui.DeselectingButton;
+import net.sf.taverna.t2.lang.ui.ValidatingUserInputDialog;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Registry;
+
+public class ComponentPreferencePanel extends JPanel {
+ private static final String BAD_URL_MESSAGE = "Invalid URL";
+ private static final String SET_URL_MESSAGE = "Set the URL of the profile";
+ private static final String HELP_LABEL = "Help";
+ private static final String RESET_LABEL = "Reset";
+ private static final String APPLY_LABEL = "Apply";
+ private static final String ADD_REMOTE_TITLE = "Add Remote Component Registry";
+ private static final String ADD_LOCAL_TITLE = "Add Local Component Registry";
+ private static final String ADD_REMOTE_LABEL = "Add remote registry";
+ private static final String ADD_LOCAL_LABEL = "Add local registry";
+ private static final String REMOVE_LABEL = "Remove registry";
+ private static final String TITLE = "Component registry management";
+ private static final String VALIDATION_MESSAGE = "Set the registry name";
+ private static final String EXCEPTION_MESSAGE = "Unable to access registry at ";
+ private static final String EXCEPTION_TITLE = "Component registry problem";
+ private static final String INVALID_NAME = "Invalid registry name";
+ private static final String DUPLICATE = "Duplicate registry name";
+ private static final long serialVersionUID = 1310173658718093383L;
+
+ private final Logger logger = getLogger(ComponentPreferencePanel.class);
+
+ private ComponentFactory factory;
+ private ComponentPreference prefs;
+ private RegistryTableModel tableModel = new RegistryTableModel();
+
+ @SuppressWarnings("serial")
+ private JTable registryTable = new JTable(tableModel) {
+ @Override
+ public String getToolTipText(MouseEvent me) {
+ int row = rowAtPoint(me.getPoint());
+ if (row >= 0)
+ return tableModel.getRowTooltipText(row);
+ return super.getToolTipText(me);
+ }
+ };
+
+ public ComponentPreferencePanel(ComponentFactory componentFactory,
+ ComponentPreference preferences) {
+ super(new GridBagLayout());
+ factory = componentFactory;
+ prefs = preferences;
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ // Title describing what kind of settings we are configuring here
+ JTextArea descriptionText = new JTextArea(TITLE);
+ descriptionText.setLineWrap(true);
+ descriptionText.setWrapStyleWord(true);
+ descriptionText.setEditable(false);
+ descriptionText.setFocusable(false);
+ descriptionText.setBorder(new EmptyBorder(10, 10, 10, 10));
+ gbc.anchor = WEST;
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.gridwidth = 1;
+ gbc.weightx = 1.0;
+ gbc.weighty = 0.0;
+ gbc.fill = HORIZONTAL;
+ add(descriptionText, gbc);
+
+ gbc.gridy++;
+ gbc.insets = new Insets(10, 0, 0, 0);
+
+ registryTable.getColumnModel().getColumn(0).setPreferredWidth(20);
+ registryTable.setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);
+ registryTable.setSelectionMode(SINGLE_SELECTION);
+ JScrollPane scrollPane = new JScrollPane(registryTable);
+ // registryTable.setFillsViewportHeight(true);
+
+ gbc.weighty = 1.0;
+ gbc.fill = BOTH;
+
+ add(scrollPane, gbc);
+
+ // Add buttons panel
+ gbc.gridx = 0;
+ gbc.gridy++;
+ gbc.weightx = 0.0;
+ gbc.weighty = 0.0;
+ gbc.gridwidth = 1;
+ gbc.fill = HORIZONTAL;
+ gbc.anchor = CENTER;
+ gbc.insets = new Insets(10, 0, 0, 0);
+ add(createRegistryButtonPanel(), gbc);
+
+ // Add buttons panel
+ gbc.gridx = 0;
+ gbc.gridy++;
+ gbc.weightx = 0.0;
+ gbc.weighty = 0.0;
+ gbc.gridwidth = 1;
+ gbc.fill = HORIZONTAL;
+ gbc.anchor = CENTER;
+ gbc.insets = new Insets(10, 0, 0, 0);
+ add(createButtonPanel(), gbc);
+
+ setFields();
+ }
+
+ /**
+ * Create the buttons for managing the list of registries.
+ * @return
+ */
+ @SuppressWarnings("serial")
+ private Component createRegistryButtonPanel() {
+ JPanel panel = new JPanel();
+ panel.add(new DeselectingButton(new AbstractAction(REMOVE_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ remove();
+ }
+ }));
+ panel.add(new DeselectingButton(new AbstractAction(ADD_LOCAL_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ addLocal();
+ }
+ }));
+ panel.add(new DeselectingButton(new AbstractAction(ADD_REMOTE_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ addRemote();
+ }
+ }));
+ return panel;
+ }
+
+ /**
+ * Create the panel to contain the buttons
+ *
+ * @return
+ */
+ @SuppressWarnings("serial")
+ private JPanel createButtonPanel() {
+ final JPanel panel = new JPanel();
+ panel.add(new DeselectingButton(new AbstractAction(HELP_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ showHelp(panel);
+ }
+ }));
+ panel.add(new DeselectingButton(new AbstractAction(RESET_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ setFields();
+ }
+ }));
+ panel.add(new DeselectingButton(new AbstractAction(APPLY_LABEL) {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ applySettings();
+ setFields();
+ }
+ }));
+ return panel;
+ }
+
+ void remove() {
+ int selectedRow = registryTable.getSelectedRow();
+ if (selectedRow != -1)
+ tableModel.removeRow(selectedRow);
+ }
+
+ void addLocal() {
+ // Run the GUI
+ LocalRegistryPanel inputPanel = new LocalRegistryPanel();
+ ValidatingUserInputDialog vuid = new ValidatingUserInputDialog(
+ ADD_LOCAL_TITLE, inputPanel);
+ vuid.addTextComponentValidation(inputPanel.getRegistryNameField(),
+ VALIDATION_MESSAGE, tableModel.getRegistryMap().keySet(),
+ DUPLICATE, "[\\p{L}\\p{Digit}_.]+", INVALID_NAME);
+ vuid.setSize(new Dimension(400, 250));
+ if (!vuid.show(ComponentPreferencePanel.this))
+ return;
+
+ // Add the local registry
+ String location = inputPanel.getLocationField().getText();
+ File newDir = new File(location);
+ try {
+ tableModel.insertRegistry(inputPanel.getRegistryNameField()
+ .getText(), getLocalRegistry(newDir));
+ } catch (MalformedURLException e) {
+ logger.error("bad url provided by user", e);
+ showMessageDialog(null, EXCEPTION_MESSAGE + location,
+ EXCEPTION_TITLE, ERROR_MESSAGE);
+ } catch (ComponentException e) {
+ logger.error("problem creating local registry", e);
+ showMessageDialog(null, EXCEPTION_MESSAGE + location,
+ EXCEPTION_TITLE, ERROR_MESSAGE);
+ }
+ }
+
+ void addRemote() {
+ RemoteRegistryPanel inputPanel = new RemoteRegistryPanel();
+ ValidatingUserInputDialog vuid = new ValidatingUserInputDialog(
+ ADD_REMOTE_TITLE, inputPanel);
+ vuid.addTextComponentValidation(inputPanel.getRegistryNameField(),
+ VALIDATION_MESSAGE, tableModel.getRegistryMap().keySet(),
+ DUPLICATE, "[\\p{L}\\p{Digit}_.]+", INVALID_NAME);
+ vuid.addTextComponentValidation(inputPanel.getLocationField(),
+ SET_URL_MESSAGE, null, "", URL_PATTERN, BAD_URL_MESSAGE);
+ vuid.setSize(new Dimension(400, 250));
+ if (!vuid.show(ComponentPreferencePanel.this))
+ return;
+
+ String location = inputPanel.getLocationField().getText();
+ try {
+ tableModel.insertRegistry(inputPanel.getRegistryNameField()
+ .getText(), getRemoteRegistry(location));
+ } catch (MalformedURLException e) {
+ logger.error("bad url provided by user", e);
+ showMessageDialog(null, EXCEPTION_MESSAGE + location,
+ EXCEPTION_TITLE, ERROR_MESSAGE);
+ } catch (ComponentException e) {
+ showMessageDialog(null, EXCEPTION_MESSAGE + location,
+ EXCEPTION_TITLE, ERROR_MESSAGE);
+ logger.error("problem creating remote registry", e);
+ }
+ }
+
+ Registry getLocalRegistry(File location) throws ComponentException,
+ MalformedURLException {
+ return factory.getRegistry(location.toURI().toURL());
+ }
+
+ Registry getRemoteRegistry(String location) throws MalformedURLException,
+ ComponentException {
+ URL url = new URL(location);
+ if (url.getProtocol() == null || url.getProtocol().equals("file"))
+ throw new MalformedURLException(
+ "may not use relative or local URLs for locating registry");
+ return factory.getRegistry(url);
+ }
+
+ private void applySettings() {
+ prefs.setRegistryMap(tableModel.getRegistryMap());
+ }
+
+ private void setFields() {
+ tableModel.setRegistryMap(prefs.getRegistryMap());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferenceUIFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferenceUIFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferenceUIFactory.java
new file mode 100644
index 0000000..b314733
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/ComponentPreferenceUIFactory.java
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.preference;
+
+import javax.swing.JPanel;
+
+import uk.org.taverna.configuration.Configurable;
+import uk.org.taverna.configuration.ConfigurationUIFactory;
+
+/**
+ * @author alanrw
+ */
+public class ComponentPreferenceUIFactory implements ConfigurationUIFactory {
+ public static final String DISPLAY_NAME = "Components";
+
+ private JPanel configPanel;//FIXME beaninject
+ private ComponentPreference prefs;// FIXME beaninject
+
+ public ComponentPreferenceUIFactory() {
+ super();
+ }
+
+ public void setConfigPanel(JPanel configPanel) {
+ this.configPanel = configPanel;
+ }
+
+ public void setPreferences(ComponentPreference pref) {
+ this.prefs = pref;
+ }
+
+ @Override
+ public boolean canHandle(String uuid) {
+ return uuid.equals(prefs.getUUID());
+ }
+
+ @Override
+ public Configurable getConfigurable() {
+ return prefs;
+ }
+
+ @Override
+ public JPanel getConfigurationPanel() {
+ return configPanel;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/LocalRegistryPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/LocalRegistryPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/LocalRegistryPanel.java
new file mode 100644
index 0000000..f9f78c0
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/LocalRegistryPanel.java
@@ -0,0 +1,117 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.preference;
+
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+import static javax.swing.JFileChooser.APPROVE_OPTION;
+import static javax.swing.JFileChooser.DIRECTORIES_ONLY;
+import static org.apache.log4j.Logger.getLogger;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+
+import javax.swing.AbstractAction;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+import net.sf.taverna.t2.lang.ui.DeselectingButton;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author alanrw
+ *
+ */
+public class LocalRegistryPanel extends JPanel {
+ private static final String BROWSE_LABEL = "Browse";
+ private static final String LOCATION_LABEL = "Location:";
+ private static final String NAME_LABEL = "Name:";
+ private static final long serialVersionUID = 732945735813617327L;
+
+ private final Logger logger = getLogger(LocalRegistryPanel.class);
+
+ private JTextField registryNameField = new JTextField(20);
+ private JTextField locationField = new JTextField(20);
+
+ public LocalRegistryPanel() {
+ super(new GridBagLayout());
+
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ GridBagConstraints constraints = new GridBagConstraints();
+
+ constraints.anchor = WEST;
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.ipadx = 20;
+ add(new JLabel(NAME_LABEL), constraints);
+
+ constraints.gridx = 1;
+ constraints.gridwidth = 2;
+ constraints.ipadx = 0;
+ constraints.weightx = 1d;
+ constraints.fill = HORIZONTAL;
+ add(registryNameField, constraints);
+
+ constraints.gridy++;
+ constraints.gridx = 0;
+ constraints.ipadx = 20;
+ constraints.fill = NONE;
+ add(new JLabel(LOCATION_LABEL), constraints);
+
+ constraints.gridx = 1;
+ constraints.gridwidth = 2;
+ constraints.ipadx = 0;
+ constraints.weightx = 1d;
+ constraints.fill = HORIZONTAL;
+ add(locationField, constraints);
+
+ constraints.gridy++;
+ constraints.gridx = 0;
+ constraints.ipadx = 20;
+ constraints.fill = NONE;
+ add(new DeselectingButton(new AbstractAction(BROWSE_LABEL) {
+ private static final long serialVersionUID = -8676803966947261009L;
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ pickDirectory();
+ }
+ }), constraints);
+ }
+
+ private void pickDirectory() {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode(DIRECTORIES_ONLY);
+ int returnVal = chooser.showOpenDialog(LocalRegistryPanel.this);
+ try {
+ if (returnVal == APPROVE_OPTION)
+ locationField.setText(chooser.getSelectedFile()
+ .getCanonicalPath());
+ } catch (IOException e) {
+ logger.error("unexpected filesystem problem", e);
+ }
+ }
+
+ /**
+ * @return the registryNameField
+ */
+ public JTextField getRegistryNameField() {
+ return registryNameField;
+ }
+
+ /**
+ * @return the locationField
+ */
+ public JTextField getLocationField() {
+ return locationField;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RegistryTableModel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RegistryTableModel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RegistryTableModel.java
new file mode 100644
index 0000000..a523c44
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RegistryTableModel.java
@@ -0,0 +1,70 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.preference;
+
+import static java.lang.String.format;
+
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import javax.swing.table.DefaultTableModel;
+
+import org.apache.taverna.component.api.Registry;
+
+/**
+ * @author alanrw
+ *
+ */
+public class RegistryTableModel extends DefaultTableModel {
+ private static final long serialVersionUID = -7789666945764974370L;
+ private SortedMap<String, Registry> registryMap = new TreeMap<String, Registry>();
+
+ public RegistryTableModel() {
+ super(new String[] { "Registry name", "Registry location" }, 0);
+ }
+
+ public void setRegistryMap(SortedMap<String, Registry> registries) {
+ registryMap.clear();
+ registryMap.putAll(registries);
+ updateRows();
+ }
+
+ public void updateRows() {
+ super.setRowCount(0);
+ for (Entry<String, Registry> entry : registryMap.entrySet())
+ super.addRow(new Object[] { entry.getKey(),
+ entry.getValue().getRegistryBaseString() });
+ }
+
+ @Override
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ }
+
+ public String getRowTooltipText(int row) {
+ Registry registry = registryMap.get(getValueAt(row, 0));
+ return format("This is a %s registry.", registry.getRegistryTypeName());
+ }
+
+ @Override
+ public void removeRow(int row) {
+ String key = (String) getValueAt(row, 0);
+ registryMap.remove(key);
+ super.removeRow(row);
+ }
+
+ public void insertRegistry(String name, Registry newRegistry) {
+ registryMap.put(name, newRegistry);
+ updateRows();
+ }
+
+ /**
+ * @return the registryMap
+ */
+ public SortedMap<String, Registry> getRegistryMap() {
+ return registryMap;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RemoteRegistryPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RemoteRegistryPanel.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RemoteRegistryPanel.java
new file mode 100644
index 0000000..a287d1e
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/preference/RemoteRegistryPanel.java
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.preference;
+
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+/**
+ * @author alanrw
+ *
+ */
+public class RemoteRegistryPanel extends JPanel {
+ private static final String LOCATION_LABEL = "Location:";
+ private static final String NAME_LABEL = "Name:";
+ private static final long serialVersionUID = 8833815753329010062L;
+
+ private JTextField registryNameField = new JTextField(20);
+ private JTextField locationField = new JTextField(20);
+
+ public RemoteRegistryPanel() {
+ super(new GridBagLayout());
+
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ GridBagConstraints constraints = new GridBagConstraints();
+
+ constraints.anchor = WEST;
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.ipadx = 20;
+ add(new JLabel(NAME_LABEL), constraints);
+
+ constraints.gridx = 1;
+ constraints.gridwidth = 2;
+ constraints.ipadx = 0;
+ constraints.weightx = 1d;
+ constraints.fill = HORIZONTAL;
+ add(registryNameField, constraints);
+
+ constraints.gridy++;
+ constraints.gridx = 0;
+ constraints.ipadx = 20;
+ constraints.fill = NONE;
+ add(new JLabel(LOCATION_LABEL), constraints);
+
+ constraints.gridx = 1;
+ constraints.gridwidth = 2;
+ constraints.ipadx = 0;
+ constraints.weightx = 1d;
+ constraints.fill = HORIZONTAL;
+ add(locationField, constraints);
+ }
+
+ /**
+ * @return the registryNameField
+ */
+ public JTextField getRegistryNameField() {
+ return registryNameField;
+ }
+
+ /**
+ * @return the locationField
+ */
+ public JTextField getLocationField() {
+ return locationField;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceDesc.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceDesc.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceDesc.java
new file mode 100644
index 0000000..2f98978
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceDesc.java
@@ -0,0 +1,156 @@
+package org.apache.taverna.component.ui.serviceprovider;
+
+import static java.util.Arrays.asList;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.COMPONENT_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.COMPONENT_VERSION;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.FAMILY_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.REGISTRY_BASE;
+import static org.apache.taverna.component.ui.ComponentConstants.ACTIVITY_URI;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.api.Version.ID;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class ComponentServiceDesc extends ServiceDescription {
+ private static Logger logger = getLogger(ComponentServiceDesc.class);
+
+ private Version.ID identification;
+ private final ComponentPreference preference;
+ private final ComponentFactory factory;
+ private final ComponentServiceIcon iconProvider;
+
+ public ComponentServiceDesc(ComponentPreference preference,
+ ComponentFactory factory, ComponentServiceIcon iconProvider,
+ Version.ID identification) {
+ this.preference = preference;
+ this.factory = factory;
+ this.identification = identification;
+ this.iconProvider = iconProvider;
+ }
+
+ /**
+ * The configuration bean which is to be used for configuring the
+ * instantiated activity. This is built from the component identifier.
+ */
+ @Override
+ public Configuration getActivityConfiguration() {
+ Configuration config = new Configuration();
+ installActivityConfiguration(config);
+ return config;
+ }
+
+ /**
+ * Make the given activity be configured to be using the component that this
+ * class identifies.
+ */
+ public void installActivityConfiguration(Activity activity) {
+ installActivityConfiguration(activity.getConfiguration());
+ }
+
+ /**
+ * Update the given configuration to have the fields for the component that
+ * this class identifies.
+ */
+ public void installActivityConfiguration(Configuration config) {
+ ObjectNode c = config.getJsonAsObjectNode();
+ ID id = getIdentification();
+ c.put(REGISTRY_BASE, id.getRegistryBase().toExternalForm());
+ c.put(FAMILY_NAME, id.getFamilyName());
+ c.put(COMPONENT_NAME, id.getComponentName());
+ c.put(COMPONENT_VERSION, id.getComponentVersion());
+ config.setJson(c);
+ }
+
+ /**
+ * An icon to represent this service description in the service palette.
+ */
+ @Override
+ public Icon getIcon() {
+ return iconProvider.getIcon();
+ }
+
+ /**
+ * The display name that will be shown in service palette and will be used
+ * as a template for processor name when added to workflow.
+ */
+ @Override
+ public String getName() {
+ return getIdentification().getComponentName();
+ }
+
+ /**
+ * The path to this service description in the service palette. Folders will
+ * be created for each element of the returned path.
+ */
+ @Override
+ public List<String> getPath() {
+ return asList("Components",
+ preference.getRegistryName(identification.getRegistryBase()),
+ identification.getFamilyName());
+ }
+
+ /**
+ * Returns a list of data values uniquely identifying this component
+ * description (i.e., no duplicates).
+ */
+ @Override
+ protected List<? extends Object> getIdentifyingData() {
+ return Arrays.asList(identification.getRegistryBase(),
+ identification.getFamilyName(),
+ identification.getComponentName());
+ }
+
+ @Override
+ public String toString() {
+ return "Component " + getName();
+ }
+
+ /**
+ * @return the identification
+ */
+ public Version.ID getIdentification() {
+ return identification;
+ }
+
+ /**
+ * @param identification
+ * the identification to set
+ */
+ public void setIdentification(Version.ID identification) {
+ this.identification = identification;
+ }
+
+ public URL getHelpURL() {
+ try {
+ return factory.getVersion(getIdentification()).getHelpURL();
+ } catch (ComponentException e) {
+ logger.error(
+ "failed to get component in order to determine its help URL",
+ e);
+ return null;
+ }
+ }
+
+ @Override
+ public URI getActivityType() {
+ return ACTIVITY_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceIcon.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceIcon.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceIcon.java
new file mode 100644
index 0000000..1e30e7b
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceIcon.java
@@ -0,0 +1,33 @@
+package org.apache.taverna.component.ui.serviceprovider;
+
+import static org.apache.taverna.component.ui.serviceprovider.Service.COMPONENT_ACTIVITY_URI;
+
+import java.net.URI;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI;
+
+public class ComponentServiceIcon implements ActivityIconSPI {
+ private static class Init {
+ private static Icon icon = new ImageIcon(
+ ComponentServiceIcon.class.getResource("/brick.png"));
+ }
+
+ @Override
+ public int canProvideIconScore(URI activityType) {
+ if (activityType.equals(COMPONENT_ACTIVITY_URI))
+ return DEFAULT_ICON + 1;
+ return NO_ICON;
+ }
+
+ @Override
+ public Icon getIcon(URI activityType) {
+ return Init.icon;
+ }
+
+ public Icon getIcon() {
+ return Init.icon;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProvider.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProvider.java
new file mode 100644
index 0000000..25ea0c1
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProvider.java
@@ -0,0 +1,218 @@
+package org.apache.taverna.component.ui.serviceprovider;
+
+import static java.util.Arrays.asList;
+import static javax.swing.JOptionPane.OK_CANCEL_OPTION;
+import static javax.swing.JOptionPane.OK_OPTION;
+import static javax.swing.JOptionPane.showConfirmDialog;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.FAMILY_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.REGISTRY_BASE;
+import static org.apache.taverna.component.ui.ComponentConstants.ACTIVITY_URI;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
+import net.sf.taverna.t2.servicedescriptions.CustomizedConfigurePanelProvider;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.Component;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Family;
+import org.apache.taverna.component.api.Registry;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.ui.panel.RegistryAndFamilyChooserPanel;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+import org.apache.taverna.component.ui.util.Utils;
+
+import uk.org.taverna.scufl2.api.common.Visitor;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class ComponentServiceProvider extends
+ AbstractConfigurableServiceProvider implements
+ CustomizedConfigurePanelProvider {
+ static final URI providerId = URI
+ .create("http://taverna.sf.net/2012/service-provider/component");
+ private static Logger logger = getLogger(ComponentServiceProvider.class);
+
+ private final ComponentFactory factory;
+ private final ComponentPreference prefs;
+ private final ComponentServiceIcon iconProvider;
+ private final Utils utils;
+
+ public ComponentServiceProvider(ComponentFactory factory,
+ ComponentPreference prefs, ComponentServiceIcon iconProvider,
+ Utils utils) {
+ super(makeConfig(null, null));
+ this.factory = factory;
+ this.prefs = prefs;
+ this.iconProvider = iconProvider;
+ this.utils = utils;
+ }
+
+ private static class Conf {
+ URL registryBase;
+ String familyName;
+
+ Conf(Configuration config) throws MalformedURLException {
+ ObjectNode node = config.getJsonAsObjectNode();
+ JsonNode item = node.get(REGISTRY_BASE);
+ if (item != null && !item.isNull())
+ registryBase = URI.create(item.textValue()).toURL();
+ item = node.get(FAMILY_NAME);
+ if (item != null && !item.isNull())
+ familyName = item.textValue();
+ }
+ }
+
+ /**
+ * Do the actual search for services. Return using the callBack parameter.
+ */
+ @Override
+ public void findServiceDescriptionsAsync(
+ FindServiceDescriptionsCallBack callBack) {
+ Conf config;
+
+ Registry registry;
+ try {
+ config = new Conf(getConfiguration());
+ registry = factory.getRegistry(config.registryBase);
+ } catch (ComponentException | MalformedURLException e) {
+ logger.error("failed to get registry API", e);
+ callBack.fail("Unable to read components", e);
+ return;
+ }
+
+ try {
+ List<ComponentServiceDesc> results = new ArrayList<>();
+ for (Family family : registry.getComponentFamilies()) {
+ // TODO get check on family name in there
+ if (family.getName().equals(config.familyName))
+ for (Component component : family.getComponents())
+ try {
+ SortedMap<Integer, Version> versions = component
+ .getComponentVersionMap();
+ ComponentServiceDesc newDesc = new ComponentServiceDesc(
+ prefs, factory, iconProvider, versions.get(
+ versions.lastKey()).getID());
+ results.add(newDesc);
+ } catch (Exception e) {
+ logger.error("problem getting service descriptor",
+ e);
+ }
+ callBack.partialResults(results);
+ callBack.finished();
+ }
+ } catch (ComponentException e) {
+ logger.error("problem querying registry", e);
+ callBack.fail("Unable to read components", e);
+ }
+ }
+
+ /**
+ * Icon for service provider
+ */
+ @Override
+ public Icon getIcon() {
+ return iconProvider.getIcon();
+ }
+
+ /**
+ * Name of service provider, appears in right click for 'Remove service
+ * provider'
+ */
+ @Override
+ public String getName() {
+ return "Component service";
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ @Override
+ public String getId() {
+ return providerId.toASCIIString();
+ }
+
+ @Override
+ protected List<? extends Object> getIdentifyingData() {
+ try {
+ Conf config = new Conf(getConfiguration());
+ return asList(config.registryBase.toString(), config.familyName);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void createCustomizedConfigurePanel(
+ CustomizedConfigureCallBack callBack) {
+ RegistryAndFamilyChooserPanel panel = new RegistryAndFamilyChooserPanel(prefs);
+
+ if (showConfirmDialog(null, panel, "Component family import",
+ OK_CANCEL_OPTION) != OK_OPTION)
+ return;
+
+ Registry registry = panel.getChosenRegistry();
+ Family family = panel.getChosenFamily();
+ if (registry == null || family == null)
+ return;
+ callBack.newProviderConfiguration(makeConfig(
+ registry.getRegistryBaseString(), family.getName()));
+ }
+
+ private static Configuration makeConfig(String registryUrl,
+ String familyName) {
+ ObjectNode cfg = JsonNodeFactory.instance.objectNode();
+ cfg.put(REGISTRY_BASE, registryUrl);
+ cfg.put(FAMILY_NAME, familyName);
+ Configuration conf = new Configuration();
+ conf.setJson(cfg);
+ conf.setType(providerId);
+ return conf;
+ }
+
+ @Override
+ public ServiceDescriptionProvider newInstance() {
+ return new ComponentServiceProvider(factory, prefs, iconProvider, utils);
+ }
+
+ @Override
+ public URI getType() {
+ return ACTIVITY_URI;
+ }
+
+ @Override
+ public void setType(URI type) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean accept(Visitor visitor) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void refreshProvidedComponent(Version.ID ident) {
+ try {
+ utils.refreshComponentServiceProvider(new ComponentServiceProviderConfig(
+ ident).getConfiguration());
+ } catch (Exception e) {
+ logger.error("Unable to refresh service panel", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProviderConfig.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProviderConfig.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProviderConfig.java
new file mode 100644
index 0000000..9d8e82f
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/ComponentServiceProviderConfig.java
@@ -0,0 +1,69 @@
+package org.apache.taverna.component.ui.serviceprovider;
+
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.FAMILY_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.REGISTRY_BASE;
+import static org.apache.taverna.component.ui.serviceprovider.ComponentServiceProvider.providerId;
+
+import java.net.URL;
+
+import org.apache.taverna.component.api.Family;
+import org.apache.taverna.component.api.Version;
+
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+public class ComponentServiceProviderConfig {
+ private URL registryBase;
+ private String familyName;
+
+ public ComponentServiceProviderConfig() {
+ }
+
+ public ComponentServiceProviderConfig(Family family) {
+ registryBase = family.getComponentRegistry().getRegistryBase();
+ familyName = family.getName();
+ }
+
+ public ComponentServiceProviderConfig(Version.ID ident) {
+ registryBase = ident.getRegistryBase();
+ familyName = ident.getFamilyName();
+ }
+
+ /**
+ * @return the registryBase
+ */
+ public URL getRegistryBase() {
+ return registryBase;
+ }
+
+ /**
+ * @param registryBase
+ * the registryBase to set
+ */
+ public void setRegistryBase(URL registryBase) {
+ this.registryBase = registryBase;
+ }
+
+ /**
+ * @return the familyName
+ */
+ public String getFamilyName() {
+ return familyName;
+ }
+
+ /**
+ * @param familyName
+ * the familyName to set
+ */
+ public void setFamilyName(String familyName) {
+ this.familyName = familyName;
+ }
+
+ public Configuration getConfiguration() {
+ Configuration c = new Configuration();
+ c.getJsonAsObjectNode().put(REGISTRY_BASE,
+ registryBase.toExternalForm());
+ c.getJsonAsObjectNode().put(FAMILY_NAME, familyName);
+ c.setType(providerId);
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/Service.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/Service.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/Service.java
new file mode 100644
index 0000000..d363e6f
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/serviceprovider/Service.java
@@ -0,0 +1,8 @@
+package org.apache.taverna.component.ui.serviceprovider;
+
+import java.net.URI;
+
+public interface Service {
+ URI COMPONENT_ACTIVITY_URI = URI
+ .create("http://ns.taverna.org.uk/2010/activity/component");
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentFileType.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentFileType.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentFileType.java
new file mode 100644
index 0000000..ee71e07
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentFileType.java
@@ -0,0 +1,32 @@
+package org.apache.taverna.component.ui.util;
+
+import net.sf.taverna.t2.workbench.file.FileType;
+
+/**
+ * The type of components.
+ *
+ * @author alanrw
+ */
+public class ComponentFileType extends FileType {
+ // TODO Change mimetype for sculf2?
+ static final String COMPONENT_MIMETYPE = "application/vnd.taverna.component";
+
+ private ComponentFileType() {
+ }
+
+ @Override
+ public String getDescription() {
+ return "Taverna component";
+ }
+
+ // Not really used
+ @Override
+ public String getExtension() {
+ return "component";
+ }
+
+ @Override
+ public String getMimeType() {
+ return COMPONENT_MIMETYPE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentHealthCheck.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentHealthCheck.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentHealthCheck.java
new file mode 100644
index 0000000..3743c79
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/ComponentHealthCheck.java
@@ -0,0 +1,65 @@
+package org.apache.taverna.component.ui.util;
+
+import static org.apache.log4j.Logger.getLogger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.ui.ComponentActivityConfigurationBean;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.common.Visitor;
+import uk.org.taverna.scufl2.api.container.WorkflowBundle;
+import uk.org.taverna.scufl2.validation.correctness.DefaultDispatchingVisitor;
+
+public class ComponentHealthCheck extends VisitKind {
+ public static final int NO_PROBLEM = 0;
+ public static final int OUT_OF_DATE = 10;
+ public static final int NON_SHAREABLE = 20;
+ public static final int FAILS_PROFILE = 30;
+ private static Logger logger = getLogger(ComponentHealthCheck.class);
+ private static final String OUTDATED_MSG = "Component out of date";
+
+ private ComponentFactory factory;
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ public List<Object> checkForOutdatedComponents(WorkflowBundle bundle) {
+ UpgradeChecker uc = new UpgradeChecker();
+ bundle.accept(uc);
+ return uc.warnings;
+ }
+
+ private class UpgradeChecker extends DefaultDispatchingVisitor {
+ ComponentFactory factory;
+ List<Object> warnings = new ArrayList<>();
+
+ @Override
+ public void visitActivity(Activity activity) {
+ ComponentActivityConfigurationBean config = new ComponentActivityConfigurationBean(
+ activity.getConfiguration().getJson(), factory);
+ Version v;
+ try {
+ v = config.getVersion();
+ } catch (ComponentException e) {
+ logger.error("failed to get component description", e);
+ warnings.add(e);//FIXME Just putting the exception in here isn't good
+ return;
+ }
+ visitComponent(activity, v);
+ }
+ protected void visitComponent(Activity activity, Version version) {
+ int latest = version.getComponent().getComponentVersionMap().lastKey();
+ if (latest > version.getVersionNumber())
+ warnings.add(new VisitReport(ComponentHealthCheck.this,
+ activity, OUTDATED_MSG, OUT_OF_DATE,
+ VisitReport.Status.WARNING));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/43334c1d/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/Utils.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/Utils.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/Utils.java
new file mode 100644
index 0000000..fc36f4a
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/util/Utils.java
@@ -0,0 +1,126 @@
+/**
+ *
+ */
+package org.apache.taverna.component.ui.util;
+
+import static org.apache.taverna.component.ui.ComponentConstants.ACTIVITY_URI;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.taverna.component.api.ComponentFactory;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.ui.preference.ComponentPreference;
+import org.apache.taverna.component.ui.serviceprovider.ComponentServiceIcon;
+import org.apache.taverna.component.ui.serviceprovider.ComponentServiceProvider;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.common.Named;
+import uk.org.taverna.scufl2.api.common.NamedSet;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+import uk.org.taverna.scufl2.api.container.WorkflowBundle;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.file.FileManager;
+
+/**
+ * @author alanrw
+ */
+public class Utils {
+ // From http://stackoverflow.com/questions/163360/regular-expresion-to-match-urls-in-java
+ public static String URL_PATTERN = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
+ public static final String LONG_STRING = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+ public static final String SHORT_STRING = "XXX";
+
+ private FileManager fileManager;
+ private ServiceDescriptionRegistry registry;
+ private ComponentFactory factory;
+ private ComponentPreference prefs;
+ private ComponentServiceIcon icon;
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setIcon(ComponentServiceIcon icon) {
+ this.icon = icon;
+ }
+
+ public void setPrefs(ComponentPreference prefs) {
+ this.prefs = prefs;
+ }
+
+ public void setRegistry(ServiceDescriptionRegistry registry) {
+ this.registry = registry;
+ }
+
+ public void refreshComponentServiceProvider(Configuration config) {
+ ComponentServiceProvider provider = new ComponentServiceProvider(
+ factory, prefs, icon, this);
+ provider.configure(config);
+ registry.removeServiceDescriptionProvider(provider);
+ registry.addServiceDescriptionProvider(provider);
+ }
+
+ public void removeComponentServiceProvider(Configuration config) {
+ ComponentServiceProvider provider = new ComponentServiceProvider(
+ factory, prefs, icon, this);
+ provider.configure(config);
+ registry.removeServiceDescriptionProvider(provider);
+ }
+
+ public boolean dataflowIsComponent(WorkflowBundle d) {
+ if (d == null)
+ return false;
+ Object dataflowSource = fileManager.getDataflowSource(d);
+ return dataflowSource instanceof Version.ID;// FIXME Really?
+ }
+
+ public boolean currentDataflowIsComponent() {
+ return dataflowIsComponent(fileManager.getCurrentDataflow());
+ }
+
+ public static boolean isComponentActivity(Object obj) {
+ if (obj == null || !(obj instanceof Activity))
+ return false;
+ Configuration cfg = ((Activity) obj).getConfiguration();
+ return cfg != null && ACTIVITY_URI.equals(cfg.getType());
+ }
+
+ private static final Pattern SANITIZER_RE = Pattern
+ .compile("[^a-zA-Z0-9]+");
+ private static final Pattern SUFFIXED_RE = Pattern
+ .compile("^(.+)_([0-9]+)$");
+
+ /**
+ * Pick a name that is unique within the context set. This is done by
+ * appending "<tt>_<i>n</i></tt>" as necessary, where <tt><i>n</i></tt> is a
+ * number.
+ *
+ * @param name
+ * The suggested name; this is always checked first.
+ * @param context
+ * The set of things that the name will have to be unique within.
+ * @return A name that is definitely not the name of anything in the given
+ * set.
+ */
+ public static String uniqueName(String name, NamedSet<? extends Named> context) {
+ String candidate = SANITIZER_RE.matcher(name).replaceAll("_");
+ if (context.getByName(candidate) == null)
+ return candidate;
+ int counter = 0;
+ String prefix = candidate;
+ Matcher m = SUFFIXED_RE.matcher(candidate);
+ if (m.matches()) {
+ prefix = m.group(1);
+ counter = Integer.parseInt(m.group(2));
+ }
+ do {
+ candidate = prefix + "_" + (++counter);
+ } while (context.getByName(candidate) != null);
+ return candidate;
+ }
+}