/* * The University of Wales, Cardiff Triana Project Software License (Based * on the Apache Software License Version 1.1) * * Copyright (c) 2003 University of Wales, Cardiff. All rights reserved. * * Redistribution and use of the software in source and binary forms, with * or without modification, are permitted provided that the following * conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, * must include the following acknowledgment: "This product includes * software developed by the University of Wales, Cardiff for the Triana * Project (http://www.trianacode.org)." Alternately, this * acknowledgment may appear in the software itself, if and wherever * such third-party acknowledgments normally appear. * * 4. The names "Triana" and "University of Wales, Cardiff" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact triana@trianacode.org. * * 5. Products derived from this software may not be called "Triana," nor * may Triana appear in their name, without prior written permission of * the University of Wales, Cardiff. * * 6. This software may not be sold, used or incorporated into any product * for sale to third parties. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL UNIVERSITY OF WALES, CARDIFF OR ITS CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * * ------------------------------------------------------------------------ * * This software consists of voluntary contributions made by many * individuals on behalf of the Triana Project. For more information on the * Triana Project, please see. http://www.trianacode.org. * * This license is based on the BSD license as adopted by the Apache * Foundation and is governed by the laws of England and Wales. */ package examples; import triana.gui.action.ActionDisplayOptions; import triana.gui.hci.GUIEnv; import triana.taskgraph.*; import triana.util.ToolTable; import javax.swing.*; import java.awt.*; import java.awt.geom.Point2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * Action to to display simple wizard * * @author Ian Wang * @version $Revision: 295 $ * @created 22nd March 2006 * @date $Date: 2007-02-07 15:38:22 +0000 (Wed, 07 Feb 2007) $ modified by $Author: spxmss $ */ public class ExampleWizardAction extends AbstractAction implements ActionDisplayOptions { public ExampleWizardAction() { putValue(SHORT_DESCRIPTION, "Example wizard for creating two unit workflow"); putValue(ACTION_COMMAND_KEY, "Example Wizard"); putValue(NAME, "Example Wizard"); } /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExampleWizardFrame window = new ExampleWizardFrame(); if (window.isAccepted()) try { createWorkflow(window.getInputTool(), window.getOutputTool()); } catch (TaskException e1) { e1.printStackTrace(); } catch (CableException e1) { e1.printStackTrace(); } } /** * Creates a workflow connecting the input tool to the output tool. Based on code contained in * the workflow wizard tutorial. */ private void createWorkflow(String inputtool, String outputtool) throws TaskException, CableException { // error if input/output tool not specified if ((inputtool.equals("")) || (outputtool.equals(""))) { JOptionPane.showMessageDialog(null, "Input/Output tool not specified", "Example Wizard Error", JOptionPane.ERROR_MESSAGE, null); return; } // retrieve the main tool table ToolTable tooltable = TaskGraphManager.getToolTable(); // retrieve the input and output tools ToolInterface intool = tooltable.getTool(inputtool); ToolInterface outtool = tooltable.getTool(outputtool); // error if input tool not found if (intool == null) { JOptionPane.showMessageDialog(null, "Invalid tool: " + intool, "Example Wizard Error", JOptionPane.ERROR_MESSAGE, null); return; } // error if output tool not found if (outtool == null) { JOptionPane.showMessageDialog(null, "Invalid tool: " + outtool, "Example Wizard Error", JOptionPane.ERROR_MESSAGE, null); return; } // create an empty workflow TaskGraph taskgraph = TaskGraphManager.createTaskGraph(); // create input and output tasks in the workflow TaskInterface intask = taskgraph.createTask(intool); TaskInterface outtask = taskgraph.createTask(outtool); // retrieve the output node from the input task, and the input node to the output task NodeInterface outnode = intask.getDataOutputNode(0); NodeInterface innode = outtask.getDataInputNode(0); // error in invalid innode if (innode == null) { JOptionPane.showMessageDialog(null, "Input tool does not have output node: " + intool, "Example Wizard Error", JOptionPane.ERROR_MESSAGE, null); return; } // error in invalid outnode if (outnode == null) { JOptionPane.showMessageDialog(null, "Output tool does not have input node: " + intool, "Example Wizard Error", JOptionPane.ERROR_MESSAGE, null); return; } // connect the outnode to the innode taskgraph.connect(outnode, innode); // set location of tasks (intask at x=0.5, y=0.5, outtask at x=1.5, y=0.6) TaskLayoutUtils.setPosition(intask, new Point.Double(0.5, 0.5)); TaskLayoutUtils.setPosition(outtask, new Point.Double(1.5, 0.5)); // display workflow GUIEnv.getApplicationFrame().addParentTaskGraphPanel(taskgraph); } private class ExampleWizardFrame extends JDialog { private JTextField intool = new JTextField(25); private JTextField outtool = new JTextField(25); private boolean accept; public ExampleWizardFrame() { super(GUIEnv.getApplicationFrame(), "Example Wizard", true); initLayout(); pack(); setLocationRelativeTo(null); setVisible(true); } /** * Create simple layout with two input text fields plus * o.k. and cancel buttons */ private void initLayout() { JPanel mainpanel = new JPanel(new BorderLayout(3, 3)); mainpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); JPanel labelpanel = new JPanel(new GridLayout(2, 1, 0, 3)); labelpanel.add(new JLabel("Input Tool")); labelpanel.add(new JLabel("Output Tool")); JPanel fieldpanel = new JPanel(new GridLayout(2, 1, 0, 3)); fieldpanel.add(intool); fieldpanel.add(outtool); JButton ok = new JButton("OK"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accept = true; setVisible(false); dispose(); } }); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accept = false; setVisible(false); dispose(); } }); JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonpanel.add(ok); buttonpanel.add(cancel); mainpanel.add(labelpanel, BorderLayout.WEST); mainpanel.add(fieldpanel, BorderLayout.CENTER); mainpanel.add(buttonpanel, BorderLayout.SOUTH); getContentPane().add(mainpanel); } /** * @return true if the wizard is accepted (o.k. pressed) */ public boolean isAccepted() { return accept; } /** * @return the name of the input tool */ public String getInputTool() { return intool.getText(); } /** * @return the name of the output tool */ public String getOutputTool() { return outtool.getText(); } } }