r714 - in trunk/jrst/src/main/java/org/nuiton/jrst: . jaxxUI
Author: jpages Date: 2012-06-13 15:17:14 +0200 (Wed, 13 Jun 2012) New Revision: 714 Url: http://nuiton.org/repositories/revision/jrst/714 Log: L'interface de JRST avec Jaxx est termin?\195?\169e. Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTCommandModel.java trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTView.jaxx trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTViewHandler.java trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanel.jaxx trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanelHandler.java Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-06-13 13:17:14 UTC (rev 714) @@ -205,39 +205,40 @@ I18n.init(new ClassPathI18nInitializer(), Locale.UK); if (args.length == 0) { - args = askOption(); - } - if (args == null) { - System.exit(0); - } + askOption(); + } else { + if (args == null) { + System.exit(0); + } - ApplicationConfig config = JRSTConfig.getConfig(args); - config.doAction(0); + ApplicationConfig config = JRSTConfig.getConfig(args); + config.doAction(0); - // parse options - String xslList = JRSTConfigOption.XSL_FILE.getOption(config); - if (xslList == null) { - xslList = JRSTConfigOption.OUT_TYPE.getOption(config); - } - List<String> unparsed = config.getUnparsed(); - if (unparsed.isEmpty()) { - JRSTConfig.help(); - } - File inputFile = new File(config.getUnparsed().get(0)); - File ouputFile = JRSTConfigOption.OUT_FILE.getOptionAsFile(config); - Overwrite overwrite = Overwrite.NEVER; - if (JRSTConfigOption.FORCE.getOptionAsBoolean(config)) { - overwrite = Overwrite.ALLTIME; - } - boolean simpleGeneration = false; - if (JRSTConfigOption.SIMPLE.getOptionAsBoolean(config)) { - simpleGeneration = true; - } + // parse options + String xslList = JRSTConfigOption.XSL_FILE.getOption(config); + if (xslList == null) { + xslList = JRSTConfigOption.OUT_TYPE.getOption(config); + } + List<String> unparsed = config.getUnparsed(); + if (unparsed.isEmpty()) { + JRSTConfig.help(); + } + File inputFile = new File(config.getUnparsed().get(0)); + File ouputFile = JRSTConfigOption.OUT_FILE.getOptionAsFile(config); + Overwrite overwrite = Overwrite.NEVER; + if (JRSTConfigOption.FORCE.getOptionAsBoolean(config)) { + overwrite = Overwrite.ALLTIME; + } + boolean simpleGeneration = false; + if (JRSTConfigOption.SIMPLE.getOptionAsBoolean(config)) { + simpleGeneration = true; + } - generate(xslList, inputFile, ouputFile, overwrite, simpleGeneration); + generate(xslList, inputFile, ouputFile, overwrite, simpleGeneration); + } } - private static String[] askOption() throws SecurityException, + private static void askOption() throws SecurityException, NoSuchMethodException, IOException { String[] result = null; try { @@ -245,14 +246,12 @@ GraphicsDevice[] gs = ge.getScreenDevices(); if (!(gs == null)) { if (gs.length > 0) { - result = askOptionGraph(); + askOptionGraph(); } } } catch (java.awt.HeadlessException e) { - result = null; + log.error("Can't generate document", e); } - - return result; } /** @@ -262,62 +261,11 @@ * @throws SecurityException * @throws NoSuchMethodException */ - protected static String[] askOptionGraph() throws SecurityException, + protected static void askOptionGraph() throws SecurityException, NoSuchMethodException { - - /* - JRSTInterface graph = new JRSTInterface(PATTERN_TYPE); - return graph.getCmd(); - */ JRSTView jrstView = new JRSTView(); jrstView.pack(); jrstView.setVisible(true); - - log.info("test"); - boolean exit = false; - String[] command = new String[]{}; - if (!jrstView.getModel().isOverwrite()) { - File file = new File(jrstView.getModel().getSaveLocationText()); - if (file.exists()) { - int choix = jrstView.getHandler().askEcraser(); - if (choix == JOptionPane.YES_OPTION) - jrstView.setOverwrite(true); - else if (choix == JOptionPane.NO_OPTION) - exit = true; - } - } - if (!exit) { - String cmd = ""; - if (jrstView.isOverwrite()) - cmd += "--force "; - if (jrstView.isSimpleMode()) { - cmd += "--simple "; - } - if (jrstView.getFormat().isSelected()) - cmd += "-t " + jrstView.getFormatList().getSelectedItem(); - else { - cmd += "-x "; - - for (int i = 0; i <jrstView.getXslListPanel().getComponentCount(); i++ ) { - JPanel panel = (JPanel)jrstView.getXslListPanel().getComponent(i); - for(JTextField c : panel.getComponents()) { - c.setEnabled(false); - } - } - - for (JTextField t : jrstView.getXslListPanel().getComponent()) { - if (!t.getText().equals("")) - cmd += t.getText() + ","; - } - cmd = cmd.substring(0, cmd.length() - 1); - } - if (jrstView.getSaveText().getText().length() > 0) - cmd += " -o " + jrstView.getSaveText().getText(); - cmd += " " + jrstView.getOpenText().getText() + " "; - command = cmd.trim().split(" "); - jrstView.dispose(); - } - return command; } /** Modified: trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTCommandModel.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTCommandModel.java 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTCommandModel.java 2012-06-13 13:17:14 UTC (rev 714) @@ -4,6 +4,8 @@ import java.beans.PropertyChangeSupport; import java.util.Iterator; import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.python.google.common.collect.Lists; /** * Created: 08/06/12 @@ -13,21 +15,26 @@ public class JRSTCommandModel { protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - protected Boolean overwrite = Boolean.FALSE; protected Boolean simpleMode = Boolean.FALSE; protected Boolean formatEnabled = Boolean.TRUE; - protected String in; - protected String out; - protected String saveLocationText; protected String openLocationText; + protected String selectedFormat; - protected int panelNumber = 0; - protected List<String> xslList; + protected JRSTView jrstView; + + public JRSTCommandModel(JRSTView jrstView) { + this.jrstView = jrstView; + xslList = Lists.newArrayList(); + saveLocationText = StringUtils.EMPTY; + openLocationText = StringUtils.EMPTY; + selectedFormat = "xml"; + } + public Boolean isOverwrite() { return overwrite; } @@ -58,26 +65,6 @@ firePropertyChange("formatEnabled", oldValue, formatEnabled); } - public String getIn() { - return in; - } - - public void setIn(String in) { - String oldValue = getIn(); - this.in = in; - firePropertyChange("in", oldValue, in); - } - - public String getOut() { - return out; - } - - public void setOut(String out) { - String oldValue = getOut(); - this.out = out; - firePropertyChange("out", oldValue, out); - } - public String getSaveLocationText() { return saveLocationText; } @@ -98,6 +85,16 @@ firePropertyChange("openLocationText", oldValue, openLocationText); } + public String getSelectedFormat() { + return selectedFormat; + } + + public void setSelectedFormat(String selectedFormat) { + String oldValue = getSelectedFormat(); + this.selectedFormat = selectedFormat; + firePropertyChange("selectedFormat", oldValue, selectedFormat); + } + public List<String> getXslList() { return xslList; } @@ -108,7 +105,22 @@ firePropertyChange("xslList", oldValue, xslList); } + public String getXsls() { + String xsls = ""; + Iterator<String> iterator = xslList.iterator(); + while (iterator.hasNext()) { + xsls += iterator.next(); + if (iterator.hasNext()) { + xsls += ","; + } + } + return xsls; + } + public String getElementXslList(Integer number) { + if (xslList.size() <= number) { + xslList.add(StringUtils.EMPTY); + } String text = xslList.get(number); return text; } @@ -124,23 +136,9 @@ } public int getPanelNumber() { - return panelNumber; + return xslList.size(); } - public void incrementPanelNumber() { - setPanelNumber(getPanelNumber() + 1); - } - - public void setPanelNumber(int panelNumber) { - int oldValue = getPanelNumber(); - this.panelNumber = panelNumber; - firePropertyChange("panelNumber", oldValue, panelNumber); - } - - public String getCommand(){ - //TODO - } - public void addPropertyChangeListener(PropertyChangeListener listener) { pcs.addPropertyChangeListener(listener); } Modified: trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTView.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTView.jaxx 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTView.jaxx 2012-06-13 13:17:14 UTC (rev 714) @@ -15,7 +15,7 @@ <DefaultComboBoxModel id='comboBoxModel' constructorParams='handler.getFormats()'/> - <JRSTCommandModel id='model'/> + <JRSTCommandModel id='model' constructorParams='this'/> <script><![CDATA[ @@ -24,20 +24,21 @@ } ]]></script> + <Table> <row> - <cell columns='3'> + <cell columns='3' anchor='west'> <JLabel id='errorLbl' text=''/> </cell> </row> <row> - <cell> + <cell anchor='west'> <JLabel text='Open'/> </cell> - <cell> + <cell weightx='1' fill='horizontal'> <JTextField id='openLocationText' - text='model.getOpenLocationText()' - onKeyReleased='model.setOpenLocationText(model.getOpenLocationText())' + text='{model.getOpenLocationText()}' + onKeyReleased='model.setOpenLocationText(openLocationText.getText())' columns='31'/> </cell> <cell> @@ -48,13 +49,13 @@ </cell> </row> <row> - <cell> + <cell anchor='west'> <JLabel text='saveAs'/> </cell> - <cell> + <cell weightx='1' fill='horizontal'> <JTextField id='saveLocationText' - text='model.getSaveLocationText()' - onKeyReleased='model.setSaveLocationText(model.getSaveLocationText())' + text='{model.getSaveLocationText()}' + onKeyReleased='model.setSaveLocationText(saveLocationText.getText())' columns='31'/> </cell> <cell> @@ -66,55 +67,54 @@ </row> <row> - <cell> + <cell anchor='west'> <JRadioButton id='format' text='Format : ' - selected='{formatEnabled}' - onActionPerformed='handler.enableFormatList()'/> + selected='{model.isFormatEnabled()}' + onActionPerformed='model.setFormatEnabled(true)'/> </cell> - <cell columns='2'> - <JComboBox id='formatList' model='{comboBoxModel}'/> + <cell columns='2' fill='horizontal'> + <JComboBox id='formatList' + model='{comboBoxModel}' + enabled='{model.isFormatEnabled()}' + onActionPerformed='model.setSelectedFormat((String)formatList.getSelectedItem())'/> </cell> </row> <row> - <cell> + <cell anchor='west'> <JRadioButton id='xslRadio' text='externalXSL' - onActionPerformed='handler.enableXslList()'/> + selected='{!model.isFormatEnabled()}' + onActionPerformed='model.setFormatEnabled(false)'/> </cell> - <cell columns='2'> + <cell columns='2' weightx='1' weighty='1' fill='both'> <JPanel id='xslListPanel' layout='{new BoxLayout(xslListPanel, BoxLayout.Y_AXIS)}'/> </cell> </row> <row> - <cell columns='3'> - <JPanel id='addXslPanel'> - <JButton id='addXslButton' - constructorParams='Resource.getIcon("icone/more.gif")' - preferredSize='{new Dimension(20, 20)}' - onActionPerformed='handler.addXslLocation()'/> - </JPanel> + <cell anchor='west'> + <JButton id='addXslButton' + constructorParams='Resource.getIcon("icone/more.gif")' + preferredSize='{new Dimension(20, 20)}' + onActionPerformed='handler.addXslLocation()'/> </cell> - </row> - - <row> - <cell columns='3'> + <cell columns='2' anchor='west'> <JCheckBox id='simpleModeChechBox' text='Simple mode' - selected='{simpleMode}' - onActionPerformed='setSimpleMode(simpleModeChechBox.isSelected())'/> + selected='{model.isSimpleMode()}' + onActionPerformed='model.setSimpleMode(simpleModeChechBox.isSelected())'/> </cell> </row> <row> - <cell columns='3'> + <cell columns='3' weightx='1' fill='horizontal'> <Table> <row> - <cell> + <cell weightx='0.5' fill='horizontal'> <JButton id='boutonAnnuler' text='Cancel' onActionPerformed='handler.cancel()'/> </cell> - <cell> + <cell weightx='0.5' fill='horizontal'> <JButton id='boutonConvertir' text='Convert' onActionPerformed='handler.convert()'/> </cell> </row> @@ -122,7 +122,6 @@ </cell> </row> - </Table> </JDialog> \ No newline at end of file Modified: trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTViewHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTViewHandler.java 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/JRSTViewHandler.java 2012-06-13 13:17:14 UTC (rev 714) @@ -1,14 +1,18 @@ package org.nuiton.jrst.jaxxUI; +import com.sun.jndi.toolkit.url.UrlUtil; import java.awt.Color; -import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.File; import javax.swing.ButtonGroup; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; -import javax.swing.JPanel; import javax.swing.JTextField; +import jaxx.runtime.context.JAXXInitialContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.jrst.JRST; import static org.nuiton.i18n.I18n._; @@ -19,6 +23,8 @@ * @author jpages <j.pages@codelutin.com> */ public class JRSTViewHandler { + /** to use log facility, just put in your code: log.info("..."); */ + protected static Log log = LogFactory.getLog(JRSTViewHandler.class); protected JRSTView jrstView; @@ -31,10 +37,7 @@ group.add(jrstView.getXslRadio()); group.add(jrstView.getFormat()); - XslPanel xslPanel = new XslPanel(); - xslPanel.setPanelNumber(jrstView.getModel().getPanelNumber()); - jrstView.getModel().incrementPanelNumber(); - jrstView.getXslListPanel().add(xslPanel); + addXslLocation(); } public void doOpenLocation() { @@ -42,24 +45,29 @@ fc.showOpenDialog(jrstView); File file = fc.getSelectedFile(); if (file != null) { - jrstView.getOpenText().setText(file.getAbsolutePath()); + JRSTCommandModel model = jrstView.getModel(); + String absolutePath = file.getAbsolutePath(); + model.setOpenLocationText(absolutePath); } } public void doOpenSaveLocation() { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.showSaveDialog(jrstView); + JRSTCommandModel model = jrstView.getModel(); File file = fc.getSelectedFile(); if (file != null) { - JTextField saveText = jrstView.getSaveText(); + String absolutePath = file.getAbsolutePath(); if (file.exists()) { int choix = askEcraser(); if (choix == JOptionPane.YES_OPTION) { - saveText.setText(file.getAbsolutePath()); + model.setOverwrite(true); + model.setSaveLocationText(absolutePath); } else if (choix == JOptionPane.NO_OPTION) doOpenSaveLocation(); - } else - saveText.setText(file.getAbsolutePath()); + } else { + model.setSaveLocationText(absolutePath); + } } } @@ -77,14 +85,29 @@ } public void addXslLocation() { - XslPanel xslPanel = new XslPanel(); - xslPanel.setPanelNumber(jrstView.getModel().getPanelNumber()); - jrstView.getModel().incrementPanelNumber(); + + JAXXInitialContext context = new JAXXInitialContext(); + context.add(jrstView); + JRSTCommandModel model = jrstView.getModel(); + context.add(model); + XslPanel xslPanel = new XslPanel(context); + xslPanel.setModel(model); + xslPanel.setModel(model); + int panelNumber = model.getPanelNumber(); + String xslPath = model.getElementXslList(panelNumber); + xslPanel.setXslPath(xslPath); + xslPanel.setPanelNumber(panelNumber); + + xslPanel.addPropertyChangeListener(XslPanel.PROPERTY_XSL_PATH, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + XslPanel source = (XslPanel)evt.getSource(); + jrstView.getModel().setElementXslList(source.getPanelNumber(), (String)evt.getNewValue()); + } + }); + jrstView.getXslListPanel().add(xslPanel); - - if (!jrstView.getFormat().isSelected()) { - enableXslList(); - } jrstView.pack(); } @@ -96,33 +119,74 @@ return errorLbl; } - public void enableFormatList() { - jrstView.getFormatList().setEnabled(true); - for (int i = 0; i <jrstView.getXslListPanel().getComponentCount(); i++ ) { - JPanel panel = (JPanel)jrstView.getXslListPanel().getComponent(i); - for(Component c : panel.getComponents()) { - c.setEnabled(false); - } - } - } - - public void enableXslList() { - jrstView.getFormatList().setEnabled(false); - for (int i = 0; i <jrstView.getXslListPanel().getComponentCount(); i++ ) { - JPanel panel = (JPanel)jrstView.getXslListPanel().getComponent(i); - for(Component c : panel.getComponents()) { - c.setEnabled(true); - } - } - } - public void convert() { - if (jrstView.getOpenText().getText().equals("")) { + if (jrstView.getOpenLocationText().getText().equals("")) { jrstView.getHandler().getErrorLabel().setText(_("openEmpty?")); jrstView.getHandler().getErrorLabel().setForeground(Color.RED); jrstView.pack(); } else { + launchJRST(); jrstView.setVisible(false); } } + + public void launchJRST() { + boolean exit = false; + String xslListOrFormat = ""; + File fileIn = null; + File fileOut = null; + JRSTCommandModel model = jrstView.getModel(); + if (!model.isOverwrite()) { + fileIn = new File(model.getOpenLocationText()); + if (fileIn.exists()) { + int choix = jrstView.getHandler().askEcraser(); + if (choix == JOptionPane.YES_OPTION) + model.setOverwrite(true); + else if (choix == JOptionPane.NO_OPTION) + exit = true; + } + } + JRST.Overwrite overwriteState = JRST.Overwrite.NEVER; + if (model.isOverwrite()) { + overwriteState = JRST.Overwrite.ALLTIME; + } + + if (!exit) { + if (model.isFormatEnabled()) + xslListOrFormat = model.getSelectedFormat(); + else { + xslListOrFormat = model.getXsls(); + } + String outputFile = ""; + int length = model.getSaveLocationText().length(); + if (length > 0) { + outputFile = model.getSaveLocationText(); + } else { + if (fileIn.isFile()) { + String name = fileIn.getName(); + String[] splitName = name.split("\\."); + outputFile = splitName[0]; + for (int i = 1; i < splitName.length - 2; i++ ) { + outputFile += splitName[i]; + } + outputFile += "."; + if (model.isFormatEnabled()) { + outputFile += xslListOrFormat; + } else { + outputFile += "xml"; + } + outputFile = fileIn.getParent() + File.separator + outputFile; + } + } + fileOut = new File(outputFile); + } + + try{ + JRST.generate(xslListOrFormat, fileIn, fileOut, overwriteState, model.isSimpleMode()); + } catch (Exception e) { + log.error("Can't generate the document with this configuration", e); + } finally { + jrstView.dispose(); + } + } } Modified: trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanel.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanel.jaxx 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanel.jaxx 2012-06-13 13:17:14 UTC (rev 714) @@ -6,18 +6,28 @@ <XslPanelHandler id='handler' constructorParams='this'/> <Integer id='panelNumber' javaBean='null'/> + <JRSTCommandModel id='model' javaBean='getContextValue(JRSTCommandModel.class)'/> + <String id='xslPath' javaBean='null'/> + <script><![CDATA[ + + protected void $afterCompleteSetup() { + handler.init(); + } + + ]]></script> + <row> - <cell> + <cell fill='horizontal' weightx='1'> <JTextField id='xslLocationText' columns='30' - enabled='false' - text='model.getElementXslList(panelNumber)' - onKeyReleased='model.setElementXslList(panelNumber, model.getElementXslList(panelNumber))'/> + enabled='{!model.isFormatEnabled()}' + text='{xslPath}' + onKeyReleased='setXslPath(xslLocationText.getText())'/> </cell> <cell> <JButton id='boutonXslLocation' - enabled='false' + enabled='{!model.isFormatEnabled()}' preferredSize='{new Dimension(30, 30)}' constructorParams='Resource.getIcon("icone/open.png")' onActionPerformed='handler.openXslLocation()'/> Modified: trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanelHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanelHandler.java 2012-06-12 16:19:42 UTC (rev 713) +++ trunk/jrst/src/main/java/org/nuiton/jrst/jaxxUI/XslPanelHandler.java 2012-06-13 13:17:14 UTC (rev 714) @@ -18,12 +18,16 @@ this.xslPanel = xslPanel; } + public void init() { + + } + public void openXslLocation() { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.showOpenDialog(xslPanel); File file = fc.getSelectedFile(); if (file != null) { - xslPanel.getXslText().setText(file.getAbsolutePath()); + xslPanel.getXslLocationText().setText(file.getAbsolutePath()); } } }
participants (1)
-
jpages@users.nuiton.org