Exemplo n.º 1
0
  @Override
  public void action(final Object comp) {
    final boolean valid = general.action(comp, true);
    ft.action(ftxindex.isSelected());

    // ...must be located before remaining checks
    if (comp == general.browse || comp == general.input) dbname.setText(general.dbname);

    final String nm = dbname.getText().trim();
    ok = valid && !nm.isEmpty();

    String inf = valid ? ok ? null : ENTER_DB_NAME : RES_NOT_FOUND;
    Msg icon = Msg.ERROR;
    if (ok) {
      ok = Databases.validName(nm);
      if (ok) gui.gopts.set(GUIOptions.DBNAME, nm);

      if (!ok) {
        // name of database is invalid
        inf = Util.info(INVALID_X, NAME);
      } else if (general.input.getText().trim().isEmpty()) {
        // database will be empty
        inf = EMPTY_DB;
        icon = Msg.WARN;
      } else if (db.contains(nm)) {
        // old database will be overwritten
        inf = OVERWRITE_DB;
        icon = Msg.WARN;
      }
    }

    general.info.setText(inf, icon);
    enableOK(buttons, B_OK, ok);
  }
Exemplo n.º 2
0
  @Override
  public void action(final Object cmp) {
    for (int i = 1; i < EDITKIND.length; ++i) if (radio[i].isSelected()) kind = i;
    gui.gprop.set(GUIProp.LASTINSERT, kind);

    String msg = null;
    ok = kind != Data.TEXT || input2.getText().length != 0;
    if (kind != Data.TEXT && kind != Data.COMM) {
      ok = XMLToken.isQName(token(input1.getText()));
      if (!ok && !input1.getText().isEmpty()) msg = Util.info(INVALID, EDITNAME);
    }
    info.setText(msg, Msg.ERROR);
    enableOK(buttons, BUTTONOK, ok);
  }
Exemplo n.º 3
0
 /**
  * Adds a text field.
  *
  * @param pos position
  */
 private void addInput(final int pos) {
   final BaseXTextField txt = new BaseXTextField(gui);
   BaseXLayout.setWidth(txt, COMPW);
   BaseXLayout.setHeight(txt, txt.getFont().getSize() + 11);
   txt.setMargin(new Insets(0, 0, 0, 10));
   txt.addKeyListener(
       new KeyAdapter() {
         @Override
         public void keyReleased(final KeyEvent e) {
           query(false);
         }
       });
   txt.addKeyListener(main);
   panel.add(txt, pos);
 }
Exemplo n.º 4
0
 /**
  * Returns the current serialization options.
  *
  * @param mth consider specified serialization method (may be {@code null})
  * @return options
  * @throws BaseXException database exception
  */
 private SerializerOptions options(final SerialMethod mth) throws BaseXException {
   final SerializerOptions sopts = new SerializerOptions();
   sopts.assign(params.getText());
   sopts.set(SerializerOptions.METHOD, SerialMethod.valueOf(method.getSelectedItem()));
   sopts.set(SerializerOptions.ENCODING, encoding.getSelectedItem());
   if (mth == SerialMethod.JSON) {
     final JsonSerialOptions jopts = new JsonSerialOptions();
     jopts.assign(mparams.getText());
     sopts.set(SerializerOptions.JSON, jopts);
   } else if (mth == SerialMethod.CSV) {
     final CsvOptions copts = new CsvOptions();
     copts.assign(mparams.getText());
     sopts.set(SerializerOptions.CSV, copts);
   }
   return sopts;
 }
