http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileManagerImpl.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileManagerImpl.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileManagerImpl.java deleted file mode 100644 index eed7d51..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileManagerImpl.java +++ /dev/null @@ -1,601 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007-2010 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.file.impl; - -import static java.awt.GraphicsEnvironment.isHeadless; -import static java.util.Collections.singleton; -import static javax.swing.SwingUtilities.invokeAndWait; -import static javax.swing.SwingUtilities.isEventDispatchThread; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - -import javax.swing.filechooser.FileFilter; - -import org.apache.taverna.lang.observer.MultiCaster; -import org.apache.taverna.lang.observer.Observable; -import org.apache.taverna.lang.observer.Observer; -import org.apache.taverna.workbench.edits.EditManager; -import org.apache.taverna.workbench.edits.EditManager.AbstractDataflowEditEvent; -import org.apache.taverna.workbench.edits.EditManager.EditManagerEvent; -import org.apache.taverna.workbench.file.DataflowInfo; -import org.apache.taverna.workbench.file.DataflowPersistenceHandler; -import org.apache.taverna.workbench.file.FileManager; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.events.ClosedDataflowEvent; -import org.apache.taverna.workbench.file.events.ClosingDataflowEvent; -import org.apache.taverna.workbench.file.events.FileManagerEvent; -import org.apache.taverna.workbench.file.events.OpenedDataflowEvent; -import org.apache.taverna.workbench.file.events.SavedDataflowEvent; -import org.apache.taverna.workbench.file.events.SetCurrentDataflowEvent; -import org.apache.taverna.workbench.file.exceptions.OpenException; -import org.apache.taverna.workbench.file.exceptions.OverwriteException; -import org.apache.taverna.workbench.file.exceptions.SaveException; -import org.apache.taverna.workbench.file.exceptions.UnsavedException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.core.Workflow; -import org.apache.taverna.scufl2.api.profiles.Profile; - -/** - * Implementation of {@link FileManager} - * - * @author Stian Soiland-Reyes - */ -public class FileManagerImpl implements FileManager { - private static Logger logger = Logger.getLogger(FileManagerImpl.class); - private static int nameIndex = 1; - - /** - * The last blank workflowBundle created using #newDataflow() until it has - * been changed - when this variable will be set to null again. Used to - * automatically close unmodified blank workflowBundles on open. - */ - private WorkflowBundle blankWorkflowBundle = null; - @SuppressWarnings("unused") - private EditManager editManager; - private EditManagerObserver editManagerObserver = new EditManagerObserver(); - protected MultiCaster<FileManagerEvent> observers = new MultiCaster<>(this); - /** - * Ordered list of open WorkflowBundle - */ - private LinkedHashMap<WorkflowBundle, OpenDataflowInfo> openDataflowInfos = new LinkedHashMap<>(); - private DataflowPersistenceHandlerRegistry dataflowPersistenceHandlerRegistry; - private Scufl2Tools scufl2Tools = new Scufl2Tools(); - private WorkflowBundle currentWorkflowBundle; - - public DataflowPersistenceHandlerRegistry getPersistanceHandlerRegistry() { - return dataflowPersistenceHandlerRegistry; - } - - public FileManagerImpl(EditManager editManager) { - this.editManager = editManager; - editManager.addObserver(editManagerObserver); - } - - /** - * Add an observer to be notified of {@link FileManagerEvent}s, such as - * {@link OpenedDataflowEvent} and {@link SavedDataflowEvent}. - * - * {@inheritDoc} - */ - @Override - public void addObserver(Observer<FileManagerEvent> observer) { - observers.addObserver(observer); - } - - @Override - public boolean canSaveWithoutDestination(WorkflowBundle workflowBundle) { - OpenDataflowInfo dataflowInfo = getOpenDataflowInfo(workflowBundle); - if (dataflowInfo.getSource() == null) - return false; - Set<?> handlers = getPersistanceHandlerRegistry() - .getSaveHandlersForType( - dataflowInfo.getFileType(), - dataflowInfo.getDataflowInfo().getCanonicalSource() - .getClass()); - return !handlers.isEmpty(); - } - - @Override - public boolean closeDataflow(WorkflowBundle workflowBundle, - boolean failOnUnsaved) throws UnsavedException { - if (workflowBundle == null) - throw new NullPointerException("Dataflow can't be null"); - ClosingDataflowEvent message = new ClosingDataflowEvent(workflowBundle); - observers.notify(message); - if (message.isAbortClose()) - return false; - if ((failOnUnsaved && getOpenDataflowInfo(workflowBundle).isChanged())) - throw new UnsavedException(workflowBundle); - if (workflowBundle.equals(getCurrentDataflow())) { - // We'll need to change current workflowBundle - // Find best candidate to the left or right - List<WorkflowBundle> workflowBundles = getOpenDataflows(); - int openIndex = workflowBundles.indexOf(workflowBundle); - if (openIndex == -1) - throw new IllegalArgumentException("Workflow was not opened " - + workflowBundle); - - if (openIndex > 0) - setCurrentDataflow(workflowBundles.get(openIndex - 1)); - else if (openIndex == 0 && workflowBundles.size() > 1) - setCurrentDataflow(workflowBundles.get(1)); - else - // If it was the last one, start a new, empty workflowBundle - newDataflow(); - } - if (workflowBundle == blankWorkflowBundle) - blankWorkflowBundle = null; - openDataflowInfos.remove(workflowBundle); - observers.notify(new ClosedDataflowEvent(workflowBundle)); - return true; - } - - @Override - public WorkflowBundle getCurrentDataflow() { - return currentWorkflowBundle; - } - - @Override - public WorkflowBundle getDataflowBySource(Object source) { - for (Entry<WorkflowBundle, OpenDataflowInfo> infoEntry : openDataflowInfos - .entrySet()) { - OpenDataflowInfo info = infoEntry.getValue(); - if (source.equals(info.getSource())) - return infoEntry.getKey(); - } - // Not found - return null; - } - - @Override - public String getDataflowName(WorkflowBundle workflowBundle) { - Object source = null; - if (isDataflowOpen(workflowBundle)) - source = getDataflowSource(workflowBundle); - // Fallback - String name; - Workflow workflow = workflowBundle.getMainWorkflow(); - if (workflow != null) - name = workflow.getName(); - else - name = workflowBundle.getName(); - if (source == null) - return name; - if (source instanceof File) - return ((File) source).getAbsolutePath(); - else if (source instanceof URL) - return source.toString(); - - // Check if it has implemented a toString() method - Method toStringMethod = null; - Method toStringMethodFromObject = null; - try { - toStringMethod = source.getClass().getMethod("toString"); - toStringMethodFromObject = Object.class.getMethod("toString"); - } catch (Exception e) { - throw new IllegalStateException( - "Source did not implement Object.toString() " + source); - } - if (!toStringMethod.equals(toStringMethodFromObject)) - return source.toString(); - return name; - } - - @Override - public String getDefaultWorkflowName() { - return "Workflow" + (nameIndex++); - } - - @Override - public Object getDataflowSource(WorkflowBundle workflowBundle) { - return getOpenDataflowInfo(workflowBundle).getSource(); - } - - @Override - public FileType getDataflowType(WorkflowBundle workflowBundle) { - return getOpenDataflowInfo(workflowBundle).getFileType(); - } - - @Override - public List<Observer<FileManagerEvent>> getObservers() { - return observers.getObservers(); - } - - /** - * Get the {@link OpenDataflowInfo} for the given WorkflowBundle - * - * @throws NullPointerException - * if the WorkflowBundle was <code>null</code> - * @throws IllegalArgumentException - * if the WorkflowBundle was not open. - * @param workflowBundle - * WorkflowBundle which information is to be found - * @return The {@link OpenDataflowInfo} describing the WorkflowBundle - */ - protected synchronized OpenDataflowInfo getOpenDataflowInfo( - WorkflowBundle workflowBundle) { - if (workflowBundle == null) - throw new NullPointerException("Dataflow can't be null"); - OpenDataflowInfo info = openDataflowInfos.get(workflowBundle); - if (info == null) - throw new IllegalArgumentException("Workflow was not opened " - + workflowBundle); - return info; - } - - @Override - public List<WorkflowBundle> getOpenDataflows() { - return new ArrayList<>(openDataflowInfos.keySet()); - } - - @Override - public List<FileFilter> getOpenFileFilters() { - List<FileFilter> fileFilters = new ArrayList<>(); - - Set<FileType> fileTypes = getPersistanceHandlerRegistry() - .getOpenFileTypes(); - if (!fileTypes.isEmpty()) - fileFilters.add(new MultipleFileTypes(fileTypes, - "All supported workflows")); - for (FileType fileType : fileTypes) - fileFilters.add(new FileTypeFileFilter(fileType)); - return fileFilters; - } - - @Override - public List<FileFilter> getOpenFileFilters(Class<?> sourceClass) { - List<FileFilter> fileFilters = new ArrayList<>(); - for (FileType fileType : getPersistanceHandlerRegistry() - .getOpenFileTypesFor(sourceClass)) - fileFilters.add(new FileTypeFileFilter(fileType)); - return fileFilters; - } - - @Override - public List<FileFilter> getSaveFileFilters() { - List<FileFilter> fileFilters = new ArrayList<>(); - for (FileType fileType : getPersistanceHandlerRegistry() - .getSaveFileTypes()) - fileFilters.add(new FileTypeFileFilter(fileType)); - return fileFilters; - } - - @Override - public List<FileFilter> getSaveFileFilters(Class<?> destinationClass) { - List<FileFilter> fileFilters = new ArrayList<>(); - for (FileType fileType : getPersistanceHandlerRegistry() - .getSaveFileTypesFor(destinationClass)) - fileFilters.add(new FileTypeFileFilter(fileType)); - return fileFilters; - } - - @Override - public boolean isDataflowChanged(WorkflowBundle workflowBundle) { - return getOpenDataflowInfo(workflowBundle).isChanged(); - } - - @Override - public boolean isDataflowOpen(WorkflowBundle workflowBundle) { - return openDataflowInfos.containsKey(workflowBundle); - } - - @Override - public WorkflowBundle newDataflow() { - WorkflowBundle workflowBundle = new WorkflowBundle(); - workflowBundle.setMainWorkflow(new Workflow()); - workflowBundle.getMainWorkflow().setName(getDefaultWorkflowName()); - workflowBundle.setMainProfile(new Profile()); - scufl2Tools.setParents(workflowBundle); - blankWorkflowBundle = null; - openDataflowInternal(workflowBundle); - blankWorkflowBundle = workflowBundle; - observers.notify(new OpenedDataflowEvent(workflowBundle)); - return workflowBundle; - } - - @Override - public void openDataflow(WorkflowBundle workflowBundle) { - openDataflowInternal(workflowBundle); - observers.notify(new OpenedDataflowEvent(workflowBundle)); - } - - /** - * {@inheritDoc} - */ - @Override - public WorkflowBundle openDataflow(FileType fileType, Object source) - throws OpenException { - if (isHeadless()) - return performOpenDataflow(fileType, source); - - OpenDataflowRunnable r = new OpenDataflowRunnable(this, fileType, - source); - if (isEventDispatchThread()) { - r.run(); - } else - try { - invokeAndWait(r); - } catch (InterruptedException | InvocationTargetException e) { - throw new OpenException("Opening was interrupted", e); - } - OpenException thrownException = r.getException(); - if (thrownException != null) - throw thrownException; - return r.getDataflow(); - } - - public WorkflowBundle performOpenDataflow(FileType fileType, Object source) - throws OpenException { - DataflowInfo dataflowInfo; - WorkflowBundle workflowBundle; - dataflowInfo = openDataflowSilently(fileType, source); - workflowBundle = dataflowInfo.getDataflow(); - openDataflowInternal(workflowBundle); - getOpenDataflowInfo(workflowBundle).setOpenedFrom(dataflowInfo); - observers.notify(new OpenedDataflowEvent(workflowBundle)); - return workflowBundle; - } - - @Override - public DataflowInfo openDataflowSilently(FileType fileType, Object source) - throws OpenException { - Set<DataflowPersistenceHandler> handlers; - Class<? extends Object> sourceClass = source.getClass(); - - boolean unknownFileType = (fileType == null); - if (unknownFileType) - handlers = getPersistanceHandlerRegistry().getOpenHandlersFor( - sourceClass); - else - handlers = getPersistanceHandlerRegistry().getOpenHandlersFor( - fileType, sourceClass); - if (handlers.isEmpty()) - throw new OpenException("Unsupported file type or class " - + fileType + " " + sourceClass); - - Throwable lastException = null; - for (DataflowPersistenceHandler handler : handlers) { - Collection<FileType> fileTypes; - if (unknownFileType) - fileTypes = handler.getOpenFileTypes(); - else - fileTypes = singleton(fileType); - for (FileType candidateFileType : fileTypes) { - if (unknownFileType && (source instanceof File)) - /* - * If source is file but fileType was not explicitly set - * from the open workflow dialog - check the file extension - * and decide which handler to use based on that (so that we - * do not loop though all handlers) - */ - if (!((File) source).getPath().endsWith( - candidateFileType.getExtension())) - continue; - - try { - DataflowInfo openDataflow = handler.openDataflow( - candidateFileType, source); - WorkflowBundle workflowBundle = openDataflow.getDataflow(); - logger.info("Loaded workflow: " + workflowBundle.getName() - + " " + workflowBundle.getGlobalBaseURI() - + " from " + source + " using " + handler); - return openDataflow; - } catch (OpenException ex) { - logger.warn("Could not open workflow " + source + " using " - + handler + " of type " + candidateFileType); - lastException = ex; - } - } - } - throw new OpenException("Could not open workflow " + source + "\n", - lastException); - } - - /** - * Mark the WorkflowBundle as opened, and close the blank WorkflowBundle if - * needed. - * - * @param workflowBundle - * WorkflowBundle that has been opened - */ - protected void openDataflowInternal(WorkflowBundle workflowBundle) { - if (workflowBundle == null) - throw new NullPointerException("Dataflow can't be null"); - if (isDataflowOpen(workflowBundle)) - throw new IllegalArgumentException("Workflow is already open: " - + workflowBundle); - - openDataflowInfos.put(workflowBundle, new OpenDataflowInfo()); - setCurrentDataflow(workflowBundle); - if (openDataflowInfos.size() == 2 && blankWorkflowBundle != null) - /* - * Behave like a word processor and close the blank WorkflowBundle - * when another workflow has been opened - */ - try { - closeDataflow(blankWorkflowBundle, true); - } catch (UnsavedException e) { - logger.error("Blank workflow was modified " - + "and could not be closed"); - } - } - - @Override - public void removeObserver(Observer<FileManagerEvent> observer) { - observers.removeObserver(observer); - } - - @Override - public void saveDataflow(WorkflowBundle workflowBundle, - boolean failOnOverwrite) throws SaveException { - if (workflowBundle == null) - throw new NullPointerException("Dataflow can't be null"); - OpenDataflowInfo lastSave = getOpenDataflowInfo(workflowBundle); - if (lastSave.getSource() == null) - throw new SaveException("Can't save without source " - + workflowBundle); - saveDataflow(workflowBundle, lastSave.getFileType(), - lastSave.getSource(), failOnOverwrite); - } - - @Override - public void saveDataflow(WorkflowBundle workflowBundle, FileType fileType, - Object destination, boolean failOnOverwrite) throws SaveException { - DataflowInfo savedDataflow = saveDataflowSilently(workflowBundle, - fileType, destination, failOnOverwrite); - getOpenDataflowInfo(workflowBundle).setSavedTo(savedDataflow); - observers.notify(new SavedDataflowEvent(workflowBundle)); - } - - @Override - public DataflowInfo saveDataflowSilently(WorkflowBundle workflowBundle, - FileType fileType, Object destination, boolean failOnOverwrite) - throws SaveException, OverwriteException { - Set<DataflowPersistenceHandler> handlers; - - Class<? extends Object> destinationClass = destination.getClass(); - if (fileType != null) - handlers = getPersistanceHandlerRegistry().getSaveHandlersForType( - fileType, destinationClass); - else - handlers = getPersistanceHandlerRegistry().getSaveHandlersFor( - destinationClass); - - SaveException lastException = null; - for (DataflowPersistenceHandler handler : handlers) { - if (failOnOverwrite) { - OpenDataflowInfo openDataflowInfo = getOpenDataflowInfo(workflowBundle); - if (handler.wouldOverwriteDataflow(workflowBundle, fileType, - destination, openDataflowInfo.getDataflowInfo())) - throw new OverwriteException(destination); - } - try { - DataflowInfo savedDataflow = handler.saveDataflow( - workflowBundle, fileType, destination); - savedDataflow.getDataflow(); - logger.info("Saved workflow: " + workflowBundle.getName() + " " - + workflowBundle.getGlobalBaseURI() + " to " - + savedDataflow.getCanonicalSource() + " using " - + handler); - return savedDataflow; - } catch (SaveException ex) { - logger.warn("Could not save to " + destination + " using " - + handler); - lastException = ex; - } - } - - if (lastException == null) - throw new SaveException("Unsupported file type or class " - + fileType + " " + destinationClass); - throw new SaveException("Could not save to " + destination + ":\n" - + lastException.getLocalizedMessage(), lastException); - } - - @Override - public void setCurrentDataflow(WorkflowBundle workflowBundle) { - setCurrentDataflow(workflowBundle, false); - } - - @Override - public void setCurrentDataflow(WorkflowBundle workflowBundle, - boolean openIfNeeded) { - currentWorkflowBundle = workflowBundle; - if (!isDataflowOpen(workflowBundle)) { - if (!openIfNeeded) - throw new IllegalArgumentException("Workflow is not open: " - + workflowBundle); - openDataflow(workflowBundle); - return; - } - observers.notify(new SetCurrentDataflowEvent(workflowBundle)); - } - - @Override - public void setDataflowChanged(WorkflowBundle workflowBundle, - boolean isChanged) { - getOpenDataflowInfo(workflowBundle).setIsChanged(isChanged); - if (blankWorkflowBundle == workflowBundle) - blankWorkflowBundle = null; - } - - @Override - public Object getCanonical(Object source) throws IllegalArgumentException, - URISyntaxException, IOException { - Object canonicalSource = source; - - if (source instanceof URL) { - URL url = ((URL) source); - if (url.getProtocol().equalsIgnoreCase("file")) - canonicalSource = new File(url.toURI()); - } - - if (canonicalSource instanceof File) - canonicalSource = ((File) canonicalSource).getCanonicalFile(); - return canonicalSource; - } - - public void setDataflowPersistenceHandlerRegistry( - DataflowPersistenceHandlerRegistry dataflowPersistenceHandlerRegistry) { - this.dataflowPersistenceHandlerRegistry = dataflowPersistenceHandlerRegistry; - } - - /** - * Observe the {@link EditManager} for changes to open workflowBundles. A - * change of an open workflow would set it as changed using - * {@link FileManagerImpl#setDataflowChanged(Dataflow, boolean)}. - * - * @author Stian Soiland-Reyes - * - */ - private final class EditManagerObserver implements - Observer<EditManagerEvent> { - @Override - public void notify(Observable<EditManagerEvent> sender, - EditManagerEvent message) throws Exception { - if (message instanceof AbstractDataflowEditEvent) { - AbstractDataflowEditEvent dataflowEdit = (AbstractDataflowEditEvent) message; - WorkflowBundle workflowBundle = dataflowEdit.getDataFlow(); - /** - * TODO: on undo/redo - keep last event or similar to determine - * if workflow was saved before. See - * FileManagerTest#isChangedWithUndo(). - */ - setDataflowChanged(workflowBundle, true); - } - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileTypeFileFilter.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileTypeFileFilter.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileTypeFileFilter.java deleted file mode 100644 index 6383295..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/FileTypeFileFilter.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; - -import javax.swing.filechooser.FileFilter; - -import org.apache.taverna.workbench.file.FileType; - -public class FileTypeFileFilter extends FileFilter { - private final FileType fileType; - - public FileTypeFileFilter(FileType fileType) { - this.fileType = fileType; - } - - @Override - public String getDescription() { - return fileType.getDescription(); - } - - @Override - public boolean accept(File file) { - if (file.isDirectory()) - // Don't grey out directories - return true; - if (fileType.getExtension() == null) - return false; - return file.getName().toLowerCase() - .endsWith("." + fileType.getExtension()); - } - - public FileType getFileType() { - return fileType; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/MultipleFileTypes.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/MultipleFileTypes.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/MultipleFileTypes.java deleted file mode 100644 index 0205d86..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/MultipleFileTypes.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; -import java.util.Set; - -import javax.swing.filechooser.FileFilter; - -import org.apache.taverna.workbench.file.FileType; - -public class MultipleFileTypes extends FileFilter { - private String description; - private final Set<FileType> fileTypes; - - public MultipleFileTypes(Set<FileType> fileTypes, String description) { - this.fileTypes = fileTypes; - this.description = description; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public boolean accept(File file) { - if (file.isDirectory()) - return true; - - String lowerFileName = file.getName().toLowerCase(); - for (FileType fileType : fileTypes) { - if (fileType.getExtension() == null) - continue; - if (lowerFileName.endsWith(fileType.getExtension())) - return true; - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInProgressDialog.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInProgressDialog.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInProgressDialog.java deleted file mode 100644 index 021a1b2..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInProgressDialog.java +++ /dev/null @@ -1,88 +0,0 @@ - -/******************************************************************************* - * Copyright (C) 2009 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.file.impl; - -import static java.awt.BorderLayout.CENTER; -import static org.apache.taverna.workbench.MainWindow.getMainWindow; -import static org.apache.taverna.workbench.icons.WorkbenchIcons.workingIcon; - -import java.awt.BorderLayout; -import java.awt.Dimension; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import org.apache.taverna.workbench.helper.HelpEnabledDialog; - -/** - * Dialog that is popped up while we are opening a workflow. - * - * @author Alex Nenadic - * @author Alan R Williams - */ -@SuppressWarnings("serial") -public class OpenDataflowInProgressDialog extends HelpEnabledDialog { - private boolean userCancelled = false; - - public OpenDataflowInProgressDialog() { - super(getMainWindow(), "Opening workflow", true); - setResizable(false); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - - JPanel panel = new JPanel(new BorderLayout()); - panel.setBorder(new EmptyBorder(10,10,10,10)); - - JPanel textPanel = new JPanel(); - JLabel text = new JLabel(workingIcon); - text.setText("Opening workflow..."); - text.setBorder(new EmptyBorder(10,0,10,0)); - textPanel.add(text); - panel.add(textPanel, CENTER); - -/* - * Cancellation does not work when opening - - // Cancel button - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - userCancelled = true; - setVisible(false); - dispose(); - } - }); - JPanel cancelButtonPanel = new JPanel(); - cancelButtonPanel.add(cancelButton); - panel.add(cancelButtonPanel, BorderLayout.SOUTH); -*/ - setContentPane(panel); - setPreferredSize(new Dimension(300, 100)); - - pack(); - } - - public boolean hasUserCancelled() { - return userCancelled; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInfo.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInfo.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInfo.java deleted file mode 100644 index 00245f1..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowInfo.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.util.Date; - -import org.apache.taverna.workbench.file.DataflowInfo; -import org.apache.taverna.workbench.file.FileType; - -/** - * Information about an open dataflow. - * - * @author Stian Soiland-Reyes - */ -public class OpenDataflowInfo { - private DataflowInfo dataflowInfo; - private boolean isChanged; - private Date openedAt; - - public OpenDataflowInfo() { - } - - public FileType getFileType() { - if (dataflowInfo == null) - return null; - return dataflowInfo.getFileType(); - } - - public Date getLastModified() { - if (dataflowInfo == null) - return null; - return dataflowInfo.getLastModified(); - } - - public Date getOpenedAtDate() { - return openedAt; - } - - public Object getSource() { - if (dataflowInfo == null) - return null; - return dataflowInfo.getCanonicalSource(); - } - - public boolean isChanged() { - return isChanged; - } - - public void setIsChanged(boolean isChanged) { - this.isChanged = isChanged; - } - - public synchronized void setOpenedFrom(DataflowInfo dataflowInfo) { - setDataflowInfo(dataflowInfo); - setOpenedAt(new Date()); - setIsChanged(false); - } - - public synchronized void setSavedTo(DataflowInfo dataflowInfo) { - setDataflowInfo(dataflowInfo); - setIsChanged(false); - } - - private void setDataflowInfo(DataflowInfo dataflowInfo) { - this.dataflowInfo = dataflowInfo; - } - - private void setOpenedAt(Date openedAt) { - this.openedAt = openedAt; - } - - public DataflowInfo getDataflowInfo() { - return dataflowInfo; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowRunnable.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowRunnable.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowRunnable.java deleted file mode 100644 index 504c2a9..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowRunnable.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * - */ -package net.sf.taverna.t2.workbench.file.impl; - -import static java.lang.Thread.sleep; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.OpenException; -import org.apache.taverna.workbench.ui.SwingWorkerCompletionWaiter; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -/** - * @author alanrw - */ -public class OpenDataflowRunnable implements Runnable { - private final FileManagerImpl fileManager; - private final FileType fileType; - private final Object source; - private WorkflowBundle dataflow; - private OpenException e; - - public OpenDataflowRunnable(FileManagerImpl fileManager, FileType fileType, - Object source) { - this.fileManager = fileManager; - this.fileType = fileType; - this.source = source; - } - - @Override - public void run() { - OpenDataflowSwingWorker openDataflowSwingWorker = new OpenDataflowSwingWorker( - fileType, source, fileManager); - OpenDataflowInProgressDialog dialog = new OpenDataflowInProgressDialog(); - openDataflowSwingWorker - .addPropertyChangeListener(new SwingWorkerCompletionWaiter( - dialog)); - openDataflowSwingWorker.execute(); - - /* - * Give a chance to the SwingWorker to finish so we do not have to - * display the dialog - */ - try { - sleep(500); - } catch (InterruptedException e) { - this.e = new OpenException("Opening was interrupted"); - } - if (!openDataflowSwingWorker.isDone()) - dialog.setVisible(true); // this will block the GUI - boolean userCancelled = dialog.hasUserCancelled(); // see if user cancelled the dialog - - if (userCancelled) { - // Stop the OpenDataflowSwingWorker if it is still working - openDataflowSwingWorker.cancel(true); - dataflow = null; - this.e = new OpenException("Opening was cancelled"); - // exit - return; - } - dataflow = openDataflowSwingWorker.getDataflow(); - this.e = openDataflowSwingWorker.getException(); - } - - public WorkflowBundle getDataflow() { - return dataflow; - } - - public OpenException getException() { - return this.e; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowSwingWorker.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowSwingWorker.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowSwingWorker.java deleted file mode 100644 index ba74b03..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/OpenDataflowSwingWorker.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 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.file.impl; - -import javax.swing.SwingWorker; - -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.OpenException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -public class OpenDataflowSwingWorker extends - SwingWorker<WorkflowBundle, Object> { - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(OpenDataflowSwingWorker.class); - private FileType fileType; - private Object source; - private FileManagerImpl fileManagerImpl; - private WorkflowBundle workflowBundle; - private OpenException e = null; - - public OpenDataflowSwingWorker(FileType fileType, Object source, - FileManagerImpl fileManagerImpl) { - this.fileType = fileType; - this.source = source; - this.fileManagerImpl = fileManagerImpl; - } - - @Override - protected WorkflowBundle doInBackground() throws Exception { - try { - workflowBundle = fileManagerImpl.performOpenDataflow(fileType, - source); - } catch (OpenException e) { - this.e = e; - } - return workflowBundle; - } - - public WorkflowBundle getDataflow() { - return workflowBundle; - } - - public OpenException getException() { - return e; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2DataflowOpener.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2DataflowOpener.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2DataflowOpener.java deleted file mode 100644 index d6e0db2..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2DataflowOpener.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.apache.taverna.workbench.file.AbstractDataflowPersistenceHandler; -import org.apache.taverna.workbench.file.DataflowInfo; -import org.apache.taverna.workbench.file.DataflowPersistenceHandler; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.OpenException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.io.ReaderException; -import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; - -public class T2DataflowOpener extends AbstractDataflowPersistenceHandler - implements DataflowPersistenceHandler { - private static final T2FlowFileType T2_FLOW_FILE_TYPE = new T2FlowFileType(); - private static Logger logger = Logger.getLogger(T2DataflowOpener.class); - - private WorkflowBundleIO workflowBundleIO; - - @SuppressWarnings("resource") - @Override - public DataflowInfo openDataflow(FileType fileType, Object source) - throws OpenException { - if (!getOpenFileTypes().contains(fileType)) - throw new OpenException("Unsupported file type " - + fileType); - InputStream inputStream; - Date lastModified = null; - Object canonicalSource = source; - if (source instanceof InputStream) - inputStream = (InputStream) source; - else if (source instanceof File) - try { - inputStream = new FileInputStream((File) source); - } catch (FileNotFoundException e) { - throw new OpenException("Could not open file " + source + ":\n" + e.getLocalizedMessage(), e); - } - else if (source instanceof URL) { - URL url = ((URL) source); - try { - URLConnection connection = url.openConnection(); - connection.setRequestProperty("Accept", "text/xml"); - inputStream = connection.getInputStream(); - if (connection.getLastModified() != 0) - lastModified = new Date(connection.getLastModified()); - } catch (IOException e) { - throw new OpenException("Could not open connection to URL " - + source+ ":\n" + e.getLocalizedMessage(), e); - } - try { - if (url.getProtocol().equalsIgnoreCase("file")) - canonicalSource = new File(url.toURI()); - } catch (URISyntaxException e) { - logger.warn("Invalid file URI created from " + url); - } - } else { - throw new OpenException("Unsupported source type " - + source.getClass()); - } - - final WorkflowBundle workflowBundle; - try { - workflowBundle = openDataflowStream(inputStream); - } finally { - try { - if (!(source instanceof InputStream)) - // We created the stream, we'll close it - inputStream.close(); - } catch (IOException ex) { - logger.warn("Could not close inputstream " + inputStream, ex); - } - } - if (canonicalSource instanceof File) - return new FileDataflowInfo(T2_FLOW_FILE_TYPE, - (File) canonicalSource, workflowBundle); - return new DataflowInfo(T2_FLOW_FILE_TYPE, canonicalSource, - workflowBundle, lastModified); - } - - protected WorkflowBundle openDataflowStream(InputStream workflowXMLstream) - throws OpenException { - WorkflowBundle workflowBundle; - try { - workflowBundle = workflowBundleIO.readBundle(workflowXMLstream, null); - } catch (ReaderException e) { - throw new OpenException("Could not read the workflow", e); - } catch (IOException e) { - throw new OpenException("Could not open the workflow file for parsing", e); - } catch (Exception e) { - throw new OpenException("Error while opening workflow", e); - } - - return workflowBundle; - } - - @Override - public List<FileType> getOpenFileTypes() { - return Arrays.<FileType> asList(new T2FlowFileType()); - } - - @Override - public List<Class<?>> getOpenSourceTypes() { - return Arrays.<Class<?>> asList(InputStream.class, URL.class, - File.class); - } - - public void setWorkflowBundleIO(WorkflowBundleIO workflowBundleIO) { - this.workflowBundleIO = workflowBundleIO; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FileFilter.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FileFilter.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FileFilter.java deleted file mode 100644 index 62b5892..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FileFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; - -import javax.swing.filechooser.FileFilter; - -public class T2FileFilter extends FileFilter { - @Override - public boolean accept(final File file) { - return file.getName().toLowerCase().endsWith(".t2flow"); - } - - @Override - public String getDescription() { - return "Taverna 2 workflows"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FlowFileType.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FlowFileType.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FlowFileType.java deleted file mode 100644 index cb2b399..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/T2FlowFileType.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import org.apache.taverna.workbench.file.FileType; - -public class T2FlowFileType extends FileType { - public static final String APPLICATION_VND_TAVERNA_T2FLOW_XML = "application/vnd.taverna.t2flow+xml"; - - @Override - public String getDescription() { - return "Taverna 2 workflow"; - } - - @Override - public String getExtension() { - return "t2flow"; - } - - @Override - public String getMimeType() { - return APPLICATION_VND_TAVERNA_T2FLOW_XML; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileFilter.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileFilter.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileFilter.java deleted file mode 100644 index d272b41..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; - -import javax.swing.filechooser.FileFilter; - -public class WorkflowBundleFileFilter extends FileFilter { - @Override - public boolean accept(final File file) { - return file.getName().toLowerCase().endsWith(".wfbundle"); - } - - @Override - public String getDescription() { - return "Taverna 3 workflows"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileType.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileType.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileType.java deleted file mode 100644 index ad50f79..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleFileType.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import org.apache.taverna.workbench.file.FileType; - -public class WorkflowBundleFileType extends FileType { - public static final String APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE = "application/vnd.taverna.scufl2.workflow-bundle"; - - @Override - public String getDescription() { - return "Taverna 3 workflow"; - } - - @Override - public String getExtension() { - return "wfbundle"; - } - - @Override - public String getMimeType() { - return APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleOpener.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleOpener.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleOpener.java deleted file mode 100644 index 6092dad..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleOpener.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.apache.taverna.workbench.file.AbstractDataflowPersistenceHandler; -import org.apache.taverna.workbench.file.DataflowInfo; -import org.apache.taverna.workbench.file.DataflowPersistenceHandler; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.OpenException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.io.ReaderException; -import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; - -public class WorkflowBundleOpener extends AbstractDataflowPersistenceHandler - implements DataflowPersistenceHandler { - private static final WorkflowBundleFileType WF_BUNDLE_FILE_TYPE = new WorkflowBundleFileType(); - private static Logger logger = Logger.getLogger(WorkflowBundleOpener.class); - private WorkflowBundleIO workflowBundleIO; - - @SuppressWarnings("resource") - @Override - public DataflowInfo openDataflow(FileType fileType, Object source) - throws OpenException { - if (!getOpenFileTypes().contains(fileType)) - throw new OpenException("Unsupported file type " + fileType); - InputStream inputStream; - Date lastModified = null; - Object canonicalSource = source; - if (source instanceof InputStream) { - inputStream = (InputStream) source; - } else if (source instanceof File) { - try { - inputStream = new FileInputStream((File) source); - } catch (FileNotFoundException e) { - throw new OpenException("Could not open file " + source + ":\n" - + e.getLocalizedMessage(), e); - } - } else if (source instanceof URL) { - URL url = ((URL) source); - try { - URLConnection connection = url.openConnection(); - connection.setRequestProperty("Accept", "application/zip"); - inputStream = connection.getInputStream(); - if (connection.getLastModified() != 0) - lastModified = new Date(connection.getLastModified()); - } catch (IOException e) { - throw new OpenException("Could not open connection to URL " - + source + ":\n" + e.getLocalizedMessage(), e); - } - try { - if (url.getProtocol().equalsIgnoreCase("file")) - canonicalSource = new File(url.toURI()); - } catch (URISyntaxException e) { - logger.warn("Invalid file URI created from " + url); - } - } else - throw new OpenException("Unsupported source type " - + source.getClass()); - - final WorkflowBundle workflowBundle; - try { - workflowBundle = openDataflowStream(inputStream); - } finally { - // We created the stream, we'll close it - try { - if (!(source instanceof InputStream)) - inputStream.close(); - } catch (IOException ex) { - logger.warn("Could not close inputstream " + inputStream, ex); - } - } - if (canonicalSource instanceof File) - return new FileDataflowInfo(WF_BUNDLE_FILE_TYPE, - (File) canonicalSource, workflowBundle); - return new DataflowInfo(WF_BUNDLE_FILE_TYPE, canonicalSource, - workflowBundle, lastModified); - } - - protected WorkflowBundle openDataflowStream(InputStream inputStream) - throws OpenException { - WorkflowBundle workflowBundle; - try { - workflowBundle = workflowBundleIO.readBundle(inputStream, null); - } catch (ReaderException e) { - throw new OpenException("Could not read the workflow", e); - } catch (IOException e) { - throw new OpenException("Could not open the workflow for parsing", - e); - } catch (Exception e) { - throw new OpenException("Error while opening workflow", e); - } - - return workflowBundle; - } - - @Override - public List<FileType> getOpenFileTypes() { - return Arrays.<FileType> asList(WF_BUNDLE_FILE_TYPE); - } - - @Override - public List<Class<?>> getOpenSourceTypes() { - return Arrays.<Class<?>> asList(InputStream.class, URL.class, - File.class); - } - - public void setWorkflowBundleIO(WorkflowBundleIO workflowBundleIO) { - this.workflowBundleIO = workflowBundleIO; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleSaver.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleSaver.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleSaver.java deleted file mode 100644 index 3933e67..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/WorkflowBundleSaver.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * 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.file.impl; - -import static net.sf.taverna.t2.workbench.file.impl.WorkflowBundleFileType.APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.apache.taverna.workbench.file.AbstractDataflowPersistenceHandler; -import org.apache.taverna.workbench.file.DataflowInfo; -import org.apache.taverna.workbench.file.DataflowPersistenceHandler; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.SaveException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; - -public class WorkflowBundleSaver extends AbstractDataflowPersistenceHandler - implements DataflowPersistenceHandler { - private static final WorkflowBundleFileType WF_BUNDLE_FILE_TYPE = new WorkflowBundleFileType(); - private static Logger logger = Logger.getLogger(WorkflowBundleSaver.class); - private WorkflowBundleIO workflowBundleIO; - - @Override - public DataflowInfo saveDataflow(WorkflowBundle workflowBundle, FileType fileType, - Object destination) throws SaveException { - if (!getSaveFileTypes().contains(fileType)) - throw new IllegalArgumentException("Unsupported file type " - + fileType); - OutputStream outStream; - if (destination instanceof File) - try { - outStream = new FileOutputStream((File) destination); - } catch (FileNotFoundException e) { - throw new SaveException("Can't create workflow file " - + destination + ":\n" + e.getLocalizedMessage(), e); - } - else if (destination instanceof OutputStream) - outStream = (OutputStream) destination; - else - throw new SaveException("Unsupported destination type " - + destination.getClass()); - - try { - saveDataflowToStream(workflowBundle, outStream); - } finally { - try { - // Only close if we opened the stream - if (!(destination instanceof OutputStream)) - outStream.close(); - } catch (IOException e) { - logger.warn("Could not close stream", e); - } - } - - if (destination instanceof File) - return new FileDataflowInfo(WF_BUNDLE_FILE_TYPE, (File) destination, - workflowBundle); - return new DataflowInfo(WF_BUNDLE_FILE_TYPE, destination, workflowBundle); - } - - protected void saveDataflowToStream(WorkflowBundle workflowBundle, - OutputStream fileOutStream) throws SaveException { - try { - workflowBundleIO.writeBundle(workflowBundle, fileOutStream, - APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE); - } catch (Exception e) { - throw new SaveException("Can't write workflow:\n" - + e.getLocalizedMessage(), e); - } - } - - @Override - public List<FileType> getSaveFileTypes() { - return Arrays.<FileType> asList(WF_BUNDLE_FILE_TYPE); - } - - @Override - public List<Class<?>> getSaveDestinationTypes() { - return Arrays.<Class<?>> asList(File.class, OutputStream.class); - } - - @Override - public boolean wouldOverwriteDataflow(WorkflowBundle workflowBundle, FileType fileType, - Object destination, DataflowInfo lastDataflowInfo) { - if (!getSaveFileTypes().contains(fileType)) - throw new IllegalArgumentException("Unsupported file type " - + fileType); - if (!(destination instanceof File)) - return false; - - File file; - try { - file = ((File) destination).getCanonicalFile(); - } catch (IOException e) { - return false; - } - if (!file.exists()) - return false; - if (lastDataflowInfo == null) - return true; - Object lastDestination = lastDataflowInfo.getCanonicalSource(); - if (!(lastDestination instanceof File)) - return true; - File lastFile = (File) lastDestination; - if (!lastFile.getAbsoluteFile().equals(file)) - return true; - - Date lastModified = new Date(file.lastModified()); - if (lastModified.equals(lastDataflowInfo.getLastModified())) - return false; - return true; - } - - public void setWorkflowBundleIO(WorkflowBundleIO workflowBundleIO) { - this.workflowBundleIO = workflowBundleIO; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseAllWorkflowsAction.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseAllWorkflowsAction.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseAllWorkflowsAction.java deleted file mode 100644 index 337d9a3..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseAllWorkflowsAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * 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.file.impl.actions; - -import static java.awt.Toolkit.getDefaultToolkit; -import static java.awt.event.InputEvent.SHIFT_DOWN_MASK; -import static java.awt.event.KeyEvent.VK_L; -import static java.awt.event.KeyEvent.VK_W; -import static javax.swing.KeyStroke.getKeyStroke; -import static org.apache.taverna.workbench.icons.WorkbenchIcons.closeAllIcon; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.util.Collections; -import java.util.List; - -import javax.swing.AbstractAction; - -import org.apache.taverna.workbench.edits.EditManager; -import org.apache.taverna.workbench.file.FileManager; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -@SuppressWarnings("serial") -public class CloseAllWorkflowsAction extends AbstractAction { - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(CloseWorkflowAction.class); - private static final String CLOSE_ALL_WORKFLOWS = "Close all workflows"; - private FileManager fileManager; - private CloseWorkflowAction closeWorkflowAction; - - public CloseAllWorkflowsAction(EditManager editManager, FileManager fileManager) { - super(CLOSE_ALL_WORKFLOWS, closeAllIcon); - this.fileManager = fileManager; - closeWorkflowAction = new CloseWorkflowAction(editManager, fileManager); - putValue( - ACCELERATOR_KEY, - getKeyStroke(VK_W, getDefaultToolkit().getMenuShortcutKeyMask() - | SHIFT_DOWN_MASK)); - putValue(MNEMONIC_KEY, VK_L); - } - - @Override - public void actionPerformed(ActionEvent event) { - Component parentComponent = null; - if (event.getSource() instanceof Component) - parentComponent = (Component) event.getSource(); - closeAllWorkflows(parentComponent); - } - - public boolean closeAllWorkflows(Component parentComponent) { - // Close in reverse so we can save nested workflows first - List<WorkflowBundle> workflowBundles = fileManager.getOpenDataflows(); - - Collections.reverse(workflowBundles); - - for (WorkflowBundle workflowBundle : workflowBundles) { - boolean success = closeWorkflowAction.closeWorkflow( - parentComponent, workflowBundle); - if (!success) - return false; - } - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseWorkflowAction.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseWorkflowAction.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseWorkflowAction.java deleted file mode 100644 index b696fae..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/CloseWorkflowAction.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * 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.file.impl.actions; - -import static java.awt.Toolkit.getDefaultToolkit; -import static java.awt.event.KeyEvent.VK_C; -import static java.awt.event.KeyEvent.VK_W; -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_OPTION; -import static javax.swing.JOptionPane.showConfirmDialog; -import static javax.swing.KeyStroke.getKeyStroke; -import static org.apache.taverna.workbench.icons.WorkbenchIcons.closeIcon; - -import java.awt.Component; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - -import org.apache.taverna.workbench.edits.EditManager; -import org.apache.taverna.workbench.file.FileManager; -import org.apache.taverna.workbench.file.exceptions.UnsavedException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -@SuppressWarnings("serial") -public class CloseWorkflowAction extends AbstractAction { - private static Logger logger = Logger.getLogger(CloseWorkflowAction.class); - private static final String CLOSE_WORKFLOW = "Close workflow"; - private final SaveWorkflowAction saveWorkflowAction; - private FileManager fileManager; - - public CloseWorkflowAction(EditManager editManager, FileManager fileManager) { - super(CLOSE_WORKFLOW, closeIcon); - this.fileManager = fileManager; - saveWorkflowAction = new SaveWorkflowAction(editManager, fileManager); - putValue( - ACCELERATOR_KEY, - getKeyStroke(VK_W, getDefaultToolkit().getMenuShortcutKeyMask())); - putValue(MNEMONIC_KEY, VK_C); - - } - @Override - public void actionPerformed(ActionEvent e) { - Component parentComponent = null; - if (e.getSource() instanceof Component) - parentComponent = (Component) e.getSource(); - closeWorkflow(parentComponent, fileManager.getCurrentDataflow()); - } - - public boolean closeWorkflow(Component parentComponent, WorkflowBundle workflowBundle) { - if (workflowBundle == null) { - logger.warn("Attempted to close a null workflow"); - return false; - } - - try { - return fileManager.closeDataflow(workflowBundle, true); - } catch (UnsavedException e1) { - fileManager.setCurrentDataflow(workflowBundle); - String msg = "Do you want to save changes before closing the workflow " - + fileManager.getDataflowName(workflowBundle) + "?"; - switch (showConfirmDialog(parentComponent, msg, "Save workflow?", - YES_NO_CANCEL_OPTION)) { - case NO_OPTION: - try { - fileManager.closeDataflow(workflowBundle, false); - return true; - } catch (UnsavedException e2) { - logger.error("Unexpected UnsavedException while " - + "closing workflow", e2); - return false; - } - case YES_OPTION: - boolean saved = saveWorkflowAction.saveDataflow( - parentComponent, workflowBundle); - if (!saved) - return false; - return closeWorkflow(parentComponent, workflowBundle); - case CANCEL_OPTION: - default: - return false; - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/NewWorkflowAction.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/NewWorkflowAction.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/NewWorkflowAction.java deleted file mode 100644 index 3497d77..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/NewWorkflowAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * 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.file.impl.actions; - -import static java.awt.Toolkit.getDefaultToolkit; -import static java.awt.event.KeyEvent.VK_N; -import static javax.swing.KeyStroke.getKeyStroke; -import static org.apache.taverna.workbench.icons.WorkbenchIcons.newIcon; - -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; - -import javax.swing.AbstractAction; - -import org.apache.taverna.workbench.file.FileManager; - -import org.apache.log4j.Logger; - -@SuppressWarnings("serial") -public class NewWorkflowAction extends AbstractAction { - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(NewWorkflowAction.class); - private static final String NEW_WORKFLOW = "New workflow"; - private FileManager fileManager; - - public NewWorkflowAction(FileManager fileManager) { - super(NEW_WORKFLOW, newIcon); - this.fileManager = fileManager; - putValue(SHORT_DESCRIPTION, NEW_WORKFLOW); - putValue(MNEMONIC_KEY, KeyEvent.VK_N); - putValue( - ACCELERATOR_KEY, - getKeyStroke(VK_N, getDefaultToolkit().getMenuShortcutKeyMask())); - } - - @Override - public void actionPerformed(ActionEvent e) { - fileManager.newDataflow(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/bf8a7ea2/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/OpenNestedWorkflowAction.java ---------------------------------------------------------------------- diff --git a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/OpenNestedWorkflowAction.java b/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/OpenNestedWorkflowAction.java deleted file mode 100644 index 91c9caa..0000000 --- a/taverna-file-impl/src/main/java/net/sf/taverna/t2/workbench/file/impl/actions/OpenNestedWorkflowAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * 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.file.impl.actions; - -import java.awt.Component; -import java.io.File; - -import org.apache.taverna.workbench.file.FileManager; -import org.apache.taverna.workbench.file.FileType; -import org.apache.taverna.workbench.file.exceptions.OpenException; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -/** - * An action for opening a nested workflow from a file. - * - * @author Alex Nenadic - */ -public class OpenNestedWorkflowAction extends OpenWorkflowAction { - private static final long serialVersionUID = -5398423684000142379L; - private static Logger logger = Logger - .getLogger(OpenNestedWorkflowAction.class); - - public OpenNestedWorkflowAction(FileManager fileManager) { - super(fileManager); - } - - /** - * Opens a nested workflow from a file (should be one file even though the - * method takes a list of files - this is because it overrides the - * {@link OpenWorkflowAction#openWorkflows(Component, File[], FileType, OpenCallback) - * openWorkflows(...)} method). - */ - @Override - public void openWorkflows(final Component parentComponent, File[] files, - FileType fileType, OpenCallback openCallback) { - ErrorLoggingOpenCallbackWrapper callback = new ErrorLoggingOpenCallbackWrapper( - openCallback); - for (File file : files) - try { - callback.aboutToOpenDataflow(file); - WorkflowBundle workflowBundle = fileManager.openDataflow( - fileType, file); - callback.openedDataflow(file, workflowBundle); - } catch (final RuntimeException ex) { - logger.warn("Could not open workflow from " + file, ex); - if (!callback.couldNotOpenDataflow(file, ex)) - showErrorMessage(parentComponent, file, ex); - } catch (final OpenException ex) { - logger.warn("Could not open workflow from " + file, ex); - if (!callback.couldNotOpenDataflow(file, ex)) - showErrorMessage(parentComponent, file, ex); - return; - } - } -}
