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 2016/10/24 07:03:46 UTC

[5/6] incubator-taverna-workbench git commit: Removed Baclava actions

Removed Baclava actions

Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/commit/a3483f50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/tree/a3483f50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/diff/a3483f50

Branch: refs/heads/master
Commit: a3483f5072eff2d2e890d055045f67e3d3040ef1
Parents: b219f5d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 21 12:27:19 2016 +0200
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 21 12:27:19 2016 +0200

----------------------------------------------------------------------
 .../ui/referenceactions/LoadInputsFromXML.java  | 114 -----------
 .../ui/referenceactions/SaveInputsAsXML.java    | 201 -------------------
 2 files changed, 315 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a3483f50/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/LoadInputsFromXML.java
----------------------------------------------------------------------
diff --git a/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/LoadInputsFromXML.java b/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/LoadInputsFromXML.java
deleted file mode 100644
index 19f238d..0000000
--- a/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/LoadInputsFromXML.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.taverna.reference.ui.referenceactions;
-/*
- * 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.
- */
-
-import static javax.swing.JFileChooser.APPROVE_OPTION;
-import static org.apache.taverna.workbench.icons.WorkbenchIcons.xmlNodeIcon;
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.prefs.Preferences;
-
-import javax.swing.AbstractAction;
-import javax.swing.JFileChooser;
-
-import org.apache.taverna.lang.ui.ExtensionFileFilter;
-import org.apache.taverna.reference.ui.RegistrationPanel;
-
-import org.jdom.Document;
-import org.jdom.input.SAXBuilder;
-
-/**
- * Loads a set of input values from an XML document
- */
-public class LoadInputsFromXML extends AbstractAction implements
-		ReferenceActionSPI {
-	private static final long serialVersionUID = -5031867688853589341L;
-	private static final String INPUT_DATA_DIR_PROPERTY = "inputDataValuesDir";
-
-	private Map<String, RegistrationPanel> inputPanelMap;
-
-	public LoadInputsFromXML() {
-		super();
-		putValue(NAME, "Load previous values");
-		putValue(SMALL_ICON, xmlNodeIcon);
-	}
-
-	@Override
-	public AbstractAction getAction() {
-		return new LoadInputsFromXML();
-	}
-
-	@Override
-	public void actionPerformed(ActionEvent e) {
-		Preferences prefs = Preferences.userNodeForPackage(getClass());
-		String curDir = prefs.get(INPUT_DATA_DIR_PROPERTY, System.getProperty("user.home"));
-
-		JFileChooser chooser = new JFileChooser();
-		chooser.setDialogTitle("Select file to load input values from");
-
-		chooser.resetChoosableFileFilters();
-		chooser.setFileFilter(new ExtensionFileFilter(new String[]{"xml"}));
-		chooser.setCurrentDirectory(new File(curDir));
-
-		if (chooser.showOpenDialog(null) != APPROVE_OPTION)
-			return;
-		prefs.put(INPUT_DATA_DIR_PROPERTY, chooser.getCurrentDirectory()
-				.toString());
-		try {
-			File file = chooser.getSelectedFile();
-			InputStreamReader stream;
-			stream = new InputStreamReader(new FileInputStream(file),
-					Charset.forName("UTF-8"));
-			Document inputDoc = new SAXBuilder(false).build(stream);
-			Map<String, DataThing> inputMap = DataThingXMLFactory.parseDataDocument(inputDoc);
-			for (String portName : inputMap.keySet()) {
-				RegistrationPanel panel = inputPanelMap.get(portName);
-				Object o = inputMap.get(portName).getDataObject();
-				if (o != null) {
-					int objectDepth = getObjectDepth(o);
-					if ((panel != null) && (objectDepth <= panel.getDepth()))
-						panel.setValue(o, objectDepth);
-				}
-			}
-		} catch (Exception ex) {
-			// Nothing
-		}
-	}
-
-	@Override
-	public void setInputPanelMap(Map<String, RegistrationPanel> inputPanelMap) {
-		this.inputPanelMap = inputPanelMap;
-	}
-
-	private int getObjectDepth(Object o) {
-		int result = 0;
-		if (o instanceof Iterable) {
-			result++;
-			@SuppressWarnings("unchecked")
-			Iterator<Object> i = ((Iterable<Object>) o).iterator();
-			if (i.hasNext())
-				result = result + getObjectDepth(i.next());
-		}
-		return result;
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a3483f50/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/SaveInputsAsXML.java
----------------------------------------------------------------------
diff --git a/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/SaveInputsAsXML.java b/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/SaveInputsAsXML.java
deleted file mode 100644
index 3ebc2df..0000000
--- a/taverna-reference-ui/src/main/java/org/apache/taverna/reference/ui/referenceactions/SaveInputsAsXML.java
+++ /dev/null
@@ -1,201 +0,0 @@
-package org.apache.taverna.reference.ui.referenceactions;
-/*
- * 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.
- */
-
-import static java.lang.System.getProperty;
-import static javax.swing.JFileChooser.APPROVE_OPTION;
-import static javax.swing.JFileChooser.FILES_ONLY;
-import static javax.swing.JOptionPane.ERROR_MESSAGE;
-import static javax.swing.JOptionPane.YES_NO_OPTION;
-import static javax.swing.JOptionPane.YES_OPTION;
-import static javax.swing.JOptionPane.showConfirmDialog;
-import static javax.swing.JOptionPane.showMessageDialog;
-import static org.apache.taverna.workbench.icons.WorkbenchIcons.xmlNodeIcon;
-import static org.jdom.Namespace.getNamespace;
-import static org.jdom.output.Format.getPrettyFormat;
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.prefs.Preferences;
-
-import javax.swing.AbstractAction;
-import javax.swing.JFileChooser;
-
-import org.apache.taverna.invocation.InvocationContext;
-import org.apache.taverna.lang.ui.ExtensionFileFilter;
-import org.apache.taverna.reference.ui.RegistrationPanel;
-
-import org.apache.log4j.Logger;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
-import org.jdom.output.XMLOutputter;
-
-/**
- * Stores the entire map of result objects to disk
- * as a single XML data document.
- *
- * @author Tom Oinn
- * @author Alex Nenadic
- */
-public class SaveInputsAsXML extends AbstractAction implements ReferenceActionSPI {
-	private static final long serialVersionUID = 452360182978773176L;
-	private static final String INPUT_DATA_DIR_PROPERTY = "inputDataValuesDir";
-	private static final Logger logger = Logger
-			.getLogger(SaveInputsAsXML.class);
-	public static final String BACLAVA_NAMESPACE = "http://org.embl.ebi.escience/baclava/0.1alpha";
-	/** {@value #BACLAVA_NAMESPACE} */
-	private static final Namespace namespace = getNamespace("b",
-			BACLAVA_NAMESPACE);
-
-	@SuppressWarnings("unused")
-	private InvocationContext context = null;
-
-	private Map<String, RegistrationPanel> inputPanelMap;
-
-	public SaveInputsAsXML(){
-		super();
-		putValue(NAME, "Save values");
-		putValue(SMALL_ICON, xmlNodeIcon);
-	}
-
-	@Override
-	public AbstractAction getAction() {
-		return new SaveInputsAsXML();
-	}
-
-	// Must be called before actionPerformed()
-	public void setInvocationContext(InvocationContext context) {
-		this.context = context;
-	}
-
-	/**
-	 * Shows a standard save dialog and dumps the entire input set to the
-	 * specified XML file.
-	 */
-	@Override
-	public void actionPerformed(ActionEvent e) {
-		Preferences prefs = Preferences.userNodeForPackage(getClass());
-		String curDir = prefs.get(INPUT_DATA_DIR_PROPERTY, getProperty("user.home"));
-
-		JFileChooser fc = new JFileChooser();
-		fc.setDialogTitle("Select file to save input values to");
-
-		fc.resetChoosableFileFilters();
-		fc.setFileFilter(new ExtensionFileFilter(new String[] { "xml" }));
-		fc.setCurrentDirectory(new File(curDir));
-		fc.setFileSelectionMode(FILES_ONLY);
-
-		File file;
-		do {
-			if (fc.showSaveDialog(null) != APPROVE_OPTION)
-				return;
-			prefs.put(INPUT_DATA_DIR_PROPERTY, fc.getCurrentDirectory().toString());
-			file = fc.getSelectedFile();
-
-			/*
-			 * If the user did not use the .xml extension for the file - append
-			 * it to the file name now
-			 */
-			if (!file.getName().toLowerCase().endsWith(".xml"))
-				file = new File(file.getParentFile(), file.getName() + ".xml");
-
-			// If the file exists, ask the user if they want to overwrite the file
-		} while (file.exists()
-				&& showConfirmDialog(null, file.getAbsolutePath()
-						+ " already exists. Do you want to overwrite it?",
-						"File already exists", YES_NO_OPTION) != YES_OPTION);
-		doSave(file);
-	}
-
-	private void doSave(final File file) {
-		// Do this in separate thread to avoid hanging UI
-		new Thread("Save(InputsAsXML: Saving inputs to " + file) {
-			@Override
-			public void run() {
-				try {
-					synchronized (inputPanelMap) {
-						saveData(file);
-					}
-				} catch (Exception ex) {
-					showMessageDialog(null, "Problem saving input data",
-							"Save Inputs Error", ERROR_MESSAGE);
-					logger.error("Problem saving input data as XML", ex);
-				}
-			}
-		}.start();
-	}
-
-	/**
-	 * Saves the input data to an XML Baclava file.
-	 */
-	private void saveData(File file) throws Exception {
-		// Build the DataThing map from the inputPanelMap
-		Map<String, Object> valueMap = new HashMap<>();
-		for (String portName : inputPanelMap.keySet()) {
-			RegistrationPanel panel = inputPanelMap.get(portName);
-			Object obj = panel.getValue();
-			if (obj != null)
-				valueMap.put(portName, obj);
-		}
-		Map<String, DataThing> dataThings = bakeDataThingMap(valueMap);
-
-		// Build the string containing the XML document from the panel map
-		String xmlString = new XMLOutputter(getPrettyFormat())
-				.outputString(getDataDocument(dataThings));
-		try (PrintWriter out = new PrintWriter(new FileWriter(file))) {
-			out.print(xmlString);
-		}
-	}
-
-	/**
-	 * Returns a map of port names to DataThings from a map of port names to a
-	 * list of (lists of ...) result objects.
-	 */
-	Map<String, DataThing> bakeDataThingMap(Map<String, Object> resultMap) {
-		Map<String, DataThing> dataThingMap = new HashMap<>();
-		for (String portName : resultMap.keySet())
-			dataThingMap.put(portName, bake(resultMap.get(portName)));
-		return dataThingMap;
-	}
-
-	/**
-	 * Returns a org.jdom.Document from a map of port named to DataThingS containing
-	 * the port's results.
-	 */
-	public static Document getDataDocument(Map<String, DataThing> dataThings) {
-		Element rootElement = new Element("dataThingMap", namespace);
-		Document theDocument = new Document(rootElement);
-		for (String key : dataThings.keySet()) {
-			DataThing value = (DataThing) dataThings.get(key);
-			Element dataThingElement = new Element("dataThing", namespace);
-			dataThingElement.setAttribute("key", key);
-			dataThingElement.addContent(value.getElement());
-			rootElement.addContent(dataThingElement);
-		}
-		return theDocument;
-	}
-
-	@Override
-	public void setInputPanelMap(Map<String, RegistrationPanel> inputPanelMap) {
-		this.inputPanelMap = inputPanelMap;
-	}
-}