Exemplo n.º 5
0
  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogInsert(final GUI main) {
    super(main, INSERTTITLE);

    label1 = new BaseXLabel(EDITNAME + COLS, true, true).border(0, 0, 0, 0);
    label2 = new BaseXLabel(EDITVALUE + COLS, true, true).border(0, 0, 0, 0);

    input1 = new BaseXTextField(this);
    input1.addKeyListener(keys);
    BaseXLayout.setWidth(input1, 320);

    input2 = new BaseXEditor(true, this);
    input2.setFont(GUIConstants.mfont);
    input2.addKeyListener(keys);
    BaseXLayout.setWidth(input2, 320);

    final BaseXBack knd = new BaseXBack(new TableLayout(1, 5));
    final ButtonGroup group = new ButtonGroup();

    final ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            change(e.getSource());
          }
        };

    final int lkind = gui.gprop.num(GUIProp.LASTINSERT);
    radio = new BaseXRadio[EDITKIND.length];
    for (int i = 1; i < EDITKIND.length; ++i) {
      radio[i] = new BaseXRadio(EDITKIND[i], false, this);
      radio[i].addActionListener(al);
      radio[i].setSelected(i == lkind);
      radio[i].addKeyListener(keys);
      group.add(radio[i]);
      knd.add(radio[i]);
    }
    set(knd, BorderLayout.NORTH);

    back = new BaseXBack(10, 0, 0, 0);
    set(back, BorderLayout.CENTER);

    final BaseXBack pp = new BaseXBack(new BorderLayout());
    info = new BaseXLabel(" ").border(8, 0, 2, 0);
    pp.add(info, BorderLayout.WEST);

    buttons = okCancel(this);
    pp.add(buttons, BorderLayout.EAST);
    set(pp, BorderLayout.SOUTH);

    setResizable(true);
    change(radio[lkind]);

    action(null);
    finish(null);
  }
Exemplo n.º 6
0
  /**
   * Default constructor.
   *
   * @param m main panel
   */
  ExploreArea(final ExploreView m) {
    super(m.gui);
    main = m;

    layout(new BorderLayout(0, 5)).mode(Fill.NONE);

    all = new BaseXTextField(gui);
    all.addKeyListener(main);
    all.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(final KeyEvent e) {
            query(false);
          }
        });
    add(all, BorderLayout.NORTH);

    panel = new BaseXBack(GUIConstants.Fill.NONE).layout(new TableLayout(20, 2, 10, 5));
    add(panel, BorderLayout.CENTER);
  }
Exemplo n.º 7
0
  @Override
  public void close() {
    try {
      gui.set(MainOptions.EXPORTER, options(SerialMethod.valueOf(method.getSelectedItem())));
    } catch (final BaseXException ex) {
      throw Util.notExpected(ex);
    }
    if (!ok) return;

    super.close();
    path.store();
  }
Exemplo n.º 8
0
  @Override
  public void action(final Object comp) {
    final String pth = path();
    final IOFile io = new IOFile(pth);
    String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null;
    ok = !pth.isEmpty();

    final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem());
    final OptionsOption<? extends Options> opts =
        mth == SerialMethod.JSON
            ? SerializerOptions.JSON
            : mth == SerialMethod.CSV ? SerializerOptions.CSV : null;
    final boolean showmparams = opts != null;
    mparams.setEnabled(showmparams);

    if (ok) {
      gui.gopts.set(GUIOptions.INPUTPATH, pth);
      try {
        if (comp == method) {
          if (showmparams) {
            final Options mopts = options(null).get(opts);
            mparams.setToolTipText(tooltip(mopts));
            mparams.setText(mopts.toString());
          } else {
            mparams.setToolTipText(null);
            mparams.setText("");
          }
        }
        Serializer.get(new ArrayOutput(), options(mth));
      } catch (final IOException ex) {
        ok = false;
        inf = ex.getMessage();
      }
    }

    info.setText(inf, ok ? Msg.WARN : Msg.ERROR);
    enableOK(buttons, B_OK, ok);
  }
Exemplo n.º 9
0
  @Override
  public void paintComponent(final Graphics g) {
    super.paintComponent(g);
    final Data data = gui.context.data();
    if (!main.visible() || data == null) return;

    final boolean pi = data.meta.pathindex;
    if (!pi || panel.getComponentCount() != 0) {
      if (!pi) init();
      return;
    }
    if (!pi) return;

    all.help(HELPSEARCHXML);
    addKeys(gui.context.data());
    panel.revalidate();
    panel.repaint();
  }
