Update of /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder In directory sc8-pr-cvs1:/tmp/cvs-serv25543/src/com/babeldoc/gui/pipeline/builder Modified Files: AddPipelineAction.java AddPipelineStageAction.java AddPipelineStageConfigAction.java PipelineBuilderController.java PipelineBuilderModel.java PipelineBuilderPanel.java PipelineTree.java RemovePipelineAction.java RemovePipelineStageAction.java Added Files: PipelineTreeCellRenderer.java Log Message: Couple of fixes here. more sensible adding / removing from tree (doesnt repaint) and added different images for entry stages, etc. --- NEW FILE: PipelineTreeCellRenderer.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use 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 * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * 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 THE APACHE SOFTWARE FOUNDATION 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 Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/PipelineTreeCellRenderer.java,v 1.1 2003/09/09 21:50:50 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ package com.babeldoc.gui.pipeline.builder; import com.babeldoc.gui.pipeline.builder.PipelineTreeNode; import com.babeldoc.core.ResourceLoader; import com.babeldoc.core.LogService; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.*; import java.awt.*; import java.io.IOException; /** * Displays the * */ public class PipelineTreeCellRenderer extends DefaultTreeCellRenderer { private ImageIcon pipelineIcon; private ImageIcon stageIcon; private ImageIcon entryIcon; public static final String ORANGE_BALL = "images/orangeball.gif"; private static final String GREEN_BALL = "images/greenball.gif"; public PipelineTreeCellRenderer() { } public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); PipelineTreeNode node = getPipelineTreeNode(value); if(node!=null) { if(node.isStage()&&node.isEntryStage()) { setIcon(getEntryIcon()); } else if(node.isStage()) { setIcon(getStageIcon()); } } return this; } protected PipelineTreeNode getPipelineTreeNode(Object value) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if(node.getUserObject() instanceof PipelineTreeNode) { return (PipelineTreeNode) (node.getUserObject()); } return null; } public ImageIcon getPipelineIcon() { return pipelineIcon; } /** * Get non-entry stage icons * * @return */ public ImageIcon getStageIcon() { if(stageIcon==null) { byte [] bytes = null; try { bytes = ResourceLoader.getResourceBytes(ORANGE_BALL); } catch (IOException e) { LogService.getInstance().logError(e); } stageIcon = new ImageIcon(bytes); } return stageIcon; } /** * Get the entry stage icon * * @return */ public ImageIcon getEntryIcon() { if(entryIcon==null) { byte [] bytes = null; try { bytes = ResourceLoader.getResourceBytes(GREEN_BALL); } catch (IOException e) { LogService.getInstance().logError(e); } entryIcon = new ImageIcon(bytes); } return entryIcon; } } Index: AddPipelineAction.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/AddPipelineAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AddPipelineAction.java 26 Aug 2003 22:23:32 -0000 1.5 --- AddPipelineAction.java 9 Sep 2003 21:50:50 -0000 1.6 *************** *** 89,95 **** /** ! * TODO: DOCUMENT ME! * ! * @param e DOCUMENT ME! */ public void actionPerformed(ActionEvent e) { --- 89,95 ---- /** ! * Handle the add pipeline action * ! * @param e The action event */ public void actionPerformed(ActionEvent e) { *************** *** 104,108 **** try { PipelineBuilderModel.createNewPipeline(s, "simple"); ! getFrame().renderTree(); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", --- 104,109 ---- try { PipelineBuilderModel.createNewPipeline(s, "simple"); ! getFrame().getTree().addPipeline(s); ! // getFrame().renderTree(); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", Index: AddPipelineStageAction.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/AddPipelineStageAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AddPipelineStageAction.java 26 Aug 2003 22:23:32 -0000 1.5 --- AddPipelineStageAction.java 9 Sep 2003 21:50:50 -0000 1.6 *************** *** 68,71 **** --- 68,72 ---- import com.babeldoc.gui.wizard.addstage.AddPipelineStageWizard; + import javax.swing.tree.TreeNode; import java.awt.event.ActionEvent; *************** *** 76,80 **** public class AddPipelineStageAction extends BuilderAction { public static final String ACTION_ADD_STAGE = "Add pipeline stage..."; ! PipelineTreeNode treenode; /** --- 77,83 ---- public class AddPipelineStageAction extends BuilderAction { public static final String ACTION_ADD_STAGE = "Add pipeline stage..."; ! ! /** The tree node to operate on */ ! private PipelineTreeNode treenode; /** *************** *** 98,103 **** */ public void actionPerformed(ActionEvent e) { ! AddPipelineStageWizard.run(treenode.toString()); ! getFrame().renderTree(); } } --- 101,110 ---- */ public void actionPerformed(ActionEvent e) { ! String stage = AddPipelineStageWizard.run(treenode.toString()).getModel().getStage(); ! ! if(stage!=null) { ! TreeNode pipeNode = getFrame().getTree().getTreeNodeForPipeline(treenode.toString()); ! getFrame().getTree().addPipelineStage(pipeNode, stage); ! } } } Index: AddPipelineStageConfigAction.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/AddPipelineStageConfigAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AddPipelineStageConfigAction.java 26 Aug 2003 22:23:32 -0000 1.3 --- AddPipelineStageConfigAction.java 9 Sep 2003 21:50:50 -0000 1.4 *************** *** 116,121 **** String key = config.substring(0, index); String value = config.substring(index + 1); ! Properties props = PipelineBuilderModel.getPipelineStageProperties(pipeline, ! stage); props.setProperty(key, value); PipelineBuilderModel.setPipelineStageProperties(pipeline, stage, props); --- 116,120 ---- String key = config.substring(0, index); String value = config.substring(index + 1); ! Properties props = PipelineBuilderModel.getPipelineStageProperties(pipeline, stage); props.setProperty(key, value); PipelineBuilderModel.setPipelineStageProperties(pipeline, stage, props); Index: PipelineBuilderController.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/PipelineBuilderController.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PipelineBuilderController.java 26 Aug 2003 22:23:32 -0000 1.4 --- PipelineBuilderController.java 9 Sep 2003 21:50:50 -0000 1.5 *************** *** 66,74 **** package com.babeldoc.gui.pipeline.builder; - import com.babeldoc.core.pipeline.PipelineException; - import java.awt.event.ActionEvent; - import javax.swing.event.ListSelectionEvent; import javax.swing.event.TreeSelectionEvent; --- 66,71 ---- *************** *** 110,114 **** /** ! * TODO: DOCUMENT ME! * * @return DOCUMENT ME! --- 107,111 ---- /** ! * Get the model * * @return DOCUMENT ME! *************** *** 172,175 **** --- 169,173 ---- private String name; private int nodeType; + private boolean entryStage; /** *************** *** 251,254 **** --- 249,260 ---- public String toString() { return name; + } + + public boolean isEntryStage() { + return entryStage; + } + + public void setEntryStage(boolean entryStage) { + this.entryStage = entryStage; } } Index: PipelineBuilderModel.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/PipelineBuilderModel.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PipelineBuilderModel.java 26 Aug 2003 22:23:32 -0000 1.8 --- PipelineBuilderModel.java 9 Sep 2003 21:50:50 -0000 1.9 *************** *** 78,81 **** --- 78,86 ---- /** + * Pipeline builder model contains all the methods necessary to drive the pipeline builder + * applet. + * + * @author bmcdonald + * @version 1.1 */ public class PipelineBuilderModel { *************** *** 106,110 **** public static String[] getAllPipelineNames() { String configName = PIPELINE_CONFIG_NAME; ! ArrayList pipes = new ArrayList(); IConfig config = ConfigService.getInstance().getConfig(configName); --- 111,115 ---- public static String[] getAllPipelineNames() { String configName = PIPELINE_CONFIG_NAME; ! List pipes = new ArrayList(); IConfig config = ConfigService.getInstance().getConfig(configName); *************** *** 143,147 **** */ public static String[] getAllPipelineStages(String pipeline) { ! ArrayList stages = new ArrayList(); IConfig config = getPipelineConfiguration(pipeline); --- 148,152 ---- */ public static String[] getAllPipelineStages(String pipeline) { ! List stages = new ArrayList(); IConfig config = getPipelineConfiguration(pipeline); *************** *** 157,161 **** } ! return (String[]) stages.toArray((new String[stages.size()])); } else { return null; --- 162,167 ---- } ! return sortPipelineStageNames(pipeline, stages); ! //return (String[]) stages.toArray((new String[stages.size()])); } else { return null; *************** *** 164,167 **** --- 170,246 ---- /** + * Get a sorted list of pipeline stages. Here are the rules: + * 1. A stage which is the entry stage is always the first in the + * list. + * 2. A stage which is has as its nextStage another stage, that nextStage + * is considered greater than this stage. + * + * @param names + * @return + */ + public static String[] sortPipelineStageNames(final String pipeline, List names) { + // System.out.println("Sorting: "+pipeline+" which has: "+names.size()+" stages."); + + final String entryStage = PipelineBuilderModel.getPipelineEntryStage(pipeline); + // System.out.println("Entry stage: "+entryStage); + + // if(names==null||names.size()==0) { + // System.out.println("Doing comparison"); + + Comparator comp = new Comparator() { + public int compare(Object o1, Object o2) { + int comp = 0; + if(o1.equals(o2)) { + comp = 0; + } else { + String lhs = (String)o1; + String rhs = (String)o2; + + if(lhs.equals(entryStage)) { + comp = -1; + } else if(rhs.equals(entryStage)){ + comp = 1; + } else { + if(isStageDownStream(pipeline, lhs, rhs)) { + comp = -1; + } else if(isStageDownStream(pipeline, rhs, lhs)) { + comp = 1; + } + } + } + + // System.out.println("Comparing: "+o1+" and "+o2+" - result is: "+comp); + return comp; + } + }; + Collections.sort(names, comp); + // return names; + return (String[]) names.toArray((new String[names.size()])); + // } + // return null; + } + + /** + * This method answers the question if the rhs stage is downstream (ie in any + * of the nextStages (or their next stages) of the lhs stage + * + * @param lhs left hand stage + * @param rhs right hand stage + * @return true if rhs is downstream of lhs + */ + public static boolean isStageDownStream(String pipeline, String lhs, String rhs) { + if(lhs==null||lhs.equals("null")) { + return false; + } else if (lhs.equals(rhs)) { + return true; + } else { + Properties lhsProps = getPipelineStageProperties(pipeline, lhs); + String lhsNext = lhsProps.getProperty("nextStage"); + + return isStageDownStream(pipeline, lhsNext, rhs); + } + } + + /** * Get all the pipeline names in the system. This calls the factory methods * to get the data *************** *** 268,272 **** /** ! * DOCUMENT ME! * * @param pipeline --- 347,351 ---- /** ! * This sets the properteis for the pipeline stage. * * @param pipeline *************** *** 318,323 **** * @return */ ! public static Properties getPipelineStageProperties(String pipeline, ! String stage) { Properties properties = new Properties(); String stageDot = stage + DOT; --- 397,401 ---- * @return */ ! public static Properties getPipelineStageProperties(String pipeline, String stage) { Properties properties = new Properties(); String stageDot = stage + DOT; *************** *** 327,339 **** String key = (String) i.next(); - // System.out.print("lets look:"+key); if (key.startsWith(stageDot)) { String value = config.getString(key); key = key.substring(stageDot.length()); properties.put(key, value); - - // System.out.println(" - Found:"+key+"="+value); - } else { - // System.out.println(); } } --- 405,412 ---- *************** *** 459,463 **** /** ! * TODO: DOCUMENT ME! * * @param args DOCUMENT ME! --- 532,536 ---- /** ! * Just do some rundimentary testing. * * @param args DOCUMENT ME! Index: PipelineBuilderPanel.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/PipelineBuilderPanel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PipelineBuilderPanel.java 26 Aug 2003 22:23:32 -0000 1.1 --- PipelineBuilderPanel.java 9 Sep 2003 21:50:50 -0000 1.2 *************** *** 72,78 **** import java.awt.event.MouseEvent; - import java.util.Iterator; - import java.util.Properties; - import javax.swing.*; import javax.swing.event.TreeModelEvent; --- 72,75 ---- *************** *** 92,95 **** --- 89,94 ---- public static final String ACTION_REMOVE_CONFIG = "remove config"; public static final String ACTION_SET_ENTRY_STAGE = "set entry stage"; + + /** the controller */ private PipelineBuilderController controller = null; private PipelineTree tree; *************** *** 110,114 **** getTree().setPreferredSize(new Dimension(640, 480)); ! getTree().setEditable(true); getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); getTree().setShowsRootHandles(true); --- 109,113 ---- getTree().setPreferredSize(new Dimension(640, 480)); ! getTree().setEditable(false); getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); getTree().setShowsRootHandles(true); *************** *** 133,137 **** /** ! * TODO: DOCUMENT ME! * * @return DOCUMENT ME! --- 132,136 ---- /** ! * Get the controller * * @return DOCUMENT ME! *************** *** 142,146 **** /** ! * TODO: DOCUMENT ME! * * @return DOCUMENT ME! --- 141,145 ---- /** ! * Get the tree * * @return DOCUMENT ME! *************** *** 151,155 **** /** ! * TODO: DOCUMENT ME! * * @param e DOCUMENT ME! --- 150,154 ---- /** ! * Handle actions * * @param e DOCUMENT ME! *************** *** 159,163 **** /** ! * TODO: DOCUMENT ME! */ public void renderTree() { --- 158,163 ---- /** ! * Render the pipeline tree ! * */ public void renderTree() { *************** *** 167,190 **** for (int i = 0; i < pipes.length; ++i) { DefaultMutableTreeNode pipenode = getTree().addObject(null, ! PipelineTreeNode.pipelineNode(pipes[i])); String[] stages = new String[0]; ! stages = getController().getModel().getAllPipelineStages(pipes[i]); if(stages!=null) { for (int j = 0; j < stages.length; ++j) { ! DefaultMutableTreeNode stagenode = getTree().addObject(pipenode, ! PipelineTreeNode.stageNode(stages[j])); ! Properties properties = getController().getModel() ! .getPipelineStageProperties(pipes[i], ! stages[j]); ! ! for (Iterator k = properties.keySet().iterator(); k.hasNext();) { ! String config = (String) k.next(); ! String value = properties.getProperty(config); ! DefaultMutableTreeNode confignode = getTree().addObject(stagenode, ! PipelineTreeNode.configNode(config + "=" + value)); ! } } } --- 167,184 ---- for (int i = 0; i < pipes.length; ++i) { + String pipe = pipes[i]; DefaultMutableTreeNode pipenode = getTree().addObject(null, ! PipelineTreeNode.pipelineNode(pipe)); String[] stages = new String[0]; ! stages = getController().getModel().getAllPipelineStages(pipe); ! String entry = getController().getModel().getPipelineEntryStage(pipe); ! if(stages!=null) { for (int j = 0; j < stages.length; ++j) { ! PipelineTreeNode treeNode = PipelineTreeNode.stageNode(stages[j]); ! treeNode.setEntryStage(stages[j].equals(entry)); ! getTree().addObject(pipenode, treeNode); } } *************** *** 220,231 **** popup.add(new RemovePipelineStageAction(getController().getModel(), this, parentNode, currentNode)); ! popup.add(new AddPipelineStageConfigAction(getController().getModel(), ! this, parentNode, currentNode)); menuItem = new JMenuItem(ACTION_SET_ENTRY_STAGE); popup.add(menuItem); ! } else if (currentNode.isConfig()) { ! menuItem = new JMenuItem(ACTION_REMOVE_CONFIG); ! menuItem.addActionListener(this); ! popup.add(menuItem); } } --- 214,225 ---- popup.add(new RemovePipelineStageAction(getController().getModel(), this, parentNode, currentNode)); ! // popup.add(new AddPipelineStageConfigAction(getController().getModel(), ! // this, parentNode, currentNode)); menuItem = new JMenuItem(ACTION_SET_ENTRY_STAGE); popup.add(menuItem); ! // } else if (currentNode.isConfig()) { ! // menuItem = new JMenuItem(ACTION_REMOVE_CONFIG); ! // menuItem.addActionListener(this); ! // popup.add(menuItem); } } *************** *** 236,240 **** /** ! * TODO: DOCUMENT ME! * * @author $author$ --- 230,234 ---- /** ! * The tree model listener * * @author $author$ *************** *** 243,247 **** class MyTreeModelListener implements TreeModelListener { /** ! * TODO: DOCUMENT ME! * * @param e DOCUMENT ME! --- 237,241 ---- class MyTreeModelListener implements TreeModelListener { /** ! * Called when tree nodes have been changed * * @param e DOCUMENT ME! *************** *** 268,272 **** /** ! * TODO: DOCUMENT ME! * * @param e DOCUMENT ME! --- 262,266 ---- /** ! * When tree nodes have been inserted * * @param e DOCUMENT ME! *************** *** 276,280 **** /** ! * TODO: DOCUMENT ME! * * @param e DOCUMENT ME! --- 270,274 ---- /** ! * When tree nodes have been removed * * @param e DOCUMENT ME! *************** *** 284,288 **** /** ! * TODO: DOCUMENT ME! * * @param e DOCUMENT ME! --- 278,282 ---- /** ! * When the tree structure has been changed * * @param e DOCUMENT ME! Index: PipelineTree.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/PipelineTree.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PipelineTree.java 11 Jun 2003 23:35:38 -0000 1.2 --- PipelineTree.java 9 Sep 2003 21:50:50 -0000 1.3 *************** *** 66,83 **** package com.babeldoc.gui.pipeline.builder; import java.awt.*; import javax.swing.*; ! import javax.swing.tree.DefaultMutableTreeNode; ! import javax.swing.tree.DefaultTreeModel; ! import javax.swing.tree.MutableTreeNode; ! import javax.swing.tree.TreePath; /** ! * TODO: DOCUMENT ME! * ! * @author $author$ ! * @version $Revision$ */ public class PipelineTree extends JTree { --- 66,83 ---- package com.babeldoc.gui.pipeline.builder; + import com.babeldoc.gui.pipeline.builder.PipelineTreeNode; + import java.awt.*; import javax.swing.*; ! import javax.swing.tree.*; /** ! * The pipeline tree is the Swing component that displays ! * all the pipeline information in a tree gui component. * ! * @author bmcdonald ! * @version 1.1 */ public class PipelineTree extends JTree { *************** *** 92,95 **** --- 92,96 ---- setPipelineRootNode(new DefaultMutableTreeNode("Pipelines")); setPipelineTreeModel(new DefaultTreeModel(getPipelineRootNode())); + this.setCellRenderer(new PipelineTreeCellRenderer()); } *************** *** 113,117 **** /** ! * TODO: DOCUMENT ME! * * @param pipelineRootNode DOCUMENT ME! --- 114,118 ---- /** ! * Set the pipeline tree root node * * @param pipelineRootNode DOCUMENT ME! *************** *** 122,126 **** /** ! * TODO: DOCUMENT ME! * * @return DOCUMENT ME! --- 123,127 ---- /** ! * Get the pipeline tree root node * * @return DOCUMENT ME! *************** *** 131,135 **** /** ! * TODO: DOCUMENT ME! * * @param pipelineTreeModel DOCUMENT ME! --- 132,136 ---- /** ! * Set the pipeline tree model for this tree component * * @param pipelineTreeModel DOCUMENT ME! *************** *** 141,147 **** /** ! * TODO: DOCUMENT ME! * ! * @return DOCUMENT ME! */ public DefaultTreeModel getPipelineTreeModel() { --- 142,148 ---- /** ! * Get the pipeline tree model. * ! * @return the model */ public DefaultTreeModel getPipelineTreeModel() { *************** *** 150,153 **** --- 151,263 ---- /** + * Add a pipeline to the tree + * + * @param pipe + * @return + */ + public TreeNode addPipeline(String pipe) { + return addObject(null, PipelineTreeNode.pipelineNode(pipe)); + } + + /** + * Remove a pipeline from the tree of pipelines. Sorry about the + * code quality - searching for matching pipeline seems to be the only way to get + * to the correct node in the tree. + * + * I suggest that we move to a cache where we keep track of the + * @param pipe + * @return + */ + public TreeNode removePipeline(String pipe) { + TreeNode treeNode = getTreeNodeForPipeline(pipe); + if(treeNode!=null) { + getPipelineTreeModel().removeNodeFromParent((MutableTreeNode)treeNode); + } + return treeNode; + } + + /** + * Add a pipeline stage to a pipiline node + * + * @param pipeNode + * @param stage + * @return + */ + public TreeNode addPipelineStage(TreeNode pipeNode, String stage) { + if(pipeNode!=null) { + return addObject((DefaultMutableTreeNode)pipeNode, PipelineTreeNode.stageNode(stage)); + } + return null; + } + + /** + * Remove the pipeline stage node from the tree + * + * @param pipeNode + * @param stage + * @return + */ + public TreeNode removePipelineStage(TreeNode pipeNode, String stage) { + if(pipeNode!=null) { + TreeNode stageNode = getTreeNodeForPipelineStage(pipeNode, stage); + getPipelineTreeModel().removeNodeFromParent((MutableTreeNode)stageNode); + } + return null; + } + + /** + * Set this node to be the entry node or not depending on the state + * of the flag argument. + * + * @param stageNode + * @param flag + * @return + */ + public TreeNode setEntryStage(TreeNode stageNode, boolean flag) { + if(stageNode!=null) { + Object o = ((DefaultMutableTreeNode)stageNode).getUserObject(); + PipelineTreeNode node = (PipelineTreeNode)o; + node.setEntryStage(flag); + } + return stageNode; + } + + /** + * Get the tree node which corresponds to the pipeline name + * + * @param pipe pipeline name + * @return tree node + */ + public TreeNode getTreeNodeForPipeline(String pipe) { + DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)getPipelineTreeModel().getRoot(); + for(int i = 0; i < rootNode.getChildCount(); ++i) { + TreeNode treeNode = rootNode.getChildAt(i); + if(pipe.equals(treeNode.toString())) { + return treeNode; + } + } + return null; + } + + /** + * Get the pipeline stage tree node node for the pipeline stage. + * + * @param pipeNode + * @param stage + * @return + */ + public TreeNode getTreeNodeForPipelineStage(TreeNode pipeNode, String stage) { + if(pipeNode!=null) { + for(int i = 0; i < pipeNode.getChildCount(); ++i) { + TreeNode treeNode = pipeNode.getChildAt(i); + if(stage.equals(treeNode.toString())) { + return treeNode; + } + } + } + return null; + } + + /** * Add child to the currently selected node. * *************** *** 156,160 **** * @return DOCUMENT ME! */ ! public DefaultMutableTreeNode addObject(Object child) { DefaultMutableTreeNode parentNode = getCurrentlySelectedNode(); --- 266,270 ---- * @return DOCUMENT ME! */ ! protected DefaultMutableTreeNode addObject(Object child) { DefaultMutableTreeNode parentNode = getCurrentlySelectedNode(); *************** *** 163,189 **** /** ! * TODO: DOCUMENT ME! * ! * @param parent DOCUMENT ME! ! * @param child DOCUMENT ME! * ! * @return DOCUMENT ME! */ ! public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, ! Object child) { return addObject(parent, child, false); } /** ! * TODO: DOCUMENT ME! * ! * @param parent DOCUMENT ME! ! * @param child DOCUMENT ME! * @param shouldBeVisible DOCUMENT ME! * * @return DOCUMENT ME! */ ! public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, ! Object child, boolean shouldBeVisible) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); --- 273,298 ---- /** ! * Add a node to the tree * ! * @param parent The tree object ! * @param child the parent object * ! * @return The tree node */ ! protected DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child) { return addObject(parent, child, false); } /** ! * Add a node to the tree * ! * @param parent The parent object ! * @param child The child object (to add) * @param shouldBeVisible DOCUMENT ME! * * @return DOCUMENT ME! */ ! protected DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, ! Object child, boolean shouldBeVisible) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); Index: RemovePipelineAction.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/RemovePipelineAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RemovePipelineAction.java 26 Aug 2003 22:23:32 -0000 1.5 --- RemovePipelineAction.java 9 Sep 2003 21:50:50 -0000 1.6 *************** *** 81,87 **** * Creates a new RemovePipelineAction object. * ! * @param model DOCUMENT ME! ! * @param frame DOCUMENT ME! ! * @param treenode DOCUMENT ME! */ public RemovePipelineAction(PipelineBuilderModel model, --- 81,87 ---- * Creates a new RemovePipelineAction object. * ! * @param model ! * @param frame ! * @param treenode */ public RemovePipelineAction(PipelineBuilderModel model, *************** *** 92,98 **** /** ! * TODO: DOCUMENT ME! * ! * @param e DOCUMENT ME! */ public void actionPerformed(ActionEvent e) { --- 92,98 ---- /** ! * Remove the pipeline from the configurations * ! * @param e Action event */ public void actionPerformed(ActionEvent e) { *************** *** 104,108 **** try { PipelineBuilderModel.deletePipeline(treenode.toString()); ! getFrame().renderTree(); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", --- 104,108 ---- try { PipelineBuilderModel.deletePipeline(treenode.toString()); ! getFrame().getTree().removePipeline(treenode.toString()); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", Index: RemovePipelineStageAction.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/pipeline/builder/RemovePipelineStageAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RemovePipelineStageAction.java 26 Aug 2003 22:23:32 -0000 1.3 --- RemovePipelineStageAction.java 9 Sep 2003 21:50:50 -0000 1.4 *************** *** 69,72 **** --- 69,73 ---- import javax.swing.*; + import javax.swing.tree.TreeNode; *************** *** 109,113 **** try { PipelineBuilderModel.deletePipelineStage(pipeline, stage); ! getFrame().renderTree(); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", --- 110,115 ---- try { PipelineBuilderModel.deletePipelineStage(pipeline, stage); ! TreeNode pipeNode = getFrame().getTree().getTreeNodeForPipeline(pipeline); ! getFrame().getTree().removePipelineStage(pipeNode, stage); } catch (Exception x) { JOptionPane.showMessageDialog(getFrame(), x.toString(), "Exception", |