http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java deleted file mode 100644 index 1202c11..0000000 --- a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/ConfigurationManagerTest.java +++ /dev/null @@ -1,109 +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.ui.impl.configuration; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.util.UUID; - -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import net.sf.taverna.t2.workbench.ui.impl.configuration.colour.ColourManagerImpl; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl; -import uk.org.taverna.configuration.impl.ConfigurationManagerImpl; - -public class ConfigurationManagerTest { - - ConfigurationManagerImpl configurationManager; - - @Before - public void setup() { - configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl()); - } - - @Test - public void createConfigManager() { - assertNotNull("Config Manager should not be null", configurationManager); - } - - @Ignore("Hardcoded /Users/Ian") //FIXME: update test to work using File.createTempFile(...) - @Test - public void populateConfigOfColourmanager() { - ColourManager manager= new ColourManagerImpl(null); - - manager.setProperty("colour.first", "25"); - manager.setProperty("colour.second", "223"); - - configurationManager.setBaseConfigLocation(new File("/Users/Ian/scratch")); - try { - configurationManager.store(manager); - } catch (Exception e1) { - e1.printStackTrace(); - } - - ColourManager manager2 = new ColourManagerImpl(configurationManager); - - try { - configurationManager.populate(manager2); - } catch (Exception e) { - e.printStackTrace(); - } - - - assertEquals("Properties do not match", manager2.getProperty("colour.first"), manager.getProperty("colour.first")); - assertEquals("Properties do not match", manager2.getProperty("colour.second"), manager.getProperty("colour.second")); - - - } - - @Test - public void saveColoursForDummyColourable() { - String dummy = ""; - ColourManager manager=new ColourManagerImpl(configurationManager); - manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); - - File f = new File(System.getProperty("java.io.tmpdir")); - File d = new File(f, UUID.randomUUID().toString()); - d.mkdir(); - configurationManager.setBaseConfigLocation(d); - try { - configurationManager.store(manager); - } catch (Exception e1) { - e1.printStackTrace(); - } - - try { - configurationManager.populate(manager); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java b/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java deleted file mode 100644 index 0239ea8..0000000 --- a/taverna-configuration-impl/src/test/java/net/sf/taverna/t2/workbench/ui/impl/configuration/colour/ColourManagerTest.java +++ /dev/null @@ -1,90 +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.ui.impl.configuration.colour; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.awt.Color; -import java.io.File; -import java.util.UUID; - -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; - -import org.junit.Before; -import org.junit.Test; - -import uk.org.taverna.configuration.Configurable; -import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl; -import uk.org.taverna.configuration.impl.ConfigurationManagerImpl; - -public class ColourManagerTest { - - private ConfigurationManagerImpl configurationManager; - - @Before - public void setup() { - configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl()); - - File f = new File(System.getProperty("java.io.tmpdir")); - File d = new File(f, UUID.randomUUID().toString()); - d.mkdir(); - configurationManager.setBaseConfigLocation(d); - } - - @Test - public void testGetPreferredColourEqualsWhite() throws Exception { - String dummy = new String(); - - Color c = new ColourManagerImpl(configurationManager).getPreferredColour(dummy); - assertEquals("The default colour should be WHITE", Color.WHITE, c); - } - - @Test - public void testConfigurableness() throws Exception { - ColourManager manager = new ColourManagerImpl(configurationManager); - assertTrue(manager instanceof Configurable); - - assertEquals("wrong category", "colour", manager.getCategory()); - assertEquals("wrong name", "Colour Management", manager.getDisplayName()); - assertEquals("wrong UUID", "a2148420-5967-11dd-ae16-0800200c9a66", - manager.getUUID()); - assertNotNull("there is no default property map", manager - .getDefaultPropertyMap()); - } - - @Test - public void saveAsWrongArrayType() throws Exception { - String dummy = ""; - ColourManager manager = new ColourManagerImpl(configurationManager); - manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff"); - - File baseLoc = File.createTempFile("test", "scratch"); - baseLoc.delete(); - assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir()); - configurationManager.setBaseConfigLocation(baseLoc); - configurationManager.store(manager); - configurationManager.populate(manager); - manager.getPreferredColour(dummy); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/ConfigurationManagerTest.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/ConfigurationManagerTest.java b/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/ConfigurationManagerTest.java new file mode 100644 index 0000000..08a4fcc --- /dev/null +++ b/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/ConfigurationManagerTest.java @@ -0,0 +1,108 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.ui.impl.configuration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.util.UUID; + +import org.apache.taverna.workbench.configuration.colour.ColourManager; +import org.apache.taverna.workbench.ui.impl.configuration.colour.ColourManagerImpl; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl; +import uk.org.taverna.configuration.impl.ConfigurationManagerImpl; + +public class ConfigurationManagerTest { + + ConfigurationManagerImpl configurationManager; + + @Before + public void setup() { + configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl()); + } + + @Test + public void createConfigManager() { + assertNotNull("Config Manager should not be null", configurationManager); + } + + @Ignore("Hardcoded /Users/Ian") //FIXME: update test to work using File.createTempFile(...) + @Test + public void populateConfigOfColourmanager() { + ColourManager manager= new ColourManagerImpl(null); + + manager.setProperty("colour.first", "25"); + manager.setProperty("colour.second", "223"); + + configurationManager.setBaseConfigLocation(new File("/Users/Ian/scratch")); + try { + configurationManager.store(manager); + } catch (Exception e1) { + e1.printStackTrace(); + } + + ColourManager manager2 = new ColourManagerImpl(configurationManager); + + try { + configurationManager.populate(manager2); + } catch (Exception e) { + e.printStackTrace(); + } + + + assertEquals("Properties do not match", manager2.getProperty("colour.first"), manager.getProperty("colour.first")); + assertEquals("Properties do not match", manager2.getProperty("colour.second"), manager.getProperty("colour.second")); + + + } + + @Test + public void saveColoursForDummyColourable() { + String dummy = ""; + ColourManager manager=new ColourManagerImpl(configurationManager); + manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); + + File f = new File(System.getProperty("java.io.tmpdir")); + File d = new File(f, UUID.randomUUID().toString()); + d.mkdir(); + configurationManager.setBaseConfigLocation(d); + try { + configurationManager.store(manager); + } catch (Exception e1) { + e1.printStackTrace(); + } + + try { + configurationManager.populate(manager); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/colour/ColourManagerTest.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/colour/ColourManagerTest.java b/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/colour/ColourManagerTest.java new file mode 100644 index 0000000..b664a04 --- /dev/null +++ b/taverna-configuration-impl/src/test/java/org/apache/taverna/workbench/ui/impl/configuration/colour/ColourManagerTest.java @@ -0,0 +1,89 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.ui.impl.configuration.colour; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.awt.Color; +import java.io.File; +import java.util.UUID; + +import org.apache.taverna.workbench.configuration.colour.ColourManager; + +import org.junit.Before; +import org.junit.Test; + +import uk.org.taverna.configuration.Configurable; +import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl; +import uk.org.taverna.configuration.impl.ConfigurationManagerImpl; + +public class ColourManagerTest { + + private ConfigurationManagerImpl configurationManager; + + @Before + public void setup() { + configurationManager = new ConfigurationManagerImpl(new ApplicationConfigurationImpl()); + + File f = new File(System.getProperty("java.io.tmpdir")); + File d = new File(f, UUID.randomUUID().toString()); + d.mkdir(); + configurationManager.setBaseConfigLocation(d); + } + + @Test + public void testGetPreferredColourEqualsWhite() throws Exception { + String dummy = new String(); + + Color c = new ColourManagerImpl(configurationManager).getPreferredColour(dummy); + assertEquals("The default colour should be WHITE", Color.WHITE, c); + } + + @Test + public void testConfigurableness() throws Exception { + ColourManager manager = new ColourManagerImpl(configurationManager); + assertTrue(manager instanceof Configurable); + + assertEquals("wrong category", "colour", manager.getCategory()); + assertEquals("wrong name", "Colour Management", manager.getDisplayName()); + assertEquals("wrong UUID", "a2148420-5967-11dd-ae16-0800200c9a66", + manager.getUUID()); + assertNotNull("there is no default property map", manager + .getDefaultPropertyMap()); + } + + @Test + public void saveAsWrongArrayType() throws Exception { + String dummy = ""; + ColourManager manager = new ColourManagerImpl(configurationManager); + manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff"); + + File baseLoc = File.createTempFile("test", "scratch"); + baseLoc.delete(); + assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir()); + configurationManager.setBaseConfigLocation(baseLoc); + configurationManager.store(manager); + configurationManager.populate(manager); + manager.getPreferredColour(dummy); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java deleted file mode 100644 index a6da26d..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityConfigurationAction.java +++ /dev/null @@ -1,167 +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.ui.actions.activity; - -import java.util.List; -import java.util.WeakHashMap; - -import javax.swing.AbstractAction; -import javax.swing.JDialog; - -import org.apache.taverna.lang.observer.Observable; -import org.apache.taverna.lang.observer.Observer; -import net.sf.taverna.t2.servicedescriptions.ServiceDescription; -import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry; -import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager; -import net.sf.taverna.t2.workbench.file.FileManager; -import net.sf.taverna.t2.workbench.file.events.ClosingDataflowEvent; -import net.sf.taverna.t2.workbench.file.events.FileManagerEvent; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog; -import org.apache.taverna.scufl2.api.activity.Activity; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.core.Processor; -import org.apache.taverna.scufl2.api.core.Workflow; -import org.apache.taverna.scufl2.api.profiles.ProcessorBinding; -import org.apache.taverna.scufl2.api.profiles.Profile; - -@SuppressWarnings("serial") -public abstract class ActivityConfigurationAction extends AbstractAction { - private static WeakHashMap<Activity, ActivityConfigurationDialog> configurationDialogs = new WeakHashMap<>(); - private static DataflowCloseListener listener; - - protected Activity activity; - private final ServiceDescriptionRegistry serviceDescriptionRegistry; - - public ActivityConfigurationAction(Activity activity, - ActivityIconManager activityIconManager, - ServiceDescriptionRegistry serviceDescriptionRegistry) { - this.activity = activity; - this.serviceDescriptionRegistry = serviceDescriptionRegistry; - putValue(SMALL_ICON, - activityIconManager.iconForActivity(activity.getType())); - } - - protected Activity getActivity() { - return activity; - } - - protected ServiceDescription getServiceDescription() { - return serviceDescriptionRegistry.getServiceDescription(activity - .getType()); - } - - protected static void setDialog(Activity activity, - ActivityConfigurationDialog dialog, FileManager fileManager) { - if (listener == null) { - listener = new DataflowCloseListener(); - /* - * Ensure that the DataflowCloseListener is the first notified - * listener. Otherwise you cannot save the configurations. - */ - List<Observer<FileManagerEvent>> existingListeners = fileManager - .getObservers(); - fileManager.addObserver(listener); - for (Observer<FileManagerEvent> observer : existingListeners) - if (!observer.equals(listener)) { - fileManager.removeObserver(observer); - fileManager.addObserver(observer); - } - } - if (configurationDialogs.containsKey(activity)) { - ActivityConfigurationDialog currentDialog = configurationDialogs - .get(activity); - if (!currentDialog.equals(dialog) && currentDialog.isVisible()) - currentDialog.setVisible(false); - } - configurationDialogs.put(activity, dialog); - dialog.setVisible(true); - } - - public static void clearDialog(Activity activity) { - if (configurationDialogs.containsKey(activity)) { - ActivityConfigurationDialog currentDialog = configurationDialogs - .get(activity); - if (currentDialog.isVisible()) - currentDialog.setVisible(false); - configurationDialogs.remove(activity); - currentDialog.dispose(); - } - } - - protected static void clearDialog(JDialog dialog) { - if (configurationDialogs.containsValue(dialog)) { - if (dialog.isVisible()) - dialog.setVisible(false); - for (Activity activity : configurationDialogs.keySet()) - if (configurationDialogs.get(activity).equals(dialog)) - configurationDialogs.remove(activity); - dialog.dispose(); - } - } - - public static boolean closeDialog(Activity activity) { - boolean closeIt = true; - if (configurationDialogs.containsKey(activity)) { - ActivityConfigurationDialog currentDialog = configurationDialogs - .get(activity); - if (currentDialog.isVisible()) - closeIt = currentDialog.closeDialog(); - if (closeIt) - configurationDialogs.remove(activity); - } - return closeIt; - } - - public static ActivityConfigurationDialog getDialog(Activity activity) { - return configurationDialogs.get(activity); - } - - private static class DataflowCloseListener implements - Observer<FileManagerEvent> { - private Scufl2Tools scufl2Tools = new Scufl2Tools(); - - @Override - public void notify(Observable<FileManagerEvent> sender, - FileManagerEvent message) throws Exception { - if (message instanceof ClosingDataflowEvent) { - ClosingDataflowEvent closingDataflowEvent = (ClosingDataflowEvent) message; - if (closingDataflowEvent.isAbortClose()) - return; - closingDataflow(closingDataflowEvent, - ((ClosingDataflowEvent) message).getDataflow()); - } - } - - private void closingDataflow(ClosingDataflowEvent event, - WorkflowBundle bundle) { - Profile profile = bundle.getMainProfile(); - for (Workflow workflow : bundle.getWorkflows()) - for (Processor p : workflow.getProcessors()) { - ProcessorBinding processorBinding = scufl2Tools - .processorBindingForProcessor(p, profile); - Activity activity = processorBinding.getBoundActivity(); - if (!closeDialog(activity)) - event.setAbortClose(true); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java deleted file mode 100644 index 85ddfd9..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/ActivityContextualView.java +++ /dev/null @@ -1,69 +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.ui.actions.activity; - -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import org.apache.taverna.scufl2.api.activity.Activity; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.configurations.Configuration; - -/** - * A contextual view specific to an Activity. Concrete subclasses must - * initialise the view by calling {@link #initView()}. - * <p> - * The implementation provides a view based upon the properties set in the - * Configuration - * - * @author Stuart Owen - * @author Ian Dunlop - * - * @see Activity - * @see ContextualView - */ -@SuppressWarnings("serial") -public abstract class ActivityContextualView extends ContextualView { - private Activity activity; - private Scufl2Tools scufl2Tools = new Scufl2Tools(); - - /** - * Constructs an instance of the view. - * <p> - * The constructor parameter for the implementation of this class should - * define the specific Activity type itself. - * - * @param activity - */ - protected ActivityContextualView(Activity activity) { - super(); - this.activity = activity; - } - - public Activity getActivity() { - return activity; - } - - public Configuration getConfigBean() { - return scufl2Tools.configurationFor(activity, activity.getParent()); - } - - @Override - public abstract void refreshView(); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java deleted file mode 100644 index b9385cb..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/actions/activity/HTMLBasedActivityContextualView.java +++ /dev/null @@ -1,81 +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.ui.actions.activity; - -import static net.sf.taverna.t2.lang.ui.HtmlUtils.buildTableOpeningTag; -import static net.sf.taverna.t2.lang.ui.HtmlUtils.createEditorPane; -import static net.sf.taverna.t2.lang.ui.HtmlUtils.getHtmlHead; -import static net.sf.taverna.t2.lang.ui.HtmlUtils.panelForHtml; - -import javax.swing.JComponent; -import javax.swing.JEditorPane; - -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import org.apache.taverna.scufl2.api.activity.Activity; - -@SuppressWarnings("serial") -public abstract class HTMLBasedActivityContextualView extends ActivityContextualView { - private static final String BEANSHELL_URI = "http://ns.taverna.org.uk/2010/activity/beanshell"; - private static final String LOCALWORKER_URI = "http://ns.taverna.org.uk/2010/activity/localworker"; - private JEditorPane editorPane; - private final ColourManager colourManager; - - public HTMLBasedActivityContextualView(Activity activity, ColourManager colourManager) { - super(activity); - this.colourManager = colourManager; - initView(); - } - - @Override - public JComponent getMainFrame() { - editorPane = createEditorPane(buildHtml()); - return panelForHtml(editorPane); - } - - private String buildHtml() { - StringBuilder html = new StringBuilder(getHtmlHead(getBackgroundColour())); - html.append(buildTableOpeningTag()); - html.append("<tr><th colspan=\"2\">").append(getViewTitle()).append("</th></tr>"); - html.append(getRawTableRowsHtml()).append("</table>"); - html.append("</body></html>"); - return html.toString(); - } - - protected abstract String getRawTableRowsHtml(); - - public String getBackgroundColour() { - String activityType = getActivity().getType().toString(); - if (LOCALWORKER_URI.equals(activityType)) - if (getConfigBean().getJson().get("isAltered").booleanValue()) - return (String) colourManager.getProperty(BEANSHELL_URI); - String colour = (String) colourManager.getProperty(activityType); - return colour == null ? "#ffffff" : colour; - } - - /** - * Update the html view with the latest information in the configuration - * bean - */ - @Override - public void refreshView() { - editorPane.setText(buildHtml()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java deleted file mode 100644 index 7e5fd04..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/AddLayerFactorySPI.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews; - -import java.net.URI; - -import javax.swing.Action; - -import org.apache.taverna.scufl2.api.core.Processor; - -/** - * SPI for adding dispatch stack layers to a processor, such as - * {@link net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.Loop}. - * <p> - * Buttons or similar will be added in the processor contextual view. - * - * @author Stian Soiland-Reyes - */ -public interface AddLayerFactorySPI { - boolean canAddLayerFor(Processor proc); - - Action getAddLayerActionFor(Processor proc); - - boolean canCreateLayerClass(URI dispatchLayerType); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java deleted file mode 100644 index 45efaab..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/ContextualView.java +++ /dev/null @@ -1,109 +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.ui.views.contextualviews; - -import static java.awt.BorderLayout.CENTER; - -import java.awt.BorderLayout; -import java.awt.Frame; - -import javax.swing.Action; -import javax.swing.JComponent; -import javax.swing.JPanel; - -/** - * An abstract class defining the base container to hold a contextual view over - * Dataflow element. - * <p> - * The specific implementation of this class to support a given dataflow element - * needs to implement the {@link #getMainFrame()} and {@link #getViewTitle()}. - * <p> - * If a view is associated with an action handler to configure this component, - * then the {@link #getConfigureAction(Frame) getConfigureAction} handler must - * be over-ridden. If this returns null then the configure button is left - * disabled and it is not possible to configure the element. - * - * @author Stuart Owen - * @author Ian Dunlop - * @author Alan R Williams - */ -@SuppressWarnings("serial") -public abstract class ContextualView extends JPanel { - /** - * When implemented, this method should define the main frame that is placed - * in this container, and provides a static view of the Dataflow element. - * - * @return a JComponent that represents the dataflow element. - */ - public abstract JComponent getMainFrame(); - - /** - * @return a String providing a title for the view - */ - public abstract String getViewTitle(); - - /** - * Allows the item to be configured, but returning an action handler that - * will be invoked when selecting to configure. By default this is provided - * by a button. - * <p> - * If there is no ability to configure the given item, then this should - * return null. - * - * @param owner - * the owning dialog to be used when displaying dialogues for - * configuration options - * @return an action that allows the element being viewed to be configured. - */ - public Action getConfigureAction(Frame owner) { - return null; - } - - /** - * This <i>must</i> be called by any sub-classes after they have initialised - * their own view since it gets their main panel and adds it to the main - * contextual view. If you don't do this you will get a very empty frame - * popping up! - */ - public void initView() { - setLayout(new BorderLayout()); - add(getMainFrame(), CENTER); - setName(getViewTitle()); - } - - public abstract void refreshView(); - - public abstract int getPreferredPosition(); - - public static String getTextFromDepth(String kind, Integer depth) { - String labelText = "The last prediction said the " + kind; - if (depth == null) { - labelText += " would not transmit a value"; - } else if (depth == -1) { - labelText += " was invalid/unpredicted"; - } else if (depth == 0) { - labelText += " would carry a single value"; - } else { - labelText += " would carry a list of depth " + depth; - } - return labelText; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java deleted file mode 100644 index decea0f..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java +++ /dev/null @@ -1,474 +0,0 @@ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity; - -import static java.awt.BorderLayout.SOUTH; -import static java.awt.Cursor.DEFAULT_CURSOR; -import static java.awt.Cursor.WAIT_CURSOR; -import static java.awt.Cursor.getPredefinedCursor; -import static java.lang.Math.max; -import static javax.swing.JOptionPane.CANCEL_OPTION; -import static javax.swing.JOptionPane.NO_OPTION; -import static javax.swing.JOptionPane.YES_NO_CANCEL_OPTION; -import static javax.swing.JOptionPane.YES_NO_OPTION; -import static javax.swing.JOptionPane.YES_OPTION; -import static javax.swing.JOptionPane.showConfirmDialog; -import static net.sf.taverna.t2.workbench.MainWindow.getMainWindow; -import static net.sf.taverna.t2.workbench.helper.Helper.showHelp; -import static net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction.clearDialog; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.swing.AbstractAction; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import org.apache.taverna.lang.observer.Observable; -import org.apache.taverna.lang.observer.Observer; -import net.sf.taverna.t2.lang.ui.DeselectingButton; -import net.sf.taverna.t2.workbench.edits.CompoundEdit; -import net.sf.taverna.t2.workbench.edits.Edit; -import net.sf.taverna.t2.workbench.edits.EditException; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.edits.EditManager.DataFlowRedoEvent; -import net.sf.taverna.t2.workbench.edits.EditManager.DataFlowUndoEvent; -import net.sf.taverna.t2.workbench.edits.EditManager.EditManagerEvent; -import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog; -import net.sf.taverna.t2.workflow.edits.AddChildEdit; -import net.sf.taverna.t2.workflow.edits.AddProcessorInputPortEdit; -import net.sf.taverna.t2.workflow.edits.AddProcessorOutputPortEdit; -import net.sf.taverna.t2.workflow.edits.ChangeDepthEdit; -import net.sf.taverna.t2.workflow.edits.ChangeGranularDepthEdit; -import net.sf.taverna.t2.workflow.edits.ChangeJsonEdit; -import net.sf.taverna.t2.workflow.edits.RemoveChildEdit; -import net.sf.taverna.t2.workflow.edits.RemoveProcessorInputPortEdit; -import net.sf.taverna.t2.workflow.edits.RemoveProcessorOutputPortEdit; -import net.sf.taverna.t2.workflow.edits.RenameEdit; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.activity.Activity; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.configurations.Configuration; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.core.Processor; -import org.apache.taverna.scufl2.api.core.Workflow; -import org.apache.taverna.scufl2.api.port.ActivityPort; -import org.apache.taverna.scufl2.api.port.InputActivityPort; -import org.apache.taverna.scufl2.api.port.InputProcessorPort; -import org.apache.taverna.scufl2.api.port.OutputActivityPort; -import org.apache.taverna.scufl2.api.port.OutputProcessorPort; -import org.apache.taverna.scufl2.api.profiles.ProcessorBinding; -import org.apache.taverna.scufl2.api.profiles.ProcessorInputPortBinding; -import org.apache.taverna.scufl2.api.profiles.ProcessorOutputPortBinding; -import org.apache.taverna.scufl2.api.profiles.Profile; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -@SuppressWarnings("serial") -public class ActivityConfigurationDialog extends HelpEnabledDialog { - private enum PortType { - INPUT, OUTPUT - } - - protected static Logger logger = Logger.getLogger(ActivityConfigurationDialog.class); - private static final Scufl2Tools scufl2Tools = new Scufl2Tools(); - - private final EditManager editManager; - - private Activity activity; - private ActivityConfigurationPanel panel; - protected WorkflowBundle owningWorkflowBundle; - protected Processor owningProcessor; - private Observer<EditManagerEvent> observer; - Dimension minimalSize = null; - Dimension buttonPanelSize = null; - JPanel buttonPanel; - protected JButton applyButton; - - public ActivityConfigurationDialog(Activity a, ActivityConfigurationPanel p, - EditManager editManager) { - super(getMainWindow(), "Configuring " + a.getClass().getSimpleName(), - false, null); - this.activity = a; - this.panel = p; - this.editManager = editManager; - - owningWorkflowBundle = activity.getParent().getParent(); - owningProcessor = findProcessor(a); - - setTitle(getRelativeName(owningWorkflowBundle, activity)); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - setLayout(new BorderLayout()); - - add(panel, BorderLayout.CENTER); - - buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - buttonPanel.setBorder(new EmptyBorder(5, 20, 5, 5)); - - JButton helpButton = new DeselectingButton("Help", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - showHelp(panel); - } - }); - buttonPanel.add(helpButton); - - applyButton = new DeselectingButton("Apply", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - /* - * For the moment it always does an apply as what should be - * happening is that the apply button only becomes available - * when the configuration has changed. However, many - * configuration panels are not set up to detected changes - */ - // if (panel.isConfigurationChanged()) { - if (checkPanelValues()) - applyConfiguration(); - // } else { - // logger.info("Ignoring apply"); - // } - } - }); - buttonPanel.add(applyButton); - - JButton closeButton = new DeselectingButton("Close", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - closeDialog(); - } - }); - buttonPanel.add(closeButton); - - add(buttonPanel, SOUTH); - - this.addWindowListener(new WindowAdapter() { - @Override - public void windowOpened(WindowEvent e) { - requestFocusInWindow(); - panel.whenOpened(); - } - - @Override - public void windowClosing(WindowEvent e) { - closeDialog(); - } - }); - pack(); - minimalSize = getSize(); - setLocationRelativeTo(null); - setResizable(true); - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int newWidth = max(getWidth(), minimalSize.width); - int newHeight = max(getHeight(), minimalSize.height); - setSize(new Dimension(newWidth, newHeight)); - } - }); - - observer = new Observer<EditManagerEvent>() { - @Override - public void notify(Observable<EditManagerEvent> sender, EditManagerEvent message) - throws Exception { - logger.info("sender is a " + sender.getClass().getCanonicalName()); - logger.info("message is a " + message.getClass().getCanonicalName()); - Edit<?> edit = message.getEdit(); - logger.info(edit.getClass().getCanonicalName()); - considerEdit(message, edit); - } - }; - editManager.addObserver(observer); - } - - private boolean checkPanelValues() { - boolean result = false; - try { - setCursor(getPredefinedCursor(WAIT_CURSOR)); - result = panel.checkValues(); - } finally { - setCursor(getPredefinedCursor(DEFAULT_CURSOR)); - } - return result; - } - - private void considerEdit(EditManagerEvent message, Edit<?> edit) { - // boolean result = false; - if (edit instanceof CompoundEdit) { - for (Edit<?> subEdit : ((CompoundEdit) edit).getChildEdits()) - considerEdit(message, subEdit); - return; - } - - Object subject = edit.getSubject(); - if (subject == owningProcessor) { - // panel.reevaluate(); - setTitle(getRelativeName(owningWorkflowBundle, activity)); - } else if (subject == owningWorkflowBundle) { - for (Workflow workflow : owningWorkflowBundle.getWorkflows()) - if (!workflow.getProcessors().contains(owningProcessor)) - clearDialog(activity); - } else if (subject == activity) { - if (message instanceof DataFlowUndoEvent) { - logger.info("undo of activity edit found"); - panel.refreshConfiguration(); - } else if (message instanceof DataFlowRedoEvent) { - logger.info("redo of activity edit found"); - panel.refreshConfiguration(); - } - } - } - - protected void configureActivity(ObjectNode json, List<ActivityPortConfiguration> inputPorts, - List<ActivityPortConfiguration> outputPorts) { - configureActivity(owningWorkflowBundle, activity, json, inputPorts, outputPorts); - } - - public void configureActivity(WorkflowBundle workflowBundle, Activity activity, - ObjectNode json, List<ActivityPortConfiguration> inputPorts, - List<ActivityPortConfiguration> outputPorts) { - try { - List<Edit<?>> editList = new ArrayList<Edit<?>>(); - Profile profile = activity.getParent(); - List<ProcessorBinding> processorBindings = scufl2Tools - .processorBindingsToActivity(activity); - Configuration configuration = scufl2Tools.configurationFor(activity, profile); - editList.add(new ChangeJsonEdit(configuration, json)); - - configurePorts(activity, editList, processorBindings, inputPorts, PortType.INPUT); - configurePorts(activity, editList, processorBindings, outputPorts, PortType.OUTPUT); - editManager.doDataflowEdit(workflowBundle, new CompoundEdit(editList)); - } catch (IllegalStateException | EditException e) { - logger.error(e); - } - } - - private void configurePorts(Activity activity, List<Edit<?>> editList, - List<ProcessorBinding> processorBindings, - List<ActivityPortConfiguration> portDefinitions, PortType portType) { - Set<ActivityPort> ports = new HashSet<>(); - for (ActivityPort activityPort : portType == PortType.INPUT ? activity - .getInputPorts() : activity.getOutputPorts()) - ports.add(activityPort); - for (ActivityPortConfiguration portDefinition : portDefinitions) { - String portName = portDefinition.getName(); - int portDepth = portDefinition.getDepth(); - int granularPortDepth = portDefinition.getGranularDepth(); - ActivityPort activityPort = portDefinition.getActivityPort(); - if (activityPort == null) { - // no activity port so add a new one - if (portType == PortType.INPUT) - createInputPort(activity, editList, processorBindings, portDefinition); - else - createOutputPort(activity, editList, processorBindings, portDefinition); - } else { - ports.remove(activityPort); - // check if port has changed - for (ProcessorBinding processorBinding : processorBindings) - if (portType == PortType.INPUT) - for (ProcessorInputPortBinding portBinding : processorBinding - .getInputPortBindings()) { - if (!portBinding.getBoundActivityPort().equals( - activityPort)) - continue; - InputProcessorPort processorPort = portBinding - .getBoundProcessorPort(); - if (!activityPort.getName().equals(portName)) - // port name changed - if (processorPort.getName().equals(activityPort.getName())) - // default mapping so change processor port - editList.add(new RenameEdit<>(processorPort, portName)); - if (!processorPort.getDepth().equals(portDepth)) - // port depth changed - editList.add(new ChangeDepthEdit<>( - processorPort, portDepth)); - } - else - for (ProcessorOutputPortBinding portBinding : processorBinding - .getOutputPortBindings()) { - if (!portBinding.getBoundActivityPort().equals( - activityPort)) - continue; - OutputProcessorPort processorPort = portBinding - .getBoundProcessorPort(); - if (!activityPort.getName().equals(portName)) - // port name changed - if (processorPort.getName().equals( - activityPort.getName())) - // default mapping so change processor port - editList.add(new RenameEdit<>( - processorPort, portName)); - if (!processorPort.getDepth().equals(portDepth)) - // port depth changed - editList.add(new ChangeDepthEdit<>( - processorPort, portDepth)); - if (!processorPort.getGranularDepth().equals( - granularPortDepth)) - // port granular depth changed - editList.add(new ChangeGranularDepthEdit<>( - processorPort, granularPortDepth)); - } - if (!activityPort.getName().equals(portName)) - // port name changed - editList.add(new RenameEdit<>(activityPort, portName)); - if (!activityPort.getDepth().equals(portDepth)) - // port depth changed - editList.add(new ChangeDepthEdit<>(activityPort, portDepth)); - if (activityPort instanceof OutputActivityPort) { - OutputActivityPort outputActivityPort = (OutputActivityPort) activityPort; - Integer granularDepth = outputActivityPort - .getGranularDepth(); - if (granularDepth == null - || !granularDepth.equals(granularPortDepth)) - // granular port depth changed - editList.add(new ChangeGranularDepthEdit<>( - outputActivityPort, granularPortDepth)); - } - } - } - - // remove any unconfigured ports - for (ActivityPort activityPort : ports) { - // remove processor ports and bindings - for (ProcessorBinding processorBinding : processorBindings) - if (portType.equals(PortType.INPUT)) - for (ProcessorInputPortBinding portBinding : processorBinding - .getInputPortBindings()) { - if (portBinding.getBoundActivityPort().equals(activityPort)) { - editList.add(new RemoveProcessorInputPortEdit(processorBinding - .getBoundProcessor(), portBinding.getBoundProcessorPort())); - editList.add(new RemoveChildEdit<>(processorBinding, - portBinding)); - } - } - else - for (ProcessorOutputPortBinding portBinding : processorBinding - .getOutputPortBindings()) - if (portBinding.getBoundActivityPort().equals(activityPort)) { - editList.add(new RemoveProcessorOutputPortEdit(processorBinding - .getBoundProcessor(), portBinding.getBoundProcessorPort())); - editList.add(new RemoveChildEdit<>(processorBinding, - portBinding)); - } - // remove activity port - editList.add(new RemoveChildEdit<Activity>(activity, activityPort)); - } - } - - private void createInputPort(Activity activity, List<Edit<?>> editList, - List<ProcessorBinding> processorBindings, - ActivityPortConfiguration portDefinition) { - InputActivityPort actPort = new InputActivityPort(null, - portDefinition.getName()); - actPort.setDepth(portDefinition.getDepth()); - // add port to activity - editList.add(new AddChildEdit<>(activity, actPort)); - for (ProcessorBinding processorBinding : processorBindings) { - Processor processor = processorBinding.getBoundProcessor(); - // add a new processor port - InputProcessorPort procPort = new InputProcessorPort(); - procPort.setName(portDefinition.getName()); - procPort.setDepth(portDefinition.getDepth()); - editList.add(new AddProcessorInputPortEdit(processor, procPort)); - // add a new port binding - ProcessorInputPortBinding binding = new ProcessorInputPortBinding(); - binding.setBoundProcessorPort(procPort); - binding.setBoundActivityPort(actPort); - editList.add(new AddChildEdit<>(processorBinding, binding)); - } - } - - private void createOutputPort(Activity activity, List<Edit<?>> editList, - List<ProcessorBinding> processorBindings, - ActivityPortConfiguration portDefinition) { - OutputActivityPort actPort = new OutputActivityPort(null, - portDefinition.getName()); - actPort.setDepth(portDefinition.getDepth()); - actPort.setGranularDepth(portDefinition.getGranularDepth()); - // add port to activity - editList.add(new AddChildEdit<Activity>(activity, actPort)); - for (ProcessorBinding processorBinding : processorBindings) { - Processor processor = processorBinding.getBoundProcessor(); - // add a new processor port - OutputProcessorPort procPort = new OutputProcessorPort(); - procPort.setName(portDefinition.getName()); - procPort.setDepth(portDefinition.getDepth()); - procPort.setGranularDepth(portDefinition.getGranularDepth()); - editList.add(new AddProcessorOutputPortEdit(processor, procPort)); - // add a new port binding - ProcessorOutputPortBinding binding = new ProcessorOutputPortBinding(); - binding.setBoundProcessorPort(procPort); - binding.setBoundActivityPort(actPort); - editList.add(new AddChildEdit<>(processorBinding, binding)); - } - } - - protected static Processor findProcessor(Activity activity) { - for (ProcessorBinding processorBinding : scufl2Tools - .processorBindingsToActivity(activity)) - return processorBinding.getBoundProcessor(); - return null; - } - - public static String getRelativeName(WorkflowBundle workflowBundle, Activity activity) { - StringBuilder relativeName = new StringBuilder(""); - if (workflowBundle != null) { - Workflow workflow = workflowBundle.getMainWorkflow(); - if (workflow != null) { - relativeName.append(workflow.getName()); - relativeName.append(":"); - } - } - Processor processor = findProcessor(activity); - if (processor != null) - relativeName.append(processor.getName()); - return relativeName.toString(); - } - - public boolean closeDialog() { - if (panel.isConfigurationChanged()) { - String relativeName = getRelativeName(owningWorkflowBundle, activity); - if (checkPanelValues()) { - int answer = showConfirmDialog(this, - "Do you want to save the configuration of " + relativeName + "?", - relativeName, YES_NO_CANCEL_OPTION); - if (answer == YES_OPTION) { - applyConfiguration(); - } else if (answer == CANCEL_OPTION) { - return false; - } - } else if (showConfirmDialog( - this, - "New configuration could not be saved. Do you still want to close?", - relativeName, YES_NO_OPTION) == NO_OPTION) - return false; - } - panel.whenClosed(); - clearDialog(activity); - return true; - } - - private void applyConfiguration() { - panel.noteConfiguration(); - configureActivity(panel.getJson(), panel.getInputPorts(), - panel.getOutputPorts()); - panel.refreshConfiguration(); - } - - @Override - public void dispose() { - super.dispose(); - editManager.removeObserver(observer); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationPanel.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationPanel.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationPanel.java deleted file mode 100644 index 38d19a2..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityConfigurationPanel.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * - */ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.JPanel; - -import org.apache.log4j.Logger; - -import org.apache.taverna.commons.services.ActivityTypeNotFoundException; -import org.apache.taverna.commons.services.InvalidConfigurationException; -import org.apache.taverna.commons.services.ServiceRegistry; -import org.apache.taverna.scufl2.api.activity.Activity; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.configurations.Configuration; -import org.apache.taverna.scufl2.api.port.ActivityPort; -import org.apache.taverna.scufl2.api.port.InputActivityPort; -import org.apache.taverna.scufl2.api.port.OutputActivityPort; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * @author alanrw - */ -@SuppressWarnings("serial") -public abstract class ActivityConfigurationPanel extends JPanel { - private static final Logger logger = Logger.getLogger(ActivityConfigurationPanel.class); - private final static Scufl2Tools scufl2Tools = new Scufl2Tools(); - - // protected final URITools uriTools = new URITools(); - private final Activity activity; - private final Configuration configuration; - private final List<ActivityPortConfiguration> inputPorts; - private final List<ActivityPortConfiguration> outputPorts; - protected ObjectNode json; - - public ActivityConfigurationPanel(Activity activity) { - this(activity, scufl2Tools.configurationFor(activity, - activity.getParent())); - } - - public ActivityConfigurationPanel(Activity activity, - Configuration configuration) { - this.activity = activity; - this.configuration = configuration; - inputPorts = new ArrayList<>(); - outputPorts = new ArrayList<>(); - } - - /** - * Initializes the configuration panel. This method is also used to discard - * any changes and reset the panel to its initial state. Subclasses should - * implement this method to set up the panel and must call - * <tt>super.initialise()</tt> first. - */ - protected void initialise() { - json = configuration.getJson().deepCopy(); - inputPorts.clear(); - for (InputActivityPort activityPort : activity.getInputPorts()) - inputPorts.add(new ActivityPortConfiguration(activityPort)); - outputPorts.clear(); - for (OutputActivityPort activityPort : activity.getOutputPorts()) - outputPorts.add(new ActivityPortConfiguration(activityPort)); - } - - public abstract boolean checkValues(); - - public abstract void noteConfiguration(); - - public boolean isConfigurationChanged() { - noteConfiguration(); - if (portsChanged(inputPorts, activity.getInputPorts().size())) - return true; - if (portsChanged(outputPorts, activity.getOutputPorts().size())) - return true; - return !json.equals(configuration.getJson()); - } - - public Configuration getConfiguration() { - return configuration; - } - - public ObjectNode getJson() { - return json; - } - - protected void setJson(ObjectNode json) { - this.json = json; - } - - public void refreshConfiguration() { - initialise(); - } - - public void whenOpened() { - } - - public void whenClosed() { - } - - /** - * Convenience method for getting simple String property values. - * - * @param name - * the property name - * @return the property value - */ - protected String getProperty(String name) { - JsonNode jsonNode = json.get(name); - if (jsonNode == null) - return null; - return json.get(name).asText(); - } - - /** - * Convenience method for setting simple String property values. - * - * @param name - * the property name - * @param value - * the property value - */ - protected void setProperty(String name, String value) { - json.put(name, value); - } - - public List<ActivityPortConfiguration> getInputPorts() { - return inputPorts; - } - - public List<ActivityPortConfiguration> getOutputPorts() { - return outputPorts; - } - - protected void configureInputPorts(ServiceRegistry serviceRegistry) { - try { - Map<String, InputActivityPort> newInputPorts = new HashMap<>(); - for (InputActivityPort port : serviceRegistry - .getActivityInputPorts(getActivity().getType(), getJson())) - newInputPorts.put(port.getName(), port); - List<ActivityPortConfiguration> inputPorts = getInputPorts(); - for (ActivityPortConfiguration portConfig : new ArrayList<>( - inputPorts)) - if (newInputPorts.containsKey(portConfig.getName())) { - InputActivityPort port = newInputPorts.remove(portConfig - .getName()); - portConfig.setDepth(port.getDepth()); - } else - inputPorts.remove(portConfig); - for (InputActivityPort newPort : newInputPorts.values()) - inputPorts.add(new ActivityPortConfiguration(newPort.getName(), - newPort.getDepth())); - } catch (InvalidConfigurationException | ActivityTypeNotFoundException e) { - logger.warn("Error configuring input ports", e); - } - } - - protected void configureOutputPorts(ServiceRegistry serviceRegistry) { - try { - Map<String, OutputActivityPort> newOutputPorts = new HashMap<>(); - for (OutputActivityPort port : serviceRegistry - .getActivityOutputPorts(getActivity().getType(), getJson())) - newOutputPorts.put(port.getName(), port); - List<ActivityPortConfiguration> outputPorts = getOutputPorts(); - for (ActivityPortConfiguration portConfig : new ArrayList<>( - outputPorts)) - if (newOutputPorts.containsKey(portConfig.getName())) { - OutputActivityPort port = newOutputPorts.remove(portConfig - .getName()); - portConfig.setDepth(port.getDepth()); - portConfig.setGranularDepth(port.getGranularDepth()); - } else - outputPorts.remove(portConfig); - for (OutputActivityPort newPort : newOutputPorts.values()) - outputPorts.add(new ActivityPortConfiguration( - newPort.getName(), newPort.getDepth())); - } catch (InvalidConfigurationException | ActivityTypeNotFoundException e) { - logger.warn("Error configuring output ports", e); - } - } - - private boolean portsChanged(List<ActivityPortConfiguration> portDefinitions, int ports) { - int checkedPorts = 0; - for (ActivityPortConfiguration portDefinition : portDefinitions) { - String portName = portDefinition.getName(); - int portDepth = portDefinition.getDepth(); - ActivityPort activityPort = portDefinition.getActivityPort(); - if (activityPort == null) - // new port added - return true; - if (!activityPort.getName().equals(portName)) - // port name changed - return true; - if (!activityPort.getDepth().equals(portDepth)) - // port depth changed - return true; - checkedPorts++; - } - if (checkedPorts < ports) - // ports deleted - return true; - return false; - } - - public Activity getActivity() { - return activity; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityPortConfiguration.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityPortConfiguration.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityPortConfiguration.java deleted file mode 100644 index 7e17ec6..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ActivityPortConfiguration.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2013 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity; - -import org.apache.taverna.scufl2.api.port.ActivityPort; - -/** - * - * - * @author David Withers - */ -public class ActivityPortConfiguration { - - private ActivityPort activityPort; - - private String name; - - private int depth; - - private int granularDepth; - - public ActivityPortConfiguration(ActivityPort activityPort) { - this.activityPort = activityPort; - name = activityPort.getName(); - depth = activityPort.getDepth(); - } - - public ActivityPortConfiguration(String name, int depth) { - this(name, depth, depth); - } - - public ActivityPortConfiguration(String name, int depth, int granularDepth) { - this.name = name; - this.depth = depth; - this.granularDepth = granularDepth; - } - - public ActivityPort getActivityPort() { - return activityPort; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getDepth() { - return depth; - } - - public void setDepth(int depth) { - this.depth = depth; - } - - public int getGranularDepth() { - return granularDepth; - } - - public void setGranularDepth(int granularDepth) { - this.granularDepth = granularDepth; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactory.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactory.java deleted file mode 100644 index b5d29d7..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactory.java +++ /dev/null @@ -1,63 +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.ui.views.contextualviews.activity; - -import java.util.List; - -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; - -/** - * Defines a factory class that when associated with a selected object creates a - * {@link ContextualView} for that selection. - * <p> - * This factory acts as an SPI to find {@link ContextualView}s for a given - * Activity and other workflow components. - * </p> - * - * @author Stuart Owen - * @author Ian Dunlop - * @author Stian Soiland-Reyes - * - * - * @param <SelectionType> - * - the selection type this factory is associated with - * - * @see ContextualView - * @see ContextualViewFactoryRegistry - */ -public interface ContextualViewFactory<SelectionType> { - /** - * @param selection - * - the object for which ContextualViews needs to be generated - * @return instance of {@link ContextualView} - */ - public List<ContextualView> getViews(SelectionType selection); - - /** - * Used by the SPI system to find the correct factory that can handle the - * given object type. - * - * @param selection - * @return true if this factory relates to the given selection type - * @see ContextualViewFactoryRegistry - */ - public boolean canHandle(Object selection); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactoryRegistry.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactoryRegistry.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactoryRegistry.java deleted file mode 100644 index 305f3c0..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/ContextualViewFactoryRegistry.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2011 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity; - -import java.util.List; - -/** - * A registry for discovering ActivityViewFactories for a given object, - * like an {@link net.sf.taverna.t2.workflowmodel.processor.activity.Activity}. - * - * @author David Withers - */ -public interface ContextualViewFactoryRegistry { - /** - * Discover and return the ContextualViewFactory associated to the provided - * object. This is accomplished by returning the discovered - * {@link ContextualViewFactory#canHandle(Object)} that returns true for - * that Object. - * - * @param object - * @return - * @see ContextualViewFactory#canHandle(Object) - */ - public <T> List<ContextualViewFactory<? super T>> getViewFactoriesForObject(T object); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/DependencyConfigurationPanel.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/DependencyConfigurationPanel.java b/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/DependencyConfigurationPanel.java deleted file mode 100644 index c28cb55..0000000 --- a/taverna-contextual-views-api/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/activity/DependencyConfigurationPanel.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2013 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.activity; - -import static java.awt.BorderLayout.CENTER; -import static java.awt.BorderLayout.NORTH; -import static java.awt.Color.RED; -import static java.awt.GridBagConstraints.FIRST_LINE_START; -import static java.awt.GridBagConstraints.HORIZONTAL; -import static java.awt.event.ItemEvent.DESELECTED; -import static java.awt.event.ItemEvent.SELECTED; -import static java.util.Arrays.asList; -import static javax.swing.Box.createRigidArea; -import static javax.swing.BoxLayout.PAGE_AXIS; -import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; -import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.io.File; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.swing.BoxLayout; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.border.EmptyBorder; - -/** - * Component for configuring activities that require dependencies. - * - * @author David Withers - */ -@SuppressWarnings("serial") -public class DependencyConfigurationPanel extends JPanel { - private String classLoaderSharing; - private List<String> localDependencies; - private File libDir; - - public DependencyConfigurationPanel(String classLoaderSharing, - List<String> localDependencies, File libDir) { - this.classLoaderSharing = classLoaderSharing; - this.localDependencies = localDependencies; - this.libDir = libDir; - setLayout(new BoxLayout(this, PAGE_AXIS)); - - // Create panel with classloading options - JPanel classloadingPanel = new ClassloadingPanel(); - // Create panel for selecting jar files - JPanel jarFilesPanel = new JarFilesPanel(); - - add(classloadingPanel); - add(createRigidArea(new Dimension(0,10))); - add(jarFilesPanel); - add(createRigidArea(new Dimension(0,10))); - - } - - public String getClassLoaderSharing() { - return classLoaderSharing; - } - - public List<String> getLocalDependencies() { - return localDependencies; - } - - // Classloading option 'workflow' - private static final String WORKFLOW = "Shared for whole workflow"; - // Classloading option 'system' - private static final String SYSTEM = "System classloader"; - - // Panel containing classloading options - private class ClassloadingPanel extends JPanel { - // Combobox with classloading options - private JComboBox<String> jcbClassloadingOption; - // Classloading option descriptions - private HashMap<String, String> classloadingDescriptions; - // JLabel with classloading option description - private JLabel jlClassloadingDescription; - - /* - * Panel containing a list of possible classloading options which users - * can select from - */ - private ClassloadingPanel() { - super(new GridBagLayout()); - jcbClassloadingOption = new JComboBox<>(new String[] { WORKFLOW, - SYSTEM }); - // Set the current classlaoding option based on the configuration bean - if ("workflow".equals(classLoaderSharing)) { - jcbClassloadingOption.setSelectedItem(WORKFLOW); - } else if ("system".equals(classLoaderSharing)) { - jcbClassloadingOption.setSelectedItem(SYSTEM); - } - - jcbClassloadingOption.addActionListener(new ActionListener(){ - // Fires up when combobox selection changes - @Override - public void actionPerformed(ActionEvent e) { - Object selectedItem = jcbClassloadingOption.getSelectedItem(); - jlClassloadingDescription.setText(classloadingDescriptions - .get(selectedItem)); - if (selectedItem.equals(WORKFLOW)) - classLoaderSharing = "workflow"; - else if (selectedItem.equals(SYSTEM)) - classLoaderSharing = "system"; - } - }); - //jcbClassloadingOption.setEnabled(false); - - classloadingDescriptions = new HashMap<>(); - classloadingDescriptions.put(WORKFLOW, "<html><small>" - + "Classes are shared across the whole workflow (with any service<br>" - + "also selecting this option), but are reinitialised for each workflow run.<br>" - + "This might be needed if a service passes objects to another, or <br>" - + "state is shared within static members of loaded classes." - + "</small></html>"); - classloadingDescriptions.put(SYSTEM, "<html><small><p>" - + "The (global) system classloader is used, any dependencies defined here are<br>" - + "made available globally on the first run. Note that if you are NOT using<br>" - + "the defaulf Taverna BootstrapClassLoader, any settings here will be disregarded." - + "</p><p>" - + "This is mainly useful if you are using JNI-based libraries. Note that <br>" - + "for JNI you also have to specify <code>-Djava.library.path</code> and <br>" - + "probably your operating system's dynamic library search path<br>" - + "<code>LD_LIBRARY_PATH</code> / <code>DYLD_LIBRARY_PATH</code> / <code>PATH</code> </p>" - + "</small></html>"); - - /* - * Set the current classlaoding description based on the item - * selected in the combobox. - */ - jlClassloadingDescription = new JLabel(classloadingDescriptions - .get(jcbClassloadingOption.getSelectedItem())); - - // Add components to the ClassloadingPanel - GridBagConstraints c = new GridBagConstraints(); - c.anchor = FIRST_LINE_START; - c.fill = HORIZONTAL; - c.gridx = 0; - c.insets = new Insets(10,0,0,0); - add(new JLabel("Classloader persistence"), c); - c.insets = new Insets(0,0,0,0); - add(jcbClassloadingOption, c); - c.insets = new Insets(0,30,0,0); - add(jlClassloadingDescription, c); - } - } - - // Panel for users to add local JAR dependencies (contains a list of jar files which users can select from) - private class JarFilesPanel extends JPanel { - private JLabel warning = new JLabel( - "<html>" - + "<center<font color='red'>" - + "Warning: Depending on local libraries makes this workflow<br>" - + "difficult or impossible to run for other users. Try depending<br>" - + "on artifacts from a public repository if possible.</font></center>" - + "</html>"); - - private JarFilesPanel() { - super(); - setMinimumSize(new Dimension(400, 150)); - setLayout(new BorderLayout()); - setBorder(new EmptyBorder(0,10,0,10)); - - JPanel labelPanel = new JPanel(); - labelPanel.setLayout(new BoxLayout(labelPanel, PAGE_AXIS)); - JLabel label = new JLabel("Local JAR files"); - JLabel libLabel = new JLabel("<html><small>" + libDir.getAbsolutePath() - + "</small></html>"); - labelPanel.add(label); - labelPanel.add(libLabel); - - add(labelPanel, NORTH); - add(new JScrollPane(jarFiles(), VERTICAL_SCROLLBAR_AS_NEEDED, - HORIZONTAL_SCROLLBAR_NEVER), CENTER); - - warning.setVisible(false); - /* - * We'll skip the warning until we actually have support for - * artifacts - */ - //add(warning); - updateWarning(); - } - - private void updateWarning() { - // Show warning if there is any local dependencies - warning.setVisible(!localDependencies.isEmpty()); - } - - public JPanel jarFiles() { - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, PAGE_AXIS)); - - // List of all jar files in the lib directory - List<String> jarFiles = asList(libDir - .list(new FileExtFilter(".jar"))); - /* - * We also add the list of jars that may have been configured - * sometime before but are now not present in the lib directory for - * some reason - */ - Set<String> missingLocalDeps = new HashSet<>(localDependencies); - missingLocalDeps.removeAll(jarFiles); - /* - * jarFiles and missingLocalDeps now contain two sets of files that - * do not intersect - */ - List<String> jarFilesList = new ArrayList<>(); - // Put them all together - jarFilesList.addAll(jarFiles); - jarFilesList.addAll(missingLocalDeps); - Collections.sort(jarFilesList); - - if (jarFilesList.isEmpty()) { - panel.add(new JLabel("<html><small>To depend on a JAR file, " - + "copy it to the above-mentioned folder.</small></html>")); - return panel; - } - - for (String jarFile : jarFilesList) { - JCheckBox checkBox = new JCheckBox(jarFile); - // Has it already been selected in some previous configuring? - checkBox.setSelected(localDependencies.contains(jarFile)); - checkBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - JCheckBox box = (JCheckBox) e.getSource(); - if (e.getStateChange() == SELECTED) - localDependencies.add(box.getText()); - else if (e.getStateChange() == DESELECTED) - localDependencies.remove(box.getText()); - updateWarning(); - } - }); - panel.add(checkBox); - // The jar may not be in the lib directory, so warn the user - if (!new File(libDir, jarFile).exists()) { - checkBox.setForeground(RED); - checkBox.setText(checkBox.getText() + " (missing file!)"); - } - } - return panel; - } - } - - public static class FileExtFilter implements FilenameFilter { - final String ext; - - public FileExtFilter(String ext) { - this.ext = ext; - } - - @Override - public boolean accept(File dir, String name) { - return name.endsWith(ext); - } - } -}
