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/03/20 15:23:00 UTC
[46/51] [abbrv] [partial] incubator-taverna-workbench git commit:
taverna-workbench-* -> taverna-*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerImpl.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerImpl.java
new file mode 100644
index 0000000..4c03dbe
--- /dev/null
+++ b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerImpl.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.colour;
+
+import static java.awt.Color.WHITE;
+import static java.awt.Color.decode;
+
+import java.awt.Color;
+import java.util.HashMap;
+import java.util.Map;
+
+import uk.org.taverna.configuration.AbstractConfigurable;
+import uk.org.taverna.configuration.ConfigurationManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+
+/**
+ * A factory class that determines the colour that a Colourable UI component
+ * should be displayed as, according to a schema configured by the user.
+ *
+ * @author Stuart Owen
+ * @author Ian Dunlop
+ * @see Colourable
+ */
+public class ColourManagerImpl extends AbstractConfigurable implements
+ ColourManager {
+ // Names of things that may be coloured
+ private static final String WORKFLOW_PORT_OBJECT = "uk.org.taverna.scufl2.api.port.WorkflowPort";
+ private static final String PROCESSOR_PORT_OBJECT = "uk.org.taverna.scufl2.api.port.ProcessorPort";
+ private static final String PROCESSOR_OBJECT = "uk.org.taverna.scufl2.api.core.Processor";
+ private static final String MERGE_OBJECT = "net.sf.taverna.t2.workflowmodel.Merge";
+ private static final String NONEXECUTABLE_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/nonExecutable";
+ private static final String XML_SPLITTER_OUT_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/xml-splitter/out";
+ private static final String XML_SPLITTER_IN_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/xml-splitter/in";
+ private static final String LOCALWORKER_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/localworker";
+ private static final String WSDL_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/wsdl";
+ private static final String CONSTANT_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/constant";
+ private static final String SOAPLAB_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/soaplab";
+ private static final String RSHELL_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/rshell";
+ private static final String NESTED_WORKFLOW = "http://ns.taverna.org.uk/2010/activity/nested-workflow";
+ private static final String MOBY_PARSER_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/biomoby/parser";
+ private static final String MOBY_OBJECT_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/biomoby/object";
+ private static final String MOBY_SERVICE_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/biomoby/service";
+ private static final String BIOMART_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/biomart";
+ private static final String BEANSHELL_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/beanshell";
+ private static final String APICONSUMER_ACTIVITY = "http://ns.taverna.org.uk/2010/activity/apiconsumer";
+
+ // Names of colours used
+ private static final String burlywood2 = "#deb887";
+ private static final String darkgoldenrod1 = "#ffb90f";
+ private static final String darkolivegreen3 = "#a2cd5a";
+ private static final String gold = "#ffd700";
+ private static final String grey = "#777777";
+ private static final String lightcyan2 = "#d1eeee";
+ private static final String lightgoldenrodyellow = "#fafad2";
+ // light purple non standard
+ private static final String lightpurple = "#ab92ea";
+ private static final String lightsteelblue = "#b0c4de";
+ private static final String mediumorchid2 = "#d15fee";
+ private static final String palegreen = "#98fb98";
+ private static final String pink = "#ffc0cb";
+ private static final String purplish = "#8070ff";
+ // ShadedLabel.Orange
+ private static final String shadedorange = "#eece8f";
+ // ShadedLabel.Green
+ private static final String shadedgreen = "#a1c69d";
+ // slightly lighter than the real steelblue4
+ private static final String steelblue4 = "#648faa";
+ private static final String turquoise = "#77aadd";
+ private static final String white = "#ffffff";
+
+ private Map<String, String> defaultPropertyMap;
+ private Map<Object, Color> cachedColours;
+
+ public ColourManagerImpl(ConfigurationManager configurationManager) {
+ super(configurationManager);
+ initialiseDefaults();
+ }
+
+ @Override
+ public String getCategory() {
+ return "colour";
+ }
+
+ @Override
+ public Map<String, String> getDefaultPropertyMap() {
+ if (defaultPropertyMap == null)
+ initialiseDefaults();
+ return defaultPropertyMap;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "Colour Management";
+ }
+
+ @Override
+ public String getFilePrefix() {
+ return "ColourManagement";
+ }
+
+ /**
+ * Unique identifier for this ColourManager
+ */
+ @Override
+ public String getUUID() {
+ return "a2148420-5967-11dd-ae16-0800200c9a66";
+ }
+
+ private void initialiseDefaults() {
+ defaultPropertyMap = new HashMap<>();
+ cachedColours = new HashMap<>();
+
+ defaultPropertyMap.put(APICONSUMER_ACTIVITY, palegreen);
+ defaultPropertyMap.put(BEANSHELL_ACTIVITY, burlywood2);
+ defaultPropertyMap.put(BIOMART_ACTIVITY, lightcyan2);
+ defaultPropertyMap.put(CONSTANT_ACTIVITY, lightsteelblue);
+ defaultPropertyMap.put(LOCALWORKER_ACTIVITY, mediumorchid2);
+ defaultPropertyMap.put(MOBY_SERVICE_ACTIVITY, darkgoldenrod1);
+ defaultPropertyMap.put(MOBY_OBJECT_ACTIVITY, gold);
+ defaultPropertyMap.put(MOBY_PARSER_ACTIVITY, white);
+ defaultPropertyMap.put(NESTED_WORKFLOW, pink);
+ defaultPropertyMap.put(RSHELL_ACTIVITY, steelblue4);
+ defaultPropertyMap.put(SOAPLAB_ACTIVITY, lightgoldenrodyellow);
+ defaultPropertyMap.put(WSDL_ACTIVITY, darkolivegreen3);
+ defaultPropertyMap.put(XML_SPLITTER_IN_ACTIVITY, lightpurple);
+ defaultPropertyMap.put(XML_SPLITTER_OUT_ACTIVITY, lightpurple);
+
+ defaultPropertyMap.put(NONEXECUTABLE_ACTIVITY, grey);
+
+ defaultPropertyMap.put(MERGE_OBJECT, turquoise);
+ defaultPropertyMap.put(PROCESSOR_OBJECT, shadedgreen);
+ defaultPropertyMap.put(PROCESSOR_PORT_OBJECT, purplish);
+ defaultPropertyMap.put(WORKFLOW_PORT_OBJECT, shadedorange);
+ }
+
+ @Override
+ public Color getPreferredColour(String itemKey) {
+ Color colour = cachedColours.get(itemKey);
+ if (colour == null) {
+ String colourString = (String) getProperty(itemKey);
+ colour = colourString == null ? WHITE : decode(colourString);
+ cachedColours.put(itemKey, colour);
+ }
+ return colour;
+ }
+
+ @Override
+ public void setPreferredColour(String itemKey, Color colour) {
+ cachedColours.put(itemKey, colour);
+ }
+
+ @Override
+ public void restoreDefaults() {
+ super.restoreDefaults();
+ if (cachedColours == null)
+ cachedColours = new HashMap<>();
+ else
+ cachedColours.clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/mimetype/MimeTypeManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/mimetype/MimeTypeManagerImpl.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/mimetype/MimeTypeManagerImpl.java
new file mode 100644
index 0000000..0ff6c65
--- /dev/null
+++ b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/mimetype/MimeTypeManagerImpl.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.mimetype;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sf.taverna.t2.workbench.configuration.mimetype.MimeTypeManager;
+import uk.org.taverna.configuration.AbstractConfigurable;
+import uk.org.taverna.configuration.ConfigurationManager;
+
+public class MimeTypeManagerImpl extends AbstractConfigurable implements
+ MimeTypeManager {
+ /**
+ * Constructs a new <code>MimeTypeManagerImpl</code>.
+ *
+ * @param configurationManager
+ */
+ public MimeTypeManagerImpl(ConfigurationManager configurationManager) {
+ super(configurationManager);
+ }
+
+ @Override
+ public String getCategory() {
+ return "Mime Type";
+ }
+
+ @Override
+ public Map<String, String> getDefaultPropertyMap() {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("text/plain", "Plain Text");
+ map.put("text/xml", "XML Text");
+ map.put("text/html", "HTML Text");
+ map.put("text/rtf", "Rich Text Format");
+ map.put("text/x-graphviz", "Graphviz Dot File");
+ map.put("image/png", "PNG Image");
+ map.put("image/jpeg", "JPEG Image");
+ map.put("image/gif", "GIF Image");
+ map.put("application/octet-stream", "Binary Data");
+ map.put("application/zip", "Zip File");
+ map.put("chemical/x-swissprot", "SWISSPROT Flat File");
+ map.put("chemical/x-embl-dl-nucleotide", "EMBL Flat File");
+ map.put("chemical/x-ppd", "PPD File");
+ map.put("chemical/seq-aa-genpept", "Genpept Protein");
+ map.put("chemical/seq-na-genbank", "Genbank Nucleotide");
+ map.put("chemical/x-pdb", "PDB 3D Structure File");
+ return map;
+ }
+
+ @Override
+ public String getUUID() {
+ return "b9277fa0-5967-11dd-ae16-0800200c9a66";
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "Mime Type Manager";
+ }
+
+ @Override
+ public String getFilePrefix() {
+ return "MimeTypeManagerImpl";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/T2ConfigurationFrameImpl.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/T2ConfigurationFrameImpl.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/T2ConfigurationFrameImpl.java
new file mode 100644
index 0000000..4910f78
--- /dev/null
+++ b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/T2ConfigurationFrameImpl.java
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.ui;
+
+import static javax.swing.JSplitPane.HORIZONTAL_SPLIT;
+import static net.sf.taverna.t2.workbench.helper.HelpCollator.registerComponent;
+import static net.sf.taverna.t2.workbench.helper.Helper.setKeyCatcher;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.ListModel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import net.sf.taverna.t2.workbench.configuration.workbench.ui.T2ConfigurationFrame;
+
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.configuration.ConfigurationUIFactory;
+
+public class T2ConfigurationFrameImpl implements T2ConfigurationFrame {
+ private static Logger logger = Logger.getLogger(T2ConfigurationFrameImpl.class);
+ private static final int FRAME_WIDTH = 700;
+ private static final int FRAME_HEIGHT = 450;
+
+ private List<ConfigurationUIFactory> configurationUIFactories = new ArrayList<>();
+
+ private JFrame frame;
+ private JSplitPane splitPane;
+ private JList<ConfigurableItem> list;
+
+ public T2ConfigurationFrameImpl() {
+ }
+
+ @Override
+ public void showFrame() {
+ getFrame().setVisible(true);
+ }
+
+ @Override
+ public void showConfiguration(String name) {
+ showFrame();
+ ListModel<ConfigurableItem> lm = list.getModel();
+ for (int i = 0; i < lm.getSize(); i++)
+ if (lm.getElementAt(i).toString().equals(name)) {
+ list.setSelectedIndex(i);
+ break;
+ }
+ }
+
+ private JFrame getFrame() {
+ if (frame != null)
+ return frame;
+
+ frame = new JFrame();
+ setKeyCatcher(frame);
+ registerComponent(frame);
+ frame.setLayout(new BorderLayout());
+
+ /*
+ * Split pane to hold list of properties (on the left) and their
+ * configurable options (on the right)
+ */
+ splitPane = new JSplitPane(HORIZONTAL_SPLIT);
+ splitPane.setBorder(null);
+
+ list = getConfigurationList();
+ JScrollPane jspList = new JScrollPane(list);
+ jspList.setBorder(new EmptyBorder(5, 5, 5, 5));
+ jspList.setMinimumSize(new Dimension(150,
+ jspList.getPreferredSize().height));
+
+ splitPane.setLeftComponent(jspList);
+ splitPane.setRightComponent(new JPanel());
+ splitPane.setDividerSize(1);
+
+ // select first item if one exists
+ if (list.getModel().getSize() > 0)
+ list.setSelectedValue(list.getModel().getElementAt(0), true);
+
+ frame.add(splitPane);
+ frame.setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
+ return frame;
+ }
+
+ private JList<ConfigurableItem> getConfigurationList() {
+ if (list != null)
+ return list;
+
+ list = new JList<>();
+ list.addListSelectionListener(new ListSelectionListener() {
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ if (list.getSelectedValue() instanceof ConfigurableItem) {
+ ConfigurableItem item = (ConfigurableItem) list
+ .getSelectedValue();
+ setMainPanel(item.getPanel());
+ }
+
+ /*
+ * Keep the split pane's divider at its current position - but
+ * looks ugly. The problem with divider moving from its current
+ * position after selecting an item from the list on the left is
+ * that the right hand side panels are loaded dynamically and it
+ * seems there is nothing we can do about it - it's just the
+ * JSplitPane's behaviour
+ */
+ // splitPane.setDividerLocation(splitPane.getLastDividerLocation());
+ }
+ });
+ list.setListData(getListItems());
+ return list;
+ }
+
+ private void setMainPanel(JPanel panel) {
+ panel.setBorder(new EmptyBorder(15, 15, 15, 15));
+ splitPane.setRightComponent(panel);
+ }
+
+ public void setConfigurationUIFactories(
+ List<ConfigurationUIFactory> configurationUIFactories) {
+ this.configurationUIFactories = configurationUIFactories;
+ }
+
+ private ConfigurableItem[] getListItems() {
+ List<ConfigurableItem> arrayList = new ArrayList<>();
+ for (ConfigurationUIFactory fac : configurationUIFactories) {
+ String name = fac.getConfigurable().getDisplayName();
+ if (name != null) {
+ logger.info("Adding configurable for name: " + name);
+ arrayList.add(new ConfigurableItem(fac));
+ } else {
+ logger.warn("The configurable " + fac.getConfigurable().getClass()
+ + " has a null name");
+ }
+ }
+ // Sort the list alphabetically
+ ConfigurableItem[] array = arrayList.toArray(new ConfigurableItem[0]);
+ Arrays.sort(array, new Comparator<ConfigurableItem>() {
+ @Override
+ public int compare(ConfigurableItem item1, ConfigurableItem item2) {
+ return item1.toString().compareToIgnoreCase(item2.toString());
+ }
+ });
+ return array;
+ }
+
+ public void update(Object service, Map<?, ?> properties) {
+ getConfigurationList().setListData(getListItems());
+ if (frame != null) {
+ frame.revalidate();
+ frame.repaint();
+ // select first item if one exists
+ if (list.getModel().getSize() > 0)
+ list.setSelectedValue(list.getModel().getElementAt(0), true);
+ }
+ }
+
+ class ConfigurableItem {
+ private final ConfigurationUIFactory factory;
+
+ public ConfigurableItem(ConfigurationUIFactory factory) {
+ this.factory = factory;
+ }
+
+ public JPanel getPanel() {
+ return factory.getConfigurationPanel();
+ }
+
+ @Override
+ public String toString() {
+ return factory.getConfigurable().getDisplayName();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchConfigurationMenu.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchConfigurationMenu.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchConfigurationMenu.java
new file mode 100644
index 0000000..453f0c0
--- /dev/null
+++ b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchConfigurationMenu.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.ui;
+
+import java.awt.event.ActionEvent;
+import java.net.URI;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+
+import net.sf.taverna.t2.ui.menu.AbstractMenuAction;
+import net.sf.taverna.t2.workbench.configuration.workbench.ui.T2ConfigurationFrame;
+
+public class WorkbenchConfigurationMenu extends AbstractMenuAction {
+ private static final String MAC_OS_X = "Mac OS X";
+
+ private T2ConfigurationFrame t2ConfigurationFrame;
+
+ public WorkbenchConfigurationMenu() {
+ super(URI.create("http://taverna.sf.net/2008/t2workbench/menu#preferences"),
+ 100);
+ }
+
+ @SuppressWarnings("serial")
+ @Override
+ protected Action createAction() {
+ return new AbstractAction("Preferences") {
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ t2ConfigurationFrame.showFrame();
+ }
+ };
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return !MAC_OS_X.equalsIgnoreCase(System.getProperty("os.name"));
+ }
+
+ public void setT2ConfigurationFrame(T2ConfigurationFrame t2ConfigurationFrame) {
+ this.t2ConfigurationFrame = t2ConfigurationFrame;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchPreferencesSection.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchPreferencesSection.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchPreferencesSection.java
new file mode 100644
index 0000000..d131ac3
--- /dev/null
+++ b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ui/WorkbenchPreferencesSection.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.ui;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.ui.menu.AbstractMenuSection;
+
+public class WorkbenchPreferencesSection extends AbstractMenuSection {
+ private static final URI FILE_MENU = URI
+ .create("http://taverna.sf.net/2008/t2workbench/menu#file");
+ private static final URI PREFERENCES_MENU_ITEM = URI
+ .create("http://taverna.sf.net/2008/t2workbench/menu#preferences");
+
+ public WorkbenchPreferencesSection() {
+ super(FILE_MENU, 100, PREFERENCES_MENU_ITEM);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent b/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
new file mode 100644
index 0000000..3b51dd4
--- /dev/null
+++ b/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
@@ -0,0 +1,2 @@
+net.sf.taverna.t2.workbench.ui.impl.configuration.ui.WorkbenchPreferencesSection
+net.sf.taverna.t2.workbench.ui.impl.configuration.ui.WorkbenchConfigurationMenu
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.configuration.ConfigurationUIFactory
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.configuration.ConfigurationUIFactory b/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.configuration.ConfigurationUIFactory
new file mode 100644
index 0000000..4af55ec
--- /dev/null
+++ b/taverna-configuration-impl/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.configuration.ConfigurationUIFactory
@@ -0,0 +1 @@
+net.sf.taverna.t2.workbench.ui.impl.configuration.WorkbenchConfigurationUIFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context-osgi.xml b/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context-osgi.xml
new file mode 100644
index 0000000..29aea44
--- /dev/null
+++ b/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context-osgi.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="t2ConfigurationFrame" interface="net.sf.taverna.t2.workbench.configuration.workbench.ui.T2ConfigurationFrame" />
+
+ <service ref="WorkbenchConfigurationUIFactory" interface="uk.org.taverna.configuration.ConfigurationUIFactory" />
+
+ <service ref="WorkbenchPreferencesSection" auto-export="interfaces" />
+ <service ref="WorkbenchConfigurationMenu" auto-export="interfaces" />
+
+ <service ref="ColourManager" interface="net.sf.taverna.t2.workbench.configuration.colour.ColourManager" />
+ <service ref="WorkbenchConfiguration" interface="net.sf.taverna.t2.workbench.configuration.workbench.WorkbenchConfiguration" />
+ <service ref="MimeTypeManager" interface="net.sf.taverna.t2.workbench.configuration.mimetype.MimeTypeManager" />
+
+ <reference id="configurationManager" interface="uk.org.taverna.configuration.ConfigurationManager" />
+ <reference id="applicationConfiguration" interface="uk.org.taverna.configuration.app.ApplicationConfiguration" />
+
+ <list id="configurationUIFactories" interface="uk.org.taverna.configuration.ConfigurationUIFactory" cardinality="0..N">
+ <listener ref="t2ConfigurationFrame" bind-method="update" unbind-method="update"/>
+ </list>
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context.xml
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context.xml b/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context.xml
new file mode 100644
index 0000000..40da7fd
--- /dev/null
+++ b/taverna-configuration-impl/src/main/resources/META-INF/spring/configuration-impl-context.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="t2ConfigurationFrame" class="net.sf.taverna.t2.workbench.ui.impl.configuration.ui.T2ConfigurationFrameImpl">
+ <property name="configurationUIFactories" ref="configurationUIFactories" />
+ </bean>
+
+ <bean id="WorkbenchConfigurationUIFactory" class="net.sf.taverna.t2.workbench.ui.impl.configuration.WorkbenchConfigurationUIFactory">
+ <property name="workbenchConfiguration">
+ <ref local="WorkbenchConfiguration"/>
+ </property>
+ </bean>
+
+ <bean id="WorkbenchPreferencesSection" class="net.sf.taverna.t2.workbench.ui.impl.configuration.ui.WorkbenchPreferencesSection" />
+ <bean id="WorkbenchConfigurationMenu" class="net.sf.taverna.t2.workbench.ui.impl.configuration.ui.WorkbenchConfigurationMenu">
+ <property name="t2ConfigurationFrame">
+ <ref local="t2ConfigurationFrame"/>
+ </property>
+ </bean>
+
+ <bean id="ColourManager" class="net.sf.taverna.t2.workbench.ui.impl.configuration.colour.ColourManagerImpl">
+ <constructor-arg ref="configurationManager"/>
+ </bean>
+ <bean id="WorkbenchConfiguration" class="net.sf.taverna.t2.workbench.ui.impl.configuration.WorkbenchConfigurationImpl">
+ <constructor-arg ref="configurationManager"/>
+ <property name="applicationConfiguration" ref="applicationConfiguration" />
+ </bean>
+ <bean id="MimeTypeManager" class="net.sf.taverna.t2.workbench.ui.impl.configuration.mimetype.MimeTypeManagerImpl">
+ <constructor-arg ref="configurationManager"/>
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java
new file mode 100644
index 0000000..1202c11
--- /dev/null
+++ b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.util.UUID;
+
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.ui.impl.configuration.colour.ColourManagerImpl;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl;
+import uk.org.taverna.configuration.impl.ConfigurationManagerImpl;
+
+public class ConfigurationManagerTest {
+
+ ConfigurationManagerImpl configurationManager;
+
+ @Before
+ public void setup() {
+ configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl());
+ }
+
+ @Test
+ public void createConfigManager() {
+ assertNotNull("Config Manager should not be null", configurationManager);
+ }
+
+ @Ignore("Hardcoded /Users/Ian") //FIXME: update test to work using File.createTempFile(...)
+ @Test
+ public void populateConfigOfColourmanager() {
+ ColourManager manager= new ColourManagerImpl(null);
+
+ manager.setProperty("colour.first", "25");
+ manager.setProperty("colour.second", "223");
+
+ configurationManager.setBaseConfigLocation(new File("/Users/Ian/scratch"));
+ try {
+ configurationManager.store(manager);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+
+ ColourManager manager2 = new ColourManagerImpl(configurationManager);
+
+ try {
+ configurationManager.populate(manager2);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ assertEquals("Properties do not match", manager2.getProperty("colour.first"), manager.getProperty("colour.first"));
+ assertEquals("Properties do not match", manager2.getProperty("colour.second"), manager.getProperty("colour.second"));
+
+
+ }
+
+ @Test
+ public void saveColoursForDummyColourable() {
+ String dummy = "";
+ ColourManager manager=new ColourManagerImpl(configurationManager);
+ manager.setProperty(dummy.getClass().getCanonicalName(), "#000000");
+
+ File f = new File(System.getProperty("java.io.tmpdir"));
+ File d = new File(f, UUID.randomUUID().toString());
+ d.mkdir();
+ configurationManager.setBaseConfigLocation(d);
+ try {
+ configurationManager.store(manager);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+
+ try {
+ configurationManager.populate(manager);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java
----------------------------------------------------------------------
diff --git a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java
new file mode 100644
index 0000000..0239ea8
--- /dev/null
+++ b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.impl.configuration.colour;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.io.File;
+import java.util.UUID;
+
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import uk.org.taverna.configuration.Configurable;
+import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl;
+import uk.org.taverna.configuration.impl.ConfigurationManagerImpl;
+
+public class ColourManagerTest {
+
+ private ConfigurationManagerImpl configurationManager;
+
+ @Before
+ public void setup() {
+ configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl());
+
+ File f = new File(System.getProperty("java.io.tmpdir"));
+ File d = new File(f, UUID.randomUUID().toString());
+ d.mkdir();
+ configurationManager.setBaseConfigLocation(d);
+ }
+
+ @Test
+ public void testGetPreferredColourEqualsWhite() throws Exception {
+ String dummy = new String();
+
+ Color c = new ColourManagerImpl(configurationManager).getPreferredColour(dummy);
+ assertEquals("The default colour should be WHITE", Color.WHITE, c);
+ }
+
+ @Test
+ public void testConfigurableness() throws Exception {
+ ColourManager manager = new ColourManagerImpl(configurationManager);
+ assertTrue(manager instanceof Configurable);
+
+ assertEquals("wrong category", "colour", manager.getCategory());
+ assertEquals("wrong name", "Colour Management", manager.getDisplayName());
+ assertEquals("wrong UUID", "a2148420-5967-11dd-ae16-0800200c9a66",
+ manager.getUUID());
+ assertNotNull("there is no default property map", manager
+ .getDefaultPropertyMap());
+ }
+
+ @Test
+ public void saveAsWrongArrayType() throws Exception {
+ String dummy = "";
+ ColourManager manager = new ColourManagerImpl(configurationManager);
+ manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff");
+
+ File baseLoc = File.createTempFile("test", "scratch");
+ baseLoc.delete();
+ assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir());
+ configurationManager.setBaseConfigLocation(baseLoc);
+ configurationManager.store(manager);
+ configurationManager.populate(manager);
+ manager.getPreferredColour(dummy);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/pom.xml b/taverna-contextual-views-api/pom.xml
new file mode 100644
index 0000000..d0f10a1
--- /dev/null
+++ b/taverna-contextual-views-api/pom.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna.workbench</groupId>
+ <artifactId>taverna-workbench</artifactId>
+ <version>3.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>taverna-contextual-views-api</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Taverna Contextual Views API</name>
+ <description>Contextual views for the activities</description>
+ <dependencies>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-activity-icons-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-activity-palette-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-configuration-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-edits-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-file-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-helper-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-workbench-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-ui</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-observer</artifactId>
+ <version>${taverna.engine.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.language</groupId>
+ <artifactId>taverna-scufl2-api</artifactId>
+ <version>${taverna.language.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.osgi</groupId>
+ <artifactId>taverna-services-api</artifactId>
+ <version>${taverna.osgi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java
new file mode 100644
index 0000000..4d2fcff
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.actions.activity;
+
+import java.util.List;
+import java.util.WeakHashMap;
+
+import javax.swing.AbstractAction;
+import javax.swing.JDialog;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.file.events.ClosingDataflowEvent;
+import net.sf.taverna.t2.workbench.file.events.FileManagerEvent;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.common.Scufl2Tools;
+import uk.org.taverna.scufl2.api.container.WorkflowBundle;
+import uk.org.taverna.scufl2.api.core.Processor;
+import uk.org.taverna.scufl2.api.core.Workflow;
+import uk.org.taverna.scufl2.api.profiles.ProcessorBinding;
+import uk.org.taverna.scufl2.api.profiles.Profile;
+
+@SuppressWarnings("serial")
+public abstract class ActivityConfigurationAction extends AbstractAction {
+ private static WeakHashMap<Activity, ActivityConfigurationDialog> configurationDialogs = new WeakHashMap<>();
+ private static DataflowCloseListener listener;
+
+ protected Activity activity;
+ private final ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public ActivityConfigurationAction(Activity activity,
+ ActivityIconManager activityIconManager,
+ ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.activity = activity;
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ putValue(SMALL_ICON,
+ activityIconManager.iconForActivity(activity.getType()));
+ }
+
+ protected Activity getActivity() {
+ return activity;
+ }
+
+ protected ServiceDescription getServiceDescription() {
+ return serviceDescriptionRegistry.getServiceDescription(activity
+ .getType());
+ }
+
+ protected static void setDialog(Activity activity,
+ ActivityConfigurationDialog dialog, FileManager fileManager) {
+ if (listener == null) {
+ listener = new DataflowCloseListener();
+ /*
+ * Ensure that the DataflowCloseListener is the first notified
+ * listener. Otherwise you cannot save the configurations.
+ */
+ List<Observer<FileManagerEvent>> existingListeners = fileManager
+ .getObservers();
+ fileManager.addObserver(listener);
+ for (Observer<FileManagerEvent> observer : existingListeners)
+ if (!observer.equals(listener)) {
+ fileManager.removeObserver(observer);
+ fileManager.addObserver(observer);
+ }
+ }
+ if (configurationDialogs.containsKey(activity)) {
+ ActivityConfigurationDialog currentDialog = configurationDialogs
+ .get(activity);
+ if (!currentDialog.equals(dialog) && currentDialog.isVisible())
+ currentDialog.setVisible(false);
+ }
+ configurationDialogs.put(activity, dialog);
+ dialog.setVisible(true);
+ }
+
+ public static void clearDialog(Activity activity) {
+ if (configurationDialogs.containsKey(activity)) {
+ ActivityConfigurationDialog currentDialog = configurationDialogs
+ .get(activity);
+ if (currentDialog.isVisible())
+ currentDialog.setVisible(false);
+ configurationDialogs.remove(activity);
+ currentDialog.dispose();
+ }
+ }
+
+ protected static void clearDialog(JDialog dialog) {
+ if (configurationDialogs.containsValue(dialog)) {
+ if (dialog.isVisible())
+ dialog.setVisible(false);
+ for (Activity activity : configurationDialogs.keySet())
+ if (configurationDialogs.get(activity).equals(dialog))
+ configurationDialogs.remove(activity);
+ dialog.dispose();
+ }
+ }
+
+ public static boolean closeDialog(Activity activity) {
+ boolean closeIt = true;
+ if (configurationDialogs.containsKey(activity)) {
+ ActivityConfigurationDialog currentDialog = configurationDialogs
+ .get(activity);
+ if (currentDialog.isVisible())
+ closeIt = currentDialog.closeDialog();
+ if (closeIt)
+ configurationDialogs.remove(activity);
+ }
+ return closeIt;
+ }
+
+ public static ActivityConfigurationDialog getDialog(Activity activity) {
+ return configurationDialogs.get(activity);
+ }
+
+ private static class DataflowCloseListener implements
+ Observer<FileManagerEvent> {
+ private Scufl2Tools scufl2Tools = new Scufl2Tools();
+
+ @Override
+ public void notify(Observable<FileManagerEvent> sender,
+ FileManagerEvent message) throws Exception {
+ if (message instanceof ClosingDataflowEvent) {
+ ClosingDataflowEvent closingDataflowEvent = (ClosingDataflowEvent) message;
+ if (closingDataflowEvent.isAbortClose())
+ return;
+ closingDataflow(closingDataflowEvent,
+ ((ClosingDataflowEvent) message).getDataflow());
+ }
+ }
+
+ private void closingDataflow(ClosingDataflowEvent event,
+ WorkflowBundle bundle) {
+ Profile profile = bundle.getMainProfile();
+ for (Workflow workflow : bundle.getWorkflows())
+ for (Processor p : workflow.getProcessors()) {
+ ProcessorBinding processorBinding = scufl2Tools
+ .processorBindingForProcessor(p, profile);
+ Activity activity = processorBinding.getBoundActivity();
+ if (!closeDialog(activity))
+ event.setAbortClose(true);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java
new file mode 100644
index 0000000..f063c02
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.actions.activity;
+
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.common.Scufl2Tools;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+/**
+ * A contextual view specific to an Activity. Concrete subclasses must
+ * initialise the view by calling {@link #initView()}.
+ * <p>
+ * The implementation provides a view based upon the properties set in the
+ * Configuration
+ *
+ * @author Stuart Owen
+ * @author Ian Dunlop
+ *
+ * @see Activity
+ * @see ContextualView
+ */
+@SuppressWarnings("serial")
+public abstract class ActivityContextualView extends ContextualView {
+ private Activity activity;
+ private Scufl2Tools scufl2Tools = new Scufl2Tools();
+
+ /**
+ * Constructs an instance of the view.
+ * <p>
+ * The constructor parameter for the implementation of this class should
+ * define the specific Activity type itself.
+ *
+ * @param activity
+ */
+ protected ActivityContextualView(Activity activity) {
+ super();
+ this.activity = activity;
+ }
+
+ public Activity getActivity() {
+ return activity;
+ }
+
+ public Configuration getConfigBean() {
+ return scufl2Tools.configurationFor(activity, activity.getParent());
+ }
+
+ @Override
+ public abstract void refreshView();
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java
new file mode 100644
index 0000000..de3df33
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.actions.activity;
+
+import static net.sf.taverna.t2.lang.ui.HtmlUtils.buildTableOpeningTag;
+import static net.sf.taverna.t2.lang.ui.HtmlUtils.createEditorPane;
+import static net.sf.taverna.t2.lang.ui.HtmlUtils.getHtmlHead;
+import static net.sf.taverna.t2.lang.ui.HtmlUtils.panelForHtml;
+
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+@SuppressWarnings("serial")
+public abstract class HTMLBasedActivityContextualView extends ActivityContextualView {
+ private static final String BEANSHELL_URI = "http://ns.taverna.org.uk/2010/activity/beanshell";
+ private static final String LOCALWORKER_URI = "http://ns.taverna.org.uk/2010/activity/localworker";
+ private JEditorPane editorPane;
+ private final ColourManager colourManager;
+
+ public HTMLBasedActivityContextualView(Activity activity, ColourManager colourManager) {
+ super(activity);
+ this.colourManager = colourManager;
+ initView();
+ }
+
+ @Override
+ public JComponent getMainFrame() {
+ editorPane = createEditorPane(buildHtml());
+ return panelForHtml(editorPane);
+ }
+
+ private String buildHtml() {
+ StringBuilder html = new StringBuilder(getHtmlHead(getBackgroundColour()));
+ html.append(buildTableOpeningTag());
+ html.append("<tr><th colspan=\"2\">").append(getViewTitle()).append("</th></tr>");
+ html.append(getRawTableRowsHtml()).append("</table>");
+ html.append("</body></html>");
+ return html.toString();
+ }
+
+ protected abstract String getRawTableRowsHtml();
+
+ public String getBackgroundColour() {
+ String activityType = getActivity().getType().toString();
+ if (LOCALWORKER_URI.equals(activityType))
+ if (getConfigBean().getJson().get("isAltered").booleanValue())
+ return (String) colourManager.getProperty(BEANSHELL_URI);
+ String colour = (String) colourManager.getProperty(activityType);
+ return colour == null ? "#ffffff" : colour;
+ }
+
+ /**
+ * Update the html view with the latest information in the configuration
+ * bean
+ */
+ @Override
+ public void refreshView() {
+ editorPane.setText(buildHtml());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java
new file mode 100644
index 0000000..6b0245c
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (C) 2008 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 net.sf.taverna.t2.workbench.ui.views.contextualviews;
+
+import java.net.URI;
+
+import javax.swing.Action;
+
+import uk.org.taverna.scufl2.api.core.Processor;
+
+/**
+ * SPI for adding dispatch stack layers to a processor, such as
+ * {@link net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.Loop}.
+ * <p>
+ * Buttons or similar will be added in the processor contextual view.
+ *
+ * @author Stian Soiland-Reyes
+ */
+public interface AddLayerFactorySPI {
+ boolean canAddLayerFor(Processor proc);
+
+ Action getAddLayerActionFor(Processor proc);
+
+ boolean canCreateLayerClass(URI dispatchLayerType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java
new file mode 100644
index 0000000..45efaab
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (C) 2007 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 net.sf.taverna.t2.workbench.ui.views.contextualviews;
+
+import static java.awt.BorderLayout.CENTER;
+
+import java.awt.BorderLayout;
+import java.awt.Frame;
+
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+
+/**
+ * An abstract class defining the base container to hold a contextual view over
+ * Dataflow element.
+ * <p>
+ * The specific implementation of this class to support a given dataflow element
+ * needs to implement the {@link #getMainFrame()} and {@link #getViewTitle()}.
+ * <p>
+ * If a view is associated with an action handler to configure this component,
+ * then the {@link #getConfigureAction(Frame) getConfigureAction} handler must
+ * be over-ridden. If this returns null then the configure button is left
+ * disabled and it is not possible to configure the element.
+ *
+ * @author Stuart Owen
+ * @author Ian Dunlop
+ * @author Alan R Williams
+ */
+@SuppressWarnings("serial")
+public abstract class ContextualView extends JPanel {
+ /**
+ * When implemented, this method should define the main frame that is placed
+ * in this container, and provides a static view of the Dataflow element.
+ *
+ * @return a JComponent that represents the dataflow element.
+ */
+ public abstract JComponent getMainFrame();
+
+ /**
+ * @return a String providing a title for the view
+ */
+ public abstract String getViewTitle();
+
+ /**
+ * Allows the item to be configured, but returning an action handler that
+ * will be invoked when selecting to configure. By default this is provided
+ * by a button.
+ * <p>
+ * If there is no ability to configure the given item, then this should
+ * return null.
+ *
+ * @param owner
+ * the owning dialog to be used when displaying dialogues for
+ * configuration options
+ * @return an action that allows the element being viewed to be configured.
+ */
+ public Action getConfigureAction(Frame owner) {
+ return null;
+ }
+
+ /**
+ * This <i>must</i> be called by any sub-classes after they have initialised
+ * their own view since it gets their main panel and adds it to the main
+ * contextual view. If you don't do this you will get a very empty frame
+ * popping up!
+ */
+ public void initView() {
+ setLayout(new BorderLayout());
+ add(getMainFrame(), CENTER);
+ setName(getViewTitle());
+ }
+
+ public abstract void refreshView();
+
+ public abstract int getPreferredPosition();
+
+ public static String getTextFromDepth(String kind, Integer depth) {
+ String labelText = "The last prediction said the " + kind;
+ if (depth == null) {
+ labelText += " would not transmit a value";
+ } else if (depth == -1) {
+ labelText += " was invalid/unpredicted";
+ } else if (depth == 0) {
+ labelText += " would carry a single value";
+ } else {
+ labelText += " would carry a list of depth " + depth;
+ }
+ return labelText;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52fd79dd/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java
----------------------------------------------------------------------
diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java
new file mode 100644
index 0000000..c4c77b7
--- /dev/null
+++ b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java
@@ -0,0 +1,474 @@
+package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity;
+
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Cursor.DEFAULT_CURSOR;
+import static java.awt.Cursor.WAIT_CURSOR;
+import static java.awt.Cursor.getPredefinedCursor;
+import static java.lang.Math.max;
+import static javax.swing.JOptionPane.CANCEL_OPTION;
+import static javax.swing.JOptionPane.NO_OPTION;
+import static javax.swing.JOptionPane.YES_NO_CANCEL_OPTION;
+import static javax.swing.JOptionPane.YES_NO_OPTION;
+import static javax.swing.JOptionPane.YES_OPTION;
+import static javax.swing.JOptionPane.showConfirmDialog;
+import static net.sf.taverna.t2.workbench.MainWindow.getMainWindow;
+import static net.sf.taverna.t2.workbench.helper.Helper.showHelp;
+import static net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction.clearDialog;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import net.sf.taverna.t2.lang.observer.Observable;
+import net.sf.taverna.t2.lang.observer.Observer;
+import net.sf.taverna.t2.lang.ui.DeselectingButton;
+import net.sf.taverna.t2.workbench.edits.CompoundEdit;
+import net.sf.taverna.t2.workbench.edits.Edit;
+import net.sf.taverna.t2.workbench.edits.EditException;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.edits.EditManager.DataFlowRedoEvent;
+import net.sf.taverna.t2.workbench.edits.EditManager.DataFlowUndoEvent;
+import net.sf.taverna.t2.workbench.edits.EditManager.EditManagerEvent;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+import net.sf.taverna.t2.workflow.edits.AddChildEdit;
+import net.sf.taverna.t2.workflow.edits.AddProcessorInputPortEdit;
+import net.sf.taverna.t2.workflow.edits.AddProcessorOutputPortEdit;
+import net.sf.taverna.t2.workflow.edits.ChangeDepthEdit;
+import net.sf.taverna.t2.workflow.edits.ChangeGranularDepthEdit;
+import net.sf.taverna.t2.workflow.edits.ChangeJsonEdit;
+import net.sf.taverna.t2.workflow.edits.RemoveChildEdit;
+import net.sf.taverna.t2.workflow.edits.RemoveProcessorInputPortEdit;
+import net.sf.taverna.t2.workflow.edits.RemoveProcessorOutputPortEdit;
+import net.sf.taverna.t2.workflow.edits.RenameEdit;
+
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.common.Scufl2Tools;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+import uk.org.taverna.scufl2.api.container.WorkflowBundle;
+import uk.org.taverna.scufl2.api.core.Processor;
+import uk.org.taverna.scufl2.api.core.Workflow;
+import uk.org.taverna.scufl2.api.port.ActivityPort;
+import uk.org.taverna.scufl2.api.port.InputActivityPort;
+import uk.org.taverna.scufl2.api.port.InputProcessorPort;
+import uk.org.taverna.scufl2.api.port.OutputActivityPort;
+import uk.org.taverna.scufl2.api.port.OutputProcessorPort;
+import uk.org.taverna.scufl2.api.profiles.ProcessorBinding;
+import uk.org.taverna.scufl2.api.profiles.ProcessorInputPortBinding;
+import uk.org.taverna.scufl2.api.profiles.ProcessorOutputPortBinding;
+import uk.org.taverna.scufl2.api.profiles.Profile;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+@SuppressWarnings("serial")
+public class ActivityConfigurationDialog extends HelpEnabledDialog {
+ private enum PortType {
+ INPUT, OUTPUT
+ }
+
+ protected static Logger logger = Logger.getLogger(ActivityConfigurationDialog.class);
+ private static final Scufl2Tools scufl2Tools = new Scufl2Tools();
+
+ private final EditManager editManager;
+
+ private Activity activity;
+ private ActivityConfigurationPanel panel;
+ protected WorkflowBundle owningWorkflowBundle;
+ protected Processor owningProcessor;
+ private Observer<EditManagerEvent> observer;
+ Dimension minimalSize = null;
+ Dimension buttonPanelSize = null;
+ JPanel buttonPanel;
+ protected JButton applyButton;
+
+ public ActivityConfigurationDialog(Activity a, ActivityConfigurationPanel p,
+ EditManager editManager) {
+ super(getMainWindow(), "Configuring " + a.getClass().getSimpleName(),
+ false, null);
+ this.activity = a;
+ this.panel = p;
+ this.editManager = editManager;
+
+ owningWorkflowBundle = activity.getParent().getParent();
+ owningProcessor = findProcessor(a);
+
+ setTitle(getRelativeName(owningWorkflowBundle, activity));
+ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+ setLayout(new BorderLayout());
+
+ add(panel, BorderLayout.CENTER);
+
+ buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+ buttonPanel.setBorder(new EmptyBorder(5, 20, 5, 5));
+
+ JButton helpButton = new DeselectingButton("Help", new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ showHelp(panel);
+ }
+ });
+ buttonPanel.add(helpButton);
+
+ applyButton = new DeselectingButton("Apply", new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ /*
+ * For the moment it always does an apply as what should be
+ * happening is that the apply button only becomes available
+ * when the configuration has changed. However, many
+ * configuration panels are not set up to detected changes
+ */
+ // if (panel.isConfigurationChanged()) {
+ if (checkPanelValues())
+ applyConfiguration();
+ // } else {
+ // logger.info("Ignoring apply");
+ // }
+ }
+ });
+ buttonPanel.add(applyButton);
+
+ JButton closeButton = new DeselectingButton("Close", new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ closeDialog();
+ }
+ });
+ buttonPanel.add(closeButton);
+
+ add(buttonPanel, SOUTH);
+
+ this.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowOpened(WindowEvent e) {
+ requestFocusInWindow();
+ panel.whenOpened();
+ }
+
+ @Override
+ public void windowClosing(WindowEvent e) {
+ closeDialog();
+ }
+ });
+ pack();
+ minimalSize = getSize();
+ setLocationRelativeTo(null);
+ setResizable(true);
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ int newWidth = max(getWidth(), minimalSize.width);
+ int newHeight = max(getHeight(), minimalSize.height);
+ setSize(new Dimension(newWidth, newHeight));
+ }
+ });
+
+ observer = new Observer<EditManagerEvent>() {
+ @Override
+ public void notify(Observable<EditManagerEvent> sender, EditManagerEvent message)
+ throws Exception {
+ logger.info("sender is a " + sender.getClass().getCanonicalName());
+ logger.info("message is a " + message.getClass().getCanonicalName());
+ Edit<?> edit = message.getEdit();
+ logger.info(edit.getClass().getCanonicalName());
+ considerEdit(message, edit);
+ }
+ };
+ editManager.addObserver(observer);
+ }
+
+ private boolean checkPanelValues() {
+ boolean result = false;
+ try {
+ setCursor(getPredefinedCursor(WAIT_CURSOR));
+ result = panel.checkValues();
+ } finally {
+ setCursor(getPredefinedCursor(DEFAULT_CURSOR));
+ }
+ return result;
+ }
+
+ private void considerEdit(EditManagerEvent message, Edit<?> edit) {
+ // boolean result = false;
+ if (edit instanceof CompoundEdit) {
+ for (Edit<?> subEdit : ((CompoundEdit) edit).getChildEdits())
+ considerEdit(message, subEdit);
+ return;
+ }
+
+ Object subject = edit.getSubject();
+ if (subject == owningProcessor) {
+ // panel.reevaluate();
+ setTitle(getRelativeName(owningWorkflowBundle, activity));
+ } else if (subject == owningWorkflowBundle) {
+ for (Workflow workflow : owningWorkflowBundle.getWorkflows())
+ if (!workflow.getProcessors().contains(owningProcessor))
+ clearDialog(activity);
+ } else if (subject == activity) {
+ if (message instanceof DataFlowUndoEvent) {
+ logger.info("undo of activity edit found");
+ panel.refreshConfiguration();
+ } else if (message instanceof DataFlowRedoEvent) {
+ logger.info("redo of activity edit found");
+ panel.refreshConfiguration();
+ }
+ }
+ }
+
+ protected void configureActivity(ObjectNode json, List<ActivityPortConfiguration> inputPorts,
+ List<ActivityPortConfiguration> outputPorts) {
+ configureActivity(owningWorkflowBundle, activity, json, inputPorts, outputPorts);
+ }
+
+ public void configureActivity(WorkflowBundle workflowBundle, Activity activity,
+ ObjectNode json, List<ActivityPortConfiguration> inputPorts,
+ List<ActivityPortConfiguration> outputPorts) {
+ try {
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+ Profile profile = activity.getParent();
+ List<ProcessorBinding> processorBindings = scufl2Tools
+ .processorBindingsToActivity(activity);
+ Configuration configuration = scufl2Tools.configurationFor(activity, profile);
+ editList.add(new ChangeJsonEdit(configuration, json));
+
+ configurePorts(activity, editList, processorBindings, inputPorts, PortType.INPUT);
+ configurePorts(activity, editList, processorBindings, outputPorts, PortType.OUTPUT);
+ editManager.doDataflowEdit(workflowBundle, new CompoundEdit(editList));
+ } catch (IllegalStateException | EditException e) {
+ logger.error(e);
+ }
+ }
+
+ private void configurePorts(Activity activity, List<Edit<?>> editList,
+ List<ProcessorBinding> processorBindings,
+ List<ActivityPortConfiguration> portDefinitions, PortType portType) {
+ Set<ActivityPort> ports = new HashSet<>();
+ for (ActivityPort activityPort : portType == PortType.INPUT ? activity
+ .getInputPorts() : activity.getOutputPorts())
+ ports.add(activityPort);
+ for (ActivityPortConfiguration portDefinition : portDefinitions) {
+ String portName = portDefinition.getName();
+ int portDepth = portDefinition.getDepth();
+ int granularPortDepth = portDefinition.getGranularDepth();
+ ActivityPort activityPort = portDefinition.getActivityPort();
+ if (activityPort == null) {
+ // no activity port so add a new one
+ if (portType == PortType.INPUT)
+ createInputPort(activity, editList, processorBindings, portDefinition);
+ else
+ createOutputPort(activity, editList, processorBindings, portDefinition);
+ } else {
+ ports.remove(activityPort);
+ // check if port has changed
+ for (ProcessorBinding processorBinding : processorBindings)
+ if (portType == PortType.INPUT)
+ for (ProcessorInputPortBinding portBinding : processorBinding
+ .getInputPortBindings()) {
+ if (!portBinding.getBoundActivityPort().equals(
+ activityPort))
+ continue;
+ InputProcessorPort processorPort = portBinding
+ .getBoundProcessorPort();
+ if (!activityPort.getName().equals(portName))
+ // port name changed
+ if (processorPort.getName().equals(activityPort.getName()))
+ // default mapping so change processor port
+ editList.add(new RenameEdit<>(processorPort, portName));
+ if (!processorPort.getDepth().equals(portDepth))
+ // port depth changed
+ editList.add(new ChangeDepthEdit<>(
+ processorPort, portDepth));
+ }
+ else
+ for (ProcessorOutputPortBinding portBinding : processorBinding
+ .getOutputPortBindings()) {
+ if (!portBinding.getBoundActivityPort().equals(
+ activityPort))
+ continue;
+ OutputProcessorPort processorPort = portBinding
+ .getBoundProcessorPort();
+ if (!activityPort.getName().equals(portName))
+ // port name changed
+ if (processorPort.getName().equals(
+ activityPort.getName()))
+ // default mapping so change processor port
+ editList.add(new RenameEdit<>(
+ processorPort, portName));
+ if (!processorPort.getDepth().equals(portDepth))
+ // port depth changed
+ editList.add(new ChangeDepthEdit<>(
+ processorPort, portDepth));
+ if (!processorPort.getGranularDepth().equals(
+ granularPortDepth))
+ // port granular depth changed
+ editList.add(new ChangeGranularDepthEdit<>(
+ processorPort, granularPortDepth));
+ }
+ if (!activityPort.getName().equals(portName))
+ // port name changed
+ editList.add(new RenameEdit<>(activityPort, portName));
+ if (!activityPort.getDepth().equals(portDepth))
+ // port depth changed
+ editList.add(new ChangeDepthEdit<>(activityPort, portDepth));
+ if (activityPort instanceof OutputActivityPort) {
+ OutputActivityPort outputActivityPort = (OutputActivityPort) activityPort;
+ Integer granularDepth = outputActivityPort
+ .getGranularDepth();
+ if (granularDepth == null
+ || !granularDepth.equals(granularPortDepth))
+ // granular port depth changed
+ editList.add(new ChangeGranularDepthEdit<>(
+ outputActivityPort, granularPortDepth));
+ }
+ }
+ }
+
+ // remove any unconfigured ports
+ for (ActivityPort activityPort : ports) {
+ // remove processor ports and bindings
+ for (ProcessorBinding processorBinding : processorBindings)
+ if (portType.equals(PortType.INPUT))
+ for (ProcessorInputPortBinding portBinding : processorBinding
+ .getInputPortBindings()) {
+ if (portBinding.getBoundActivityPort().equals(activityPort)) {
+ editList.add(new RemoveProcessorInputPortEdit(processorBinding
+ .getBoundProcessor(), portBinding.getBoundProcessorPort()));
+ editList.add(new RemoveChildEdit<>(processorBinding,
+ portBinding));
+ }
+ }
+ else
+ for (ProcessorOutputPortBinding portBinding : processorBinding
+ .getOutputPortBindings())
+ if (portBinding.getBoundActivityPort().equals(activityPort)) {
+ editList.add(new RemoveProcessorOutputPortEdit(processorBinding
+ .getBoundProcessor(), portBinding.getBoundProcessorPort()));
+ editList.add(new RemoveChildEdit<>(processorBinding,
+ portBinding));
+ }
+ // remove activity port
+ editList.add(new RemoveChildEdit<Activity>(activity, activityPort));
+ }
+ }
+
+ private void createInputPort(Activity activity, List<Edit<?>> editList,
+ List<ProcessorBinding> processorBindings,
+ ActivityPortConfiguration portDefinition) {
+ InputActivityPort actPort = new InputActivityPort(null,
+ portDefinition.getName());
+ actPort.setDepth(portDefinition.getDepth());
+ // add port to activity
+ editList.add(new AddChildEdit<>(activity, actPort));
+ for (ProcessorBinding processorBinding : processorBindings) {
+ Processor processor = processorBinding.getBoundProcessor();
+ // add a new processor port
+ InputProcessorPort procPort = new InputProcessorPort();
+ procPort.setName(portDefinition.getName());
+ procPort.setDepth(portDefinition.getDepth());
+ editList.add(new AddProcessorInputPortEdit(processor, procPort));
+ // add a new port binding
+ ProcessorInputPortBinding binding = new ProcessorInputPortBinding();
+ binding.setBoundProcessorPort(procPort);
+ binding.setBoundActivityPort(actPort);
+ editList.add(new AddChildEdit<>(processorBinding, binding));
+ }
+ }
+
+ private void createOutputPort(Activity activity, List<Edit<?>> editList,
+ List<ProcessorBinding> processorBindings,
+ ActivityPortConfiguration portDefinition) {
+ OutputActivityPort actPort = new OutputActivityPort(null,
+ portDefinition.getName());
+ actPort.setDepth(portDefinition.getDepth());
+ actPort.setGranularDepth(portDefinition.getGranularDepth());
+ // add port to activity
+ editList.add(new AddChildEdit<Activity>(activity, actPort));
+ for (ProcessorBinding processorBinding : processorBindings) {
+ Processor processor = processorBinding.getBoundProcessor();
+ // add a new processor port
+ OutputProcessorPort procPort = new OutputProcessorPort();
+ procPort.setName(portDefinition.getName());
+ procPort.setDepth(portDefinition.getDepth());
+ procPort.setGranularDepth(portDefinition.getGranularDepth());
+ editList.add(new AddProcessorOutputPortEdit(processor, procPort));
+ // add a new port binding
+ ProcessorOutputPortBinding binding = new ProcessorOutputPortBinding();
+ binding.setBoundProcessorPort(procPort);
+ binding.setBoundActivityPort(actPort);
+ editList.add(new AddChildEdit<>(processorBinding, binding));
+ }
+ }
+
+ protected static Processor findProcessor(Activity activity) {
+ for (ProcessorBinding processorBinding : scufl2Tools
+ .processorBindingsToActivity(activity))
+ return processorBinding.getBoundProcessor();
+ return null;
+ }
+
+ public static String getRelativeName(WorkflowBundle workflowBundle, Activity activity) {
+ StringBuilder relativeName = new StringBuilder("");
+ if (workflowBundle != null) {
+ Workflow workflow = workflowBundle.getMainWorkflow();
+ if (workflow != null) {
+ relativeName.append(workflow.getName());
+ relativeName.append(":");
+ }
+ }
+ Processor processor = findProcessor(activity);
+ if (processor != null)
+ relativeName.append(processor.getName());
+ return relativeName.toString();
+ }
+
+ public boolean closeDialog() {
+ if (panel.isConfigurationChanged()) {
+ String relativeName = getRelativeName(owningWorkflowBundle, activity);
+ if (checkPanelValues()) {
+ int answer = showConfirmDialog(this,
+ "Do you want to save the configuration of " + relativeName + "?",
+ relativeName, YES_NO_CANCEL_OPTION);
+ if (answer == YES_OPTION) {
+ applyConfiguration();
+ } else if (answer == CANCEL_OPTION) {
+ return false;
+ }
+ } else if (showConfirmDialog(
+ this,
+ "New configuration could not be saved. Do you still want to close?",
+ relativeName, YES_NO_OPTION) == NO_OPTION)
+ return false;
+ }
+ panel.whenClosed();
+ clearDialog(activity);
+ return true;
+ }
+
+ private void applyConfiguration() {
+ panel.noteConfiguration();
+ configureActivity(panel.getJson(), panel.getInputPorts(),
+ panel.getOutputPorts());
+ panel.refreshConfiguration();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ editManager.removeObserver(observer);
+ }
+}