home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xa / OverviewPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  18.6 KB  |  491 lines

  1. package com.extensibility.xa;
  2.  
  3. import com.extensibility.app.BaseAction;
  4. import com.extensibility.app.BaseDocument;
  5. import com.extensibility.app.BaseEdit;
  6. import com.extensibility.app.BaseUndoable;
  7. import com.extensibility.app.DialogFactory;
  8. import com.extensibility.app.OpenURIDialog;
  9. import com.extensibility.app.SaveURIDialog;
  10. import com.extensibility.app.UI;
  11. import com.extensibility.plugin.api.URIVersionedAccess;
  12. import com.extensibility.rock.RBevelBorder;
  13. import com.extensibility.rock.RButton;
  14. import com.extensibility.rock.Screen;
  15. import com.extensibility.rock.ScrollPop;
  16. import com.extensibility.xa.undo.ClearDeclsUndoable;
  17. import com.extensibility.xml.BaseDeclaration;
  18. import com.extensibility.xml.DTDUtilities;
  19. import com.extensibility.xml.ExternalPEDeclaration;
  20. import com.extensibility.xml.ExternalSubset;
  21. import com.extensibility.xml.InternalPEDeclaration;
  22. import com.extensibility.xml.NamespaceDeclaration;
  23. import com.extensibility.xml.Schema;
  24. import com.extensibility.xml.SchemaFlavorIntf;
  25. import com.extensibility.xml.SchemaIntf;
  26. import com.extensibility.xml.SchemaUtilities;
  27. import com.extensibility.xml.URI;
  28. import java.awt.Component;
  29. import java.awt.GridBagConstraints;
  30. import java.awt.GridBagLayout;
  31. import java.awt.datatransfer.Clipboard;
  32. import java.awt.datatransfer.ClipboardOwner;
  33. import java.awt.datatransfer.DataFlavor;
  34. import java.awt.datatransfer.Transferable;
  35. import java.awt.event.MouseEvent;
  36. import java.io.FileNotFoundException;
  37. import java.io.IOException;
  38. import java.io.Writer;
  39. import java.net.UnknownHostException;
  40. import java.util.Enumeration;
  41. import java.util.Vector;
  42. import javax.swing.Icon;
  43. import javax.swing.JComponent;
  44. import javax.swing.JPanel;
  45. import javax.swing.JPopupMenu;
  46. import javax.swing.JScrollPane;
  47. import javax.swing.event.MouseInputAdapter;
  48. import javax.swing.tree.DefaultMutableTreeNode;
  49. import javax.swing.tree.DefaultTreeModel;
  50. import javax.swing.tree.TreePath;
  51.  
  52. public class OverviewPane extends CompositePane implements ClipboardOwner {
  53.    public CutAction cutAction;
  54.    public CopyAction copyAction;
  55.    public PasteAction pasteAction;
  56.    public ClearAction clearAction;
  57.    Icon icnElement = UI.getIcon("tbElem.gif");
  58.    Icon icnAttribute = UI.getIcon("tbAttr.gif");
  59.    Icon icnPE = UI.getIcon("tbPE.gif");
  60.    Icon icnGE = UI.getIcon("tbGE.gif");
  61.    Icon icnNotation = UI.getIcon("tbNT.gif");
  62.    Icon icnSubset = UI.getIcon("uri.gif");
  63.    Icon icnSubsetRO = UI.getIcon("uri_ro.gif");
  64.    Icon icnPI = UI.getIcon("tbPI.gif");
  65.    Icon icnMSO = null;
  66.    Icon icnMSC = null;
  67.    Icon icnNamespace = UI.getIcon("tbNS.gif");
  68.    Icon icnDataType = UI.getIcon("tbDT.gif");
  69.    JPanel panel;
  70.    JScrollPane scrollTree;
  71.    OverTree tree;
  72.    BaseDeclaration currentDecl;
  73.    OverTreeModel treeModel;
  74.    MouseInputAdapter treeMouseInputListener = new 1(this);
  75.    ImportAction importAction = new ImportAction(this);
  76.    IncludeAction includeAction = new IncludeAction(this);
  77.    SchemaDocListener schemaListener = new 8(this);
  78.  
  79.    public OverviewPane(SchemaDoc var1) {
  80.       super(var1);
  81.       this.prepare();
  82.       this.cutAction = new CutAction(this);
  83.       this.copyAction = new CopyAction(this);
  84.       this.pasteAction = new PasteAction(this);
  85.       this.clearAction = new ClearAction(this);
  86.       this.tree.updateTree(this.getShowDecls());
  87.    }
  88.  
  89.    protected void doPopup(MouseEvent var1) {
  90.       TreePath var2 = this.tree.getClosestPathForLocation(var1.getX(), var1.getY());
  91.       if (var2 != null) {
  92.          BaseDeclaration var3 = this.getDeclOfPath(var2);
  93.          if (var3 != null) {
  94.             this.tree.setSelectionPath(var2);
  95.             boolean var4 = true;
  96.             if (var3 instanceof ExternalSubset && ((ExternalSubset)var3).getParent() == null) {
  97.                var4 = false;
  98.             }
  99.  
  100.             ScrollPop var5 = new ScrollPop();
  101.             if (var4) {
  102.                ((JPopupMenu)var5).add(this.cutAction);
  103.             }
  104.  
  105.             ((JPopupMenu)var5).add(this.copyAction);
  106.             ((JPopupMenu)var5).add(this.pasteAction);
  107.             if (var4) {
  108.                ((JPopupMenu)var5).add(this.clearAction);
  109.             }
  110.  
  111.             ((JPopupMenu)var5).addSeparator();
  112.             ((JPopupMenu)var5).add(((CompositePane)this).getSchemaWin().createGotoAction(var3));
  113.             if (var3 instanceof ExternalSubset && ((ExternalSubset)var3).getParent() != null) {
  114.                ((JPopupMenu)var5).addSeparator();
  115.                URI var6 = ((ExternalSubset)var3).getSystemURI();
  116.                URIVersionedAccess var7 = (URIVersionedAccess)var6.getInterface(Class.forName("com.extensibility.plugin.api.URIVersionedAccess"));
  117.                if (var7 != null) {
  118.                }
  119.  
  120.                if (((CompositePane)this).getSchemaDoc().isEditable(var6)) {
  121.                   ((JPopupMenu)var5).add(this.createLockURIAction(var6, var3));
  122.                   ((CompositePane)this).getSchemaWin().buildModuleChangerItems(var3, var6, var5);
  123.                } else {
  124.                   ((JPopupMenu)var5).add(this.createUnlockURIAction(var6, var3));
  125.                }
  126.             }
  127.  
  128.             ((JPopupMenu)var5).show(this.tree, var1.getX(), var1.getY());
  129.          }
  130.       }
  131.    }
  132.  
  133.    protected BaseAction createCheckinAction(URI var1, BaseDeclaration var2) {
  134.       return new 2(var1, var2, this, "pop.uri.checkin", var1.getShortName());
  135.    }
  136.  
  137.    protected BaseAction createUncheckoutAction(URI var1, BaseDeclaration var2) {
  138.       return new 3(var1, var2, this, "pop.uri.uncheckout", var1.getShortName());
  139.    }
  140.  
  141.    protected BaseAction createCheckoutAction(URI var1, BaseDeclaration var2) {
  142.       return new 4(var1, var2, this, "pop.uri.checkout", var1.getShortName());
  143.    }
  144.  
  145.    protected BaseAction createUnlockURIAction(URI var1, BaseDeclaration var2) {
  146.       return new 5(var1, var2, this, "pop.uri.set.editable", var1.getShortName());
  147.    }
  148.  
  149.    protected BaseAction createLockURIAction(URI var1, BaseDeclaration var2) {
  150.       return new 6(var1, var2, this, "pop.uri.set.non.editable", var1.getShortName());
  151.    }
  152.  
  153.    public void updateTreeModel(BaseDeclaration var1) {
  154.       DefaultMutableTreeNode var2 = this.treeModel.findNode(var1);
  155.       if (var2 != null) {
  156.          DefaultTreeModel var3 = (DefaultTreeModel)this.tree.getModel();
  157.          var3.nodeChanged(var2);
  158.       }
  159.  
  160.    }
  161.  
  162.    public String getClassName() {
  163.       return "com.extensibility.xa.OverviewPane";
  164.    }
  165.  
  166.    public JComponent getComponent() {
  167.       return this.scrollTree;
  168.    }
  169.  
  170.    private void prepare() {
  171.       this.panel = new JPanel(new GridBagLayout());
  172.       this.panel.setBorder(new RBevelBorder(1));
  173.       GridBagConstraints var1 = new GridBagConstraints();
  174.       var1.weightx = (double)0.5F;
  175.       var1.fill = 2;
  176.       var1.weightx = (double)1.0F;
  177.       var1.gridwidth = 2;
  178.       var1.gridx = 0;
  179.       this.treeModel = new OverTreeModel(((CompositePane)this).getSchemaDoc());
  180.       this.tree = new OverTree(this.treeModel);
  181.       this.tree.setFont(UI.getDocFont());
  182.       this.tree.setCellRenderer(new DeclRenderer(this));
  183.       this.tree.addMouseListener(this.treeMouseInputListener);
  184.       this.tree.addMouseMotionListener(this.treeMouseInputListener);
  185.       this.scrollTree = new JScrollPane(this.tree);
  186.       var1.gridy = 1;
  187.       var1.fill = 1;
  188.       var1.weighty = (double)1.0F;
  189.       this.panel.add(this.scrollTree, var1);
  190.       this.setButtonsOnFlavor();
  191.       this.tree.addTreeSelectionListener(new 7(this));
  192.       ((CompositePane)this).getSchemaDoc().addDocumentListener(this.schemaListener);
  193.       this.setButtonsOnFlavor();
  194.    }
  195.  
  196.    private BaseDeclaration getDeclOfPath(TreePath var1) {
  197.       if (var1 == null) {
  198.          return null;
  199.       } else {
  200.          Object var2 = var1.getLastPathComponent();
  201.          return var2 instanceof DefaultMutableTreeNode ? (BaseDeclaration)((DefaultMutableTreeNode)var2).getUserObject() : null;
  202.       }
  203.    }
  204.  
  205.    boolean getShowDecls() {
  206.       return true;
  207.    }
  208.  
  209.    public void declarationFocused(BaseDeclaration var1) {
  210.       this.currentDecl = var1;
  211.       super.declarationFocused(var1);
  212.    }
  213.  
  214.    protected boolean hasDeclTable() {
  215.       return false;
  216.    }
  217.  
  218.    protected void doInclude() {
  219.       SchemaDoc var1 = ((CompositePane)this).getSchemaDoc();
  220.       SchemaIntf var2 = var1.getSchema();
  221.       SchemaFlavorIntf var3 = var2.getFlavor();
  222.       String var4 = var3.getFlavorName();
  223.       ExternalSubset var5 = this.currentDecl == null ? null : var2.getStructure().findParent(this.currentDecl.getURI());
  224.       if (var5 != null && !var1.isEditable(var5.getSystemURI())) {
  225.          DialogFactory.stop(this.getComponent(), UI.getString("stop.ro.dest.uri", this.currentDecl.getURI().getShortName()));
  226.       } else if (!var3.isSupported(Class.forName("com.extensibility.xml.ExternalSubset"))) {
  227.          ((CompositePane)this).beep();
  228.       } else {
  229.          OpenURIDialog var6 = new OpenURIDialog(((CompositePane)this).getSchemaWin(), ((BaseDocument)var1).getURI(), new String[]{var4}, true);
  230.          ((SaveURIDialog)var6).show();
  231.          URI var7 = ((SaveURIDialog)var6).getURI();
  232.          boolean var8 = var6.isNew();
  233.          if (var7 != null) {
  234.             if (var8) {
  235.                try {
  236.                   Schema var9 = new Schema(var7, var3.getFlavorName());
  237.                   Writer var10 = var7.createWriter();
  238.                   var9.write(var10);
  239.                   var10.close();
  240.                } catch (FileNotFoundException var12) {
  241.                   DialogFactory.stop(this.getComponent(), UI.getString("stop.bad.module.name", var7.getShortName()));
  242.                   return;
  243.                } catch (IOException var13) {
  244.                   DialogFactory.showException(((CompositePane)this).getSchemaWin(), 133, var13);
  245.                   return;
  246.                }
  247.             }
  248.  
  249.             String var14 = DTDUtilities.generateValidName(var7.getShortName());
  250.             if (!SchemaUtilities.compatibleFlavor(var3, var7, true)) {
  251.                String var17 = SchemaUtilities.getFlavor(var7, true);
  252.                DialogFactory.stop(this.getComponent(), UI.getString("stop.wrong.flavor", var17 == null ? "" : var17));
  253.             } else if (!var1.isSupported("GESTALT_MULTI_INSTANCE_MODULES") && var1.getStructure().findParent(var7) != null) {
  254.                DialogFactory.stop(this.getComponent(), UI.getString("stop.module.exists", var7.toSource()));
  255.             } else if (var1.getName().equals(var14)) {
  256.                DialogFactory.stop(this.getComponent(), UI.getString("error.name.exists", var14));
  257.             } else {
  258.                if (!var1.isSupported("GESTALT_MULTI_INSTANCE_MODULES")) {
  259.                   String var15 = var14;
  260.  
  261.                   for(int var11 = 2; var1.getNamedDeclaration(var14, Class.forName("com.extensibility.xml.ParameterEntityDeclaration")) != null; var14 = String.valueOf(var15).concat(String.valueOf(var11++))) {
  262.                   }
  263.                }
  264.  
  265.                AddModuleUndoable var16 = new AddModuleUndoable(this, ((CompositePane)this).getSchemaWin(), var7, var1.getFocusedURI(true), var14);
  266.                ((BaseDocument)var1).getUndoManager().addEdit(var16);
  267.                var16.doCommand();
  268.                if (var8) {
  269.                   var1.unlockModule(var7);
  270.                }
  271.  
  272.             }
  273.          }
  274.       }
  275.    }
  276.  
  277.    protected void doImport() {
  278.       SchemaFlavorIntf var1 = ((CompositePane)this).getSchemaDoc().getSchema().getFlavor();
  279.       String var2 = var1.getFlavorName();
  280.       if (!var1.isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration"))) {
  281.          ((CompositePane)this).beep();
  282.       } else {
  283.          URI var3 = DialogFactory.openURI(this.getComponent(), ((CompositePane)this).getSchemaDoc().getURI(), new String[]{var2}, UI.getString("overview.import"));
  284.          if (var3 != null) {
  285.             String var4 = DTDUtilities.makeValidName(var3.getShortName());
  286.             if (var3.exists() && !SchemaUtilities.compatibleFlavor(var1, var3, true)) {
  287.                DialogFactory.stop(this.getComponent(), UI.getString("stop.wrong.flavor", SchemaUtilities.getFlavor(var3, true)));
  288.             } else {
  289.                BaseUndoable var5 = this.createAddNamespaceUndoable(var3, ((CompositePane)this).getSchemaDoc().getFocusedURI(true));
  290.                ((CompositePane)this).getSchemaDoc().getUndoManager().addEdit(var5);
  291.                ((BaseEdit)var5).doCommand();
  292.             }
  293.          }
  294.       }
  295.    }
  296.  
  297.    public BaseUndoable createAddNamespaceUndoable(URI var1, URI var2) {
  298.       return new AddNamespaceUndoable(this, ((CompositePane)this).getSchemaWin(), var1, var2);
  299.    }
  300.  
  301.    protected NamespaceDeclaration doAddNamespace(String var1, URI var2, URI var3) {
  302.       NamespaceDeclaration var4 = new NamespaceDeclaration(var1, var2.toSource());
  303.       ((BaseDeclaration)var4).setURI(var3);
  304.       ((CompositePane)this).getSchemaDoc().insertDeclaration(var4, (BaseDeclaration)null);
  305.       return var4;
  306.    }
  307.  
  308.    protected ExternalPEDeclaration doAddModule(URI var1, URI var2, String var3) {
  309.       ExternalPEDeclaration var4 = new ExternalPEDeclaration(var3, (String)null, var1);
  310.       ((BaseDeclaration)var4).setURI(var2);
  311.       ((CompositePane)this).getSchemaDoc().insertDeclaration(var4, this.currentDecl);
  312.  
  313.       try {
  314.          int var5 = ((CompositePane)this).getSchemaDoc().insertSubset(var4);
  315.          if (var5 > 0) {
  316.             DialogFactory.caution((Component)null, UI.getString("caution.extsubset.errors", (new Integer(var5)).toString(), ((BaseDeclaration)var4).getName()));
  317.          }
  318.  
  319.          ExternalSubset var6 = (ExternalSubset)((CompositePane)this).getSchemaDoc().getNamedDeclaration(((BaseDeclaration)var4).getName(), Class.forName("com.extensibility.xml.ExternalSubset"));
  320.          this.select(var6);
  321.       } catch (UnknownHostException var7) {
  322.          DialogFactory.note((Component)null, UI.getString("note.url.not.found", var1.getFullName()));
  323.       } catch (FileNotFoundException var8) {
  324.          DialogFactory.note(this.getComponent(), UI.getString("note.uri.not.found", var1.getShortName()));
  325.       } catch (IOException var9) {
  326.          DialogFactory.showException((Component)null, 107, var9);
  327.       }
  328.  
  329.       return var4;
  330.    }
  331.  
  332.    protected void doRemove() {
  333.       if (this.currentDecl != null && this.currentDecl != ((CompositePane)this).getSchemaDoc().getStructure()) {
  334.          if (!((CompositePane)this).getSchemaDoc().isEditable(this.currentDecl)) {
  335.             DialogFactory.showException(this.getComponent(), 106, UI.getString("error.decl.not.editable"), this.currentDecl.getName());
  336.          } else {
  337.             if (this.currentDecl instanceof InternalPEDeclaration) {
  338.                Enumeration var1 = ((CompositePane)this).getSchemaDoc().getUsedBy((InternalPEDeclaration)this.currentDecl);
  339.                if (var1.hasMoreElements()) {
  340.                   String var2 = UI.getString("stop.delete.in.use", this.currentDecl.getName(), ((BaseDeclaration)var1.nextElement()).getName());
  341.                   DialogFactory.stop(this.getComponent(), var2);
  342.                   return;
  343.                }
  344.             }
  345.  
  346.             ClearDeclsUndoable var3 = this.createRemoveDeclUndoable(this.currentDecl);
  347.             var3.doCommand();
  348.             ((CompositePane)this).getSchemaDoc().getUndoManager().addEdit(var3);
  349.             this.currentDecl = null;
  350.          }
  351.       } else {
  352.          ((CompositePane)this).beep();
  353.       }
  354.    }
  355.  
  356.    public ClearDeclsUndoable createRemoveDeclUndoable(BaseDeclaration var1) {
  357.       return new TreeRemoveDeclsUndoable((OverviewPane)null, var1, ((CompositePane)this).getSchemaWin());
  358.    }
  359.  
  360.    protected void doRemoveNamespace(NamespaceDeclaration var1) {
  361.       if (var1 == null) {
  362.          ((CompositePane)this).beep();
  363.       } else {
  364.          ((CompositePane)this).getSchemaDoc().removeDeclaration(var1);
  365.       }
  366.    }
  367.  
  368.    protected void doRemoveDecl(BaseDeclaration var1) {
  369.       if (var1 == null) {
  370.          ((CompositePane)this).beep();
  371.       } else {
  372.          if (var1 instanceof ExternalSubset) {
  373.             ((CompositePane)this).getSchemaDoc().removeSubset((ExternalSubset)var1);
  374.          } else {
  375.             ((CompositePane)this).getSchemaDoc().removeDeclaration(var1);
  376.             if (var1 instanceof ExternalPEDeclaration) {
  377.                ExternalSubset var2 = (ExternalSubset)((CompositePane)this).getSchemaDoc().getNamedDeclaration(var1.getName(), Class.forName("com.extensibility.xml.ExternalSubset"));
  378.                ((CompositePane)this).getSchemaDoc().removeSubset(var2);
  379.             }
  380.          }
  381.  
  382.       }
  383.    }
  384.  
  385.    public boolean select(BaseDeclaration var1) {
  386.       if (var1 == null) {
  387.          this.tree.clearSelection();
  388.          return false;
  389.       } else {
  390.          DefaultMutableTreeNode var2 = this.treeModel.findNode(var1);
  391.          if (var2 != null) {
  392.             DefaultTreeModel var3 = (DefaultTreeModel)this.tree.getModel();
  393.             TreePath var4 = new TreePath(var3.getPathToRoot(var2));
  394.             this.tree.setSelectionPath(var4);
  395.             return true;
  396.          } else {
  397.             return false;
  398.          }
  399.       }
  400.    }
  401.  
  402.    public void cut() {
  403.       this.copy();
  404.       this.clear();
  405.    }
  406.  
  407.    public void copy() {
  408.       Clipboard var1 = Screen.getClip();
  409.       BaseDeclaration var2 = this.getDeclOfPath(this.tree.getLeadSelectionPath());
  410.       if (var2 != null && !(var2 instanceof ExternalSubset)) {
  411.          ClipData var3 = new ClipData(((CompositePane)this).getSchemaDoc(), var2);
  412.          var1.setContents(var3, this);
  413.       } else {
  414.          ((CompositePane)this).beep();
  415.       }
  416.    }
  417.  
  418.    public void paste() {
  419.       ((CompositePane)this).getSchemaDoc().touch(((CompositePane)this).getSchemaDoc().getFocusedURI(true));
  420.       Clipboard var1 = Screen.getClip();
  421.       Transferable var2 = var1.getContents(this);
  422.       if (var2 != null && var2 instanceof ClipData) {
  423.          try {
  424.             BaseDeclaration var3 = this.getDeclOfPath(this.tree.getLeadSelectionPath());
  425.             Object var4 = null;
  426.             Vector var5 = (Vector)var2.getTransferData((DataFlavor)null);
  427.  
  428.             for(int var6 = 0; var6 < var5.size(); ++var6) {
  429.                BaseDeclaration var7 = (BaseDeclaration)var5.elementAt(var6);
  430.                if (var6 == 0) {
  431.                   ;
  432.                }
  433.  
  434.                if (var7 instanceof ExternalSubset) {
  435.                   ((CompositePane)this).beep();
  436.                } else {
  437.                   ((CompositePane)this).getSchemaDoc().insertDeclaration(var7, var3, (Boolean)null, (Boolean)null, ((ClipData)var2).getSchemaDoc());
  438.                }
  439.             }
  440.          } catch (Exception var8) {
  441.             DialogFactory.showException(this.getComponent(), 100, var8);
  442.          }
  443.  
  444.       } else {
  445.          ((CompositePane)this).beep();
  446.       }
  447.    }
  448.  
  449.    public void clear() {
  450.       ((CompositePane)this).getSchemaDoc().touch(this.currentDecl);
  451.       this.doRemove();
  452.    }
  453.  
  454.    public void lostOwnership(Clipboard var1, Transferable var2) {
  455.    }
  456.  
  457.    private void setButtonsOnFlavor() {
  458.       SchemaIntf var1 = ((CompositePane)this).getSchemaDoc().getSchema();
  459.       SchemaFlavorIntf var2 = var1.getFlavor();
  460.       RButton var3 = null;
  461.       RButton var4 = null;
  462.       if (var2.isSupported(Class.forName("com.extensibility.xml.ExternalSubset"))) {
  463.          var4 = new RButton(this.includeAction);
  464.       }
  465.  
  466.       if (var2.isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration"))) {
  467.          if (var4 == null) {
  468.             var4 = new RButton(this.importAction);
  469.          } else {
  470.             var3 = new RButton(this.importAction);
  471.          }
  472.       }
  473.  
  474.       CompositePane.setHeader(this.scrollTree, var3, var4);
  475.    }
  476.  
  477.    public void focusDeclaration(BaseDeclaration var1) {
  478.       this.select(var1);
  479.    }
  480.  
  481.    // $FF: synthetic method
  482.    static void access$2000171(OverviewPane var0) {
  483.       var0.setButtonsOnFlavor();
  484.    }
  485.  
  486.    // $FF: synthetic method
  487.    static BaseDeclaration access$2000071(OverviewPane var0, TreePath var1) {
  488.       return var0.getDeclOfPath(var1);
  489.    }
  490. }
  491.