From eacd6cecdeeb14f9c96e74fafbacbc7f7c4804b8 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 12 Jul 2012 14:54:26 +0200 Subject: GUI support for errors on suspend refs #23 --- .../java/com/c2kernel/gui/tabs/ExecutionPane.java | 2 +- .../gui/tabs/execution/ActivityViewer.java | 185 +++++++++++++-------- .../c2kernel/gui/tabs/execution/RequestButton.java | 3 +- 3 files changed, 115 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/main/java/com/c2kernel/gui/tabs/ExecutionPane.java b/src/main/java/com/c2kernel/gui/tabs/ExecutionPane.java index a853695..a5df52c 100644 --- a/src/main/java/com/c2kernel/gui/tabs/ExecutionPane.java +++ b/src/main/java/com/c2kernel/gui/tabs/ExecutionPane.java @@ -86,7 +86,7 @@ public class ExecutionPane extends EntityTabPane implements EntityProxyObserver< jobList = ((ItemProxy)sourceEntity.getEntity()).getJobList(MainFrame.userAgent); activitySelector.addItem(emptyAct); for (Job thisJob : jobList) { - Logger.msg(7, "ExecutionPane - loadJobList " + thisJob.isOutcomeUsed() + "|" + thisJob.getSchemaType() + "|" + thisJob.getSchemaVersion() + "|"); + Logger.msg(7, "ExecutionPane - loadJobList " + thisJob.hasOutcome() + "|" + thisJob.getSchemaType() + "|" + thisJob.getSchemaVersion() + "|"); ActivityItem newAct = new ActivityItem(thisJob); if (activities.contains(newAct)) { int actIndex = activities.indexOf(newAct); diff --git a/src/main/java/com/c2kernel/gui/tabs/execution/ActivityViewer.java b/src/main/java/com/c2kernel/gui/tabs/execution/ActivityViewer.java index 34118a3..14a15f6 100644 --- a/src/main/java/com/c2kernel/gui/tabs/execution/ActivityViewer.java +++ b/src/main/java/com/c2kernel/gui/tabs/execution/ActivityViewer.java @@ -10,8 +10,10 @@ import java.io.File; import java.util.ArrayList; import javax.swing.Box; +import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -22,11 +24,15 @@ import javax.swing.JTextArea; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.ItemProxy; +import com.c2kernel.gui.ImageLoader; import com.c2kernel.gui.MainFrame; import com.c2kernel.gui.tabs.EntityTabPane; import com.c2kernel.gui.tabs.ExecutionPane; +import com.c2kernel.gui.tabs.outcome.InvalidOutcomeException; +import com.c2kernel.gui.tabs.outcome.InvalidSchemaException; import com.c2kernel.gui.tabs.outcome.OutcomeException; import com.c2kernel.gui.tabs.outcome.OutcomeHandler; +import com.c2kernel.process.Gateway; import com.c2kernel.utils.FileStringUtility; import com.c2kernel.utils.Language; import com.c2kernel.utils.LocalObjectLoader; @@ -37,7 +43,9 @@ public class ActivityViewer extends JPanel implements Runnable { ItemProxy item; Box outcomeButtons = Box.createHorizontalBox(); OutcomeHandler outcomePanel; + OutcomeHandler errorPanel; JPanel outcomeView = new JPanel(new GridLayout(1,1)); + JPanel errorView = new JPanel(new GridLayout(2,1)); ActivityItem thisAct; ArrayList requestButtons = new ArrayList(); JLabel noOutcome = new JLabel(Language.translate("No outcome data is required for this activity")); @@ -159,87 +167,47 @@ public class ActivityViewer extends JPanel implements Runnable { loadButton.setEnabled(false); c.gridx--; c.gridwidth = 2; - boolean outcomeEmpty = true; for (Object name2 : thisAct.getJobs()) { Job thisJob = (Job)name2; RequestButton newButton = new RequestButton(thisJob, this); requestButtons.add(newButton); outcomeButtons.add(newButton); outcomeButtons.add(Box.createHorizontalStrut(5)); + newButton.setEnabled(false); + + if (thisJob.requiresOutcome() && outcomePanel == null) { + try { + outcomePanel = getOutcomeHandler(thisJob); + outcomeView = outcomePanel.getPanel(); + newButton.setEnabled(true); + } catch (ObjectNotFoundException ex) { + outcomeView.add(new JLabel(Language.translate("Schema not found:")+" "+thisJob.getSchemaType()+" v"+thisJob.getSchemaVersion())); + } catch (Exception ex) { + outcomeView.add(new JLabel(Language.translate("ERROR loading outcome editor: ") + +ex.getClass().getName()+" ("+ex.getMessage()+")")); + Logger.error(ex); + } + } + else if (thisJob.isError()) { + try { + errorPanel = getOutcomeHandler(thisJob); + errorView.add(errorPanel.getPanel()); + newButton.setEnabled(true); + } catch (Exception ex) { + errorView.add(new JLabel(Language.translate("ERROR loading error editor: ") + +ex.getClass().getName()+" ("+ex.getMessage()+")")); - if (thisJob.isOutcomeUsed()) { - String schema; - if (outcomeEmpty) { - try { - schema = LocalObjectLoader.getSchema(thisJob.getSchemaType(), thisJob.getSchemaVersion()).schema; - outcomePanel = EntityTabPane.getOutcomeHandler(thisJob.getSchemaType(), thisJob.getSchemaVersion()); - outcomePanel.setReadOnly(false); - outcomePanel.setDescription(schema); - String outcomeString = thisJob.getOutcomeString(); - if ( outcomeString!= null && outcomeString.length() > 0) - outcomePanel.setOutcome(outcomeString); - outcomeView = outcomePanel.getPanel(); - } catch (ObjectNotFoundException ex) { - outcomeView.add(new JLabel(Language.translate("Schema not found:")+" "+thisJob.getSchemaType()+" v"+thisJob.getSchemaVersion())); - outcomePanel = null; - } catch (Exception ex) { - outcomeView.add(new JLabel(Language.translate("ERROR loading outcome editor: ") - +ex.getClass().getName()+" ("+ex.getMessage()+")")); - Logger.error(ex); - outcomePanel = null; - } - } - outcomeEmpty = false; - if (outcomePanel == null) newButton.setEnabled(false); - else { - saveButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String output; - try { - output = outcomePanel.getOutcome(); - int returnVal = chooser.showSaveDialog(null); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File targetFile = chooser.getSelectedFile(); - if (!(targetFile.getAbsolutePath().endsWith(".xml"))) - targetFile = new File(targetFile.getAbsolutePath()+".xml"); - - Logger.msg(2, "ExecutionPane - Exporting outcome to file " + targetFile.getName()); - FileStringUtility.string2File(targetFile, output); - } - } catch (Exception ex) { - Logger.error(ex); - MainFrame.exceptionDialog(ex); - } - } - }); - saveButton.setEnabled(true); - - loadButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { - int returnVal = chooser.showOpenDialog(null); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File targetFile = chooser.getSelectedFile(); - - Logger.msg(2, "ViewpointPane.actionPerformed() - Reading outcome from file " + targetFile.getName()); - String outcome = FileStringUtility.file2String(targetFile); - outcomePanel.setOutcome(outcome); - new Thread(outcomePanel).start(); - } - } catch (Exception ex) { - Logger.error(ex); - MainFrame.exceptionDialog(ex); - } - } - }); - loadButton.setEnabled(true); - } + } } + else + newButton.setEnabled(true); } - if (outcomeEmpty) + if (outcomePanel == null) outcomeView.add(noOutcome); + else + enableLoadSaveButtons(); + + c.gridy++; c.weighty=1.0; c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; @@ -248,15 +216,86 @@ public class ActivityViewer extends JPanel implements Runnable { } + public OutcomeHandler getOutcomeHandler(Job thisJob) throws ObjectNotFoundException, InvalidSchemaException, InvalidOutcomeException { + String schema; + OutcomeHandler thisForm; + schema = LocalObjectLoader.getSchema(thisJob.getSchemaType(), thisJob.getSchemaVersion()).schema; + thisForm = EntityTabPane.getOutcomeHandler(thisJob.getSchemaType(), thisJob.getSchemaVersion()); + thisForm.setReadOnly(false); + thisForm.setDescription(schema); + String outcomeString = thisJob.getOutcomeString(); + if ( outcomeString!= null && outcomeString.length() > 0) + thisForm.setOutcome(outcomeString); + return thisForm; + } + + public void enableLoadSaveButtons() { + saveButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String output; + try { + output = outcomePanel.getOutcome(); + int returnVal = chooser.showSaveDialog(null); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File targetFile = chooser.getSelectedFile(); + if (!(targetFile.getAbsolutePath().endsWith(".xml"))) + targetFile = new File(targetFile.getAbsolutePath()+".xml"); + + Logger.msg(2, "ExecutionPane - Exporting outcome to file " + targetFile.getName()); + FileStringUtility.string2File(targetFile, output); + } + } catch (Exception ex) { + Logger.error(ex); + MainFrame.exceptionDialog(ex); + } + } + }); + saveButton.setEnabled(true); + + loadButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int returnVal = chooser.showOpenDialog(null); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File targetFile = chooser.getSelectedFile(); + + Logger.msg(2, "ViewpointPane.actionPerformed() - Reading outcome from file " + targetFile.getName()); + String outcome = FileStringUtility.file2String(targetFile); + outcomePanel.setOutcome(outcome); + new Thread(outcomePanel).start(); + } + } catch (Exception ex) { + Logger.error(ex); + MainFrame.exceptionDialog(ex); + } + } + }); + loadButton.setEnabled(true); + } + public void init() { if (outcomePanel != null) new Thread(outcomePanel).start(); + if (errorPanel != null) + new Thread(errorPanel).start(); } public void execute(Job thisJob) { - try{ - if (thisJob.isOutcomeUsed() && thisJob.getSchemaType().length() > 0) + try { + if (thisJob.requiresOutcome() && thisJob.getSchemaType().length() > 0) thisJob.setOutcome(outcomePanel.getOutcome()); + else if (thisJob.isError()) { + //JOptionPane errorDialog = new JOptionPane(); + Box errorBox = Box.createVerticalBox(); + errorBox.add(new JLabel("Please give details of the error:")); + errorBox.add(errorView); + int result = JOptionPane.showConfirmDialog(this, errorBox, "Send Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); + if (result != JOptionPane.OK_OPTION) + return; + thisJob.setOutcome(errorPanel.getOutcome()); + } executingJob = thisJob; new Thread(this).start(); } catch (OutcomeException ex) { diff --git a/src/main/java/com/c2kernel/gui/tabs/execution/RequestButton.java b/src/main/java/com/c2kernel/gui/tabs/execution/RequestButton.java index e1372a2..96123ff 100644 --- a/src/main/java/com/c2kernel/gui/tabs/execution/RequestButton.java +++ b/src/main/java/com/c2kernel/gui/tabs/execution/RequestButton.java @@ -22,7 +22,8 @@ import com.c2kernel.lifecycle.instance.stateMachine.Transitions; this.parent = parent; String label = Transitions.getTransitionName(myJob.getPossibleTransition()); label = Character.toUpperCase(label.charAt(0))+label.substring(1); - if (myJob.isOutcomeUsed()) setBackground(Color.white); + if (myJob.requiresOutcome()) setBackground(Color.white); + if (myJob.isError()) setBackground(Color.pink); super.setText(label); addActionListener(this); } -- cgit v1.2.3