예제 #1
0
  static boolean enableDTD2Schema(Context context) {
    Element element = (context != null ? context.getElement() : null);
    boolean bEnable = ((element != null));
    if (bEnable) {
      if (element instanceof TextNode && element.getShortLabel().toUpperCase().endsWith(".DTD"))
        bEnable = true;
      else bEnable = false;
    }
    // In case the Navigator returns nothing, check the Editor
    if (!bEnable) {
      Editor editor = EditorManager.getEditorManager().getCurrentEditor();
      if (editor != null) {
        if (editor.getContext().getNode() instanceof TextNode
            && editor.getContext().getNode().getShortLabel().toUpperCase().endsWith(".DTD")) {
          bEnable = true;
        }
      }
    }

    return bEnable;
  }
예제 #2
0
  private CodeEditor getEditor() {
    if (_editor == null) {
      List editors = EditorManager.getEditorManager().getAllEditors();

      for (int i = 0, size = editors.size(); i < size; i++) {
        oracle.ide.editor.Editor editor = (oracle.ide.editor.Editor) editors.get(i);

        if (editor instanceof CodeEditor) {
          if (_node.equals(editor.getContext().getDocument())) {
            _editor = (CodeEditor) editor;

            break;
          }
        }
      }
    }

    if (_editor != null) {
      return _editor;
    }

    // should never happen
    throw new IllegalStateException("could not find an editor for " + _node);
  }
예제 #3
0
 // <frag href="CustomEditor_setContext.frag">
 public synchronized void setContext(Context context) {
   if (context != null) {
     Element element = context.getElement();
     if (element instanceof XMLSourceNode) {
       super.setContext(context);
       wn = (XMLSourceNode) element;
       if (!wn.isOpen()) {
         try {
           wn.open();
         } catch (Exception ex) {
           ex.printStackTrace();
         }
       }
       view = new CustomEditorJPanel(wn);
     }
   } else {
     System.out.println("Context is null!");
   }
 }
예제 #4
0
  public boolean handleEvent(IdeAction action, Context context) {
    int cmdId = action.getCommandId();
    String msg = "";
    boolean ret = false;

    if (cmdId == DTD_TO_SCHEMA_CMD_ID) {
      TextNode element = null;
      if (context.getElement() != null
          && context.getElement() instanceof TextNode
          && context.getElement().getShortLabel().toUpperCase().endsWith(".DTD"))
        element = (TextNode) context.getElement();
      if (element == null) // Check Editor
      {
        Editor editor = EditorManager.getEditorManager().getCurrentEditor();
        if (editor != null) {
          if (editor.getContext().getNode() instanceof TextNode
              && editor.getContext().getNode().getShortLabel().toUpperCase().endsWith(".DTD")) {
            element = (TextNode) editor.getContext().getNode();
          }
        }
      }
      if (element != null) {
        try {
          final TextNode dtdNode = (TextNode) element;
          // We need:
          //   The root name
          //   The path to the schema to generate
          final Project currentPrj = Ide.getActiveProject();
          final String srcPath = JProjectUtil.getProjectBasePath(currentPrj).getFile().toString();

          if (dp == null) dp = new DialogPanel();
          dp.setDefaultLocation(srcPath);
          // Set the DTD root list
          URL dtdURL = dtdNode.getURL();
          // get the DTD object
          dp.getRootCombo().removeAllItems();
          DTD dtdNoRoot = getDTD(dtdURL, null);
          NamedNodeMap map = dtdNoRoot.getElementDecls();
          for (int i = 0; i < map.getLength(); i++) {
            Node node = map.item(i);
            dp.getRootCombo().addItem(node.getNodeName());
          }
          // Suggest a default name for the schema
          String dtdFullName = dtdNode.getLongLabel();
          String xsdFullName = dtdFullName.substring(0, dtdFullName.lastIndexOf(".dtd")) + ".xsd";
          dp.getSchemaNameFld().setText(xsdFullName);

          JEWTDialog dlg = OnePageWizardDialogFactory.createJEWTDialog(dp, null, "DTD to Schema");
          dlg.addVetoableChangeListener(new LocalVetoableChangeListener());

          dlg.setDefaultButton(JEWTDialog.BUTTON_OK);
          dlg.setOKButtonEnabled(true);

          String topic = "dtd_to_schema_html";
          HelpSystem.getHelpSystem().registerTopic((JComponent) dlg.getContent(), topic);
          boolean go = WizardLauncher.runDialog(dlg);

          if (go) {
            final String root = dp.getRoot();
            final String fName = dp.getSchemaName();

            class SchemaGenerationRunnable implements Runnable {
              XmlSchemaNode xsn = null;
              boolean ok = true;

              public void run() {
                try {
                  URL dtdURL = dtdNode.getURL();
                  // get the DTD object
                  DTD dtd = getDTD(dtdURL, root);
                  // convert DTD to Schema DOM tree
                  XMLDocument dtddoc = dtd.convertDTD2Schema();

                  URL classURL = URLFactory.newURL(fName);
                  if (classURL == null) {
                    JOptionPane.showMessageDialog(
                        null, "Cannot create URL for " + fName, "Ooops", JOptionPane.ERROR_MESSAGE);
                    //                  ok2go.setValue(false);
                    ok = false;
                  } else { // Let's go on
                    xsn = (XmlSchemaNode) NodeFactory.findOrCreate(XmlSchemaNode.class, classURL);
                    currentPrj.add(xsn, true);
                    xsn.open();
                    // Now the Node is created, let's create its content
                    TextBuffer tb = xsn.acquireTextBuffer();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    PrintWriter pw = new PrintWriter(baos);
                    dtddoc.print(pw);
                    String content = baos.toString();
                    tb.beginEdit();
                    tb.append(content.toCharArray());
                    tb.endEdit();
                    ok = true;
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              public boolean isOk() {
                return ok;
              }

              public XmlSchemaNode getXmlSchemaNode() {
                return xsn;
              }
            }
            SchemaGenerationRunnable schemaGeneration = new SchemaGenerationRunnable();
            SchemaGenerationProgress generationProgress =
                new SchemaGenerationProgress(schemaGeneration);
            final String LABEL = "Converting...";
            ProgressBar progress =
                new ProgressBar(Ide.getMainWindow(), LABEL, generationProgress, true);
            generationProgress.setProgressBar(progress);
            progress.start("Please wait", "");
            // reset
            generationProgress = null;
            progress = null;
            if (schemaGeneration.isOk()) {
              // Open the created node
              EditorManager.getEditorManager()
                  .openDefaultEditorInFrame(schemaGeneration.getXmlSchemaNode().getURL());
              // Add the compilation date
              SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:dd a"); // NOTRANS
              msg += ("Schema generation [" + sdf.format(new Date()) + "] " + " successful.");
              // Display message in log window.
              logMessage(msg);
              msg = ""; // reset
            }
          }
          ret = true;
        } catch (Exception ex) {
          logMessage("Error:" + ex.toString());
          ex.printStackTrace();
        }
      } else logMessage("element is null");
    }
    if (msg != null && msg.trim().length() > 0) {
      logMessage(msg);
      //    Ide.getStatusBar().setText(msg);
      ret = true;
    }
    return ret;
  }
예제 #5
0
 public void close() {
   view.setVisible(false);
   super.close();
 }