Exemplo n.º 10
0
  @Override
  public void close() {
    super.close();

    final String in1 = input1.getText();
    final String in2 = string(input2.getText());
    switch (kind) {
      case Data.ATTR:
      case Data.PI:
        result.add(in1);
        result.add(in2);
        break;
      case Data.ELEM:
        result.add(in1);
        break;
      case Data.TEXT:
      case Data.COMM:
        result.add(in2);
        break;
    }
  }
Exemplo n.º 11
0
  @Override
  public void close() {
    final MainProp mprop = gui.context.mprop;
    mprop.set(MainProp.LANG, lang.getSelectedItem().toString());

    // new database path: close existing database
    final String dbpath = path.getText();
    if (!mprop.get(MainProp.DBPATH).equals(dbpath)) gui.execute(new Close());
    mprop.set(MainProp.DBPATH, dbpath);
    mprop.write();

    final int mh = hitsAsProperty();
    gui.context.prop.set(Prop.MAXHITS, mh);

    final GUIProp gprop = gui.gprop;
    gprop.set(GUIProp.MOUSEFOCUS, focus.isSelected());
    gprop.set(GUIProp.SIMPLEFD, simpfd.isSelected());
    gprop.set(GUIProp.JAVALOOK, javalook.isSelected());
    gprop.set(GUIProp.MAXHITS, mh);
    gprop.write();
    dispose();
  }
Exemplo n.º 12
0
  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogExport(final GUI main) {
    super(main, EXPORT);

    // create checkboxes
    final BaseXBack p = new BaseXBack(new TableLayout(4, 1, 0, 0));
    p.add(new BaseXLabel(OUTPUT_DIR + COL, true, true).border(0, 0, 6, 0));

    // output label
    BaseXBack pp = new BaseXBack(new TableLayout(1, 2, 8, 0));

    path = new BaseXTextField(main.gopts.get(GUIOptions.INPUTPATH), this);
    pp.add(path.history(GUIOptions.INPUTS, this));

    final BaseXButton browse = new BaseXButton(BROWSE_D, this);
    browse.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            choose();
          }
        });
    pp.add(browse);
    p.add(pp);

    // provide components for method and encoding
    final MainOptions opts = gui.context.options;
    final SerializerOptions sopts = opts.get(MainOptions.EXPORTER);

    // method (ignore last entry)
    final StringList sl = new StringList();
    for (final SerialMethod sm : SerialMethod.values()) sl.add(sm.name());
    sl.remove(sl.size() - 1);
    method = new BaseXCombo(this, sl.finish());
    final SerialMethod sm = sopts.get(SerializerOptions.METHOD);
    method.setSelectedItem((sm == null ? SerialMethod.BASEX : sm).name());

    mparams = new BaseXTextField(this);
    mparams.setColumns(24);

    final BaseXBack mth = new BaseXBack(new TableLayout(1, 2, 8, 0));
    mth.add(method);
    mth.add(mparams);

    encoding = new BaseXCombo(this, ENCODINGS);
    String enc = sopts.get(SerializerOptions.ENCODING);
    boolean f = false;
    for (final String s : ENCODINGS) f |= s.equals(enc);
    if (!f) {
      enc = enc.toUpperCase(Locale.ENGLISH);
      for (final String s : ENCODINGS) f |= s.equals(enc);
    }
    encoding.setSelectedItem(f ? enc : sopts.get(SerializerOptions.ENCODING));

    params = new BaseXTextField(sopts.toString(), this);
    params.setToolTipText(tooltip(SerializerMode.DEFAULT.get()));

    pp = new BaseXBack(new TableLayout(3, 2, 16, 6)).border(8, 0, 8, 0);
    pp.add(new BaseXLabel(METHOD + COL, true, true));
    pp.add(mth);
    pp.add(new BaseXLabel(ENCODING + COL, true, true));
    pp.add(encoding);
    pp.add(new BaseXLabel(PARAMETERS + COL, true, true));
    pp.add(params);
    p.add(pp);
    info = new BaseXLabel(" ").border(8, 0, 0, 0);
    p.add(info);

    // indentation
    set(p, BorderLayout.CENTER);

    // buttons
    pp = new BaseXBack(new BorderLayout());
    buttons = okCancel();
    pp.add(buttons, BorderLayout.EAST);
    set(pp, BorderLayout.SOUTH);

    action(method);
    finish(null);
  }
