From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- .../gui/view/CompActDefOutcomeHandler.java | 218 +++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100755 source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java (limited to 'source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java') diff --git a/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java b/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java new file mode 100755 index 0000000..cb0ef59 --- /dev/null +++ b/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java @@ -0,0 +1,218 @@ +package com.c2kernel.lifecycle.gui.view; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.JSplitPane; + +import com.c2kernel.graph.layout.DefaultGraphLayoutGenerator; +import com.c2kernel.graph.view.EditorPanel; +import com.c2kernel.graph.view.VertexPropertyPanel; +import com.c2kernel.gui.MainFrame; +import com.c2kernel.gui.tabs.outcome.*; +import com.c2kernel.lifecycle.CompositeActivityDef; +import com.c2kernel.lifecycle.gui.model.WfDefGraphPanel; +import com.c2kernel.lifecycle.gui.model.WfEdgeDefFactory; +import com.c2kernel.lifecycle.gui.model.WfVertexDefFactory; +import com.c2kernel.lifecycle.gui.model.WfVertexDefOutlineCreator; +import com.c2kernel.lifecycle.instance.gui.view.FindActDefPanel; +import com.c2kernel.process.Gateway; +import com.c2kernel.utils.CastorXMLUtility; +import com.c2kernel.utils.FileStringUtility; +import com.c2kernel.utils.Logger; +import com.c2kernel.utils.Resource; + +/************************************************************************** + * + * $Revision: 1.14 $ + * $Date: 2005/09/07 13:46:31 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +public class CompActDefOutcomeHandler + extends JPanel + implements OutcomeHandler { + + protected JButton mLoadButton = new JButton(Resource.getImageResource("graph/load.png")); + protected JButton mLayoutButton = new JButton(Resource.getImageResource("graph/autolayout.png")); + protected JButton[] mOtherToolBarButtons = { mLayoutButton, mLoadButton }; + + protected CompositeActivityDef mCompActDef = null; + protected WfEdgeDefFactory mWfEdgeDefFactory = new WfEdgeDefFactory(); + protected WfVertexDefFactory mWfVertexDefFactory = new WfVertexDefFactory(); + + protected EditorPanel mEditorPanel; + protected VertexPropertyPanel mPropertyPanel; + protected JSplitPane mSplitPane; + boolean unsaved; + + public CompActDefOutcomeHandler() { + super(); + mPropertyPanel = loadPropertyPanel(); + mPropertyPanel.createLayout(new FindActDefPanel()); + mEditorPanel = + new EditorPanel( + mWfEdgeDefFactory, + mWfVertexDefFactory, + new WfVertexDefOutlineCreator(), + true, + mOtherToolBarButtons, + new WfDefGraphPanel(new WfDirectedEdgeDefRenderer(), + new WfVertexDefRenderer())); + } + + protected void createLayout() + { + mLoadButton.setToolTipText("Load from local disc"); + mLayoutButton.setToolTipText("Auto-Layout"); + + // Add the editor pane + GridBagLayout gridbag = new GridBagLayout(); + setLayout(gridbag); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 1; + c.fill = GridBagConstraints.BOTH; + c.weighty = 2.0; + c.weightx = 2.0; + mSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mEditorPanel, mPropertyPanel); + mSplitPane.setDividerSize(5); + gridbag.setConstraints(mSplitPane, c); + add(mSplitPane); + } + + protected void createListeners() + { + mLoadButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + File selectedFile = null; + + int returnValue = MainFrame.xmlChooser.showOpenDialog(null); + + switch (returnValue) + { + case JFileChooser.APPROVE_OPTION : + selectedFile = MainFrame.xmlChooser.getSelectedFile(); + try { + String newWf = FileStringUtility.file2String(selectedFile); + setOutcome(newWf); + setUpGraphEditor(); + } catch (Exception e) { + Logger.exceptionDialog(e); + } + case JFileChooser.CANCEL_OPTION : + case JFileChooser.ERROR_OPTION : + + default : + } + } + }); + + mLayoutButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + DefaultGraphLayoutGenerator.layoutGraph(mEditorPanel.mGraphModelManager.getModel()); + } + }); + } + + public void setUpGraphEditor() { + mEditorPanel.mGraphModelManager.setModel(mCompActDef.getChildrenGraphModel()); + // Give the editor panel the edge and vertex types + mEditorPanel.updateVertexTypes(mCompActDef.getVertexTypeNameAndConstructionInfo()); + mEditorPanel.updateEdgeTypes(mCompActDef.getEdgeTypeNameAndConstructionInfo()); + mEditorPanel.enterSelectMode(); + mWfVertexDefFactory.setCreationContext(mCompActDef); + } + + /** + * + */ + public void setOutcome(String outcome) throws InvalidOutcomeException { + try { + CompositeActivityDef newAct = (CompositeActivityDef)CastorXMLUtility.unmarshall(outcome); + if (mCompActDef != null) + newAct.setName(mCompActDef.getName()); + mCompActDef = newAct; + } catch (Exception ex) { + Logger.error(ex); + throw new InvalidOutcomeException(ex.getMessage()); + } + } + /** + * + */ + public void setDescription(String description) + throws InvalidSchemaException { + // ignore - always the same + } + /** + * + */ + public void setReadOnly(boolean readOnly) { + mLayoutButton.setEnabled(!readOnly); + mLoadButton.setEnabled(!readOnly); + mEditorPanel.setEditable(!readOnly); + mPropertyPanel.setEditable(!readOnly); + } + /** + * + */ + public JPanel getPanel() throws OutcomeNotInitialisedException { + return this; + } + /** + * + */ + public String getOutcome() throws OutcomeException { + try { + return CastorXMLUtility.marshall(mCompActDef); + } catch (Exception ex) { + throw new OutcomeException(ex.getMessage()); + } + } + /** + * + */ + public void run() { + Thread.currentThread().setName("Composite Act Def Viewer"); + createLayout(); + createListeners(); + mPropertyPanel.setGraphModelManager(mEditorPanel.mGraphModelManager); + setUpGraphEditor(); + } + + public VertexPropertyPanel loadPropertyPanel() + { + String wfPanelClass = Gateway.getProperty("WfPropertyPanel"); + if (wfPanelClass != null) { + try { + Class panelClass = Class.forName(wfPanelClass); + return (VertexPropertyPanel)panelClass.newInstance(); + } catch (Exception ex) { + Logger.error("Could not load wf props panel:"+wfPanelClass); + Logger.error(ex); + } + } + return new VertexPropertyPanel(); + } + + public boolean isUnsaved() { + return unsaved; + } + + public void saved() { + unsaved = false; + } + + public void export(File targetFile) throws Exception { + ElemActDefOutcomeHandler.exportAct(targetFile.getParentFile(), mCompActDef); + } +} -- cgit v1.2.3