http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponent.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponent.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponent.java deleted file mode 100644 index dc0018e..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponent.java +++ /dev/null @@ -1,389 +0,0 @@ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.impl; - -import static java.awt.GridBagConstraints.BOTH; -import static java.awt.GridBagConstraints.CENTER; -import static java.awt.GridBagConstraints.HORIZONTAL; -import static java.awt.GridBagConstraints.LINE_START; -import static java.awt.GridBagConstraints.NONE; -import static net.sf.taverna.t2.lang.ui.ShadedLabel.BLUE; -import static net.sf.taverna.t2.lang.ui.ShadedLabel.GREEN; -import static net.sf.taverna.t2.lang.ui.ShadedLabel.ORANGE; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.minusIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.plusIcon; - -import java.awt.Color; -import java.awt.Frame; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; -import javax.swing.Timer; - -import org.apache.taverna.lang.observer.Observable; -import org.apache.taverna.lang.observer.Observer; -import org.apache.taverna.lang.observer.SwingAwareObserver; -import net.sf.taverna.t2.lang.ui.ShadedLabel; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.edits.EditManager.EditManagerEvent; -import net.sf.taverna.t2.workbench.selection.DataflowSelectionModel; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.selection.events.DataflowSelectionMessage; -import net.sf.taverna.t2.workbench.selection.events.SelectionManagerEvent; -import net.sf.taverna.t2.workbench.selection.events.WorkflowBundleSelectionEvent; -import net.sf.taverna.t2.workbench.ui.Utils; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactoryRegistry; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentSPI; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; - -@SuppressWarnings("serial") -public class ContextualViewComponent extends JScrollPane implements UIComponentSPI { - /** delay before contextual view is redrawn */ - private static final int DELAY = 250; - private static final Color[] colors = new Color[] { BLUE, GREEN, ORANGE }; - // HACK ALERT! - public static boolean selfGenerated = false; - - private Observer<DataflowSelectionMessage> dataflowSelectionListener = new DataflowSelectionListener(); - private SelectionManager selectionManager; - private ContextualViewFactoryRegistry contextualViewFactoryRegistry; - GridBagConstraints gbc; - protected Map<JPanel, SectionLabel> panelToLabelMap = new HashMap<>(); - private String lastOpenedSectionName = ""; - private JPanel mainPanel; - private List<JPanel> shownComponents = null; - int colorIndex = 0; - private Timer updateSelectionTimer = null; - private Object lastSelectedObject = null; - - private static final Comparator<ContextualView> viewComparator = new Comparator<ContextualView>() { - @Override - public int compare(ContextualView o1, ContextualView o2) { - return o1.getPreferredPosition() - o2.getPreferredPosition(); - } - }; - - public ContextualViewComponent(EditManager editManager, - SelectionManager selectionManager, - ContextualViewFactoryRegistry contextualViewFactoryRegistry) { - this.selectionManager = selectionManager; - this.contextualViewFactoryRegistry = contextualViewFactoryRegistry; - updateSelectionTimer = new Timer(DELAY, updateSelectionListener); - updateSelectionTimer.setRepeats(false); - - initialise(); - - editManager.addObserver(new EditManagerObserver()); - selectionManager.addObserver(new SelectionManagerObserver()); - } - - @Override - public ImageIcon getIcon() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getName() { - return "Details"; - } - - private void initialise() { - mainPanel = new JPanel(new GridBagLayout()); - this.setViewportView(mainPanel); - } - - @Override - public void onDisplay() { - } - - @Override - public void onDispose() { - updateSelectionTimer.stop(); - } - - @SuppressWarnings("unchecked") - private void updateContextualView(List<ContextualViewFactory<? super Object>> viewFactories, - Object selection) { - if (selection == lastSelectedObject) - return; - lastSelectedObject = selection; - mainPanel = new JPanel(new GridBagLayout()); - panelToLabelMap.clear(); - - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.weightx = 0.1; - gbc.fill = HORIZONTAL; - - gbc.gridy = 0; - shownComponents = new ArrayList<>(); - List<ContextualView> views = new ArrayList<>(); - for (ContextualViewFactory<?> cvf : viewFactories) - views.addAll(((ContextualViewFactory<Object>) cvf) - .getViews(selection)); - Collections.sort(views, viewComparator); - colorIndex = 0; - if (views.isEmpty()) - mainPanel.add(new JLabel("No details available")); - else - populateContextualView(viewFactories, gbc, views); - gbc.weighty = 0.1; - gbc.fill = BOTH; - mainPanel.add(new JPanel(), gbc); - // mainPanel.revalidate(); - // mainPanel.repaint(); - this.setViewportView(mainPanel); - // this.revalidate(); - // this.repaint(); - } - - private void populateContextualView( - List<ContextualViewFactory<? super Object>> viewFactories, - GridBagConstraints gbc, List<ContextualView> views) { - JPanel firstPanel = null; - JPanel lastOpenedSection = null; - for (ContextualView view : views) { - SectionLabel label = new SectionLabel(view.getViewTitle(), nextColor()); - mainPanel.add(label, gbc); - gbc.gridy++; - JPanel subPanel = new JPanel(); - if (view.getViewTitle().equals(lastOpenedSectionName)) - lastOpenedSection = subPanel; - subPanel.setLayout(new GridBagLayout()); - - GridBagConstraints constraints = new GridBagConstraints(); - constraints.gridx = 0; - constraints.gridy = 0; - constraints.weightx = 0.1; - constraints.weighty = 0; - constraints.anchor = CENTER; - constraints.fill = HORIZONTAL; - - subPanel.add(view, constraints); - Frame frame = Utils.getParentFrame(this); - Action configureAction = view.getConfigureAction(frame); - if (configureAction != null) { - JButton configButton = new JButton(configureAction); - if (configButton.getText() == null - || configButton.getText().isEmpty()) - configButton.setText("Configure"); - constraints.gridy++; - constraints.fill = NONE; - constraints.anchor = LINE_START; - subPanel.add(configButton, constraints); - } - if (firstPanel == null) - firstPanel = subPanel; - mainPanel.add(subPanel, gbc); - shownComponents.add(subPanel); - gbc.gridy++; - if (viewFactories.size() != 1) - makeCloseable(subPanel, label); - else { - lastOpenedSectionName = label.getText(); - lastOpenedSection = subPanel; - panelToLabelMap.put(subPanel, label); - subPanel.setVisible(false); - } - } - if (lastOpenedSection != null) - openSection(lastOpenedSection); - else if (firstPanel != null) - openSection(firstPanel); - } - - private void clearContextualView() { - lastSelectedObject = null; - mainPanel = new JPanel(new GridBagLayout()); - mainPanel.add(new JLabel("No details available")); - this.setViewportView(mainPanel); - this.revalidate(); - } - - public void updateSelection(Object selectedItem) { - findContextualView(selectedItem); - } - - private Runnable updateSelectionRunnable = new Runnable() { - @Override - public void run() { - Object selection = getSelection(); - if (selection == null) - clearContextualView(); - else - updateSelection(selection); - } - }; - - private ActionListener updateSelectionListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - SwingUtilities.invokeLater(updateSelectionRunnable); - } - }; - - public void updateSelection() { - updateSelectionTimer.restart(); - } - - private Object getSelection() { - WorkflowBundle workflowBundle = selectionManager.getSelectedWorkflowBundle(); - - /* - * If there is no currently opened dataflow, clear the contextual view - * panel - */ - if (workflowBundle == null) { - return null; - } - DataflowSelectionModel selectionModel = selectionManager - .getDataflowSelectionModel(workflowBundle); - Set<Object> selection = selectionModel.getSelection(); - - /* - * If the dataflow is opened but no component of the dataflow is - * selected, clear the contextual view panel - */ - if (selection.isEmpty()) - return null; - return selection.iterator().next(); - } - - private void findContextualView(Object selection) { - List<ContextualViewFactory<? super Object>> viewFactoriesForBeanType = contextualViewFactoryRegistry - .getViewFactoriesForObject(selection); - updateContextualView(viewFactoriesForBeanType, selection); - } - - private final class SelectionManagerObserver extends SwingAwareObserver<SelectionManagerEvent> { - @Override - public void notifySwing(Observable<SelectionManagerEvent> sender, SelectionManagerEvent message) { - if (message instanceof WorkflowBundleSelectionEvent) - bundleSelected((WorkflowBundleSelectionEvent) message); - } - - private void bundleSelected(WorkflowBundleSelectionEvent event) { - WorkflowBundle oldBundle = event - .getPreviouslySelectedWorkflowBundle(); - WorkflowBundle newBundle = event.getSelectedWorkflowBundle(); - - if (oldBundle != null) - selectionManager.getDataflowSelectionModel(oldBundle) - .removeObserver(dataflowSelectionListener); - if (newBundle != null) - selectionManager.getDataflowSelectionModel(newBundle) - .addObserver(dataflowSelectionListener); - lastSelectedObject = null; - updateSelection(); - } - } - - private final class DataflowSelectionListener extends SwingAwareObserver<DataflowSelectionMessage> { - @Override - public void notifySwing(Observable<DataflowSelectionMessage> sender, - DataflowSelectionMessage message) { - updateSelection(); - } - } - - private final class EditManagerObserver extends SwingAwareObserver<EditManagerEvent> { - @Override - public void notifySwing(Observable<EditManagerEvent> sender, EditManagerEvent message) { - Object selection = getSelection(); - if ((selection != lastSelectedObject) && !selfGenerated) { - lastSelectedObject = null; - refreshView(); - } - } - } - - public void refreshView() { - if (mainPanel != null) - updateSelection(); - } - - private final class SectionLabel extends ShadedLabel { - private JLabel expand; - - private SectionLabel(String text, Color colour) { - super(text, colour); - expand = new JLabel(minusIcon); - add(expand, 0); - setExpanded(true); - } - - public void setExpanded(boolean expanded) { - if (expanded) - expand.setIcon(minusIcon); - else - expand.setIcon(plusIcon); - } - } - - private void makeCloseable(JPanel panel, SectionLabel label) { - panel.setVisible(false); - if (panelToLabelMap.get(panel) != label) { - panelToLabelMap.put(panel, label); - // Only add mouse listener once - label.addMouseListener(new SectionOpener(panel)); - } - } - - protected class SectionOpener extends MouseAdapter { - private final JPanel sectionToOpen; - - public SectionOpener(JPanel sectionToOpen) { - this.sectionToOpen = sectionToOpen; - } - - @Override - public void mouseClicked(MouseEvent e) { - openSection(sectionToOpen); - } - } - - public synchronized void openSection(JPanel sectionToOpen) { - lastOpenedSectionName = ""; - for (Entry<JPanel, SectionLabel> entry : panelToLabelMap.entrySet()) { - JPanel section = entry.getKey(); - SectionLabel sectionLabel = entry.getValue(); - - if (section != sectionToOpen) - section.setVisible(false); - else { - section.setVisible(!section.isVisible()); - if (section.isVisible()) - lastOpenedSectionName = sectionLabel.getText(); - } - sectionLabel.setExpanded(section.isVisible()); - } - this.revalidate(); - this.repaint(); - } - - private Color nextColor() { - if (colorIndex >= colors.length) - colorIndex = 0; - return colors[colorIndex++]; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponentFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponentFactory.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponentFactory.java deleted file mode 100644 index db43a0d..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/impl/ContextualViewComponentFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007-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.impl; - -import javax.swing.ImageIcon; - -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactoryRegistry; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentSPI; - -public class ContextualViewComponentFactory implements UIComponentFactorySPI { - private EditManager editManager; - private SelectionManager selectionManager; - private ContextualViewFactoryRegistry contextualViewFactoryRegistry; - - @Override - public UIComponentSPI getComponent() { - return new ContextualViewComponent(editManager, selectionManager, - contextualViewFactoryRegistry); - } - - @Override - public ImageIcon getIcon() { - return null; - } - - @Override - public String getName() { - return "Details"; - } - - public void setEditManager(EditManager editManager) { - this.editManager = editManager; - } - - public void setSelectionManager(SelectionManager selectionManager) { - this.selectionManager = selectionManager; - } - - public void setContextualViewFactoryRegistry( - ContextualViewFactoryRegistry contextualViewFactoryRegistry) { - this.contextualViewFactoryRegistry = contextualViewFactoryRegistry; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualView.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualView.java deleted file mode 100644 index 452f7b3..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualView.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.inputport; - -import static java.awt.FlowLayout.LEFT; - -import java.awt.FlowLayout; - -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import org.apache.taverna.scufl2.api.port.InputActivityPort; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; - -/** - * Contextual view for dataflow procerssor's input ports. - * - * @author Alex Nenadic - */ -class InputPortContextualView extends ContextualView { - private static final String NO_DETAILS_AVAILABLE_HTML = "<html><body>" - + "<i>No details available.</i>" + "</body><html>"; - private static final long serialVersionUID = -7743029534480678624L; - - private InputActivityPort inputPort; - private JPanel inputPortView; - - public InputPortContextualView(InputActivityPort inputport) { - this.inputPort = inputport; - initView(); - } - - @Override - public JComponent getMainFrame() { - refreshView(); - return inputPortView; - } - - @Override - public String getViewTitle() { - return "Service input port: " + inputPort.getName(); - } - - @Override - public void refreshView() { - inputPortView = new JPanel(new FlowLayout(LEFT)); - inputPortView.setBorder(new EmptyBorder(5, 5, 5, 5)); - JLabel label = new JLabel(NO_DETAILS_AVAILABLE_HTML); - inputPortView.add(label); - } - - @Override - public int getPreferredPosition() { - return 100; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualViewFactory.java deleted file mode 100644 index bf35c17..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/inputport/InputPortContextualViewFactory.java +++ /dev/null @@ -1,48 +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.inputport; - -import java.util.Arrays; -import java.util.List; - -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory; -import org.apache.taverna.scufl2.api.port.InputActivityPort; - -/** - * A factory of contextual views for dataflow proessor's (i.e. its associated - * activity's) input ports. - * - * @author Alex Nenadic - */ -public class InputPortContextualViewFactory implements - ContextualViewFactory<InputActivityPort> { - @Override - public boolean canHandle(Object object) { - return object instanceof InputActivityPort; - } - - @Override - public List<ContextualView> getViews(InputActivityPort inputport) { - return Arrays.asList(new ContextualView[] { - new InputPortContextualView(inputport)}); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationAction.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationAction.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationAction.java deleted file mode 100644 index ad06636..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationAction.java +++ /dev/null @@ -1,79 +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.merge; - -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.AbstractAction; - -import net.sf.taverna.t2.workbench.edits.EditException; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workflow.edits.ReorderMergePositionsEdit; - -import org.apache.log4j.Logger; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.core.DataLink; - -/** - * Configuration action for a Merge. This action changes the order of - * merge's incoming ports. - * - * @author Alex Nenadic - * - */ -@SuppressWarnings("serial") -class MergeConfigurationAction extends AbstractAction { - private static Logger logger = Logger - .getLogger(MergeConfigurationAction.class); - - private final List<DataLink> reorderedDataLinksList; - private final List<DataLink> datalinks; - private final EditManager editManager; - private final SelectionManager selectionManager; - - MergeConfigurationAction(List<DataLink> datalinks, - List<DataLink> reorderedDataLinksList, EditManager editManager, - SelectionManager selectionManager) { - this.datalinks = datalinks; - this.reorderedDataLinksList = reorderedDataLinksList; - this.editManager = editManager; - this.selectionManager = selectionManager; - } - - @Override - public void actionPerformed(ActionEvent e) { - ReorderMergePositionsEdit edit = new ReorderMergePositionsEdit( - datalinks, reorderedDataLinksList); - - WorkflowBundle bundle = selectionManager.getSelectedWorkflowBundle(); - - try { - editManager.doDataflowEdit(bundle, edit); - } catch (IllegalStateException ex1) { - logger.error("Could not configure merge", ex1); - } catch (EditException ex2) { - logger.error("Could not configure merge", ex2); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationView.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationView.java deleted file mode 100644 index 8f07c58..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeConfigurationView.java +++ /dev/null @@ -1,233 +0,0 @@ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.merge; - -import static java.awt.BorderLayout.EAST; -import static java.awt.BorderLayout.NORTH; -import static java.awt.BorderLayout.SOUTH; -import static java.lang.Math.max; -import static javax.swing.BoxLayout.Y_AXIS; -import static javax.swing.ListSelectionModel.SINGLE_SELECTION; -import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS; -import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS; -import static javax.swing.SwingConstants.CENTER; -import static javax.swing.SwingConstants.LEFT; -import static javax.swing.SwingConstants.RIGHT; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.downArrowIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.upArrowIcon; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.FontMetrics; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.BoxLayout; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import org.apache.taverna.scufl2.api.core.DataLink; - -@SuppressWarnings("serial") -public class MergeConfigurationView extends HelpEnabledDialog { - private static final String TITLE = "<html><body><b>Order of incoming links</b></body></html>"; - - private List<DataLink> dataLinks; - private List<DataLink> reorderedDataLinks; - /** Ordered list of labels for dataLinks to be displayed to the user */ - private DefaultListModel<String> labelListModel; - /** JList that displays the labelListModel */ - JList<String> list; - /** Button to push the dataLink up the list */ - private JButton upButton; - /** Button to push the dataLink down the list */ - private JButton downButton; - private final EditManager editManager; - private final SelectionManager selectionManager; - - public MergeConfigurationView(List<DataLink> dataLinks, EditManager editManager, - SelectionManager selectionManager) { - super((Frame)null, "Merge Configuration", true); - - this.dataLinks = new ArrayList<>(dataLinks); - reorderedDataLinks = new ArrayList<>(dataLinks); - this.editManager = editManager; - this.selectionManager = selectionManager; - labelListModel = new DefaultListModel<>(); - for (DataLink dataLink : dataLinks) - labelListModel.addElement(dataLink.toString()); - - initComponents(); - } - - private void initComponents() { - getContentPane().setLayout(new BorderLayout()); - - JPanel listPanel = new JPanel(); - listPanel.setLayout(new BorderLayout()); - listPanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), - new EtchedBorder())); - - JLabel title = new JLabel(TITLE); - title.setBorder(new EmptyBorder(5, 5, 5, 5)); - listPanel.add(title, NORTH); - - list = new JList<>(labelListModel); - list.setSelectionMode(SINGLE_SELECTION); - list.setVisibleRowCount(-1); - list.addListSelectionListener(new ListSelectionListener() { - /** - * Enable and disable up and down buttons based on which item in the - * list is selected - */ - @Override - public void valueChanged(ListSelectionEvent e) { - int index = list.getSelectedIndex(); - if ((index == -1) || (index == 0 && labelListModel.size() == 0)) { - // nothing selected or only one item in the list - upButton.setEnabled(false); - downButton.setEnabled(false); - } else { - upButton.setEnabled(index > 0); - downButton.setEnabled(index < labelListModel.size() - 1); - } - } - }); - - final JScrollPane listScroller = new JScrollPane(list); - listScroller.setBorder(new EmptyBorder(5, 5, 5, 5)); - listScroller.setBackground(listPanel.getBackground()); - listScroller.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_ALWAYS); - listScroller.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); - // Set the size of scroll pane to make all list items visible - FontMetrics fm = listScroller.getFontMetrics(this.getFont()); - int listScrollerHeight = fm.getHeight() * labelListModel.size() + 75; //+75 just in case - listScroller.setPreferredSize(new Dimension(listScroller - .getPreferredSize().width, max(listScrollerHeight, - listScroller.getPreferredSize().height))); - listPanel.add(listScroller, BorderLayout.CENTER); - - JPanel upDownButtonPanel = new JPanel(); - upDownButtonPanel.setLayout(new BoxLayout(upDownButtonPanel, Y_AXIS)); - upDownButtonPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - - upButton = new JButton(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - int index = list.getSelectedIndex(); - if (index != -1) { - // Swap the labels - String label = (String) labelListModel.elementAt(index); - labelListModel.set(index, labelListModel.get(index - 1)); - labelListModel.set(index - 1, label); - // Swap the dataLinks - DataLink dataLink = reorderedDataLinks.get(index); - reorderedDataLinks.set(index, - reorderedDataLinks.get(index - 1)); - reorderedDataLinks.set(index - 1, dataLink); - // Make the pushed item selected - list.setSelectedIndex(index - 1); - // Refresh the list - listScroller.repaint(); - listScroller.revalidate(); - } - } - }); - upButton.setIcon(upArrowIcon); - upButton.setText("Up"); - // Place text to the right of icon, vertically centered - upButton.setVerticalTextPosition(CENTER); - upButton.setHorizontalTextPosition(RIGHT); - // Set the horizontal alignment of the icon and text - upButton.setHorizontalAlignment(LEFT); - upButton.setEnabled(false); - upDownButtonPanel.add(upButton); - - downButton = new JButton(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - int index = list.getSelectedIndex(); - if (index != -1) { - // Swap the labels - String label = (String) labelListModel.elementAt(index); - labelListModel.set(index, labelListModel.get(index + 1)); - labelListModel.set(index + 1, label); - // Swap the dataLinks - DataLink dataLink = reorderedDataLinks.get(index); - reorderedDataLinks.set(index, - reorderedDataLinks.get(index + 1)); - reorderedDataLinks.set(index + 1, dataLink); - // Make the pushed item selected - list.setSelectedIndex(index + 1); - // Refresh the list - list.repaint(); - listScroller.revalidate(); - } - } - }); - downButton.setIcon(downArrowIcon); - downButton.setText("Down"); - // Place text to the right of icon, vertically centered - downButton.setVerticalTextPosition(CENTER); - downButton.setHorizontalTextPosition(RIGHT); - // Set the horizontal alignment of the icon and text - downButton.setHorizontalAlignment(LEFT); - downButton.setEnabled(false); - // set the up button to be of the same size as down button - upButton.setPreferredSize(downButton.getPreferredSize()); - upButton.setMaximumSize(downButton.getPreferredSize()); - upButton.setMinimumSize(downButton.getPreferredSize()); - upDownButtonPanel.add(downButton); - - listPanel.add(upDownButtonPanel, EAST); - - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - - JButton jbOK = new JButton("OK"); - jbOK.addActionListener(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - new MergeConfigurationAction(dataLinks, reorderedDataLinks, - editManager, selectionManager).actionPerformed(e); - closeDialog(); - } - }); - - JButton jbCancel = new JButton("Cancel"); - jbCancel.addActionListener(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - closeDialog(); - } - }); - - buttonPanel.add(jbOK); - buttonPanel.add(jbCancel); - - getContentPane().add(listPanel, BorderLayout.CENTER); - getContentPane().add(buttonPanel, SOUTH); - pack(); - } - - /** - * Close the dialog. - */ - private void closeDialog() { - setVisible(false); - dispose(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualView.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualView.java deleted file mode 100644 index 441f41b..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualView.java +++ /dev/null @@ -1,150 +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.merge; - -import static java.awt.BorderLayout.CENTER; -import static java.awt.BorderLayout.SOUTH; -import static java.awt.FlowLayout.LEFT; -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 java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JEditorPane; -import javax.swing.JPanel; - -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import org.apache.taverna.workflowmodel.Merge; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.core.DataLink; - -/** - * Contextual view for a {@link Merge}. - * - * @author Alex Nenadic - */ -@SuppressWarnings("serial") -class MergeContextualView extends ContextualView { - @SuppressWarnings("unused") - private DataLink dataLink; - private List<DataLink> datalinks; - @SuppressWarnings("unused") - private WorkflowBundle workflow; - private JEditorPane editorPane; - private final EditManager editManager; - private final ColourManager colourManager; - private final SelectionManager selectionManager; - - // TODO inject from Spring via factory? - private Scufl2Tools scufl2Tools = new Scufl2Tools(); - - public MergeContextualView(DataLink dataLink, EditManager editManager, - SelectionManager selectionManager, ColourManager colourManager) { - this.dataLink = dataLink; - this.selectionManager = selectionManager; - datalinks = scufl2Tools.datalinksTo(dataLink.getSendsTo()); - this.editManager = editManager; - this.colourManager = colourManager; - workflow = selectionManager.getSelectedWorkflowBundle(); - initView(); - } - - @Override - public JComponent getMainFrame() { - editorPane = createEditorPane(buildHtml()); - return panelForHtml(editorPane); - } - - @Override - public String getViewTitle() { - return "Merge Position"; - } - - /** - * Update the view with the latest information from the configuration bean. - */ - @Override - public void refreshView() { - editorPane.setText(buildHtml()); - repaint(); - } - - private String buildHtml() { - StringBuilder html = new StringBuilder( - getHtmlHead(getBackgroundColour())); - html.append(buildTableOpeningTag()) - .append("<tr><td colspan=\"2\"><b>") - .append(getViewTitle()) - .append("</b></td></tr>") - .append("<tr><td colspan=\"2\"><b>Ordered incoming links</b></td></tr>"); - - int counter = 1; - for (DataLink datalink : datalinks) - html.append("<tr><td>").append(counter++).append(".</td><td>") - .append(datalink).append("</td></tr>"); - - return html.append("</table>").append("</body></html>").toString(); - } - - protected JPanel panelForHtml(JEditorPane editorPane) { - final JPanel panel = new JPanel(); - - JPanel buttonPanel = new JPanel(new FlowLayout(LEFT)); - - JButton configureButton = new JButton(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - MergeConfigurationView mergeConfigurationView = new MergeConfigurationView( - datalinks, editManager, selectionManager); - mergeConfigurationView.setLocationRelativeTo(panel); - mergeConfigurationView.setVisible(true); - } - }); - configureButton.setText("Configure"); - buttonPanel.add(configureButton); - - panel.setLayout(new BorderLayout()); - panel.add(editorPane, CENTER); - panel.add(buttonPanel, SOUTH); - return panel; - } - - public String getBackgroundColour() { - return colourManager.getDefaultPropertyMap().get( - "net.sf.taverna.t2.workflowmodel.Merge"); - } - - @Override - public int getPreferredPosition() { - return 100; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualViewFactory.java deleted file mode 100644 index 8e4a93a..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/merge/MergeContextualViewFactory.java +++ /dev/null @@ -1,66 +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.merge; - -import java.util.Arrays; -import java.util.List; - -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory; -import org.apache.taverna.scufl2.api.core.DataLink; - -/** - * A factory of contextual views for dataflow's merges. - * - * @author Alex Nenadic - */ -public class MergeContextualViewFactory implements ContextualViewFactory<DataLink> { - private EditManager editManager; - private SelectionManager selectionManager; - private ColourManager colourManager; - - @Override - public boolean canHandle(Object object) { - return object instanceof DataLink - && ((DataLink) object).getMergePosition() != null; - } - - @Override - public List<ContextualView> getViews(DataLink merge) { - return Arrays.asList(new ContextualView[] { - new MergeContextualView(merge, editManager, selectionManager, colourManager)}); - } - - public void setEditManager(EditManager editManager) { - this.editManager = editManager; - } - - public void setColourManager(ColourManager colourManager) { - this.colourManager = colourManager; - } - - public void setSelectionManager(SelectionManager selectionManager) { - this.selectionManager = selectionManager; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualView.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualView.java deleted file mode 100644 index d997637..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualView.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.views.contextualviews.outputport; - -import static java.awt.FlowLayout.LEFT; - -import java.awt.FlowLayout; - -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; - -/** - * Contextual view for dataflow procerssor's output ports. - * - * @author Alex Nenadic - */ -public class OutputPortContextualView extends ContextualView { - private static final String NO_DETAILS_AVAILABLE_HTML = "<html><body>" - + "<i>No details available.</i>" + "</body><html>"; - private static final long serialVersionUID = -7743029534480678624L; - - private ActivityOutputPort outputPort; - private JPanel outputPortView; - - public OutputPortContextualView(ActivityOutputPort outputport) { - this.outputPort = outputport; - initView(); - } - - @Override - public JComponent getMainFrame() { - refreshView(); - return outputPortView; - } - - @Override - public String getViewTitle() { - return "Service output port: " + outputPort.getName(); - } - - @Override - public void refreshView() { - outputPortView = new JPanel(new FlowLayout(LEFT)); - outputPortView.setBorder(new EmptyBorder(5,5,5,5)); - JLabel label = new JLabel(NO_DETAILS_AVAILABLE_HTML); - outputPortView.add(label); - } - - @Override - public int getPreferredPosition() { - return 100; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualViewFactory.java deleted file mode 100644 index a01a259..0000000 --- a/taverna-contextual-views-impl/src/main/java/net/sf/taverna/t2/workbench/ui/views/contextualviews/outputport/OutputPortContextualViewFactory.java +++ /dev/null @@ -1,48 +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.outputport; - -import java.util.Arrays; -import java.util.List; - -import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView; -import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory; -import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; - -/** - * A factory of contextual views for dataflow proessor's (i.e. its associated - * activity's) output ports. - * - * @author Alex Nenadic - */ -public class OutputPortContextualViewFactory implements - ContextualViewFactory<ActivityOutputPort> { - @Override - public boolean canHandle(Object object) { - return object instanceof ActivityOutputPort; - } - - @Override - public List<ContextualView> getViews(ActivityOutputPort outputport) { - return Arrays.asList(new ContextualView[] { - new OutputPortContextualView(outputport)}); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/activity/impl/ContextualViewFactoryRegistryImpl.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/activity/impl/ContextualViewFactoryRegistryImpl.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/activity/impl/ContextualViewFactoryRegistryImpl.java new file mode 100644 index 0000000..d3d858d --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/activity/impl/ContextualViewFactoryRegistryImpl.java @@ -0,0 +1,71 @@ +/* +* 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.views.contextualviews.activity.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory; +import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactoryRegistry; + +/** + * An SPI registry for discovering ActivityViewFactories for a given object, + * like an {@link org.apache.taverna.workflowmodel.processor.activity.Activity}. + * <p> + * For {@link ContextualViewFactory factories} to be found, its full qualified + * name needs to be defined as a resource file + * <code>/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualViewFactory</code> + * + * @author Alan R Williams + * @author Stuart Owen + * @author Ian Dunlop + * @author Stian Soiland-Reyes + * + * @see ContextualViewFactory + */ +public class ContextualViewFactoryRegistryImpl implements + ContextualViewFactoryRegistry { + private List<ContextualViewFactory<?>> contextualViewFactories; + + /** + * 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) + */ + @Override + public List<ContextualViewFactory<?>> getViewFactoriesForObject( + Object object) { + List<ContextualViewFactory<?>> result = new ArrayList<>(); + for (ContextualViewFactory<?> factory : contextualViewFactories) + if (factory.canHandle(object)) + result.add(factory); + return result; + } + + public void setContextualViewFactories( + List<ContextualViewFactory<?>> contextualViewFactories) { + this.contextualViewFactories = contextualViewFactories; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualView.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualView.java new file mode 100644 index 0000000..f912549 --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualView.java @@ -0,0 +1,262 @@ +/* +* 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.views.contextualviews.annotated; + +import static javax.swing.BoxLayout.Y_AXIS; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; +import java.util.regex.Pattern; + +import javax.swing.BoxLayout; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.EmptyBorder; +import javax.swing.border.TitledBorder; + +import org.apache.taverna.annotation.Annotated; +import org.apache.taverna.annotation.AnnotationBeanSPI; +import org.apache.taverna.lang.ui.DialogTextArea; +import org.apache.taverna.workbench.edits.CompoundEdit; +import org.apache.taverna.workbench.edits.Edit; +import org.apache.taverna.workbench.edits.EditException; +import org.apache.taverna.workbench.edits.EditManager; +import org.apache.taverna.workbench.selection.SelectionManager; +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; +import org.apache.taverna.workbench.ui.views.contextualviews.impl.ContextualViewComponent; + +import org.apache.log4j.Logger; + +import org.apache.taverna.scufl2.api.container.WorkflowBundle; + +/** + * This is a ContextualView that should be able to display and allow editing of + * Annotation information for any Annotated. At the moment it is only used for + * Dataflow. + * + * @author Alan R Williams + */ +@SuppressWarnings("serial") +class AnnotatedContextualView extends ContextualView { + private static final int WORKFLOW_NAME_LENGTH = 20; + public static final String VIEW_TITLE = "Annotations"; + private final static String MISSING_VALUE = "Type here to give details"; + private final static int DEFAULT_AREA_WIDTH = 60; + private final static int DEFAULT_AREA_ROWS = 8; + + private static Logger logger = Logger + .getLogger(AnnotatedContextualView.class); + private static PropertyResourceBundle prb = (PropertyResourceBundle) ResourceBundle + .getBundle("annotatedcontextualview"); + + // TODO convert to scufl2 + // private static AnnotationTools annotationTools = new AnnotationTools(); + + /** + * The object to which the Annotations apply + */ + private Annotated<?> annotated; + private SelectionManager selectionManager; + private EditManager editManager; + private boolean isStandalone = false; + private JPanel panel; + @SuppressWarnings("unused") + private final List<AnnotationBeanSPI> annotationBeans; + + public AnnotatedContextualView(Annotated<?> annotated, + EditManager editManager, SelectionManager selectionManager, + List<AnnotationBeanSPI> annotationBeans) { + super(); + this.editManager = editManager; + this.selectionManager = selectionManager; + this.annotationBeans = annotationBeans; + this.annotated = annotated; + + initialise(); + initView(); + } + + @Override + public void refreshView() { + initialise(); + } + + private void initialise() { + if (panel == null) { + panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, Y_AXIS)); + } else + panel.removeAll(); + populatePanel(); + revalidate(); + } + + @Override + public JComponent getMainFrame() { + return panel; + } + + @Override + public String getViewTitle() { + return VIEW_TITLE; + } + + private Map<String,String> getAnnotations() { + // TODO convert to scufl2 + Map<String, String> result = new HashMap<>(); + //for (Class<?> c : annotationTools.getAnnotatingClasses(annotated)) { + // String name = ""; + // try { + // name = prb.getString(c.getCanonicalName()); + // } catch (MissingResourceException e) { + // name = c.getCanonicalName(); + // } + // String value = annotationTools.getAnnotationString(annotated, c, + // MISSING_VALUE); + // result.put(name,value); + //} + return result; + } + public void populatePanel() { + JPanel scrollPanel = new JPanel(); + scrollPanel.setLayout(new BoxLayout(scrollPanel, Y_AXIS)); + panel.setBorder(new EmptyBorder(5, 5, 5, 5)); + Map<String,String>annotations = getAnnotations(); + for (String name : annotations.keySet()) { + JPanel subPanel = new JPanel(); + subPanel.setBorder(new TitledBorder(name)); + subPanel.add(createTextArea(String.class, annotations.get(name))); + scrollPanel.add(subPanel); + } + JScrollPane scrollPane = new JScrollPane(scrollPanel); + panel.add(scrollPane); + } + + private JScrollPane createTextArea(Class<?> c, String value) { + DialogTextArea area = new DialogTextArea(value); + area.setFocusable(true); + area.addFocusListener(new TextAreaFocusListener(area, c)); + area.setColumns(DEFAULT_AREA_WIDTH); + area.setRows(DEFAULT_AREA_ROWS); + area.setLineWrap(true); + area.setWrapStyleWord(true); + + return new JScrollPane(area); + } + + private class TextAreaFocusListener implements FocusListener { + String oldValue = null; + Class<?> annotationClass; + DialogTextArea area = null; + + public TextAreaFocusListener(DialogTextArea area, Class<?> c) { + annotationClass = c; + oldValue = area.getText(); + this.area = area; + } + + @Override + public void focusGained(FocusEvent e) { + if (area.getText().equals(MISSING_VALUE)) + area.setText(""); + } + + @Override + public void focusLost(FocusEvent e) { + String currentValue = area.getText(); + if (currentValue.isEmpty() || currentValue.equals(MISSING_VALUE)) { + currentValue = MISSING_VALUE; + area.setText(currentValue); + } + if (!currentValue.equals(oldValue)) { + if (currentValue == MISSING_VALUE) + currentValue = ""; + try { + WorkflowBundle currentDataflow = selectionManager + .getSelectedWorkflowBundle(); + List<Edit<?>> editList = new ArrayList<>(); + addWorkflowNameEdits(currentValue, currentDataflow, + editList); + if (!isStandalone) + ContextualViewComponent.selfGenerated = true; + editManager.doDataflowEdit(currentDataflow, + new CompoundEdit(editList)); + ContextualViewComponent.selfGenerated = false; + } catch (EditException e1) { + logger.warn("Can't set annotation", e1); + } + oldValue = area.getText(); + } + } + + private boolean isTitleAnnotation() { + // TODO convert to scufl2 + return prb.getString(annotationClass.getCanonicalName()).equals( + "Title"); + } + + // TODO convert to scufl2 + private void addWorkflowNameEdits(String currentValue, + WorkflowBundle currentDataflow, List<Edit<?>> editList) { + //editList.add(annotationTools.setAnnotationString(annotated, + // annotationClass, currentValue, edits)); + if (annotated == currentDataflow && isTitleAnnotation() + && !currentValue.isEmpty()) { + @SuppressWarnings("unused") + String sanitised = sanitiseName(currentValue); + //editList.add(edits.getUpdateDataflowNameEdit(currentDataflow, + // sanitised)); + } + } + } + + /** + * Checks that the name does not have any characters that are invalid for a + * processor name. + * <p> + * The resulting name must contain only the chars [A-Za-z_0-9]. + * + * @param name + * the original name + * @return the sanitised name + */ + private static String sanitiseName(String name) { + if (name.length() > WORKFLOW_NAME_LENGTH) + name = name.substring(0, WORKFLOW_NAME_LENGTH); + if (Pattern.matches("\\w++", name)) + return name; + StringBuilder temp = new StringBuilder(); + for (char c : name.toCharArray()) + temp.append(Character.isLetterOrDigit(c) || c == '_' ? c : '_'); + return temp.toString(); + } + + @Override + public int getPreferredPosition() { + return 500; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualViewFactory.java new file mode 100644 index 0000000..9cd0d1f --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/annotated/AnnotatedContextualViewFactory.java @@ -0,0 +1,62 @@ +/* +* 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.views.contextualviews.annotated; + +import static java.util.Collections.singletonList; + +import java.util.List; + +import org.apache.taverna.annotation.Annotated; +import org.apache.taverna.annotation.AnnotationBeanSPI; +import org.apache.taverna.workbench.edits.EditManager; +import org.apache.taverna.workbench.selection.SelectionManager; +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; +import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory; +import org.apache.taverna.workflowmodel.processor.activity.Activity; + +public class AnnotatedContextualViewFactory implements + ContextualViewFactory<Annotated<?>> { + private EditManager editManager; + private List<AnnotationBeanSPI> annotationBeans; + private SelectionManager selectionManager; + + @Override + public boolean canHandle(Object selection) { + return ((selection instanceof Annotated) && !(selection instanceof Activity)); + } + + @Override + public List<ContextualView> getViews(Annotated<?> selection) { + return singletonList((ContextualView) new AnnotatedContextualView( + selection, editManager, selectionManager, annotationBeans)); + } + + public void setEditManager(EditManager editManager) { + this.editManager = editManager; + } + + public void setSelectionManager(SelectionManager selectionManager) { + this.selectionManager = selectionManager; + } + + public void setAnnotationBeans(List<AnnotationBeanSPI> annotationBeans) { + this.annotationBeans = annotationBeans; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualView.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualView.java new file mode 100644 index 0000000..8bf136c --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualView.java @@ -0,0 +1,73 @@ +/* +* 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.views.contextualviews.condition; + +import java.awt.FlowLayout; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; +import org.apache.taverna.scufl2.api.core.BlockingControlLink; + +/** + * Contextual view for dataflow's control (condition) links. + * + * @author David Withers + */ +class ConditionContextualView extends ContextualView { + private static final long serialVersionUID = -894521200616176439L; + + private final BlockingControlLink condition; + private JPanel contitionView; + + public ConditionContextualView(BlockingControlLink condition) { + this.condition = condition; + initView(); + } + + @Override + public JComponent getMainFrame() { + refreshView(); + return contitionView; + } + + @Override + public String getViewTitle() { + return "Control link: " + condition.getBlock().getName() + + " runs after " + condition.getUntilFinished().getName(); + } + + @Override + public void refreshView() { + contitionView = new JPanel(new FlowLayout(FlowLayout.LEFT)); + contitionView.setBorder(new EmptyBorder(5, 5, 5, 5)); + JLabel label = new JLabel( + "<html><body><i>No details available.</i></body><html>"); + contitionView.add(label); + } + + @Override + public int getPreferredPosition() { + return 100; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualViewFactory.java new file mode 100644 index 0000000..30bc50e --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/condition/ConditionContextualViewFactory.java @@ -0,0 +1,50 @@ +/* +* 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.views.contextualviews.condition; + +import static java.util.Arrays.asList; + +import java.util.List; + +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; +import org.apache.taverna.workbench.ui.views.contextualviews.activity.ContextualViewFactory; +import org.apache.taverna.workflowmodel.Condition; +import org.apache.taverna.scufl2.api.core.BlockingControlLink; + +/** + * A factory of contextual views for dataflow's condition links. + * + * @author David Withers + * + */ +public class ConditionContextualViewFactory implements + ContextualViewFactory<BlockingControlLink> { + @Override + public boolean canHandle(Object object) { + return object instanceof Condition; + } + + @Override + public List<ContextualView> getViews(BlockingControlLink condition) { + return asList(new ContextualView[] { new ConditionContextualView( + condition) }); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualView.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualView.java new file mode 100644 index 0000000..d40d75a --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualView.java @@ -0,0 +1,124 @@ +/* +* 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.views.contextualviews.dataflow; + +import static org.apache.taverna.lang.ui.HtmlUtils.buildTableOpeningTag; +import static org.apache.taverna.lang.ui.HtmlUtils.createEditorPane; +import static org.apache.taverna.lang.ui.HtmlUtils.getHtmlHead; +import static org.apache.taverna.lang.ui.HtmlUtils.panelForHtml; + +import javax.swing.JComponent; +import javax.swing.JEditorPane; + +import org.apache.taverna.workbench.configuration.colour.ColourManager; +import org.apache.taverna.workbench.file.FileManager; +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; +import org.apache.taverna.workflowmodel.Dataflow; +import org.apache.taverna.scufl2.api.core.Workflow; +import org.apache.taverna.scufl2.api.port.InputWorkflowPort; +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort; + +/** + * @author alanrw + */ +@SuppressWarnings("serial") +class DataflowContextualView extends ContextualView { + private static int MAX_LENGTH = 50; + private static final String ELLIPSIS = "..."; + + private Workflow dataflow; + private JEditorPane editorPane; + private final FileManager fileManager; + private final ColourManager colourManager; + + public DataflowContextualView(Workflow dataflow, FileManager fileManager, + ColourManager colourManager) { + this.dataflow = dataflow; + this.fileManager = fileManager; + 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><td colspan=\"2\" align=\"center\"><b>Source</b></td></tr>"); + String source = "Newly created"; + if (fileManager.getDataflowSource(dataflow.getParent()) != null) + source = fileManager.getDataflowName(dataflow.getParent()); + + html.append("<tr><td colspan=\"2\" align=\"center\">").append(source) + .append("</td></tr>"); + if (!dataflow.getInputPorts().isEmpty()) { + html.append("<tr><th>Input Port Name</th><th>Depth</th></tr>"); + for (InputWorkflowPort dip : dataflow.getInputPorts()) + html.append("<tr><td>") + .append(dip.getName()) + .append("</td><td>") + .append(dip.getDepth() < 0 ? "invalid/unpredicted" + : dip.getDepth()).append("</td></tr>"); + } + if (!dataflow.getOutputPorts().isEmpty()) { + html.append("<tr><th>Output Port Name</th><th>Depth</th></tr>"); + for (OutputWorkflowPort dop : dataflow.getOutputPorts()) + html.append("<tr><td>") + .append(dop.getName()) + .append("</td><td>") + .append(/*(dop.getDepth() < 0 ?*/ "invalid/unpredicted" /*: dop.getDepth())*/) + .append("</td>" + "</tr>"); + } + + return html.append("</table>").append("</body></html>").toString(); + } + + public String getBackgroundColour() { + return colourManager.getDefaultPropertyMap().get( + Dataflow.class.toString()); + } + + @Override + public int getPreferredPosition() { + return 100; + } + + private String limitName(String fullName) { + if (fullName.length() <= MAX_LENGTH) + return fullName; + return fullName.substring(0, MAX_LENGTH - ELLIPSIS.length()) + ELLIPSIS; + } + + @Override + public String getViewTitle() { + return "Workflow " + limitName(dataflow.getName()); + } + + @Override + public void refreshView() { + editorPane.setText(buildHtml()); + repaint(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualViewFactory.java new file mode 100644 index 0000000..9bb3fed --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflow/DataflowContextualViewFactory.java @@ -0,0 +1,57 @@ +/* +* 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.views.contextualviews.dataflow; + +import java.util.Arrays; +import java.util.List; + +import org.apache.taverna.workbench.configuration.colour.ColourManager; +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; +import org.apache.taverna.scufl2.api.core.Workflow; + +/** + * @author alanrw + */ +public class DataflowContextualViewFactory implements + ContextualViewFactory<Workflow> { + private FileManager fileManager; + private ColourManager colourManager; + + @Override + public boolean canHandle(Object selection) { + return selection instanceof Workflow; + } + + @Override + public List<ContextualView> getViews(Workflow selection) { + return Arrays.asList(new ContextualView[] { + new DataflowContextualView(selection, fileManager, colourManager)}); + } + + public void setFileManager(FileManager fileManager) { + this.fileManager = fileManager; + } + + public void setColourManager(ColourManager colourManager) { + this.colourManager = colourManager; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualView.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualView.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualView.java new file mode 100644 index 0000000..e2a0c30 --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualView.java @@ -0,0 +1,95 @@ +/* +* 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.views.contextualviews.dataflowinputport; + +import static java.awt.FlowLayout.LEFT; + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +import org.apache.taverna.scufl2.api.port.InputWorkflowPort; +import org.apache.taverna.workbench.file.FileManager; +import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView; + +/** + * Contextual view for dataflow's input ports. + * + * @author Alex Nenadic + */ +class DataflowInputPortContextualView extends ContextualView{ + private static final long serialVersionUID = -8746856072335775933L; + + private InputWorkflowPort dataflowInputPort; + private JPanel dataflowInputPortView; + @SuppressWarnings("unused") + private FileManager fileManager; + + public DataflowInputPortContextualView(InputWorkflowPort inputport, + FileManager fileManager) { + this.dataflowInputPort = inputport; + this.fileManager = fileManager; + initView(); + } + + @Override + public JComponent getMainFrame() { + refreshView(); + return dataflowInputPortView; + } + + @Override + public String getViewTitle() { + return "Workflow input port: " + dataflowInputPort.getName(); + } + + @Override + public void refreshView() { + dataflowInputPortView = new JPanel(new FlowLayout(LEFT)); + dataflowInputPortView.setBorder(new EmptyBorder(5, 5, 5, 5)); + JLabel label = new JLabel(getTextFromDepth("port", + dataflowInputPort.getDepth())); + dataflowInputPortView.add(label); + } + + @SuppressWarnings("serial") + @Override + public Action getConfigureAction(Frame owner) { + return new AbstractAction("Update prediction") { + @Override + public void actionPerformed(ActionEvent e) { + // fileManager.getCurrentDataflow().checkValidity(); + refreshView(); + } + }; + } + + @Override + public int getPreferredPosition() { + return 100; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualViewFactory.java ---------------------------------------------------------------------- diff --git a/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualViewFactory.java b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualViewFactory.java new file mode 100644 index 0000000..e53ce14 --- /dev/null +++ b/taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/dataflowinputport/DataflowInputPortContextualViewFactory.java @@ -0,0 +1,53 @@ +/* +* 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.views.contextualviews.dataflowinputport; + +import java.util.Arrays; +import java.util.List; + +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; +import org.apache.taverna.scufl2.api.port.InputWorkflowPort; + +/** + * A factory of contextual views for dataflow's input ports. + * + * @author Alex Nenadic + */ +public class DataflowInputPortContextualViewFactory implements + ContextualViewFactory<InputWorkflowPort> { + private FileManager fileManager; + + @Override + public boolean canHandle(Object object) { + return object instanceof InputWorkflowPort; + } + + @Override + public List<ContextualView> getViews(InputWorkflowPort inputport) { + return Arrays.asList(new ContextualView[] { + new DataflowInputPortContextualView(inputport, fileManager)}); + } + + public void setFileManager(FileManager fileManager) { + this.fileManager = fileManager; + } +}
