Exemplo n.º 1
0
 @Override
 protected void updateItem(boolean accept, Object... params) {
   String function = param(null, 0, params);
   boolean refresh = function == null;
   if (refresh) function = getFunction();
   Element element = select(function);
   if (element != null) {
     String body = textArea.getText();
     if (accept) {
       NodeList nodes = evaluateXPath(element, "./BODY/text()");
       if (nodes != null && nodes.getLength() > 0) {
         Node node = nodes.item(0);
         CDATASection cdata = ProfileManager.transports.createCDATASection(body);
         node.getParentNode().replaceChild(cdata, node);
         updateModel(refresh, true, true);
       }
     } else if (refresh) setFunction(function);
   }
 }
Exemplo n.º 2
0
 @Override
 protected boolean addItem(boolean refresh, Object function) {
   if (ProfileManager.transportsLoaded()) {
     String body = textArea.getText();
     if (notNullOrEmpty(body)) {
       Element element = ProfileManager.transports.createElement("FUNCTION");
       element.setAttribute("name", stringValueOf(function));
       if (notNullOrEmpty(profile)) element.setAttribute("profile", profile);
       Element el = ProfileManager.transports.createElement("BODY");
       CDATASection cdata = ProfileManager.transports.createCDATASection(body);
       el.appendChild(cdata);
       element.appendChild(el);
       select().appendChild(element);
       updateModel(true, true, true, function);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 3
0
  private void createUI(final Component parent, final Container container) {
    comboBoxes = new JComboBox[] {new JComboBox()};
    textArea = new TextToggle().createBufferedTextArea("beanshell", "/modes/java.xml");

    JToolBar bar = new JToolBar();
    container.add(bar, BorderLayout.NORTH);
    final RolloverButton btn =
        createButton(
            bar,
            ACCEPT_BUTTON_KEY,
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                save(getItem(), false);
                Window window = SwingUtilities.getWindowAncestor(container);
                if (window != null) window.dispose();
              }
            });
    comboBoxes[0].addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
              String function = getFunction();
              if (select(function) != null) setFunction(function);
              else setDirty(true);
            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
              String item = stringValueOf(ev.getItem());
              save(item, false);
            }
          }
        });
    comboBoxes[0].setEditable(true);
    comboEdit(0).setHorizontalAlignment(JTextField.CENTER);
    bar.add(comboBoxes[0]);
    comboEdit(0)
        .addKeyListener(
            new KeyAdapter() {
              @Override
              public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                  btn.doClick();
                }
              }
            });
    installAddRemove(bar, "function");
    installUpdate(bar);
    final RolloverButton test = new RolloverButton();
    test.setText("Test");
    test.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            testThis(parent, container, comboEdit(0).getText());
          }
        });
    test.setEnabled(findAllIn(selector, Pattern.compile("/")).length < 2);
    bar.add(test);
    textArea.setOnTextChanged(
        new Job<JComponent>() {
          public void perform(JComponent t, Object[] params) throws Exception {
            setDirty(true);
          }
        });
    container.add(textArea.getUIComponent(), BorderLayout.CENTER);
    mess = new JLabel();
    mess.setHorizontalAlignment(JTextField.CENTER);
    container.add(mess, BorderLayout.SOUTH);
    updateModel(true, false, false);
  }