Update of /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/journal/browser
In directory sc8-pr-cvs1:/tmp/cvs-serv8166/modules/gui/src/com/babeldoc/gui/journal/browser
Modified Files:
JournalBrowserModel.java JournalBrowserFrame.java
JournalTree.java Command.java
Log Message:
Added support for replaying a step and viewing a document at a step
Index: JournalBrowserModel.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/journal/browser/JournalBrowserModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** JournalBrowserModel.java 11 Jun 2003 23:35:38 -0000 1.2
--- JournalBrowserModel.java 6 Sep 2003 00:58:45 -0000 1.3
***************
*** 85,88 ****
--- 85,97 ----
/**
+ * Returns the Journal for this JournalBrowserModel
+ * @return Journal the journal for this JournalBrowserModel
+ */
+ public IJournal getJournal() {
+ return JournalFactory.getJournal();
+ }
+
+
+ /**
* DOCUMENT ME!
*
***************
*** 93,97 ****
public QueryTicket[] getTicketSteps(IJournalTicket ticket) {
try {
! return JournalFactory.getJournal().getAllTicketSteps(ticket);
} catch (Exception e) {
e.printStackTrace();
--- 102,106 ----
public QueryTicket[] getTicketSteps(IJournalTicket ticket) {
try {
! return getJournal().getAllTicketSteps(ticket);
} catch (Exception e) {
e.printStackTrace();
Index: JournalBrowserFrame.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/journal/browser/JournalBrowserFrame.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** JournalBrowserFrame.java 25 Aug 2003 14:13:14 -0000 1.4
--- JournalBrowserFrame.java 6 Sep 2003 00:58:45 -0000 1.5
***************
*** 70,74 ****
--- 70,77 ----
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+ import java.util.Iterator;
+ import java.util.Set;
+ import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
***************
*** 78,84 ****
--- 81,91 ----
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
+ import javax.swing.JTextArea;
import javax.swing.JTree;
+ import javax.swing.ScrollPaneConstants;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
+ import javax.swing.event.TreeSelectionEvent;
+ import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
***************
*** 86,97 ****
import com.babeldoc.core.config.ConfigService;
/**
* This is the main window to the the JournalBrowser
*/
! public class JournalBrowserFrame extends JFrame {
private JournalBrowserModel model;
private JournalTree tree;
private String version = ConfigService.getString("env/build", "babeldoc_version");
private String TITLE_MESSAGE = "JournalBrowser v" + version;
--- 93,114 ----
import com.babeldoc.core.config.ConfigService;
+ import com.babeldoc.core.journal.IJournal;
+ import com.babeldoc.core.journal.JournalException;
+ import com.babeldoc.core.journal.JournalOperation;
+ import com.babeldoc.core.pipeline.PipelineDocument;
/**
* This is the main window to the the JournalBrowser
*/
! public class JournalBrowserFrame extends JFrame implements TreeSelectionListener {
private JournalBrowserModel model;
private JournalTree tree;
+ private JMenuItem jMenuEditReplay; // will enable/disable these menu options
+ private JMenuItem jMenuEditShowDocument;
+
+ private int journalStart = 0;
+ private int journalCount = 100;
+
private String version = ConfigService.getString("env/build", "babeldoc_version");
private String TITLE_MESSAGE = "JournalBrowser v" + version;
***************
*** 109,130 ****
// Link the controller to this frame.
! tree = new JournalTree(this.model);
!
! getTree().getModel().addTreeModelListener(new MyTreeModelListener());
!
! getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
! getTree().setShowsRootHandles(false);
! getTree().putClientProperty("JTree.lineStyle", "Angled");
! getTree().addMouseListener(new MouseAdapter() {
! public void mousePressed(MouseEvent e) {
! TreePath selPath = getTree().getPathForLocation(e.getX(), e.getY());
! getTree().setSelectionPath(selPath);
! maybeShowPopup(e);
! }
!
! public void mouseReleased(MouseEvent e) {
! maybeShowPopup(e);
! }
! });
// build the menu options
--- 126,130 ----
// Link the controller to this frame.
! tree = initializeTree(this.model);
// build the menu options
***************
*** 149,152 ****
--- 149,163 ----
jMenuBar.add(jMenuFile);
+ // File | Reload
+ JMenuItem jMenuFileReload = new JMenuItem("Reload");
+ jMenuFileReload.setMnemonic('R');
+ jMenuFileReload.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ tree = initializeTree(model);
+ tree.populateTree(journalStart, journalCount);
+ }
+ });
+ jMenuFile.add(jMenuFileReload);
+
// File | Exit
JMenuItem jMenuFileExit = new JMenuItem("Exit");
***************
*** 164,181 ****
jMenuBar.add(jMenuEdit);
! // Edit | Replay
! JMenuItem jMenuEditReplay = new JMenuItem("Replay");
jMenuEditReplay.setMnemonic('R');
! jMenuEditReplay.addActionListener(new ActionListener() {
! public void actionPerformed(ActionEvent e) {
! JOptionPane.showMessageDialog(
! null,
! COMING_SOON_MESSAGE,
! "Coming Soon!",
! JOptionPane.PLAIN_MESSAGE);
! }
! });
jMenuEdit.add(jMenuEditReplay);
// ====== View menu items ======
JMenu jMenuView = new JMenu("View");
--- 175,192 ----
jMenuBar.add(jMenuEdit);
! // Edit | Replay (this one is declared above so it can be enabled/disabled
! jMenuEditReplay = new JMenuItem("Replay");
jMenuEditReplay.setMnemonic('R');
! jMenuEditReplay.addActionListener(new ReplayActionListener());
! jMenuEditReplay.setEnabled(false); // default to disabled
jMenuEdit.add(jMenuEditReplay);
+ // Edit | Show Document (this one is declared above so it can be enabled/disabled
+ jMenuEditShowDocument = new JMenuItem("Show Document");
+ jMenuEditShowDocument.setMnemonic('S');
+ jMenuEditShowDocument.addActionListener(new ShowDocumentActionListener());
+ jMenuEditShowDocument.setEnabled(false); // default to disabled
+ jMenuEdit.add(jMenuEditShowDocument);
+
// ====== View menu items ======
JMenu jMenuView = new JMenu("View");
***************
*** 254,257 ****
--- 265,300 ----
/**
+ * Initialize the JournalBrowser tree
+ * @return The initialized JournalTree object
+ * @param model The JournalBrowserModel containing the journal tickets to display
+ */
+ protected JournalTree initializeTree(JournalBrowserModel model) {
+
+ // Link the controller to this frame.
+ JournalTree tree = new JournalTree(model);
+
+ tree.getModel().addTreeModelListener(new MyTreeModelListener());
+ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setShowsRootHandles(false);
+ tree.putClientProperty("JTree.lineStyle", "Angled");
+
+ // add listeners
+ tree.addTreeSelectionListener(this);
+ tree.addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ TreePath selPath = getTree().getPathForLocation(e.getX(), e.getY());
+ getTree().setSelectionPath(selPath);
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+ });
+
+ return tree;
+ }
+
+ /**
* DOCUMENT ME!
*
***************
*** 309,311 ****
--- 352,483 ----
}
}
+
+ /**
+ * @see javax.swing.event.TreeSelectionListener#valueChanged(TreeSelectionEvent)
+ */
+ public void valueChanged(TreeSelectionEvent e) {
+ // if a step has been selected that can be replayed, enable the
+ // replay menu option. Othewise, don't...
+ DefaultMutableTreeNode selectedNode =
+ (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
+
+ // sanity checks first
+ if (selectedNode != null) {
+ if (selectedNode.getUserObject() instanceof JournalTreeTicketStep) {
+ // if the operation is updateDocument, we can replay from this step
+ JournalTreeTicketStep step = (JournalTreeTicketStep)selectedNode.getUserObject();
+ boolean found = step.getQTicket().getOperation().equals(JournalOperation.updateDocument.toString());
+ if (found) {
+ jMenuEditReplay.setEnabled(true);
+ jMenuEditShowDocument.setEnabled(true);
+ }
+ else {
+ jMenuEditReplay.setEnabled(false);
+ jMenuEditShowDocument.setEnabled(false);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Implements the ActionListener that handles the REPLAY functionality
+ *
+ * @author David Glick
+ * @version $Revision$
+ */
+ class ReplayActionListener implements ActionListener {
+ public void actionPerformed(ActionEvent ae) {
+ // the tree listener ensures that only steps that can be replayed will
+ // enable the replay menu option. Just do it.
+ // Sanity checks first.
+ TreePath selectedTreePath = tree.getSelectionPath();
+ if (selectedTreePath != null) {
+ DefaultMutableTreeNode selectedNode =
+ (DefaultMutableTreeNode)selectedTreePath.getLastPathComponent();
+ if (selectedNode.getUserObject() instanceof JournalTreeTicketStep) {
+ JournalTreeTicketStep step = (JournalTreeTicketStep)selectedNode.getUserObject();
+ try {
+ model.getJournal().replayTicket(step.getQTicket().getTicket(),
+ step.getQTicket().getStep());
+ }
+ catch (JournalException e) {
+ // display error message
+ JOptionPane.showMessageDialog(
+ null,
+ "Error replaying journal:\n" + e.toString(),
+ "JournalBrowser Replay Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Implements the ActionListener that handles the SHOW DOCUMENT functionality
+ *
+ * @author David Glick
+ * @version $Revision$
+ */
+ class ShowDocumentActionListener implements ActionListener {
+ public void actionPerformed(ActionEvent ae) {
+ // the tree listener ensures that only steps that have documents will
+ // enable the menu option. Just do it.
+ // Sanity checks first.
+ TreePath selectedTreePath = tree.getSelectionPath();
+ if (selectedTreePath != null) {
+ DefaultMutableTreeNode selectedNode =
+ (DefaultMutableTreeNode)selectedTreePath.getLastPathComponent();
+ if (selectedNode.getUserObject() instanceof JournalTreeTicketStep) {
+ JournalTreeTicketStep step = (JournalTreeTicketStep)selectedNode.getUserObject();
+ try {
+ PipelineDocument doc = model.getJournal().getDocumentAtTicketStep(step.getQTicket().getTicket(),
+ step.getQTicket().getStep());
+
+ // create a JTextArea so we can use a JScrollPane to scroll if needed
+ JTextArea text = new JTextArea();
+ text.setLineWrap(true);
+ text.setWrapStyleWord(true);
+ text.setEditable(false);
+ text.setSize(600, 600);
+
+ // show the document
+ text.append("====== Document ======\n");
+ text.append(doc.toString());
+
+ // show the attributes
+ text.append("\n\n====== Attributes ======\n");
+ Set keyset = doc.getAttributes().keySet();
+ Iterator keyiter = keyset.iterator();
+ while(keyiter.hasNext()) {
+ String key = (String)keyiter.next();
+ Object cls = doc.get(key);
+ text.append(key + ": " + cls.toString() + "\n");
+ }
+
+ // wrap the JTextArea in the JScrollpane
+ JScrollPane sp = new JScrollPane(text, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+ ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+
+ // show the pane
+ JOptionPane.showMessageDialog(
+ null,
+ sp,
+ "JournalBrowser Show Document",
+ JOptionPane.PLAIN_MESSAGE);
+ }
+ catch (JournalException e) {
+ // display error message
+ JOptionPane.showMessageDialog(
+ null,
+ "Error replaying journal:\n" + e.toString(),
+ "JournalBrowser Replay Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ }
+ }
+
}
Index: JournalTree.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/journal/browser/JournalTree.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JournalTree.java 19 Aug 2003 05:11:38 -0000 1.3
--- JournalTree.java 6 Sep 2003 00:58:45 -0000 1.4
***************
*** 66,69 ****
--- 66,70 ----
package com.babeldoc.gui.journal.browser;
+ import com.babeldoc.core.journal.JournalOperation;
import com.babeldoc.core.journal.query.QueryTicket;
***************
*** 71,74 ****
--- 72,76 ----
import java.awt.Dimension;
import java.awt.Font;
+ import java.util.Enumeration;
import javax.swing.*;
***************
*** 107,119 ****
/**
! * Populate the tree (duh!)
*/
private void populateTree() {
! QueryTicket[] qts = this.browserModel.getTickets(0, 100);
if (qts != null) {
for (int i = 0; i < qts.length; ++i) {
JournalTreeTicket jtreeticket = new JournalTreeTicket(qts[i]);
- System.out.println("Adding ticket: " + jtreeticket);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(jtreeticket);
--- 109,127 ----
/**
! * Populate the tree with the default journal record set
*/
private void populateTree() {
! populateTree(0, 100);
! }
!
! /**
! * Populate the tree (duh!)
! */
! public void populateTree(int start, int length) {
! QueryTicket[] qts = this.browserModel.getTickets(start, length);
if (qts != null) {
for (int i = 0; i < qts.length; ++i) {
JournalTreeTicket jtreeticket = new JournalTreeTicket(qts[i]);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(jtreeticket);
***************
*** 137,141 ****
/**
! * Cell renderer to show error steps in red
*/
class JournalBrowserCellRenderer extends JPanel implements TreeCellRenderer {
--- 145,149 ----
/**
! * Cell renderer to show steps of interest in color
*/
class JournalBrowserCellRenderer extends JPanel implements TreeCellRenderer {
***************
*** 146,156 ****
protected Font defaultFont;
protected Font boldFont;
! private final Color FAIL_COLOR=Color.WHITE;
! private final Color FAIL_BCOLOR=Color.RED;
! private final Color MSG_COLOR=Color.WHITE;
! private final Color MSG_BCOLOR=Color.BLUE;
private final int STRUT_WIDTH=4;
/**
* Constructor
--- 154,169 ----
protected Font defaultFont;
protected Font boldFont;
+ protected Font italicFont;
! private final Color FAIL_BCOLOR=Color.WHITE;
! private final Color FAIL_COLOR=Color.RED;
! private final Color MSG_BCOLOR=Color.WHITE;
! private final Color MSG_COLOR=Color.BLUE;
private final int STRUT_WIDTH=4;
+ private final int NORMAL_STEP=0;
+ private final int ERROR_STEP=1;
+ private final int JOURNAL_STEP=2;
+
/**
* Constructor
***************
*** 173,178 ****
defaultFont = text.getFont();
! // create a bold font to use for emphasis
! boldFont = new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize());
}
--- 186,192 ----
defaultFont = text.getFont();
! // create fonts to use for emphasis
! boldFont = new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize());
! italicFont = new Font(defaultFont.getName(), Font.ITALIC, defaultFont.getSize()+2);
}
***************
*** 213,235 ****
// do a bit of sanity checking here
if (value instanceof DefaultMutableTreeNode) {
-
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
if (node.getUserObject() instanceof JournalTreeTicketStep) {
- // Use the following color scheme:
- // failure = red background, white text
- // message = green background, white text
- QueryTicket ticket = (QueryTicket)((JournalTreeTicketStep)node.getUserObject()).getQTicket();
if (leaf) {
! if (ticket.getOperation().equals("updateStatus") && ticket.getOther().equals("fail")) {
! text.setForeground(FAIL_COLOR);
! text.setBackground(FAIL_BCOLOR);
! text.setFont(boldFont);
! }
! else if (ticket.getOperation().equals("updateJournal")) {
! text.setForeground(MSG_COLOR);
! text.setBackground(MSG_BCOLOR);
! text.setFont(boldFont);
}
}
}
}
--- 227,268 ----
// do a bit of sanity checking here
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
if (node.getUserObject() instanceof JournalTreeTicketStep) {
if (leaf) {
! setSpecialColor((JournalTreeTicketStep)node.getUserObject(), text,
! selected);
! }
! }
! else if (node.getUserObject() instanceof JournalTreeTicket) {
! // if any children are in error state, use error color. Else if
! // any children are in journalUpdate state, use journal color
! JournalTreeTicketStep step = null;
! Enumeration enum = node.children();
! while (enum.hasMoreElements()) {
! DefaultMutableTreeNode elem = (DefaultMutableTreeNode)enum.nextElement();
! if (elem.getUserObject() instanceof JournalTreeTicketStep) {
! JournalTreeTicketStep tStep = (JournalTreeTicketStep)elem.getUserObject();
!
! // any error immediately shows error and leaves
! if (tStep.getState() == JournalTreeTicketStep.ERROR_STEP) {
! step = tStep;
! break; // no need to scan any further (think about it!)
! }
! else if (tStep.getState() == JournalTreeTicketStep.JOURNAL_STEP) {
! step = tStep;
! }
! // make sure step has a value so that, if no special color needs
! // to be displayed, we can still show the normal colors
! else if (step==null) {
! step = tStep;
! }
}
}
+
+ // if any color needs to be set, do so now based on the saved
+ // step
+ if (step != null) {
+ setSpecialColor(step, text, selected);
+ }
}
}
***************
*** 249,252 ****
--- 282,312 ----
super.setBackground(color);
}
+
+ /**
+ * Change the text color if a failure or journalUpdate occurred
+ * @param ticket the QueryTicket to test
+ */
+ protected void setSpecialColor(JournalTreeTicketStep step, JTextArea text,
+ boolean selected) {
+ if (step.getState() == JournalTreeTicketStep.ERROR_STEP) {
+ text.setForeground(selected?FAIL_BCOLOR:FAIL_COLOR);
+ text.setBackground(selected?FAIL_COLOR:FAIL_BCOLOR);
+ text.setFont(boldFont);
+ }
+ else if (step.getState() == JournalTreeTicketStep.JOURNAL_STEP) {
+ text.setForeground(selected?MSG_BCOLOR:MSG_COLOR);
+ text.setBackground(selected?MSG_COLOR:MSG_BCOLOR);
+ text.setFont(boldFont);
+ }
+ else {
+ if (step.getState() == JournalTreeTicketStep.DOCUMENT_STEP) {
+ text.setFont(boldFont);
+ }
+
+ // no special color; set standard colors
+ text.setForeground(selected?text.getSelectedTextColor():text.getForeground());
+ text.setBackground(selected?text.getSelectionColor():text.getBackground());
+ }
+ }
}
}
***************
*** 326,336 ****
*/
class JournalTreeTicketStep extends JournalTreeObject {
/**
* Creates a new JournalTreeTicketStep object.
*
! * @param qticket DOCUMENT ME!
*/
public JournalTreeTicketStep(QueryTicket qticket) {
super(qticket);
}
--- 386,418 ----
*/
class JournalTreeTicketStep extends JournalTreeObject {
+ public static final int NORMAL_STEP = 1;
+ public static final int ERROR_STEP = 2;
+ public static final int JOURNAL_STEP = 3;
+ public static final int DOCUMENT_STEP = 4;
+
+ private int state; // the state of this ticket state
+
/**
* Creates a new JournalTreeTicketStep object.
*
! * @param qticket The QueryTicket represented by this instance
*/
public JournalTreeTicketStep(QueryTicket qticket) {
super(qticket);
+
+ // set the state of this step
+ if (qticket.getOperation().equals(JournalOperation.updateStatus.toString())
+ && qticket.getOther().equals("fail")) {
+ state = ERROR_STEP;
+ }
+ else if (qticket.getOperation().equals(JournalOperation.updateJournal.toString())) {
+ state = JOURNAL_STEP;
+ }
+ else if (qticket.getOperation().equals(JournalOperation.updateDocument.toString())) {
+ state = DOCUMENT_STEP;
+ }
+ else {
+ state = NORMAL_STEP;
+ }
}
***************
*** 346,348 ****
--- 428,438 ----
", other: " + getQTicket().getOther();
}
+
+ /**
+ * Returns the state.
+ * @return int
+ */
+ public int getState() {
+ return state;
+ }
}
Index: Command.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/gui/src/com/babeldoc/gui/journal/browser/Command.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Command.java 11 Jun 2003 23:35:38 -0000 1.2
--- Command.java 6 Sep 2003 00:58:45 -0000 1.3
***************
*** 99,103 ****
public void execute(CommandLine commandLine) {
JournalBrowser.run();
- System.out.println("Application has finished");
}
--- 99,102 ----
|