Re: Auto detection of grammar
Olivier POTONNIEE <[email protected]> Tue, 06 Jan 2004 17:26:58 +0100
| Newsgroups | gmane.editors.pollo.devel |
|---|---|
| Message-ID | <[email protected]> |
Here it is (I just realize I also changed default to classic tree view instead of Pollo, which is an independent matter):
$ diff -u ViewTypesDialog.java.orig ViewTypesDialog.java
--- ViewTypesDialog.java.orig 2003-10-03 13:06:00.000000000 +0200
+++ ViewTypesDialog.java 2004-01-06 16:04:58.950488000 +0100
@@ -2,8 +2,13 @@
import org.outerj.pollo.Pollo;
import org.outerj.pollo.xmleditor.displayspec.IDisplaySpecification;
+import org.outerj.pollo.xmleditor.model.XmlModel;
import org.outerj.pollo.config.*;
+import org.w3c.dom.*;
+
+import com.sun.rsasign.t;
+
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
@@ -11,6 +16,7 @@
import java.awt.*;
import java.awt.event.*;
import java.io.File;
+import java.util.StringTokenizer;
/**
* A dialog from which the user can select a viewtype.
@@ -50,6 +56,7 @@
protected JFileChooser schemaChooser;
protected JFileChooser displaySpecChooser;
+ protected JButton okButton;
public static ViewTypesDialog getInstance()
{
@@ -264,9 +271,10 @@
polloTree = new JRadioButton("Pollo tree");
treeTypeGroup.add(polloTree);
box9.add(polloTree);
- polloTree.setSelected(true);
+ polloTree.setSelected(false);
classicTree = new JRadioButton("Classic tree");
treeTypeGroup.add(classicTree);
+ classicTree.setSelected(true);
box9.add(classicTree);
box9.add(Box.createHorizontalGlue());
displaySpecVertBox.add(box9);
@@ -284,7 +292,7 @@
add(verticalBox, BorderLayout.CENTER);
- JButton okButton = new JButton("Okay");
+ okButton = new JButton("Okay");
okButton.setActionCommand("ok");
okButton.addActionListener(this);
@@ -435,12 +443,45 @@
/**
* @return true if the user selected ok, otherwise false
*/
- public boolean showDialog(Frame parent)
+ public boolean showDialog(Frame parent, XmlModel xmlModel)
{
+ // If document has a schema, select it by default
+ boolean hasSchema = false;
+ String schemaloc = null;
+ Document doc = xmlModel.getDocument();
+ NamedNodeMap attrs = doc.getDocumentElement().getAttributes();
+ try {
+ Node locattr = attrs.getNamedItem("xsi:noNamespaceSchemaLocation");
+ schemaloc = locattr.getNodeValue();
+ hasSchema = true;
+ } catch (Exception e1) {
+ try {
+ Node locattr = attrs.getNamedItem("xsi:schemaLocation");
+ String nslocpair = locattr.getNodeValue();
+ StringTokenizer tokens = new StringTokenizer(nslocpair, " ");
+ tokens.nextToken();
+ schemaloc = tokens.nextToken();
+ hasSchema = true;
+ } catch (Exception e2) {
+ // no schema, forget it
+ }
+ }
+
JDialog dialog = new JDialog(parent, "Select View Type");
dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { ok = false; }});
dialog.setModal(true);
dialog.setContentPane(this);
+
+ if (hasSchema) {
+ //predefinedViewTypeButton.setSelected(false);
+ enableSelectPredefined(false);
+ customViewTypeButton.setSelected(true);
+ autodetectSchemaButton.setSelected(true);
+ enableSelectCustom(true);
+ schemaFileCombo.getEditor().setItem(schemaloc);
+ getRootPane().setDefaultButton(okButton);
+ }
+
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
--
Olivier
Bruno Dumon wrote:
> On Tue, 2004-01-06 at 17:00, Olivier POTONNIEE wrote:
>
>>I eventually did it this way: if a schemaLocation (or
>>noNamespaceSchemaLocation) is detected in the document root element,
>>then it is proposed as the default schema in the configuration panel.
>>I also added the default selection of the "Ok" button, so that the
>>user only has to type "Enter" on keyboard. However the config dialog
>>is still proposed to allow any other configuration.
>>
>>Modifications done to org.outerj.pollo.gui.ViewTypesDialog:
>
>
> Could you please send your patch as an attachment, and use "diff -u" to
> produce a more readable diff?
>
> Thanks very much!
>
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click