You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2018/06/29 10:55:08 UTC
[21/27] incubator-taverna-plugin-component git commit: package rename
folders
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/util/Utils.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/util/Utils.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/util/Utils.java
new file mode 100644
index 0000000..e81cbf6
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/util/Utils.java
@@ -0,0 +1,144 @@
+/*
+* 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 io.github.taverna_extras.component.ui.util;
+
+import static io.github.taverna_extras.component.ui.ComponentConstants.ACTIVITY_URI;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import io.github.taverna_extras.component.api.ComponentFactory;
+import io.github.taverna_extras.component.api.Version;
+import io.github.taverna_extras.component.ui.preference.ComponentPreference;
+import io.github.taverna_extras.component.ui.serviceprovider.ComponentServiceIcon;
+import io.github.taverna_extras.component.ui.serviceprovider.ComponentServiceProvider;
+
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.common.Named;
+import org.apache.taverna.scufl2.api.common.NamedSet;
+import org.apache.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.servicedescriptions.ServiceDescriptionRegistry;
+import org.apache.taverna.workbench.file.FileManager;
+//import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+//import net.sf.taverna.t2.workbench.file.FileManager;
+
+/**
+ * @author alanrw
+ */
+public class Utils {
+ // From http://stackoverflow.com/questions/163360/regular-expresion-to-match-urls-in-java
+ public static String URL_PATTERN = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
+ public static final String LONG_STRING = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+ public static final String SHORT_STRING = "XXX";
+
+ private FileManager fileManager;
+ private ServiceDescriptionRegistry registry;
+ private ComponentFactory factory;
+ private ComponentPreference prefs;
+ private ComponentServiceIcon icon;
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setIcon(ComponentServiceIcon icon) {
+ this.icon = icon;
+ }
+
+ public void setPrefs(ComponentPreference prefs) {
+ this.prefs = prefs;
+ }
+
+ public void setRegistry(ServiceDescriptionRegistry registry) {
+ this.registry = registry;
+ }
+
+ public void refreshComponentServiceProvider(Configuration config) {
+ ComponentServiceProvider provider = new ComponentServiceProvider(
+ factory, prefs, icon, this);
+ provider.configure(config);
+ registry.removeServiceDescriptionProvider(provider);
+ registry.addServiceDescriptionProvider(provider);
+ }
+
+ public void removeComponentServiceProvider(Configuration config) {
+ ComponentServiceProvider provider = new ComponentServiceProvider(
+ factory, prefs, icon, this);
+ provider.configure(config);
+ registry.removeServiceDescriptionProvider(provider);
+ }
+
+ public boolean dataflowIsComponent(WorkflowBundle d) {
+ if (d == null)
+ return false;
+ Object dataflowSource = fileManager.getDataflowSource(d);
+ return dataflowSource instanceof Version.ID;// FIXME Really?
+ }
+
+ public boolean currentDataflowIsComponent() {
+ return dataflowIsComponent(fileManager.getCurrentDataflow());
+ }
+
+ public static boolean isComponentActivity(Object obj) {
+ if (obj == null || !(obj instanceof Activity))
+ return false;
+ Configuration cfg = ((Activity) obj).getConfiguration();
+ return cfg != null && ACTIVITY_URI.equals(cfg.getType());
+ }
+
+ private static final Pattern SANITIZER_RE = Pattern
+ .compile("[^a-zA-Z0-9]+");
+ private static final Pattern SUFFIXED_RE = Pattern
+ .compile("^(.+)_([0-9]+)$");
+
+ /**
+ * Pick a name that is unique within the context set. This is done by
+ * appending "<tt>_<i>n</i></tt>" as necessary, where <tt><i>n</i></tt> is a
+ * number.
+ *
+ * @param name
+ * The suggested name; this is always checked first.
+ * @param context
+ * The set of things that the name will have to be unique within.
+ * @return A name that is definitely not the name of anything in the given
+ * set.
+ */
+ public static String uniqueName(String name, NamedSet<? extends Named> context) {
+ String candidate = SANITIZER_RE.matcher(name).replaceAll("_");
+ if (context.getByName(candidate) == null)
+ return candidate;
+ int counter = 0;
+ String prefix = candidate;
+ Matcher m = SUFFIXED_RE.matcher(candidate);
+ if (m.matches()) {
+ prefix = m.group(1);
+ counter = Integer.parseInt(m.group(2));
+ }
+ do {
+ candidate = prefix + "_" + (++counter);
+ } while (context.getByName(candidate) != null);
+ return candidate;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivityContextViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivityContextViewFactory.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivityContextViewFactory.java
new file mode 100644
index 0000000..c27278f
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivityContextViewFactory.java
@@ -0,0 +1,140 @@
+/*
+* 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 io.github.taverna_extras.component.ui.view;
+
+import static io.github.taverna_extras.component.api.config.ComponentConfig.URI;
+
+import java.awt.Frame;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Action;
+
+import io.github.taverna_extras.component.api.ComponentFactory;
+import io.github.taverna_extras.component.ui.config.ComponentConfigureAction;
+
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.servicedescriptions.ServiceDescriptionRegistry;
+import org.apache.taverna.services.ServiceRegistry;
+import org.apache.taverna.workbench.activityicons.ActivityIconManager;
+import org.apache.taverna.workbench.configuration.colour.ColourManager;
+import org.apache.taverna.workbench.edits.EditManager;
+import org.apache.taverna.workbench.file.FileManager;
+import org.apache.taverna.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
+import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+public class ComponentActivityContextViewFactory implements
+ ContextualViewFactory<Activity> {
+ private ColourManager colourManager;
+ private ViewUtil util;
+ private ComponentFactory factory;
+ private ActivityIconManager aim;
+ private ServiceDescriptionRegistry sdr;
+ private EditManager em;
+ private FileManager fm;
+ private ServiceRegistry sr;
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+ public void setViewUtils(ViewUtil util) {
+ this.util = util;
+ }
+
+ public void setIconManager(ActivityIconManager aim) {
+ this.aim = aim;
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry sdr) {
+ this.sdr = sdr;
+ }
+
+ public void setEditManager(EditManager em) {
+ this.em = em;
+ }
+
+ public void setFileManager(FileManager fm) {
+ this.fm = fm;
+ }
+
+ public void setServiceTypeRegistry(ServiceRegistry sr) {
+ this.sr = sr;
+ }
+
+ @Override
+ public boolean canHandle(Object selection) {
+ return selection instanceof Activity
+ && ((Activity) selection).getType().equals(URI);
+ }
+
+ @Override
+ public List<ContextualView> getViews(Activity selection) {
+ return Arrays.<ContextualView>asList(new ComponentActivityContextualView(selection));
+ }
+
+ @SuppressWarnings("serial")
+ private class ComponentActivityContextualView extends
+ HTMLBasedActivityContextualView {
+ public ComponentActivityContextualView(Activity activity) {
+ super(activity, colourManager);
+ init();
+ }
+
+ private void init() {
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Component service";
+ }
+
+ /**
+ * View position hint
+ */
+ @Override
+ public int getPreferredPosition() {
+ // We want to be on top
+ return 100;
+ }
+
+ @Override
+ public Action getConfigureAction(Frame owner) {
+ return new ComponentConfigureAction(getActivity(), owner, factory,
+ aim, sdr, em, fm, sr);
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ try {
+ return util.getRawTablesHtml(getConfigBean());
+ } catch (MalformedURLException e) {
+ return "<tr><td>malformed URL: <pre>" + e.getMessage()
+ + "</pre></td></tr>";
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationContextViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationContextViewFactory.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationContextViewFactory.java
new file mode 100644
index 0000000..fcb6e4a
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationContextViewFactory.java
@@ -0,0 +1,154 @@
+/*
+* 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 io.github.taverna_extras.component.ui.view;
+
+import static org.apache.log4j.Logger.getLogger;
+import static io.github.taverna_extras.component.api.config.ComponentConfig.URI;
+
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import io.github.taverna_extras.component.api.ComponentException;
+import io.github.taverna_extras.component.api.ComponentFactory;
+import io.github.taverna_extras.component.api.profile.Profile;
+import io.github.taverna_extras.component.ui.ComponentActivityConfigurationBean;
+import io.github.taverna_extras.component.ui.annotation.AbstractSemanticAnnotationContextualView;
+
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.core.Workflow;
+import org.apache.taverna.scufl2.api.port.InputActivityPort;
+import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
+import org.apache.taverna.scufl2.api.port.OutputActivityPort;
+import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
+import org.apache.taverna.scufl2.api.port.Port;
+import org.apache.taverna.workbench.file.FileManager;
+import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
+import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+public class ComponentActivitySemanticAnnotationContextViewFactory implements
+ ContextualViewFactory<Object> {
+ public static final String VIEW_TITLE = "Inherited Semantic Annotations";
+ private static final Logger logger = getLogger(ComponentActivitySemanticAnnotationContextViewFactory.class);
+
+ private FileManager fm;
+ private ComponentFactory factory;
+
+ public void setFileManager(FileManager fm) {
+ this.fm = fm;
+ }
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ @Override
+ public boolean canHandle(Object selection) {
+ return getContainingComponentActivity(selection) != null;
+ }
+
+ public Activity getContainingComponentActivity(Object selection) {
+ if (selection instanceof Activity) {
+ Activity a = (Activity) selection;
+ if (a.getType().equals(URI))
+ return a;
+ }
+ if (selection instanceof InputActivityPort
+ || selection instanceof OutputActivityPort)
+ return getContainingComponentActivity(((OutputActivityPort) selection)
+ .getParent());
+ return null;
+ }
+
+ @Override
+ public List<ContextualView> getViews(Object selection) {
+ return Arrays
+ .<ContextualView> asList(new SemanticAnnotationCV(
+ selection));
+ }
+
+ @SuppressWarnings("serial")
+ private class SemanticAnnotationCV extends
+ AbstractSemanticAnnotationContextualView {
+ private Profile componentProfile;
+
+ public SemanticAnnotationCV(Object selection) {
+ super(fm, false);
+ Activity componentActivity = getContainingComponentActivity(selection);
+ try {
+ ComponentActivityConfigurationBean configuration = new ComponentActivityConfigurationBean(
+ componentActivity.getConfiguration(), factory);
+ setAnnotatedThing(selection, configuration.getVersion()
+ .getImplementation().getMainWorkflow());
+ componentProfile = configuration.getComponent().getFamily()
+ .getComponentProfile();
+ setProfile(selection);
+ super.initialise();
+ } catch (ComponentException e) {
+ logger.error("problem querying registry", e);
+ } catch (MalformedURLException e) {
+ logger.error("malformed URL in component description", e);
+ }
+ }
+
+ private void setAnnotatedThing(Object selection,
+ Workflow underlyingDataflow) {
+ if (selection instanceof Activity) {
+ setAnnotated(underlyingDataflow);
+ } else if (selection instanceof InputActivityPort) {
+ String name = ((Port) selection).getName();
+ for (InputWorkflowPort dip : underlyingDataflow.getInputPorts())
+ if (dip.getName().equals(name)) {
+ setAnnotated(dip);
+ break;
+ }
+ } else if (selection instanceof OutputActivityPort) {
+ String name = ((Port) selection).getName();
+ for (OutputWorkflowPort dop : underlyingDataflow
+ .getOutputPorts())
+ if (dop.getName().equals(name)) {
+ setAnnotated(dop);
+ break;
+ }
+ }
+ }
+
+ private void setProfile(Object selection) throws ComponentException {
+ if (componentProfile == null)
+ return;
+ if (selection instanceof Activity) {
+ setSemanticAnnotationProfiles(componentProfile
+ .getSemanticAnnotations());
+ } else if (selection instanceof InputActivityPort) {
+ setSemanticAnnotationProfiles(componentProfile
+ .getInputSemanticAnnotationProfiles());
+ } else if (selection instanceof OutputActivityPort) {
+ setSemanticAnnotationProfiles(componentProfile
+ .getOutputSemanticAnnotationProfiles());
+ }
+ }
+
+ @Override
+ public String getViewTitle() {
+ return VIEW_TITLE;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationPanel.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationPanel.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationPanel.java
new file mode 100644
index 0000000..d3580a8
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentActivitySemanticAnnotationPanel.java
@@ -0,0 +1,112 @@
+/*
+* 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 io.github.taverna_extras.component.ui.view;
+
+import static java.awt.Color.GRAY;
+import static java.awt.Color.WHITE;
+import static java.awt.GridBagConstraints.BOTH;
+import static java.awt.GridBagConstraints.EAST;
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.SOUTHEAST;
+import static java.lang.String.format;
+import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getDisplayName;
+import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getObjectName;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.util.Set;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.EmptyBorder;
+
+import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
+
+import org.apache.jena.ontology.OntProperty;
+import org.apache.jena.rdf.model.Statement;
+
+public class ComponentActivitySemanticAnnotationPanel extends JPanel {
+ private static final long serialVersionUID = 3599768150252711758L;
+ private static final String ANNTYPE_MSG = "Annotation type : %s";
+ private static final String NONE_MSG = "No semantic annotations";
+ private SemanticAnnotationProfile profile;
+ private final Set<Statement> statements;
+
+ public ComponentActivitySemanticAnnotationPanel(
+ SemanticAnnotationProfile profile, Set<Statement> statements) {
+ this.profile = profile;
+ this.statements = statements;
+ initialize();
+ }
+
+ private void initialize() {
+ setLayout(new GridBagLayout());
+ setBorder(new AbstractBorder() {
+ private static final long serialVersionUID = -5921448975807056953L;
+
+ @Override
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height) {
+ g.setColor(GRAY);
+ g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
+ }
+ });
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.anchor = SOUTHEAST;
+ c.fill = BOTH;
+ c.weightx = 1;
+ c.gridx = 0;
+
+ OntProperty predicate = profile.getPredicate();
+ c.gridwidth = 2;
+ JLabel label = new JLabel(format(ANNTYPE_MSG, getDisplayName(predicate)));
+ label.setBorder(new EmptyBorder(5, 5, 5, 5));
+ label.setBackground(WHITE);
+ label.setOpaque(true);
+ add(label, c);
+
+ c.insets = new Insets(5, 7, 0, 0);
+ c.anchor = EAST;
+ c.fill = HORIZONTAL;
+ if (statements.isEmpty()) {
+ c.gridwidth = 2;
+ // c.weightx = 1;
+ // c.gridy++;
+ add(new JLabel(NONE_MSG), c);
+ } else {
+ c.gridwidth = 1;
+ for (Statement statement : statements) {
+ c.gridx = 0;
+ c.weightx = 1;
+ JTextArea value = new JTextArea(getObjectName(statement));
+ value.setBackground(WHITE);
+ value.setOpaque(true);
+ value.setBorder(new EmptyBorder(2, 4, 2, 4));
+ add(value, c);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextViewFactory.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextViewFactory.java
new file mode 100644
index 0000000..938a32e
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextViewFactory.java
@@ -0,0 +1,61 @@
+/*
+* 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 io.github.taverna_extras.component.ui.view;
+
+import static io.github.taverna_extras.component.api.config.ComponentConfig.URI;
+
+import java.util.Arrays;
+import java.util.List;
+
+import io.github.taverna_extras.component.api.Version;
+
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.workbench.file.FileManager;
+import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
+import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+public class ComponentContextViewFactory implements
+ ContextualViewFactory<WorkflowBundle> {
+ private FileManager fileManager;
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ @Override
+ public boolean canHandle(Object selection) {
+ if (selection instanceof WorkflowBundle) {
+ Object dataflowSource = fileManager
+ .getDataflowSource((WorkflowBundle) selection);
+ //FIXME Is this right?
+ return dataflowSource instanceof Version.ID;
+ }
+ return selection instanceof Activity
+ && ((Activity) selection).getType().equals(URI);
+ }
+
+ @Override
+ public List<ContextualView> getViews(WorkflowBundle selection) {
+ Object dataflowSource = fileManager.getDataflowSource(selection);
+ return Arrays.<ContextualView> asList(new ComponentContextualView(
+ (Version.ID) dataflowSource));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextualView.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextualView.java
new file mode 100644
index 0000000..c763d06
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ComponentContextualView.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 io.github.taverna_extras.component.ui.view;
+
+import static java.lang.String.format;
+
+import java.awt.Color;
+
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+
+import io.github.taverna_extras.component.api.Version;
+import org.apache.taverna.lang.ui.HtmlUtils;
+import org.apache.taverna.workbench.configuration.colour.ColourManager;
+import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
+
+@SuppressWarnings("serial")
+public class ComponentContextualView extends ContextualView {
+ private JEditorPane editorPane;
+ private final Version.ID component;
+ ColourManager colourManager;//FIXME beaninject
+ ViewUtil viewUtils;//FIXME beaninject;
+
+ public ComponentContextualView(Version.ID component) {
+ this.component = component;
+ initView();
+ }
+
+ @Override
+ public JComponent getMainFrame() {
+ editorPane = HtmlUtils.createEditorPane(buildHtml());
+ return HtmlUtils.panelForHtml(editorPane);
+ }
+
+ private String buildHtml() {
+ StringBuilder html = new StringBuilder(HtmlUtils.getHtmlHead(getBackgroundColour()));
+ html.append(HtmlUtils.buildTableOpeningTag());
+ viewUtils.getRawTablesHtml(component, html);
+ return html.append("</table></body></html>").toString();
+ }
+
+ public String getBackgroundColour() {
+ Color colour = colourManager.getPreferredColour(
+ "io.github.taverna_extras.component.registry.Component");
+ return format("#%1$2x%2$2x%3$2x", colour.getRed(), colour.getGreen(),
+ colour.getBlue());
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 50;
+ }
+
+ private static int MAX_LENGTH = 50;
+
+ private String limitName(String fullName) {
+ if (fullName.length() > MAX_LENGTH)
+ return fullName.substring(0, MAX_LENGTH - 3) + "...";
+ return fullName;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Component " + limitName(component.getComponentName());
+ }
+
+ @Override
+ public void refreshView() {
+ editorPane.setText(buildHtml());
+ repaint();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ViewUtil.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ViewUtil.java b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ViewUtil.java
new file mode 100644
index 0000000..5764f6c
--- /dev/null
+++ b/taverna-component-activity-ui/src/main/java/io/github/taverna_extras/component/ui/view/ViewUtil.java
@@ -0,0 +1,178 @@
+/*
+* 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 io.github.taverna_extras.component.ui.view;
+
+import static java.lang.String.format;
+import static org.apache.log4j.Logger.getLogger;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import io.github.taverna_extras.component.api.Component;
+import io.github.taverna_extras.component.api.ComponentFactory;
+import io.github.taverna_extras.component.api.Family;
+import io.github.taverna_extras.component.api.Version;
+import io.github.taverna_extras.component.ui.ComponentActivityConfigurationBean;
+
+import org.apache.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
+import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
+import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
+
+/**
+ * @author alanrw
+ */
+public class ViewUtil {
+ private static Logger logger = getLogger(ViewUtil.class);
+
+ private static final String VERSION_DESCRIPTION_LABEL = "Component version description";
+ private static final String COMPONENT_DESCRIPTION_LABEL = "Component description";
+ private static final String FAMILY_DESCRIPTION_LABEL = "Family description";
+
+ private static final String plainFormat = "<tr><td><b>%1$s</b></td><td nowrap=\"wrap\" style=\"width:100px;\">%2$s</td></tr>";
+ private static final String headerFormat = "<tr><th>%1$s</th><th>%2$s</th></tr>";
+ private static final String rowFormat = "<tr><td><b>%1$s</b></td><td>%2$s</td></tr>";
+ private static final String rowLinkFormat = "<tr><td><b>%1$s</b></td><td><a href=\"%3$s\">%2$s</a></td></tr>";
+ private static final String descriptionFormat = "<tr><td colspan=\"2\"><b>%1$s</b></td></tr><tr><td colspan=\"2\" nowrap=\"wrap\" style=\"width:100px;\">%2$s</td></tr>";
+
+ private ComponentFactory factory;//FIXME beaninject
+
+ public void setComponentFactory(ComponentFactory factory) {
+ this.factory = factory;
+ }
+
+ public String getRawTablesHtml(Version.ID id) {
+ StringBuilder html = new StringBuilder();
+ getRawTablesHtml(id, html);
+ return html.toString();
+ }
+
+ public String getRawTablesHtml(Configuration config) throws MalformedURLException {
+ StringBuilder html = new StringBuilder();
+ getRawTablesHtml(
+ new ComponentActivityConfigurationBean(
+ config.getJsonAsObjectNode(), factory), html);
+ return html.toString();
+ }
+
+ public void getRawTablesHtml(Version.ID id, StringBuilder html) {
+ URL registryBase = id.getRegistryBase();
+ String registryLink = null;
+ if (registryBase.getProtocol().startsWith("http"))
+ registryLink = registryBase.toExternalForm();
+ /*
+ * \u200b is a zero-width space, so the HTML renderer can know to break
+ * lines.
+ */
+ String registryName = registryBase.toString().replaceAll("/", "\u200b/");
+ appendRow(html, "Component registry base", registryName, registryLink);
+
+ String familyName = id.getFamilyName();
+ appendRow(html, "Component family", familyName, null);
+ try {
+ Family family = factory.getFamily(registryBase, familyName);
+ if (family != null)
+ appendDescriptionHtml(html, FAMILY_DESCRIPTION_LABEL,
+ family.getDescription());
+ } catch (Exception e) {
+ logger.error("failed to get component family description", e);
+ }
+
+ String componentName = id.getComponentName();
+ String helpLink = null;
+ try {
+ URL helpURL = factory.getVersion(id).getHelpURL();
+ if (helpURL != null)
+ helpLink = helpURL.toExternalForm();
+ } catch (Exception e) {
+ logger.error(e);
+ }
+
+ appendRow(html, "Component name", componentName, helpLink);
+ try {
+ Component component = factory.getComponent(registryBase,
+ familyName, componentName);
+ if (component != null)
+ appendDescriptionHtml(html, COMPONENT_DESCRIPTION_LABEL,
+ component.getDescription());
+ } catch (Exception e) {
+ logger.error("failed to get component description", e);
+ }
+
+ Integer componentVersion = id.getComponentVersion();
+
+ if (componentVersion == null)
+ appendRow(html, "Component version", "N/A", helpLink);
+ else {
+ appendRow(html, "Component version", componentVersion, helpLink);
+ try {
+ Version version = factory.getVersion(registryBase,
+ familyName, componentName, componentVersion);
+ if (version != null) {
+ appendDescriptionHtml(html, VERSION_DESCRIPTION_LABEL,
+ version.getDescription());
+ WorkflowBundle impl = version.getImplementation();
+ Set<InputWorkflowPort> inputs = impl.getMainWorkflow().getInputPorts();
+ if (!inputs.isEmpty()) {
+ appendHeaderRow(html, "Input Port Name", "Depth");
+ for (InputWorkflowPort input : inputs)
+ appendPlainRow(html, input.getName(), input.getDepth());
+ }
+ Set<OutputWorkflowPort> outputs = impl.getMainWorkflow().getOutputPorts();
+ if (!outputs.isEmpty()) {
+ appendHeaderRow(html, "Output Port Name", "Depth");
+ for (OutputWorkflowPort output : outputs) {
+ //FIXME get depth of output ports!
+ appendPlainRow(html, output.getName(), -1 /*output.getDepth()*/);
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error("failed to get component version description", e);
+ }
+ }
+ }
+
+ private static void appendRow(StringBuilder html, Object label,
+ Object value, String link) {
+ if (link == null)
+ html.append(format(rowFormat, label, value));
+ else
+ html.append(format(rowLinkFormat, label, value, link));
+ }
+
+ private static void appendHeaderRow(StringBuilder html, Object label1,
+ Object label2) {
+ html.append(format(headerFormat, label1, label2));
+ }
+
+ private static void appendPlainRow(StringBuilder html, Object value1,
+ Object value2) {
+ html.append(format(plainFormat, value1, value2));
+ }
+
+ private static void appendDescriptionHtml(StringBuilder html,
+ String header, String description) {
+ if ((description != null) && !description.isEmpty())
+ html.append(format(descriptionFormat, header, description));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentAction.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentAction.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentAction.java
deleted file mode 100644
index f359c9d..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentAction.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui;
-
-import static java.awt.Color.RED;
-import static javax.swing.SwingUtilities.invokeLater;
-import static org.apache.log4j.Logger.getLogger;
-
-import javax.swing.AbstractAction;
-
-import org.apache.log4j.Logger;
-import io.github.taverna_extras.component.ui.serviceprovider.ComponentServiceIcon;
-
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.workbench.models.graph.GraphController;
-import org.apache.taverna.workbench.models.graph.svg.SVGGraph;
-import org.apache.taverna.workbench.views.graph.GraphViewComponent;
-
-@SuppressWarnings("serial")
-public abstract class ComponentAction extends AbstractAction {
- private static Logger logger = getLogger(ComponentAction.class);
-
- protected GraphViewComponent graphView;
-
- protected ComponentAction(String title, GraphViewComponent graphView) {
- this.graphView = graphView;
- }
-
- public void setIcon(ComponentServiceIcon icon) {
- putValue(SMALL_ICON, icon.getIcon());
- }
-
- protected void markGraphAsBelongingToComponent(WorkflowBundle bundle) {
- final GraphController gc = graphView.getGraphController(bundle
- .getMainWorkflow());
- invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- SVGGraph g = (SVGGraph) gc.getGraph();
- g.setFillColor(RED);
- gc.redraw();
- } catch (NullPointerException e) {
- logger.error(e);
- }
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentActivityConfigurationBean.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentActivityConfigurationBean.java
deleted file mode 100644
index 26e673e..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentActivityConfigurationBean.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui;
-
-import static org.apache.log4j.Logger.getLogger;
-import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.COMPONENT_NAME;
-import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.COMPONENT_VERSION;
-import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.FAMILY_NAME;
-import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.REGISTRY_BASE;
-import static io.github.taverna_extras.component.ui.ComponentConstants.ACTIVITY_URI;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import io.github.taverna_extras.component.api.Component;
-import io.github.taverna_extras.component.api.ComponentException;
-import io.github.taverna_extras.component.api.ComponentFactory;
-import io.github.taverna_extras.component.api.Version;
-import io.github.taverna_extras.component.api.config.ComponentPropertyNames;
-import io.github.taverna_extras.component.api.profile.ExceptionHandling;
-
-import org.apache.taverna.scufl2.api.activity.Activity;
-import org.apache.taverna.scufl2.api.configurations.Configuration;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.port.InputActivityPort;
-import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
-import org.apache.taverna.scufl2.api.port.OutputActivityPort;
-import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Component activity configuration bean.
- */
-public class ComponentActivityConfigurationBean extends Version.Identifier {
- public static final String ERROR_CHANNEL = "error_channel";
- public static final List<String> ignorableNames = Arrays
- .asList(ERROR_CHANNEL);
- private static final long serialVersionUID = 5774901665863468058L;
- private static final Logger logger = getLogger(ComponentActivityConfigurationBean.class);
-
- private ActivityPortsDefinitionBean ports = null;
- private ComponentFactory factory;
- private ExceptionHandling eh;
-
- public ComponentActivityConfigurationBean(Version.ID toBeCopied,
- ComponentFactory factory) {
- super(toBeCopied.getRegistryBase(), toBeCopied.getFamilyName(),
- toBeCopied.getComponentName(), toBeCopied.getComponentVersion());
- this.factory = factory;
- try {
- getPorts();
- } catch (ComponentException e) {
- logger.error("failed to get component realization", e);
- }
- }
-
- public ComponentActivityConfigurationBean(JsonNode json,
- ComponentFactory factory) throws MalformedURLException {
- super(getUrl(json), getFamily(json), getComponent(json),
- getVersion(json));
- this.factory = factory;
- }
-
- public ComponentActivityConfigurationBean(Configuration configuration,
- ComponentFactory factory) throws MalformedURLException {
- this(configuration.getJson(), factory);
- }
-
- private static URL getUrl(JsonNode json) throws MalformedURLException {
- return new URL(json.get(REGISTRY_BASE).textValue());
- }
-
- private static String getFamily(JsonNode json) {
- return json.get(FAMILY_NAME).textValue();
- }
-
- private static String getComponent(JsonNode json) {
- return json.get(COMPONENT_NAME).textValue();
- }
-
- private static Integer getVersion(JsonNode json) {
- JsonNode node = json.get(COMPONENT_VERSION);
- if (node == null || !node.isInt())
- return null;
- return node.intValue();
- }
-
- public Component getComponent() throws ComponentException {
- return factory.getComponent(getRegistryBase(), getFamilyName(),
- getComponentName());
- }
-
- public Version getVersion() throws ComponentException {
- return factory.getVersion(this);
- }
-
- private ActivityPortsDefinitionBean getPortsDefinition(WorkflowBundle w) {
- ActivityPortsDefinitionBean result = new ActivityPortsDefinitionBean();
-
- for (InputWorkflowPort iwp : w.getMainWorkflow().getInputPorts())
- result.inputs.add(makeInputDefinition(iwp));
- for (OutputWorkflowPort owp : w.getMainWorkflow().getOutputPorts())
- result.outputs.add(makeOutputDefinition(getDepth(owp), owp.getName()));
-
- try {
- eh = factory.getFamily(getRegistryBase(), getFamilyName())
- .getComponentProfile().getExceptionHandling();
- if (eh != null)
- result.outputs.add(makeOutputDefinition(1, ERROR_CHANNEL));
- } catch (io.github.taverna_extras.component.api.ComponentException e) {
- logger.error("failed to get exception handling for family", e);
- }
- return result;
- }
-
- private int getDepth(OutputWorkflowPort owp) {
- return 0; //FIXME How to get the depth of an output?
- }
-
- private InputActivityPort makeInputDefinition(InputWorkflowPort dip) {
- InputActivityPort port = new InputActivityPort();
- port.setName(dip.getName());
- port.setDepth(dip.getDepth());
- return port;
- }
-
- private OutputActivityPort makeOutputDefinition(int depth, String name) {
- OutputActivityPort port = new OutputActivityPort();
- port.setName(name);
- port.setDepth(depth);
- port.setGranularDepth(depth);
- return port;
- }
-
- /**
- * @return the ports
- */
- public ActivityPortsDefinitionBean getPorts() throws ComponentException {
- if (ports == null)
- ports = getPortsDefinition(getVersion().getImplementation());
- return ports;
- }
-
- public ExceptionHandling getExceptionHandling() {
- return eh;
- }
-
- public void installConfiguration(Activity a) {
- Configuration conf = a.createConfiguration(ACTIVITY_URI);
- ObjectNode json = conf.getJsonAsObjectNode();
- json.put(REGISTRY_BASE, getRegistryBase().toExternalForm());
- json.put(FAMILY_NAME, getFamilyName());
- json.put(COMPONENT_NAME, getComponentName());
- json.put(COMPONENT_VERSION, getComponentVersion());
- }
-
- public static class ActivityPortsDefinitionBean {
- public List<InputActivityPort> inputs = new ArrayList<>();
- public List<OutputActivityPort> outputs = new ArrayList<>();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentConstants.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentConstants.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentConstants.java
deleted file mode 100644
index baec10f..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/ComponentConstants.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui;
-
-import static java.net.URI.create;
-
-import java.net.URI;
-
-public interface ComponentConstants {
- URI ACTIVITY_URI = create("http://ns.taverna.org.uk/2010/activity/component");
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AbstractSemanticAnnotationContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AbstractSemanticAnnotationContextualView.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AbstractSemanticAnnotationContextualView.java
deleted file mode 100644
index 6cc48d0..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AbstractSemanticAnnotationContextualView.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static java.awt.GridBagConstraints.HORIZONTAL;
-import static java.awt.GridBagConstraints.NORTHWEST;
-import static java.lang.String.CASE_INSENSITIVE_ORDER;
-import static org.apache.log4j.Logger.getLogger;
-import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.createSemanticAnnotation;
-import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getDisplayName;
-
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.ExecutionException;
-
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSeparator;
-import javax.swing.SwingWorker;
-
-import org.apache.log4j.Logger;
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-
-import org.apache.taverna.scufl2.api.common.AbstractNamed;
-import org.apache.taverna.scufl2.api.common.Named;
-
-import org.apache.jena.ontology.OntProperty;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.Statement;
-import org.apache.taverna.workbench.file.FileManager;
-import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
-
-/**
- * @author alanrw
- */
-public abstract class AbstractSemanticAnnotationContextualView extends
- ContextualView {
- private static final long serialVersionUID = 3567849347002793442L;
- private static final Logger logger = getLogger(SemanticAnnotationContextualView.class);
-
- private final FileManager fileManager;
-
- public AbstractSemanticAnnotationContextualView(FileManager fileManager,
- boolean allowChange) {
- super();
- this.fileManager = fileManager;
- this.allowChange = allowChange;
- }
-
- private final boolean allowChange;
- private JPanel panel;
- private AbstractNamed annotated;
- private List<SemanticAnnotationProfile> semanticAnnotationProfiles;
- private Model model;
- private Resource subject;
-
- private static Comparator<SemanticAnnotationProfile> comparator = new Comparator<SemanticAnnotationProfile>() {
- @Override
- public int compare(SemanticAnnotationProfile arg0,
- SemanticAnnotationProfile arg1) {
- String d0 = getDisplayName(arg0.getPredicate());
- String d1 = getDisplayName(arg1.getPredicate());
- return CASE_INSENSITIVE_ORDER.compare(d0, d1);
- }
- };
-
- @Override
- public JComponent getMainFrame() {
- return panel;
- }
-
- @Override
- public int getPreferredPosition() {
- return 510;
- }
-
- protected final void initialise() {
- populateModel();
- if (panel == null)
- panel = new JPanel(new GridBagLayout());
- else
- panel.removeAll();
- populatePanel(panel);
- }
-
- public void removeStatement(Statement statement) {
- model.remove(statement);
- // populatePanel(panel);
- updateSemanticAnnotation();
- }
-
- public void addStatement(Statement statement) {
- model.add(statement);
- // populatePanel(panel);
- updateSemanticAnnotation();
- }
-
- public void changeStatement(Statement origStatement, OntProperty predicate,
- RDFNode node) {
- if (predicate == null)
- return;
- model.remove(origStatement);
- model.add(subject, predicate, node);
- // populatePanel(panel);
- updateSemanticAnnotation();
- }
-
- public void addStatement(OntProperty predicate, RDFNode node) {
- if (predicate == null)
- return;
- model.add(subject, predicate, node);
- // populatePanel(panel);
- updateSemanticAnnotation();
- }
-
- @Override
- public void refreshView() {
- populatePanel(panel);
- }
-
- // public void addModel(Model model) {
- // this.model.add(model);
- // initialise();
- // updateSemanticAnnotation();
- // }
-
- public void updateSemanticAnnotation() {
- try {
- createSemanticAnnotation(fileManager.getCurrentDataflow(),
- annotated, model);
- } catch (IOException e) {
- logger.error("failed to add semantic annotation", e);
- }
- }
-
- public void setAnnotated(Named annotated) {
- this.annotated = (AbstractNamed) annotated;
- }
-
- public void setSemanticAnnotationProfiles(
- List<SemanticAnnotationProfile> profiles) {
- this.semanticAnnotationProfiles = profiles;
- }
-
- public Model getModel() {
- return model;
- }
-
- private void populateModel() {
- this.model = SemanticAnnotationUtils.populateModel(fileManager
- .getCurrentDataflow());
- this.subject = model.createResource(annotated.getURI().toASCIIString());
- }
-
- public Named getAnnotated() {
- return annotated;
- }
-
- private void populatePanel(JPanel panel) {
- panel.removeAll();
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.anchor = NORTHWEST;
- gbc.fill = HORIZONTAL;
- gbc.gridx = 0;
- gbc.weightx = 1;
- gbc.weighty = 0;
- gbc.insets = new Insets(5, 5, 5, 5);
- panel.add(new JLabel("Reading semantic annotations"), gbc);
- revalidate();
- initView();
- new StatementsReader().execute();
- }
-
- private Set<Statement> listStatements(OntProperty predicate) {
- if (predicate == null)
- return Collections.emptySet();
- return model.listStatements(subject, predicate, (RDFNode) null).toSet();
- }
-
- private void populateViewWithPredicates(GridBagConstraints gbc,
- Map<SemanticAnnotationProfile, Set<Statement>> profileStatements,
- Set<Statement> statements,
- Set<SemanticAnnotationProfile> unresolvablePredicates) {
- for (Entry<SemanticAnnotationProfile, Set<Statement>> entry : profileStatements
- .entrySet()) {
- panel.add(
- new SemanticAnnotationPanel(this, entry.getKey(), entry
- .getValue(), allowChange), gbc);
- panel.add(new JSeparator(), gbc);
- }
- for (SemanticAnnotationProfile semanticAnnotationProfile : unresolvablePredicates) {
- panel.add(
- new UnresolveablePredicatePanel(semanticAnnotationProfile),
- gbc);
- panel.add(new JSeparator(), gbc);
- }
-
- if (semanticAnnotationProfiles.isEmpty())
- panel.add(new JLabel("No annotations possible"), gbc);
- for (Statement s : statements)
- panel.add(new UnrecognizedStatementPanel(s), gbc);
-
- gbc.weighty = 1;
- panel.add(new JPanel(), gbc);
- }
-
- private class StatementsReader extends SwingWorker<Void, Object> {
- private Map<SemanticAnnotationProfile, Set<Statement>> profileStatements = new TreeMap<>(
- comparator);
- private Set<Statement> statements;
- private Set<SemanticAnnotationProfile> unresolvablePredicates = new HashSet<>();
-
- @Override
- protected Void doInBackground() throws Exception {
- try {
- parseStatements();
- } catch (Exception e) {
- logger.error("failed to parse annotation statements", e);
- throw e;
- }
- return null;
- }
-
- private void parseStatements() {
- statements = listStatements(null);
- for (SemanticAnnotationProfile semanticAnnotationProfile : semanticAnnotationProfiles) {
- OntProperty predicate = semanticAnnotationProfile
- .getPredicate();
- if (predicate == null) {
- unresolvablePredicates.add(semanticAnnotationProfile);
- continue;
- }
-
- Set<Statement> statementsWithPredicate = listStatements(predicate);
- profileStatements.put(semanticAnnotationProfile,
- statementsWithPredicate);
- statements.removeAll(statementsWithPredicate);
- }
- }
-
- @Override
- protected void done() {
- panel.removeAll();
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.anchor = NORTHWEST;
- gbc.fill = HORIZONTAL;
- gbc.gridx = 0;
- gbc.weightx = 1;
- gbc.weighty = 0;
- gbc.insets = new Insets(5, 5, 5, 5);
-
- try {
- get();
- populateViewWithPredicates(gbc, profileStatements, statements,
- unresolvablePredicates);
- } catch (ExecutionException | InterruptedException e) {
- logger.error(e);
- panel.add(new JLabel("Unable to read semantic annotations"),
- gbc);
- }
-
- revalidate();
- initView();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotateSemanticsMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotateSemanticsMenuAction.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotateSemanticsMenuAction.java
deleted file mode 100644
index 1543533..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotateSemanticsMenuAction.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static java.awt.BorderLayout.CENTER;
-import static java.awt.BorderLayout.SOUTH;
-import static java.awt.FlowLayout.TRAILING;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.Frame;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.net.URI;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JDialog;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
-import io.github.taverna_extras.component.api.ComponentFactory;
-import io.github.taverna_extras.component.api.Version;
-import org.apache.taverna.lang.ui.DeselectingButton;
-
-import org.apache.taverna.scufl2.api.activity.Activity;
-import org.apache.taverna.scufl2.api.common.AbstractNamed;
-import org.apache.taverna.scufl2.api.port.ActivityPort;
-import org.apache.taverna.ui.menu.AbstractContextualMenuAction;
-import org.apache.taverna.workbench.file.FileManager;
-
-/**
- * @author alanrw
- */
-public class AnnotateSemanticsMenuAction extends AbstractContextualMenuAction {
- private static final String ANNOTATE_SEMANTICS = "Annotate semantics...";
- private static final URI configureSection = URI
- .create("http://taverna.sf.net/2009/contextMenu/configure");
- private FileManager fileManager;
- private ComponentFactory factory;
-
- public AnnotateSemanticsMenuAction() {
- super(configureSection, 45);
- }
-
- public void setComponentFactory(ComponentFactory factory) {
- this.factory = factory;
- }
-
- public void setFileManager(FileManager fm) {
- this.fileManager = fm;
- }
-
- @Override
- public boolean isEnabled() {
- Object selection = getContextualSelection().getSelection();
- Object dataflowSource = fileManager.getDataflowSource(fileManager
- .getCurrentDataflow());
- if (dataflowSource instanceof Version.ID)
- return (selection instanceof AbstractNamed)
- && !(selection instanceof Activity || selection instanceof ActivityPort);
- return false;
- }
-
- @SuppressWarnings("serial")
- @Override
- protected Action createAction() {
- return new AbstractAction(ANNOTATE_SEMANTICS) {
- @Override
- public void actionPerformed(ActionEvent e) {
- showAnnotateSemanticsPanel();
- }
- };
- }
-
- private void showAnnotateSemanticsPanel() {
- SemanticAnnotationContextualView view = new SemanticAnnotationContextualView(
- fileManager, factory, (AbstractNamed) getContextualSelection()
- .getSelection());
-
- final JDialog dialog = new JDialog((Frame) null, "Annotate semantics");
- dialog.setLayout(new BorderLayout());
- dialog.add(new JScrollPane(view), CENTER);
-
- JPanel buttonPanel = new JPanel(new FlowLayout(TRAILING));
- buttonPanel.add(new DeselectingButton("OK", new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- dialog.setVisible(false);
- }
- }));
-
- dialog.add(buttonPanel, SOUTH);
- dialog.setSize(new Dimension(400, 300));
- dialog.setLocationRelativeTo(null);
- dialog.setModal(true);
- dialog.setVisible(true);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotationPropertyPanelFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotationPropertyPanelFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotationPropertyPanelFactory.java
deleted file mode 100644
index 0dfaf0a..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/AnnotationPropertyPanelFactory.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static org.apache.jena.rdf.model.ResourceFactory.createTypedLiteral;
-import static java.lang.Integer.MIN_VALUE;
-import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getObjectName;
-
-import javax.swing.JComponent;
-import javax.swing.JTextArea;
-
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-
-import org.apache.jena.ontology.OntProperty;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Statement;
-
-/**
- *
- *
- * @author Alan Williams
- */
-public class AnnotationPropertyPanelFactory extends PropertyPanelFactorySPI {
- @Override
- public JComponent getInputComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return getDefaultInputComponent(semanticAnnotationProfile, statement);
- }
-
- @Override
- public RDFNode getNewTargetNode(Statement originalStatement,
- JComponent component) {
- String newText = ((JTextArea) component).getText();
- if ((originalStatement == null)
- || !getObjectName(originalStatement).equals(newText))
- return createTypedLiteral(newText);
- return null;
- }
-
- @Override
- public int getRatingForSemanticAnnotation(
- SemanticAnnotationProfile semanticAnnotationProfile) {
- OntProperty property = semanticAnnotationProfile.getPredicate();
- if ((property != null) && property.isAnnotationProperty())
- return 100;
- return MIN_VALUE;
- }
-
- @Override
- public JComponent getDisplayComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return getDefaultDisplayComponent(semanticAnnotationProfile, statement);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DatatypePropertyPanelFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DatatypePropertyPanelFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DatatypePropertyPanelFactory.java
deleted file mode 100644
index bd7ebcc..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DatatypePropertyPanelFactory.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static org.apache.jena.rdf.model.ResourceFactory.createTypedLiteral;
-import static java.lang.Integer.MIN_VALUE;
-import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getObjectName;
-
-import javax.swing.JComponent;
-import javax.swing.JTextArea;
-
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-
-import org.apache.jena.ontology.OntProperty;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Statement;
-
-/**
- * @author Alan Williams
- */
-public class DatatypePropertyPanelFactory extends PropertyPanelFactorySPI {
- public DatatypePropertyPanelFactory() {
- super();
- }
-
- @Override
- public JComponent getInputComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return getDefaultInputComponent(semanticAnnotationProfile, statement);
- }
-
- @Override
- public RDFNode getNewTargetNode(Statement originalStatement,
- JComponent component) {
- JTextArea inputText = (JTextArea) component;
- String newText = inputText.getText();
- if ((originalStatement == null)
- || !getObjectName(originalStatement).equals(newText))
- return createTypedLiteral(newText);
- return null;
- }
-
- @Override
- public int getRatingForSemanticAnnotation(
- SemanticAnnotationProfile semanticAnnotationProfile) {
- OntProperty property = semanticAnnotationProfile.getPredicate();
- if ((property != null) && property.isDatatypeProperty())
- return 100;
- return MIN_VALUE;
- }
-
- @Override
- public JComponent getDisplayComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return getDefaultDisplayComponent(semanticAnnotationProfile, statement);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DateTimePropertyPanelFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DateTimePropertyPanelFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DateTimePropertyPanelFactory.java
deleted file mode 100644
index e9dbda7..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/DateTimePropertyPanelFactory.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDdateTime;
-import static org.apache.jena.rdf.model.ResourceFactory.createTypedLiteral;
-import static java.lang.Integer.MIN_VALUE;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-import javax.swing.JComponent;
-import javax.swing.JSpinner;
-import javax.swing.SpinnerDateModel;
-import javax.swing.text.DefaultCaret;
-
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-
-import org.apache.jena.datatypes.xsd.XSDDateTime;
-import org.apache.jena.ontology.OntProperty;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Statement;
-
-/**
- *
- *
- * @author Alan Williams
- */
-public class DateTimePropertyPanelFactory extends PropertyPanelFactorySPI {
-
- private static String DateTimeString = XSDdateTime.getURI();
-
- public DateTimePropertyPanelFactory() {
- super();
- }
-
- @Override
- public JComponent getInputComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- Date now = new Date();
- SpinnerDateModel dateModel = new SpinnerDateModel(now, null, now,
- Calendar.DAY_OF_MONTH);
- JSpinner s = new JSpinner(dateModel);
- JSpinner.DateEditor de = new JSpinner.DateEditor(s,
- "yyyy-MM-dd-HH-mm-ss");
-
- /*
- * Suggested hack from
- * http://www.coderanch.com/t/345684/GUI/java/JSpinner-DateEditor-Set-default-focus
- */
-
- de.getTextField().setCaret(new DefaultCaret() {
- private static final long serialVersionUID = 6779256780590610172L;
- private boolean diverted = false;
-
- @Override
- public void setDot(int dot) {
- diverted = (dot == 0);
- if (diverted)
- dot = getComponent().getDocument().getLength();
- super.setDot(dot);
- }
-
- @Override
- public void moveDot(int dot) {
- if (diverted) {
- super.setDot(0);
- diverted = false;
- }
- super.moveDot(dot);
- }
- });
- s.setEditor(de);
- if (statement != null) {
- Object o = statement.getObject().asLiteral().getValue();
- if (o instanceof XSDDateTime)
- dateModel.setValue(((XSDDateTime) o).asCalendar().getTime());
- }
- return s;
- }
-
- @Override
- public RDFNode getNewTargetNode(Statement originalStatement,
- JComponent component) {
- JSpinner spinner = (JSpinner) component;
- Date d = (Date) spinner.getValue();
- if ((originalStatement == null)
- || !originalStatement.getObject().asLiteral().getValue()
- .equals(d)) {
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(d);
- return createTypedLiteral(cal);
- }
- return null;
- }
-
- @Override
- public int getRatingForSemanticAnnotation(
- SemanticAnnotationProfile semanticAnnotationProfile) {
- OntProperty property = semanticAnnotationProfile.getPredicate();
- if ((property != null) && property.isDatatypeProperty()
- && DateTimeString.equals(semanticAnnotationProfile
- .getClassString()))
- return 200;
- return MIN_VALUE;
- }
-
- @Override
- public JComponent getDisplayComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- JComponent result = getInputComponent(semanticAnnotationProfile,
- statement);
- result.setEnabled(false);
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/FallbackPropertyPanelFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/FallbackPropertyPanelFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/FallbackPropertyPanelFactory.java
deleted file mode 100644
index efc3b42..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/FallbackPropertyPanelFactory.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Statement;
-
-/**
- * @author alanrw
- */
-public class FallbackPropertyPanelFactory extends PropertyPanelFactorySPI {
- @Override
- public JComponent getInputComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return new JLabel("Unable to handle "
- + semanticAnnotationProfile.getPredicateString());
- }
-
- @Override
- public RDFNode getNewTargetNode(Statement originalStatement,
- JComponent component) {
- return null;
- }
-
- @Override
- public int getRatingForSemanticAnnotation(
- SemanticAnnotationProfile semanticAnnotationProfile) {
- return 0;
- }
-
- @Override
- public JComponent getDisplayComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return getDefaultDisplayComponent(semanticAnnotationProfile, statement);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/GreyBorder.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/GreyBorder.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/GreyBorder.java
deleted file mode 100644
index d5e4fbe..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/GreyBorder.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Graphics;
-
-import javax.swing.border.AbstractBorder;
-
-@SuppressWarnings("serial")
-class GreyBorder extends AbstractBorder {
- @Override
- public void paintBorder(Component c, Graphics g, int x, int y, int width,
- int height) {
- g.setColor(Color.GRAY);
- g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/ObjectPropertyWithIndividualsPanelFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/ObjectPropertyWithIndividualsPanelFactory.java b/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/ObjectPropertyWithIndividualsPanelFactory.java
deleted file mode 100644
index fefe5c0..0000000
--- a/taverna-component-activity-ui/src/main/java/org/apache/taverna/component/ui/annotation/ObjectPropertyWithIndividualsPanelFactory.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
-* 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 io.github.taverna_extras.component.ui.annotation;
-
-import static java.awt.FlowLayout.RIGHT;
-import static java.awt.GridBagConstraints.EAST;
-import static java.awt.GridBagConstraints.NORTHWEST;
-import static java.lang.Integer.MIN_VALUE;
-import static javax.swing.JOptionPane.OK_CANCEL_OPTION;
-import static javax.swing.JOptionPane.OK_OPTION;
-import static javax.swing.JOptionPane.QUESTION_MESSAGE;
-import static javax.swing.JOptionPane.showConfirmDialog;
-import static javax.swing.JOptionPane.showInputDialog;
-import static io.github.taverna_extras.component.ui.annotation.SemanticAnnotationUtils.getDisplayName;
-
-import java.awt.Component;
-import java.awt.FlowLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.List;
-import java.util.Vector;
-
-import javax.swing.DefaultListCellRenderer;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.ListCellRenderer;
-
-import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile;
-import io.github.taverna_extras.component.ui.localworld.LocalWorld;
-
-import org.apache.jena.ontology.Individual;
-import org.apache.jena.ontology.OntClass;
-import org.apache.jena.ontology.OntModel;
-import org.apache.jena.ontology.OntProperty;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Statement;
-import org.apache.taverna.lang.ui.DeselectingButton;
-
-/**
- * @author David Withers
- * @author Alan Williams
- */
-public class ObjectPropertyWithIndividualsPanelFactory extends
- PropertyPanelFactorySPI {
- /*
- * TODO Consider what sort of sharing model is appropriate for the local
- * world
- */
- private static LocalWorld localWorld = LocalWorld.getInstance();
-
- @Override
- public int getRatingForSemanticAnnotation(
- SemanticAnnotationProfile semanticAnnotationProfile) {
- OntProperty property = semanticAnnotationProfile.getPredicate();
- if ((property != null) && property.isObjectProperty()
- /*
- * && !semanticAnnotationProfile.getIndividuals().isEmpty()
- */)
- return 100;
- return MIN_VALUE;
- }
-
- @Override
- public JComponent getInputComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- return new ComboBoxWithAdd(semanticAnnotationProfile, statement);
- }
-
- @Override
- public RDFNode getNewTargetNode(Statement originalStatement,
- JComponent component) {
- ComboBoxWithAdd panel = (ComboBoxWithAdd) component;
- RDFNode newNode = panel.getSelectedItem();
- if ((originalStatement == null)
- || !originalStatement.getObject().equals(newNode))
- return newNode;
- return null;
- }
-
-
- private static class ComboBoxWithAdd extends JPanel {
- private static final long serialVersionUID = -9156213096428945270L;
- private static DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
- OntClass rangeClass = null;
- JComboBox<Individual> resources;
-
- public ComboBoxWithAdd(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- super(new GridBagLayout());
-
- rangeClass = semanticAnnotationProfile.getRangeClass();
-
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.anchor = NORTHWEST;
- List<Individual> individuals = semanticAnnotationProfile
- .getIndividuals();
- if (rangeClass != null)
- individuals
- .addAll(localWorld.getIndividualsOfClass(rangeClass));
-
- resources = new JComboBox<Individual>(new Vector<>(individuals));
- resources.setRenderer(new ListCellRenderer<Individual>() {
- @Override
- public Component getListCellRendererComponent(
- JList<? extends Individual> list, Individual value,
- int index, boolean isSelected, boolean cellHasFocus) {
- return defaultRenderer.getListCellRendererComponent(list,
- getDisplayName(value), index, isSelected,
- cellHasFocus);
- }
- });
- resources.setEditable(false);
- if (statement != null) {
- Object origResource = statement.getObject();
- if (origResource != null)
- resources.setSelectedItem(origResource);
- }
- this.add(resources, gbc);
-
- gbc.gridy++;
-
- JPanel buttonPanel = new JPanel(new FlowLayout(RIGHT));
- buttonPanel.add(new DeselectingButton("Add external",
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addExternal();
- }
- }));
- buttonPanel.add(new DeselectingButton("Add local",
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addLocal();
- }
- }));
- gbc.anchor = EAST;
- this.add(buttonPanel, gbc);
- }
-
- private void addExternal() {
- String answer = showInputDialog("Please enter the URL for the resource");
- resources.addItem(localWorld.createIndividual(answer, rangeClass));
- }
-
- private void addLocal() {
- TurtleInputPanel turtlePanel = new TurtleInputPanel(rangeClass);
- if (showConfirmDialog(null, turtlePanel, "Turtle input",
- OK_CANCEL_OPTION, QUESTION_MESSAGE) == OK_OPTION) {
- OntModel addedModel = turtlePanel.getContentAsModel();
- for (Individual i : addedModel.listIndividuals(rangeClass)
- .toList())
- resources.addItem(i);
- localWorld.addModelFromString(turtlePanel.getContentAsString());
- }
- }
-
- public RDFNode getSelectedItem() {
- return (RDFNode) resources.getSelectedItem();
- }
- }
-
- @Override
- public JComponent getDisplayComponent(
- SemanticAnnotationProfile semanticAnnotationProfile,
- Statement statement) {
- JComponent result = getDefaultDisplayComponent(
- semanticAnnotationProfile, statement);
- return result;
- }
-}