Exemplo n.º 13
0
 /**
  * Returns the chosen XML file or directory path.
  *
  * @return file or directory
  */
 public String path() {
   return path.getText().trim();
 }
Exemplo n.º 14
0
 /** Opens a file dialog to choose an XML document or directory. */
 private void choose() {
   final IOFile io = new BaseXFileChooser(CHOOSE_DIR, path.getText(), gui).select(Mode.DOPEN);
   if (io != null) path.setText(io.path());
 }
Exemplo n.º 15
0
  /**
   * Runs a query.
   *
   * @param force force the execution of a new query
   */
  void query(final boolean force) {
    final TokenBuilder tb = new TokenBuilder();
    final Data data = gui.context.data();

    final int cs = panel.getComponentCount();
    for (int c = 0; c < cs; c += 2) {
      final BaseXCombo com = (BaseXCombo) panel.getComponent(c);
      final int k = com.getSelectedIndex();
      if (k <= 0) continue;
      String key = com.getSelectedItem().toString();
      final boolean attr = key.startsWith("@");
      if (!key.contains(":") && !attr) key = "*:" + key;

      final Component comp = panel.getComponent(c + 1);
      String pattern = "";
      String val1 = null;
      String val2 = null;
      if (comp instanceof BaseXTextField) {
        val1 = ((BaseXTextField) comp).getText();
        if (!val1.isEmpty()) {
          if (val1.startsWith("\"")) {
            val1 = val1.replaceAll("\"", "");
            pattern = PATEX;
          } else {
            pattern = attr && data.meta.attrindex || !attr && data.meta.textindex ? PATSUB : PATEX;
          }
        }
      } else if (comp instanceof BaseXCombo) {
        final BaseXCombo combo = (BaseXCombo) comp;
        if (combo.getSelectedIndex() != 0) {
          val1 = combo.getSelectedItem().toString();
          pattern = PATEX;
        }
      } else if (comp instanceof BaseXDSlider) {
        final BaseXDSlider slider = (BaseXDSlider) comp;
        if (slider.min != slider.totMin || slider.max != slider.totMax) {
          final double m = slider.min;
          final double n = slider.max;
          val1 = (long) m == m ? Long.toString((long) m) : Double.toString(m);
          val2 = (long) n == n ? Long.toString((long) n) : Double.toString(n);
          pattern = PATNUM;
        }
      }

      if (attr) {
        key = "descendant-or-self::node()/" + key;
        if (tb.size() == 0) tb.add("//*");
        if (pattern.isEmpty()) pattern = PATSIMPLE;
      } else {
        tb.add("//" + key);
        key = "text()";
      }
      tb.addExt(pattern, key, val1, key, val2);
    }

    String qu = tb.toString();
    final boolean root = gui.context.root();
    final boolean rt = gui.gprop.is(GUIProp.FILTERRT);
    if (!qu.isEmpty() && !rt && !root) qu = "." + qu;

    String simple = all.getText().trim();
    if (!simple.isEmpty()) {
      simple = Find.find(simple, gui.context, rt);
      qu = !qu.isEmpty() ? simple + " | " + qu : simple;
    }

    if (qu.isEmpty()) qu = rt || root ? "/" : ".";

    if (!force && last.equals(qu)) return;
    last = qu;
    gui.xquery(qu, false);
  }
Exemplo n.º 16
0
 @Override
 public void setText(final String txt) {
   super.setText(txt);
   box.removeAllItems();
   pop.setVisible(false);
 }